yuan
9 小时以前 c0bdce5b5deb0b680534f276d0bb61dbbaa83890
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -439,7 +439,8 @@
        productionOrderBomMapper.insert(orderBom);
        Map<Long, Long> idMap = new HashMap<>();
        BigDecimal lastProcessDemandedQuantity = orderQuantity;
        // 需求量按“父节点需求量 × 本行单耗”逐层计算,兄弟节点互不影响,结果与录入顺序无关。
        Map<Long, BigDecimal> demandedQuantityBySourceId = new HashMap<>();
        for (TechnologyBomStructure source : structureList) {
            // 子节点 parentId 需要映射成新快照节点 id,才能保留原始 BOM 层级。
            ProductionBomStructure target = new ProductionBomStructure();
@@ -449,11 +450,19 @@
            target.setProductModelId(source.getProductModelId());
            target.setTechnologyOperationId(source.getOperationId());
            target.setUnitQuantity(source.getUnitQuantity());
            target.setDemandedQuantity(lastProcessDemandedQuantity.multiply(source.getUnitQuantity()));
            // 根节点以订单数量为基数,子节点以父节点需求量为基数。
            boolean rootNode = source.getParentId() == null || source.getParentId() == 0L;
            BigDecimal baseQuantity = rootNode
                    ? orderQuantity
                    : demandedQuantityBySourceId.get(source.getParentId());
            if (baseQuantity == null) {
                throw new ServiceException("BOM结构数据异常,存在找不到父节点的子节点");
            }
            target.setDemandedQuantity(baseQuantity.multiply(defaultDecimal(source.getUnitQuantity())));
            target.setUnit(source.getUnit());
            productionBomStructureMapper.insert(target);
            idMap.put(source.getId(), target.getId());
            lastProcessDemandedQuantity = target.getDemandedQuantity();
            demandedQuantityBySourceId.put(source.getId(), target.getDemandedQuantity());
        }
        return orderBom;
    }