TprdProductController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Ropin.Inspection.Api.Common;
  5. using Ropin.Inspection.Model;
  6. using Ropin.Inspection.Service;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Api.Controllers
  12. {
  13. public class TprdProductController : BaseController
  14. {
  15. private readonly ILogger<TprdProductController> _logger;
  16. private readonly ITprdProductService _TprdProductService;
  17. /// <summary>
  18. /// 构造函数
  19. /// </summary>
  20. /// <param name="TprdProductService"></param>
  21. /// <param name="logger"></param>
  22. public TprdProductController(ITprdProductService TprdProductService, ILogger<TprdProductController> logger)
  23. {
  24. _TprdProductService = TprdProductService;
  25. _logger = logger;
  26. }
  27. /// <summary>
  28. /// 通过ID获取器具信息
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. [HttpGet("GetProductAsync/{id}")]
  33. public async Task<ApiResult> GetProductAsync(Guid id)
  34. {
  35. if (Guid.Empty == id)
  36. {
  37. return new ApiResult(ReturnCode.GeneralError);
  38. }
  39. try
  40. {
  41. var content = await _TprdProductService.GetByIdAsync(id);
  42. return new ApiResult<TprdProductViewModel>(content);
  43. }
  44. catch (Exception ex)
  45. {
  46. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  47. }
  48. }
  49. /// <summary>
  50. /// 获取所有器具
  51. /// </summary>
  52. /// <returns></returns>
  53. [HttpGet("GetProductsAsync")]
  54. public async Task<ApiResult> GetProductsAsync()
  55. {
  56. try
  57. {
  58. var contentList = await _TprdProductService.GetAllAsync();
  59. return new ApiResult<IEnumerable<TprdProductViewModel>>(contentList);
  60. }
  61. catch (Exception ex)
  62. {
  63. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  64. }
  65. }
  66. /// <summary>
  67. /// 通过各个条件查询器具
  68. /// </summary>
  69. /// <param name="searchModel"></param>
  70. /// <returns></returns>
  71. [HttpPost("GetProductsByAsync")]
  72. public async Task<ApiResult> GetProductsByAsync(TprdProductSearchModel searchModel)
  73. {
  74. if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode))
  75. {
  76. return new ApiResult(ReturnCode.ArgsError);
  77. }
  78. searchModel.IsPagination = false;
  79. try
  80. {
  81. var contentList = await _TprdProductService.GetConditionAsync(searchModel);
  82. return new ApiResult<IEnumerable<TprdProductViewModel>>(contentList);
  83. }
  84. catch (Exception ex)
  85. {
  86. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  87. }
  88. }
  89. /// <summary>
  90. /// 获取器具设备数
  91. /// </summary>
  92. /// <param name="storeCode"></param>
  93. /// <returns></returns>
  94. [HttpGet("GetDeviceCountByAsync/{storeCode}")]
  95. [AllowAnonymous]
  96. public async Task<ApiResult> GetDeviceCountByAsync(string storeCode)
  97. {
  98. if (string.IsNullOrEmpty(storeCode))
  99. {
  100. return new ApiResult(ReturnCode.ArgsError);
  101. }
  102. try
  103. {
  104. var count = await _TprdProductService.GetDeviceCountByAsync(storeCode);
  105. return new ApiResult<int>(count);
  106. }
  107. catch (Exception ex)
  108. {
  109. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  110. }
  111. }
  112. /// <summary>
  113. /// 获取异常器具设备数
  114. /// </summary>
  115. /// <param name="storeCode"></param>
  116. /// <returns></returns>
  117. [HttpGet("GetAlertDeviceCountByAsync/{storeCode}")]
  118. [AllowAnonymous]
  119. public async Task<ApiResult> GetAlertDeviceCountByAsync(string storeCode)
  120. {
  121. if (string.IsNullOrEmpty(storeCode))
  122. {
  123. return new ApiResult(ReturnCode.ArgsError);
  124. }
  125. try
  126. {
  127. var count = await _TprdProductService.GetAlertDeviceCountByAsync(storeCode);
  128. return new ApiResult<int>(count);
  129. }
  130. catch (Exception ex)
  131. {
  132. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  133. }
  134. }
  135. /// <summary>
  136. /// 获取异常器具设备列表
  137. /// </summary>
  138. /// <param name="storeCode"></param>
  139. /// <returns></returns>
  140. [HttpGet("GetAlertProductsByAsync/{storeCode}")]
  141. [AllowAnonymous]
  142. public async Task<ApiResult> GetAlertProductsByAsync(string storeCode)
  143. {
  144. if (string.IsNullOrEmpty(storeCode))
  145. {
  146. return new ApiResult(ReturnCode.ArgsError);
  147. }
  148. try
  149. {
  150. var items = await _TprdProductService.GetAlertProductsByAsync(storeCode);
  151. return new ApiResult<IEnumerable<TprdProductViewModel>>(items);
  152. }
  153. catch (Exception ex)
  154. {
  155. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  156. }
  157. }
  158. /// <summary>
  159. /// 获取超过有效期器具列表
  160. /// </summary>
  161. /// <param name="storeCode"></param>
  162. /// <returns></returns>
  163. [HttpGet("GetValiDateProductsByAsync/{storeCode}")]
  164. [AllowAnonymous]
  165. public async Task<ApiResult> GetValiDateProductsByAsync(string storeCode)
  166. {
  167. if (string.IsNullOrEmpty(storeCode))
  168. {
  169. return new ApiResult(ReturnCode.ArgsError);
  170. }
  171. try
  172. {
  173. var items = await _TprdProductService.GetValiDateProductsByAsync(storeCode);
  174. return new ApiResult<IEnumerable<TprdProductViewModel>>(items);
  175. }
  176. catch (Exception ex)
  177. {
  178. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  179. }
  180. }
  181. /// <summary>
  182. /// 通过code取异常设备信息
  183. /// </summary>
  184. /// <param name="code"></param>
  185. /// <returns></returns>
  186. [HttpGet("GetAlertProductByCodeAsync/{code}")]
  187. [AllowAnonymous]
  188. public async Task<ApiResult> GetAlertProductByCodeAsync(Guid code)
  189. {
  190. if (Guid.Empty.Equals(code) )
  191. {
  192. return new ApiResult(ReturnCode.ArgsError);
  193. }
  194. try
  195. {
  196. var items = await _TprdProductService.GetAlertProductByCodeAsync(code);
  197. return new ApiResult<TprdProductViewModel>(items);
  198. }
  199. catch (Exception ex)
  200. {
  201. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  202. }
  203. }
  204. /// <summary>
  205. /// 通过code取过期设备信息
  206. /// </summary>
  207. /// <param name="code"></param>
  208. /// <returns></returns>
  209. [HttpGet("GetValiDateProductByCodeAsync/{code}")]
  210. [AllowAnonymous]
  211. public async Task<ApiResult> GetValiDateProductByCodeAsync(Guid code)
  212. {
  213. if (Guid.Empty.Equals(code))
  214. {
  215. return new ApiResult(ReturnCode.ArgsError);
  216. }
  217. try
  218. {
  219. var items = await _TprdProductService.GetValiDateProductByCodeAsync(code);
  220. return new ApiResult<TprdProductViewModel>(items);
  221. }
  222. catch (Exception ex)
  223. {
  224. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  225. }
  226. }
  227. /// <summary>
  228. /// 通过网点取设备及运行的数据
  229. /// </summary>
  230. /// <param name="searchModel"></param>
  231. /// <returns></returns>
  232. [HttpPost("GetProductWithDataByAsync")]
  233. [AllowAnonymous]
  234. public async Task<ApiResult> GetProductWithDataByAsync(TprdProductWithDataSearchModel searchModel)
  235. {
  236. if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode))
  237. {
  238. return new ApiResult(ReturnCode.ArgsError);
  239. }
  240. searchModel.IsPagination = false;
  241. try
  242. {
  243. var contentList = await _TprdProductService.GetProductWithDataByAsync(searchModel);
  244. return new ApiResult<IEnumerable<AllProductWithDevViewModel>>(contentList);
  245. }
  246. catch (Exception ex)
  247. {
  248. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  249. }
  250. }
  251. /// <summary>
  252. /// 根据网点区域取设备
  253. /// </summary>
  254. /// <param name="searchModel"></param>
  255. /// <returns></returns>
  256. [HttpPost("GetDeviceByAreaCode")]
  257. [AllowAnonymous]
  258. public async Task<ApiResult> GetDeviceByAreaCode(TprdDeviceByAreaSearchModel searchModel)
  259. {
  260. if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode))
  261. {
  262. return new ApiResult(ReturnCode.ArgsError);
  263. }
  264. try
  265. {
  266. var contentList = await _TprdProductService.GetDeviceByAreaCode(searchModel);
  267. return new ApiResult<IEnumerable<TprdDeviceByAreaViewModel>>(contentList);
  268. }
  269. catch (Exception ex)
  270. {
  271. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  272. }
  273. }
  274. /// <summary>
  275. /// 创建器具
  276. /// </summary>
  277. /// <param name="content"></param>
  278. /// <returns></returns>
  279. [HttpPost("CreateProductAsync")]
  280. public async Task<ApiResult> CreateProductAsync(TprdProductViewModel content)
  281. {
  282. if (content == null)
  283. {
  284. return new ApiResult(ReturnCode.ArgsError);
  285. }
  286. try
  287. {
  288. await _TprdProductService.CreateOneAsync(content);
  289. }
  290. catch (Exception ex)
  291. {
  292. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  293. }
  294. return new ApiResult(ReturnCode.Success);
  295. }
  296. /// <summary>
  297. /// 扫巡二维码获取器具
  298. /// </summary>
  299. /// <param name="QRCode"></param>
  300. /// <param name="storeCode"></param>
  301. /// <returns></returns>
  302. [HttpGet("GetProductByQRCodeAsync/{QRCode}/{storeCode}")]
  303. public async Task<ApiResult> GetProductByQRCodeAsync(string QRCode, string storeCode)
  304. {
  305. try
  306. {
  307. if (string.IsNullOrEmpty(QRCode) || string.IsNullOrEmpty(storeCode))
  308. {
  309. return new ApiResult(ReturnCode.GeneralError);
  310. }
  311. TprdProductViewModel item = await _TprdProductService.GetProductByQRCodeAsync(QRCode, storeCode);
  312. return new ApiResult<TprdProductViewModel>(item);
  313. }
  314. catch (Exception ex)
  315. {
  316. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  317. }
  318. }
  319. /// <summary>
  320. /// 删除器具
  321. /// </summary>
  322. /// <param name="id"></param>
  323. /// <returns></returns>
  324. [HttpDelete("DeleteProductAsync/{id}")]
  325. public async Task<ApiResult> DeleteProductAsync(Guid id)
  326. {
  327. if (Guid.Empty == id)
  328. {
  329. return new ApiResult(ReturnCode.GeneralError);
  330. }
  331. try
  332. {
  333. await _TprdProductService.DeleteAsync(id);
  334. }
  335. catch (Exception ex)
  336. {
  337. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  338. }
  339. return new ApiResult(ReturnCode.Success);
  340. }
  341. /// <summary>
  342. /// 更新器具
  343. /// </summary>
  344. /// <param name="id"></param>
  345. /// <param name="updateModel"></param>
  346. /// <returns></returns>
  347. [HttpPut("UpdateProductAsync/{id}")]
  348. public async Task<ApiResult> UpdateProductAsync(Guid id, TprdProductUpdateModel updateModel)
  349. {
  350. if (Guid.Empty == id)
  351. {
  352. return new ApiResult(ReturnCode.GeneralError);
  353. }
  354. try
  355. {
  356. await _TprdProductService.UpdateAsync(id, updateModel);
  357. }
  358. catch (Exception ex)
  359. {
  360. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  361. }
  362. return new ApiResult(ReturnCode.Success);
  363. }
  364. }
  365. }