From 7706e5b97ebbdd767a237d5a79d18da6e1269a1d Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期五, 23 一月 2026 16:13:31 +0800
Subject: [PATCH] feat(stock): 添加库存出入库记录导出功能

---
 src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java |   50 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 34 insertions(+), 16 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 15bc09e..35e2f13 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -4,16 +4,16 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.basic.excel.SupplierManageExcelDto;
-import com.ruoyi.basic.pojo.SupplierManage;
-import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.account.pojo.BorrowInfo;
+import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.stock.dto.StockInRecordDto;
 import com.ruoyi.stock.dto.StockInventoryDto;
 import com.ruoyi.stock.dto.StockOutRecordDto;
 import com.ruoyi.stock.execl.StockInventoryExportData;
-import com.ruoyi.stock.pojo.StockInRecord;
 import com.ruoyi.stock.pojo.StockInventory;
 import com.ruoyi.stock.mapper.StockInventoryMapper;
 import com.ruoyi.stock.service.StockInRecordService;
@@ -21,14 +21,11 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.stock.service.StockOutRecordService;
 import lombok.AllArgsConstructor;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.time.LocalDate;
-import java.util.ArrayList;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -46,7 +43,7 @@
     private  StockInventoryMapper stockInventoryMapper;
     private StockInRecordService stockInRecordService;
     private StockOutRecordService stockOutRecordService;
-
+    private SalesLedgerProductMapper salesLedgerProductMapper;
     @Override
     public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
         return stockInventoryMapper.pagestockInventory(page, stockInventoryDto);
@@ -72,6 +69,7 @@
             newStockInventory.setProductModelId(stockInventoryDto.getProductModelId());
             newStockInventory.setQualitity(stockInventoryDto.getQualitity());
             newStockInventory.setVersion(1);
+            newStockInventory.setRemark(stockInventoryDto.getRemark());
             stockInventoryMapper.insert(newStockInventory);
         }else {
              stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
@@ -101,20 +99,40 @@
     }
 
     @Override
-    public Boolean importStockInventory(MultipartFile file) {
+    public R importStockInventory(MultipartFile file) {
         try {
+            final StringBuffer[] errorMsg = {new StringBuffer()};
+            //鏌ヨ鎵�鏈夌殑浜у搧
+            List<SalesLedgerProduct> salesLedgerProducts =salesLedgerProductMapper.selectProduct();
+
             ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class);
             List<StockInventoryExportData> list = util.importExcel(file.getInputStream());
-            ArrayList<StockInventory> stockInventories = new ArrayList<>();
             list.stream().forEach(dto -> {
-               // TODO: 2026/1/21 娣诲姞鍏ュ簱璁板綍
+                salesLedgerProducts.stream().forEach(item->{
+                    if (item.getProductCategory().equals(dto.getProductName())&&item.getSpecificationModel().equals(dto.getModel())) {
+                            //鏇存柊搴撳瓨
+                        StockInventoryDto stockInventoryDto = new StockInventoryDto();
+                        stockInventoryDto.setRecordId(0L);
+                        stockInventoryDto.setRecordType(StockQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
+                        stockInventoryDto.setQualitity(dto.getQualitity());
+                        stockInventoryDto.setProductModelId(item.getProductModelId());
+                        this.addstockInventory(stockInventoryDto);                    }else {
+                        errorMsg[0] = errorMsg[0].append("浜у搧鍚嶇О锛�"+dto.getProductName()+"瑙勬牸锛�"+dto.getModel()+"涓嶅瓨鍦�").append("\n");
+                    }
+                });
             });
-
-            this.saveOrUpdateBatch(stockInventories);
-            return true;
+            return R.ok(errorMsg[0]);
         }catch (Exception e){
             e.printStackTrace();
         }
-        return false;
+        return R.fail();
+    }
+
+    @Override
+    public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) {
+
+        List<StockInventoryExportData> list = stockInventoryMapper.listStockInventoryExportData(stockInventoryDto);
+        ExcelUtil<StockInventoryExportData> util = new ExcelUtil<>(StockInventoryExportData.class);
+        util.exportExcel(response,list, "搴撳瓨淇℃伅");
     }
 }

--
Gitblit v1.9.3