gongchunyi
6 小时以前 3481d209ec847542b73fa16616ffe0e13c949e80
fix: 入库与出库数量绑定
已修改8个文件
250 ■■■■ 文件已修改
doc/河南鹤壁天沐钢化玻璃厂.sql 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java 88 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/pojo/SalesLedgerProduct.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java 73 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
doc/ºÓÄϺױÚÌìãå¸Ö»¯²£Á§³§.sql
@@ -128,4 +128,14 @@
    ADD COLUMN `stocked_quantity` decimal(18, 2) DEFAULT 0.00 COMMENT '已入库数量' AFTER `product_stock_status`;
ALTER TABLE `sales_ledger_product`
    ADD COLUMN `remaining_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT '剩余待入库数量' AFTER `stocked_quantity`
    ADD COLUMN `remaining_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT '剩余待入库数量' AFTER `stocked_quantity`;
ALTER TABLE `sales_ledger_product`
    ADD COLUMN `shipped_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT '已出库数量' AFTER `stocked_quantity`;
ALTER TABLE `sales_ledger_product`
    ADD COLUMN `remaining_shipped_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT '剩余待出库数量' AFTER `shipped_quantity`;
ALTER TABLE `sales_ledger_product`
    ADD COLUMN `unqualified_stocked_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT '不合格入库数量' AFTER `stocked_quantity`,
    ADD COLUMN `unqualified_shipped_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT '不合格出库数量' AFTER `shipped_quantity`;
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -214,7 +214,8 @@
                            purchaseLedgerServiceImpl.addQualityInspect(purchaseLedger, salesLedgerProduct);
                        }else {
                            //直接入库
                            stockUtils.addStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), purchaseLedger.getId());
                            stockUtils.addStock(null, salesLedgerProduct.getId(), salesLedgerProduct.getProductModelId(),
                                    salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), salesLedgerProduct.getId());
                        }
                    }
                } else if (status.equals(3)) {
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -51,7 +51,13 @@
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.mapper.StockInRecordMapper;
import com.ruoyi.stock.mapper.StockOutRecordMapper;
import com.ruoyi.stock.pojo.StockInRecord;
import com.ruoyi.stock.pojo.StockOutRecord;
import com.ruoyi.stock.service.StockInRecordService;
import com.ruoyi.stock.service.StockInventoryService;
import com.ruoyi.stock.service.StockOutRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
@@ -154,6 +160,14 @@
    private SalesLedgerProductTemplateMapper salesLedgerProductTemplateMapper;
    @Autowired
    private StockInventoryService stockInventoryService;
    @Autowired
    private StockInRecordMapper stockInRecordMapper;
    @Autowired
    private StockOutRecordMapper stockOutRecordMapper;
    @Autowired
    private StockInRecordService stockInRecordService;
    @Autowired
    private StockOutRecordService stockOutRecordService;
    @Autowired
    private StockUtils stockUtils;
    @Value("${file.upload-dir}")
@@ -447,6 +461,34 @@
                .eq(SalesLedgerProduct::getType, 2);
        List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(salesLedgerProductQueryWrapper);
        if (CollectionUtils.isNotEmpty(salesLedgerProducts)) {
            List<Long> productIds = salesLedgerProducts.stream().map(SalesLedgerProduct::getId).filter(Objects::nonNull).collect(Collectors.toList());
            // åˆ é™¤å°è´¦å‰å…ˆå›žé€€åº“存记录(先删出库再删入库),避免库存回退校验被误拦
            if (CollectionUtils.isNotEmpty(productIds)) {
                List<Long> stockOutRecordIds = stockOutRecordMapper.selectList(new LambdaQueryWrapper<StockOutRecord>()
                                .and(w -> w
                                        .in(StockOutRecord::getSalesLedgerProductId, productIds)
                                        .or(q -> q.in(StockOutRecord::getRecordId, productIds)
                                                .in(StockOutRecord::getRecordType, Arrays.asList(
                                                        StockOutUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_OUT.getCode()
                                                ))))
                                .select(StockOutRecord::getId))
                        .stream().map(StockOutRecord::getId).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(stockOutRecordIds)) {
                    stockOutRecordService.batchDelete(stockOutRecordIds);
                }
                List<Long> stockInRecordIds = stockInRecordMapper.selectList(new LambdaQueryWrapper<StockInRecord>()
                                .and(w -> w
                                        .in(StockInRecord::getSalesLedgerProductId, productIds)
                                        .or(q -> q.in(StockInRecord::getRecordId, productIds)
                                                .in(StockInRecord::getRecordType, Arrays.asList(
                                                        StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode()
                                                ))))
                                .select(StockInRecord::getId))
                        .stream().map(StockInRecord::getId).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(stockInRecordIds)) {
                    stockInRecordService.batchDelete(stockInRecordIds);
                }
            }
            salesLedgerProducts.stream().forEach(salesLedgerProduct -> {
                // æ‰¹é‡åˆ é™¤å…³è”的采购台账产品
                LambdaQueryWrapper<ProcurementRecordStorage> queryWrapper = new LambdaQueryWrapper<>();
@@ -828,6 +870,9 @@
        if (purchaseLedger == null) {
            throw new ServiceException("入库失败,采购台账不存在");
        }
        if (!Objects.equals(purchaseLedger.getApprovalStatus(), 3)) {
            throw new ServiceException("入库失败,采购订单未审批通过,不允许扫码入库");
        }
        if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) {
            throw new ServiceException("采购入库失败,入库产品不能为空");
        }
@@ -901,6 +946,9 @@
        if (purchaseLedger == null) {
            throw new ServiceException("出库失败,采购台账不存在");
        }
        if (!Objects.equals(purchaseLedger.getApprovalStatus(), 3)) {
            throw new ServiceException("出库失败,采购订单未审批通过,不允许扫码出库");
        }
        if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) {
            throw new ServiceException("采购出库失败,出库产品不能为空");
        }
