gongchunyi
7 小时以前 a8188d1675594d7756eddccc3eda60601325942a
src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
@@ -131,10 +131,15 @@
        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);
@@ -217,13 +222,13 @@
            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;
//            }
@@ -232,7 +237,6 @@
            update.setDemandedQuantity(demandedQuantity);
            updateList.add(update);
            structure.setDemandedQuantity(demandedQuantity);
            lastProcessDemandedQuantity = demandedQuantity;
        }
        if (!updateList.isEmpty()) {
            this.updateBatchById(updateList);
@@ -823,12 +827,20 @@
        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,
@@ -846,6 +858,26 @@
        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(