浏览代码

压缩文件夹

wuheng 1 年之前
父节点
当前提交
169aeba555

+ 76 - 0
common/src/main/java/com/koobietech/eas/common/utils/FileManager.java

@@ -9,6 +9,8 @@ import java.nio.channels.FileChannel;
 import java.nio.file.*;
 import java.nio.file.*;
 import java.text.DecimalFormat;
 import java.text.DecimalFormat;
 import java.util.Objects;
 import java.util.Objects;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 
 @Component
 @Component
 public class FileManager {
 public class FileManager {
@@ -421,4 +423,78 @@ public class FileManager {
         }
         }
         return result;
         return result;
     }
     }
+
+    /**
+     * 压缩文件夹
+     */
+    public boolean createZipFile(String tempZipFilePath, String folderToCompress ) {
+        boolean result = true;
+        if ( !isFolderExists(folderToCompress)) {
+            return false;
+        }
+        if (isFolderExists( tempZipFilePath )) {
+            return false;
+        }
+        FileOutputStream fileOutputStream = null;
+        ZipOutputStream zipOutputStream = null;
+        try {
+            fileOutputStream = new FileOutputStream(tempZipFilePath);
+            zipOutputStream = new ZipOutputStream(fileOutputStream);
+            compressFolder(folderToCompress, zipOutputStream);
+        } catch (IOException e) {
+            result = false;
+        } finally {
+            try {
+                if ( Objects.nonNull(fileOutputStream) ) {
+                    fileOutputStream.close();
+                }
+                if ( Objects.nonNull(zipOutputStream)) {
+                    zipOutputStream.close();
+                }
+            } catch (Exception ignored) {}
+        }
+        return result;
+    }
+
+    private void compressFolder(String sourceFolder, ZipOutputStream zipOutputStream) {
+        File folder = new File(sourceFolder);
+        File[] files = folder.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    compressFolder( sourceFolder + separator + file.getName(), zipOutputStream);
+                } else {
+                    addToZipFile(file.getName(), sourceFolder + File.separator + file.getName(), zipOutputStream);
+                }
+            }
+        }
+    }
+
+    private void addToZipFile(String fileName, String fileAbsolutePath, ZipOutputStream zipOutputStream) {
+        FileInputStream fileInputStream = null;
+        ZipEntry entry = new ZipEntry(fileName);
+        try {
+            zipOutputStream.putNextEntry(entry);
+            fileInputStream = new FileInputStream(fileAbsolutePath);
+            byte[] buffer = new byte[1024];
+            int bytesRead;
+            while ((bytesRead = fileInputStream.read(buffer)) != -1) {
+                zipOutputStream.write(buffer, 0, bytesRead);
+            }
+        } catch (Exception ignored) {}finally {
+            try {
+                if ( Objects.nonNull(zipOutputStream )) {
+                    zipOutputStream.closeEntry();
+                }
+                if ( Objects.nonNull(fileInputStream)) {
+                    fileInputStream.close();
+                }
+            } catch (IOException ignored) {}
+        }
+    }
+
+    private static String getFileFullName(String fileAbsolutePath) {
+        String[] names = fileAbsolutePath.replace("\\", "/").split("/");
+        return names[names.length -1];
+    }
 }
 }

+ 0 - 15
common/src/test/java/com/koobietech/eas/common/utils/PasswordManagerTest.java

