From 189fe18f9aaabc39cc4bb4cc00f531bc43fe152e Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 09 六月 2026 16:20:30 +0800
Subject: [PATCH] 新增台账时增加库存类型

---
 src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java |   46 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
index 0de9c64..d5b203b 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -26,6 +26,7 @@
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.mapper.ShippingInfoMapper;
 import com.ruoyi.sales.mapper.ShippingProductDetailMapper;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.sales.pojo.ShippingInfo;
 import com.ruoyi.sales.pojo.ShippingProductDetail;
 import com.ruoyi.sales.service.ShippingInfoService;
@@ -148,8 +149,12 @@
 
     @Override
     public boolean add(ShippingInfoDto req) {
+        String ledgerStockType = resolveLedgerStockType(req.getSalesLedgerProductId());
         this.save(req);
-        req.getBatchNoDetailList().forEach(item -> item.setShippingInfoId(req.getId()));
+        req.getBatchNoDetailList().forEach(item -> {
+            item.setShippingInfoId(req.getId());
+            item.setStockType(ledgerStockType);
+        });
         shippingProductDetailMapper.insert(req.getBatchNoDetailList());
         // 淇濆瓨鏂囦欢
         fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs());
@@ -197,11 +202,16 @@
     }
 
     private void addShippingStockOutRecord(ShippingProductDetail shippingProductDetail, Long shippingInfoId) {
-        String stockType = shippingProductDetail.getStockType();
-        if (stockType != null) {
-            stockType = stockType.trim().toLowerCase();
+        ShippingInfo shippingInfo = this.getById(shippingInfoId);
+        String stockType = resolveLedgerStockType(shippingInfo != null ? shippingInfo.getSalesLedgerProductId() : null);
+        if (stockType == null) {
+            stockType = normalizeStockType(shippingProductDetail.getStockType());
         }
-        if ("waste".equals(stockType) || "unqualified".equals(stockType)) {
+        String detailStockType = normalizeStockType(shippingProductDetail.getStockType());
+        if (detailStockType != null && stockType != null && !stockType.equals(detailStockType)) {
+            throw new RuntimeException("鍙戣揣鏄庣粏搴撳瓨绫诲瀷涓庨攢鍞彴璐︿骇鍝佸簱瀛樼被鍨嬩笉涓�鑷�");
+        }
+        if ("waste".equals(stockType)) {
             StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
             stockUninventoryDto.setRecordId(shippingInfoId);
             stockUninventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
@@ -231,4 +241,30 @@
         String normalized = batchNo.trim();
         return normalized.isEmpty() ? null : normalized;
     }
+
+    private String normalizeStockType(String stockType) {
+        if (stockType == null) {
+            return null;
+        }
+        String normalized = stockType.trim().toLowerCase();
+        if (normalized.isEmpty()) {
+            return null;
+        }
+        if ("unqualified".equals(normalized)) {
+            return "waste";
+        }
+        return normalized;
+    }
+
+    private String resolveLedgerStockType(Long salesLedgerProductId) {
+        if (salesLedgerProductId == null) {
+            return null;
+        }
+        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(salesLedgerProductId);
+        if (salesLedgerProduct == null) {
+            throw new RuntimeException("閿�鍞彴璐︿骇鍝佷笉瀛樺湪");
+        }
+        String stockType = normalizeStockType(salesLedgerProduct.getStockType());
+        return stockType == null ? "qualified" : stockType;
+    }
 }

--
Gitblit v1.9.3