瀏覽代碼

文件下载 附件下载

hxf 2 年之前
父節點
當前提交
5cdead7d26

+ 13 - 5
neim-biz/src/main/java/com/jiayue/biz/controller/ManualEntryController.java

@@ -12,6 +12,7 @@ import org.springframework.security.core.parameters.P;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -130,7 +131,7 @@ public class ManualEntryController extends BaseController {
     @PostMapping("/projectProgressParse")
     public AjaxResult projectProgressParse(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") String eqId, @RequestParam("name") String name) {
 
-        projectProgressService.projectProgressParse(multipartFile, eqId, name);
+        projectProgressService.projectProgressParse(multipartFile, eqId);
         return AjaxResult.success("200");
 
     }
@@ -139,13 +140,20 @@ public class ManualEntryController extends BaseController {
      * 保存附件
      *
      * @param multipartFile 文件
-     * @param name          文件夹名
+     * @param id            文件夹名
      */
-    @PostMapping("/saveAttachment")
-    public void saveAttachment(@RequestParam("file") MultipartFile multipartFile, @RequestParam("name") String name) {
+    @PostMapping("/uploadProjectAnnex")
+    public AjaxResult saveAttachment(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") String id) {
 
-        projectProgressService.saveAttachment(multipartFile, name);
+        projectProgressService.saveAttachment(multipartFile, id);
+        return AjaxResult.success("200");
+    }
 
+    //下载文件
+    @GetMapping("/exportProjectEvolve")
+    public void downloadFile(HttpServletResponse response, String equipmentId) {
+        projectProgressService.downloadProjectProgress(response, equipmentId);
     }
 
+
 }

+ 7 - 3
neim-biz/src/main/java/com/jiayue/biz/service/ProjectProgressService.java

@@ -5,6 +5,7 @@ package com.jiayue.biz.service;
 import com.jiayue.biz.domain.ProjectProgress;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 public interface ProjectProgressService {
@@ -15,10 +16,13 @@ public interface ProjectProgressService {
     /**
      * 保存附件
      * @param multipartFile 文件
-     * @param name 文件夹名
+     * @param id 文件夹名
      */
-    void saveAttachment(MultipartFile multipartFile, String name);
+    void saveAttachment(MultipartFile multipartFile, String id);
 
     //项目进展解析
-    void projectProgressParse(MultipartFile multipartFile, String eqId,String name);
+    void projectProgressParse(MultipartFile multipartFile, String eqId);
+
+    //下载模板
+    void downloadProjectProgress(HttpServletResponse response, String id);
 }

+ 26 - 9
neim-biz/src/main/java/com/jiayue/biz/service/impl/ProjectProgressServiceImpl.java

@@ -2,6 +2,7 @@ package com.jiayue.biz.service.impl;
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.db.handler.StringHandler;
+import cn.hutool.http.HttpResponse;
 import cn.hutool.poi.excel.ExcelReader;
 import cn.hutool.poi.excel.ExcelUtil;
 import com.jiayue.biz.domain.ProjectMenusOne;
@@ -19,7 +20,11 @@ import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
 import java.io.*;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -44,14 +49,28 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
         return mongoTemplate.find(new Query(), ProjectProgress.class, "project_progress");
     }
 
+
+    //下载模板
+    public void downloadProjectProgress(HttpServletResponse response, String id) {
+        File projectProgressDirFileNew = new File(projectProgressDir + id + File.separator + projectProgressBackNew);
+        File[] files = projectProgressDirFileNew.listFiles();
+        if (files.length > 0) {
+            com.jiayue.biz.util.FileUtil.downloadFile(files[0], response);
+        }
+
+
+    }
+
+
     /**
      * 保存附件
+     *
      * @param multipartFile 文件
-     * @param name 文件夹名
+     * @param id          文件夹名
      */
     @SneakyThrows
-    public void saveAttachment(MultipartFile multipartFile, String name){
-        File projectProgressDirFileNew = new File(projectProgressDir + name + File.separator + projectProgressAttachment);
+    public void saveAttachment(MultipartFile multipartFile, String id) {
+        File projectProgressDirFileNew = new File(projectProgressDir + id + File.separator + projectProgressAttachment);
         if (!projectProgressDirFileNew.exists()) {
             projectProgressDirFileNew.mkdirs();
         }
@@ -61,16 +80,16 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
 
 
     //项目进展解析
-    public void projectProgressParse(MultipartFile multipartFile, String id, String name) {
+    public void projectProgressParse(MultipartFile multipartFile, String id) {
         String fileName = multipartFile.getOriginalFilename();
         File filed = new File(fileName);
         try {
             ExcelReader reader = ExcelUtil.getReader(filed);
             List<List<Object>> read = reader.read();
             //解析文件入库
-            saveProjectProgress(read,id);
+            saveProjectProgress(read, id);
 
-            File projectProgressDirFileNew = new File(projectProgressDir + name + File.separator + projectProgressBackNew);
+            File projectProgressDirFileNew = new File(projectProgressDir + id + File.separator + projectProgressBackNew);
             if (!projectProgressDirFileNew.exists()) {
                 projectProgressDirFileNew.mkdirs();
             }
@@ -93,9 +112,8 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
     }
 
 
-
     //项目进展解析文件入库
-    public void saveProjectProgress(List<List<Object>> read,String id){
+    public void saveProjectProgress(List<List<Object>> read, String id) {
         ArrayList<ProjectMenusOne> projectMenusOneList = new ArrayList<>();
 
         String s1 = "";
@@ -155,7 +173,6 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
     }
 
 
-
     //设置二级
     public ProjectMenusTow hTow(List<Object> objects) {
         ProjectMenusTow projectMenusTow = new ProjectMenusTow();

+ 32 - 4
neim-biz/src/main/java/com/jiayue/biz/util/FileUtil.java

@@ -4,11 +4,12 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.springframework.util.ResourceUtils;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
@@ -131,6 +132,33 @@ public class FileUtil {
         return pathStr;
     }
 
+    //下载文件
+    public static void downloadFile(File file, HttpServletResponse response) {
+        String name = file.getName();
+        FileInputStream fileInputStream = null;
+        ServletOutputStream outputStream = null;
+        try {
+            fileInputStream = new FileInputStream(file);
+            String encode = URLEncoder.encode(name, StandardCharsets.UTF_8.toString());
+            response.setContentType("application/octet-stream");
+            String percentEncodedFileName = encode.replaceAll("\\+", "%20");
+            String contentDispositionValue =
+                    "attachment; filename=" + percentEncodedFileName;
+            response.setHeader("Content-disposition", contentDispositionValue);
+            int len = 0;
+            byte[] buffer = new byte[1024];
+            outputStream = response.getOutputStream();
+            while ((len = fileInputStream.read(buffer)) > 0) {
+                outputStream.write(buffer, 0, len);
+            }
+            fileInputStream.close();
+            outputStream.flush();
+            outputStream.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     /**
      * 获取上报文件目录相对路径
      *

+ 3 - 2
neim-ui/src/views/manualEntry/projectEvolveEntry/index.vue

@@ -86,7 +86,7 @@
 
 <script>
 import {getProjectInfo,projectProgressParse,uploadProjectAnnex} from "@/api/biz/manualEntry/projectEvolveEntry";
-
+import download from '@/plugins/download'
 export default {
   // 项目进展录入
   name: "index",
@@ -149,6 +149,7 @@ export default {
     fjDataUpload(item) {
       this.fullscreenLoading = true
       const formData = new FormData()
+      formData.append("file", item.file)
       formData.append("id", this.row.id)
       uploadProjectAnnex(formData).then((response) => {
         this.$refs.upload.clearFiles()
@@ -167,7 +168,7 @@ export default {
     },
     handleClick(row) {
       this.row = row
-      this.dialogVisible = true
+      this.fjDialogVisible = true
     },
     /*下载最新项目进展*/
     handleAllExport(row) {