Jelajahi Sumber

1.7.5认证通版本功能优化

JiangChongBo 2 tahun lalu
induk
melakukan
e15aa6e177

+ 65 - 0
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -1523,6 +1523,71 @@ public class AuthServiceImpl implements AuthService {
                     ServletOutputStream outputStream = response.getOutputStream();
                     // 设置下载文件的mineType,告诉浏览器下载文件类型
 //                                int i = fileName.lastIndexOf(".");
+//                                String substring = fileName.substring(i + 1, filePath.length());
+                    response.setContentType("application/zip");
+                    // 设置一个响应头,无论是否被浏览器解析,都下载
+                    response.setHeader("Content-disposition", "attachment; filename=" + fileName);
+                    byte[] bytes = new byte[1024];
+                    int len;
+                    while ((len = fileInputStream.read(bytes)) != -1) {
+                        outputStream.write(bytes, 0, len);
+                    }
+                    fileInputStream.close();
+                    outputStream.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            file.delete();
+            FileZipUtils.deleteFile(new File(zipPath));
+        }else {
+            ArrayList<ChallengeRoundVo> fileTreeVos = new ArrayList<>();
+            ChallengeRoundVo f = authMapper.getChallengeRoundInfo(Integer.valueOf(fileId));
+                fileTreeVos.add(f);
+            //有package则在服务器固定路径new file.mkdir
+            UUID uuid = UUID.randomUUID();
+            String zipPath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/" + uuid;
+            String filePath = zipPath;
+            if ("dev".equals(active)) {
+                zipPath = "D:\\caimei-workSpace\\file\\" + uuid;
+                filePath = zipPath;
+            }
+            boolean mkdirs = new File(filePath).mkdirs();
+            Assert.isTrue(mkdirs, "文件夹创建失败");
+            for (ChallengeRoundVo challengeRoundVo : fileTreeVos) {
+                //普通文件直接下载到临时文件夹uuid下
+                String fileName = "";
+                if ("dev".equals(active)) {
+                    fileName = zipPath + "\\"+challengeRoundVo.getTitle() ;
+                } else {
+                    fileName = zipPath + "/"+challengeRoundVo.getTitle() ;
+                }
+                OSSUtils.downFileByFilePath("authFile/", challengeRoundVo.getOssName(), fileName);
+//                else {
+//                    //文件夹在uuid文件夹下创建自己包名的文件夹
+//                    String param = fileTreeVo.getId() + "," + authUserId;
+//                    String myPath = "";
+//                    myPath = filePath + "/" + fileTreeVo.getFileName();
+//                    if ("dev".equals(active)) {
+//                        myPath = filePath + "\\" + fileTreeVo.getFileName();
+//                    }
+//                    boolean dirs = new File(myPath).mkdirs();
+//                    Assert.isTrue(dirs, "文件夹创建失败");
+//                    recursion(param, myPath);
+//                }
+            }
+
+            //压缩
+            FileZipUtils.compress(zipPath, "", true);
+            String s = zipPath + ".zip";
+            String fileName = uuid + ".zip";
+            File file = new File(s);
+            try {
+                if (file.exists()) {
+                    FileInputStream fileInputStream = new FileInputStream(file);
+                    ServletOutputStream outputStream = response.getOutputStream();
+                    // 设置下载文件的mineType,告诉浏览器下载文件类型
+//                                int i = fileName.lastIndexOf(".");
 //                                String substring = fileName.substring(i + 1, filePath.length());
                     response.setContentType("application/zip");
                     // 设置一个响应头,无论是否被浏览器解析,都下载