From 0891b6708cc09c2672a19661a8555aae0e742df1 Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期四, 24 九月 2026 16:54:27 +0800
Subject: [PATCH] feat: 新增多模块导入导出功能

---
 src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java |   77 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
index b73f8b2..4369d88 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
@@ -17,6 +17,10 @@
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.stock.dto.StockInventoryDto;
 import com.ruoyi.stock.dto.StockOutRecordDto;
+import com.ruoyi.stock.dto.StockOutRecordImportDto;
+import com.ruoyi.basic.mapper.ProductModelMapper;
+import com.ruoyi.basic.pojo.ProductModel;
+import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.stock.dto.StockUninventoryDto;
 import com.ruoyi.stock.execl.StockOutRecordExportData;
 import com.ruoyi.stock.mapper.StockInventoryMapper;
@@ -31,7 +35,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -50,6 +56,7 @@
     private final StockUninventoryMapper stockUninventoryMapper;
     private final AccountSalesCollectionMapper accountSalesCollectionMapper;
     private final AccountInvoiceApplicationMapper accountInvoiceApplicationMapper;
+    private final ProductModelMapper productModelMapper;
 
     @Override
     public IPage<StockOutRecordDto> listPage(Page page, StockOutRecordDto stockOutRecordDto) {
@@ -230,4 +237,74 @@
         }
         return stockUninventoryMapper.selectOne(eq);
     }
+
+    @Override
+    public AjaxResult importData(MultipartFile file, String type) {
+        List<StockOutRecordImportDto> rows;
+        try {
+            ExcelUtil<StockOutRecordImportDto> util = new ExcelUtil<>(StockOutRecordImportDto.class);
+            rows = util.importExcel(file.getInputStream());
+        } catch (Exception e) {
+            return AjaxResult.error("瑙f瀽Excel澶辫触锛�" + e.getMessage());
+        }
+        if (CollectionUtils.isEmpty(rows)) {
+            return AjaxResult.error("瀵煎叆鏂囦欢鏃犳暟鎹�");
+        }
+        String stockType = StringUtils.isEmpty(type) ? "0" : type.trim();
+        String recordType = "1".equals(stockType)
+                ? StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode()
+                : StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_OUT.getCode();
+
+        int success = 0;
+        List<String> errors = new ArrayList<>();
+        for (int i = 0; i < rows.size(); i++) {
+            StockOutRecordImportDto row = rows.get(i);
+            int rowNo = i + 2; // 棣栬涓鸿〃澶�
+            try {
+                String productName = trim(row.getProductName());
+                String model = trim(row.getModel());
+                if (StringUtils.isEmpty(productName)) {
+                    errors.add("绗�" + rowNo + "琛岋細浜у搧澶х被涓虹┖");
+                    continue;
+                }
+                if (StringUtils.isEmpty(model)) {
+                    errors.add("绗�" + rowNo + "琛岋細瑙勬牸鍨嬪彿涓虹┖");
+                    continue;
+                }
+                if (row.getStockOutNum() == null) {
+                    errors.add("绗�" + rowNo + "琛岋細鍑哄簱鏁伴噺涓虹┖");
+                    continue;
+                }
+                ProductModel productModel = productModelMapper.selectByProductNameAndModel(productName, model);
+                if (productModel == null) {
+                    errors.add("绗�" + rowNo + "琛岋細鏈壘鍒颁骇鍝乕" + productName + " / " + model + "]");
+                    continue;
+                }
+                StockOutRecordDto dto = new StockOutRecordDto();
+                dto.setProductModelId(productModel.getId());
+                dto.setBatchNo(trim(row.getBatchNo()));
+                dto.setStockOutNum(row.getStockOutNum());
+                dto.setRemark(row.getRemark());
+                dto.setType(stockType);
+                dto.setRecordType(recordType);
+                dto.setApprovalStatus(ReviewStatusEnum.PENDING_REVIEW.getCode());
+                add(dto);
+                success++;
+            } catch (Exception e) {
+                errors.add("绗�" + rowNo + "琛岋細" + e.getMessage());
+            }
+        }
+
+        AjaxResult result = AjaxResult.success();
+        result.put("totalCount", rows.size());
+        result.put("successCount", success);
+        result.put("failCount", rows.size() - success);
+        result.put("errors", errors);
+        result.put("msg", "瀵煎叆瀹屾垚锛氭垚鍔� " + success + " 鏉★紝澶辫触 " + (rows.size() - success) + " 鏉�");
+        return result;
+    }
+
+    private String trim(String value) {
+        return value == null ? null : value.trim();
+    }
 }

--
Gitblit v1.9.3