浏览代码

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 年之前
父节点
当前提交
fccf728697

+ 0 - 2
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldFileController.java

@@ -227,7 +227,5 @@ public class MouldFileController {
         }
         return msg;
     }
-
-
 }
 

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

@@ -17,8 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
 import java.util.UUID;
 
 /**
@@ -35,6 +34,8 @@ public class ProjectFileController {
 
     @Value("${upload.path}")
     private String path;
+    @Value("${download.path}")
+    private String downLoadpath;
     @Autowired
     private ProjectFileService projectFileService;
 
@@ -63,11 +64,12 @@ public class ProjectFileController {
     @ApiOperation("项目文档的下载")
     @RequestMapping("/dowloadFile")
     @ResponseBody
-    public HttpRespMsg dowloadFile(ProjectFile projectFile,String token){
-        HttpRespMsg msg = projectFileService.dowloadFile(projectFile,token);
+    public HttpRespMsg dowloadFile(ProjectFile projectFile,String token,HttpServletResponse response){
+        HttpRespMsg msg = projectFileService.dowloadFile(projectFile,token,downLoadpath,response);
         return msg;
     }
 
+
     /**
      * 项目文档的列表
      * 参数: token 用户身份凭证,projectId 项目id

+ 3 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/service/ProjectFileService.java

@@ -6,6 +6,8 @@ import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * <p>
  *  服务类
@@ -18,7 +20,7 @@ public interface ProjectFileService extends IService<ProjectFile> {
 
     HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path);
 
-    HttpRespMsg dowloadFile(ProjectFile projectFile, String token);
+    HttpRespMsg dowloadFile(ProjectFile projectFile, String token,String path,HttpServletResponse response);
 
     HttpRespMsg getFileList(UserVO userVO);
 

+ 29 - 3
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/ProjectFileServiceImpl.java

@@ -18,8 +18,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.util.List;
 import java.util.UUID;
 
@@ -99,7 +99,7 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
     }
 
     @Override
-    public HttpRespMsg dowloadFile(ProjectFile projectFile, String token) {
+    public HttpRespMsg dowloadFile(ProjectFile projectFile, String token,String downLoadpath,HttpServletResponse response) {
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
         //添加上传记录
@@ -113,6 +113,32 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
         projectOperationDynamicsMapper.insert(dynamics);
         return msg;
     }
+    public void downloadLocal(HttpServletResponse response, String downLoadpath,ProjectFile file) throws FileNotFoundException {
+        // 下载本地文件
+        String fileName = file.getFileName().toString(); // 文件的默认保存名
+        // 读到流中
+        File dir = null;
+        dir = new File(downLoadpath);
+        // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+        InputStream inStream = new FileInputStream(downLoadpath);// 文件的存放路径
+        // 设置输出的格式
+        response.reset();
+        response.setContentType("bin");
+        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
+        // 循环取出流中的数据
+        byte[] b = new byte[100];
+        int len;
+        try {
+            while ((len = inStream.read(b)) > 0)
+                response.getOutputStream().write(b, 0, len);
+            inStream.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 
     @Override
     public HttpRespMsg getFileList(UserVO userVO) {

+ 1 - 1
cloud-model/src/main/resources/application.properties

@@ -37,7 +37,7 @@ spring.thymeleaf.prefix=classpath:/static/
 # 文件上传路径
 upload.path=D:/mould/upload/
 ######################################################################################################
-# 文件上传路径
+# 文件下载路径
 download.path=D:/mould/download/
 # 邀请人员链接前缀
 invitation.url.prefix=https://localhost:8090/#/invite/