ReportFormController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. private List<object[]> GetOee(string moduleType, IEnumerable<MachineStatistic> oees)
  66. {
  67. var result = new List<object[]>();
  68. var data = oees.Where(x => x.ModuleType == moduleType);
  69. foreach (var item in data)
  70. {
  71. object[] o = new object[2];
  72. o[0] = item.Date.ToString("yyyy-MM-dd");
  73. if (item.OEE != null)
  74. {
  75. o[1] = Math.Round(item.OEE.Value * 100, 2);
  76. }
  77. result.Add(o);
  78. }
  79. return result;
  80. }
  81. private List<object[]> GetCapacity(string moduleType, IEnumerable<MachineStatistic> oees)
  82. {
  83. var result = new List<object[]>();
  84. var data = oees.Where(x => x.ModuleType == moduleType);
  85. foreach (var item in data)
  86. {
  87. object[] o = new object[2];
  88. o[0] = item.Date.ToString("yyyy-MM-dd");
  89. o[1] = item.Capacity;
  90. result.Add(o);
  91. }
  92. return result;
  93. }
  94. private List<string> GetModuleTypes(IEnumerable<MachineStatistic> oees)
  95. {
  96. List<string> result = new List<string>();
  97. foreach (var item in oees)
  98. {
  99. if (!result.Contains(item.ModuleType))
  100. {
  101. result.Add(item.ModuleType);
  102. }
  103. }
  104. return result;
  105. }
  106. }
  107. }