From a76e1d17d67641993dea6335cb8e1465a94df58d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 21 五月 2026 15:39:05 +0800
Subject: [PATCH] feat(stock): 优化库存管理和成品树结构功能 1- 为ApproveProcessMapper.xml和ProductBomMapper.xml添加排序功能 2- 在ProductionProductMainDto中新增bomInputQty字段用于产品结构投入数量 3- 修改ProductionProductMainServiceImpl中投入数量计算逻辑,使用前端传入的bomInputQty值 4- 在ProductWorkOrderDto中添加bomInputQty字段并在服务实现中计算标准投入数量 5- 更新SalesLedgerMapper.xml查询逻辑,从product_summary获取电压信息 6- 为SalesLedgerProduct添加stockId字段并修改库存扣减逻辑使用具体库存ID 7- 重构StockInventoryController中的成品库存树查询接口和导入导出功能 8- 新增成品和非成品库存导入导出的数据模型和Excel工具类 9- 优化StockInventoryServiceImpl中的库存扣减逻辑,支持按特定库存ID操作 10- 更新库存导入导出功能,区分成品和非成品类型并提供相应模板

---
 src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java b/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
index 4dc2f7a..2358caf 100644
--- a/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
+++ b/src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
@@ -22,12 +22,19 @@
 import com.ruoyi.sales.service.ISalesLedgerService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.math.BigDecimal;
+import java.net.URLEncoder;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -42,6 +49,7 @@
 @RequestMapping("/purchase/ledger")
 @AllArgsConstructor
 @Api(tags = "閲囪喘鍙拌处")
+@Slf4j
 public class PurchaseLedgerController extends BaseController {
     private IPurchaseLedgerService purchaseLedgerService;
 
@@ -51,6 +59,57 @@
     private PurchaseLedgerTemplateMapper purchaseLedgerTemplateMapper;
 
     private SalesLedgerProductTemplateMapper salesLedgerProductTemplateMapper;
+
+
+    /**
+     * 瀵煎叆閲囪喘鍙拌处
+     */
+    @Log(title = "瀵煎叆閲囪喘鍙拌处", businessType = BusinessType.INSERT)
+    @PostMapping("/import")
+    @ApiOperation("瀵煎叆閲囪喘鍙拌处")
+    public AjaxResult importData(@RequestParam("file")
+                                 @ApiParam(value = "Excel鏂囦欢", required = true)
+                                         MultipartFile file) {
+        return purchaseLedgerService.importData(file);
+    }
+
+    @ApiOperation("瀵煎嚭閲囪喘鍙拌处妯℃澘")
+    @PostMapping("/exportTemplate")
+    public void exportTemplate(HttpServletResponse response) {
+        // 1. 妯℃澘鏂囦欢鍦╮esources/static涓嬬殑璺緞
+        String templatePath = "static/閲囪喘鍙拌处瀵煎叆妯℃澘.xlsx";
+
+        // 2. 鑾峰彇妯℃澘鏂囦欢鐨勮緭鍏ユ祦
+        try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(templatePath)) {
+            if (inputStream == null) {
+                throw new FileNotFoundException("妯℃澘鏂囦欢涓嶅瓨鍦細" + templatePath);
+            }
+
+            // 3. 璁剧疆鍝嶅簲澶达紝瑙﹀彂娴忚鍣ㄤ笅杞�
+            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+            response.setCharacterEncoding("utf-8");
+            String fileName = URLEncoder.encode("閲囪喘鍙拌处瀵煎叆妯℃澘.xlsx", "utf-8").replaceAll("\\+", "%20");
+            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
+
+            // 4. 灏嗘ā鏉挎枃浠跺啓鍏ュ搷搴旇緭鍑烘祦
+            try (OutputStream outputStream = response.getOutputStream()) {
+                byte[] buffer = new byte[1024];
+                int len;
+                while ((len = inputStream.read(buffer)) > 0) {
+                    outputStream.write(buffer, 0, len);
+                }
+                outputStream.flush();
+            }
+        } catch (IOException e) {
+            log.error("瀵煎嚭閿�鍞彴璐︽ā鏉垮け璐�", e);
+            // 鑻ユā鏉挎枃浠惰鍙栧け璐ワ紝杩斿洖閿欒鎻愮ず
+            try {
+                response.getWriter().write("妯℃澘瀵煎嚭澶辫触锛�" + e.getMessage());
+            } catch (IOException ex) {
+                log.error("鍝嶅簲杈撳嚭閿欒", ex);
+            }
+        }
+    }
 
     /**
      * 鏌ヨ閲囪喘鍙拌处鍒楄〃
@@ -130,6 +189,14 @@
     }
 
     /**
+     * 鏌ヨ閲囪喘鍙拌处鍜屼骇鍝佺埗瀛愬垪琛�
+     */
+    @GetMapping("/getPurchaseByCode")
+    public PurchaseLedgerDto getPurchaseByCode(PurchaseLedgerDto purchaseLedgerDto) {
+        return purchaseLedgerService.getPurchaseByCode(purchaseLedgerDto);
+    }
+
+    /**
      * 鍒犻櫎閲囪喘鍙拌处
      */
     @Log(title = "閲囪喘鍙拌处", businessType = BusinessType.DELETE)

--
Gitblit v1.9.3