ExcelService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. using Core.Dtos;
  2. using Microsoft.Extensions.Logging;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using NPOI.HSSF.Record;
  6. using NPOI.HSSF.Record.CF;
  7. using OfficeOpenXml;
  8. using OfficeOpenXml.ConditionalFormatting;
  9. using OfficeOpenXml.Drawing.Chart;
  10. using OfficeOpenXml.Style;
  11. using ProductionLineMonitor.Application.Services.FaultService;
  12. using ProductionLineMonitor.Application.Services.OEEService;
  13. using ProductionLineMonitor.Core.Dtos;
  14. using ProductionLineMonitor.Core.IRepositories;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Drawing;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Security.Claims;
  21. using System.Text;
  22. using static ProductionLineMonitor.Core.Utils.EmailHelper;
  23. namespace ProductionLineMonitor.Application.Services
  24. {
  25. public class ExcelService : IExcelService
  26. {
  27. private readonly IUnitOfWork _unitOfWork;
  28. private readonly IOEEService _oeeService;
  29. private readonly IFaultService _faultService;
  30. public ExcelService(
  31. IUnitOfWork unitOfWork,
  32. IOEEService oEEService,
  33. IFaultService faultService)
  34. {
  35. _unitOfWork = unitOfWork;
  36. _oeeService = oEEService;
  37. _faultService = faultService;
  38. }
  39. public bool EquipmentOperationReport(DateTime dateTime)
  40. {
  41. try
  42. {
  43. string date = dateTime.ToString("yyyy-MM-dd");
  44. if (dateTime.Hour == 8)
  45. {
  46. date = dateTime.AddDays(-1).ToString("yyyy-MM-dd");
  47. }
  48. JToken? UtilizationRateEmailList;
  49. using (StreamReader file = File.OpenText("D:\\ReportForms\\Email.json"))
  50. {
  51. using JsonTextReader reader = new JsonTextReader(file);
  52. JObject jsonObject = (JObject)JToken.ReadFrom(reader);
  53. UtilizationRateEmailList = jsonObject["UtilizationRateEmail"];
  54. }
  55. if (UtilizationRateEmailList == null || UtilizationRateEmailList.Count() == 0)
  56. {
  57. return false;
  58. }
  59. DateTime startTime = DateTime.Parse($"{date} 08:00:00");
  60. DateTime endTime = startTime.AddDays(1);
  61. DateTime dataStartTime = endTime.AddDays(-7);
  62. int count = 0;
  63. // 文件夹存储路径
  64. string dateNowStr = DateTime.Now.ToString("yyyyMMddHHmmss");
  65. string folderPath = $"D:\\ReportForms\\{DateTime.Now:yyyyMM}\\{dateNowStr}";
  66. foreach (var UtilizationRateEmail in UtilizationRateEmailList)
  67. {
  68. count++;
  69. LogerHelper.RecordLogTxt($"EquipmentOperationReport Group-{count} Begin");
  70. if ((!(bool)UtilizationRateEmail["IsSend"]))
  71. {
  72. LogerHelper.RecordLogTxt($"EquipmentOperationReport Group-{count} isSend is False");
  73. continue;
  74. }
  75. string path = Path.Combine(folderPath, $"Group-{count}.xlsx");
  76. if (!Directory.Exists(folderPath))
  77. Directory.CreateDirectory(folderPath);
  78. string[] machineIdString = UtilizationRateEmail["MachineIDs"].ToString().Split(',');
  79. if (machineIdString == null || machineIdString.Length == 0)
  80. {
  81. LogerHelper.RecordLogTxt($"EquipmentOperationReport Group-{count} machineIdString is null or length is 0");
  82. continue;
  83. }
  84. foreach (var machineId in machineIdString)
  85. {
  86. var machine = _unitOfWork.MachineRepository.GetById(machineId);
  87. var line = _unitOfWork.ProductionLineRepository.FirstOrDefault(x => x.Id == machine.ProductionLineId);
  88. var machineOEE = _oeeService.GetOEE(machineId, dataStartTime.ToString("yyyy-MM-dd"), startTime.ToString("yyyy-MM-dd"));
  89. var machineHourDatas = _unitOfWork.MachineOutPutPerHourRepository.GetList(
  90. x =>
  91. x.MachineId == machine.Id &&
  92. x.DataTime >= startTime &&
  93. x.DataTime < endTime).OrderBy(o => o.DataTime).ToList();
  94. FileInfo file = new FileInfo(path);
  95. //ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  96. using ExcelPackage package = new ExcelPackage(file);
  97. ExcelWorksheet worksheet = package.Workbook.Worksheets.Add($"{line.Name} {machine.Name}");
  98. worksheet.View.ZoomScale = 80;
  99. worksheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
  100. #region tab header
  101. worksheet.Cells[1, 1].Value = "NO";
  102. worksheet.Cells[1, 2].Value = "时间";
  103. worksheet.Cells[1, 3].Value = "稼动率(%)";
  104. worksheet.Cells[1, 4].Value = "待机率(%)";
  105. worksheet.Cells[1, 5].Value = "报警率(%)";
  106. worksheet.Cells[1, 6].Value = "换料率(%)";
  107. worksheet.Cells[1, 7].Value = "产能(pcs)";
  108. worksheet.Cells[1, 8].Value = "稼动(min)";
  109. worksheet.Cells[1, 9].Value = "待机(min)";
  110. worksheet.Cells[1, 10].Value = "报警(min)";
  111. worksheet.Cells[1, 11].Value = "换料(min)";
  112. worksheet.Cells[1, 12].Value = "合计(min)";
  113. worksheet.Cells[1, 15].Value = $"{startTime:yyyy-MM-dd} 早班";
  114. worksheet.Cells[1, 15, 1, 24].Merge = true;
  115. worksheet.Cells[2, 15].Value = "NO";
  116. worksheet.Cells[2, 16].Value = "时段";
  117. worksheet.Cells[2, 17].Value = "机种";
  118. worksheet.Cells[2, 18].Value = "运行时间";
  119. worksheet.Cells[2, 19].Value = "报警时间";
  120. worksheet.Cells[2, 20].Value = "待料时间";
  121. worksheet.Cells[2, 21].Value = "换料时间";
  122. worksheet.Cells[2, 22].Value = "产能";
  123. worksheet.Cells[2, 23].Value = "TT";
  124. worksheet.Cells[2, 24].Value = "报警次数";
  125. worksheet.Cells[16, 15].Value = "NO";
  126. worksheet.Cells[16, 16].Value = "故障码";
  127. worksheet.Cells[16, 17].Value = "故障详情";
  128. worksheet.Cells[16, 24].Value = "报警次数";
  129. worksheet.Cells[16, 17, 16, 23].Merge = true;
  130. worksheet.Cells[17, 17, 17, 23].Merge = true;
  131. worksheet.Cells[18, 17, 18, 23].Merge = true;
  132. worksheet.Cells[19, 17, 19, 23].Merge = true;
  133. worksheet.Cells[20, 17, 20, 23].Merge = true;
  134. worksheet.Cells[21, 17, 21, 23].Merge = true;
  135. worksheet.Cells[22, 17, 22, 23].Merge = true;
  136. worksheet.Cells[23, 17, 23, 23].Merge = true;
  137. worksheet.Cells[24, 17, 24, 23].Merge = true;
  138. worksheet.Cells[25, 17, 25, 23].Merge = true;
  139. worksheet.Cells[26, 17, 26, 23].Merge = true;
  140. worksheet.Cells[1, 26].Value = $"{startTime:yyyy-MM-dd} 夜班";
  141. worksheet.Cells[1, 26, 1, 35].Merge = true;
  142. worksheet.Cells[2, 26].Value = "NO";
  143. worksheet.Cells[2, 27].Value = "时段";
  144. worksheet.Cells[2, 28].Value = "机种";
  145. worksheet.Cells[2, 29].Value = "运行时间";
  146. worksheet.Cells[2, 30].Value = "报警时间";
  147. worksheet.Cells[2, 31].Value = "待料时间";
  148. worksheet.Cells[2, 32].Value = "换料时间";
  149. worksheet.Cells[2, 33].Value = "产能";
  150. worksheet.Cells[2, 34].Value = "TT";
  151. worksheet.Cells[2, 35].Value = "报警次数";
  152. worksheet.Cells[16, 26].Value = "NO";
  153. worksheet.Cells[16, 27].Value = "故障码";
  154. worksheet.Cells[16, 28].Value = "故障详情";
  155. worksheet.Cells[16, 35].Value = "报警次数";
  156. worksheet.Cells[16, 28, 16, 34].Merge = true;
  157. worksheet.Cells[17, 28, 17, 34].Merge = true;
  158. worksheet.Cells[18, 28, 18, 34].Merge = true;
  159. worksheet.Cells[19, 28, 19, 34].Merge = true;
  160. worksheet.Cells[20, 28, 20, 34].Merge = true;
  161. worksheet.Cells[21, 28, 21, 34].Merge = true;
  162. worksheet.Cells[22, 28, 22, 34].Merge = true;
  163. worksheet.Cells[23, 28, 23, 34].Merge = true;
  164. worksheet.Cells[24, 28, 24, 34].Merge = true;
  165. worksheet.Cells[25, 28, 25, 34].Merge = true;
  166. worksheet.Cells[26, 28, 26, 34].Merge = true;
  167. worksheet.Column(1).Width = 5;
  168. worksheet.Column(2).Width = 12;
  169. worksheet.Column(3).Width = 12;
  170. worksheet.Column(4).Width = 12;
  171. worksheet.Column(5).Width = 12;
  172. worksheet.Column(6).Width = 12;
  173. worksheet.Column(7).Width = 12;
  174. worksheet.Column(8).Width = 12;
  175. worksheet.Column(9).Width = 12;
  176. worksheet.Column(10).Width = 12;
  177. worksheet.Column(11).Width = 12;
  178. worksheet.Column(12).Width = 12;
  179. worksheet.Column(13).Width = 2;
  180. worksheet.Column(14).Width = 2;
  181. worksheet.Column(15).Width = 5;
  182. worksheet.Column(16).Width = 12;
  183. worksheet.Column(17).Width = 12;
  184. worksheet.Column(18).Width = 12;
  185. worksheet.Column(19).Width = 12;
  186. worksheet.Column(20).Width = 12;
  187. worksheet.Column(21).Width = 12;
  188. worksheet.Column(22).Width = 12;
  189. worksheet.Column(23).Width = 12;
  190. worksheet.Column(24).Width = 12;
  191. worksheet.Column(22).Width = 12;
  192. worksheet.Column(23).Width = 12;
  193. worksheet.Column(25).Width = 2;
  194. worksheet.Column(26).Width = 5;
  195. worksheet.Column(27).Width = 12;
  196. worksheet.Column(28).Width = 12;
  197. worksheet.Column(29).Width = 12;
  198. worksheet.Column(30).Width = 12;
  199. worksheet.Column(31).Width = 12;
  200. worksheet.Column(32).Width = 12;
  201. worksheet.Column(33).Width = 12;
  202. worksheet.Column(34).Width = 12;
  203. worksheet.Column(35).Width = 12;
  204. #endregion
  205. for (int i = 0; i < machineOEE.Count; i++)
  206. {
  207. worksheet.Cells[i + 2, 1].Value = i + 1;
  208. worksheet.Cells[i + 2, 2].Value = machineOEE[i].Date + " " + machineOEE[i].Shift;
  209. worksheet.Cells[i + 2, 3].Value = (int)machineOEE[i].RunTimeRate;
  210. worksheet.Cells[i + 2, 4].Value = (int)machineOEE[i].IdelTimeRate;
  211. worksheet.Cells[i + 2, 5].Value = (int)machineOEE[i].DownTimeRate;
  212. worksheet.Cells[i + 2, 6].Value = (int)machineOEE[i].LoadMATTimeRate;
  213. worksheet.Cells[i + 2, 7].Value = machineOEE[i].Outputs;
  214. worksheet.Cells[i + 2, 8].Value = machineOEE[i].RunTime / 60;
  215. worksheet.Cells[i + 2, 9].Value = machineOEE[i].IdelTime / 60;
  216. worksheet.Cells[i + 2, 10].Value = machineOEE[i].DownTime / 60;
  217. worksheet.Cells[i + 2, 11].Value = machineOEE[i].LoadMATTime / 60;
  218. worksheet.Cells[i + 2, 12].Value
  219. = (machineOEE[i].RunTime + machineOEE[i].IdelTime + machineOEE[i].DownTime + machineOEE[i].LoadMATTime) / 60;
  220. }
  221. if (machineHourDatas != null)
  222. {
  223. if (machineHourDatas.Count == 24)
  224. {
  225. {
  226. int autoSum = 0;
  227. int alarmTimeSum = 0;
  228. int idelSum = 0;
  229. int outputSum = 0;
  230. double ttSum = 0;
  231. int alarmSum = 0;
  232. int loadTimeSum = 0;
  233. for (int i = 0; i < 12; i++)
  234. {
  235. int auto = machineHourDatas[i].AutoRunTime.Value / 60;
  236. autoSum += auto;
  237. int alarmTime = machineHourDatas[i].AlarmTime.Value / 60;
  238. alarmTimeSum += alarmTime;
  239. int idel = machineHourDatas[i].IdleTime.Value / 60;
  240. idelSum += idel;
  241. int output = machineHourDatas[i].OutPut.Value;
  242. outputSum += output;
  243. double tt = machineHourDatas[i].TT;
  244. //ttSum += tt;
  245. int alarm = machineHourDatas[i].AlarmSum.Value;
  246. alarmSum += alarm;
  247. int loadTime = machineHourDatas[i].LoadMATTime.Value / 60;
  248. loadTimeSum += loadTime;
  249. worksheet.Cells[i + 3, 15].Value = i + 1;
  250. worksheet.Cells[i + 3, 16].Value = machineHourDatas[i].Period;
  251. worksheet.Cells[i + 3, 17].Value = machineHourDatas[i].ModuleType;
  252. worksheet.Cells[i + 3, 18].Value = auto;
  253. worksheet.Cells[i + 3, 19].Value = alarmTime;
  254. worksheet.Cells[i + 3, 20].Value = idel;
  255. worksheet.Cells[i + 3, 21].Value = loadTime;
  256. worksheet.Cells[i + 3, 22].Value = output;
  257. worksheet.Cells[i + 3, 23].Value = Math.Round(tt, 2);
  258. worksheet.Cells[i + 3, 24].Value = alarm;
  259. }
  260. worksheet.Cells[15, 15].Value = "合计";
  261. worksheet.Cells[15, 15, 15, 17].Merge = true;
  262. worksheet.Cells[15, 18].Value = autoSum;
  263. worksheet.Cells[15, 19].Value = alarmTimeSum;
  264. worksheet.Cells[15, 20].Value = idelSum;
  265. worksheet.Cells[15, 21].Value = loadTimeSum;
  266. worksheet.Cells[15, 22].Value = outputSum;
  267. if (outputSum != 0)
  268. ttSum = autoSum * 60.0 / outputSum;
  269. else
  270. ttSum = 0;
  271. worksheet.Cells[15, 23].Value = Math.Round(ttSum, 2);
  272. worksheet.Cells[15, 24].Value = alarmSum;
  273. var faults = _faultService.GetFaultFrequencyTop10(machineId, startTime, startTime.AddHours(12), "安全门,门禁,提示上料,提示卸料,门锁,门打开,请选择LOT生产");
  274. for (int i = 0; i < faults.Count; i++)
  275. {
  276. worksheet.Cells[17 + i, 15].Value = i + 1;
  277. worksheet.Cells[17 + i, 16].Value = faults[i].FaultCode;
  278. worksheet.Cells[17 + i, 17].Value = faults[i].FaultInfo;
  279. worksheet.Cells[17 + i, 24].Value = faults[i].Count;
  280. }
  281. }
  282. {
  283. int autoSum = 0;
  284. int alarmTimeSum = 0;
  285. int idelSum = 0;
  286. int outputSum = 0;
  287. double ttSum = 0;
  288. int alarmSum = 0;
  289. int loadTimeSum = 0;
  290. for (int i = 12; i < 24; i++)
  291. {
  292. int auto = machineHourDatas[i].AutoRunTime.Value / 60;
  293. autoSum += auto;
  294. int alarmTime = machineHourDatas[i].AlarmTime.Value / 60;
  295. alarmTimeSum += alarmTime;
  296. int idel = machineHourDatas[i].IdleTime.Value / 60;
  297. idelSum += idel;
  298. int output = machineHourDatas[i].OutPut.Value;
  299. outputSum += output;
  300. double tt = machineHourDatas[i].TT;
  301. //ttSum += tt;
  302. int alarm = machineHourDatas[i].AlarmSum.Value;
  303. alarmSum += alarm;
  304. int loadTime = machineHourDatas[i].LoadMATTime.Value / 60;
  305. loadTimeSum += loadTime;
  306. worksheet.Cells[i - 12 + 3, 26].Value = i + 1;
  307. worksheet.Cells[i - 12 + 3, 27].Value = machineHourDatas[i].Period;
  308. worksheet.Cells[i - 12 + 3, 28].Value = machineHourDatas[i].ModuleType;
  309. worksheet.Cells[i - 12 + 3, 29].Value = auto;
  310. worksheet.Cells[i - 12 + 3, 30].Value = alarmTime;
  311. worksheet.Cells[i - 12 + 3, 31].Value = idel;
  312. worksheet.Cells[i - 12 + 3, 32].Value = loadTime;
  313. worksheet.Cells[i - 12 + 3, 33].Value = output;
  314. worksheet.Cells[i - 12 + 3, 34].Value = Math.Round(tt, 2);
  315. worksheet.Cells[i - 12 + 3, 35].Value = alarm;
  316. }
  317. worksheet.Cells[15, 26].Value = "合计";
  318. worksheet.Cells[15, 26, 15, 28].Merge = true;
  319. worksheet.Cells[15, 29].Value = autoSum;
  320. worksheet.Cells[15, 30].Value = alarmTimeSum;
  321. worksheet.Cells[15, 31].Value = idelSum;
  322. worksheet.Cells[15, 32].Value = loadTimeSum;
  323. worksheet.Cells[15, 33].Value = outputSum;
  324. if (outputSum != 0)
  325. ttSum = autoSum * 60.0 / outputSum;
  326. else
  327. ttSum = 0;
  328. worksheet.Cells[15, 34].Value = Math.Round(ttSum, 2);
  329. worksheet.Cells[15, 35].Value = alarmSum;
  330. var faults = _faultService.GetFaultFrequencyTop10(machineId, startTime.AddHours(12), startTime.AddHours(24), "安全门,门禁,提示上料,提示卸料,门锁,门打开,请选择LOT生产");
  331. for (int i = 0; i < faults.Count; i++)
  332. {
  333. worksheet.Cells[17 + i, 26].Value = i + 1;
  334. worksheet.Cells[17 + i, 27].Value = faults[i].FaultCode;
  335. worksheet.Cells[17 + i, 28].Value = faults[i].FaultInfo;
  336. worksheet.Cells[17 + i, 35].Value = faults[i].Count;
  337. }
  338. }
  339. }
  340. }
  341. //var faultFrequencys = _faultService.GetFaultFrequencyTop10ByShift(
  342. // machine.Id, dataStartTime, endTime, "安全门,门禁,提示上料,提示卸料,门锁");
  343. //var tables = new FaultFrequencyByShiftTable(faultFrequencys);
  344. //ExcelWorksheet worksheet1 = package.Workbook.Worksheets.Add($"{line.Name} {machine.Name} 报警");
  345. //worksheet1.View.ZoomScale = 80;
  346. //worksheet1.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
  347. //worksheet1.Column(1).Width = 5;
  348. //worksheet1.Column(2).Width = 10;
  349. //worksheet1.Column(3).Width = 30;
  350. //worksheet1.Cells[1, 1].Value = "NO";
  351. //worksheet1.Cells[1, 2].Value = "Code";
  352. //worksheet1.Cells[1, 3].Value = "Name";
  353. //for (int i = 0; i < tables.Shifts.Count(); i++)
  354. //{
  355. // worksheet1.Column(i + 4).Width = 20;
  356. // worksheet1.Cells[1, i + 4].Value = tables.Shifts[i];
  357. //}
  358. //for (int i = 0; i < tables.Nos.Count; i++)
  359. //{
  360. // worksheet1.Cells[i + 2, 1].Value = tables.Nos[i];
  361. // worksheet1.Cells[i + 2, 2].Value = tables.FaultCodes[i];
  362. // worksheet1.Cells[i + 2, 3].Value = tables.FaultInfos[i];
  363. // for (int j = 0; j < tables.Shifts.Count(); j++)
  364. // {
  365. // worksheet1.Cells[i + 2, j + 4].Value = tables.Counts[j, i];
  366. // }
  367. //}
  368. //var databar = worksheet1.Cells["D2:Q33"].ConditionalFormatting.AddDatabar(Color.Red);
  369. //// 创建数据条条件格式对象
  370. //ExcelConditionalFormattingDataBar dataBarConditionalFormatting = (ExcelConditionalFormattingDataBar)worksheet.Cells["D2:Q33"].ConditionalFormatting;
  371. //// 设置渐变填充
  372. //dataBarConditionalFormatting.BarFill.Type = ExcelFillStyle.DarkGray;
  373. ExcelChartSerie chartSerie;
  374. ExcelChart chart = worksheet.Drawings.AddChart("chart", eChartType.ColumnStacked);
  375. chart.YAxis.MinValue = 0;
  376. chart.YAxis.MaxValue = 100;
  377. chart.YAxis.Format = "0 \"%\"";
  378. chart.Legend.Position = eLegendPosition.Bottom;
  379. chart.Legend.Add();
  380. chart.Title.Text = "设备稼动曲线"; //设置图表的名称
  381. chart.SetPosition(540, 20); //设置图表位置
  382. chart.SetSize(1000, 400); //设置图表大小
  383. chart.ShowHiddenData = true;
  384. chartSerie = chart.Series.Add(worksheet.Cells[2, 3, machineOEE.Count + 1, 3], worksheet.Cells[2, 2, machineOEE.Count + 1, 2]);
  385. chartSerie.HeaderAddress = worksheet.Cells[1, 3];
  386. chartSerie = chart.Series.Add(worksheet.Cells[2, 4, machineOEE.Count + 1, 4], worksheet.Cells[2, 2, machineOEE.Count + 1, 2]);
  387. chartSerie.HeaderAddress = worksheet.Cells[1, 4];
  388. chartSerie = chart.Series.Add(worksheet.Cells[2, 5, machineOEE.Count + 1, 5], worksheet.Cells[2, 2, machineOEE.Count + 1, 2]);
  389. chartSerie.HeaderAddress = worksheet.Cells[1, 5];
  390. chartSerie = chart.Series.Add(worksheet.Cells[2, 6, machineOEE.Count + 1, 6], worksheet.Cells[2, 2, machineOEE.Count + 1, 2]);
  391. chartSerie.HeaderAddress = worksheet.Cells[1, 6];
  392. //var chartType2 = chart.PlotArea.ChartTypes.Add(eChartType.Line);
  393. //chartType2.UseSecondaryAxis = true;
  394. //chartType2.YAxis.Format = "0 \"pcs\"";
  395. //chartSerie = chartType2.Series.Add(worksheet.Cells[2, 6, machineOEE.Count + 1, 6], worksheet.Cells[2, 2, machineOEE.Count + 1, 2]);
  396. //chartSerie.HeaderAddress = worksheet.Cells[1, 6];
  397. foreach (var item in chart.Series)
  398. {
  399. var pieSerie = (ExcelBarChartSerie)item;
  400. pieSerie.DataLabel.ShowValue = true;
  401. }
  402. ExcelChart chart1 = worksheet.Drawings.AddChart("chart1", eChartType.ColumnStacked);
  403. chart1.Legend.Position = eLegendPosition.Bottom;
  404. chart1.Legend.Add();
  405. chart1.Title.Text = "设备产能曲线"; //设置图表的名称
  406. chart1.SetPosition(540, 1030); //设置图表位置
  407. chart1.SetSize(1000, 400); //设置图表大小
  408. chart1.ShowHiddenData = true;
  409. chart1.YAxis.Format = "0 \"pcs\"";
  410. ExcelChartSerie chartSerie1;
  411. chartSerie1 = chart1.Series.Add(worksheet.Cells[2, 7, machineOEE.Count + 1, 7], worksheet.Cells[2, 2, machineOEE.Count + 1, 2]);
  412. chartSerie1.HeaderAddress = worksheet.Cells[1, 7];
  413. foreach (var item in chart1.Series)
  414. {
  415. var pieSerie = (ExcelBarChartSerie)item;
  416. pieSerie.DataLabel.ShowValue = true;
  417. }
  418. package.Save();
  419. }
  420. string ReceiverAppSettingName = UtilizationRateEmail["ReceiverAppSettingName"].ToString();
  421. if (ReceiverAppSettingName == null || String.IsNullOrEmpty(ReceiverAppSettingName))
  422. {
  423. LogerHelper.RecordLogTxt($"EquipmentOperationReport Group-{count} ReceiverAppSettingName is null");
  424. continue;
  425. }
  426. SendMail(
  427. MailType.Message,
  428. ReceiverAppSettingName,
  429. "",
  430. "",
  431. "EQP.EAPAUTO01@eink.com",
  432. "",
  433. $"稼动数据 -- {dateNowStr}",
  434. "",
  435. new string[] { path },
  436. new string[] { dateNowStr },
  437. Encoding.UTF8);
  438. LogerHelper.RecordLogTxt($"EquipmentOperationReport Group-{count} Send over, ReceiverAppSettingName:【{ReceiverAppSettingName}】, file:【{path}】, EmailFileName:【{dateNowStr}】");
  439. }
  440. return true;
  441. }
  442. catch (Exception ex)
  443. {
  444. LogerHelper.RecordLogTxt($"EquipmentOperationReport Exception, Message:{ex.Message}, StackTrace:{ex.StackTrace}");
  445. return false;
  446. }
  447. }
  448. }
  449. }