@@ -938,12 +986,6 @@
            }
            stockUtils.assertQualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine);
            BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity();
            BigDecimal newStocked = oldStocked.subtract(outboundThisLine);
            if (newStocked.compareTo(BigDecimal.ZERO) < 0) {
                newStocked = BigDecimal.ZERO;
            }
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setRecordId(dbProduct.getId());
            stockInventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.PURCHASE_SCAN_STOCK_OUT.getCode());
@@ -953,17 +995,8 @@
            stockInventoryDto.setSalesLedgerProductId(dbProduct.getId());
            stockInventoryService.subtractStockInventory(stockInventoryDto);
            BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity();
            int lineStockStatus;
            if (newStocked.compareTo(BigDecimal.ZERO) <= 0) {
                lineStockStatus = 0;
            } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) {
                lineStockStatus = 1;
            } else {
                lineStockStatus = 2;
            }
            dbProduct.setStockedQuantity(newStocked);
            dbProduct.setProductStockStatus(lineStockStatus);
            BigDecimal oldShipped = dbProduct.getShippedQuantity() == null ? BigDecimal.ZERO : dbProduct.getShippedQuantity();
            dbProduct.setShippedQuantity(oldShipped.add(outboundThisLine));
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }
@@ -978,6 +1011,9 @@
        PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(dto.getPurchaseLedgerId());
        if (purchaseLedger == null) {
            throw new ServiceException("不合格入库失败,采购台账不存在");
        }
        if (!Objects.equals(purchaseLedger.getApprovalStatus(), 3)) {
            throw new ServiceException("不合格入库失败,采购订单未审批通过,不允许扫码入库");
        }
        if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) {
            throw new ServiceException("采购不合格入库失败,入库产品不能为空");
@@ -1016,6 +1052,11 @@
            }
            stockUtils.addUnStock(null, null, dbProduct.getProductModelId(), inboundThisLine,
                    StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId());
            BigDecimal oldUnStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity();
            dbProduct.setUnqualifiedStockedQuantity(oldUnStocked.add(inboundThisLine));
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }
    }
