ResourceController.cs 20 KB

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