gongchunyi
2026-09-23 e07fe939bb0775452ef8831bcd5e7035f931b679
src/main/java/com/ruoyi/basic/service/impl/SupplierServiceImpl.java
@@ -226,11 +226,9 @@
                List<StockInRecord> currentDirectRecords = directInboundRecords.stream().filter(s -> s.getRecordId().equals(ledgerId)).toList();
                for (StockInRecord sir : currentDirectRecords) {
                    List<SalesLedgerProduct> currentProducts = salesLedgerProducts.stream().filter(s -> s.getSalesLedgerId().equals(ledgerId)).toList();
                    for (SalesLedgerProduct slp : currentProducts) {
                        if (sir.getStockInNum() != null && slp.getTaxInclusiveUnitPrice() != null) {
                            shippedAmount = shippedAmount.add(sir.getStockInNum().multiply(slp.getTaxInclusiveUnitPrice()));
                        }
                    BigDecimal unitPrice = getPurchaseInboundUnitPrice(salesLedgerProducts, ledgerId, sir);
                    if (sir.getStockInNum() != null && unitPrice != null) {
                        shippedAmount = shippedAmount.add(sir.getStockInNum().multiply(unitPrice));
                    }
                }
@@ -323,11 +321,9 @@
            List<StockInRecord> currentDirectRecords = directInboundRecords.stream().filter(s -> s.getRecordId().equals(vo.getPurchaseLedgerId())).toList();
            for (StockInRecord sir : currentDirectRecords) {
                List<SalesLedgerProduct> currentProducts = salesLedgerProducts.stream().filter(s -> s.getSalesLedgerId().equals(vo.getPurchaseLedgerId())).toList();
                for (SalesLedgerProduct slp : currentProducts) {
                    if (sir.getStockInNum() != null && slp.getTaxInclusiveUnitPrice() != null) {
                        shippedAmount = shippedAmount.add(sir.getStockInNum().multiply(slp.getTaxInclusiveUnitPrice()));
                    }
                BigDecimal unitPrice = getPurchaseInboundUnitPrice(salesLedgerProducts, vo.getPurchaseLedgerId(), sir);
                if (sir.getStockInNum() != null && unitPrice != null) {
                    shippedAmount = shippedAmount.add(sir.getStockInNum().multiply(unitPrice));
                }
            }
@@ -373,4 +369,29 @@
                .min(BigDecimal::compareTo)
                .orElse(null);
    }
    /**
     * 直接入库记录(7)的含税单价:批次号格式为“采购合同号-采购产品行ID”,按对应产品行取价
     */
    private BigDecimal getPurchaseInboundUnitPrice(List<SalesLedgerProduct> allSlp, Long salesLedgerId, StockInRecord record) {
        String batchNo = record.getBatchNo();
        int separatorIndex = batchNo == null ? -1 : batchNo.lastIndexOf('-');
        if (separatorIndex > -1) {
            try {
                Long productId = Long.valueOf(batchNo.substring(separatorIndex + 1));
                BigDecimal unitPrice = allSlp.stream()
                        .filter(s -> s.getId().equals(productId))
                        .map(SalesLedgerProduct::getTaxInclusiveUnitPrice)
                        .filter(java.util.Objects::nonNull)
                        .findFirst()
                        .orElse(null);
                if (unitPrice != null) {
                    return unitPrice;
                }
            } catch (NumberFormatException ignored) {
                // 批次号不符合约定格式,回退按产品规格匹配
            }
        }
        return getMinTaxInclusiveUnitPrice(allSlp, salesLedgerId, record.getProductModelId());
    }
}