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.IRepositories; 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; private readonly IUnitOfWork _unitOfWork; public ReportFormController( IReportFormService reportFormService, IOEEService oeeService, IExcelService excelService, IUnitOfWork unitOfWork) { _reportFormService = reportFormService; _oeeService = oeeService; _excelService = excelService; _unitOfWork = unitOfWork; } [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.Success(reportFormDto)); } [HttpPost] public IActionResult GetMachineStatisticV1(string id, DateTime startTime, DateTime endTime) { //MachineOEE machine = new MachineOEE(); List lst = _oeeService.GetOEE(id, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd")); return Ok(ResultDto>.Success(lst)); } //[HttpPost] //public IActionResult GetMachineStatisticV2(string id, DateTime startTime, DateTime endTime, int peroid) //{ // //MachineOEE machine = new MachineOEE(); // Dictionary> lst = new Dictionary>(); // if (peroid == 3) // { // lst = _oeeService.GetOEEByPeriod(id, // startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid,0); // } // else // { // lst = _oeeService.GetOEEByPeriod(id, // startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid, 0); // } // return Ok(ResultDto>>.Success(lst)); //} [HttpPost] public IActionResult GetMachineStatisticV3(string id, DateTime startTime, DateTime endTime, int peroid, int shift) { List lst = new List(); if (peroid == 3) { lst = _oeeService.GetOEEByPeriodV2(id, startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid, shift); } else { lst = _oeeService.GetOEEByPeriodV2(id, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid, shift); } return Ok(ResultDto>.Success(lst)); } /// /// /// /// /// /// /// //0:按班;1:天;2:周;3:月 /// //peroid为0时有效,0:汇总,1:白班数据,2:夜班数据 /// [HttpPost] public IActionResult GetMachineStatisticV4(string id, DateTime startTime, DateTime endTime, int peroid, int dayOrnight) { var list = _oeeService.GetOEEByPeriod(id, startTime, endTime, peroid, dayOrnight); return Ok(ResultDto>>.Success(list)); } [HttpPost] public IActionResult GetOEEExtendSetting(string ids) { var idList = ids.Split(','); var machine = _unitOfWork.Repository().GetList().Where(x => idList.Contains(x.Id)); Dictionary DicOEEExtend = new Dictionary(); if (machine != null && machine.Count() != 0) { foreach (var item in machine) { DicOEEExtend.Add(item.Id, string.IsNullOrEmpty(item.OEEExtendSettings) ? "" : item.OEEExtendSettings); } } return Ok(ResultDto>.Success(DicOEEExtend)); } private List GetOee(string moduleType, IEnumerable oees) { var result = new List(); 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 GetCapacity(string moduleType, IEnumerable oees) { var result = new List(); 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 GetModuleTypes(IEnumerable oees) { List result = new List(); foreach (var item in oees) { if (!result.Contains(item.ModuleType)) { result.Add(item.ModuleType); } } return result; } } }