ResourceController.cs 30 KB

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