From 520f321b958cbf6aa62323686e46d88e897bf20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= <17363321594@163.com> Date: Fri, 26 Sep 2025 11:43:27 +0800 Subject: [PATCH] =?UTF-8?q?MRP=E7=89=A9=E6=96=99=E5=88=86=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/mm/paintedparts_call/MmCallService.cs | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/DOAN.Service/MES/mm/paintedparts_call/MmCallService.cs b/DOAN.Service/MES/mm/paintedparts_call/MmCallService.cs index 77bb2fe..679ad19 100644 --- a/DOAN.Service/MES/mm/paintedparts_call/MmCallService.cs +++ b/DOAN.Service/MES/mm/paintedparts_call/MmCallService.cs @@ -221,55 +221,55 @@ namespace DOAN.Service.MES.mm.paintedparts_call .ToList(); // 计算每个 ProductionCode 的 DeliveryNum 总和 - var deliveryNumDict = workorders + var totalDeliveryDict = workorders .GroupBy(x => x.ProductionCode) .ToDictionary(g => g.Key, g => g.Sum(x => x.DeliveryNum)); // 生成 MmCallRequests List mmCallMrpList = new(); - // 1. 按工单顺序排序 (假设按ProductionCode排序,可根据实际需求调整) - var sortedWorkorders = workorders.OrderBy(x => x.ProductionCode).ToList(); + //// 1. 按工单顺序排序 (假设按ProductionCode排序,可根据实际需求调整) + //var sortedWorkorders = workorders.OrderBy(x => x.ProductionCode).ToList(); - // 2. 计算总交货量并拆分为四组 - int totalDeliveryNum = sortedWorkorders.Sum(x => x.DeliveryNum).Value; - int groupTarget = totalDeliveryNum / 4; + //// 2. 计算总交货量并拆分为四组 + //int totalDeliveryNum = sortedWorkorders.Sum(x => x.DeliveryNum).Value; + //int groupTarget = totalDeliveryNum / 4; - List> groups = new List>(); - List currentGroup = new List(); - int currentSum = 0; + //List> groups = new List>(); + //List currentGroup = new List(); + //int currentSum = 0; - foreach (var wo in sortedWorkorders) - { - currentGroup.Add(wo); - currentSum += wo.DeliveryNum.Value; + //foreach (var wo in sortedWorkorders) + //{ + // currentGroup.Add(wo); + // currentSum += wo.DeliveryNum.Value; - if (currentSum >= groupTarget * (groups.Count + 1)) - { - groups.Add(currentGroup); - currentGroup = new List(); - currentSum = 0; - } - } + // if (currentSum >= groupTarget * (groups.Count + 1)) + // { + // groups.Add(currentGroup); + // currentGroup = new List(); + // currentSum = 0; + // } + //} - // 处理剩余工单 - if (currentGroup.Any()) - { - if (groups.Count < 4) - { - groups.Add(currentGroup); - } - else - { - groups[3].AddRange(currentGroup); - } - } + //// 处理剩余工单 + //if (currentGroup.Any()) + //{ + // if (groups.Count < 4) + // { + // groups.Add(currentGroup); + // } + // else + // { + // groups[3].AddRange(currentGroup); + // } + //} - // 确保有四组 - while (groups.Count < 4) - { - groups.Add(new List()); - } + //// 确保有四组 + //while (groups.Count < 4) + //{ + // groups.Add(new List()); + //} // 3. 定义四个时间段 var timePeriods = new List<(DateTime Start, DateTime End)> @@ -281,24 +281,16 @@ namespace DOAN.Service.MES.mm.paintedparts_call }; // 4. 分时段计算物料需求 - for (int i = 0; i < groups.Count && i < timePeriods.Count; i++) + foreach (var (startTime, endTime) in timePeriods) { - var group = groups[i]; - var (startTime, endTime) = timePeriods[i]; - - if (!group.Any()) - continue; - // 获取该组的ProductionCode列表并转换为HashSet以提高查找效率 // 显式指定泛型类型参数确保从dynamic转换为string - var groupProductionCodes = new HashSet( - group.Select(x => x.ProductionCode.ToString()).Distinct() - ); + var groupProductionCodes = new HashSet(lineProductionCodeList); - // 计算该组的DeliveryNum字典 - var groupDeliveryDict = group - .GroupBy(x => x.ProductionCode) - .ToDictionary(g => g.Key, g => g.Sum(x => x.DeliveryNum)); + //// 计算该组的DeliveryNum字典 + //var groupDeliveryDict = group + // .GroupBy(x => x.ProductionCode) + // .ToDictionary(g => g.Key, g => g.Sum(x => x.DeliveryNum)); // 按linecode与MaterialCode进行聚合统计 var aggregatedData = mmCallMaterialBoms @@ -318,15 +310,13 @@ namespace DOAN.Service.MES.mm.paintedparts_call MaterialName = g.Key.subInvName, TotalQuantity = g.Sum(bom => { - if ( - !groupDeliveryDict.TryGetValue( - bom.InvCode, - out int workOrderDeliveryNum - ) - ) + int totalDeliveryNum = workorders + .Where(w => w.ProductionCode == bom.InvCode) + .Sum(w => w.DeliveryNum) ?? 0; + + if (totalDeliveryNum <= 0) { - Context.Ado.RollbackTran(); - throw new Exception($"{bom.InvCode}交货数量异常"); + return 0m; // 没有交货量则跳过 } decimal iusequantity; @@ -336,7 +326,7 @@ namespace DOAN.Service.MES.mm.paintedparts_call throw new Exception($"{bom.subInvCode}BOM使用数量异常"); } - return workOrderDeliveryNum * iusequantity; + return totalDeliveryNum * iusequantity; }) }) .ToList(); @@ -364,6 +354,16 @@ namespace DOAN.Service.MES.mm.paintedparts_call ); } } + mmCallMrpList = mmCallMrpList + .Where(it => !string.IsNullOrEmpty(it.MaterialCode) && + (it.MaterialCode.Contains("-") || it.MaterialCode.Contains("—"))) + .ToList(); + + foreach (var mrp in mmCallMrpList.Take(10)) + { + Console.WriteLine($"MaterialCode: {mrp.MaterialCode}"); + } + // 删除旧数据并插入新数据 Context .Deleteable()