浏览代码

新增 归档压缩包

Administrator 1 年之前
父节点
当前提交
33820651a4

+ 25 - 29
ruoyi-system/src/main/java/com/ruoyi/system/service/loan/impl/LoanApplicationServiceImpl.java

@@ -602,7 +602,7 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
         List<File> fileList = new ArrayList<>();
         if (loanApplicationFjList != null && loanApplicationFjList.size() > 0) {
             for (LoanApplicationFj loanApplicationFj : loanApplicationFjList) {
-                fileList.add(new File(loanApplicationFj.getUrl().replace("/profile", filePath)));
+                fileList.add(new File(loanApplicationFj.getUrl().replace("/profile/upload/", filePath)));
             }
         }
         String corporationFront = loanApplicationOld.getCorporationFront();
@@ -638,10 +638,12 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
         }
 
 
+        //16位序列号
+        String id = Seq.getId(Seq.uploadSeqType);
         String name = StringUtils.format("{}_{}.{}",
-                loanApplicationOld.getEnterpriseName(), Seq.getId(Seq.uploadSeqType) + "文档", "zip");
-        String zipFileName = StringUtils.format("{}/{}_{}.{}",loanApplicationOld.getLoanApplicationNumber(),
-                loanApplicationOld.getEnterpriseName(), Seq.getId(Seq.uploadSeqType) + "文档", "zip");
+                loanApplicationOld.getEnterpriseName(), id + "文档", "zip");
+        String zipFileName = StringUtils.format("{}/{}_{}.{}", loanApplicationOld.getLoanApplicationNumber(),
+                loanApplicationOld.getEnterpriseName(), id + "文档", "zip");
         //进行压缩
         zipEncryptExample(fileList, filePath, zipFileName, "123");
         //把压缩包的url插入附件表
@@ -669,40 +671,34 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
      */
     public void zipEncryptExample(List<File> fileList, String zipPathDir, String zipFileName, String password) {
         String zipFilePath = zipPathDir + "/" + zipFileName;
+        ZipOutputStream out = null;
+        BufferedOutputStream bo = null;
         try {
+            out = new ZipOutputStream(new FileOutputStream(zipFilePath));
 
-/*            ZipParameters zipParameters = new ZipParameters();
-            zipParameters.setEncryptFiles(true);
-            zipParameters.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD); // 标准AES加密
-            ZipFile zipFile = new ZipFile(zipPathDir, password.toCharArray());
-            zipFile.addFiles(fileList, zipParameters);*/
-
-            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(zipFilePath)));
-            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zos));
-            File zipFile = new File(zipPathDir);
-            if (!zipFile.exists()) {
-                zipFile.mkdirs();
-            }
+            bo = new BufferedOutputStream(out);
             for (File file : fileList) {
                 if (file.exists()) {
                     ZipEntry zipEntry = new ZipEntry(file.getName());
-                    zos.putNextEntry(zipEntry);
-                    Path path = Paths.get(file.getAbsolutePath());
-                    BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(path)));
-                    while (reader.ready()) {
-                        writer.write(reader.readLine());
+
+                    out.putNextEntry(zipEntry);
+
+                    FileInputStream in = new FileInputStream(file);
+
+                    BufferedInputStream bi = new BufferedInputStream(in);
+                    int b;
+                    while ((b = bi.read()) != -1) {
+                        bo.write(b);
                     }
-                    writer.flush();
-                    reader.close();
-                    zos.closeEntry();
-                } else {
-                    //文件路径异常filePath:filePath
+                    bo.flush();
+                    bi.close();
+                    in.close();
                 }
             }
-            zos.flush();
-            writer.close();
+            bo.close();
+            out.close();
             System.out.println("文件加密成功,保存位置:" + zipFilePath);
-        } catch (Exception e) {
+        } catch (IOException e) {
             e.printStackTrace();
         }
     }