From 802796c22d7d21a6d572cd4c11844e6865521666 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期一, 22 六月 2026 11:53:05 +0800
Subject: [PATCH] 新增库存,采购入库关联供应商,外协入库关联厂家

---
 src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
index fd08560..e6fb860 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -13,6 +13,7 @@
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.stock.enums.StockInventorySourceEnum;
 
 import java.time.LocalDateTime;
 import com.ruoyi.stock.dto.StockInRecordDto;
@@ -240,6 +241,12 @@
                 throw new BaseException("鍙湁寰呭鎵圭姸鎬佺殑璁板綍鎵嶈兘瀹℃壒,鍏ュ簱鎵规:" + stockInRecord.getInboundBatches());
             }
 
+            // 鍏煎鍘嗗彶鏁版嵁鎴栦笂娓告紡浼犲満鏅紝瀹℃壒鏃惰ˉ榻愭潵婧愶紝閬垮厤搴熷搧搴撳瓨鍙拌处鏉ユ簮涓虹┖
+            String resolvedSource = resolveStockSource(stockInRecord);
+            if (StringUtils.isNotEmpty(resolvedSource)) {
+                stockInRecord.setSource(resolvedSource);
+            }
+
             // 鑾峰彇瀹℃壒鏃朵慨鏀圭殑鍏ュ簱鏁伴噺锛屽鏋滄病鏈変慨鏀瑰垯浣跨敤鍘熸暟閲�
             final BigDecimal finalStockInNum;
             if (item.getStockInNum() != null && item.getStockInNum().compareTo(BigDecimal.ZERO) > 0) {
@@ -274,8 +281,12 @@
                             setBatchNo(stockInRecord.getBatchNo());
                             setRemark(stockInRecord.getRemark());
                             setWarnNum(stockInRecord.getWarnNum());
-                            setManufacturerId(stockInRecord.getManufacturerId());
                             setSource(stockInRecord.getSource());
+                            if (StockInventorySourceEnum.PURCHASE_RECEIPT.getCode().equals(stockInRecord.getSource())) {
+                                setSupplierId(stockInRecord.getSupplierId());
+                            } else if (StockInventorySourceEnum.OUTSOURCED_RECEIPT.getCode().equals(stockInRecord.getSource())) {
+                                setManufacturerId(stockInRecord.getManufacturerId());
+                            }
                             setVersion(1);
                         }});
                     } else {
@@ -290,10 +301,8 @@
                     stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo());
                     stockUninventoryDto.setQualitity(finalStockInNum);
                     stockUninventoryDto.setRemark(stockInRecord.getRemark());
-                    stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
                     stockUninventoryDto.setSource(stockInRecord.getSource());
                     stockUninventoryDto.setType(uninventoryType);
-                    stockUninventoryDto.setSource(stockInRecord.getSource());
                     if (stockUninventory == null) {
                         stockUninventoryMapper.insert(new StockUninventory() {{
                             setProductModelId(stockInRecord.getProductModelId());
@@ -301,7 +310,6 @@
                             setBatchNo(stockInRecord.getBatchNo());
                             setType(uninventoryType);
                             setRemark(stockInRecord.getRemark());
-                            setManufacturerId(stockInRecord.getManufacturerId());
                             setSource(stockInRecord.getSource());
                             setVersion(1);
                         }});
@@ -349,11 +357,32 @@
         stockInventoryDto.setBatchNo(stockInRecord.getBatchNo());
         stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
         stockInventoryDto.setRemark(stockInRecord.getRemark());
-        stockInventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
         stockInventoryDto.setSource(stockInRecord.getSource());
+        if (StockInventorySourceEnum.PURCHASE_RECEIPT.getCode().equals(stockInRecord.getSource())) {
+            stockInventoryDto.setSupplierId(stockInRecord.getSupplierId());
+        } else if (StockInventorySourceEnum.OUTSOURCED_RECEIPT.getCode().equals(stockInRecord.getSource())) {
+            stockInventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
+        }
         return stockInventoryDto;
     }
 
+    private String resolveStockSource(StockInRecord stockInRecord) {
+        if (stockInRecord == null || StringUtils.isNotEmpty(stockInRecord.getSource())) {
+            return stockInRecord == null ? null : stockInRecord.getSource();
+        }
+        if (StockInQualifiedRecordTypeEnum.DEFECTIVE_SCRAP.getCode().equals(stockInRecord.getRecordType())
+                || StockInQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode().equals(stockInRecord.getRecordType())) {
+            if (StockInQualifiedRecordTypeEnum.DEFECTIVE_SCRAP.getCode().equals(stockInRecord.getRecordType())) {
+                return StockInventorySourceEnum.DEFECTIVE_SCRAP.getCode();
+            }
+            return StockInventorySourceEnum.PROD_GENERATED.getCode();
+        }
+        if (StockInQualifiedRecordTypeEnum.RETURN_WASTE_IN.getCode().equals(stockInRecord.getRecordType())) {
+            return StockInventorySourceEnum.RETURN_GENERATED.getCode();
+        }
+        return stockInRecord.getSource();
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int batchReAudit(List<Long> ids) {

--
Gitblit v1.9.3