1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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<MachineOEEInfo> GetOEE(string machineId, string startDate, string endDate)
- {
- List<MachineOEEInfo> OEES = new List<MachineOEEInfo>();
-
- DateTime startTime = DateTime.Parse($"{startDate} 08:00:00");
- DateTime endTime = DateTime.Parse($"{endDate} 08:00:00").AddDays(1);
-
- List<MachineOutPutPerHour> 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;
- }
- }
- }
|