using NPOI.SS.Formula.Functions; using ProductionLineMonitor.Application.Services.HomeService.Dtos; using ProductionLineMonitor.Application.Services.HomeService.Models; using ProductionLineMonitor.Core.Dtos; using ProductionLineMonitor.Core.IRepositories; using ProductionLineMonitor.Core.Models; using ProductionLineMonitor.Web.Services; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProductionLineMonitor.Application.Services.HomeService { public class HomeService : IHomeService { private readonly IUnitOfWork _unitOfWork; public HomeService(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } public ResultDto CreateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto) { DateTime date = DateTime.Now; int year, month; year = date.Year; if (date.Day >= 21) month = date.Month + 1; else month = date.Month; // 判断机种是否已经添加 IList monthModuleTypes = MesApiService.GetMonthModuleTypeDtos(year, month); if (monthModuleTypes != null) { if (monthModuleTypes.Any(x => x.ModuleType == dto.ModuleType)) { return ResultDto.Fail($"当月{dto.ModuleType}机种已经添加"); } } dto.Id = Guid.NewGuid().ToString(); dto.Year = year; dto.Month = month; return MesApiService.CreateMonthModuleType(dto); } public ResultDto CreateMonthModuleTypeV1(MonthModuleTypeCreateAndUpdateDto dto) { // 判断机种是否已经添加 IList monthModuleTypes = MesApiService .GetMonthModuleTypeDtosByMark(dto.Year, dto.Month, dto.Mark); if (monthModuleTypes != null) { if (monthModuleTypes.Any(x => x.ModuleType == dto.ModuleType)) { return ResultDto.Fail($"当月{dto.ModuleType}机种已经添加"); } } dto.Id = Guid.NewGuid().ToString(); return MesApiService.CreateMonthModuleType(dto); } public ResultDto DeleteMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto) { if (string.IsNullOrEmpty(dto.Id)) return ResultDto.Fail("Id 异常!"); return MesApiService.DeleteMonthModuleType(dto); } public ResultDto UpdateMonthModuleType(MonthModuleTypeCreateAndUpdateDto dto) { DateTime date = DateTime.Now; int year, month; year = date.Year; if (date.Day >= 21) month = date.Month + 1; else month = date.Month; IList monthModuleTypes = MesApiService.GetMonthModuleTypeDtos(year, month); if (monthModuleTypes == null) { return ResultDto.Fail("修改对象不存在!"); } dto.Year = year; dto.Month = month; return MesApiService.UpdateMonthModuleType(dto); } public ResultDto UpdateMonthModuleTypeV1(MonthModuleTypeCreateAndUpdateDto dto) { // 判断机种是否已经添加 IList monthModuleTypes = MesApiService .GetMonthModuleTypeDtosByMark(dto.Year, dto.Month, dto.Mark); if (monthModuleTypes == null) { return ResultDto.Fail("修改对象不存在!"); } return MesApiService.UpdateMonthModuleType(dto); } public ModuleTypeOverview GetModuleTypeOverview() { var lines = GetLinesByMark("2F"); return new ModuleTypeOverview(lines, 10); } public IEnumerable GetMonthModuleTypes(int year, int month) { return MesApiService.GetMonthModuleTypes(year, month).OrderByDescending(o => o.PlanCapacity); } public ModuleTypeOverview GetModuleTypeOverview(string mark, int year, int month) { IList lines = GetLinesByMark(mark); return new ModuleTypeOverview(lines, 10, year, month, mark); } private IList GetLinesByMark(string mark) { return mark switch { "2F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 2 && x.MakeClassification == "EPD").ToList(), "1F" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "EPD").ToList(), "FPL" => _unitOfWork.ProductionLineRepository.GetList(x => x.Floor == 1 && x.MakeClassification == "FPL").ToList(), _ => new List(), }; } public IEnumerable GetMonthModuleTypesByMark(string mark, int year, int month) { return MesApiService.GetMonthModuleTypeDtosByMark(year, month, mark).OrderByDescending(o => o.PlanCapacity); } public ModuleTypeOverviewV1 GetModuleTypeOverviewV1(string mark, int year, int month) { IList lines = GetLinesByMark(mark); return new ModuleTypeOverviewV1(lines, 10, year, month, mark); } } }