@@ -1028,6 +1069,9 @@
        PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(dto.getPurchaseLedgerId());
        if (purchaseLedger == null) {
            throw new ServiceException("不合格出库失败,采购台账不存在");
        }
        if (!Objects.equals(purchaseLedger.getApprovalStatus(), 3)) {
            throw new ServiceException("不合格出库失败,采购订单未审批通过,不允许扫码出库");
        }
        if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) {
            throw new ServiceException("采购不合格出库失败,出库产品不能为空");
@@ -1064,9 +1108,19 @@
            if (dbProduct.getProductModelId() == null) {
                throw new ServiceException("不合格出库失败,产品规格未维护,无法出库");
            }
            BigDecimal unStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity();
            BigDecimal unShipped = dbProduct.getUnqualifiedShippedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedShippedQuantity();
            BigDecimal canUnShip = unStocked.subtract(unShipped);
            if (outboundThisLine.compareTo(canUnShip) > 0) {
                throw new ServiceException("不合格出库失败,出库数量不能大于不合格入库数量");
            }
            stockUtils.assertUnqualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine);
            stockUtils.subtractUnStock(null, null, dbProduct.getProductModelId(), outboundThisLine,
                    StockOutUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_OUT.getCode(), dbProduct.getId());
            dbProduct.setUnqualifiedShippedQuantity(unShipped.add(outboundThisLine));
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }
    }
src/main/java/com/ruoyi/sales/pojo/SalesLedgerProduct.java
@@ -78,6 +78,11 @@
     */
    private BigDecimal stockedQuantity;
    /**
     * å·²å‡ºåº“数量
     */
    private BigDecimal shippedQuantity;
    @Excel(name = "最低库存数量")
    private BigDecimal minStock;
