ResourceController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep, LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep)
  19. {
  20. _mapper = mapper;
  21. _config = config;
  22. _carDataRep = carDataRep;
  23. _localGuideDataRep = localGuideDataRep;
  24. _ThreeCodeRep = threeCodeRep;
  25. }
  26. #region 车公司资料板块
  27. /// <summary>
  28. /// 车公司信息查询
  29. /// </summary>
  30. /// <returns></returns>
  31. [HttpPost]
  32. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33. public async Task<IActionResult> QuerCarData(DtoBase dto)
  34. {
  35. try
  36. {
  37. if (dto.PortType==1)
  38. {
  39. var carDada = _carDataRep.QueryDto<Res_CarData, CarDataView>().ToList();
  40. if (carDada.Count == 0)
  41. {
  42. return Ok(JsonView(false, "暂无数据!"));
  43. }
  44. carDada = carDada.OrderByDescending(s => s.CreateTime).ToList();
  45. return Ok(JsonView(true, "查询成功", carDada));
  46. }
  47. else if(dto.PortType==2)
  48. {
  49. var carDada = _carDataRep.QueryDto<Res_CarData, CarDataView>().ToList();
  50. if (carDada.Count == 0)
  51. {
  52. return Ok(JsonView(false, "暂无数据!"));
  53. }
  54. carDada=carDada.OrderByDescending(s=>s.CreateTime).ToList();
  55. return Ok(JsonView(true, "查询成功", carDada));
  56. }
  57. else
  58. {
  59. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  60. }
  61. }
  62. catch (Exception ex)
  63. {
  64. return Ok(JsonView(false, "程序错误!"));
  65. throw;
  66. }
  67. }
  68. /// <summary>
  69. /// 车公司信息添加
  70. /// </summary>
  71. /// <returns></returns>
  72. [HttpPost]
  73. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  74. public async Task<IActionResult> AddCarData(AddCarDataDto dto)
  75. {
  76. try
  77. {
  78. if (dto.UnitArea == "")
  79. {
  80. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  81. }
  82. if (dto.UnitName == "")
  83. {
  84. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  85. }
  86. if (dto.Contact == "")
  87. {
  88. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  89. }
  90. if (dto.ContactTel == "")
  91. {
  92. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  93. }
  94. 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();
  95. if (carDada.Count!=0)
  96. {
  97. return Ok(JsonView(false, "该信息已存在,请勿重复添加!"));
  98. }
  99. Res_CarData _CarData = _mapper.Map<Res_CarData>(dto);
  100. int id = await _carDataRep.AddAsyncReturnId(_CarData);
  101. if (id == 0)
  102. {
  103. return Ok(JsonView(false, "添加失败!"));
  104. }
  105. return Ok(JsonView(true, "添加成功", new { Id = id }));
  106. }
  107. catch (Exception ex)
  108. {
  109. return Ok(JsonView(false, "程序错误!"));
  110. throw;
  111. }
  112. }
  113. /// <summary>
  114. /// 车公司信息修改
  115. /// </summary>
  116. /// <returns></returns>
  117. [HttpPost]
  118. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  119. public async Task<IActionResult> UpCarData(UpCarDataDto dto)
  120. {
  121. try
  122. {
  123. if (dto.UnitArea == "")
  124. {
  125. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  126. }
  127. if (dto.UnitName == "")
  128. {
  129. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  130. }
  131. if (dto.Contact == "")
  132. {
  133. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  134. }
  135. if (dto.ContactTel == "")
  136. {
  137. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  138. }
  139. bool res = await _carDataRep.UpdateAsync(a => a.Id == dto.Id, a => new Res_CarData
  140. {
  141. UnitArea = dto.UnitArea,
  142. UnitName = dto.UnitName,
  143. Address = dto.Address,
  144. Contact = dto.Contact,
  145. ContactTel = dto.ContactTel,
  146. ContactEmail = dto.ContactEmail,
  147. ContactFax = dto.ContactFax,
  148. CarDes = dto.CarDes,
  149. CarPicPaths = dto.CarPicPaths,
  150. OtherInfo = dto.OtherInfo,
  151. Score = dto.Score,
  152. QualificationScore = dto.QualificationScore,
  153. CarAgeScore = dto.CarAgeScore,
  154. CleanImgScore = dto.CleanImgScore,
  155. SmellScore = dto.SmellScore,
  156. WaterPaperScore = dto.WaterPaperScore,
  157. HardwareScore = dto.HardwareScore,
  158. TimeScore = dto.TimeScore,
  159. SafetyScore = dto.SafetyScore,
  160. DrivingAgeScore = dto.DrivingAgeScore,
  161. Remark = dto.Remark,
  162. });
  163. if (!res) { return Ok(JsonView(false, "修改失败!")); }
  164. return Ok(JsonView(true, "修改成功"));
  165. }
  166. catch (Exception ex)
  167. {
  168. return Ok(JsonView(false, "程序错误!"));
  169. throw;
  170. }
  171. }
  172. /// <summary>
  173. /// 车公司信息删除
  174. /// </summary>
  175. /// <returns></returns>
  176. [HttpPost]
  177. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  178. public async Task<IActionResult> DelCarData(DelCarDataDto dto)
  179. {
  180. try
  181. {
  182. bool res = await _carDataRep.SoftDeleteByIdAsync<Res_CarData>(dto.Id.ToString(), dto.DeleteUserId);
  183. if (!res) { return Ok(JsonView(false, "删除失败!")); }
  184. return Ok(JsonView(true, "删除成功"));
  185. }
  186. catch (Exception ex)
  187. {
  188. return Ok(JsonView(false, "程序错误!"));
  189. throw;
  190. }
  191. }
  192. #endregion
  193. #region 导游地接资料板块
  194. /// <summary>
  195. /// 导游地接资料查询
  196. /// </summary>
  197. /// <param name="dto"></param>
  198. /// <returns></returns>
  199. [HttpPost]
  200. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  201. public async Task<IActionResult> QuerLocalGuide(DtoBase dto)
  202. {
  203. try
  204. {
  205. if (dto.PortType == 1)
  206. {
  207. var LocalGuideData = _localGuideDataRep.QueryDto<Res_LocalGuideData, LocalGuideDataView>().ToList();
  208. if (LocalGuideData.Count == 0)
  209. {
  210. return Ok(JsonView(false, "暂无数据!"));
  211. }
  212. LocalGuideData = LocalGuideData.OrderByDescending(s => s.CreateTime).ToList();
  213. return Ok(JsonView(true, "查询成功", LocalGuideData));
  214. }
  215. else if (dto.PortType == 2)
  216. {
  217. var LocalGuideData = _localGuideDataRep.QueryDto<Res_LocalGuideData, LocalGuideDataView>().ToList();
  218. if (LocalGuideData.Count == 0)
  219. {
  220. return Ok(JsonView(false, "暂无数据!"));
  221. }
  222. LocalGuideData = LocalGuideData.OrderByDescending(s => s.CreateTime).ToList();
  223. return Ok(JsonView(true, "查询成功", LocalGuideData));
  224. }
  225. else
  226. {
  227. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. return Ok(JsonView(false, "程序错误!"));
  233. throw;
  234. }
  235. }
  236. /// <summary>
  237. /// 导游地接信息操作(增改)
  238. /// </summary>
  239. /// <returns></returns>
  240. [HttpPost]
  241. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  242. public async Task<IActionResult> OperationLocalGuide(LocalGuideOperationDto dto)
  243. {
  244. try
  245. {
  246. if (dto.UnitArea == "")
  247. {
  248. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  249. }
  250. if (dto.UnitName == "")
  251. {
  252. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  253. }
  254. if (dto.Contact == "")
  255. {
  256. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  257. }
  258. if (dto.ContactTel == "")
  259. {
  260. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  261. }
  262. Result result = await _localGuideDataRep.LocalGuideOperation(dto);
  263. if (result.Code != 0)
  264. {
  265. return Ok(JsonView(false, result.Msg));
  266. }
  267. return Ok(JsonView(true, result.Msg));
  268. }
  269. catch (Exception ex)
  270. {
  271. return Ok(JsonView(false, "程序错误!"));
  272. throw;
  273. }
  274. }
  275. /// <summary>
  276. /// 导游地接信息操作(删除)
  277. /// </summary>
  278. /// <returns></returns>
  279. [HttpPost]
  280. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  281. public async Task<IActionResult> DelLocalGuide(LocalGuideDelDto dto)
  282. {
  283. try
  284. {
  285. var res = await _localGuideDataRep.SoftDeleteByIdAsync<Res_LocalGuideData>(dto.Id.ToString(),dto.DeleteUserId);
  286. if (!res)
  287. {
  288. return Ok(JsonView(false, "删除失败"));
  289. }
  290. return Ok(JsonView(true,"删除成功!"));
  291. }
  292. catch (Exception ex)
  293. {
  294. return Ok(JsonView(false, "程序错误!"));
  295. throw;
  296. }
  297. }
  298. #endregion
  299. #region 机场三字码信息
  300. /// <summary>
  301. /// 机场三字码查询
  302. /// </summary>
  303. /// <param name="dto"></param>
  304. /// <returns></returns>
  305. [HttpPost]
  306. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  307. public async Task<IActionResult> QuerThreeCode(DtoBase dto)
  308. {
  309. try
  310. {
  311. if (dto.PortType == 1)
  312. {
  313. var ThreeCode = _localGuideDataRep.QueryDto<Res_ThreeCode, ThreeCodeView>().ToList();
  314. if (ThreeCode.Count == 0)
  315. {
  316. return Ok(JsonView(false, "暂无数据!"));
  317. }
  318. ThreeCode = ThreeCode.OrderByDescending(s => s.CreateTime).ToList();
  319. return Ok(JsonView(true, "查询成功", ThreeCode));
  320. }
  321. else if (dto.PortType == 2)
  322. {
  323. //分页写法
  324. if (dto.PageIndex==0 || dto.PageSize==0)
  325. {
  326. return Ok(JsonView(false, "请传入PageIndex和PageSize参数"));
  327. }
  328. JsonView _ThreeCode = await _ThreeCodeRep.QuerThreeCode(dto.PageIndex, dto.PageSize);
  329. if (_ThreeCode.Code != 0)
  330. {
  331. return Ok(JsonView(false, _ThreeCode.Msg));
  332. }
  333. return Ok(_ThreeCode);
  334. }
  335. else
  336. {
  337. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  338. }
  339. }
  340. catch (Exception ex)
  341. {
  342. return Ok(JsonView(false, "程序错误!"));
  343. throw;
  344. }
  345. }
  346. /// <summary>
  347. /// 机场编辑,添加操作
  348. /// </summary>
  349. /// <param name="dto"></param>
  350. /// <returns></returns>
  351. [HttpPost]
  352. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  353. public async Task<IActionResult> OperationThreeCode(ThreeCodeOperationDto dto)
  354. {
  355. try
  356. {
  357. if (dto.Three == "")
  358. {
  359. return Ok(JsonView(false, "请检查三字码是否填写!"));
  360. }
  361. if (dto.Country == "")
  362. {
  363. return Ok(JsonView(false, "请检查国家是否填写!"));
  364. }
  365. if (dto.City == "")
  366. {
  367. return Ok(JsonView(false, "请检查城市是否填写正确!"));
  368. }
  369. if (dto.AirPort == "")
  370. {
  371. return Ok(JsonView(false, "请检查机场是否填写正确!"));
  372. }
  373. Result result = await _ThreeCodeRep.ThreeCodeOperation(dto);
  374. if (result.Code != 0)
  375. {
  376. return Ok(JsonView(false, result.Msg));
  377. }
  378. return Ok(JsonView(true, result.Msg));
  379. }
  380. catch (Exception ex)
  381. {
  382. return Ok(JsonView(false, "程序错误!"));
  383. throw;
  384. }
  385. }
  386. /// <summary>
  387. /// 机场三字码资料操作(删除)
  388. /// </summary>
  389. /// <returns></returns>
  390. [HttpPost]
  391. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  392. public async Task<IActionResult> DelThreeCode(ThreeCodeDelDto dto)
  393. {
  394. try
  395. {
  396. var res = await _ThreeCodeRep.SoftDeleteByIdAsync<Res_ThreeCode>(dto.Id.ToString(), dto.DeleteUserId);
  397. if (!res)
  398. {
  399. return Ok(JsonView(false, "删除失败"));
  400. }
  401. return Ok(JsonView(true, "删除成功!"));
  402. }
  403. catch (Exception ex)
  404. {
  405. return Ok(JsonView(false, "程序错误!"));
  406. throw;
  407. }
  408. }
  409. #endregion
  410. }
  411. }