TispRecordController.cs 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Hosting.Internal;
  6. using Microsoft.Extensions.Logging;
  7. using NPOI.SS.UserModel;
  8. using NPOI.Util;
  9. using NPOI.XSSF.UserModel;
  10. using NPOI.XWPF.UserModel;
  11. using Ropin.Inspection.Api.Common;
  12. using Ropin.Inspection.Common.Helper;
  13. using Ropin.Inspection.Model;
  14. using Ropin.Inspection.Model.Common;
  15. using Ropin.Inspection.Model.SearchModel;
  16. using Ropin.Inspection.Model.ViewModel;
  17. using Ropin.Inspection.Service;
  18. using Ropin.Inspection.Service.Interface;
  19. using System;
  20. using System.Collections;
  21. using System.Collections.Generic;
  22. using System.IO;
  23. using System.IO.Compression;
  24. using System.Linq;
  25. using System.Threading.Tasks;
  26. namespace Ropin.Inspection.Api.Controllers
  27. {
  28. /// <summary>
  29. /// 巡检记录
  30. /// </summary>
  31. public class TispRecordController : BaseController
  32. {
  33. public ILogger<TispRecordController> _logger { get; }
  34. private readonly ITispRecordService _tispRecordService;
  35. private readonly ITispRecordImageService _tispRecordImageService;
  36. //private readonly IWebHostEnvironment _hostingEnvironment;
  37. private readonly IWebHostEnvironment _hostingEnvironment;
  38. private readonly IPushMsgService _pushMsgService;
  39. private readonly ITispRecordItemService _tispRecordItemService;
  40. private readonly ITpntStoreService _TpntStoreService;
  41. /// <summary>
  42. /// 构造函数
  43. /// </summary>
  44. /// <param name="tispRecordService"></param>
  45. /// <param name="tispRecordImageService"></param>
  46. /// <param name="hostingEnvironment"></param>
  47. /// <param name="logger"></param>
  48. public TispRecordController(ITispRecordService tispRecordService, IPushMsgService pushMsgService, ITispRecordImageService tispRecordImageService, IWebHostEnvironment hostingEnvironment, ILogger<TispRecordController> logger, ITispRecordItemService tispRecordItemService,ITpntStoreService TpntStoreService)
  49. {
  50. _tispRecordService = tispRecordService;
  51. _tispRecordImageService = tispRecordImageService;
  52. _hostingEnvironment = hostingEnvironment;
  53. _logger = logger;
  54. _pushMsgService = pushMsgService;
  55. _tispRecordItemService = tispRecordItemService;
  56. _TpntStoreService = TpntStoreService;
  57. }
  58. /// <summary>
  59. /// 通过ID获取巡检点信息
  60. /// </summary>
  61. /// <param name="id"></param>
  62. /// <returns></returns>
  63. [HttpGet("GetRecordAsync/{id}")]
  64. public async Task<ApiResult> GetRecordAsync(Guid id)
  65. {
  66. if (Guid.Empty == id)
  67. {
  68. return new ApiResult(ReturnCode.ArgsError);
  69. }
  70. try
  71. {
  72. TispRecordViewModel record = await _tispRecordService.GetByIdAsync(id);
  73. return new ApiResult<TispRecordViewModel>(record);
  74. }
  75. catch (Exception ex)
  76. {
  77. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  78. }
  79. }
  80. ///// <summary>
  81. ///// 获取所有巡检
  82. ///// </summary>
  83. ///// <returns></returns>
  84. //[HttpGet("GetRecordsAsync")]
  85. //public async Task<ApiResult> GetRecordsAsync()
  86. //{
  87. // try
  88. // {
  89. // var recordList = await _tispRecordService.GetAllAsync();
  90. // return new ApiResult<IEnumerable<TispRecordViewModel>>(recordList);
  91. // }
  92. // catch (Exception ex)
  93. // {
  94. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  95. // }
  96. //}
  97. /// <summary>
  98. /// 条件获取巡检记录
  99. /// </summary>
  100. /// <param name="searchModel"></param>
  101. /// <returns></returns>
  102. [HttpPost("GetRecordsConditionAsync")]
  103. public async Task<ApiResult> GetRecordsConditionAsync(TispRecordSearchModel searchModel)
  104. {
  105. if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode))
  106. {
  107. return new ApiResult(ReturnCode.ArgsError);
  108. }
  109. try
  110. {
  111. var recordList = await _tispRecordService.GetRecordsConditionAsync(searchModel);
  112. return new ApiResult<PagesModel<TispRecordDetailViewModel>>(new PagesModel<TispRecordDetailViewModel>(recordList?.ToList(), searchModel));
  113. }
  114. catch (Exception ex)
  115. {
  116. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  117. }
  118. }
  119. /// <summary>
  120. /// 创建巡检记录
  121. /// </summary>
  122. /// <param name="record"></param>
  123. /// <returns></returns>
  124. [Route("CreateRecordAsync")]
  125. [HttpPost]
  126. public async Task<ApiResult> CreateRecordAsync(TispRecordCreateViewModel record)
  127. {
  128. if (record == null || record.TispRecordItemList == null || !record.TispRecordItemList.Any())
  129. {
  130. return new ApiResult(ReturnCode.ArgsError);
  131. }
  132. try
  133. {
  134. await _tispRecordService.CreateRecordAsync(record);
  135. if (record.TispRecordItemList.Where(i => i.C_Status == "0").Any())
  136. {
  137. //没有设备ID不能发消息
  138. //await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel
  139. //{
  140. // C_DevStoreCode = "",
  141. // C_MsgTypeCode = "MSG_TYPE_002",
  142. // Msg = record.TispRecordItemList.Where(i => i.C_Status == "0").Select(x => x.C_InspectionContent).First(),
  143. // Subject = "点检异常",
  144. // DevNumber = record.C_SpotCode.ToString(),
  145. // DevName = "未知",
  146. // GenerationType = 2,
  147. // msgStatus = 0,
  148. //}, "点检异常");
  149. //await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel
  150. //{
  151. // C_DevStoreCode = updateModel.C_DevStoreCode,
  152. // C_MsgTypeCode = "MSG_TYPE_009",
  153. // Msg = updateModel.C_Name + " " + updateModel.C_Remark,
  154. // Subject = updateModel.C_Status == "5" ? "维保取消,设备名:" : "维保确认,设备名:" + updateModel.C_DevStoreName,
  155. // DevNumber = updateModel.C_DevStoreCode,
  156. // DevName = updateModel.C_DevStoreName,
  157. //});
  158. }
  159. }
  160. catch (Exception ex)
  161. {
  162. return new ApiResult(ReturnCode.GeneralError, ex.Message + ex.InnerException);
  163. }
  164. return new ApiResult(ReturnCode.Success);
  165. }
  166. /// <summary>
  167. /// 创建巡检记录,带照片
  168. /// </summary>
  169. /// <param name="records"></param>
  170. /// <param name="Files"></param>
  171. /// <returns></returns>
  172. [Route("CreateRecordAndImageAsync")]
  173. [HttpPost]
  174. public async Task<ApiResult> CreateRecordAndImageAsync(IEnumerable<TispRecordViewModel> records, IFormCollection Files)
  175. {
  176. if (records == null)
  177. {
  178. return new ApiResult(ReturnCode.ArgsError);
  179. }
  180. try
  181. {
  182. await _tispRecordService.CreateRecordAndImageAsync(records);
  183. }
  184. catch (Exception ex)
  185. {
  186. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  187. }
  188. return new ApiResult(ReturnCode.Success);
  189. }
  190. /// <summary>
  191. /// 删除
  192. /// </summary>
  193. /// <param name="id"></param>
  194. /// <returns></returns>
  195. [HttpDelete("DeleteRecordAsync/{id}")]
  196. public async Task<ApiResult> DeleteRecordAsync(Guid id)
  197. {
  198. if (Guid.Empty == id)
  199. {
  200. return new ApiResult(ReturnCode.ArgsError);
  201. }
  202. try
  203. {
  204. await _tispRecordService.DeleteAsync(id);
  205. }
  206. catch (Exception ex)
  207. {
  208. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  209. }
  210. return new ApiResult(ReturnCode.Success);
  211. }
  212. /// <summary>
  213. /// 更新巡检记录
  214. /// </summary>
  215. /// <param name="id"></param>
  216. /// <param name="updateModel"></param>
  217. /// <returns></returns>
  218. [HttpPut("UpdateRecordAsync/{id}")]
  219. public async Task<ApiResult> UpdateSpotAsync(Guid id, TispRecordUpdateViewModel updateModel)
  220. {
  221. if (Guid.Empty == id)
  222. {
  223. return new ApiResult(ReturnCode.ArgsError);
  224. }
  225. try
  226. {
  227. await _tispRecordService.UpdateAsync(id, updateModel);
  228. }
  229. catch (Exception ex)
  230. {
  231. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  232. }
  233. return new ApiResult(ReturnCode.Success);
  234. }
  235. /// <summary>
  236. /// 上传巡检图片
  237. /// </summary>
  238. /// <param name="id">巡检记录Id</param>
  239. /// <param name="Files"></param>
  240. /// <returns></returns>
  241. [HttpPost("UploadRecordImageAsync/{id}")]
  242. public async Task<ApiResult> UploadRecordImageAsync(Guid id, IFormCollection Files)
  243. {
  244. try
  245. {
  246. //var form = Request.Form;//直接从表单里面获取文件名不需要参数
  247. string dd = Files["File"];
  248. var form = Files;//定义接收类型的参数
  249. Hashtable hash = new Hashtable();
  250. IFormFileCollection cols = Request.Form.Files;
  251. if (cols == null || cols.Count == 0)
  252. {
  253. return new ApiResult(ReturnCode.GeneralError, "没有上传文件");
  254. }
  255. foreach (IFormFile file in cols)
  256. {
  257. //定义图片数组后缀格式
  258. string[] LimitPictureType = { ".JPG", ".JPEG", ".GIF", ".PNG", ".BMP" };
  259. //获取图片后缀是否存在数组中
  260. string currentPictureExtension = Path.GetExtension(file.FileName).ToUpper();
  261. if (LimitPictureType.Contains(currentPictureExtension))
  262. {
  263. //为了查看图片就不在重新生成文件名称了
  264. var dateDirectory = DateTime.Now.ToString("yyyyMM");
  265. var relativePath = Path.Combine("wwwroot/uploads/images/", dateDirectory);
  266. var directoryPath = Path.Combine(Directory.GetCurrentDirectory(), relativePath);
  267. var fileRelativePath = Path.Combine(relativePath + "/", file.FileName);
  268. if (!Directory.Exists(directoryPath))
  269. {
  270. Directory.CreateDirectory(directoryPath);
  271. }
  272. var path = Path.Combine(directoryPath + "/", file.FileName);
  273. //var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", filePath);
  274. ////文件存储路径
  275. //var new_path = string.Format("/uploads/images/" + dateName + "/", file.FileName);
  276. ////获取当前web目录
  277. //var webRootPath = _hostingEnvironment.WebRootPath;
  278. //var path = webRootPath + new_path;
  279. using (var stream = new FileStream(path, FileMode.Create))
  280. {
  281. //图片路径保存到数据库里面去
  282. bool flage = true;
  283. await _tispRecordImageService.CreateOneAsync(new TispRecordImageViewModel{ C_RecordItemCode = id,C_ImageURL = fileRelativePath, C_Status= '1' });
  284. if (flage == true)
  285. {
  286. //再把文件保存的文件夹中
  287. file.CopyTo(stream);
  288. hash.Add("file", "/" + fileRelativePath);
  289. }
  290. }
  291. }
  292. else
  293. {
  294. return new ApiResult(ReturnCode.GeneralError, "请上传指定格式的图片");
  295. }
  296. }
  297. return new ApiResult<Hashtable>(new Hashtable(hash));
  298. //return new ApiResult(ReturnCode.Success, "上传成功");
  299. }
  300. catch (Exception ex)
  301. {
  302. return new ApiResult(ReturnCode.GeneralError, ex.Message + ex.InnerException);
  303. }
  304. }
  305. /// <summary>
  306. /// 获取所有巡检点的巡检状况
  307. /// </summary>
  308. /// <param name="searchModel"></param>
  309. /// <returns></returns>
  310. [HttpGet("GetAllSpotRecordAsync")]
  311. [AllowAnonymous]
  312. public async Task<ApiResult> GetAllSpotRecordAsync([FromQuery] AllSpotRecordSearchModel searchModel)
  313. {
  314. try
  315. {
  316. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  317. {
  318. return new ApiResult(ReturnCode.ArgsError);
  319. }
  320. searchModel.IsPagination = false;
  321. IEnumerable<AllSpotRecordWithDevViewModel> allSpotRecordList = await _tispRecordService.GetAllSpotRecordAsync(searchModel);
  322. return new ApiResult<PagesModel<AllSpotRecordWithDevViewModel>>(new PagesModel<AllSpotRecordWithDevViewModel>(allSpotRecordList?.ToList(), searchModel));
  323. }
  324. catch (Exception ex)
  325. {
  326. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  327. }
  328. }
  329. /// <summary>
  330. /// 获取巡检员的分配的巡检点巡检情况
  331. /// </summary>
  332. /// <param name="searchModel"></param>
  333. /// <returns></returns>
  334. [HttpGet("GetUserSpotRecordAsync")]
  335. public async Task<ApiResult> GetUserSpotRecordAsync([FromQuery] UserSpotRecordSearchModel searchModel)
  336. {
  337. try
  338. {
  339. if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
  340. {
  341. return new ApiResult(ReturnCode.ArgsError);
  342. }
  343. IEnumerable<AllSpotRecordViewModel> allSpotRecordList = await _tispRecordService.GetUserSpotRecordAsync(searchModel);
  344. return new ApiResult<PagesModel<AllSpotRecordViewModel>>(new PagesModel<AllSpotRecordViewModel>(allSpotRecordList?.ToList(), searchModel));
  345. }
  346. catch (Exception ex)
  347. {
  348. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  349. }
  350. }
  351. /// <summary>
  352. /// 获取用户当天已经巡检过的巡检点数
  353. /// </summary>
  354. /// <param name="usrId"></param>
  355. /// <param name="storeCode"></param>
  356. /// <returns></returns>
  357. [HttpGet("GetUserTodaySpotRecordCountAsync/{usrId}/{storeCode}")]
  358. public async Task<ApiResult> GetUserTodaySpotRecordCountAsync(Guid usrId,string storeCode)
  359. {
  360. try
  361. {
  362. int result = await _tispRecordService.GetUserTodaySpotRecordCountAsync(usrId, storeCode);
  363. return new ApiResult<int>(result);
  364. }
  365. catch (Exception ex)
  366. {
  367. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  368. }
  369. }
  370. /// <summary>
  371. /// 获取用户当天已经巡检过的巡检点记录
  372. /// </summary>
  373. /// <param name="usrId"></param>
  374. /// <param name="storeCode"></param>
  375. /// <returns></returns>
  376. [HttpGet("GetUserTodaySpotRecordsAsync/{usrId}/{storeCode}")]
  377. public async Task<ApiResult> GetUserTodaySpotRecordsAsync(Guid usrId, string storeCode)
  378. {
  379. try
  380. {
  381. IEnumerable<AllSpotRecordViewModel> allSpotRecordList = await _tispRecordService.GetUserTodaySpotRecordsAsync(usrId, storeCode);
  382. return new ApiResult<IEnumerable<AllSpotRecordViewModel>>(allSpotRecordList);
  383. }
  384. catch (Exception ex)
  385. {
  386. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  387. }
  388. }
  389. /// <summary>
  390. /// 获取用户当天还未巡检过的巡检点数
  391. /// </summary>
  392. /// <param name="usrId"></param>
  393. /// <param name="storeCode"></param>
  394. /// <returns></returns>
  395. [HttpGet("GetUserTodayNotSpotRecordCountAsync/{usrId}/{storeCode}")]
  396. public async Task<ApiResult> GetUserTodayNotSpotRecordCountAsync(Guid usrId, string storeCode)
  397. {
  398. try
  399. {
  400. int result = await _tispRecordService.GetUserTodayNotSpotRecordCountAsync(usrId, storeCode);
  401. return new ApiResult<int>(result);
  402. }
  403. catch (Exception ex)
  404. {
  405. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  406. }
  407. }
  408. /// <summary>
  409. /// 获取用户当天还未巡检过的巡检点
  410. /// </summary>
  411. /// <param name="usrId"></param>
  412. /// <param name="storeCode"></param>
  413. /// <returns></returns>
  414. [HttpGet("GetUserTodayNotSpotRecordsAsync/{usrId}/{storeCode}")]
  415. public async Task<ApiResult> GetUserTodayNotSpotRecordsAsync(Guid usrId,string storeCode)
  416. {
  417. if (Guid.Empty.Equals(usrId) || string.IsNullOrEmpty(storeCode))
  418. {
  419. return new ApiResult(ReturnCode.ArgsError);
  420. }
  421. try
  422. {
  423. IEnumerable<AllSpotRecordViewModel> allSpotRecordList = await _tispRecordService.GetUserTodayNotSpotRecordsAsync(usrId, storeCode);
  424. return new ApiResult<IEnumerable<AllSpotRecordViewModel>>(allSpotRecordList);
  425. }
  426. catch (Exception ex)
  427. {
  428. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  429. }
  430. }
  431. /// <summary>
  432. /// 最近三十天巡检统计
  433. /// </summary>
  434. /// <param name="storeCode"></param>
  435. /// <returns></returns>
  436. [HttpGet("GetRecords30DaysStatisticsAsync/{storeCode}")]
  437. public async Task<ApiResult> GetRecords30DaysStatisticsAsync(string storeCode)
  438. {
  439. try
  440. {
  441. TispRecord30DaysStatisticsViewModel statistics = await _tispRecordService.GetRecords30DaysStatisticsAsync(storeCode);
  442. return new ApiResult<TispRecord30DaysStatisticsViewModel>(statistics);
  443. }
  444. catch (Exception ex)
  445. {
  446. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  447. }
  448. }
  449. /// <summary>
  450. /// 最近7天异常处理统计
  451. /// </summary>
  452. /// <param name="storeCode"></param>
  453. /// <returns></returns>
  454. [HttpGet("GetAlarmRecovery7DaysStatisticsAsync/{storeCode}")]
  455. public async Task<ApiResult> GetAlarmRecovery7DaysStatisticsAsync(string storeCode)
  456. {
  457. try
  458. {
  459. TispAlarmRecovery7DaysStatisticsViewModel statistics = await _tispRecordService.GetAlarmRecovery7DaysStatisticsAsync(storeCode);
  460. return new ApiResult<TispAlarmRecovery7DaysStatisticsViewModel>(statistics);
  461. }
  462. catch (Exception ex)
  463. {
  464. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  465. }
  466. }
  467. /// <summary>
  468. /// 取当天关于巡检点的正常,异常统计
  469. /// </summary>
  470. /// <param name="storeCode"></param>
  471. /// <returns></returns>
  472. [HttpGet("GetTodaySpotStatisticsAsync/{storeCode}")]
  473. public async Task<ApiResult> GetTodaySpotStatisticsAsync(string storeCode)
  474. {
  475. try
  476. {
  477. TodaySpotStatistics statistics = await _tispRecordService.GetTodaySpotStatisticsAsync(storeCode);
  478. return new ApiResult<TodaySpotStatistics>(statistics);
  479. }
  480. catch (Exception ex)
  481. {
  482. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  483. }
  484. }
  485. /// <summary>
  486. /// 取当天关于巡检点内容的正常,异常,恢复统计
  487. /// </summary>
  488. /// <param name="storeCode"></param>
  489. /// <returns></returns>
  490. [HttpGet("GetTodaySpotContentStatisticsAsync/{storeCode}")]
  491. public async Task<ApiResult> GetTodaySpotContentStatisticsAsync(string storeCode)
  492. {
  493. try
  494. {
  495. TodaySpotContentStatistics statistics = await _tispRecordService.GetTodaySpotContentStatisticsAsync(storeCode);
  496. return new ApiResult<TodaySpotContentStatistics>(statistics);
  497. }
  498. catch (Exception ex)
  499. {
  500. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  501. }
  502. }
  503. /// <summary>
  504. /// 最近12个月巡检次数统计
  505. /// </summary>
  506. /// <param name="storeCode"></param>
  507. /// <returns></returns>
  508. [HttpGet("GetRecord12MonthStatisticsAsync/{storeCode}")]
  509. public async Task<ApiResult> GetRecord12MonthStatisticsAsync(string storeCode)
  510. {
  511. try
  512. {
  513. Record12MonthStatisticsViewModel statistics = await _tispRecordService.GetRecord12MonthStatisticsAsync(storeCode);
  514. return new ApiResult<Record12MonthStatisticsViewModel>(statistics);
  515. }
  516. catch (Exception ex)
  517. {
  518. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  519. }
  520. }
  521. /// <summary>
  522. /// 最近12个月巡检次数统计,大屏
  523. /// </summary>
  524. /// <param name="storeCode"></param>
  525. /// <returns></returns>
  526. [HttpGet("GetRecord12MonthStatisticsFullScreenAsync/{storeCode}")]
  527. [AllowAnonymous]
  528. public async Task<IEnumerable<FullScreenRecordItem>> GetRecord12MonthStatisticsFullScreenAsync(string storeCode)
  529. {
  530. if (string.IsNullOrEmpty(storeCode))
  531. {
  532. return null;
  533. }
  534. try
  535. {
  536. var content = await _tispRecordService.GetRecord12MonthStatisticsFullScreenAsync(storeCode);
  537. return content;
  538. }
  539. catch (Exception ex)
  540. {
  541. return null;
  542. }
  543. }
  544. /// <summary>
  545. /// 最近12个月点检、维保、维修次数统计,大屏
  546. /// </summary>
  547. /// <param name="storeCode"></param>
  548. /// <returns></returns>
  549. [HttpGet("GetAllDevOpsRecord12MonthStatisticsFullScreenAsync/{storeCode}")]
  550. [AllowAnonymous]
  551. public async Task<IEnumerable<FullScreenRecordItem>> GetAllDevOpsRecord12MonthStatisticsFullScreenAsync(string storeCode)
  552. {
  553. if (string.IsNullOrEmpty(storeCode))
  554. {
  555. return null;
  556. }
  557. try
  558. {
  559. var content = await _tispRecordService.GetAllDevOpsRecord12MonthStatisticsFullScreenAsync(storeCode);
  560. return content;
  561. }
  562. catch (Exception ex)
  563. {
  564. return null;
  565. }
  566. }
  567. /// <summary>
  568. /// 发送邮件(附件为巡检记录)
  569. /// </summary>
  570. /// <param name="searchModel"></param>
  571. /// <returns></returns>
  572. [HttpPost("SendRecordsToEmail")]
  573. public async Task SendRecordsToEmail(SendRecordToEmailModel searchModel)
  574. {
  575. if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode))
  576. {
  577. return;
  578. }
  579. try
  580. {
  581. var recordList = await _tispRecordService.GetRecordsConditionAsync(searchModel);
  582. string zip = @"wwwroot\\ZipFile";
  583. if (!System.IO.Directory.Exists(zip))
  584. {
  585. Directory.CreateDirectory(zip);
  586. }
  587. string zipPaht = zip + "\\点检记录下载_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip";
  588. IWorkbook workbook = new XSSFWorkbook();
  589. ISheet sheet = workbook.CreateSheet("sheet1");
  590. sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 5));
  591. var titleRow = sheet.CreateRow(0);
  592. titleRow.Height = 20 * 25;
  593. NPOI.SS.UserModel.ICell titleCell = titleRow.CreateCell(0);
  594. titleCell.SetCellValue("设备点检记录");
  595. //第一行字体样式
  596. IFont font = workbook.CreateFont();
  597. font.IsBold = true;
  598. font.FontHeightInPoints = 16;
  599. font.FontName = "宋体";
  600. ICellStyle titleCellStyle = workbook.CreateCellStyle();
  601. titleCellStyle.SetFont(font);
  602. titleCellStyle.Alignment = HorizontalAlignment.Center; //字体居中
  603. //边框
  604. titleCellStyle.BorderBottom = BorderStyle.Thin;
  605. titleCellStyle.BorderLeft = BorderStyle.Thin;
  606. titleCellStyle.BorderRight = BorderStyle.Thin;
  607. titleCellStyle.BorderTop = BorderStyle.Thin;
  608. titleCell.CellStyle = titleCellStyle;
  609. var headRow = sheet.CreateRow(1);
  610. //headRow.CreateCell(0).SetCellValue("序 号");
  611. headRow.CreateCell(0).SetCellValue("点检点名称");
  612. headRow.CreateCell(1).SetCellValue("点检编号");
  613. headRow.CreateCell(2).SetCellValue("点检人");
  614. headRow.CreateCell(3).SetCellValue("点检时间");
  615. headRow.CreateCell(4).SetCellValue("状态");
  616. headRow.CreateCell(5).SetCellValue("备注");
  617. //第二行,列名
  618. IFont font1 = workbook.CreateFont();
  619. font1.IsBold = true;
  620. font1.FontHeightInPoints = 12;
  621. font1.FontName = "宋体";
  622. ICellStyle headCellStyle = workbook.CreateCellStyle();
  623. headCellStyle.SetFont(font1);
  624. //边框
  625. headCellStyle.BorderBottom = BorderStyle.Thin;
  626. headCellStyle.BorderLeft = BorderStyle.Thin;
  627. headCellStyle.BorderRight = BorderStyle.Thin;
  628. headCellStyle.BorderTop = BorderStyle.Thin;
  629. foreach (var item in headRow.Cells)
  630. {
  631. item.CellStyle = headCellStyle;
  632. }
  633. int start = 2;
  634. IFont font3 = workbook.CreateFont();
  635. font3.FontHeightInPoints = 9;
  636. font3.FontName = "宋体";
  637. ICellStyle contentCellStyle = workbook.CreateCellStyle();
  638. contentCellStyle.SetFont(font3);
  639. //边框
  640. contentCellStyle.BorderBottom = BorderStyle.Thin;
  641. contentCellStyle.BorderLeft = BorderStyle.Thin;
  642. contentCellStyle.BorderRight = BorderStyle.Thin;
  643. contentCellStyle.BorderTop = BorderStyle.Thin;
  644. foreach (var item in recordList)
  645. {
  646. if (item!=null)
  647. {
  648. var row = sheet.CreateRow(start);
  649. row.CreateCell(0).SetCellValue(item.C_Name);
  650. row.CreateCell(1).SetCellValue(item.C_Number);
  651. row.CreateCell(2).SetCellValue(item.C_CreateByName);
  652. row.CreateCell(3).SetCellValue(item.D_CreateOn.ToString("yyyy-MM-dd hh:mm:ss"));
  653. switch (item.C_Status)
  654. {
  655. case "0":
  656. row.CreateCell(4).SetCellValue("禁用");
  657. break;
  658. case "1":
  659. row.CreateCell(4).SetCellValue("正常");
  660. break;
  661. case "2":
  662. row.CreateCell(4).SetCellValue("异常");
  663. break;
  664. case "3":
  665. row.CreateCell(4).SetCellValue("确认异常");
  666. break;
  667. case "4":
  668. row.CreateCell(4).SetCellValue("取消异常");
  669. break;
  670. default:
  671. row.CreateCell(4).SetCellValue("未知状态");
  672. break;
  673. }
  674. row.CreateCell(5).SetCellValue(item.C_Remark);
  675. start++;
  676. foreach (var cell in row.Cells)
  677. {
  678. cell.CellStyle = contentCellStyle;
  679. }
  680. }
  681. }
  682. // 自适应单元格
  683. for (int i = 0; i < sheet.LastRowNum; i++)
  684. {
  685. sheet.AutoSizeRow(i);
  686. }
  687. for (int i = 0; i < 7; i++)
  688. {
  689. sheet.AutoSizeColumn(i, true);
  690. }
  691. using (var zipFile = new FileStream(zipPaht, FileMode.Create))
  692. {
  693. // 列表Excel
  694. using (var memoryStream = new NpoiMemoryStream())
  695. {
  696. workbook.Write(memoryStream);
  697. byte[] excelData = memoryStream.ToArray();
  698. using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
  699. {
  700. archive.CreateEntry("点检记录报表.xlsx").Open().Write(excelData, 0, excelData.Length);
  701. }
  702. }
  703. }
  704. //内容word
  705. foreach (var cell in recordList.ToList())
  706. {
  707. if (cell != null)
  708. {
  709. var repairOrders = await _tispRecordItemService.GetRecordItemsByRecordIdAsync(cell.C_ID);
  710. List<List<TispRecordItemDetailViewModel>> recordItems = repairOrders.ToList();
  711. if (recordItems.Count > 0)
  712. {
  713. XWPFDocument doc = new XWPFDocument();
  714. var paragraph = doc.CreateParagraph();
  715. var run1 = paragraph.CreateRun();
  716. run1.FontSize = 18;
  717. int serialNum = 1;
  718. run1.SetText("点检主题:" + cell.C_Name);
  719. foreach (var itemList in recordItems)
  720. {
  721. if (itemList==null)
  722. {
  723. continue;
  724. }
  725. var p0 = doc.CreateParagraph();
  726. var run0 = p0.CreateRun();
  727. run0.FontSize = 16;
  728. run0.SetText(" " + serialNum.ToString() + "、"+ itemList.FirstOrDefault()?.C_Name);
  729. int serialNum1 = 1;
  730. foreach (var item in itemList)
  731. {
  732. if(item==null)continue;
  733. var p1 = doc.CreateParagraph();
  734. var run = p1.CreateRun();
  735. run.FontSize = 14;
  736. string status = string.Empty;
  737. //1 = 正常;0 = 异常;2 = 恢复;3 = 确认异常;4 = 取消异常
  738. switch (item.C_Status)
  739. {
  740. case "1":
  741. status = "正常";
  742. break;
  743. case "2":
  744. status = "异常已处理";
  745. break;
  746. case "3":
  747. status = "确认异常";
  748. break;
  749. case "4":
  750. status = "取消异常";
  751. break;
  752. case "0":
  753. status = "巡检异常";
  754. break;
  755. }
  756. run.SetText(" " + serialNum.ToString() + "." + serialNum1.ToString());
  757. run.AddCarriageReturn();
  758. run.AppendText(" 操作时间:" + item.D_CreateOn.ToString("yyyy-MM-dd HH:mm"));
  759. run.AddCarriageReturn();
  760. run.AppendText(" 状态:" + status);
  761. run.AddCarriageReturn();
  762. run.AppendText(" 处理人员:" + item.ReportUserName);
  763. if (item.RecordImageList != null && item.RecordImageList.Count() > 0)
  764. {
  765. run.AddCarriageReturn();
  766. run.AppendText(" 现场拍照:");
  767. foreach (var path in item.RecordImageList)
  768. {
  769. string pathFile = path.C_ImageURL;
  770. if (pathFile != null)
  771. {
  772. if (pathFile[0].ToString() == @"/")
  773. {
  774. pathFile = pathFile.Substring(1);
  775. }
  776. if (!System.IO.File.Exists(pathFile))
  777. {
  778. pathFile = @"wwwroot/error.png";
  779. }
  780. FileStream fileStream = new FileStream(pathFile, FileMode.Open, FileAccess.Read);
  781. run.AddCarriageReturn();
  782. run.AddPicture(fileStream, 6, pathFile, Units.ToEMU(100), Units.ToEMU(100));
  783. }
  784. }
  785. }
  786. run.AddCarriageReturn();
  787. run.AppendText(" 现场描述:" + item.C_Remark);
  788. serialNum1++;
  789. }
  790. serialNum++;
  791. }
  792. using (var zipFile = new FileStream(zipPaht, FileMode.OpenOrCreate))
  793. {
  794. using (var memoryStream = new NpoiMemoryStream())
  795. {
  796. doc.Write(memoryStream);
  797. byte[] excelData = memoryStream.ToArray();
  798. using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
  799. {
  800. archive.CreateEntry("点检记录/" + cell.C_ID + ".docx").Open().Write(excelData, 0, excelData.Length);
  801. }
  802. }
  803. }
  804. }
  805. }
  806. }
  807. var zipFile1 = new FileStream(zipPaht, FileMode.Open);
  808. string emailName = $"{searchModel.DevName} 设备点检记录 {searchModel.Start.ToString("yyyy-MM-dd HH:mm:ss")}至{searchModel.End.ToString("yyyy-MM-dd HH:mm:ss")}";
  809. EmailHelper.SendEmail(searchModel.Mails, emailName, "", "报表见附件", $"{emailName}.zip", "application/zip", zipFile1);
  810. System.IO.File.Delete(zipPaht);
  811. //using var stream = new NpoiMemoryStream();
  812. //workbook.Write(stream);
  813. //stream.Seek(0, SeekOrigin.Begin);
  814. //EmailHelper.SendEmail(searchModel.Mails, $"{searchModel.Start}-{searchModel.End}设备点检记录报表", "", "报表见附件", $"{searchModel.Start}-{searchModel.End}设备点检记录报表.xlsx", "application/vnd.ms-excel", stream);
  815. }
  816. catch (Exception ex)
  817. {
  818. throw;
  819. }
  820. }
  821. /// <summary>
  822. /// 导出点检记录压缩包
  823. /// </summary>
  824. /// <param name="searchModel"></param>
  825. /// <returns></returns>
  826. [HttpPost("ExportZip")]
  827. [AllowAnonymous]
  828. public async Task<IActionResult> ExportZip(TispRecordSearchModel searchModel)
  829. {
  830. var recordList = await _tispRecordService.GetRecordsConditionAsync(searchModel);
  831. string zip = @"wwwroot\\ZipFile";
  832. if (!System.IO.Directory.Exists(zip))
  833. {
  834. Directory.CreateDirectory(zip);
  835. }
  836. string zipPaht = zip + "\\点检记录下载.zip";
  837. System.IO.File.Delete(zipPaht);
  838. TpntStoreViewModel spotModel = null;
  839. if (!string.IsNullOrEmpty(searchModel.C_StoreCode))
  840. {
  841. Guid guid = Guid.Parse(searchModel.C_StoreCode);
  842. spotModel = await _TpntStoreService.GetByIdAsync(guid);
  843. }
  844. IWorkbook workbook = new XSSFWorkbook();
  845. ISheet sheet = workbook.CreateSheet();
  846. #region
  847. //标题加粗居中.
  848. IFont font = workbook.CreateFont();
  849. font.IsBold = true;
  850. font.FontHeightInPoints = 25;
  851. font.FontName = "宋体";
  852. ICellStyle titleCellStyle = workbook.CreateCellStyle();
  853. titleCellStyle.SetFont(font);
  854. titleCellStyle.Alignment = HorizontalAlignment.Center; //字体居中
  855. //边框
  856. titleCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  857. titleCellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  858. titleCellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  859. titleCellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  860. titleCellStyle.WrapText = true;
  861. #endregion
  862. #region
  863. //表头加粗居中.
  864. IFont font1 = workbook.CreateFont();
  865. font1.IsBold = true;
  866. font1.FontHeightInPoints = 14;
  867. font1.FontName = "宋体";
  868. ICellStyle headCellStyle = workbook.CreateCellStyle();
  869. headCellStyle.SetFont(font1);
  870. headCellStyle.Alignment = HorizontalAlignment.Center; //字体居中
  871. //边框
  872. headCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  873. headCellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  874. headCellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  875. headCellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  876. headCellStyle.WrapText = true;
  877. #endregion
  878. #region
  879. //行.
  880. IFont font2 = workbook.CreateFont();
  881. font2.IsBold = false;
  882. font2.FontHeightInPoints = 12;
  883. font2.FontName = "宋体";
  884. ICellStyle rowCellStyle = workbook.CreateCellStyle();
  885. rowCellStyle.SetFont(font2);
  886. rowCellStyle.Alignment = HorizontalAlignment.Center; //字体居中
  887. //边框
  888. rowCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  889. rowCellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  890. rowCellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  891. rowCellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  892. rowCellStyle.WrapText = true;
  893. #endregion
  894. #region 超链接
  895. // 创建样式
  896. ICellStyle styleLInk = workbook.CreateCellStyle();
  897. // 设置字体颜色为蓝色
  898. IFont fontLink = workbook.CreateFont();
  899. fontLink.IsBold = false;
  900. fontLink.FontHeightInPoints = 12;
  901. fontLink.FontName = "宋体";
  902. fontLink.Color = IndexedColors.Green.Index;
  903. styleLInk.SetFont(fontLink);
  904. // 设置下划线
  905. fontLink.Underline = FontUnderlineType.Single;
  906. styleLInk.SetFont(fontLink);
  907. styleLInk.Alignment = HorizontalAlignment.Center; //字体居中
  908. //边框
  909. styleLInk.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  910. styleLInk.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  911. styleLInk.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  912. styleLInk.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  913. styleLInk.WrapText = true;
  914. #endregion
  915. sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 7));
  916. IRow title = sheet.CreateRow(0);
  917. title.Height = 30 * 25;
  918. title.CreateCell(0).SetCellValue("点检记录报表" + (spotModel == null ? "" : "(" + spotModel.C_Name + ")"));
  919. foreach (var item in title.Cells)
  920. {
  921. item.CellStyle = titleCellStyle;
  922. }
  923. IRow head = sheet.CreateRow(1);
  924. head.CreateCell(0).SetCellValue("序号");
  925. head.CreateCell(1).SetCellValue("点检点名称");
  926. head.CreateCell(2).SetCellValue("点检点编号");
  927. head.CreateCell(3).SetCellValue("点检人");
  928. head.CreateCell(4).SetCellValue("点检时间");
  929. head.CreateCell(5).SetCellValue("状态");
  930. head.CreateCell(6).SetCellValue("备注");
  931. head.CreateCell(7).SetCellValue("附件");
  932. foreach (var item in head.Cells)
  933. {
  934. item.CellStyle = headCellStyle;
  935. }
  936. int rowNumber = 2; int number = 1;
  937. if (recordList.Any() && recordList.FirstOrDefault() != null)
  938. {
  939. foreach (var x in recordList)
  940. {
  941. IRow content = sheet.CreateRow(rowNumber);
  942. content.CreateCell(0).SetCellValue(number);
  943. content.CreateCell(1).SetCellValue(x.C_Name);
  944. content.CreateCell(2).SetCellValue(x.C_Number);
  945. content.CreateCell(3).SetCellValue(x.C_CreateByName);
  946. content.CreateCell(4).SetCellValue(x.D_CreateOn.ToString("yyyy-MM-dd HH:mm"));
  947. string statusVal = "";
  948. switch (x.C_Status)
  949. {
  950. case "0": statusVal = "禁用"; break;
  951. case "1": statusVal = "正常"; break;
  952. case "2": statusVal = "异常"; break;
  953. case "3": statusVal = "确认异常"; break;
  954. case "4": statusVal = "取消异常"; break;
  955. default: statusVal = "未知状态"; break;
  956. }
  957. content.CreateCell(5).SetCellValue(statusVal);
  958. content.CreateCell(6).SetCellValue(x.C_Remark);
  959. //超链接
  960. NPOI.SS.UserModel.ICell cell = content.CreateCell(7);
  961. cell.SetCellValue("附件");
  962. IHyperlink link = new XSSFHyperlink(HyperlinkType.Url);
  963. link.Address = ("点检记录/" + x.C_ID + ".docx");
  964. cell.Hyperlink = link;
  965. foreach (var item in content.Cells)
  966. {
  967. item.CellStyle = rowCellStyle;
  968. }
  969. // 应用样式到单元格
  970. cell.CellStyle = styleLInk;
  971. rowNumber++; number++;
  972. }
  973. }
  974. else
  975. {
  976. IRow content1 = sheet.CreateRow(rowNumber);
  977. content1.CreateCell(0).SetCellValue("暂无数据");
  978. sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(2, 2, 0, 7));
  979. }
  980. for (int i = 0; i <= 7; i++)
  981. {
  982. if (i == 0)
  983. {
  984. sheet.SetColumnWidth(i, 2000);
  985. }
  986. else if (i == 1)
  987. {
  988. sheet.SetColumnWidth(i, 7000);
  989. }
  990. else
  991. {
  992. sheet.SetColumnWidth(i, 4500);
  993. }
  994. }
  995. using (var zipFile = new FileStream(zipPaht, FileMode.Create))
  996. {
  997. // 列表Excel
  998. using (var memoryStream = new NpoiMemoryStream())
  999. {
  1000. workbook.Write(memoryStream);
  1001. byte[] excelData = memoryStream.ToArray();
  1002. using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
  1003. {
  1004. archive.CreateEntry("点检记录报表.xlsx").Open().Write(excelData, 0, excelData.Length);
  1005. }
  1006. }
  1007. }
  1008. //内容word
  1009. foreach (var cell in recordList.ToList())
  1010. {
  1011. if (cell != null)
  1012. {
  1013. var repairOrders = await _tispRecordItemService.GetRecordItemsByRecordIdAsync(cell.C_ID);
  1014. List<List<TispRecordItemDetailViewModel>> recordItems = repairOrders.ToList();
  1015. if (recordItems.Count > 0)
  1016. {
  1017. XWPFDocument doc = new XWPFDocument();
  1018. var paragraph = doc.CreateParagraph();
  1019. var run1 = paragraph.CreateRun();
  1020. run1.FontSize = 18;
  1021. int serialNum = 1;
  1022. run1.SetText("点检主题:" + cell.C_Name);
  1023. foreach (var itemList in recordItems)
  1024. {
  1025. if (itemList == null) { continue; }
  1026. var p0 = doc.CreateParagraph();
  1027. var run0 = p0.CreateRun();
  1028. run0.FontSize = 16;
  1029. run0.SetText(" " + serialNum.ToString() + "、" + itemList.FirstOrDefault()?.C_Name);
  1030. int serialNum1 = 1;
  1031. foreach (var item in itemList)
  1032. {
  1033. if(item == null) { continue; }
  1034. var p1 = doc.CreateParagraph();
  1035. var run = p1.CreateRun();
  1036. run.FontSize = 14;
  1037. string status = string.Empty;
  1038. //1 = 正常;0 = 异常;2 = 恢复;3 = 确认异常;4 = 取消异常
  1039. switch (item.C_Status)
  1040. {
  1041. case "1":
  1042. status = "正常";
  1043. break;
  1044. case "2":
  1045. status = "异常已处理";
  1046. break;
  1047. case "3":
  1048. status = "确认异常";
  1049. break;
  1050. case "4":
  1051. status = "取消异常";
  1052. break;
  1053. case "0":
  1054. status = "巡检异常";
  1055. break;
  1056. }
  1057. run.SetText(" " + serialNum.ToString() + "." + serialNum1.ToString());
  1058. run.AddCarriageReturn();
  1059. run.AppendText(" 操作时间:" + item.D_CreateOn.ToString("yyyy-MM-dd HH:mm"));
  1060. run.AddCarriageReturn();
  1061. run.AppendText(" 状态:" + status);
  1062. run.AddCarriageReturn();
  1063. run.AppendText(" 处理人员:" + item.ReportUserName);
  1064. if (item.RecordImageList != null && item.RecordImageList.Count() > 0)
  1065. {
  1066. run.AddCarriageReturn();
  1067. run.AppendText(" 现场拍照:");
  1068. foreach (var path in item.RecordImageList)
  1069. {
  1070. string pathFile = path.C_ImageURL;
  1071. if (pathFile != null)
  1072. {
  1073. if (pathFile[0].ToString() == @"/")
  1074. {
  1075. pathFile = pathFile.Substring(1);
  1076. }
  1077. if (!System.IO.File.Exists(pathFile))
  1078. {
  1079. pathFile = @"wwwroot/error.png";
  1080. }
  1081. FileStream fileStream = new FileStream(pathFile, FileMode.Open, FileAccess.Read);
  1082. run.AddCarriageReturn();
  1083. run.AddPicture(fileStream, 6, pathFile, Units.ToEMU(100), Units.ToEMU(100));
  1084. }
  1085. }
  1086. }
  1087. run.AddCarriageReturn();
  1088. run.AppendText(" 现场描述:" + item.C_Remark);
  1089. serialNum1++;
  1090. }
  1091. serialNum++;
  1092. }
  1093. using (var zipFile = new FileStream(zipPaht, FileMode.OpenOrCreate))
  1094. {
  1095. using (var memoryStream = new NpoiMemoryStream())
  1096. {
  1097. doc.Write(memoryStream);
  1098. byte[] excelData = memoryStream.ToArray();
  1099. using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
  1100. {
  1101. archive.CreateEntry("点检记录/" + cell.C_ID + ".docx").Open().Write(excelData, 0, excelData.Length);
  1102. }
  1103. }
  1104. }
  1105. }
  1106. }
  1107. }
  1108. var zipFile1 = new FileStream(zipPaht, FileMode.Open);
  1109. // 将压缩后的数据作为响应返回给客户端(这里假设你使用的是HTTP GET请求)
  1110. return File(zipFile1, "application/zip", "点检记录报表.zip"); // 这里假设你的文件类型是.xlsx的GZip压缩文件。你可以根据需要调整MIME类型和文件扩展名。
  1111. }
  1112. }
  1113. }