| | |
| | | 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); |