From 925803beda3ec938c762d6a8bd734ecc2ef0146f Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Wed, 4 Feb 2026 13:29:32 +0800 Subject: [PATCH] =?UTF-8?q?2026-02-04=20=E6=8A=A5=E4=BB=B7=E3=80=90?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E3=80=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/QuoteDetailServiceImpl.java | 102 ++++++++++++++++-- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/spring/modules/quote/service/impl/QuoteDetailServiceImpl.java b/src/main/java/com/spring/modules/quote/service/impl/QuoteDetailServiceImpl.java index d7e8e0d2..a04c30ca 100644 --- a/src/main/java/com/spring/modules/quote/service/impl/QuoteDetailServiceImpl.java +++ b/src/main/java/com/spring/modules/quote/service/impl/QuoteDetailServiceImpl.java @@ -202,6 +202,8 @@ public class QuoteDetailServiceImpl extends ServiceImpl queryQuoteDetailCost(QuoteDetail detail) { + log.info("========== [COST_CALC] START - QuoteDetailId: {} ==========", detail.getId()); + QuoteDetail quoteDetail = getById(detail.getId()); Map map = new HashMap<>(); // 1、工具成本 @@ -234,9 +236,13 @@ public class QuoteDetailServiceImpl extends ServiceImpl routingList = quoteDetailRoutingService.queryQuoteDetailRouting(queryRouting); Map> routingMap = routingList.stream().collect(Collectors.groupingBy(QuoteDetailRouting::getTreeId)); + log.info("[COST_CALC] Total routing records loaded: {}", routingList.size()); + // 查询 BOM QuoteDetailBom quoteDetailBom = new QuoteDetailBom(); quoteDetailBom.setQuoteDetailId(quoteDetail.getId()); @@ -251,30 +259,46 @@ public class QuoteDetailServiceImpl extends ServiceImpl bomList = quoteDetailBomService.queryQuoteDetailBom(quoteDetailBom); Map> bomMap = bomList.stream().collect(Collectors.groupingBy(QuoteDetailBom::getTreeId)); + log.info("[COST_CALC] Total BOM component records loaded: {}", bomList.size()); long treeId = 0; + int nodeIndex = 0; // 第一层BOM for (QuoteDetailBomTree bomTree : list) { + nodeIndex++; + log.info("[COST_CALC] ===== Processing node {}/{}: PartNo={}, Level={}, TreeId={}, ParentId={}, BomType={} =====", + nodeIndex, list.size(), bomTree.getPartNo(), bomTree.getLevel(), bomTree.getId(), bomTree.getParentId(), bomTree.getBomType()); + if (Long.valueOf(0L).equals(bomTree.getParentId())){ treeId = bomTree.getId(); + log.info("[COST_CALC] This is ROOT node (ParentId=0)"); } // 查询物料类型,只有Manufactured或Manufactured Recipe类型的物料才计算Routing成本 String partType = quoteDetailBomTreeService.queryPartType(bomTree.getSite(), bomTree.getPartNo()); boolean isManufacturedPart = "Manufactured".equals(partType) || "Manufactured Recipe".equals(partType); + log.info("[COST_CALC] PartType for {}: {}, isManufacturedPart: {}", bomTree.getPartNo(), partType, isManufacturedPart); // 计算具体人工成本 List routings = Optional.ofNullable(routingMap.get(bomTree.getId())).orElse(new ArrayList<>()); + log.info("[COST_CALC] Found {} routing records for this node", routings.size()); BigDecimal bomLabourCost = BigDecimal.ZERO; BigDecimal bomMachineCost = BigDecimal.ZERO; // 获得 BomTree的 人工和制造成本(仅Manufactured或Manufactured Recipe类型的物料) if (isManufacturedPart) { for (QuoteDetailRouting routing : routings) { + log.info("[COST_CALC] Routing: OperationId={}, LaborCost={}, MachCost={}", + routing.getOperationId(), routing.getTotalLaborCost(), routing.getTotalMachCost()); bomLabourCost = bomLabourCost.add(routing.getTotalLaborCost()); bomMachineCost = bomMachineCost.add(routing.getTotalMachCost()); } + log.info("[COST_CALC] Base routing cost for node {}: LabourCost={}, MachineCost={}", + bomTree.getPartNo(), bomLabourCost, bomMachineCost); + } else { + log.info("[COST_CALC] Skipping routing cost for non-manufactured part (PartType={})", partType); } + // BomTree的物料成本 List boms = Optional.ofNullable(bomMap.get(bomTree.getId())).orElse(new ArrayList<>()); BigDecimal bomQuotePrice = BigDecimal.ZERO; @@ -286,21 +310,40 @@ public class QuoteDetailServiceImpl extends ServiceImpl bomTree.getLevel() || tree.getId() != parentId) { continue; } + convolutionStep++; + log.info("[COST_CALC] Convolution step {}: Current PartNo={}, CurrentTreeId={}, Looking for parent TreeId={}", + convolutionStep, partNo, currentTreeId, parentId); + // 获取 层级比自己高的Bom 来获得BOM信息 用量和损耗 -// List parentBomList = quoteDetailBomService.lambdaQuery().eq(QuoteDetailBom::getTreeId, parentId).eq(QuoteDetailBom::getComponentPart, partNo).list(); String finalPartNo = partNo; - List parentBomList = bomMap.get(parentId).stream().filter(bom->bom.getComponentPart().equals(finalPartNo)).collect(Collectors.toList()); + List parentBomListRaw = bomMap.get(parentId); + if (parentBomListRaw == null) { + log.warn("[COST_CALC] WARNING: No BOM list found for parentId={}", parentId); + continue; + } + List parentBomList = parentBomListRaw.stream().filter(bom->bom.getComponentPart().equals(finalPartNo)).collect(Collectors.toList()); + log.info("[COST_CALC] Found {} matching BOM records for component {} in parent {}", + parentBomList.size(), finalPartNo, parentId); + // 赋值新的成本 for (QuoteDetailBom bom : parentBomList) { bom.setQuotePrice(bomQuotePrice); @@ -320,21 +363,52 @@ public class QuoteDetailServiceImpl extends ServiceImpl String.valueOf(b.getBomId())).collect(Collectors.joining(","))); + } + + log.info("[COST_CALC] Before convolution: LabourCost={}, MachineCost={}", bomLabourCost, bomMachineCost); + log.info("[COST_CALC] Multiplier (qtyPerAssembly): {}", qtyPerAssembly); + // 计算 损耗和用量得到的差异 bomLabourCost = bomLabourCost.multiply(qtyPerAssembly); bomMachineCost = bomMachineCost.multiply(qtyPerAssembly); + + log.info("[COST_CALC] After convolution: LabourCost={}, MachineCost={}", bomLabourCost, bomMachineCost); + // 拿到上层数据 + // BUG FIX: Update currentTreeId to the parent node's TreeId for the next iteration + currentTreeId = tree.getId(); parentId = tree.getParentId(); partNo = tree.getPartNo(); + log.debug("[COST_CALC] Moving up: nextTreeId={}, nextParentId={}, nextPartNo={}", currentTreeId, parentId, partNo); } + + log.info("[COST_CALC] Final cost for node {}: LabourCost={}, MachineCost={}", bomTree.getPartNo(), bomLabourCost, bomMachineCost); + log.info("[COST_CALC] Accumulating to total - Before: LabourCost={}, MachineCost={}", labourCost, machineCost); + labourCost = labourCost.add(bomLabourCost); machineCost = machineCost.add(bomMachineCost); + + log.info("[COST_CALC] Accumulating to total - After: LabourCost={}, MachineCost={}", labourCost, machineCost); } // 计算最终成本 List boms = bomMap.get(treeId); @@ -376,6 +450,20 @@ public class QuoteDetailServiceImpl extends ServiceImpl