From 5d81fcc5768741323a2e343fc01f44e17e68b65b Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 25 六月 2026 14:59:38 +0800
Subject: [PATCH] 1.库存入库新增质检流程 2.销售相关查询返回总合同号 3.采购相关查询返回总合同号

---
 src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
index 24605ba..afa8098 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -14,6 +14,9 @@
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.project.system.service.ISysDictDataService;
+import com.ruoyi.quality.dto.QualityInspectDto;
+import com.ruoyi.quality.service.IQualityInspectService;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.stock.dto.StockInRecordDto;
@@ -29,7 +32,8 @@
 import com.ruoyi.stock.service.StockOutRecordService;
 import com.ruoyi.stock.service.StockUninventoryService;
 import jakarta.servlet.http.HttpServletResponse;
-import lombok.RequiredArgsConstructor;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
@@ -51,7 +55,6 @@
  * @since 2026-01-21 04:16:36
  */
 @Service
-@RequiredArgsConstructor
 public class StockInventoryServiceImpl extends ServiceImpl<StockInventoryMapper, StockInventory> implements StockInventoryService {
 
     private final StockInventoryMapper stockInventoryMapper;
@@ -60,6 +63,27 @@
     private final StockUninventoryService stockUninventoryService;
     private final SalesLedgerProductMapper salesLedgerProductMapper;
     private final ProductModelMapper productModelMapper;
+    private final ISysDictDataService sysDictDataService;
+    private final IQualityInspectService qualityInspectService;
+
+    public StockInventoryServiceImpl(
+            StockInventoryMapper stockInventoryMapper,
+            StockInRecordService stockInRecordService,
+            StockOutRecordService stockOutRecordService,
+            StockUninventoryService stockUninventoryService,
+            SalesLedgerProductMapper salesLedgerProductMapper,
+            ProductModelMapper productModelMapper,
+            ISysDictDataService sysDictDataService,
+            @Lazy IQualityInspectService qualityInspectService) {
+        this.stockInventoryMapper = stockInventoryMapper;
+        this.stockInRecordService = stockInRecordService;
+        this.stockOutRecordService = stockOutRecordService;
+        this.stockUninventoryService = stockUninventoryService;
+        this.salesLedgerProductMapper = salesLedgerProductMapper;
+        this.productModelMapper = productModelMapper;
+        this.sysDictDataService = sysDictDataService;
+        this.qualityInspectService = qualityInspectService;
+    }
 
     @Override
     public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
@@ -81,6 +105,12 @@
         }
         stockInventoryDto.setBatchNo(batchNo);
 
+        // 澶勭悊浠撳簱瀛楁锛氱┖瀛楃涓叉垨null鏃跺彇娑堢粦瀹�
+        String warehouse = stockInventoryDto.getWarehouse();
+        if (StringUtils.isEmpty(warehouse)) {
+            stockInventoryDto.setWarehouse(null);
+        }
+
         LambdaQueryWrapper<StockInventory> eq = new QueryWrapper<StockInventory>().lambda()
                 .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId());
         eq.eq(StockInventory::getBatchNo, stockInventoryDto.getBatchNo());
@@ -92,6 +122,7 @@
         stockInRecordDto.setBatchNo(stockInventoryDto.getBatchNo());
         stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
         stockInRecordDto.setType("0");
+        stockInRecordDto.setCreateTime(stockInventoryDto.getCreateTime());
         stockInRecordService.add(stockInRecordDto);
         //鍐嶈繘琛屾柊澧炲簱瀛樻暟閲忓簱瀛�
         //鍏堟煡璇㈠簱瀛樿〃涓殑浜у搧鏄惁瀛樺湪锛屼笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
@@ -105,11 +136,57 @@
             newStockInventory.setBatchNo(stockInventoryDto.getBatchNo());
             newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
             newStockInventory.setWarnNum(stockInventoryDto.getWarnNum());
+            newStockInventory.setWarehouse(stockInventoryDto.getWarehouse());
             stockInventoryMapper.insert(newStockInventory);
         } else {
             stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
         }
         return true;
