using ProductionLineMonitor.Application.Services.HomeService.Dtos; using ProductionLineMonitor.Application.Services.LineService.Dtos; using ProductionLineMonitor.Core.IRepositories; using ProductionLineMonitor.Web.Services; using ProductionLineMonitor.Web.Services.LineService; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ProductionLineMonitor.Application.Services.LineService { public class LineService : ILineService { private readonly IUnitOfWork _unitOfWork; public LineService(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } public LineMonthData GetLineMonthData(string lineId, string date, string moduleType) { var line = _unitOfWork.ProductionLineRepository.FirstOrDefault(x => x.Id == lineId); return new LineMonthData(line, Convert.ToDateTime($"{date} 08:00:00"), 10, moduleType); } public IList GetLineOverview(string date) { IList lineOverviews = new List(); var lines = _unitOfWork.ProductionLineRepository.GetList( x => x.FactoryNo == "03"); foreach (var line in lines) { LineOverviewDto lineOverview = new LineOverviewDto { Id = line.Id, Floor = line.Floor, Line = line.Line, Name = line.Name, LineName = line.LineName }; lineOverviews.Add(lineOverview); } List threads = new List(); foreach (var lineOverview in lineOverviews) { Thread thread = new Thread(() => { ProductionLineViewModel viewModel = new ProductionLineViewModel( lineOverview.Floor, lineOverview.Line, date, "FOG", lineOverview.LineName); foreach (var productionPlan in viewModel.ProductionPlans) { OverviewProductionPlanDto plan = new OverviewProductionPlanDto { ModuleType = productionPlan.ModuleType, Capa = productionPlan.Capa, PlanCapacity = productionPlan.PlanCapacity }; lineOverview.OverviewProductionPlans.Add(plan); } }); thread.Start(); threads.Add(thread); } foreach (var item in threads) { item.Join(); } return lineOverviews; } public IList GetLineOverviewV1(string date) { IList lineOverviews = new List(); var lines = _unitOfWork.ProductionLineRepository.GetList( x => x.FactoryNo == "03").OrderBy(o => o.Order); foreach (var line in lines) { var lst = MesApiService.GetProductionPlansV1(line.Floor, line.Line, date); OverProductionPlanDto lineOverview = new OverProductionPlanDto( line.Floor, line.Line, lst, line.Id, line.HourDataTopic, line.LineName); lineOverviews.Add(lineOverview); } var rs = _unitOfWork.RecipeRepository.GetList().ToList(); List threads = new List(); foreach (var lineOverview in lineOverviews) { Thread thread = new Thread(() => { ProductionLineViewModel viewModel = new ProductionLineViewModel(lineOverview.Floor, lineOverview.Line, date, lineOverview.HourDataTopic, lineOverview.LineName); int c = 0; if (viewModel.LoadOutPutPerHours.Count() > 0) { c = viewModel.LoadOutPutPerHours.Select(x => x.OutPut).Sum(); } #region 临时处理机种获取不到问题 if (lineOverview.ModuleType == null || lineOverview.ModuleType == "") { if (viewModel.LoadOutPutPerHours.Count() > 0) { string m = viewModel.LoadOutPutPerHours[0].ModuleType; lineOverview.SetModuleType(m); lineOverview.Capa = MesApiService.GetCapaTT(viewModel.Floor, viewModel.Line, m).Capa.ToString(); } } #endregion lineOverview.SetCapacity(c); }); thread.Start(); threads.Add(thread); } foreach (var item in threads) { item.Join(); } return lineOverviews; } } }