ResourceController.cs 28 KB

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