ResourceController.cs 29 KB

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