+    }
+
+    /**
+     * 鍒涘缓璐ㄦ鍗�
+     * 鏍规嵁 inspectType 鍐冲畾璐ㄦ绫诲瀷锛�
+     * - 0: 鍘熸潗鏂欐楠�
+     * - 1: 杩囩▼妫�楠�
+     * 濡傛灉鏈寚瀹� inspectType锛屽垯鏍规嵁浜у搧淇℃伅鑷姩鍒ゆ柇
+     */
+    private void createQualityInspect(StockInventoryDto stockInventoryDto) {
+        // 鏌ヨ浜у搧淇℃伅
+        ProductModel productModel = productModelMapper.selectById(stockInventoryDto.getProductModelId());
+        if (productModel == null) {
+            throw new ServiceException("浜у搧瑙勬牸涓嶅瓨鍦�");
+        }
+
+        // 纭畾 inspectType
+        Integer inspectType = stockInventoryDto.getInspectType();
+        if (inspectType == null) {
+            // 榛樿浣跨敤鍘熸潗鏂欐楠�
+            inspectType = 0;
+        }
+
+        // 鏋勫缓璐ㄦ鍗�
+        QualityInspectDto qualityInspectDto = new QualityInspectDto();
+        qualityInspectDto.setInspectType(inspectType);
+        qualityInspectDto.setProductModelId(stockInventoryDto.getProductModelId());
+        qualityInspectDto.setProductId(productModel.getProductId());
+        qualityInspectDto.setProductName(stockInventoryDto.getProductName());
+        qualityInspectDto.setQuantity(stockInventoryDto.getQualitity());
+        qualityInspectDto.setInspectState(0); // 鏈彁浜�
+//        qualityInspectDto.setRemark(stockInventoryDto.getRemark());
+
+        // 璁剧疆浜у搧淇℃伅
+        if (productModel.getProductName() != null) {
+            qualityInspectDto.setProductName(productModel.getProductName());
+        }
+        qualityInspectDto.setModel(productModel.getModel());
+        qualityInspectDto.setUnit(productModel.getUnit());
+
+        // 鍒濆鍖栫┖鐨勬楠屽弬鏁板垪琛�
+        qualityInspectDto.setQualityInspectParams(new ArrayList<>());
+
+        // 淇濆瓨璐ㄦ鍗�
+        qualityInspectService.add(qualityInspectDto);
     }
 
     //鍑哄簱璋冪敤
@@ -131,6 +208,7 @@
         stockOutRecordDto.setStockOutNum(stockInventoryDto.getQualitity());
         stockOutRecordDto.setBatchNo(stockInventoryDto.getBatchNo());
         stockOutRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
+        stockOutRecordDto.setOutboundBatches(stockInventoryDto.getOutboundBatches());
         stockOutRecordDto.setType("0");
         stockOutRecordService.add(stockOutRecordDto);
 
@@ -160,6 +238,14 @@
         }
         stockInventoryDto.setBatchNo(batchNo);
 
+        // 鍒ゆ柇鏄惁闇�瑕佽川妫�
+        if (Boolean.TRUE.equals(stockInventoryDto.getNeedInspect())) {
+            // 鍒涘缓璐ㄦ鍗�
+            createQualityInspect(stockInventoryDto);
+            return true;
+        }
+
+        // 涓嶉渶瑕佽川妫�锛岀洿鎺ュ垱寤哄叆搴撹褰�
         StockInRecordDto stockInRecordDto = new StockInRecordDto();
         stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
         stockInRecordDto.setRecordType(stockInventoryDto.getRecordType());
@@ -168,6 +254,9 @@
         stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
         stockInRecordDto.setType("0");
         stockInRecordDto.setRemark(stockInventoryDto.getRemark());
+        stockInRecordDto.setWarnNum(stockInventoryDto.getWarnNum());
+        stockInRecordDto.setCreateTime(stockInventoryDto.getCreateTime());
+        stockInRecordDto.setWarehouse(stockInventoryDto.getWarehouse());
         stockInRecordService.add(stockInRecordDto);
         return true;
     }
@@ -286,6 +375,7 @@
         stockOutRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
         stockOutRecordDto.setType("0");
         stockOutRecordDto.setRemark(stockInventoryDto.getRemark());
+        stockOutRecordDto.setOutboundBatches(stockInventoryDto.getOutboundBatches());
         stockOutRecordService.add(stockOutRecordDto);
         return true;
     }
@@ -312,6 +402,14 @@
             int successCount = 0;
 
             for (StockInventoryExportData dto : list) {
+                // 楠岃瘉浠撳簱鏄惁瀛樺湪浜庡瓧鍏镐腑
+                if (StringUtils.isNotEmpty(dto.getWarehouse())) {
+                    String warehouseLabel = sysDictDataService.selectDictLabel("warehouse", dto.getWarehouse());
+                    if (StringUtils.isEmpty(warehouseLabel)) {
+                        throw new RuntimeException("浠撳簱鍊� " + dto.getWarehouse() + " 涓嶅瓨鍦ㄤ簬瀛楀吀涓�");
+                    }
+                }
+
                 // 鏋勫缓鏌ユ壘閿�
                 String key = dto.getProductName() + "|" + dto.getModel();
                 SalesLedgerProduct matchedProduct = productMap.get(key);
@@ -325,6 +423,7 @@
                         stockInventoryDto.setQualitity(dto.getQualifiedQuantity());
                         stockInventoryDto.setRemark(dto.getRemark());
                         stockInventoryDto.setWarnNum(dto.getWarnNum());
+                        stockInventoryDto.setWarehouse(dto.getWarehouse());
 
                         // 楠岃瘉鍚堟牸鍐荤粨鏁伴噺
                         if (ObjectUtils.isNotEmpty(dto.getQualifiedLockedQuantity())) {
@@ -348,6 +447,7 @@
                         stockUninventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_IN.getCode());
                         stockUninventoryDto.setQualitity(dto.getUnQualifiedQuantity());
                         stockUninventoryDto.setRemark(dto.getRemark());
+                        stockUninventoryDto.setWarehouse(dto.getWarehouse());
 
                         // 楠岃瘉涓嶅悎鏍煎喕缁撴暟閲�
                         if (ObjectUtils.isNotEmpty(dto.getUnQualifiedLockedQuantity())) {

--
Gitblit v1.9.3