DevOpsPlanController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model.ViewModel.LGS;
  5. using Ropin.Inspection.Service.MTN.Interface;
  6. using System.Threading.Tasks;
  7. using System;
  8. using Ropin.Inspection.Model.ViewModel.MTN;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Ropin.Inspection.Model;
  11. using Minio.DataModel.Args;
  12. using Minio;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using Ropin.Inspection.Model.ViewModel;
  16. namespace Ropin.Inspection.Api.Controllers.MTN
  17. {
  18. public class DevOpsPlanController : BaseController
  19. {
  20. private readonly IDevOpsPlanService _devOpsPlanService;
  21. public DevOpsPlanController(IDevOpsPlanService devOpsPlanService)
  22. {
  23. _devOpsPlanService = devOpsPlanService;
  24. }
  25. /// <summary>
  26. /// 添加
  27. /// </summary>
  28. /// <param name="devOpsPlanModel"></param>
  29. /// <returns></returns>
  30. [HttpPost("Add")]
  31. public async Task<ApiResult> AddAsync(DevOpsPlanModel devOpsPlanModel)
  32. {
  33. try
  34. {
  35. await _devOpsPlanService.CreateOneAsync(devOpsPlanModel);
  36. }
  37. catch (Exception ex)
  38. {
  39. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  40. }
  41. return new ApiResult(ReturnCode.Success);
  42. }
  43. /// <summary>
  44. /// 分页列表
  45. /// </summary>
  46. /// <param name="input"></param>
  47. /// <returns></returns>
  48. [HttpPost("Page")]
  49. public async Task<ApiResult> PageAsync(DevOpsPlanInput input)
  50. {
  51. try
  52. {
  53. var libraryModels = await _devOpsPlanService.PageAsync(input);
  54. PagesModel<DevOpsPlanModel> pages = new PagesModel<DevOpsPlanModel>(libraryModels, input);
  55. return new ApiResult<PagesModel<DevOpsPlanModel>>(pages);
  56. }
  57. catch (Exception ex)
  58. {
  59. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  60. }
  61. }
  62. [HttpGet("Detail/{id}")]
  63. public async Task<ApiResult> DeatilAsync(string id)
  64. {
  65. var result = await _devOpsPlanService.GetByIdAsync(id);
  66. return new ApiResult<DevOpsPlanModel>(result);
  67. }
  68. /// <summary>
  69. /// 删除
  70. /// </summary>
  71. /// <param name="id"></param>
  72. /// <returns></returns>
  73. [HttpDelete("Delete/{id}")]
  74. public async Task<ApiResult> DeleteReportAsync(string id)
  75. {
  76. try
  77. {
  78. await _devOpsPlanService.DeleteAsync(id);
  79. return new ApiResult(ReturnCode.Success);
  80. }
  81. catch (Exception ex)
  82. {
  83. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  84. }
  85. }
  86. /// <summary>
  87. /// 更新
  88. /// </summary>
  89. /// <param name="devOpsPlanModel"></param>
  90. /// <returns></returns>
  91. [HttpPost("Update")]
  92. public async Task<ApiResult> UpdateAsync(DevOpsPlanModel devOpsPlanModel)
  93. {
  94. var result = await _devOpsPlanService.UpdateOneAsync(devOpsPlanModel);
  95. return new ApiResult<bool>(result >= 1);
  96. }
  97. /// <summary>
  98. /// 添加运维计划设备
  99. /// </summary>
  100. /// <param name="devOpsPlanDeviceModel"></param>
  101. /// <returns></returns>
  102. [HttpPost("AddDevice")]
  103. public async Task<ApiResult> AddDevice(DevOpsPlanDeviceModel devOpsPlanDeviceModel)
  104. {
  105. try
  106. {
  107. await _devOpsPlanService.AddDeviceAsync(devOpsPlanDeviceModel);
  108. }
  109. catch (Exception ex)
  110. {
  111. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  112. }
  113. return new ApiResult(ReturnCode.Success);
  114. }
  115. /// <summary>
  116. /// 设备列表
  117. /// </summary>
  118. /// <param name="imageLibraryModel"></param>
  119. /// <returns></returns>
  120. [HttpGet("DeviceList/{id}")]
  121. public async Task<ApiResult> DeviceListAsync(string id)
  122. {
  123. try
  124. {
  125. var libraryModels = await _devOpsPlanService.DeviceListAsync(id);
  126. //var result = libraryModels
  127. // .GroupBy(x => new
  128. // {
  129. // x.CDevStoreCode,
  130. // x.DevStoreName,
  131. // x.Url,
  132. // x.CNumberCode,
  133. // })
  134. // .Select(x => new DevOpsPlanDeviceGroupModel
  135. // {
  136. // CDevStoreCode = x.Key.CDevStoreCode,
  137. // DevStoreName = x.Key.DevStoreName,
  138. // Url = x.Key.Url,
  139. // CNumberCode = x.Key.CNumberCode,
  140. // })
  141. // .ToList();
  142. //result.ForEach(x =>
  143. //{
  144. // x.Spots = libraryModels.Where(y => y.CDevStoreCode == x.CDevStoreCode).Select(y=>new SpotGroupModel { CName=y.SpotName,CSpotCode=y.CSpotCode}).ToList();
  145. //});
  146. return new ApiResult<List<DevOpsPlanDeviceModel>>(libraryModels);
  147. }
  148. catch (Exception ex)
  149. {
  150. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  151. }
  152. }
  153. /// <summary>
  154. /// 删除设备
  155. /// </summary>
  156. /// <param name="id"></param>
  157. /// <returns></returns>
  158. [HttpDelete("DeleteDeveice/{id}")]
  159. public async Task<ApiResult> DeleteDeviceAsync(string id)
  160. {
  161. try
  162. {
  163. await _devOpsPlanService.DeleteDeviceAsync(id);
  164. return new ApiResult(ReturnCode.Success);
  165. }
  166. catch (Exception ex)
  167. {
  168. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  169. }
  170. }
  171. /// <summary>
  172. /// 删除运维点
  173. /// </summary>
  174. /// <param name="id"></param>
  175. /// <returns></returns>
  176. [HttpDelete("DeleteDeviceSpot/{planId}/{spotId}")]
  177. public async Task<ApiResult> DeleteDeviceSpotAsync(string planId, string spotId)
  178. {
  179. try
  180. {
  181. await _devOpsPlanService.DeleteDeviceSpotAsync(planId, spotId);
  182. return new ApiResult(ReturnCode.Success);
  183. }
  184. catch (Exception ex)
  185. {
  186. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  187. }
  188. }
  189. /// <summary>
  190. /// 添加运维计划设备内容
  191. /// </summary>
  192. /// <param name="devOpsPlanContentModel"></param>
  193. /// <returns></returns>
  194. [HttpPost("AddDeviceContent")]
  195. public async Task<ApiResult> AddDeviceContentAsync(DevOpsPlanContentModel devOpsPlanContentModel)
  196. {
  197. try
  198. {
  199. await _devOpsPlanService.AddDeviceContentAsync(devOpsPlanContentModel);
  200. }
  201. catch (Exception ex)
  202. {
  203. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  204. }
  205. return new ApiResult(ReturnCode.Success);
  206. }
  207. /// <summary>
  208. /// 设备内容列表
  209. /// </summary>
  210. /// <param name="imageLibraryModel"></param>
  211. /// <returns></returns>
  212. [HttpGet("DeviceContentList/{deviceId}/{id}")]
  213. public async Task<ApiResult> DeviceContentListAsync(string deviceId ,string id)
  214. {
  215. try
  216. {
  217. var result = await _devOpsPlanService.DeviceContentListAsync(deviceId,id);
  218. return new ApiResult<List<string>>(result);
  219. }
  220. catch (Exception ex)
  221. {
  222. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  223. }
  224. }
  225. /// <summary>
  226. /// 添加运维计划人员
  227. /// </summary>
  228. /// <param name="devOpsPlanPersonModel"></param>
  229. /// <returns></returns>
  230. [HttpPost("AddPlanPerson")]
  231. public async Task<ApiResult> AddPlanPersonAsync(DevOpsPlanPersonModel devOpsPlanPersonModel)
  232. {
  233. try
  234. {
  235. await _devOpsPlanService.AddPlanPersonAsync(devOpsPlanPersonModel);
  236. }
  237. catch (Exception ex)
  238. {
  239. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  240. }
  241. return new ApiResult(ReturnCode.Success);
  242. }
  243. /// <summary>
  244. /// 计划人员列表
  245. /// </summary>
  246. /// <param name="imageLibraryModel"></param>
  247. /// <returns></returns>
  248. [HttpGet("PlanPersonList/{id}")]
  249. public async Task<ApiResult> PlanPersonListAsync(string id)
  250. {
  251. try
  252. {
  253. var result = await _devOpsPlanService.PlanPersonListAsync(id);
  254. return new ApiResult<List<string>>(result);
  255. }
  256. catch (Exception ex)
  257. {
  258. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  259. }
  260. }
  261. /// <summary>
  262. /// 取消计划
  263. /// </summary>
  264. /// <returns></returns>
  265. [HttpPost("CancelPlan/{id}")]
  266. public async Task<ApiResult> CancelPlan(string id)
  267. {
  268. var result = await _devOpsPlanService.CancelPlan(id);
  269. return new ApiResult<bool>(result);
  270. }
  271. /// <summary>
  272. /// 确认计划
  273. /// </summary>
  274. /// <returns></returns>
  275. [HttpPost("ConfirmPlan/{id}")]
  276. public async Task<ApiResult> ConfirmPlan(string id)
  277. {
  278. var result = await _devOpsPlanService.ConfirmPlan(id);
  279. return new ApiResult<bool>(result);
  280. }
  281. /// <summary>
  282. /// 生成工单
  283. /// </summary>
  284. /// <param name="id"></param>
  285. /// <returns></returns>
  286. [HttpPost("GenerateWorkOrder/{id}")]
  287. public async Task<ApiResult> GenerateWorkOrder(string id)
  288. {
  289. try
  290. {
  291. var result = await _devOpsPlanService.GenerateWorkOrder(id);
  292. return new ApiResult<bool>(result);
  293. }
  294. catch (Exception ex)
  295. {
  296. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  297. }
  298. }
  299. /// <summary>
  300. /// 查看工单
  301. /// </summary>
  302. /// <param name="id"></param>
  303. /// <returns></returns>
  304. [HttpPost("GetDevOps/{id}")]
  305. public async Task<ApiResult> GetDevOps(string id, BaseSearchModel searchModel)
  306. {
  307. List<TmtnDevOpsDetailViewModel> result = await _devOpsPlanService.GetDevOps(id, searchModel);
  308. return new ApiResult<PagesModel<TmtnDevOpsDetailViewModel>>(new PagesModel<TmtnDevOpsDetailViewModel>(result, searchModel));
  309. }
  310. [HttpPost("SetOpsTime")]
  311. public async Task<ApiResult> SetOpsTime(SetOpsModel model)
  312. {
  313. var result = await _devOpsPlanService.SetOpsTime(model);
  314. return new ApiResult<bool>(result);
  315. }
  316. /// <summary>
  317. /// 通过工单id获取巡检点内容.
  318. /// </summary>
  319. [HttpPost("GetSpotContent")]
  320. public async Task<ApiResult> GetSpotContent(GetOpsSpotContentModel model)
  321. {
  322. try
  323. {
  324. if (string.IsNullOrEmpty(model.QrCode) || string.IsNullOrEmpty(model.StoreCode))
  325. {
  326. return new ApiResult(ReturnCode.GeneralError);
  327. }
  328. var spot = await _devOpsPlanService.GetSpotContent(model);
  329. return new ApiResult<TispSpotViewModel>(spot);
  330. }
  331. catch (Exception ex)
  332. {
  333. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  334. }
  335. }
  336. /// <summary>
  337. /// 设置点检工单状态
  338. /// </summary>
  339. /// <param name="model"></param>
  340. /// <returns></returns>
  341. [HttpPost("SetWorkOrderStatus")]
  342. public async Task<ApiResult> SetWorkOrderStatus(GetOpsSpotContentModel model)
  343. {
  344. try
  345. {
  346. await _devOpsPlanService.SetWorkOrderStatus(model);
  347. return new ApiResult<bool>(true);
  348. }
  349. catch (Exception ex)
  350. {
  351. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  352. }
  353. }
  354. }
  355. }