ReportFormController.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using Microsoft.AspNetCore.Mvc;
  2. using ProductionLineMonitor.Application.Services;
  3. using ProductionLineMonitor.Application.Services.OEEService;
  4. using ProductionLineMonitor.Application.Services.OEEService.Dtos;
  5. using ProductionLineMonitor.Core.Dtos;
  6. using ProductionLineMonitor.Core.IRepositories;
  7. using ProductionLineMonitor.Core.Models;
  8. using ProductionLineMonitor.Core.Services;
  9. using ProductionLineMonitor.Core.Utils;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. namespace ProductionLineMonitor.Web.Controllers
  14. {
  15. public class ReportFormController : BaseController
  16. {
  17. private readonly IReportFormService _reportFormService;
  18. private readonly IOEEService _oeeService;
  19. private readonly IExcelService _excelService;
  20. private readonly IUnitOfWork _unitOfWork;
  21. public ReportFormController(
  22. IReportFormService reportFormService,
  23. IOEEService oeeService,
  24. IExcelService excelService,
  25. IUnitOfWork unitOfWork)
  26. {
  27. _reportFormService = reportFormService;
  28. _oeeService = oeeService;
  29. _excelService = excelService;
  30. _unitOfWork = unitOfWork;
  31. }
  32. [HttpGet]
  33. public IActionResult Index()
  34. {
  35. //_excelService.EquipmentOperationReport(DateTime.Parse("2024-09-12 08:00:00"));
  36. return View();
  37. }
  38. [HttpGet]
  39. public IActionResult EquipmentOperationReport(DateTime dateTime)
  40. {
  41. _excelService.EquipmentOperationReport(dateTime);
  42. return Ok();
  43. }
  44. [HttpPost]
  45. public IActionResult GetMachineStatistic(string id, DateTime startTime, DateTime endTime)
  46. {
  47. ReportFormDto reportFormDto = new ReportFormDto();
  48. reportFormDto.Date = DateTimeHelper.GetDate(startTime, endTime);
  49. var oees = _reportFormService.GetMachineOEE(id, startTime, endTime.AddDays(1));
  50. var moduleTypes = GetModuleTypes(oees);
  51. foreach (var moduleType in moduleTypes)
  52. {
  53. Form form = new Form();
  54. form.Name = moduleType;
  55. form.Oee = GetOee(moduleType, oees);
  56. form.Capacity = GetCapacity(moduleType, oees);
  57. reportFormDto.Forms.Add(form);
  58. }
  59. return Ok(ResultDto<ReportFormDto>.Success(reportFormDto));
  60. }
  61. [HttpPost]
  62. public IActionResult GetMachineStatisticV1(string id, DateTime startTime, DateTime endTime)
  63. {
  64. //MachineOEE machine = new MachineOEE();
  65. List<MachineOEEInfo> lst = _oeeService.GetOEE(id,
  66. startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  67. return Ok(ResultDto<List<MachineOEEInfo>>.Success(lst));
  68. }
  69. //[HttpPost]
  70. //public IActionResult GetMachineStatisticV2(string id, DateTime startTime, DateTime endTime, int peroid)
  71. //{
  72. // //MachineOEE machine = new MachineOEE();
  73. // Dictionary<string, List<MachineOEEInfoByPeriod>> lst = new Dictionary<string, List<MachineOEEInfoByPeriod>>();
  74. // if (peroid == 3)
  75. // {
  76. // lst = _oeeService.GetOEEByPeriod(id,
  77. // startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid,0);
  78. // }
  79. // else
  80. // {
  81. // lst = _oeeService.GetOEEByPeriod(id,
  82. // startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid, 0);
  83. // }
  84. // return Ok(ResultDto<Dictionary<string, List<MachineOEEInfoByPeriod>>>.Success(lst));
  85. //}
  86. [HttpPost]
  87. public IActionResult GetMachineStatisticV3(string id, DateTime startTime, DateTime endTime, int peroid, int shift)
  88. {
  89. List<MachineOEEInfoByPeriod> lst = new List<MachineOEEInfoByPeriod>();
  90. if (peroid == 3)
  91. {
  92. lst = _oeeService.GetOEEByPeriodV2(id,
  93. startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid, shift);
  94. }
  95. else
  96. {
  97. lst = _oeeService.GetOEEByPeriodV2(id,
  98. startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid, shift);
  99. }
  100. return Ok(ResultDto<List<MachineOEEInfoByPeriod>>.Success(lst));
  101. }
  102. /// <summary>
  103. ///
  104. /// </summary>
  105. /// <param name="id"></param>
  106. /// <param name="startTime"></param>
  107. /// <param name="endTime"></param>
  108. /// <param name="peroid"></param>//0:按班;1:天;2:周;3:月
  109. /// <param name="dayOrnight"></param>//peroid为0时有效,0:汇总,1:白班数据,2:夜班数据
  110. /// <returns></returns>
  111. [HttpPost]
  112. public IActionResult GetMachineStatisticV4(string id, DateTime startTime, DateTime endTime, int peroid, int dayOrnight)
  113. {
  114. var list = _oeeService.GetOEEByPeriod(id, startTime, endTime, peroid, dayOrnight);
  115. return Ok(ResultDto<Dictionary<string, List<MachineOEEInfoByPeriod>>>.Success(list));
  116. }
  117. [HttpPost]
  118. public IActionResult GetOEEExtendSetting(string ids)
  119. {
  120. var idList = ids.Split(',');
  121. var machine = _unitOfWork.Repository<Machine>().GetList().Where(x => idList.Contains(x.Id));
  122. Dictionary<string, string> DicOEEExtend = new Dictionary<string, string>();
  123. if (machine != null && machine.Count() != 0)
  124. {
  125. foreach (var item in machine)
  126. {
  127. DicOEEExtend.Add(item.Id, string.IsNullOrEmpty(item.OEEExtendSettings) ? "" : item.OEEExtendSettings);
  128. }
  129. }
  130. return Ok(ResultDto<Dictionary<string, string>>.Success(DicOEEExtend));
  131. }
  132. private List<object[]> GetOee(string moduleType, IEnumerable<MachineStatistic> oees)
  133. {
  134. var result = new List<object[]>();
  135. var data = oees.Where(x => x.ModuleType == moduleType);
  136. foreach (var item in data)
  137. {
  138. object[] o = new object[2];
  139. o[0] = item.Date.ToString("yyyy-MM-dd");
  140. if (item.OEE != null)
  141. {
  142. o[1] = Math.Round(item.OEE.Value * 100, 2);
  143. }
  144. result.Add(o);
  145. }
  146. return result;
  147. }
  148. private List<object[]> GetCapacity(string moduleType, IEnumerable<MachineStatistic> oees)
  149. {
  150. var result = new List<object[]>();
  151. var data = oees.Where(x => x.ModuleType == moduleType);
  152. foreach (var item in data)
  153. {
  154. object[] o = new object[2];
  155. o[0] = item.Date.ToString("yyyy-MM-dd");
  156. o[1] = item.Capacity;
  157. result.Add(o);
  158. }
  159. return result;
  160. }
  161. private List<string> GetModuleTypes(IEnumerable<MachineStatistic> oees)
  162. {
  163. List<string> result = new List<string>();
  164. foreach (var item in oees)
  165. {
  166. if (!result.Contains(item.ModuleType))
  167. {
  168. result.Add(item.ModuleType);
  169. }
  170. }
  171. return result;
  172. }
  173. }
  174. }