| | |
| | | List<ProductionBomStructure> updateList = new ArrayList<>(); |
| | | Map<String, ProductionBomStructure> tempEntityMap = new HashMap<>(); |
| | | |
| | | Map<Long, Boolean> operationPickMap = loadOperationPickMap(flatDtoList.stream() |
| | | .map(ProductionBomStructureDto::getTechnologyOperationId) |
| | | .collect(Collectors.toList())); |
| | | |
| | | for (ProductionBomStructureDto item : flatDtoList) { |
| | | ProductionBomStructure entity = new ProductionBomStructure(); |
| | | BeanUtils.copyProperties(item, entity); |
| | | entity.setProductionOrderBomId(orderBomId); |
| | | entity.setIsPick(operationPickMap.getOrDefault(item.getTechnologyOperationId(), Boolean.FALSE)); |
| | | if (item.getId() == null) { |
| | | entity.setParentId(null); |
| | | insertList.add(entity); |
| | |
| | | return; |
| | | } |
| | | List<ProductionBomStructure> updateList = new ArrayList<>(); |
| | | BigDecimal lastProcessDemandedQuantity = orderQuantity; |
| | | for (ProductionBomStructure structure : structureList) { |
| | | if (structure == null || structure.getId() == null) { |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal demandedQuantity = lastProcessDemandedQuantity.multiply(defaultDecimal(structure.getUnitQuantity())); |
| | | BigDecimal demandedQuantity = defaultDecimal(orderQuantity) |
| | | .multiply(defaultDecimal(structure.getUnitQuantity())); |
| | | // if (compareDecimal(structure.getDemandedQuantity(), demandedQuantity) == 0) { |
| | | // continue; |
| | | // } |
| | |
| | | update.setDemandedQuantity(demandedQuantity); |
| | | updateList.add(update); |
| | | structure.setDemandedQuantity(demandedQuantity); |
| | | lastProcessDemandedQuantity = demandedQuantity; |
| | | } |
| | | if (!updateList.isEmpty()) { |
| | | this.updateBatchById(updateList); |
| | |
| | | if (bomStructure == null) { |
| | | return null; |
| | | } |
| | | // The root node is the first output node; other rows use their direct parent as the current operation output. |
| | | if (bomStructure.getParentId() == null) { |
| | | if (bomStructure.getParentId() == null || hasChildren(bomStructure, structureById)) { |
| | | return bomStructure; |
| | | } |
| | | ProductionBomStructure parent = structureById.get(bomStructure.getParentId()); |
| | | return parent != null ? parent : bomStructure; |
| | | } |
| | | |
| | | private boolean hasChildren(ProductionBomStructure bomStructure, |
| | | Map<Long, ProductionBomStructure> structureById) { |
| | | if (bomStructure == null || bomStructure.getId() == null || structureById == null) { |
| | | return false; |
| | | } |
| | | return structureById.values().stream() |
| | | .anyMatch(child -> child != null && Objects.equals(child.getParentId(), bomStructure.getId())); |
| | | } |
| | | |
| | | private Long resolveOutputProductModelId(ProductionBomStructure outputNode, |
| | |
| | | return technologyOperationMapper.selectById(technologyOperationId); |
| | | } |
| | | |
| | | /** |
| | | * 批量读取工序的“是否领料”标记,保证生产BOM结构中的领料标记与工序主数据一致。 |
| | | */ |
| | | private Map<Long, Boolean> loadOperationPickMap(List<Long> technologyOperationIds) { |
| | | if (technologyOperationIds == null || technologyOperationIds.isEmpty()) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | Set<Long> operationIdSet = technologyOperationIds.stream() |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | if (operationIdSet.isEmpty()) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | return technologyOperationMapper.selectBatchIds(operationIdSet).stream() |
| | | .filter(item -> item != null && item.getId() != null) |
| | | .collect(Collectors.toMap(TechnologyOperation::getId, |
| | | item -> Boolean.TRUE.equals(item.getIsPick()), |
| | | (left, right) -> left)); |
| | | } |
| | | |
| | | private String generateNextTaskNo() { |
| | | String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | ProductionOperationTask latestTask = productionOperationTaskMapper.selectOne( |