123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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<MonthModuleTypeDto> 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<MonthModuleType> 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<MonthModuleTypeDto> 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<MonthModuleType> 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<MonthModuleType> GetMonthModuleTypes(int year, int month)
- {
- return MesApiService.GetMonthModuleTypes(year, month).OrderByDescending(o => o.PlanCapacity);
- }
- public ModuleTypeOverview GetModuleTypeOverview(string mark, int year, int month)
- {
- IList<ProductionLine> lines = GetLinesByMark(mark);
- return new ModuleTypeOverview(lines, 10, year, month, mark);
- }
- private IList<ProductionLine> 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<ProductionLine>(),
- };
- }
- public IEnumerable<MonthModuleType> 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<ProductionLine> lines = GetLinesByMark(mark);
- return new ModuleTypeOverviewV1(lines, 10, year, month, mark);
- }
- }
- }
|