gongchunyi
10 小时以前 10570a9fa5e87231210a449eddc732c7d0599349
src/main/java/com/ruoyi/production/util/TaskPlanQuantityUtil.java
@@ -88,6 +88,49 @@
        return demandedQuantityMap;
    }
    public Map<Long, Set<Long>> buildOperationOutputProductModelMap(List<ProductionBomStructure> bomStructures,
                                                                     Long rootProductModelId) {
        if (bomStructures == null || bomStructures.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<Long, ProductionBomStructure> structureById = new HashMap<>();
        for (ProductionBomStructure item : bomStructures) {
            if (item != null && item.getId() != null) {
                structureById.put(item.getId(), item);
            }
        }
        Map<Long, Set<Long>> outputProductModelMap = new HashMap<>();
        for (ProductionBomStructure bomStructure : bomStructures) {
            if (bomStructure == null || bomStructure.getTechnologyOperationId() == null) {
                continue;
            }
            ProductionBomStructure outputNode = resolveOperationOutputNode(bomStructure, structureById);
            Long outputProductModelId = resolveOutputProductModelId(outputNode, rootProductModelId);
            if (outputProductModelId != null) {
                outputProductModelMap.computeIfAbsent(
                        bomStructure.getTechnologyOperationId(), key -> new LinkedHashSet<>())
                        .add(outputProductModelId);
            }
        }
        return outputProductModelMap;
    }
    public Long resolveOperationOutputProductModelId(Long operationId,
                                                      Long preferredProductModelId,
                                                      Map<Long, Set<Long>> outputProductModelMap,
                                                      Long rootProductModelId) {
        Set<Long> candidates = outputProductModelMap == null ? null : outputProductModelMap.get(operationId);
        if (candidates != null && !candidates.isEmpty()) {
            if (preferredProductModelId != null && candidates.contains(preferredProductModelId)) {
                return preferredProductModelId;
            }
            if (candidates.size() == 1) {
                return candidates.iterator().next();
            }
        }
        return preferredProductModelId != null ? preferredProductModelId : rootProductModelId;
    }
    /**
     * 构建工序需求量key
     */
@@ -110,13 +153,22 @@
        if (bomStructure == null) {
            return null;
        }
        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()));
    }
    /**
     * 解析输出产品规格ID
     */