TmtnDevOpsController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Api.Controllers;
  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. using Ropin.Inspection.Model.ViewModel;
  12. using Microsoft.AspNetCore.Authorization;
  13. using Ropin.Inspection.Model.Common;
  14. using static System.Net.Mime.MediaTypeNames;
  15. namespace Ropin.Inspection.Api
  16. {
  17. public class TmtnDevOpsController : BaseController
  18. {
  19. public ILogger<TmtnDevOpsController> _logger { get; }
  20. private readonly ITmtnDevOpsService _TmtnDevOpsService;
  21. private readonly IPushMsgService _pushMsgService;
  22. /// <summary>
  23. /// 构造函数
  24. /// </summary>
  25. /// <param name="TmtnDevOpsService"></param>
  26. /// <param name="pushMsgService"></param>
  27. /// <param name="logger"></param>
  28. public TmtnDevOpsController(ITmtnDevOpsService TmtnDevOpsService, IPushMsgService pushMsgService, ILogger<TmtnDevOpsController> logger)
  29. {
  30. _TmtnDevOpsService = TmtnDevOpsService;
  31. _pushMsgService = pushMsgService;
  32. _logger = logger;
  33. }
  34. /// <summary>
  35. /// 通过id获取运维工单信息
  36. /// </summary>
  37. /// <param name="id"></param>
  38. /// <returns></returns>
  39. [HttpGet("GetDevOpsAsync/{id}")]
  40. public async Task<ApiResult> GetDevOpsAsync(string id)
  41. {
  42. if (string.IsNullOrEmpty(id))
  43. {
  44. return new ApiResult(ReturnCode.GeneralError);
  45. }
  46. try
  47. {
  48. var content = await _TmtnDevOpsService.GetConditionAsync(new TmtnDevOpsSearchModel { C_ID = id });
  49. return new ApiResult<TmtnDevOpsViewModel>(content.FirstOrDefault());
  50. }
  51. catch (Exception ex)
  52. {
  53. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  54. }
  55. }
  56. /// <summary>
  57. /// 获取所有运维工单
  58. /// </summary>
  59. /// <returns></returns>
  60. [HttpGet("GetDevOpssAsync/{name=}")]
  61. public async Task<ApiResult> GetDevOpssAsync(string name)
  62. {
  63. try
  64. {
  65. var contentList = await _TmtnDevOpsService.GetAllAsync();
  66. if (string.IsNullOrWhiteSpace(name))
  67. return new ApiResult<IEnumerable<TmtnDevOpsViewModel>>(contentList);
  68. else
  69. return new ApiResult<IEnumerable<TmtnDevOpsViewModel>>(contentList.Where(x => x.C_Name.Contains(name)));
  70. }
  71. catch (Exception ex)
  72. {
  73. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  74. }
  75. }
  76. /// <summary>
  77. /// 条件查询运维工单
  78. /// </summary>
  79. /// <param name="searchModel"></param>
  80. /// <returns></returns>
  81. [HttpPost("GetDevOpsByAsync")]
  82. public async Task<ApiResult> GetDevOpsByAsync(TmtnDevOpsSearchModel searchModel)
  83. {
  84. if (searchModel == null)
  85. {
  86. return new ApiResult(ReturnCode.ArgsError);
  87. }
  88. searchModel.IsPagination = false;
  89. try
  90. {
  91. var contentList = await _TmtnDevOpsService.GetConditionAsync(searchModel);
  92. return new ApiResult<PagesModel<TmtnDevOpsViewModel>>(new PagesModel<TmtnDevOpsViewModel>(contentList, searchModel));
  93. }
  94. catch (Exception ex)
  95. {
  96. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  97. }
  98. }
  99. /// <summary>
  100. /// 条件查询运维工单列表包含图片
  101. /// </summary>
  102. /// <param name="searchModel"></param>
  103. /// <returns></returns>
  104. [HttpPost("GetDevOpsWithImageAsync/{name=}")]
  105. public async Task<ApiResult> GetDevOpsWithImageAsync(TmtnDevOpsOrderSearchModel searchModel, string name)
  106. {
  107. if (searchModel == null)
  108. {
  109. return new ApiResult(ReturnCode.ArgsError);
  110. }
  111. searchModel.IsPagination = false;
  112. try
  113. {
  114. var contentList = await _TmtnDevOpsService.GetDevOpsWithImageAsync(searchModel);
  115. if (string.IsNullOrWhiteSpace(name))
  116. return new ApiResult<PagesModel<TmtnDevOpsWithImageViewModel>>(new PagesModel<TmtnDevOpsWithImageViewModel>(contentList, searchModel));
  117. else
  118. return new ApiResult<PagesModel<TmtnDevOpsWithImageViewModel>>(new PagesModel<TmtnDevOpsWithImageViewModel>(contentList.Where(x => x.C_Name.Contains(name)), searchModel));
  119. }
  120. catch (Exception ex)
  121. {
  122. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  123. }
  124. }
  125. /// <summary>
  126. /// 获取30天运维完成统计
  127. /// </summary>
  128. /// <param name="storeCode"></param>
  129. /// <returns></returns>
  130. [HttpGet("Get30DaysDevOpsStatisticsAsync/{storeCode}")]
  131. public async Task<ApiResult> GetRecords30DaysStatisticsAsync(string storeCode)
  132. {
  133. if (string.IsNullOrEmpty(storeCode))
  134. {
  135. return new ApiResult(ReturnCode.GeneralError);
  136. }
  137. try
  138. {
  139. var content = await _TmtnDevOpsService.GetRecords30DaysStatisticsAsync(storeCode);
  140. return new ApiResult<TispRecord30DaysStatisticsViewModel>(content);
  141. }
  142. catch (Exception ex)
  143. {
  144. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  145. }
  146. }
  147. /// <summary>
  148. /// 获取30天运维完成统计大屏
  149. /// </summary>
  150. /// <param name="storeCode"></param>
  151. /// <returns></returns>
  152. [HttpGet("GetRecords30DaysStatisticsFullScreenAsync/{storeCode}")]
  153. [AllowAnonymous]
  154. public async Task<IEnumerable<FullScreenRecordItem>> GetRecords30DaysStatisticsFullScreenAsync(string storeCode)
  155. {
  156. if (string.IsNullOrEmpty(storeCode))
  157. {
  158. return null;
  159. }
  160. try
  161. {
  162. var content = await _TmtnDevOpsService.GetRecords30DaysStatisticsFullScreenAsync(storeCode);
  163. return content;
  164. }
  165. catch (Exception ex)
  166. {
  167. return null;
  168. }
  169. }
  170. /// <summary>
  171. /// 创建运维工单
  172. /// </summary>
  173. /// <param name="content"></param>
  174. /// <returns></returns>
  175. [HttpPost("CreateDevOpsAsync")]
  176. public async Task<ApiResult> CreateDevOpsAsync(TmtnDevOpsViewModel content)
  177. {
  178. if (content == null)
  179. {
  180. return new ApiResult(ReturnCode.ArgsError);
  181. }
  182. try
  183. {
  184. var results = await _TmtnDevOpsService.CreateDevOpsAsync(content);
  185. await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel
  186. {
  187. C_DevStoreCode = content.C_DevStoreCode,
  188. C_MsgTypeCode = "MSG_TYPE_002",
  189. Msg = content.C_Name + " "+ content.C_Remark,
  190. Subject = "上报维保: " + content.C_Name,
  191. DevNumber = content.C_DevStoreCode,
  192. DevName = content.C_DevStoreName,
  193. GenerationType = 2,
  194. msgStatus = 0,
  195. }, "设备维保",null, results?.C_ID,"1");
  196. }
  197. catch (Exception ex)
  198. {
  199. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  200. }
  201. return new ApiResult(ReturnCode.Success);
  202. }
  203. /// <summary>
  204. /// 删除运维工单
  205. /// </summary>
  206. /// <param name="id"></param>
  207. /// <returns></returns>
  208. [HttpDelete("DeleteDevOpsAsync/{id}")]
  209. public async Task<ApiResult> DeleteDevOpsAsync(string id)
  210. {
  211. if (string.IsNullOrEmpty(id))
  212. {
  213. return new ApiResult(ReturnCode.GeneralError);
  214. }
  215. try
  216. {
  217. await _TmtnDevOpsService.DeleteAsync(id);
  218. }
  219. catch (Exception ex)
  220. {
  221. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  222. }
  223. return new ApiResult(ReturnCode.Success);
  224. }
  225. /// <summary>
  226. /// 更新运维工单
  227. /// </summary>
  228. /// <param name="id"></param>
  229. /// <param name="updateModel"></param>
  230. /// <returns></returns>
  231. [HttpPut("UpdateDevOpsAsync/{id}")]
  232. public async Task<ApiResult> UpdateDevOpsAsync(string id, TmtnDevOpsUpdateModel updateModel)
  233. {
  234. if (string.IsNullOrEmpty(id))
  235. {
  236. return new ApiResult(ReturnCode.GeneralError);
  237. }
  238. try
  239. {
  240. await _TmtnDevOpsService.UpdateAsync(id, updateModel);
  241. await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel
  242. {
  243. C_DevStoreCode = updateModel.C_DevStoreCode,
  244. C_MsgTypeCode = "MSG_TYPE_009",
  245. Msg = updateModel.C_Name + " " + updateModel.C_Remark,
  246. Subject = updateModel.C_Status == "5"? "维保取消,设备名:": "维保确认,设备名:" + updateModel.C_DevStoreName,
  247. DevNumber = updateModel.C_DevStoreCode,
  248. DevName = updateModel.C_DevStoreName,
  249. GenerationType = 2,
  250. msgStatus = 0,
  251. }, "设备维保",null,id,updateModel.C_Status);
  252. }
  253. catch (Exception ex)
  254. {
  255. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  256. }
  257. return new ApiResult(ReturnCode.Success);
  258. }
  259. /// <summary>
  260. /// 通过设备ID取运维内容及状态,大屏
  261. /// </summary>
  262. /// <param name="devStoreCode"></param>
  263. /// <returns></returns>
  264. [HttpPost("GetDevOpsFullScreenByDevIdAsync")]
  265. [AllowAnonymous]
  266. public async Task<ApiResult> GetDevOpsFullScreenByDevIdAsync(DevOpsItemSearchModel searchModel)
  267. {
  268. if (searchModel == null)
  269. {
  270. return new ApiResult(ReturnCode.ArgsError);
  271. }
  272. try
  273. {
  274. var opslist = await _TmtnDevOpsService.GetDevOpsFullScreenByDevIdAsync(searchModel);
  275. var repairList = await _TmtnDevOpsService.GetDevRepairFullScreenByDevIdAsync(searchModel);
  276. var recordList = await _TmtnDevOpsService.GetISPRecordAsync(searchModel);
  277. IEnumerable<DevOpsFullScreenRecord> list;
  278. if (opslist == null)
  279. opslist = new List<DevOpsFullScreenRecord>();
  280. if (repairList == null)
  281. repairList = new List<DevOpsFullScreenRecord>();
  282. if (recordList == null)
  283. recordList = new List<DevOpsFullScreenRecord>();
  284. list = opslist?.Concat(repairList).Concat(recordList).ToList().OrderByDescending(o => o.RecordTime);
  285. if (!list.Any())
  286. {
  287. searchModel.TotalCount = 0;
  288. return new ApiResult<PagesModel<DevOpsFullScreenRecord>>(new PagesModel<DevOpsFullScreenRecord>(list, searchModel));
  289. }
  290. searchModel.TotalCount = list.Count();
  291. return new ApiResult<PagesModel<DevOpsFullScreenRecord>>(new PagesModel<DevOpsFullScreenRecord>(searchModel.IsPagination ? list.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : list, searchModel));
  292. }
  293. catch (Exception ex)
  294. {
  295. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  296. }
  297. }
  298. /// <summary>
  299. /// 通过设备ID取运维内容及状态统计,大屏
  300. /// </summary>
  301. /// <param name="devStoreCode"></param>
  302. /// <returns></returns>
  303. [HttpPost("GetDevOpsCountFullScreenByDevIdAsync")]
  304. [AllowAnonymous]
  305. public async Task<ApiResult> GetDevOpsCountFullScreenByDevIdAsync(DevOpsItemSearchModel searchModel)
  306. {
  307. if (searchModel == null)
  308. {
  309. return new ApiResult(ReturnCode.ArgsError);
  310. }
  311. try
  312. {
  313. var content = await _TmtnDevOpsService.GetDevOpsCountFullScreenByDevIdAsync(searchModel);
  314. //content.DevOpsRecordItem.Where(x => x.C_Status == "1").Count();
  315. return new ApiResult<RepairStatistics>(content);
  316. }
  317. catch (Exception ex)
  318. {
  319. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  320. }
  321. }
  322. /// <summary>
  323. /// 通过设备ID取维修内容及状态统计,大屏
  324. /// </summary>
  325. /// <param name="devStoreCode"></param>
  326. /// <returns></returns>
  327. [HttpPost("GetDevRepairCountFullScreenByDevIdAsync")]
  328. [AllowAnonymous]
  329. public async Task<ApiResult> GetDevRepairCountFullScreenByDevIdAsync(DevOpsItemSearchModel searchModel)
  330. {
  331. if (searchModel == null)
  332. {
  333. return new ApiResult(ReturnCode.ArgsError);
  334. }
  335. try
  336. {
  337. var content = await _TmtnDevOpsService.GetDevRepairCountFullScreenByDevIdAsync(searchModel);
  338. //content.DevOpsRecordItem.Where(x => x.C_Status == "1").Count();
  339. return new ApiResult<RepairStatistics>(content);
  340. }
  341. catch (Exception ex)
  342. {
  343. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  344. }
  345. }
  346. }
  347. }