HomeService.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using NPOI.SS.Formula.Functions;
  2. using ProductionLineMonitor.Application.Services.HomeService.Dtos;
  3. using ProductionLineMonitor.Application.Services.HomeService.Models;
  4. using ProductionLineMonitor.Core.Dtos;
  5. using ProductionLineMonitor.Core.IRepositories;
  6. using ProductionLineMonitor.Core.Models;
  7. using ProductionLineMonitor.Web.Services;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. namespace ProductionLineMonitor.Application.Services.HomeService
  13. {
  14. public class HomeService : IHomeService
  15. {
  16. private readonly IUnitOfWork _unitOfWork;
  17. public HomeService(IUnitOfWork unitOfWork)
  18. {
  19. _unitOfWork = unitOfWork;
  20. }
  21. public ResultDto CreateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto)
  22. {
  23. DateTime date = DateTime.Now;
  24. int year, month;
  25. year = date.Year;
  26. if (date.Day >= 21)
  27. month = date.Month + 1;
  28. else
  29. month = date.Month;
  30. // 判断机种是否已经添加
  31. IList<MonthModuleTypeDto> monthModuleTypes = MesApiService.GetMonthModuleTypeDtos(year, month);
  32. if (monthModuleTypes != null)
  33. {
  34. if (monthModuleTypes.Any(x => x.ModuleType == dto.ModuleType))
  35. {
  36. return ResultDto.Fail($"当月{dto.ModuleType}机种已经添加");
  37. }
  38. }
  39. dto.Id = Guid.NewGuid().ToString();
  40. dto.Year = year;
  41. dto.Month = month;
  42. return MesApiService.CreateMonthModuleType(dto);
  43. }
  44. public ResultDto CreateMonthModuleTypeV1(MonthModuleTypeCreateAndUpdateDto dto)
  45. {
  46. // 判断机种是否已经添加
  47. IList<MonthModuleType> monthModuleTypes = MesApiService
  48. .GetMonthModuleTypeDtosByMark(dto.Year, dto.Month, dto.Mark);
  49. if (monthModuleTypes != null)
  50. {
  51. if (monthModuleTypes.Any(x => x.ModuleType == dto.ModuleType))
  52. {
  53. return ResultDto.Fail($"当月{dto.ModuleType}机种已经添加");
  54. }
  55. }
  56. dto.Id = Guid.NewGuid().ToString();
  57. return MesApiService.CreateMonthModuleType(dto);
  58. }
  59. public ResultDto DeleteMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto)
  60. {
  61. if (string.IsNullOrEmpty(dto.Id))
  62. return ResultDto.Fail("Id 异常!");
  63. return MesApiService.DeleteMonthModuleType(dto);
  64. }
  65. public ResultDto UpdateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto)
  66. {
  67. DateTime date = DateTime.Now;
  68. int year, month;
  69. year = date.Year;
  70. if (date.Day >= 21)
  71. month = date.Month + 1;
  72. else
  73. month = date.Month;
  74. IList<MonthModuleTypeDto> monthModuleTypes = MesApiService.GetMonthModuleTypeDtos(year, month);
  75. if (monthModuleTypes == null)
  76. {
  77. return ResultDto.Fail("修改对象不存在!");
  78. }
  79. dto.Year = year;
  80. dto.Month = month;
  81. return MesApiService.UpdateMonthModuleType(dto);
  82. }
  83. public ResultDto UpdateMonthModuleTypeV1(MonthModuleTypeCreateAndUpdateDto dto)
  84. {
  85. // 判断机种是否已经添加
  86. IList<MonthModuleType> monthModuleTypes = MesApiService
  87. .GetMonthModuleTypeDtosByMark(dto.Year, dto.Month, dto.Mark);
  88. if (monthModuleTypes == null)
  89. {
  90. return ResultDto.Fail("修改对象不存在!");
  91. }
  92. return MesApiService.UpdateMonthModuleType(dto);
  93. }
  94. public ModuleTypeOverview GetModuleTypeOverview()
  95. {
  96. var lines = GetLinesByMark("2F");
  97. return new ModuleTypeOverview(lines, 10);
  98. }
  99. public IEnumerable<MonthModuleType> GetMonthModuleTypes(int year, int month)
  100. {
  101. return MesApiService.GetMonthModuleTypes(year, month).OrderByDescending(o => o.PlanCapacity);
  102. }
  103. public ModuleTypeOverview GetModuleTypeOverview(string mark, int year, int month)
  104. {
  105. IList<ProductionLine> lines = GetLinesByMark(mark);
  106. return new ModuleTypeOverview(lines, 10, year, month, mark);
  107. }
  108. private IList<ProductionLine> GetLinesByMark(string mark)
  109. {
  110. return mark switch
  111. {
  112. "2F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 2 && x.MakeClassification == "EPD").ToList(),
  113. "1F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "EPD").ToList(),
  114. "FPL" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "FPL").ToList(),
  115. _ => new List<ProductionLine>(),
  116. };
  117. }
  118. public IEnumerable<MonthModuleType> GetMonthModuleTypesByMark(string mark, int year, int month)
  119. {
  120. return MesApiService.GetMonthModuleTypeDtosByMark(year, month, mark).OrderByDescending(o => o.PlanCapacity);
  121. }
  122. public ModuleTypeOverviewV1 GetModuleTypeOverviewV1(string mark, int year, int month)
  123. {
  124. IList<ProductionLine> lines = GetLinesByMark(mark);
  125. return new ModuleTypeOverviewV1(lines, 10, year, month, mark);
  126. }
  127. }
  128. }