Explorar o código

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
%!s(int64=5) %!d(string=hai) anos
pai
achega
255012c146

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

@@ -64,7 +64,7 @@ public class ProjectFileController {
     @ApiOperation("项目文档的下载")
     @ApiOperation("项目文档的下载")
     @RequestMapping("/dowloadFile")
     @RequestMapping("/dowloadFile")
     @ResponseBody
     @ResponseBody
-    public HttpRespMsg dowloadFile(ProjectFile projectFile,String token,HttpServletResponse response) throws FileNotFoundException {
+    public HttpRespMsg dowloadFile(ProjectFile projectFile,String token,HttpServletResponse response) throws FileNotFoundException, UnsupportedEncodingException {
         HttpRespMsg msg = projectFileService.dowloadFile(projectFile,token,downLoadpath,response,path);
         HttpRespMsg msg = projectFileService.dowloadFile(projectFile,token,downLoadpath,response,path);
         return msg;
         return msg;
     }
     }

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

@@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.FileNotFoundException;
 import java.io.FileNotFoundException;
+import java.io.UnsupportedEncodingException;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -21,7 +22,7 @@ public interface ProjectFileService extends IService<ProjectFile> {
 
 
     HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path);
     HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path);
 
 
-    HttpRespMsg dowloadFile(ProjectFile projectFile, String token,String downLoadpath,HttpServletResponse response,String path) throws FileNotFoundException;
+    HttpRespMsg dowloadFile(ProjectFile projectFile, String token,String downLoadpath,HttpServletResponse response,String path) throws FileNotFoundException, UnsupportedEncodingException;
 
 
     HttpRespMsg getFileList(UserVO userVO);
     HttpRespMsg getFileList(UserVO userVO);
 
 

+ 90 - 31
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/ProjectFileServiceImpl.java

@@ -15,17 +15,19 @@ import com.hssx.cloudmodel.service.ProjectOperationDynamicsService;
 import com.hssx.cloudmodel.util.FileUtil;
 import com.hssx.cloudmodel.util.FileUtil;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Base64Utils;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.io.*;
