ResourceController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep, LocalGuideDataRepository localGuideDataRep)
  16. {
  17. _mapper = mapper;
  18. _config = config;
  19. _carDataRep = carDataRep;
  20. _localGuideDataRep = localGuideDataRep;
  21. }
  22. #region 车公司资料板块
  23. /// <summary>
  24. /// 车公司信息查询
  25. /// </summary>
  26. /// <returns></returns>
  27. [HttpPost]
  28. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29. public async Task<IActionResult> QuerCarData(DtoBase dto)
  30. {
  31. try
  32. {
  33. if (dto.PortType==1)
  34. {
  35. var carDada = _carDataRep.QueryDto<Res_CarData, CarDataView>().ToList();
  36. if (carDada.Count == 0)
  37. {
  38. return Ok(JsonView(false, "暂无数据!"));
  39. }
  40. carDada = carDada.OrderByDescending(s => s.CreateTime).ToList();
  41. return Ok(JsonView(true, "查询成功", carDada));
  42. }
  43. else if(dto.PortType==2)
  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
  54. {
  55. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  56. }
  57. }
  58. catch (Exception ex)
  59. {
  60. return Ok(JsonView(false, "程序错误!"));
  61. throw;
  62. }
  63. }
  64. /// <summary>
  65. /// 车公司信息添加
  66. /// </summary>
  67. /// <returns></returns>
  68. [HttpPost]
  69. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  70. public async Task<IActionResult> AddCarData(AddCarDataDto dto)
  71. {
  72. try
  73. {
  74. if (dto.UnitArea == "")
  75. {
  76. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  77. }
  78. if (dto.UnitName == "")
  79. {
  80. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  81. }
  82. if (dto.Contact == "")
  83. {
  84. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  85. }
  86. if (dto.ContactTel == "")
  87. {
  88. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  89. }
  90. 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();
  91. if (carDada.Count!=0)
  92. {
  93. return Ok(JsonView(false, "该信息已存在,请勿重复添加!"));
  94. }
  95. Res_CarData _CarData = _mapper.Map<Res_CarData>(dto);
  96. int id = await _carDataRep.AddAsyncReturnId(_CarData);
  97. if (id == 0)
  98. {
  99. return Ok(JsonView(false, "添加失败!"));
  100. }
  101. return Ok(JsonView(true, "添加成功", new { Id = id }));
  102. }
  103. catch (Exception ex)
  104. {
  105. return Ok(JsonView(false, "程序错误!"));
  106. throw;
  107. }
  108. }
  109. /// <summary>
  110. /// 车公司信息修改
  111. /// </summary>
  112. /// <returns></returns>
  113. [HttpPost]
  114. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  115. public async Task<IActionResult> UpCarData(UpCarDataDto dto)
  116. {
  117. try
  118. {
  119. if (dto.UnitArea == "")
  120. {
  121. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  122. }
  123. if (dto.UnitName == "")
  124. {
  125. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  126. }
  127. if (dto.Contact == "")
  128. {
  129. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  130. }
  131. if (dto.ContactTel == "")
  132. {
  133. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  134. }
  135. bool res = await _carDataRep.UpdateAsync(a => a.Id == dto.Id, a => new Res_CarData
  136. {
  137. UnitArea = dto.UnitArea,
  138. UnitName = dto.UnitName,
  139. Address = dto.Address,
  140. Contact = dto.Contact,
  141. ContactTel = dto.ContactTel,
  142. ContactEmail = dto.ContactEmail,
  143. ContactFax = dto.ContactFax,
  144. CarDes = dto.CarDes,
  145. CarPicPaths = dto.CarPicPaths,
  146. OtherInfo = dto.OtherInfo,
  147. Score = dto.Score,
  148. QualificationScore = dto.QualificationScore,
  149. CarAgeScore = dto.CarAgeScore,
  150. CleanImgScore = dto.CleanImgScore,
  151. SmellScore = dto.SmellScore,
  152. WaterPaperScore = dto.WaterPaperScore,
  153. HardwareScore = dto.HardwareScore,
  154. TimeScore = dto.TimeScore,
  155. SafetyScore = dto.SafetyScore,
  156. DrivingAgeScore = dto.DrivingAgeScore,
  157. Remark = dto.Remark,
  158. });
  159. if (!res) { return Ok(JsonView(false, "修改失败!")); }
  160. return Ok(JsonView(true, "修改成功"));
  161. }
  162. catch (Exception ex)
  163. {
  164. return Ok(JsonView(false, "程序错误!"));
  165. throw;
  166. }
  167. }
  168. /// <summary>
  169. /// 车公司信息删除
  170. /// </summary>
  171. /// <returns></returns>
  172. [HttpPost]
  173. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  174. public async Task<IActionResult> DelCarData(DelCarDataDto dto)
  175. {
  176. try
  177. {
  178. bool res = await _carDataRep.SoftDeleteByIdAsync<Res_CarData>(dto.Id.ToString(), dto.DeleteUserId);
  179. if (!res) { return Ok(JsonView(false, "删除失败!")); }
  180. return Ok(JsonView(true, "删除成功"));
  181. }
  182. catch (Exception ex)
  183. {
  184. return Ok(JsonView(false, "程序错误!"));
  185. throw;
  186. }
  187. }
  188. #endregion
  189. #region 导游地接资料板块
  190. /// <summary>
  191. /// 导游地接资料查询
  192. /// </summary>
  193. /// <param name="dto"></param>
  194. /// <returns></returns>
  195. [HttpPost]
  196. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  197. public async Task<IActionResult> QuerLocalGuide(DtoBase dto)
  198. {
  199. try
  200. {
  201. if (dto.PortType == 1)
  202. {
  203. var LocalGuideData = _localGuideDataRep.QueryDto<Res_LocalGuideData, LocalGuideDataView>().ToList();
  204. if (LocalGuideData.Count == 0)
  205. {
  206. return Ok(JsonView(false, "暂无数据!"));
  207. }
  208. LocalGuideData = LocalGuideData.OrderByDescending(s => s.CreateTime).ToList();
  209. return Ok(JsonView(true, "查询成功", LocalGuideData));
  210. }
  211. else if (dto.PortType == 2)
  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
  222. {
  223. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. return Ok(JsonView(false, "程序错误!"));
  229. throw;
  230. }
  231. }
  232. /// <summary>
  233. /// 导游地接信息操作(增改)
  234. /// </summary>
  235. /// <returns></returns>
  236. [HttpPost]
  237. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  238. public async Task<IActionResult> LocalGuideOperation(LocalGuideOperationDto dto)
  239. {
  240. try
  241. {
  242. if (dto.UnitArea == "")
  243. {
  244. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  245. }
  246. if (dto.UnitName == "")
  247. {
  248. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  249. }
  250. if (dto.Contact == "")
  251. {
  252. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  253. }
  254. if (dto.ContactTel == "")
  255. {
  256. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  257. }
  258. Result result = await _localGuideDataRep.LocalGuideOperation(dto);
  259. if (result.Code != 0)
  260. {
  261. return Ok(JsonView(false, result.Msg));
  262. }
  263. return Ok(JsonView(true, result.Msg, new { Id = result.Data }));
  264. }
  265. catch (Exception ex)
  266. {
  267. return Ok(JsonView(false, "程序错误!"));
  268. throw;
  269. }
  270. }
  271. /// <summary>
  272. /// 导游地接信息操作(删除)
  273. /// </summary>
  274. /// <returns></returns>
  275. [HttpPost]
  276. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  277. public async Task<IActionResult> LocalGuideDel(LocalGuideDelDto dto)
  278. {
  279. try
  280. {
  281. var res = await _localGuideDataRep.SoftDeleteByIdAsync<Res_LocalGuideData>(dto.Id.ToString(),dto.DeleteUserId);
  282. if (!res)
  283. {
  284. return Ok(JsonView(false, "删除失败"));
  285. }
  286. return Ok(JsonView(true,"删除成功!"));
  287. }
  288. catch (Exception ex)
  289. {
  290. return Ok(JsonView(false, "程序错误!"));
  291. throw;
  292. }
  293. }
  294. #endregion
  295. }
  296. }