From c8ec928e26cdf8efc51a576547ebcfbe3cb71f6d Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 16 三月 2023 16:28:24 +0800
Subject: [PATCH] 新增核价管理-上传询价后可进行下载功能

---
 src/main/java/com/zy/crm/manager/controller/PriOnlineController.java |   68 ++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/crm/manager/controller/PriOnlineController.java b/src/main/java/com/zy/crm/manager/controller/PriOnlineController.java
index 87f68a8..8333bff 100644
--- a/src/main/java/com/zy/crm/manager/controller/PriOnlineController.java
+++ b/src/main/java/com/zy/crm/manager/controller/PriOnlineController.java
@@ -18,8 +18,13 @@
 import com.zy.crm.common.web.BaseController;
 import com.zy.crm.manager.service.PriService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.ClassUtils;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -181,16 +186,73 @@
 
     @RequestMapping(value = "/priOnline/uploadCheck/auth")
     @ManagerAuth
-    public R uploadCheck(@RequestBody Map<String,Object> map){
-        PriOnline priOnline = priOnlineService.selectById(Long.parseLong(map.get("id").toString()));
+    public R uploadCheck(@RequestParam("id") Integer id,
+                         @RequestParam("checkData") String checkData,
+                         @RequestParam("file") MultipartFile[] files){
+        PriOnline priOnline = priOnlineService.selectById(id);
         if (priOnline.getStatus() == 1) {
             return R.error("鏍镐环宸插畬鎴愶紝绂佹涓婁紶");
         }
-        priOnline.setCheckData(map.get("checkData").toString());
+        priOnline.setCheckData(checkData);
+
+
+        MultipartFile file = files[0];
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
+        String path =  ClassUtils.getDefaultClassLoader().getResource("excel/uploadCheckData").getPath();
+        //鏂囦欢鍚庣紑鍚�
+        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+        //涓婁紶鏂囦欢鍚�
+        String filename = format.format(new Date()) + suffix;
+        //鏈�缁堟枃浠惰矾寰�
+        String filepath = path + "/" + filename;
+
+
+        //鏈嶅姟鍣ㄧ淇濆瓨鐨勬枃浠跺璞�
+        File serverFile = new File(filepath);
+        if(!serverFile.exists()) {
+            try {
+                //鍒涘缓鏂囦欢
+                serverFile.createNewFile();
+                //灏嗕笂浼犵殑鏂囦欢鍐欏叆鍒版湇鍔″櫒绔枃浠跺唴
+                file.transferTo(serverFile);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        //淇濆瓨鏂囦欢鍚�
+        priOnline.setCheckDataFile(filename);
         priOnlineService.updateById(priOnline);
         return R.ok();
     }
 
+    @GetMapping("/priOnline/checkDataDownload/{filename}")
+    public void download(@PathVariable String filename, HttpServletResponse response) {
+        try {
+            ClassPathResource pathResource = new ClassPathResource("excel/uploadCheckData/" + filename);
+            File file = pathResource.getFile();
+            InputStream inputStream = pathResource.getInputStream();
+            //杈撳嚭鏂囦欢
+            InputStream fis = new BufferedInputStream(inputStream);
+            byte[] buffer = new byte[fis.available()];
+            fis.read(buffer);
+            fis.close();
+            response.reset();
+
+            //鑾峰彇鏂囦欢鐨勫悕瀛楀啀娴忚鍣ㄤ笅杞介〉闈�
+            String name = file.getName();
+            response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1"));
+            response.addHeader("Content-Length", "" + file.length());
+            OutputStream out = new BufferedOutputStream(response.getOutputStream());
+            response.setContentType("application/octet-stream");
+            out.write(buffer);
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     @RequestMapping(value = "/priOnline/delete/auth")
     @ManagerAuth
     public R delete(Long[] ids){

--
Gitblit v1.9.1