src/main/java/com/ruoyi/stock/support/FinishedProductStockDimensionResolver.java
@@ -5,6 +5,10 @@
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.production.mapper.ProductProcessMapper;
@@ -35,15 +39,21 @@
    private final ProductionProductOutputMapper productionProductOutputMapper;
    private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
    private final ProductProcessMapper productProcessMapper;
    private final ProductMapper productMapper;
    private final ProductModelMapper productModelMapper;
    public FinishedProductStockDimensionResolver(ProductionProductMainMapper productionProductMainMapper,
                                                 ProductionProductOutputMapper productionProductOutputMapper,
                                                 ProductProcessRouteItemMapper productProcessRouteItemMapper,
                                                 ProductProcessMapper productProcessMapper) {
                                                 ProductProcessMapper productProcessMapper,
                                                 ProductMapper productMapper,
                                                 ProductModelMapper productModelMapper) {
        this.productionProductMainMapper = productionProductMainMapper;
        this.productionProductOutputMapper = productionProductOutputMapper;
        this.productProcessRouteItemMapper = productProcessRouteItemMapper;
        this.productProcessMapper = productProcessMapper;
        this.productMapper = productMapper;
        this.productModelMapper = productModelMapper;
    }
    /**
@@ -64,13 +74,27 @@
     */
    public String resolveVoltage(Long productMainId) {
        List<ProductionProductOutput> outputs = loadOutputs(productMainId);
        Long productModelId = outputs.stream()
                .map(ProductionProductOutput::getProductModelId)
                .filter(id -> id != null)
                .findFirst()
                .orElse(null);
        boolean isFinishedProduct = isFinishedProduct(productModelId);
        for (ProductionProductOutput output : outputs) {
            String voltage = resolveVoltageValue(output.getOtherData());
            if (StringUtils.isNotBlank(voltage)) {
                return voltage;
            }
        }
        throw new ServiceException("请配置参数电压");
        if (isFinishedProduct) {
            throw new ServiceException("请配置参数电压");
        }
        return null;
    }
    private ProductionProductMain loadProductionMain(Long productMainId) {
@@ -114,6 +138,15 @@
        if (CollectionUtils.isEmpty(routeItems)) {
            throw new ServiceException("订单工艺路线未配置工序,无法确定成品类别");
        }
        Long productModelId = routeItems.stream()
                .map(ProductProcessRouteItem::getProductModelId)
                .filter(id -> id != null)
                .findFirst()
                .orElse(null);
        boolean isFinishedProduct = isFinishedProduct(productModelId);
        Set<Long> processIds = routeItems.stream()
                .map(ProductProcessRouteItem::getProcessId)
                .filter(id -> id != null)
@@ -126,12 +159,19 @@
                .map(ProductProcess::getName)
                .filter(name -> PROCESS_COPPER.equals(name) || PROCESS_SILVER.equals(name))
                .collect(Collectors.toCollection(LinkedHashSet::new));
        if (matchedCategories.isEmpty()) {
        if (matchedCategories.isEmpty() && isFinishedProduct) {
            throw new ServiceException("订单工艺路线未配置印铜/印银工序,无法确定成品类别");
        }
        if (matchedCategories.size() > 1) {
            throw new ServiceException("订单工艺路线同时配置了印铜和印银,无法确定成品类别");
        }
        if (matchedCategories.isEmpty()) {
            return null;
        }
        String matchedProcess = matchedCategories.iterator().next();
        if (PROCESS_COPPER.equals(matchedProcess)) {
            return PROCESS_CATEGORY_COPPER;
@@ -181,4 +221,38 @@
        }
        return null;
    }
}
    private boolean isFinishedProduct(Long productModelId) {
        if (productModelId == null) {
            return false;
        }
        ProductModel productModel = productModelMapper.selectById(productModelId);
        if (productModel == null || productModel.getProductId() == null) {
            return false;
        }
        return isFinishedProductRecursive(productModel.getProductId());
    }
    private boolean isFinishedProductRecursive(Long productId) {
        if (productId == null) {
            return false;
        }
        Product product = productMapper.selectById(productId);
        if (product == null) {
            return false;
        }
        if ("成品".equals(product.getProductName())) {
            return true;
        }
        if (product.getParentId() == null) {
            return false;
        }
        return isFinishedProductRecursive(product.getParentId());
    }
}