123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using Microsoft.AspNetCore.Mvc;
- using ProductionLineMonitor.Application.Services;
- using ProductionLineMonitor.Application.Services.OEEService;
- using ProductionLineMonitor.Application.Services.OEEService.Dtos;
- using ProductionLineMonitor.Core.Dtos;
- using ProductionLineMonitor.Core.Models;
- using ProductionLineMonitor.Core.Services;
- using ProductionLineMonitor.Core.Utils;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ProductionLineMonitor.Web.Controllers
- {
- public class ReportFormController : BaseController
- {
- private readonly IReportFormService _reportFormService;
- private readonly IOEEService _oeeService;
- private readonly IExcelService _excelService;
- public ReportFormController(
- IReportFormService reportFormService,
- IOEEService oeeService,
- IExcelService excelService)
- {
- _reportFormService = reportFormService;
- _oeeService = oeeService;
- _excelService = excelService;
- }
- [HttpGet]
- public IActionResult Index()
- {
- //_excelService.EquipmentOperationReport(DateTime.Parse("2024-09-12 08:00:00"));
- return View();
- }
- [HttpGet]
- public IActionResult EquipmentOperationReport(DateTime dateTime)
- {
- _excelService.EquipmentOperationReport(dateTime);
- return Ok();
- }
- [HttpPost]
- public IActionResult GetMachineStatistic(string id, DateTime startTime, DateTime endTime)
- {
- ReportFormDto reportFormDto = new ReportFormDto();
- reportFormDto.Date = DateTimeHelper.GetDate(startTime, endTime);
- var oees = _reportFormService.GetMachineOEE(id, startTime, endTime.AddDays(1));
- var moduleTypes = GetModuleTypes(oees);
- foreach (var moduleType in moduleTypes)
- {
- Form form = new Form();
- form.Name = moduleType;
- form.Oee = GetOee(moduleType, oees);
- form.Capacity = GetCapacity(moduleType, oees);
- reportFormDto.Forms.Add(form);
- }
- return Ok(ResultDto<ReportFormDto>.Success(reportFormDto));
- }
- [HttpPost]
- public IActionResult GetMachineStatisticV1(string id, DateTime startTime, DateTime endTime)
- {
- //MachineOEE machine = new MachineOEE();
- List<MachineOEEInfo> lst = _oeeService.GetOEE(id,
- startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
- return Ok(ResultDto<List<MachineOEEInfo>>.Success(lst));
- }
- private List<object[]> GetOee(string moduleType, IEnumerable<MachineStatistic> oees)
- {
- var result = new List<object[]>();
- var data = oees.Where(x => x.ModuleType == moduleType);
- foreach (var item in data)
- {
- object[] o = new object[2];
- o[0] = item.Date.ToString("yyyy-MM-dd");
- if (item.OEE != null)
- {
- o[1] = Math.Round(item.OEE.Value * 100, 2);
- }
- result.Add(o);
- }
- return result;
- }
- private List<object[]> GetCapacity(string moduleType, IEnumerable<MachineStatistic> oees)
- {
- var result = new List<object[]>();
- var data = oees.Where(x => x.ModuleType == moduleType);
- foreach (var item in data)
- {
- object[] o = new object[2];
- o[0] = item.Date.ToString("yyyy-MM-dd");
- o[1] = item.Capacity;
- result.Add(o);
- }
- return result;
- }
- private List<string> GetModuleTypes(IEnumerable<MachineStatistic> oees)
- {
- List<string> result = new List<string>();
- foreach (var item in oees)
- {
- if (!result.Contains(item.ModuleType))
- {
- result.Add(item.ModuleType);
- }
- }
- return result;
- }
- }
- }
|