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 ++++++++++++++++++++++++++++++++-
 src/main/java/com/zy/crm/manager/entity/PriOnline.java               |    4 ++
 src/main/resources/excel/uploadCheckData/lock                        |    0 
 src/main/webapp/static/js/priOnline/priOnline.js                     |   19 ++++++---
 src/main/webapp/views/priOnline/priOnline_check.html                 |    8 ++++
 src/main/webapp/views/priOnline/priOnline.html                       |    6 ++
 6 files changed, 95 insertions(+), 10 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){
diff --git a/src/main/java/com/zy/crm/manager/entity/PriOnline.java b/src/main/java/com/zy/crm/manager/entity/PriOnline.java
index bc08c1c..dab502d 100644
--- a/src/main/java/com/zy/crm/manager/entity/PriOnline.java
+++ b/src/main/java/com/zy/crm/manager/entity/PriOnline.java
@@ -91,6 +91,10 @@
     @TableField("member_id")
     private Long memberId;
 
+    @ApiModelProperty(value= "涓婁紶鎶ヤ环excel鏁版嵁鐨勫師濮嬫枃浠跺湴鍧�")
+    @TableField("check_data_file")
+    private String checkDataFile;
+
     public PriOnline() {}
 
     public PriOnline(String title,String sheetData,Date createTime,String filepath) {
diff --git a/src/main/resources/excel/uploadCheckData/lock b/src/main/resources/excel/uploadCheckData/lock
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/main/resources/excel/uploadCheckData/lock
diff --git a/src/main/webapp/static/js/priOnline/priOnline.js b/src/main/webapp/static/js/priOnline/priOnline.js
index abc3432..8a2c1cc 100644
--- a/src/main/webapp/static/js/priOnline/priOnline.js
+++ b/src/main/webapp/static/js/priOnline/priOnline.js
@@ -248,16 +248,23 @@
                             return;
                         }
 
+                        let formData = new FormData($("#uploadFile")[0]);
+                        formData.append("id", data.id);
+                        formData.append("checkData", zip(exportJson.sheets));
                         $.ajax({
                             url: baseUrl+"/priOnline/uploadCheck/auth",
                             headers: {'token': localStorage.getItem('token')},
-                            data: JSON.stringify({
-                                id: data.id,
-                                checkData: zip(exportJson.sheets)
-                            }),
+                            data: formData,
+                            // data: JSON.stringify({
+                            //     id: data.id,
+                            //     checkData: zip(exportJson.sheets)
+                            // }),
+                            // dataType: "json",
                             method: 'POST',
-                            dataType: "json",
-                            contentType:'application/json;charset=UTF-8',
+                            cache: false,
+                            processData: false,
+                            contentType: false,
+                            // contentType:'application/json;charset=UTF-8',
                             success: function (res) {
                                 if (res.code == 200) {
                                     layer.msg('涓婁紶鎴愬姛',{time:1000},() => {
diff --git a/src/main/webapp/views/priOnline/priOnline.html b/src/main/webapp/views/priOnline/priOnline.html
index 5f765dc..00a4175 100644
--- a/src/main/webapp/views/priOnline/priOnline.html
+++ b/src/main/webapp/views/priOnline/priOnline.html
@@ -41,7 +41,11 @@
   </div>
 </script>
 
-<input type="file" style="display: none;" id="uploadQuote">
+<form id="uploadFile" enctype="multipart/form-data" style="display: none;" >
+  <input type="file" name="file" id="uploadQuote">
+  <input type="button" onclick="upload()" value="涓婁紶"/>
+</form>
+
 
 <script type="text/html" id="operate">
   <a class="layui-btn layui-btn-xs btn-edit" lay-event="check">鏍镐环</a>
diff --git a/src/main/webapp/views/priOnline/priOnline_check.html b/src/main/webapp/views/priOnline/priOnline_check.html
index 6b15b5a..69c7596 100644
--- a/src/main/webapp/views/priOnline/priOnline_check.html
+++ b/src/main/webapp/views/priOnline/priOnline_check.html
@@ -26,6 +26,7 @@
 <!--  <div><button type="button" id="otherSave">鍙︿繚瀛樺埌鏈嶅姟鍣�</button></div>-->
   <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="allprint">鍏ㄩ儴鎵撳嵃</button></div>
   <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="print">閫夊尯鎵撳嵃</button></div>
+  <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="download">涓嬭浇</button></div>
 </div>
 <div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height: 100vh;left: 0px;top: 0px;"></div>
 <script>
@@ -43,6 +44,8 @@
       myFolderUrl: '' //宸︿笂瑙�<杩斿洖鎸夐挳鐨勯摼鎺�
     }
 
+    let checkDataFile = "";
+
     if(getUrlParams('id') == false || getUrlParams('id') == undefined){
       //鏂板
       luckysheet.create(options)
@@ -58,6 +61,7 @@
         headers: {'token': localStorage.getItem('token')},
         success:function(res) {
           if (res.code == 200) {
+            checkDataFile = res.data.checkDataFile
             options.data = unzip(res.data.checkData)
             luckysheet.create(options)
             $("#luckysheet_info_detail_update").hide()
@@ -130,6 +134,10 @@
       }
     })
 
+    $("#download").on("click",() => {
+      window.open(baseUrl + "/priOnline/checkDataDownload/" +checkDataFile)
+    })
+
   })
 
   $("#allprint").on("click",() => {

--
Gitblit v1.9.1