LineService.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using ProductionLineMonitor.Application.Services.HomeService.Dtos;
  2. using ProductionLineMonitor.Application.Services.LineService.Dtos;
  3. using ProductionLineMonitor.Core.IRepositories;
  4. using ProductionLineMonitor.Web.Services;
  5. using ProductionLineMonitor.Web.Services.LineService;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace ProductionLineMonitor.Application.Services.LineService
  13. {
  14. public class LineService : ILineService
  15. {
  16. private readonly IUnitOfWork _unitOfWork;
  17. public LineService(IUnitOfWork unitOfWork)
  18. {
  19. _unitOfWork = unitOfWork;
  20. }
  21. public LineMonthData GetLineMonthData(string lineId, string date, string moduleType)
  22. {
  23. var line = _unitOfWork.ProductionLineRepository.FirstOrDefault(x => x.Id == lineId);
  24. return new LineMonthData(line, Convert.ToDateTime($"{date} 08:00:00"), 10, moduleType);
  25. }
  26. public IList<LineOverviewDto> GetLineOverview(string date)
  27. {
  28. IList<LineOverviewDto> lineOverviews = new List<LineOverviewDto>();
  29. var lines = _unitOfWork.ProductionLineRepository.GetList(
  30. x => x.FactoryNo == "03");
  31. foreach (var line in lines)
  32. {
  33. LineOverviewDto lineOverview = new LineOverviewDto
  34. {
  35. Id = line.Id,
  36. Floor = line.Floor,
  37. Line = line.Line,
  38. Name = line.Name,
  39. LineName = line.LineName
  40. };
  41. lineOverviews.Add(lineOverview);
  42. }
  43. List<Thread> threads = new List<Thread>();
  44. foreach (var lineOverview in lineOverviews)
  45. {
  46. Thread thread = new Thread(() =>
  47. {
  48. ProductionLineViewModel viewModel = new ProductionLineViewModel(
  49. lineOverview.Floor, lineOverview.Line, date, "FOG", lineOverview.LineName);
  50. foreach (var productionPlan in viewModel.ProductionPlans)
  51. {
  52. OverviewProductionPlanDto plan = new OverviewProductionPlanDto
  53. {
  54. ModuleType = productionPlan.ModuleType,
  55. Capa = productionPlan.Capa,
  56. PlanCapacity = productionPlan.PlanCapacity
  57. };
  58. lineOverview.OverviewProductionPlans.Add(plan);
  59. }
  60. });
  61. thread.Start();
  62. threads.Add(thread);
  63. }
  64. foreach (var item in threads)
  65. {
  66. item.Join();
  67. }
  68. return lineOverviews;
  69. }
  70. public IList<OverProductionPlanDto> GetLineOverviewV1(string date)
  71. {
  72. IList<OverProductionPlanDto> lineOverviews = new List<OverProductionPlanDto>();
  73. var lines = _unitOfWork.ProductionLineRepository.GetList(
  74. x => x.FactoryNo == "03").OrderBy(o => o.Order);
  75. foreach (var line in lines)
  76. {
  77. var lst = MesApiService.GetProductionPlansV1(line.Floor, line.Line, date);
  78. OverProductionPlanDto lineOverview = new OverProductionPlanDto(
  79. line.Floor, line.Line, lst, line.Id, line.HourDataTopic, line.LineName);
  80. lineOverviews.Add(lineOverview);
  81. }
  82. var rs = _unitOfWork.RecipeRepository.GetList().ToList();
  83. List<Thread> threads = new List<Thread>();
  84. foreach (var lineOverview in lineOverviews)
  85. {
  86. Thread thread = new Thread(() =>
  87. {
  88. ProductionLineViewModel viewModel = new ProductionLineViewModel(lineOverview.Floor,
  89. lineOverview.Line, date, lineOverview.HourDataTopic, lineOverview.LineName);
  90. int c = 0;
  91. if (viewModel.LoadOutPutPerHours.Count() > 0)
  92. {
  93. c = viewModel.LoadOutPutPerHours.Select(x => x.OutPut).Sum();
  94. }
  95. #region 临时处理机种获取不到问题
  96. if (lineOverview.ModuleType == null || lineOverview.ModuleType == "")
  97. {
  98. if (viewModel.LoadOutPutPerHours.Count() > 0)
  99. {
  100. string m = viewModel.LoadOutPutPerHours[0].ModuleType;
  101. lineOverview.SetModuleType(m);
  102. lineOverview.Capa = MesApiService.GetCapaTT(viewModel.Floor, viewModel.Line, m).Capa.ToString();
  103. }
  104. }
  105. #endregion
  106. lineOverview.SetCapacity(c);
  107. });
  108. thread.Start();
  109. threads.Add(thread);
  110. }
  111. foreach (var item in threads)
  112. {
  113. item.Join();
  114. }
  115. return lineOverviews;
  116. }
  117. }
  118. }