using AutoMapper; using Core.Dtos; using NPOI.Util; using ProductionLineMonitor.Application.Services.OEEService.Dtos; using ProductionLineMonitor.Core.IRepositories; using ProductionLineMonitor.Core.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProductionLineMonitor.Application.Services.OEEService { public class OEEService : IOEEService { private readonly IUnitOfWork _unitOfWork; public OEEService(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } public List GetOEE(string machineId, string startDate, string endDate) { List OEES = new List(); DateTime startTime = DateTime.Parse($"{startDate} 08:00:00"); DateTime endTime = DateTime.Parse($"{endDate} 08:00:00").AddDays(1); List outputs = _unitOfWork.MachineOutPutPerHourRepository .GetList( x => x.MachineId == machineId && x.DataTime >= startTime && x.DataTime < endTime) .OrderBy( o => o.DataTime) .ToList(); for (var i = startTime; i < endTime; i = i.AddHours(12)) { DateTime tempTime = i.AddHours(12); MachineOEEInfo machineOEE = new MachineOEEInfo { StartTime = i, EndTime = tempTime, OutPutPerHours = outputs.FindAll(x => x.DataTime >= i && x.DataTime < tempTime) }; machineOEE.CalculateOEE(); OEES.Add(machineOEE); } return OEES; } } }