+import java.net.URLEncoder;
 import java.util.List;
 import java.util.List;
 import java.util.UUID;
 import java.util.UUID;
 
 
 /**
 /**
  * <p>
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  * </p>
  *
  *
  * @author 吴涛涛
  * @author 吴涛涛
@@ -45,7 +47,7 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
     public HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path) {
     public HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path) {
         HttpRespMsg msg = new HttpRespMsg();
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
-        if(user != null){
+        if (user != null) {
             if (file != null) {
             if (file != null) {
                 ProjectFile projectFile = new ProjectFile();
                 ProjectFile projectFile = new ProjectFile();
                 projectFile.setUploaderId(user.getId());
                 projectFile.setUploaderId(user.getId());
@@ -68,7 +70,7 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
                     String sufix = fileName.substring(pos);
                     String sufix = fileName.substring(pos);
                     fileName = rand + sufix;
                     fileName = rand + sufix;
                     projectFile.setFileType(sufix);//文件后缀
                     projectFile.setFileType(sufix);//文件后缀
-                    projectFile.setUrl("/upload/"+fileName);
+                    projectFile.setUrl("/upload/" + fileName);
                     File saveFile = new File(dir, fileName);
                     File saveFile = new File(dir, fileName);
                     projectFileMapper.insert(projectFile);
                     projectFileMapper.insert(projectFile);
                     try {
                     try {
@@ -92,14 +94,14 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
                 }
                 }
                 msg.data = projectFile;
                 msg.data = projectFile;
             }
             }
-        }else{
+        } else {
             msg.setError("当前用户不存在或者未登录");
             msg.setError("当前用户不存在或者未登录");
         }
         }
         return msg;
         return msg;
     }
     }
 
 
     @Override
     @Override
-    public HttpRespMsg dowloadFile(ProjectFile projectFile, String token,String downLoadpath,HttpServletResponse response,String path) throws FileNotFoundException {
+    public HttpRespMsg dowloadFile(ProjectFile projectFile, String token, String downLoadpath, HttpServletResponse response, String path) throws FileNotFoundException, UnsupportedEncodingException {
         HttpRespMsg msg = new HttpRespMsg();
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
         //添加上传记录
         //添加上传记录
@@ -111,35 +113,92 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
         dynamics.setOperator(user.getUsername());
         dynamics.setOperator(user.getUsername());
         dynamics.setProjectId(file.getProjectId());
         dynamics.setProjectId(file.getProjectId());
         projectOperationDynamicsMapper.insert(dynamics);
         projectOperationDynamicsMapper.insert(dynamics);
-        downloadLocal(response,downLoadpath,file,path);
+        downloadLocal(response, downLoadpath, file, path);
         return msg;
         return msg;
     }
     }
-    public void downloadLocal(HttpServletResponse response, String downLoadpath,ProjectFile file,String path) 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(path.substring(0, path.length() - "/upload/".length())+file.getUrl());// 文件的存放路径
-        // 设置输出的格式
-        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();
+
+    public void downloadLocal(HttpServletResponse response, String downLoadpath, ProjectFile file, String path) throws FileNotFoundException, UnsupportedEncodingException {
+//        // 下载本地文件
+//        String fileName = file.getFileName().toString(); // 文件的默认保存名
+//        // 读到流中
+//        File dir = null;
+//        dir = new File(downLoadpath);
+//        // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
+//        if (!dir.exists()) {
+//            dir.mkdirs();
+//        }
+//        InputStream inStream = new FileInputStream(path.substring(0, path.length() - "/upload/".length())+file.getUrl());// 文件的存放路径
+//        // 设置输出的格式
+//        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();
+//        }
+        /*文件下载*/
+
+
+//        public static void downloadFile (HttpServletResponse response, String fileName, String path){
+            //下载本地文件
+            String fileName = file.getFileName().toString(); // 文件的默认保存名
+            // 读到流中
+            File dir = null;
+            dir = new File(downLoadpath);
+            // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+            if (fileName != null) {
+                //设置文件路径
+                File file1 = new File(path.substring(0, path.length() - "/upload/".length()) + file.getUrl());
+                if (file1.exists()) {
+                    response.setHeader("content-type", "application/octet-stream");
+                    response.setContentType("application/octet-stream");
+                    try {
+                        response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1"));
+                    } catch (UnsupportedEncodingException e) {
+                        e.printStackTrace();
+                    }
+                    byte[] buffer = new byte[1024];
+                    FileInputStream fis = null;
+                    BufferedInputStream bis = null;
+                    try {
+                        fis = new FileInputStream(file1);
+                        bis = new BufferedInputStream(fis);
+                        OutputStream os = response.getOutputStream();
+                        int i = bis.read(buffer);
+                        while (i != -1) {
+                            os.write(buffer, 0, i);
+                            i = bis.read(buffer);
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                        if (bis != null) {
+                            try {
+                                bis.close();
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                            }
+                        }
+                        if (fis != null) {
+                            try {
+                                fis.close();
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    }
+                }
+            }
         }
         }
-    }
 
 
     @Override
     @Override
     public HttpRespMsg getFileList(UserVO userVO) {
     public HttpRespMsg getFileList(UserVO userVO) {

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

@@ -40,7 +40,7 @@ upload.path=E:/staticproject/cloudmodel
 # 文件下载路径
 # 文件下载路径
 download.path=E:/mould/download/
 download.path=E:/mould/download/
 # 邀请人员链接前缀
 # 邀请人员链接前缀
-invitation.url.prefix=https://118.190.47.230:9098/#/invite/
+invitation.url.prefix=http://118.190.47.230:9098/#/invite/
 #######################################################################################################
 #######################################################################################################
 # 配置上传文件的大小设置
 # 配置上传文件的大小设置
 # Single file max size  即单个文件大小
 # Single file max size  即单个文件大小