From c2ad2126d6f8423e0a5e6e20bbb91ef6bb1cffc0 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期一, 25 五月 2026 13:26:27 +0800
Subject: [PATCH] fix(approve): 修复审批流程为空时的异常处理

---
 src/main/java/com/ruoyi/sales/controller/SalesQuotationController.java |   64 ++++++++++++++++++++++++++-----
 1 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/controller/SalesQuotationController.java b/src/main/java/com/ruoyi/sales/controller/SalesQuotationController.java
index f9ea1df..c7a5ec0 100644
--- a/src/main/java/com/ruoyi/sales/controller/SalesQuotationController.java
+++ b/src/main/java/com/ruoyi/sales/controller/SalesQuotationController.java
@@ -1,29 +1,28 @@
 package com.ruoyi.sales.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.ruoyi.aftersalesservice.dto.AfterSalesServiceDto;
-import com.ruoyi.aftersalesservice.pojo.AfterSalesService;
-import com.ruoyi.common.utils.StringUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.sales.dto.SalesQuotationDto;
-import com.ruoyi.sales.pojo.SalesQuotation;
 import com.ruoyi.sales.service.SalesQuotationService;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.BeanUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
 
 @RestController
 @RequestMapping("/sales/quotation")
+@Slf4j
 public class SalesQuotationController {
     @Autowired
     private SalesQuotationService salesQuotationService;
@@ -39,7 +38,7 @@
         SalesQuotationDto afterSalesService = new SalesQuotationDto();
         IPage<SalesQuotationDto> listPage = salesQuotationService.listPage(page, afterSalesService);
         ExcelUtil<SalesQuotationDto> util = new ExcelUtil<SalesQuotationDto>(SalesQuotationDto.class);
-        util.exportExcel(response, listPage.getRecords() , "鍙嶉鐧昏");
+        util.exportExcel(response, listPage.getRecords() , "閿�鍞姤浠�");
     }
 
 
@@ -48,6 +47,7 @@
         return AjaxResult.success(salesQuotationService.add(salesQuotationDto));
     }
     @PostMapping("/update")
+    @Log(title = "鎶ヤ环鏇存柊", businessType = BusinessType.UPDATE)
     public AjaxResult update(@RequestBody SalesQuotationDto salesQuotationDto) {
         return AjaxResult.success(salesQuotationService.edit(salesQuotationDto));
     }
@@ -55,4 +55,46 @@
     public AjaxResult delete(@RequestBody Long id) {
         return AjaxResult.success(salesQuotationService.delete(id));
     }
+
+    @PostMapping("/downloadTemplate")
+    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);
+            }
+        }
+    }
+
+    @PostMapping("/import")
+    public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("approveUserIdsJson") String approveUserIdsJson) {
+        return AjaxResult.success(salesQuotationService.importData(file, approveUserIdsJson));
+    }
 }

--
Gitblit v1.9.3