@@ -4,24 +4,9 @@ package com.koobietech.eas.common.utils;
 class PasswordManagerTest {
 class PasswordManagerTest {
 
 
 
 
-
     public static void main(String[] args) {
     public static void main(String[] args) {
 
 
 
 
-        //ST911X3B98736M20251021273
-//        System.out.println(StudentArchiveGenerator.generateStudentCode(
-//                "911", "232126198703194770", "10212", "2021"
-//        ));
-
- //       System.out.println(StudentArchiveGenerator.parseStudentNumber("ST911X3B98736M20251021273"));
-
-   //     System.out.println(StudentArchiveGenerator.parseArchiveNumber("SA911X3B98723081544551711"));
-
-        //SA911X3B98723081544551720
-//        System.out.println(StudentArchiveGenerator.generateArchiveCode(
-//                "ST911X3B98736M20251021273", "20"
-//        ));
-
 
 
     }
     }
 
 

+ 5 - 7
controller/src/main/java/com/koobietech/eas/config/CaptchaConfig.java

@@ -46,16 +46,15 @@ public class CaptchaConfig {
         config.put(Const.CAPTCHA_WATER_FONT, "宋体");
         config.put(Const.CAPTCHA_WATER_FONT, "宋体");
         config.put(Const.CAPTCHA_CACAHE_MAX_NUMBER, "1000");
         config.put(Const.CAPTCHA_CACAHE_MAX_NUMBER, "1000");
         config.put(Const.CAPTCHA_TIMING_CLEAR_SECOND, "180");
         config.put(Const.CAPTCHA_TIMING_CLEAR_SECOND, "180");
-        if ((StringUtils.isNotBlank(config.getProperty(Const.ORIGINAL_PATH_JIGSAW))
-                && config.getProperty(Const.ORIGINAL_PATH_JIGSAW).startsWith("classpath:"))
-                || (StringUtils.isNotBlank(config.getProperty(Const.ORIGINAL_PATH_PIC_CLICK))
-                && config.getProperty(Const.ORIGINAL_PATH_PIC_CLICK).startsWith("classpath:"))) {
+        boolean jigsawNotBlank = StringUtils.isNotBlank(config.getProperty(Const.ORIGINAL_PATH_JIGSAW));
+        boolean picNotBlank = StringUtils.isNotBlank(config.getProperty(Const.ORIGINAL_PATH_PIC_CLICK));
+        if ( jigsawNotBlank && picNotBlank ) {
             config.put(Const.CAPTCHA_INIT_ORIGINAL, "true");
             config.put(Const.CAPTCHA_INIT_ORIGINAL, "true");
             initializeBaseMap(config.getProperty(Const.ORIGINAL_PATH_JIGSAW),
             initializeBaseMap(config.getProperty(Const.ORIGINAL_PATH_JIGSAW),
                     config.getProperty(Const.ORIGINAL_PATH_PIC_CLICK));
                     config.getProperty(Const.ORIGINAL_PATH_PIC_CLICK));
         }
         }
-        CaptchaService s = CaptchaServiceFactory.getInstance(config);
-        return s;
+        CaptchaService captchaService = CaptchaServiceFactory.getInstance(config);
+        return captchaService;
     }
     }
 
 
     private static void initializeBaseMap(String jigsaw, String picClick) {
     private static void initializeBaseMap(String jigsaw, String picClick) {
@@ -80,5 +79,4 @@ public class CaptchaConfig {
         }
         }
         return imgMap;
         return imgMap;
     }
     }
-
 }
 }

+ 5 - 2
service/src/main/java/com/koobietech/eas/service/StudentLoginService.java

@@ -1,7 +1,5 @@
 package com.koobietech.eas.service;
 package com.koobietech.eas.service;
 
 
-import com.anji.captcha.model.common.ResponseModel;
-import com.koobietech.eas.common.result.JsonResult;
 import com.koobietech.eas.dao.dto.LoginToken;
 import com.koobietech.eas.dao.dto.LoginToken;
 import com.koobietech.eas.dao.pojo.AdminPojo;
 import com.koobietech.eas.dao.pojo.AdminPojo;
 
 
@@ -10,5 +8,10 @@ import com.koobietech.eas.dao.pojo.AdminPojo;
  * @author lc
  * @author lc
  */
  */
 public interface StudentLoginService {
 public interface StudentLoginService {
+    /**
+     * 学员登录
+     * @param adminPojo
+     * @return
+     */
     LoginToken studentLogin(AdminPojo adminPojo);
     LoginToken studentLogin(AdminPojo adminPojo);
 }
 }