From 9bad654b1062facc325d57f383e5f318d4e0de9c Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期日, 21 六月 2026 13:13:23 +0800
Subject: [PATCH] feat: 补片直接入库出库

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 1b4c7fc..6bdd037 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -2463,6 +2463,9 @@
             if (CollectionUtils.isEmpty(rowList)) {
                 continue;
             }
+            if (StringUtils.hasText(rowList.get(0).getCustomerName()) && rowList.get(0).getCustomerName().startsWith("琛ョ墖")) {
+                continue;
+            }
             SalesLedger ledger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>().eq(SalesLedger::getSalesContractNo, orderNo).last("LIMIT 1"));
             if (ledger == null) {
 //                throw new ServiceException("瀵煎叆澶辫触,璁㈠崟缂栧彿[" + orderNo + "]涓嶅瓨鍦�,鏃犳硶琛ュ綍宸插彂璐ф暟鎹�");
@@ -2563,6 +2566,7 @@
             ledger.setStockStatus(allInbound ? 2 : (anyInbound ? 1 : 0));
             ledger.setDeliveryStatus(allShipped ? 5 : 1);
 //            ledger.setReviewStatus(1);
+            ledger.setOrderStatus(1);
             salesLedgerMapper.updateById(ledger);
         }
     }
@@ -2720,6 +2724,88 @@
 
                 salesLedgerProductServiceImpl.addProductionData(product);
                 contractAmount = contractAmount.add(lineAmount);
+
+                if (customer.getCustomerName() != null && customer.getCustomerName().startsWith("琛ョ墖")) {
+                    stockUtils.addStock(
+                            ledger.getId(),
+                            product.getId(),
+                            product.getProductModelId(),
+                            qty,
+                            StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode(),
+                            product.getId()
+                    );
+                    stockUtils.substractStock(
+                            ledger.getId(),
+                            product.getId(),
+                            product.getProductModelId(),
+                            qty,
+                            StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(),
+                            product.getId()
+                    );
+
+                    StockInRecord inRecord = stockInRecordMapper.selectOne(new LambdaQueryWrapper<StockInRecord>()
+                            .eq(StockInRecord::getSalesLedgerProductId, product.getId())
+                            .orderByDesc(StockInRecord::getId).last("LIMIT 1"));
+                    if (inRecord != null) {
+                        String batch = "RK";
+                        if (row.getReportDate() != null) {
+                            String dateStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(row.getReportDate());
+                            batch += dateStr + "-" + row.getReportDate().getTime();
+                        } else {
+                            batch += System.currentTimeMillis() + "-" + inRecord.getId();
+                        }
+                        inRecord.setInboundBatches(batch);
+                        if (row.getReportDate() != null) {
+                            LocalDateTime reportDateTime = LocalDateTime.ofInstant(row.getReportDate().toInstant(), ZoneId.systemDefault());
+                            inRecord.setCreateTime(reportDateTime);
+                            inRecord.setUpdateTime(reportDateTime);
+                        }
+                        stockInRecordMapper.updateById(inRecord);
+                    }
+
+                    StockOutRecord outRecord = stockOutRecordMapper.selectOne(new LambdaQueryWrapper<StockOutRecord>()
+                            .eq(StockOutRecord::getSalesLedgerProductId, product.getId())
+                            .orderByDesc(StockOutRecord::getId).last("LIMIT 1"));
+                    if (outRecord != null) {
+                        String batch = "CK";
+                        if (row.getReportDate() != null) {
+                            String dateStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(row.getReportDate());
+                            batch += dateStr + "-" + row.getReportDate().getTime();
+                        } else {
+                            batch += System.currentTimeMillis() + "-" + outRecord.getId();
+                        }
+                        outRecord.setOutboundBatches(batch);
+                        if (row.getReportDate() != null) {
+                            LocalDateTime reportDateTime = LocalDateTime.ofInstant(row.getReportDate().toInstant(), ZoneId.systemDefault());
+                            outRecord.setCreateTime(reportDateTime);
+                            outRecord.setUpdateTime(reportDateTime);
+                        }
+                        stockOutRecordMapper.updateById(outRecord);
+                    }
+
+                    product.setStockedQuantity(qty);
+                    product.setShippedQuantity(qty);
+                    product.setApproveStatus(3);
+                    updateProductStockStatus(product);
+                    product.fillRemainingQuantity();
+                    updateProductShipStatus(product);
+                    salesLedgerProductMapper.updateById(product);
+
+                    ShippingInfo shippingInfo = new ShippingInfo();
+                    shippingInfo.setSalesLedgerId(ledger.getId());
+                    shippingInfo.setSalesLedgerProductId(product.getId());
+                    shippingInfo.setStatus("宸插彂璐�");
+                    if (row.getReportDate() != null) {
+                        String dateStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(row.getReportDate());
+                        shippingInfo.setShippingNo("CK" + dateStr + "-" + row.getReportDate().getTime());
+                    } else {
+                        shippingInfo.setShippingNo("CK" + System.currentTimeMillis());
+                    }
+                    shippingInfo.setType("璐ц溅");
+                    shippingInfo.setShippingCarNumber("鏃�");
+                    shippingInfo.setShippingDate(row.getReportDate());
+                    shippingInfoMapper.insert(shippingInfo);
+                }
             }
 
             ledger.setContractAmount(contractAmount);
@@ -2727,6 +2813,27 @@
                 ledger.setReviewStatus(1);
             }
 
+            if (customer.getCustomerName() != null && customer.getCustomerName().startsWith("琛ョ墖")) {
+                List<SalesLedgerProduct> latestProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId()).eq(SalesLedgerProduct::getType, SaleEnum.SALE.getCode()));
+                boolean allShipped = CollectionUtils.isNotEmpty(latestProducts) && latestProducts.stream().allMatch(p -> {
+                    BigDecimal pQty = defaultDecimal(p.getQuantity());
+                    BigDecimal shipped = defaultDecimal(p.getShippedQuantity());
+                    return shipped.compareTo(pQty) >= 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 pQty = defaultDecimal(p.getQuantity());
+                    BigDecimal stocked = defaultDecimal(p.getStockedQuantity());
+                    return pQty.compareTo(BigDecimal.ZERO) <= 0 || stocked.compareTo(pQty) >= 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);
+                ledger.setOrderStatus(1);
+            }
+
             salesLedgerMapper.updateById(ledger);
         }
     }

--
Gitblit v1.9.3