gongchunyi
14 小时以前 0962b43c6b8874e181107b2b6be21cdd6d198c09
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -2314,10 +2314,28 @@
                    if (dbProduct.getProductModelId() == null) {
                        throw new ServiceException("导入失败,订单编号[" + orderNo + "]产品规格未维护,无法补录出库");
                    }
                    // 历史已发货补录:直接写入入库+出库记录
                    stockUtils.addStock(
                            ledger.getId(),
                            dbProduct.getId(),
                            dbProduct.getProductModelId(),
                            allocQty,
                            StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode(),
                            dbProduct.getId()
                    );
                    stockUtils.substractStock(
                            ledger.getId(),
                            dbProduct.getId(),
                            dbProduct.getProductModelId(),
                            allocQty,
                            StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(),
                            dbProduct.getId()
                    );
                    BigDecimal oldShipped = defaultDecimal(dbProduct.getShippedQuantity());
                    BigDecimal newShipped = oldShipped.add(allocQty);
                    dbProduct.setStockedQuantity(defaultDecimal(dbProduct.getQuantity()));
                    dbProduct.setShippedQuantity(newShipped);
                    dbProduct.setApproveStatus(3);
                    updateProductStockStatus(dbProduct);
                    dbProduct.fillRemainingQuantity();
                    updateProductShipStatus(dbProduct);
@@ -2345,9 +2363,16 @@
                BigDecimal shipped = defaultDecimal(p.getShippedQuantity());
                return shipped.compareTo(qty) >= 0;
            });
            boolean anyInbound = CollectionUtils.isNotEmpty(latestProducts) && latestProducts.stream().anyMatch(p -> defaultDecimal(p.getStockedQuantity()).compareTo(BigDecimal.ZERO) > 0);
            boolean allInbound = CollectionUtils.isNotEmpty(latestProducts) && latestProducts.stream().allMatch(p -> {
                BigDecimal qty = defaultDecimal(p.getQuantity());
                BigDecimal stocked = defaultDecimal(p.getStockedQuantity());
                return qty.compareTo(BigDecimal.ZERO) <= 0 || stocked.compareTo(qty) >= 0;
            });
            if (allShipped && rowList.get(0).getReportDate() != null) {
                ledger.setDeliveryDate(DateUtils.toLocalDate(rowList.get(0).getReportDate()));
            }
            ledger.setStockStatus(allInbound ? 2 : (anyInbound ? 1 : 0));
            ledger.setDeliveryStatus(allShipped ? 5 : 1);
            salesLedgerMapper.updateById(ledger);
        }