Ver código fonte

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java
5 anos atrás
pai
commit
8ca50d5b2c

+ 38 - 4
cloud-model/src/main/java/com/hssx/cloudmodel/controller/ProjectFileController.java

@@ -1,6 +1,7 @@
 package com.hssx.cloudmodel.controller;
 
 
+import com.hssx.cloudmodel.entity.MouldFile;
 import com.hssx.cloudmodel.entity.ProjectFile;
 import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.service.ProjectFileService;
@@ -8,11 +9,8 @@ import com.hssx.cloudmodel.util.HttpRespMsg;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.*;
 
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
@@ -69,6 +67,42 @@ public class ProjectFileController {
         return msg;
     }
 
+    /**
+     * 项目文档的下载
+     * id 所要下载的文件id ,
+     * @return
+     */
+    @GetMapping("/download/{id}")
+    public HttpRespMsg download(@PathVariable("id") Integer id,
+                                HttpServletRequest request,HttpServletResponse resp) throws IOException {
+        HttpRespMsg msg = new HttpRespMsg();
+        ProjectFile model = projectFileService.getById(id);// 文件实体
+        msg.data = model;
+        FileInputStream fis = null;
+        try {
+            String fileName = model.getFileName();
+            String filePath = path+model.getUrl().substring("/upload/".length());
+            fis = new FileInputStream(filePath);
+            resp.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            resp.setCharacterEncoding("UTF-8");
+            resp.setHeader("Content-Disposition",
+                    "attachment;filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
+            byte[] b = new byte[1024];
+            int len;
+            while ((len = fis.read(b)) > 0) {
+                resp.getOutputStream().write(b, 0, len);
+            }
+        } catch (Exception e) {
+
+            msg.setError("文件[ {} ]下载错误");
+        } finally {
+            resp.getOutputStream().flush();
+            resp.getOutputStream().close();
+            fis.close();
+        }
+        return msg;
+    }
+
 
     /**
      * 项目文档的列表