src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
@@ -217,22 +217,28 @@ return; } List<ProductionBomStructure> updateList = new ArrayList<>(); BigDecimal lastProcessDemandedQuantity = orderQuantity; // 需求量按“父节点需求量 × 本行单耗”逐层计算,兄弟节点互不影响,结果与录入顺序无关。 Map<Long, BigDecimal> demandedQuantityById = new HashMap<>(); for (ProductionBomStructure structure : structureList) { if (structure == null || structure.getId() == null) { continue; } BigDecimal demandedQuantity = lastProcessDemandedQuantity.multiply(defaultDecimal(structure.getUnitQuantity())); // if (compareDecimal(structure.getDemandedQuantity(), demandedQuantity) == 0) { // continue; // } // 根节点以订单数量为基数,子节点以父节点需求量为基数。 boolean rootNode = structure.getParentId() == null || structure.getParentId() == 0L; BigDecimal baseQuantity = rootNode ? orderQuantity : demandedQuantityById.get(structure.getParentId()); if (baseQuantity == null) { throw new ServiceException("BOM结构数据异常,存在找不到父节点的子节点"); } BigDecimal demandedQuantity = baseQuantity.multiply(defaultDecimal(structure.getUnitQuantity())); ProductionBomStructure update = new ProductionBomStructure(); update.setId(structure.getId()); update.setDemandedQuantity(demandedQuantity); updateList.add(update); structure.setDemandedQuantity(demandedQuantity); lastProcessDemandedQuantity = demandedQuantity; demandedQuantityById.put(structure.getId(), demandedQuantity); } if (!updateList.isEmpty()) { this.updateBatchById(updateList); 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; }