TmtnDevOpsRecordController.cs 51 KB

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