@@ -87,6 +92,22 @@
    @Excel(name = "剩余数量")
    @ApiModelProperty("剩余待入库数量(订单数量-合格已入库)")
    private BigDecimal remainingQuantity;
    /**
     * å‰©ä½™å‡ºåº“数量
     */
    private BigDecimal remainingShippedQuantity;
    /**
     * ä¸åˆæ ¼å…¥åº“数量
     */
    private BigDecimal unqualifiedStockedQuantity;
    /**
     * ä¸åˆæ ¼å‡ºåº“数量
     */
    private BigDecimal unqualifiedShippedQuantity;
    /**
     * ç¨Žçއ
@@ -330,8 +351,14 @@
    public void fillRemainingQuantity() {
        BigDecimal q = this.quantity == null ? BigDecimal.ZERO : this.quantity;
        BigDecimal stocked = this.stockedQuantity == null ? BigDecimal.ZERO : this.stockedQuantity;
        BigDecimal rem = q.subtract(stocked);
        this.remainingQuantity = rem.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : rem;
        BigDecimal remIn = q.subtract(stocked);
        this.remainingQuantity = remIn.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : remIn;
        BigDecimal shipped = this.shippedQuantity == null ? BigDecimal.ZERO : this.shippedQuantity;
        // å‰©ä½™å‡ºåº“数量:以“已入库数量”为基准(出库只能从已入库中扣减)
        BigDecimal remOut = stocked.subtract(shipped);
        this.remainingShippedQuantity = remOut.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : remOut;
    }
}
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -193,19 +193,27 @@
            if (item.getFutureTicketsAmount() == null || item.getFutureTicketsAmount().compareTo(BigDecimal.ZERO) == 0) {
                item.setFutureTicketsAmount(BigDecimal.ZERO);
            }
            if (item.getApproveStatus() == null || item.getApproveStatus() != 2) {
                Integer hasSufficientStock = item.getHasSufficientStock();
                if (hasSufficientStock != null && hasSufficientStock == 0) {
                    item.setApproveStatus(0);
                } else {
                    item.setApproveStatus(1);
                }
            }
            BigDecimal returnQuality = finalReturnOrderGroupDtoMap.getOrDefault(item.getId(), BigDecimal.ZERO);
            item.setReturnQuality(returnQuality);
            BigDecimal quantity = item.getQuantity() == null ? BigDecimal.ZERO : item.getQuantity();
            item.setAvailableQuality(quantity.subtract(returnQuality));
            BigDecimal shipped = item.getShippedQuantity() == null ? BigDecimal.ZERO : item.getShippedQuantity();
            BigDecimal available = quantity.subtract(returnQuality).subtract(shipped);
            item.setAvailableQuality(available.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : available);
            item.fillRemainingQuantity();
            if (item.getApproveStatus() == null || item.getApproveStatus() != 2) {
                BigDecimal remainingShipped = item.getRemainingShippedQuantity() == null ? BigDecimal.ZERO : item.getRemainingShippedQuantity();
                boolean hasOutbound = shipped.compareTo(BigDecimal.ZERO) > 0;
                if (hasOutbound && remainingShipped.compareTo(BigDecimal.ZERO) <= 0) {
                    item.setApproveStatus(0);
                } else {
                    Integer hasSufficientStock = item.getHasSufficientStock();
                    if (hasSufficientStock != null && hasSufficientStock == 0) {
                        item.setApproveStatus(0);
                    } else {
                        item.setApproveStatus(1);
                    }
                }
            }
            ProductModel productModel = finalProductModelMap.get(item.getProductModelId());
            if (productModel != null) {
                item.setThickness(productModel.getThickness());
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1690,22 +1690,55 @@
            throw new ServiceException("入库失败,未查询到该销售订单的销售产品");
        }
        for (SalesLedgerProduct product : salesLedgerProducts) {
            if (!Objects.equals(product.getSalesLedgerId(), ledger.getId())) {
                throw new ServiceException("入库失败,存在不属于当前销售订单的产品");
            }
            if (product.getProductModelId() == null) {
                continue;
            }
            BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity();
            BigDecimal oldStocked = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity();
            BigDecimal inboundQty = orderQty.subtract(oldStocked);
            if (inboundQty.compareTo(BigDecimal.ZERO) < 0) {
                inboundQty = BigDecimal.ZERO;
            }
            if (inboundQty.compareTo(BigDecimal.ZERO) <= 0) {
                continue;
            }
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setRecordId(product.getId());
            stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode());
            stockInventoryDto.setQualitity(product.getQuantity());
            stockInventoryDto.setQualitity(inboundQty);
            stockInventoryDto.setProductModelId(product.getProductModelId());
            stockInventoryDto.setSalesLedgerId(ledger.getId());
            stockInventoryDto.setSalesLedgerProductId(product.getId());
            stockInventoryService.addstockInventory(stockInventoryDto);
            BigDecimal newStocked = oldStocked.add(inboundQty);
            int lineStockStatus;
            if (newStocked.compareTo(BigDecimal.ZERO) <= 0) {
                lineStockStatus = 0;
            } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) {
                lineStockStatus = 1;
            } else {
                lineStockStatus = 2;
            }
            product.setStockedQuantity(newStocked);
            product.setProductStockStatus(lineStockStatus);
            product.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(product);
        }
        //  æŒ‰é”€å”®è®¢å•产品入库情况更新主单入库状态:1-部分入库,2-已入库
        List<SalesLedgerProduct> ledgerAllProducts = salesLedgerProductMapper.selectList(Wrappers.<SalesLedgerProduct>lambdaQuery().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId()));
        boolean hasStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().anyMatch(item -> Objects.equals(item.getProductStockStatus(), 1));
        boolean allStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().allMatch(item -> Objects.equals(item.getProductStockStatus(), 1));
        boolean hasStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().anyMatch(item -> {
            BigDecimal sq = item.getStockedQuantity();
            return sq != null && sq.compareTo(BigDecimal.ZERO) > 0;
        });
        boolean allStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().allMatch(item -> {
            BigDecimal orderQty = item.getQuantity() == null ? BigDecimal.ZERO : item.getQuantity();
            BigDecimal stockedQty = item.getStockedQuantity() == null ? BigDecimal.ZERO : item.getStockedQuantity();
            return orderQty.compareTo(BigDecimal.ZERO) <= 0 || stockedQty.compareTo(orderQty) >= 0;
        });
        ledger.setStockStatus(allStocked ? 2 : (hasStocked ? 1 : 0));
        baseMapper.updateById(ledger);
    }
@@ -1874,6 +1907,11 @@
            }
            stockUtils.addUnStock(ledgerId, dbProduct.getId(), dbProduct.getProductModelId(), inboundThisLine,
                    StockInUnQualifiedRecordTypeEnum.SALES_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId());
            BigDecimal oldUnStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity();
            dbProduct.setUnqualifiedStockedQuantity(oldUnStocked.add(inboundThisLine));
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }
    }
@@ -1927,12 +1965,6 @@
            }
            stockUtils.assertQualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine);
            BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity();
            BigDecimal newStocked = oldStocked.subtract(outboundThisLine);
            if (newStocked.compareTo(BigDecimal.ZERO) < 0) {
                newStocked = BigDecimal.ZERO;
            }
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setRecordId(dbProduct.getId());
            stockInventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SCAN_STOCK_OUT.getCode());
@@ -1942,17 +1974,8 @@
            stockInventoryDto.setSalesLedgerProductId(dbProduct.getId());
            stockInventoryService.subtractStockInventory(stockInventoryDto);
            BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity();
            int lineStockStatus;
            if (newStocked.compareTo(BigDecimal.ZERO) <= 0) {
                lineStockStatus = 0;
            } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) {
                lineStockStatus = 1;
            } else {
                lineStockStatus = 2;
            }
            dbProduct.setStockedQuantity(newStocked);
            dbProduct.setProductStockStatus(lineStockStatus);
            BigDecimal oldShipped = dbProduct.getShippedQuantity() == null ? BigDecimal.ZERO : dbProduct.getShippedQuantity();
            dbProduct.setShippedQuantity(oldShipped.add(outboundThisLine));
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }
@@ -2015,9 +2038,19 @@
            if (dbProduct.getProductModelId() == null) {
                throw new ServiceException("不合格出库失败,产品规格未维护,无法出库");
            }
            BigDecimal unStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity();
            BigDecimal unShipped = dbProduct.getUnqualifiedShippedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedShippedQuantity();
            BigDecimal canUnShip = unStocked.subtract(unShipped);
            if (outboundThisLine.compareTo(canUnShip) > 0) {
                throw new ServiceException("不合格出库失败,出库数量不能大于不合格入库数量");
            }
            stockUtils.assertUnqualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine);
            stockUtils.subtractUnStock(ledgerId, dbProduct.getId(), dbProduct.getProductModelId(), outboundThisLine,
                    StockOutUnQualifiedRecordTypeEnum.SALE_SCAN_UNSTOCK_OUT.getCode(), dbProduct.getId());
            dbProduct.setUnqualifiedShippedQuantity(unShipped.add(outboundThisLine));
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }
    }
}
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -88,6 +88,9 @@
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId());
            if (salesLedgerProduct != null) {
                stockUtils.substractStock(salesLedgerProduct.getSalesLedgerId(), salesLedgerProduct.getId(), salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
                BigDecimal shipped = salesLedgerProduct.getShippedQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getShippedQuantity();
                salesLedgerProduct.setShippedQuantity(shipped.add(salesLedgerProduct.getQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getQuantity()));
                salesLedgerProductMapper.updateById(salesLedgerProduct);
            }
        }
        byId.setExpressNumber(req.getExpressNumber());
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -58,13 +58,15 @@
    @Transactional(rollbackFor = Exception.class)
    public Boolean addstockInventory(StockInventoryDto stockInventoryDto) {
        //新增入库记录再添加库存
        //  æ›´æ–°äº§å“å…¥åº“状态
        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId());
        if (salesLedgerProduct == null) {
            throw new ServiceException("入库失败,销售产品不存在");
        //  æ›´æ–°è®¢å•产品入库状态(仅当传入了产品行ID时)
        if (stockInventoryDto.getSalesLedgerProductId() != null) {
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId());
            if (salesLedgerProduct == null) {
                throw new ServiceException("入库失败,销售产品不存在");
            }
            salesLedgerProduct.setProductStockStatus(1);
            salesLedgerProductMapper.updateById(salesLedgerProduct);
        }
        salesLedgerProduct.setProductStockStatus(1);
        salesLedgerProductMapper.updateById(salesLedgerProduct);
        StockInRecordDto stockInRecordDto = new StockInRecordDto();
        stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());