ResourceController.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. 
  2. using NetTaste;
  3. using System.Drawing.Printing;
  4. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  5. namespace OASystem.API.Controllers
  6. {
  7. /// <summary>
  8. /// 资料相关
  9. /// </summary>
  10. //[Authorize]
  11. [Route("api/[controller]/[action]")]
  12. public class ResourceController : ControllerBase
  13. {
  14. private readonly IMapper _mapper;
  15. private readonly IConfiguration _config;
  16. private readonly CarDataRepository _carDataRep;
  17. private readonly LocalGuideDataRepository _localGuideDataRep;
  18. private readonly ThreeCodeRepository _ThreeCodeRep;
  19. private readonly HotelDataRepository _hotelDataRep;
  20. private readonly ResItemInfoRepository _resItemInfoRep;
  21. public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep,
  22. LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep,
  23. HotelDataRepository hotelDataRep, ResItemInfoRepository resItemInfoRep)
  24. {
  25. _mapper = mapper;
  26. _config = config;
  27. _carDataRep = carDataRep;
  28. _localGuideDataRep = localGuideDataRep;
  29. _ThreeCodeRep = threeCodeRep;
  30. _hotelDataRep = hotelDataRep;
  31. _resItemInfoRep = resItemInfoRep;
  32. }
  33. #region 车公司资料板块
  34. /// <summary>
  35. /// 车公司信息查询
  36. /// </summary>
  37. /// <returns></returns>
  38. [HttpPost]
  39. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  40. public async Task<IActionResult> QueryCarData(QueryCarDataDto dto)
  41. {
  42. try
  43. {
  44. Result LocalGuide = await _carDataRep.QueryCarData(dto);
  45. if (LocalGuide.Code == 0)
  46. {
  47. return Ok(JsonView(true, "查询成功", LocalGuide.Data));
  48. }
  49. else
  50. {
  51. return Ok(JsonView(false, LocalGuide.Msg));
  52. }
  53. }
  54. catch (Exception)
  55. {
  56. return Ok(JsonView(false, "程序错误!"));
  57. throw;
  58. }
  59. }
  60. /// <summary>
  61. /// 车公司资料下拉框数据
  62. /// </summary>
  63. /// <returns></returns>
  64. [HttpPost]
  65. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  66. public async Task<IActionResult> QueryCarSelect()
  67. {
  68. try
  69. {
  70. var CarData = _carDataRep.QueryDto<Res_CarData, CarDataSelectView>().ToList();
  71. if (CarData.Count == 0)
  72. {
  73. return Ok(JsonView(false, "暂无数据!"));
  74. }
  75. CarData.Add(new CarDataSelectView { Id = 0, UnitArea = "全部" });
  76. CarData = CarData.Where((x, i) => CarData.FindIndex(z => z.UnitArea == x.UnitArea) == i).ToList();
  77. CarData = CarData.OrderBy(x => x.Id).ToList();
  78. return Ok(JsonView(true, "查询成功", CarData));
  79. }
  80. catch (Exception)
  81. {
  82. return Ok(JsonView(false, "程序错误!"));
  83. throw;
  84. }
  85. }
  86. /// <summary>
  87. /// 车公司信息添加
  88. /// </summary>
  89. /// <returns></returns>
  90. [HttpPost]
  91. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  92. public async Task<IActionResult> AddCarData(AddCarDataDto dto)
  93. {
  94. try
  95. {
  96. if (dto.UnitArea == "")
  97. {
  98. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  99. }
  100. if (dto.UnitName == "")
  101. {
  102. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  103. }
  104. if (dto.Contact == "")
  105. {
  106. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  107. }
  108. if (dto.ContactTel == "")
  109. {
  110. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  111. }
  112. var carDada = _carDataRep.QueryDto<Res_CarData, CarDataView>(a => a.UnitArea == dto.UnitArea && a.UnitName == dto.UnitName && a.Contact == dto.Contact && a.ContactTel == dto.ContactTel).ToList();
  113. if (carDada.Count != 0)
  114. {
  115. return Ok(JsonView(false, "该信息已存在,请勿重复添加!"));
  116. }
  117. Res_CarData _CarData = _mapper.Map<Res_CarData>(dto);
  118. int id = await _carDataRep.AddAsyncReturnId(_CarData);
  119. if (id == 0)
  120. {
  121. return Ok(JsonView(false, "添加失败!"));
  122. }
  123. return Ok(JsonView(true, "添加成功", new { Id = id }));
  124. }
  125. catch (Exception ex)
  126. {
  127. return Ok(JsonView(false, "程序错误!"));
  128. throw;
  129. }
  130. }
  131. /// <summary>
  132. /// 车公司信息修改
  133. /// </summary>
  134. /// <returns></returns>
  135. [HttpPost]
  136. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  137. public async Task<IActionResult> UpCarData(UpCarDataDto dto)
  138. {
  139. try
  140. {
  141. if (dto.UnitArea == "")
  142. {
  143. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  144. }
  145. if (dto.UnitName == "")
  146. {
  147. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  148. }
  149. if (dto.Contact == "")
  150. {
  151. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  152. }
  153. if (dto.ContactTel == "")
  154. {
  155. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  156. }
  157. bool res = await _carDataRep.UpdateAsync(a => a.Id == dto.Id, a => new Res_CarData
  158. {
  159. UnitArea = dto.UnitArea,
  160. UnitName = dto.UnitName,
  161. Address = dto.Address,
  162. Contact = dto.Contact,
  163. ContactTel = dto.ContactTel,
  164. ContactEmail = dto.ContactEmail,
  165. ContactFax = dto.ContactFax,
  166. CarDes = dto.CarDes,
  167. CarPicPaths = dto.CarPicPaths,
  168. OtherInfo = dto.OtherInfo,
  169. Score = dto.Score,
  170. QualificationScore = dto.QualificationScore,
  171. CarAgeScore = dto.CarAgeScore,
  172. CleanImgScore = dto.CleanImgScore,
  173. SmellScore = dto.SmellScore,
  174. WaterPaperScore = dto.WaterPaperScore,
  175. HardwareScore = dto.HardwareScore,
  176. TimeScore = dto.TimeScore,
  177. SafetyScore = dto.SafetyScore,
  178. DrivingAgeScore = dto.DrivingAgeScore,
  179. Remark = dto.Remark,
  180. });
  181. if (!res) { return Ok(JsonView(false, "修改失败!")); }
  182. return Ok(JsonView(true, "修改成功"));
  183. }
  184. catch (Exception ex)
  185. {
  186. return Ok(JsonView(false, "程序错误!"));
  187. throw;
  188. }
  189. }
  190. /// <summary>
  191. /// 车公司信息删除
  192. /// </summary>
  193. /// <returns></returns>
  194. [HttpPost]
  195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  196. public async Task<IActionResult> DelCarData(DelCarDataDto dto)
  197. {
  198. try
  199. {
  200. bool res = await _carDataRep.SoftDeleteByIdAsync<Res_CarData>(dto.Id.ToString(), dto.DeleteUserId);
  201. if (!res) { return Ok(JsonView(false, "删除失败!")); }
  202. return Ok(JsonView(true, "删除成功"));
  203. }
  204. catch (Exception ex)
  205. {
  206. return Ok(JsonView(false, "程序错误!"));
  207. throw;
  208. }
  209. }
  210. #endregion
  211. #region 导游地接资料板块
  212. /// <summary>
  213. /// 导游地接资料查询
  214. /// </summary>
  215. /// <param name="dto"></param>
  216. /// <returns></returns>
  217. [HttpPost]
  218. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  219. public async Task<IActionResult> QueryLocalGuide(QueryLocalGuide dto)
  220. {
  221. try
  222. {
  223. Result LocalGuide = await _localGuideDataRep.QueryLocalGuide(dto);
  224. if (LocalGuide.Code == 0)
  225. {
  226. return Ok(JsonView(true, "查询成功", LocalGuide.Data));
  227. }
  228. else
  229. {
  230. return Ok(JsonView(false, LocalGuide.Msg));
  231. }
  232. }
  233. catch (Exception ex)
  234. {
  235. return Ok(JsonView(false, "程序错误!"));
  236. throw;
  237. }
  238. }
  239. /// <summary>
  240. /// 导游地接资料下拉框数据
  241. /// </summary>
  242. /// <returns></returns>
  243. [HttpPost]
  244. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  245. public async Task<IActionResult> QueryLocalGuideSelect()
  246. {
  247. try
  248. {
  249. var LocalGuide = _carDataRep.QueryDto<Res_LocalGuideData, QueryLocalGuideSelectView>().ToList();
  250. if (LocalGuide.Count == 0)
  251. {
  252. return Ok(JsonView(false, "暂无数据!"));
  253. }
  254. LocalGuide.Add(new QueryLocalGuideSelectView { Id = 0, UnitArea = "全部" });
  255. LocalGuide = LocalGuide.Where((x, i) => LocalGuide.FindIndex(z => z.UnitArea == x.UnitArea) == i).ToList();
  256. LocalGuide = LocalGuide.OrderBy(x => x.Id).ToList();
  257. return Ok(JsonView(true, "查询成功", LocalGuide));
  258. }
  259. catch (Exception)
  260. {
  261. return Ok(JsonView(false, "程序错误!"));
  262. throw;
  263. }
  264. }
  265. /// <summary>
  266. /// 导游地接信息操作(Status:1.新增,2.修改)
  267. /// </summary>
  268. /// <returns></returns>
  269. [HttpPost]
  270. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  271. public async Task<IActionResult> OperationLocalGuide(LocalGuideOperationDto dto)
  272. {
  273. try
  274. {
  275. if (dto.UnitArea == "")
  276. {
  277. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  278. }
  279. if (dto.UnitName == "")
  280. {
  281. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  282. }
  283. if (dto.Contact == "")
  284. {
  285. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  286. }
  287. if (dto.ContactTel == "")
  288. {
  289. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  290. }
  291. Result result = await _localGuideDataRep.LocalGuideOperation(dto);
  292. if (result.Code != 0)
  293. {
  294. return Ok(JsonView(false, result.Msg));
  295. }
  296. return Ok(JsonView(true, result.Msg));
  297. }
  298. catch (Exception ex)
  299. {
  300. return Ok(JsonView(false, "程序错误!"));
  301. throw;
  302. }
  303. }
  304. /// <summary>
  305. /// 导游地接信息操作(删除)
  306. /// </summary>
  307. /// <returns></returns>
  308. [HttpPost]
  309. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  310. public async Task<IActionResult> DelLocalGuide(LocalGuideDelDto dto)
  311. {
  312. try
  313. {
  314. var res = await _localGuideDataRep.SoftDeleteByIdAsync<Res_LocalGuideData>(dto.Id.ToString(), dto.DeleteUserId);
  315. if (!res)
  316. {
  317. return Ok(JsonView(false, "删除失败"));
  318. }
  319. return Ok(JsonView(true, "删除成功!"));
  320. }
  321. catch (Exception ex)
  322. {
  323. return Ok(JsonView(false, "程序错误!"));
  324. throw;
  325. }
  326. }
  327. #endregion
  328. #region 机场三字码信息
  329. /// <summary>
  330. /// 机场三字码查询
  331. /// </summary>
  332. /// <param name="dto"></param>
  333. /// <returns></returns>
  334. [HttpPost]
  335. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  336. public async Task<IActionResult> QueryThreeCode(DtoBase dto)
  337. {
  338. try
  339. {
  340. if (dto.PortType == 1)
  341. {
  342. var ThreeCode = _localGuideDataRep.QueryDto<Res_ThreeCode, ThreeCodeView>().ToList();
  343. if (ThreeCode.Count == 0)
  344. {
  345. return Ok(JsonView(false, "暂无数据!"));
  346. }
  347. ThreeCode = ThreeCode.OrderByDescending(s => s.CreateTime).ToList();
  348. return Ok(JsonView(true, "查询成功", ThreeCode));
  349. }
  350. else if (dto.PortType == 2)
  351. {
  352. //分页写法
  353. if (dto.PageIndex == 0 || dto.PageSize == 0)
  354. {
  355. return Ok(JsonView(false, "请传入PageIndex和PageSize参数"));
  356. }
  357. JsonView _ThreeCode = await _ThreeCodeRep.QuerThreeCode(dto.PageIndex, dto.PageSize);
  358. if (_ThreeCode.Code != 0)
  359. {
  360. return Ok(JsonView(false, _ThreeCode.Msg));
  361. }
  362. return Ok(_ThreeCode);
  363. }
  364. else
  365. {
  366. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  367. }
  368. }
  369. catch (Exception ex)
  370. {
  371. return Ok(JsonView(false, "程序错误!"));
  372. throw;
  373. }
  374. }
  375. /// <summary>
  376. /// 机场三字码资料操作(Status:1.新增,2.修改)
  377. /// </summary>
  378. /// <param name="dto"></param>
  379. /// <returns></returns>
  380. [HttpPost]
  381. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  382. public async Task<IActionResult> OperationThreeCode(ThreeCodeOperationDto dto)
  383. {
  384. try
  385. {
  386. if (dto.Three == "")
  387. {
  388. return Ok(JsonView(false, "请检查三字码是否填写!"));
  389. }
  390. if (dto.Country == "")
  391. {
  392. return Ok(JsonView(false, "请检查国家是否填写!"));
  393. }
  394. if (dto.City == "")
  395. {
  396. return Ok(JsonView(false, "请检查城市是否填写正确!"));
  397. }
  398. if (dto.AirPort == "")
  399. {
  400. return Ok(JsonView(false, "请检查机场是否填写正确!"));
  401. }
  402. Result result = await _ThreeCodeRep.ThreeCodeOperation(dto);
  403. if (result.Code != 0)
  404. {
  405. return Ok(JsonView(false, result.Msg));
  406. }
  407. return Ok(JsonView(true, result.Msg));
  408. }
  409. catch (Exception ex)
  410. {
  411. return Ok(JsonView(false, "程序错误!"));
  412. throw;
  413. }
  414. }
  415. /// <summary>
  416. /// 机场三字码资料操作(删除)
  417. /// </summary>
  418. /// <returns></returns>
  419. [HttpPost]
  420. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  421. public async Task<IActionResult> DelThreeCode(ThreeCodeDelDto dto)
  422. {
  423. try
  424. {
  425. var res = await _ThreeCodeRep.SoftDeleteByIdAsync<Res_ThreeCode>(dto.Id.ToString(), dto.DeleteUserId);
  426. if (!res)
  427. {
  428. return Ok(JsonView(false, "删除失败"));
  429. }
  430. return Ok(JsonView(true, "删除成功!"));
  431. }
  432. catch (Exception ex)
  433. {
  434. return Ok(JsonView(false, "程序错误!"));
  435. throw;
  436. }
  437. }
  438. #endregion
  439. #region 酒店资料数据
  440. /// <summary>
  441. /// 酒店信息查询
  442. /// </summary>
  443. /// <param name="dto"></param>
  444. /// <returns></returns>
  445. [HttpPost]
  446. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  447. public async Task<IActionResult> QueryHotelData(DtoBase dto)
  448. {
  449. try
  450. {
  451. if (dto.PortType == 1)
  452. {
  453. var HotelData = _localGuideDataRep.QueryDto<Res_HotelData, HotelDataView>().ToList();
  454. if (HotelData.Count == 0)
  455. {
  456. return Ok(JsonView(false, "暂无数据!"));
  457. }
  458. HotelData = HotelData.OrderByDescending(s => s.CreateTime).ToList();
  459. return Ok(JsonView(true, "查询成功", HotelData));
  460. }
  461. else if (dto.PortType == 2)
  462. {
  463. var HotelData = _localGuideDataRep.QueryDto<Res_HotelData, HotelDataView>().ToList();
  464. if (HotelData.Count == 0)
  465. {
  466. return Ok(JsonView(false, "暂无数据!"));
  467. }
  468. HotelData = HotelData.OrderByDescending(s => s.CreateTime).ToList();
  469. return Ok(JsonView(true, "查询成功", HotelData));
  470. }
  471. else
  472. {
  473. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  474. }
  475. }
  476. catch (Exception ex)
  477. {
  478. return Ok(JsonView(false, "程序错误!"));
  479. throw;
  480. }
  481. }
  482. /// <summary>
  483. /// 酒店资料操作(Status:1.新增,2.修改)
  484. /// </summary>
  485. /// <param name="dto"></param>
  486. /// <returns></returns>
  487. [HttpPost]
  488. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  489. public async Task<IActionResult> OperationHotelData(OperationHotelDto dto)
  490. {
  491. try
  492. {
  493. if (dto.City == "")
  494. {
  495. return Ok(JsonView(false, "请检查酒店所在城市是否填写!"));
  496. }
  497. if (dto.Name == "")
  498. {
  499. return Ok(JsonView(false, "请检查酒店名称是否填写!"));
  500. }
  501. if (dto.Address == "")
  502. {
  503. return Ok(JsonView(false, "请检查酒店地址是否填写正确!"));
  504. }
  505. if (dto.Tel == "")
  506. {
  507. return Ok(JsonView(false, "请检查酒店联系方式是否填写正确!"));
  508. }
  509. Result result = await _hotelDataRep.OperationHotelData(dto);
  510. if (result.Code != 0)
  511. {
  512. return Ok(JsonView(false, result.Msg));
  513. }
  514. return Ok(JsonView(true, result.Msg));
  515. }
  516. catch (Exception ex)
  517. {
  518. return Ok(JsonView(false, "程序错误!"));
  519. throw;
  520. }
  521. }
  522. /// <summary>
  523. /// 酒店资料操作(删除)
  524. /// </summary>
  525. /// <returns></returns>
  526. [HttpPost]
  527. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  528. public async Task<IActionResult> DelHotelData(DelHotelDataDto dto)
  529. {
  530. try
  531. {
  532. var res = await _hotelDataRep.SoftDeleteByIdAsync<Res_HotelData>(dto.Id.ToString(), dto.DeleteUserId);
  533. if (!res)
  534. {
  535. return Ok(JsonView(false, "删除失败"));
  536. }
  537. return Ok(JsonView(true, "删除成功!"));
  538. }
  539. catch (Exception ex)
  540. {
  541. return Ok(JsonView(false, "程序错误!"));
  542. throw;
  543. }
  544. }
  545. #endregion
  546. #region 物料信息、供应商维护
  547. #region 供应商
  548. /// <summary>
  549. /// 物料供应商查询
  550. /// </summary>
  551. /// <param name="paras">Json序列化</param>
  552. /// <returns></returns>
  553. [HttpPost]
  554. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  555. public async Task<IActionResult> PostSearchItemVendor(string paras)
  556. {
  557. if (string.IsNullOrEmpty(paras))
  558. {
  559. return Ok(JsonView(false, "参数为空"));
  560. }
  561. Search_ResItemVendorDto _ItemVendorDto = System.Text.Json.JsonSerializer.Deserialize<Search_ResItemVendorDto>(paras);
  562. if (_ItemVendorDto != null)
  563. {
  564. if (_ItemVendorDto.SearchType == 2) //获取列表
  565. {
  566. Res_ItemVendorListView rstList = _resItemInfoRep.GetVendorList(_ItemVendorDto);
  567. return Ok(rstList);
  568. }
  569. else
  570. {
  571. Res_ItemVendorView rstInfo = _resItemInfoRep.getVendorInfo(_ItemVendorDto);
  572. return Ok(rstInfo);
  573. }
  574. }
  575. else
  576. {
  577. return Ok(JsonView(false, "参数反序列化失败"));
  578. }
  579. return Ok(JsonView(false));
  580. }
  581. /// <summary>
  582. /// 创建/编辑/删除供应商信息
  583. /// </summary>
  584. /// <param name="_dto"></param>
  585. /// <returns></returns>
  586. [HttpPost]
  587. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  588. public async Task<IActionResult> PostEditItemVendor(Edit_ResItemVendorDto _dto)
  589. {
  590. bool rst = false;
  591. if (_dto.EditType >= 0)
  592. {
  593. if (string.IsNullOrEmpty(_dto.VendorFullName))
  594. {
  595. return Ok(JsonView(false, "全称未填写"));
  596. }
  597. if (string.IsNullOrEmpty(_dto.VendorLinker))
  598. {
  599. return Ok(JsonView(false, "联系人未填写"));
  600. }
  601. if (string.IsNullOrEmpty(_dto.VendorMobile))
  602. {
  603. return Ok(JsonView(false, "联系人手机号未填写"));
  604. }
  605. if (_dto.EditType == 0)
  606. {
  607. var checkEmpty = _resItemInfoRep.Query<Res_ItemVendor>(s => s.FullName == _dto.VendorFullName).First();
  608. if (checkEmpty != null)
  609. {
  610. return Ok(JsonView(false, "已存在同名供应商"));
  611. }
  612. rst = await _resItemInfoRep.addVendorInfo(_dto);
  613. }
  614. else if (_dto.EditType == 1)
  615. {
  616. if (_dto.VendorId > 0)
  617. {
  618. Res_ItemVendor _entity = _mapper.Map<Res_ItemVendor>(_dto);
  619. rst = await _resItemInfoRep.updVendorInfo(_entity);
  620. }
  621. else
  622. {
  623. return Ok(JsonView(false, "供应商不存在"));
  624. }
  625. }
  626. }
  627. else
  628. {
  629. if (_dto.VendorId < 1 || _dto.SysUserId < 1)
  630. {
  631. return Ok(JsonView(false, "用户Id或供应商Id不存在"));
  632. }
  633. Res_ItemVendor _entity = _mapper.Map<Res_ItemVendor>(_dto);
  634. rst = await _resItemInfoRep.delVendorInfo(_entity);
  635. }
  636. return Ok(JsonView(rst));
  637. }
  638. #endregion
  639. #region 物料信息
  640. /// <summary>
  641. /// 物料信息查询
  642. /// </summary>
  643. /// <param name="paras">Json序列化</param>
  644. /// <returns></returns>
  645. [HttpPost]
  646. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  647. public async Task<IActionResult> PostSearchItemInfo(string paras)
  648. {
  649. if (string.IsNullOrEmpty(paras))
  650. {
  651. return Ok(JsonView(false, "参数为空"));
  652. }
  653. Search_ItemInfoDto _ItemInfoDto = System.Text.Json.JsonSerializer.Deserialize<Search_ItemInfoDto>(paras);
  654. if (_ItemInfoDto != null)
  655. {
  656. if (_ItemInfoDto.SearchType == 2) //获取列表
  657. {
  658. Res_ItemInfoListView rstList = _resItemInfoRep.GetItemList(_ItemInfoDto);
  659. return Ok(rstList);
  660. }
  661. else
  662. {
  663. Res_ItemInfoView rstInfo = _resItemInfoRep.getItemInfo(_ItemInfoDto);
  664. return Ok(rstInfo);
  665. }
  666. }
  667. else
  668. {
  669. return Ok(JsonView(false, "参数反序列化失败"));
  670. }
  671. return Ok(JsonView(false));
  672. }
  673. /// <summary>
  674. /// 创建/编辑/删除物料信息
  675. /// </summary>
  676. ///
  677. /// <returns></returns>
  678. [HttpPost]
  679. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  680. public async Task<IActionResult> PostEditItemInfo(Edit_ResItemInfoDto _dto)
  681. {
  682. bool rst = false;
  683. if (_dto.EditType >= 0)
  684. {
  685. if (_dto.VendorId < 1)
  686. {
  687. return Ok(JsonView(false, "未选择供应商"));
  688. }
  689. if (string.IsNullOrEmpty(_dto.ItemName))
  690. {
  691. return Ok(JsonView(false, "物料名称为空"));
  692. }
  693. if (_dto.SetDataId < 1)
  694. {
  695. return Ok(JsonView(false, "未选择物料类型"));
  696. }
  697. if (_dto.SysUserId < 1)
  698. {
  699. return Ok(JsonView(false, "当前操作用户Id为空"));
  700. }
  701. if (_dto.CurrRate <= 0)
  702. {
  703. return Ok(JsonView(false, "物料录入价格不能小于等于0"));
  704. }
  705. if (_dto.EditType == 0)
  706. {
  707. //判断物料名称、类型、供应商全部重复
  708. var checkEmpty = _resItemInfoRep.Query<Res_ItemDetailInfo>(s => s.ItemName == _dto.ItemName && s.SetDataId == _dto.SetDataId && s.VendorId == _dto.VendorId).First();
  709. if (checkEmpty != null)
  710. {
  711. return Ok(JsonView(false, "已存在重复物料信息"));
  712. }
  713. Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
  714. DateTime dtNow = DateTime.Now;
  715. _entity.CreateUserId = _dto.SysUserId;
  716. _entity.IsDel = 0;
  717. _entity.MaxRate = _dto.CurrRate;
  718. _entity.MaxDt = dtNow;
  719. _entity.CurrRate = _dto.CurrRate;
  720. _entity.CurrDt = dtNow;
  721. _entity.MinRate = _dto.CurrRate;
  722. _entity.MinDt = dtNow;
  723. rst = await _resItemInfoRep.AddAsync<Res_ItemDetailInfo>(_entity) > 0;
  724. }
  725. else if (_dto.EditType == 1)
  726. {
  727. if (_dto.ItemId > 0)
  728. {
  729. Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
  730. _entity.Id = _dto.ItemId;
  731. rst = await _resItemInfoRep.updItemInfo(_entity);
  732. }
  733. else
  734. {
  735. return Ok(JsonView(false, "供应商不存在"));
  736. }
  737. }
  738. }
  739. else
  740. {
  741. if (_dto.ItemId < 1 || _dto.SysUserId < 1)
  742. {
  743. return Ok(JsonView(false, "用户Id或物料信息Id不存在"));
  744. }
  745. Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
  746. rst = await _resItemInfoRep.delItemInfo(_entity);
  747. }
  748. return Ok(JsonView(rst));
  749. }
  750. #endregion
  751. #region 物料类型获取
  752. /// <summary>
  753. /// 物料类型列表获取
  754. /// </summary>
  755. /// <param name="paras">Json序列化</param>
  756. /// <returns></returns>
  757. [HttpGet]
  758. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  759. public async Task<IActionResult> GetItemTypeListBySetData()
  760. {
  761. List<SetDataView> list = _resItemInfoRep.GetItemTypeListBySetData();
  762. return Ok(JsonView(list));
  763. }
  764. #endregion
  765. #endregion
  766. }
  767. }