OEEService.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using AutoMapper;
  2. using Core.Dtos;
  3. using NPOI.Util;
  4. using ProductionLineMonitor.Application.Services.OEEService.Dtos;
  5. using ProductionLineMonitor.Core.IRepositories;
  6. using ProductionLineMonitor.Core.Models;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. namespace ProductionLineMonitor.Application.Services.OEEService
  12. {
  13. public class OEEService : IOEEService
  14. {
  15. private readonly IUnitOfWork _unitOfWork;
  16. public OEEService(IUnitOfWork unitOfWork)
  17. {
  18. _unitOfWork = unitOfWork;
  19. }
  20. public List<MachineOEEInfo> GetOEE(string machineId, string startDate, string endDate)
  21. {
  22. List<MachineOEEInfo> OEES = new List<MachineOEEInfo>();
  23. DateTime startTime = DateTime.Parse($"{startDate} 08:00:00");
  24. DateTime endTime = DateTime.Parse($"{endDate} 08:00:00").AddDays(1);
  25. List<MachineOutPutPerHour> outputs = _unitOfWork.MachineOutPutPerHourRepository
  26. .GetList(
  27. x =>
  28. x.MachineId == machineId &&
  29. x.DataTime >= startTime &&
  30. x.DataTime < endTime)
  31. .OrderBy(
  32. o =>
  33. o.DataTime)
  34. .ToList();
  35. for (var i = startTime; i < endTime; i = i.AddHours(12))
  36. {
  37. DateTime tempTime = i.AddHours(12);
  38. MachineOEEInfo machineOEE = new MachineOEEInfo
  39. {
  40. StartTime = i,
  41. EndTime = tempTime,
  42. OutPutPerHours = outputs.FindAll(x => x.DataTime >= i && x.DataTime < tempTime)
  43. };
  44. machineOEE.CalculateOEE();
  45. OEES.Add(machineOEE);
  46. }
  47. return OEES;
  48. }
  49. }
  50. }