TispRecordItemController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Newtonsoft.Json;
  5. using NPOI.HPSF;
  6. using NPOI.SS.UserModel;
  7. using NPOI.Util;
  8. using NPOI.XWPF.UserModel;
  9. using Ropin.Inspection.Api.Common;
  10. using Ropin.Inspection.Common.Helper;
  11. using Ropin.Inspection.Model;
  12. using Ropin.Inspection.Model.Common;
  13. using Ropin.Inspection.Model.SearchModel;
  14. using Ropin.Inspection.Model.ViewModel;
  15. using Ropin.Inspection.Service;
  16. using Ropin.Inspection.Service.Interface;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.IO;
  20. using System.IO.Compression;
  21. using System.Linq;
  22. using System.Threading.Tasks;
  23. namespace Ropin.Inspection.Api.Controllers
  24. {
  25. /// <summary>
  26. /// 巡检详细记录
  27. /// </summary>
  28. public class TispRecordItemController : BaseController
  29. {
  30. public ILogger<TispRecordItemController> _logger { get; }
  31. private readonly ITispRecordItemService _tispRecordItemService;
  32. private readonly ITispRecordImageService _tispRecordImageService;
  33. private readonly IReportService _reportService;
  34. /// <summary>
  35. ///
  36. /// </summary>
  37. /// <param name="tispRecordItemService"></param>
  38. /// <param name="tispRecordImageService"></param>
  39. /// <param name="logger"></param>
  40. public TispRecordItemController(ITispRecordItemService tispRecordItemService, IReportService reportService, ITispRecordImageService tispRecordImageService, ILogger<TispRecordItemController> logger)
  41. {
  42. _tispRecordItemService = tispRecordItemService;
  43. _tispRecordImageService = tispRecordImageService;
  44. _reportService = reportService;
  45. _logger = logger;
  46. }
  47. /// <summary>
  48. /// 通过巡检记录ID获取巡检信息
  49. /// </summary>
  50. /// <param name="recordId"></param>
  51. /// <returns></returns>
  52. [HttpGet("GetRecordItemsAsync/{recordId}")]
  53. public async Task<ApiResult> GetRecordItemsAsync(Guid recordId)
  54. {
  55. if (Guid.Empty == recordId)
  56. {
  57. return new ApiResult(ReturnCode.GeneralError);
  58. }
  59. try
  60. {
  61. IEnumerable<TispRecordItemDetailViewModel> recordItems = await _tispRecordItemService.GetRecordsConditionAsync(recordId);
  62. return new ApiResult<IEnumerable<TispRecordItemDetailViewModel>>(recordItems);
  63. }
  64. catch (Exception ex)
  65. {
  66. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  67. }
  68. }
  69. /// <summary>
  70. /// 通过巡检记录ID获取巡检详细信息,通过内容分组
  71. /// </summary>
  72. /// <param name="recordId"></param>
  73. /// <returns></returns>
  74. [HttpGet("GetRecordItemsByRecordIdAsync/{recordId}")]
  75. [AllowAnonymous]
  76. public async Task<ApiResult> GetRecordItemsByRecordIdAsync(Guid recordId)
  77. {
  78. if (Guid.Empty == recordId)
  79. {
  80. return new ApiResult(ReturnCode.ArgsError);
  81. }
  82. try
  83. {
  84. List<List<TispRecordItemDetailViewModel>> recordItems = await _tispRecordItemService.GetRecordItemsByRecordIdAsync(recordId);
  85. return new ApiResult<List<List<TispRecordItemDetailViewModel>>>(recordItems);
  86. }
  87. catch (Exception ex)
  88. {
  89. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  90. }
  91. }
  92. /// <summary>
  93. /// 通过详细记录ID获取巡检信息
  94. /// </summary>
  95. /// <param name="id"></param>
  96. /// <returns></returns>
  97. [HttpGet("GetRecordItemByIdAsync/{id}")]
  98. public async Task<ApiResult> GetRecordItemByIdAsync(Guid id)
  99. {
  100. if (Guid.Empty == id)
  101. {
  102. return new ApiResult(ReturnCode.GeneralError);
  103. }
  104. try
  105. {
  106. IEnumerable<TispRecordItemDetailViewModel> recordItems = await _tispRecordItemService.GetRecordItemByIdAsync(id);
  107. return new ApiResult<IEnumerable<TispRecordItemDetailViewModel>>(recordItems);
  108. }
  109. catch (Exception ex)
  110. {
  111. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  112. }
  113. }
  114. /// <summary>
  115. /// 获取异常上报记录
  116. /// </summary>
  117. /// <param name="searchModel"></param>
  118. /// <returns></returns>
  119. [HttpPost("GetAlarmRecordsAsync")]
  120. public async Task<ApiResult> GetAlarmRecordsAsync(TispRecordAlarmSearchModel searchModel)
  121. {
  122. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  123. {
  124. return new ApiResult(ReturnCode.GeneralError);
  125. }
  126. try
  127. {
  128. IEnumerable<TispRecordItemDetailViewModel> recordItems = await _tispRecordItemService.GetAlarmRecordsAsync(searchModel);
  129. return new ApiResult<PagesModel<TispRecordItemDetailViewModel>>(new PagesModel<TispRecordItemDetailViewModel>(recordItems?.ToList(), searchModel));
  130. }
  131. catch (Exception ex)
  132. {
  133. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  134. }
  135. }
  136. /// <summary>
  137. /// 后台管理平台,获取异常上报记录
  138. /// </summary>
  139. /// <param name="searchModel"></param>
  140. /// <returns></returns>
  141. [HttpPost("GetAlarmRecordListAsync")]
  142. public async Task<ApiResult> GetAlarmRecordListAsync(TispRecordAlarmSearchModel searchModel)
  143. {
  144. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  145. {
  146. return new ApiResult(ReturnCode.GeneralError);
  147. }
  148. try
  149. {
  150. IEnumerable<TispRecordItemDetailViewModel> recordItems = await _tispRecordItemService.GetAlarmRecordListAsync(searchModel);
  151. return new ApiResult<PagesModel<TispRecordItemDetailViewModel>>(new PagesModel<TispRecordItemDetailViewModel>(recordItems?.ToList(), searchModel));
  152. }
  153. catch (Exception ex)
  154. {
  155. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  156. }
  157. }
  158. /// <summary>
  159. /// 扫巡检点二维码获取异常记录
  160. /// </summary>
  161. /// <param name="QRCode"></param>
  162. /// <param name="storeCode"></param>
  163. /// <returns></returns>
  164. [HttpGet("GetAlarmRecordsByQRCodeAsync/{QRCode}/{storeCode}")]
  165. //[AllowAnonymous]
  166. public async Task<ApiResult> GetAlarmRecordsByQRCodeAsync(string QRCode,string storeCode)
  167. {
  168. try
  169. {
  170. if (string.IsNullOrEmpty(QRCode)|| string.IsNullOrEmpty(storeCode))
  171. {
  172. return new ApiResult(ReturnCode.GeneralError);
  173. }
  174. IEnumerable<TispRecordItemAlarmDetailViewModel> recordItems = await _tispRecordItemService.GetAlarmRecordsByQRCodeAsync(QRCode, storeCode);
  175. return new ApiResult<IEnumerable<TispRecordItemAlarmDetailViewModel>>(recordItems?.ToList());
  176. }
  177. catch (Exception ex)
  178. {
  179. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  180. }
  181. }
  182. /// <summary>
  183. /// 根据巡检点二维码获取最新巡检记录
  184. /// </summary>
  185. /// <param name="QRCode"></param>
  186. /// <param name="storeCode"></param>
  187. /// <returns></returns>
  188. [HttpGet("GetNewRecordByQRCodeAsync/{QRCode}/{storeCode}")]
  189. public async Task<ApiResult> GetNewRecordByQRCodeAsync(string QRCode,string storeCode)
  190. {
  191. try
  192. {
  193. if (string.IsNullOrEmpty(QRCode))
  194. {
  195. return new ApiResult(ReturnCode.GeneralError);
  196. }
  197. IEnumerable<TispRecordItemAlarmDetailViewModel> recordItems = await _tispRecordItemService.GetNewRecordByQRCodeAsync(QRCode, storeCode);
  198. return new ApiResult<IEnumerable<TispRecordItemAlarmDetailViewModel>>(recordItems?.ToList());
  199. }
  200. catch (Exception ex)
  201. {
  202. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  203. }
  204. }
  205. /// <summary>
  206. /// 获取异常上报记录数
  207. /// </summary>
  208. /// <param name="searchModel"></param>
  209. /// <returns></returns>
  210. [HttpGet("GetAlarmRecordsCountAsync")]
  211. public async Task<ApiResult> GetAlarmRecordsCountAsync([FromQuery] TispRecordAlarmSearchModel searchModel)
  212. {
  213. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  214. {
  215. return new ApiResult(ReturnCode.GeneralError);
  216. }
  217. try
  218. {
  219. int recordCount = await _tispRecordItemService.GetAlarmRecordsCountAsync(searchModel);
  220. return new ApiResult<int>(recordCount);
  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("GetAlarmRecoveryRecordsAsync")]
  233. [AllowAnonymous]
  234. public async Task<ApiResult> GetAlarmRecoveryRecordsAsync(TispRecordAlarmSearchModel searchModel)
  235. {
  236. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  237. {
  238. return new ApiResult(ReturnCode.GeneralError);
  239. }
  240. try
  241. {
  242. IEnumerable<TispRecordItemDetailViewModel> recordItems = await _tispRecordItemService.GetAlarmRecoveryRecordsAsync(searchModel);
  243. //if (null == recordItems)
  244. // return new ApiResult<IEnumerable<TispRecordItemDetailViewModel>>(recordItems);
  245. //else
  246. return new ApiResult<PagesModel<TispRecordItemDetailViewModel>>(new PagesModel<TispRecordItemDetailViewModel>(recordItems?.ToList(), searchModel));
  247. }
  248. catch (Exception ex)
  249. {
  250. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  251. }
  252. }
  253. /// <summary>
  254. /// 获取异常处理记录数
  255. /// </summary>
  256. /// <param name="searchModel"></param>
  257. /// <returns></returns>
  258. [HttpGet("GetAlarmRecoveryRecordsCountAsync")]
  259. public async Task<ApiResult> GetAlarmRecoveryRecordsCountAsync([FromQuery] TispRecordAlarmSearchModel searchModel)
  260. {
  261. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  262. {
  263. return new ApiResult(ReturnCode.GeneralError);
  264. }
  265. try
  266. {
  267. int recordCount = await _tispRecordItemService.GetAlarmRecoveryRecordsCountAsync(searchModel);
  268. return new ApiResult<int>(recordCount);
  269. }
  270. catch (Exception ex)
  271. {
  272. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  273. }
  274. }
  275. /// <summary>
  276. /// 巡检异常恢复处理
  277. /// </summary>
  278. /// <param name="recordItemId"></param>
  279. /// <param name="updateModel"></param>
  280. /// <returns></returns>
  281. [HttpPut("RecoveryRecordItemAlarmAsync/{recordItemId}")]
  282. public async Task<ApiResult> RecoveryRecordItemAlarmAsync(Guid recordItemId, TispRecoveryRecordItemAlarmUpdateViewModel updateModel)
  283. {
  284. if (Guid.Empty == recordItemId)
  285. {
  286. return new ApiResult(ReturnCode.GeneralError);
  287. }
  288. try
  289. {
  290. await _tispRecordItemService.RecoveryRecordItemAlarmAsync(recordItemId, updateModel);
  291. }
  292. catch (Exception ex)
  293. {
  294. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  295. }
  296. return new ApiResult(ReturnCode.Success);
  297. }
  298. /// <summary>
  299. /// 巡检异常确认处理
  300. /// </summary>
  301. /// <param name="recordItemId"></param>
  302. /// <param name="updateModel"></param>
  303. /// <returns></returns>
  304. [HttpPut("ConfirmRecordItemAlarmAsync/{recordItemId}")]
  305. public async Task<ApiResult> ConfirmRecordItemAlarmAsync(Guid recordItemId, TispRecoveryRecordItemAlarmUpdateViewModel updateModel)
  306. {
  307. if (Guid.Empty == recordItemId)
  308. {
  309. return new ApiResult(ReturnCode.GeneralError);
  310. }
  311. try
  312. {
  313. await _tispRecordItemService.ConfirmRecordItemAlarmAsync(recordItemId, updateModel);
  314. }
  315. catch (Exception ex)
  316. {
  317. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  318. }
  319. return new ApiResult(ReturnCode.Success);
  320. }
  321. /// <summary>
  322. /// 巡检异常确认处理
  323. /// </summary>
  324. /// <param name="updateModel"></param>
  325. /// <returns></returns>
  326. [HttpPost("ConfirmAlarmAsync")]
  327. public async Task<ApiResult> ConfirmAlarmAsync(TispRecoveryAlarmUpdateViewModel updateModel)
  328. {
  329. if (string.IsNullOrEmpty(updateModel.recordItemId))
  330. {
  331. return new ApiResult(ReturnCode.GeneralError);
  332. }
  333. Guid id = Guid.Parse(updateModel.recordItemId);
  334. try
  335. {
  336. await _tispRecordItemService.ConfirmRecordItemAlarmAsync(id, new TispRecoveryRecordItemAlarmUpdateViewModel { C_Remark = updateModel.C_Remark,FilePaths = updateModel.FilePaths });
  337. }
  338. catch (Exception ex)
  339. {
  340. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  341. }
  342. return new ApiResult(ReturnCode.Success);
  343. }
  344. /// <summary>
  345. /// 巡检异常取消处理
  346. /// </summary>
  347. /// <param name="recordItemId"></param>
  348. /// <param name="updateModel"></param>
  349. /// <returns></returns>
  350. [HttpPut("CancelRecordItemAlarmAsync/{recordItemId}")]
  351. public async Task<ApiResult> CancelRecordItemAlarmAsync(Guid recordItemId, TispRecoveryRecordItemAlarmUpdateViewModel updateModel)
  352. {
  353. if (Guid.Empty == recordItemId)
  354. {
  355. return new ApiResult(ReturnCode.GeneralError);
  356. }
  357. try
  358. {
  359. await _tispRecordItemService.CancelRecordItemAlarmAsync(recordItemId, updateModel);
  360. }
  361. catch (Exception ex)
  362. {
  363. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  364. }
  365. return new ApiResult(ReturnCode.Success);
  366. }
  367. /// <summary>
  368. /// 巡检记录修改
  369. /// </summary>
  370. /// <param name="recordItemId"></param>
  371. /// <param name="updateModel"></param>
  372. /// <returns></returns>
  373. [HttpPut("UpdateRecordItemAsync/{recordItemId}")]
  374. public async Task<ApiResult> UpdateRecordItemAsync(Guid recordItemId, TispRecordItemUpdateViewModel updateModel)
  375. {
  376. if (Guid.Empty == recordItemId)
  377. {
  378. return new ApiResult(ReturnCode.GeneralError);
  379. }
  380. try
  381. {
  382. await _tispRecordItemService.UpdateRecordItemAsync(recordItemId, updateModel);
  383. }
  384. catch (Exception ex)
  385. {
  386. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  387. }
  388. return new ApiResult(ReturnCode.Success);
  389. }
  390. /// <summary>
  391. /// 消防设施每周检查记录
  392. /// </summary>
  393. /// <param name="start"></param>
  394. /// <param name="end"></param>
  395. /// <returns></returns>
  396. [HttpGet("GetFireFightingFacilitiesAsync")]
  397. public async Task<ApiResult> GetFireFightingFacilitiesAsync(DateTime start, DateTime end, string storeCode)
  398. {
  399. if (start.Year < 2010 || end.Year < 2010 || string.IsNullOrEmpty(storeCode))
  400. {
  401. return new ApiResult(ReturnCode.GeneralError);
  402. }
  403. try
  404. {
  405. object o = await _tispRecordItemService.GetFireFightingFacilitiesAsync(start, end.AddDays(1), storeCode);
  406. ReportViewModel reportViewModel = new ReportViewModel
  407. {
  408. G_ID = Guid.NewGuid(),
  409. C_StoreCode = storeCode,
  410. I_Type = 3,
  411. C_GroupName = "设备设施检查",
  412. C_Name = "设备设施点检记录" + "(" + DateTime.Now.AddDays(1).ToString("yyyy/MM/dd HH:mm") + ")",
  413. C_Status = "1",
  414. D_CreateTime = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy/MM/dd HH:mm")),
  415. D_Start = start,
  416. D_End = end,
  417. C_Data = JsonConvert.SerializeObject(o)
  418. };
  419. await _reportService.CreateOneAsync(reportViewModel);
  420. return new ApiResult<object>(o);
  421. }
  422. catch (Exception ex)
  423. {
  424. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  425. }
  426. }
  427. /// <summary>
  428. /// 防火巡检记录表
  429. /// </summary>
  430. /// <param name="start"></param>
  431. /// <param name="end"></param>
  432. /// <returns></returns>
  433. [HttpGet("GetFireInspectionRecordAsync")]
  434. public async Task<ApiResult> GetFireInspectionRecordAsync(DateTime start, DateTime end, string storeCode)
  435. {
  436. if (start.Year < 2010 || end.Year < 2010 || string.IsNullOrEmpty(storeCode))
  437. {
  438. return new ApiResult(ReturnCode.GeneralError);
  439. }
  440. try
  441. {
  442. var work = this.ActualWork(start, end.AddDays(1), storeCode);
  443. var timeout = this.Timeout(20000);
  444. object o = null;
  445. var finishedTask = await Task.WhenAny(timeout, work);
  446. if (finishedTask == timeout)
  447. {
  448. return new ApiResult(ReturnCode.GeneralError, "请求超时");
  449. }
  450. else
  451. {
  452. o = work.Result;
  453. }
  454. return new ApiResult<object>(o);
  455. }
  456. catch (Exception ex)
  457. {
  458. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  459. }
  460. }
  461. private async Task<object> ActualWork(DateTime start, DateTime end, string storeCode)
  462. {
  463. return await _tispRecordItemService.GetFireInspectionRecordAsync(start, end, storeCode);
  464. }
  465. private async Task Timeout(int timeoutValue)
  466. {
  467. await Task.Delay(timeoutValue);
  468. }
  469. /// <summary>
  470. /// 防火检查记录(周)
  471. /// </summary>
  472. /// <param name="start"></param>
  473. /// <param name="end"></param>
  474. /// <returns></returns>
  475. [HttpGet("GetFirePreventionWeekRecordAsync")]
  476. public async Task<ApiResult> GetFirePreventionWeekRecordAsync(DateTime start, DateTime end, string storeCode)
  477. {
  478. if (start.Year < 2010 || end.Year < 2010 || string.IsNullOrEmpty(storeCode))
  479. {
  480. return new ApiResult(ReturnCode.GeneralError);
  481. }
  482. try
  483. {
  484. object o = await _tispRecordItemService.GetFirePreventionWeekRecordAsync(start, end.AddDays(1), storeCode);
  485. return new ApiResult<object>(o);
  486. }
  487. catch (Exception ex)
  488. {
  489. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  490. }
  491. }
  492. /// <summary>
  493. /// 隐患整改验收单
  494. /// </summary>
  495. /// <param name="start"></param>
  496. /// <param name="end"></param>
  497. /// <returns></returns>
  498. [HttpGet("HiddenDangerRectificationAcceptanceForm")]
  499. public async Task<ApiResult> HiddenDangerRectificationAcceptanceForm(DateTime start, DateTime end,string storeCode)
  500. {
  501. if (start.Year < 2010 || end.Year < 2010 || string.IsNullOrEmpty(storeCode))
  502. {
  503. return new ApiResult(ReturnCode.GeneralError);
  504. }
  505. try
  506. {
  507. object o = await _tispRecordItemService.HiddenDangerRectificationAcceptanceForm(start, end.AddDays(1), storeCode);
  508. return new ApiResult<object>(o);
  509. }
  510. catch (Exception ex)
  511. {
  512. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  513. }
  514. }
  515. /// <summary>
  516. /// 发送点检邮件【大屏-详情】
  517. /// </summary>
  518. /// <param name="searchModel"></param>
  519. /// <returns></returns>
  520. [HttpPost("SendEmilOrderItem")]
  521. [AllowAnonymous]
  522. public async Task<ApiResult> SendEmilOrderItem(SendRecordToEmailModel searchModel)
  523. {
  524. try
  525. {
  526. if (searchModel == null && searchModel.C_ID!=Guid.Empty)
  527. {
  528. return new ApiResult(ReturnCode.ArgsError, "请输入参数");
  529. }
  530. List<List<TispRecordItemDetailViewModel>> recordItems = await _tispRecordItemService.GetRecordItemsByRecordIdAsync(searchModel.C_ID);
  531. string zip = @"wwwroot\\ZipFile";
  532. if (!System.IO.Directory.Exists(zip))
  533. {
  534. Directory.CreateDirectory(zip);
  535. }
  536. string zipPaht = zip + $"\\{searchModel.C_ID}点检详情下载.zip";
  537. if (recordItems.Count > 0)
  538. {
  539. XWPFDocument doc = new XWPFDocument();
  540. var paragraph = doc.CreateParagraph();
  541. var run1 = paragraph.CreateRun();
  542. run1.FontSize = 18;
  543. int serialNum = 1;
  544. run1.SetText(searchModel.DevName);
  545. foreach (var itemList in recordItems)
  546. {
  547. if (itemList==null)
  548. {
  549. continue;
  550. }
  551. var p0 = doc.CreateParagraph();
  552. var run0 = p0.CreateRun();
  553. run0.FontSize = 16;
  554. run0.SetText(" " + serialNum.ToString() + "、" + itemList.FirstOrDefault()?.C_Name);
  555. int serialNum1 = 1;
  556. foreach (var item in itemList)
  557. {
  558. if (item == null) { continue; }
  559. var p1 = doc.CreateParagraph();
  560. var run = p1.CreateRun();
  561. run.FontSize = 14;
  562. string status = string.Empty;
  563. //1 = 正常;0 = 异常;2 = 恢复;3 = 确认异常;4 = 取消异常
  564. switch (item.C_Status)
  565. {
  566. case "1":
  567. status = "正常";
  568. break;
  569. case "2":
  570. status = "异常已处理";
  571. break;
  572. case "3":
  573. status = "确认异常";
  574. break;
  575. case "4":
  576. status = "取消异常";
  577. break;
  578. case "0":
  579. status = "巡检异常";
  580. break;
  581. }
  582. run.SetText(" " + serialNum.ToString() + "." + serialNum1.ToString());
  583. run.AddCarriageReturn();
  584. run.AppendText(" 操作时间:" + item.D_CreateOn.ToString("yyyy-MM-dd HH:mm"));
  585. run.AddCarriageReturn();
  586. run.AppendText(" 状态:" + status);
  587. run.AddCarriageReturn();
  588. run.AppendText(" 处理人员:" + item.ReportUserName);
  589. if (item.RecordImageList != null && item.RecordImageList.Count() > 0)
  590. {
  591. run.AddCarriageReturn();
  592. run.AppendText(" 现场拍照:");
  593. foreach (var path in item.RecordImageList)
  594. {
  595. string pathFile = path.C_ImageURL;
  596. if (pathFile != null)
  597. {
  598. if (pathFile[0].ToString() == @"/")
  599. {
  600. pathFile = pathFile.Substring(1);
  601. }
  602. if (!System.IO.File.Exists(pathFile))
  603. {
  604. pathFile = @"wwwroot/error.png";
  605. }
  606. FileStream fileStream = new FileStream(pathFile, FileMode.Open, FileAccess.Read);
  607. run.AddCarriageReturn();
  608. run.AddPicture(fileStream, 6, pathFile, Units.ToEMU(100), Units.ToEMU(100));
  609. }
  610. }
  611. }
  612. run.AddCarriageReturn();
  613. run.AppendText(" 现场描述:" + item.C_Remark);
  614. serialNum1++;
  615. }
  616. serialNum++;
  617. }
  618. using (var zipFile = new FileStream(zipPaht, FileMode.Create))
  619. {
  620. using (var memoryStream = new NpoiMemoryStream())
  621. {
  622. doc.Write(memoryStream);
  623. byte[] excelData = memoryStream.ToArray();
  624. using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
  625. {
  626. archive.CreateEntry($"{searchModel.C_ID}点检详情.docx").Open().Write(excelData, 0, excelData.Length);
  627. }
  628. }
  629. }
  630. }
  631. string emailName = $"{searchModel.DevName}-点检详情";
  632. using (var zipFile1 = new FileStream(zipPaht, FileMode.Open))
  633. {
  634. await Task.Run(() =>
  635. {
  636. EmailHelper.SendEmail(searchModel.Mails, emailName, "", "详情见附件", $"{emailName}.zip", "application/zip", zipFile1);
  637. });
  638. }
  639. System.IO.File.Delete(zipPaht);
  640. return new ApiResult(ReturnCode.Success);
  641. }
  642. catch (Exception ex)
  643. {
  644. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  645. }
  646. }
  647. }
  648. }