feat(stock): 完善成品库存维度解析和生产投料扣减逻辑
- 在电压参数解析中增加非成品情况下的空值返回
- 在工艺路线成品类别判断中增加非成品情况下的空值返回
- 添加光检外观和包装工序跳过库存扣减的功能
- 修改生产投料环节仅对非光检包装工序执行库存扣减
已修改2个文件
107 ■■■■ 文件已修改
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/support/FinishedProductStockDimensionResolver.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -327,6 +327,11 @@
        // 第七步-1:投入数量强制取前端传入的 bomInputQty
        BigDecimal inputBaseQty = bomInputQty;
        // 第七步-2:光检外观和包装工序不扣减库存
        String currentProcessName = productProcess.getName() == null ? "" : productProcess.getName().trim();
        boolean shouldSkipStockDeduction = PROCESS_OPTICAL_INSPECTION.equals(currentProcessName)
                || PROCESS_PACKAGING.equals(currentProcessName);
        for (ProductStructureDto productStructureDto : productStructureDtos) {
            if (productStructureDto.getProductModelId() == null) {
                throw new ServiceException("投入物料产品型号不能为空");
@@ -357,14 +362,16 @@
            productionProductInput.setProductMainId(productionProductMain.getId());
            productionProductInputMapper.insert(productionProductInput);
            stockUtils.substractStock(
                    productStructureDto.getProductModelId(),
                    needQty,
                    StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
                    productionProductMain.getId(),
                    null,
                    null
            );
            if (!shouldSkipStockDeduction) {
                stockUtils.substractStock(
                        productStructureDto.getProductModelId(),
                        needQty,
                        StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
                        productionProductMain.getId(),
                        null,
                        null
                );
            }
        }
        // 第八步:写产出记录并计算本次合格数量
@@ -852,4 +859,4 @@
        }
        return null;
    }
}
}
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());
    }
}