TmtnDevOperateRecordController.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.Extensions.Logging;
  5. using Ropin.Inspection.Api.Common;
  6. using Ropin.Inspection.Api.Controllers;
  7. using Ropin.Inspection.Model;
  8. using Ropin.Inspection.Model.Entities;
  9. using Ropin.Inspection.Model.ViewModel;
  10. using Ropin.Inspection.Service;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Threading.Tasks;
  15. namespace Ropin.Inspection.Api
  16. {
  17. public class TmtnDevOperateRecordController : BaseController
  18. {
  19. public ILogger<TmtnDevOperateRecordController> _logger { get; }
  20. private readonly ITmtnDevOperateRecordService _TmtnDevOperateRecordService;
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="TmtnDevOperateRecordService"></param>
  25. /// <param name="logger"></param>
  26. public TmtnDevOperateRecordController(ITmtnDevOperateRecordService TmtnDevOperateRecordService, ILogger<TmtnDevOperateRecordController> logger)
  27. {
  28. _TmtnDevOperateRecordService = TmtnDevOperateRecordService;
  29. _logger = logger;
  30. }
  31. /// <summary>
  32. /// 取运维工单统计
  33. /// </summary>
  34. /// <param name="storeCode"></param>
  35. /// <returns></returns>
  36. [HttpGet("GetDevOpsStatisticsAsync/{storeCode}")]
  37. public async Task<ApiResult> GetDevOpsStatisticsAsync(string storeCode)
  38. {
  39. if (string.IsNullOrEmpty(storeCode))
  40. {
  41. return new ApiResult(ReturnCode.GeneralError);
  42. }
  43. try
  44. {
  45. var content = await _TmtnDevOperateRecordService.GetDevOpsStatisticsAsync(storeCode);
  46. return new ApiResult<RepairStatistics>(content);
  47. }
  48. catch (Exception ex)
  49. {
  50. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  51. }
  52. }
  53. /// <summary>
  54. /// 维保次数统计,大屏
  55. /// </summary>
  56. /// <param name="storeCode"></param>
  57. /// <returns></returns>
  58. [HttpGet("GetDevOpsStatisticsFullScreenAsync/{storeCode}")]
  59. [AllowAnonymous]
  60. public async Task<IEnumerable<FullScreenRecordItem>> GetDevOpsStatisticsFullScreenAsync(string storeCode)
  61. {
  62. if (string.IsNullOrEmpty(storeCode))
  63. {
  64. return new FullScreenRecordItem[0];
  65. }
  66. try
  67. {
  68. var content = await _TmtnDevOperateRecordService.GetDevOpsStatisticsFullScreenAsync(storeCode);
  69. return content;
  70. }
  71. catch
  72. {
  73. return new FullScreenRecordItem[0];
  74. }
  75. }
  76. /// <summary>
  77. /// 通过id获取设备操作记录信息
  78. /// </summary>
  79. /// <param name="id"></param>
  80. /// <returns></returns>
  81. [HttpGet("GetDevOperateRecordAsync/{id}")]
  82. public async Task<ApiResult> GetDevOperateRecordAsync(string id)
  83. {
  84. if (string.IsNullOrEmpty(id))
  85. {
  86. return new ApiResult(ReturnCode.GeneralError);
  87. }
  88. try
  89. {
  90. var content = await _TmtnDevOperateRecordService.GetConditionAsync(new TmtnDevOperateRecordSearchModel { C_ID = id });
  91. return new ApiResult<TmtnDevOperateRecordViewModel>(content.FirstOrDefault());
  92. }
  93. catch (Exception ex)
  94. {
  95. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  96. }
  97. }
  98. /// <summary>
  99. /// 获取所有设备操作记录
  100. /// </summary>
  101. /// <returns></returns>
  102. [HttpGet("GetDevOperateRecordsAsync")]
  103. public async Task<ApiResult> GetDevOperateRecordsAsync()
  104. {
  105. try
  106. {
  107. var contentList = await _TmtnDevOperateRecordService.GetAllAsync();
  108. return new ApiResult<IEnumerable<TmtnDevOperateRecordViewModel>>(contentList);
  109. }
  110. catch (Exception ex)
  111. {
  112. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  113. }
  114. }
  115. /// <summary>
  116. /// 通过设备操作记录名称条件查询
  117. /// </summary>
  118. /// <param name="searchModel"></param>
  119. /// <returns></returns>
  120. [HttpPost("GetDevOperateRecordsByAsync")]
  121. public async Task<ApiResult> GetDevOperateRecordsByAsync(TmtnDevOperateRecordSearchModel searchModel)
  122. {
  123. if (searchModel == null)
  124. {
  125. return new ApiResult(ReturnCode.ArgsError);
  126. }
  127. searchModel.IsPagination = false;
  128. try
  129. {
  130. var contentList = await _TmtnDevOperateRecordService.GetConditionAsync(searchModel);
  131. return new ApiResult<PagesModel<TmtnDevOperateRecordViewModel>>(new PagesModel<TmtnDevOperateRecordViewModel>(contentList, searchModel));
  132. }
  133. catch (Exception ex)
  134. {
  135. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  136. }
  137. }
  138. /// <summary>
  139. /// 创建设备操作记录
  140. /// </summary>
  141. /// <param name="content"></param>
  142. /// <returns></returns>
  143. [HttpPost("CreateDevOperateRecordAsync")]
  144. public async Task<ApiResult> CreateDevOperateRecordAsync(TmtnDevOperateRecordViewModel content)
  145. {
  146. if (content == null)
  147. {
  148. return new ApiResult(ReturnCode.ArgsError);
  149. }
  150. try
  151. {
  152. await _TmtnDevOperateRecordService.CreateOneAsync(content);
  153. }
  154. catch (Exception ex)
  155. {
  156. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  157. }
  158. return new ApiResult(ReturnCode.Success);
  159. }
  160. /// <summary>
  161. /// 删除设备操作记录
  162. /// </summary>
  163. /// <param name="id"></param>
  164. /// <returns></returns>
  165. [HttpDelete("DeleteDevOperateRecordAsync/{id}")]
  166. public async Task<ApiResult> DeleteDevOperateRecordAsync(string id)
  167. {
  168. if (string.IsNullOrEmpty(id))
  169. {
  170. return new ApiResult(ReturnCode.GeneralError);
  171. }
  172. try
  173. {
  174. await _TmtnDevOperateRecordService.DeleteAsync(id);
  175. }
  176. catch (Exception ex)
  177. {
  178. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  179. }
  180. return new ApiResult(ReturnCode.Success);
  181. }
  182. /// <summary>
  183. /// 更新设备操作记录
  184. /// </summary>
  185. /// <param name="id"></param>
  186. /// <param name="updateModel"></param>
  187. /// <returns></returns>
  188. [HttpPut("UpdateDevOperateRecordAsync/{id}")]
  189. public async Task<ApiResult> UpdateDevOperateRecordAsync(string id, TmtnDevOperateRecordUpdateModel updateModel)
  190. {
  191. if (string.IsNullOrEmpty(id))
  192. {
  193. return new ApiResult(ReturnCode.GeneralError);
  194. }
  195. try
  196. {
  197. await _TmtnDevOperateRecordService.UpdateAsync(id, updateModel);
  198. }
  199. catch (Exception ex)
  200. {
  201. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  202. }
  203. return new ApiResult(ReturnCode.Success);
  204. }
  205. /// <summary>
  206. /// 通过维保id获取维保列表
  207. /// </summary>
  208. /// <param name="devId"></param>
  209. /// <param name="repairId"></param>
  210. /// <returns></returns>
  211. [HttpGet("GetDevOpsRecordItemAsync/{devId}/{repairId}")]
  212. public async Task<ApiResult> GetRepairOrderItemViewAsync(string devId, string repairId)
  213. {
  214. if (string.IsNullOrEmpty(devId))
  215. return new ApiResult(ReturnCode.GeneralError);
  216. if (string.IsNullOrEmpty(repairId))
  217. return new ApiResult(ReturnCode.GeneralError);
  218. try
  219. {
  220. var content = await _TmtnDevOperateRecordService.GetDevOpsRecordItemAsync(devId, repairId);
  221. return new ApiResult<TmtnDevOpsRecordItemDetailViewMode>(content);
  222. }
  223. catch (Exception ex)
  224. {
  225. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  226. }
  227. }
  228. }
  229. }