ReportFormController.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.Models;
  7. using ProductionLineMonitor.Core.Services;
  8. using ProductionLineMonitor.Core.Utils;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. namespace ProductionLineMonitor.Web.Controllers
  13. {
  14. public class ReportFormController : BaseController
  15. {
  16. private readonly IReportFormService _reportFormService;
  17. private readonly IOEEService _oeeService;
  18. private readonly IExcelService _excelService;
  19. public ReportFormController(
  20. IReportFormService reportFormService,
  21. IOEEService oeeService,
  22. IExcelService excelService)
  23. {
  24. _reportFormService = reportFormService;
  25. _oeeService = oeeService;
  26. _excelService = excelService;
  27. }
  28. [HttpGet]
  29. public IActionResult Index()
  30. {
  31. //_excelService.EquipmentOperationReport(DateTime.Parse("2024-09-12 08:00:00"));
  32. return View();
  33. }
  34. [HttpGet]
  35. public IActionResult EquipmentOperationReport(DateTime dateTime)
  36. {
  37. _excelService.EquipmentOperationReport(dateTime);
  38. return Ok();
  39. }
  40. [HttpPost]
  41. public IActionResult GetMachineStatistic(string id, DateTime startTime, DateTime endTime)
  42. {
  43. ReportFormDto reportFormDto = new ReportFormDto();
  44. reportFormDto.Date = DateTimeHelper.GetDate(startTime, endTime);
  45. var oees = _reportFormService.GetMachineOEE(id, startTime, endTime.AddDays(1));
  46. var moduleTypes = GetModuleTypes(oees);
  47. foreach (var moduleType in moduleTypes)
  48. {
  49. Form form = new Form();
  50. form.Name = moduleType;
  51. form.Oee = GetOee(moduleType, oees);
  52. form.Capacity = GetCapacity(moduleType, oees);
  53. reportFormDto.Forms.Add(form);
  54. }
  55. return Ok(ResultDto<ReportFormDto>.Success(reportFormDto));
  56. }
  57. [HttpPost]
  58. public IActionResult GetMachineStatisticV1(string id, DateTime startTime, DateTime endTime)
  59. {
  60. //MachineOEE machine = new MachineOEE();
  61. List<MachineOEEInfo> lst = _oeeService.GetOEE(id,
  62. startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  63. return Ok(ResultDto<List<MachineOEEInfo>>.Success(lst));
  64. }
  65. [HttpPost]
  66. public IActionResult GetMachineStatisticV2(string id, DateTime startTime, DateTime endTime, int peroid)
  67. {
  68. //MachineOEE machine = new MachineOEE();
  69. Dictionary<string, List<MachineOEEInfoByPeriod>> lst = new Dictionary<string, List<MachineOEEInfoByPeriod>>();
  70. if (peroid == 3)
  71. {
  72. lst = _oeeService.GetOEEByPeriod(id,
  73. startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid);
  74. }
  75. else
  76. {
  77. lst = _oeeService.GetOEEByPeriod(id,
  78. startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid);
  79. }
  80. return Ok(ResultDto<Dictionary<string, List<MachineOEEInfoByPeriod>>>.Success(lst));
  81. }
  82. private List<object[]> GetOee(string moduleType, IEnumerable<MachineStatistic> oees)
  83. {
  84. var result = new List<object[]>();
  85. var data = oees.Where(x => x.ModuleType == moduleType);
  86. foreach (var item in data)
  87. {
  88. object[] o = new object[2];
  89. o[0] = item.Date.ToString("yyyy-MM-dd");
  90. if (item.OEE != null)
  91. {
  92. o[1] = Math.Round(item.OEE.Value * 100, 2);
  93. }
  94. result.Add(o);
  95. }
  96. return result;
  97. }
  98. private List<object[]> GetCapacity(string moduleType, IEnumerable<MachineStatistic> oees)
  99. {
  100. var result = new List<object[]>();
  101. var data = oees.Where(x => x.ModuleType == moduleType);
  102. foreach (var item in data)
  103. {
  104. object[] o = new object[2];
  105. o[0] = item.Date.ToString("yyyy-MM-dd");
  106. o[1] = item.Capacity;
  107. result.Add(o);
  108. }
  109. return result;
  110. }
  111. private List<string> GetModuleTypes(IEnumerable<MachineStatistic> oees)
  112. {
  113. List<string> result = new List<string>();
  114. foreach (var item in oees)
  115. {
  116. if (!result.Contains(item.ModuleType))
  117. {
  118. result.Add(item.ModuleType);
  119. }
  120. }
  121. return result;
  122. }
  123. }
  124. }