浏览代码

zip 包下载

wuheng 1 年之前
父节点
当前提交
fcbeb2aa8c

+ 7 - 6
common/src/main/java/com/koobietech/eas/common/utils/FileManager.java

@@ -433,8 +433,8 @@ public class FileManager {
         if ( !isFolderExists(folderToCompress)) {
         if ( !isFolderExists(folderToCompress)) {
             return false;
             return false;
         }
         }
-        if (isFolderExists( tempZipFilePath )) {
-            return false;
+        if ( isFolderExists( tempZipFilePath )) {
+            deleteFolder(tempZipFilePath);
         }
         }
         FileOutputStream fileOutputStream = null;
         FileOutputStream fileOutputStream = null;
         ZipOutputStream zipOutputStream = null;
         ZipOutputStream zipOutputStream = null;
@@ -458,6 +458,8 @@ public class FileManager {
     }
     }
 
 
     private void compressFolder(String sourceFolder, ZipOutputStream zipOutputStream) {
     private void compressFolder(String sourceFolder, ZipOutputStream zipOutputStream) {
+        System.out.println( "sourceFolder" );
+        System.out.println( sourceFolder );
         File folder = new File(sourceFolder);
         File folder = new File(sourceFolder);
         File[] files = folder.listFiles();
         File[] files = folder.listFiles();
         if (files != null) {
         if (files != null) {
@@ -465,13 +467,15 @@ public class FileManager {
                 if (file.isDirectory()) {
                 if (file.isDirectory()) {
                     compressFolder( sourceFolder + separator + file.getName(), zipOutputStream);
                     compressFolder( sourceFolder + separator + file.getName(), zipOutputStream);
                 } else {
                 } else {
-                    addToZipFile(file.getName(), sourceFolder + File.separator + file.getName(), zipOutputStream);
+                    addToZipFile(file.getName(), sourceFolder + separator + file.getName(), zipOutputStream);
                 }
                 }
             }
             }
         }
         }
     }
     }
 
 
     private void addToZipFile(String fileName, String fileAbsolutePath, ZipOutputStream zipOutputStream) {
     private void addToZipFile(String fileName, String fileAbsolutePath, ZipOutputStream zipOutputStream) {
+        System.out.println( "fileAbsolutePath" );
+        System.out.println( fileAbsolutePath );
         FileInputStream fileInputStream = null;
         FileInputStream fileInputStream = null;
         ZipEntry entry = new ZipEntry(fileName);
         ZipEntry entry = new ZipEntry(fileName);
         try {
         try {
@@ -484,9 +488,6 @@ public class FileManager {
             }
             }
         } catch (Exception ignored) {}finally {
         } catch (Exception ignored) {}finally {
             try {
             try {
-                if ( Objects.nonNull(zipOutputStream )) {
-                    zipOutputStream.closeEntry();
-                }
                 if ( Objects.nonNull(fileInputStream)) {
                 if ( Objects.nonNull(fileInputStream)) {
                     fileInputStream.close();
                     fileInputStream.close();
                 }
                 }

+ 7 - 0
controller/src/main/java/com/koobietech/eas/controller/EasSysStuProfileController.java

@@ -78,6 +78,13 @@ public class EasSysStuProfileController {
         return JsonResult.bool(res);
         return JsonResult.bool(res);
     }
     }
 
 
+    @PostMapping("/downloadArchives")
+    @Operation(summary = "下载学员档案", description = "下载学员档案")
+    public JsonResult downloadArchives(@RequestParam(required = true) String studentNumber){
+        String res = easStuProfileService.downloadArchives(studentNumber);
+        return JsonResult.data(res);
+    }
+
     @PostMapping("/query")
     @PostMapping("/query")
     @Operation(summary = "查询学员信息", description = "查询学员信息")
     @Operation(summary = "查询学员信息", description = "查询学员信息")
     public JsonPageResult query(@RequestBody(required = false) EasArcTlsStudents studentDto,
     public JsonPageResult query(@RequestBody(required = false) EasArcTlsStudents studentDto,

+ 2 - 0
service/src/main/java/com/koobietech/eas/service/EasArchiveFileDownloadService.java

@@ -5,6 +5,8 @@ import javax.servlet.http.HttpServletResponse;
 public interface EasArchiveFileDownloadService {
 public interface EasArchiveFileDownloadService {
     String getArchiveToken(String archiveId);
     String getArchiveToken(String archiveId);
 
 
+    String getArchiveDownloadToken(String archiveNumber, String filePath);
+
     String getFilePathByToken(String archiveToken);
     String getFilePathByToken(String archiveToken);
 
 
     boolean downloadFileByToken(String archiveToken, HttpServletResponse response);
     boolean downloadFileByToken(String archiveToken, HttpServletResponse response);

+ 1 - 0
service/src/main/java/com/koobietech/eas/service/EasArchivesFilesService.java

@@ -92,4 +92,5 @@ public interface EasArchivesFilesService {
      */
      */
     boolean refreshProfile();
     boolean refreshProfile();
 
 
+    String createZipArchives(String studentNumber);
 }
 }

+ 2 - 0
service/src/main/java/com/koobietech/eas/service/EasStuProfileService.java

@@ -35,4 +35,6 @@ public interface EasStuProfileService {
     boolean addArchives(EasArcArchives arc);
     boolean addArchives(EasArcArchives arc);
 
 
     boolean delArchives(Integer id);
     boolean delArchives(Integer id);
+
+    String downloadArchives(String studentNumber);
 }
 }

+ 15 - 13
service/src/main/java/com/koobietech/eas/service/impl/EasArchiveFileDownloadServiceImpl.java

@@ -33,15 +33,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
 
 
     @Override
     @Override
     public String getArchiveToken(String archiveNumber) {
     public String getArchiveToken(String archiveNumber) {
-        //在getArchiveToken中,使用UUID随机生成字符串作为k键,
-        // 为了保证每次生成的字符串不同,在生成的时候加上时间戳
-        // 使用根据id查询到的所需文件在本机上的地址file_path作为v值
-        // 获取当前时间戳
-        long timestamp = System.currentTimeMillis();
-        // 使用UUID生成一个唯一标识
-        String uniqueId = UUID.randomUUID().toString();
-        // 将用户传入的ID与时间戳和唯一标识拼接起来
-        String token = archiveNumber + "_" + timestamp + "_" + uniqueId;
 
 
         EasArcArchivesExample easArcArchivesExample = new EasArcArchivesExample();
         EasArcArchivesExample easArcArchivesExample = new EasArcArchivesExample();
         easArcArchivesExample.createCriteria().andArchiveNumberEqualTo(archiveNumber);
         easArcArchivesExample.createCriteria().andArchiveNumberEqualTo(archiveNumber);
@@ -52,14 +43,25 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
             throw new EasException("文件不存在");
             throw new EasException("文件不存在");
         }
         }
 
 
-        // 获取文件路径
-        String filePath = easArcArchives.getFilePath();
+        return getArchiveDownloadToken( easArcArchives.getArchiveNumber(),  easArcArchives.getFilePath() );
+
+    }
+
+    @Override
+    public String getArchiveDownloadToken(String archiveNumber, String filePath){
 
 
-        archiveRedisService.saveArchiveToken(token,filePath);
+        long timestamp = System.currentTimeMillis();
+        // 使用UUID生成一个唯一标识
+        String uniqueId = UUID.randomUUID().toString();
+        // 将用户传入的ID与时间戳和唯一标识拼接起来
+        String token = archiveNumber + "_" + timestamp + "_" + uniqueId;
+
+        // 将token存入redis
+        archiveRedisService.saveArchiveToken(token, filePath);
         // 将token返回给用户
         // 将token返回给用户
         String archiveToken = passwordManager.archiveEncryptPassword(token);
         String archiveToken = passwordManager.archiveEncryptPassword(token);
-        return archiveToken;
 
 
+        return archiveToken;
     }
     }
 
 
     @Override
     @Override

+ 14 - 0
service/src/main/java/com/koobietech/eas/service/impl/EasArchivesFilesServiceImpl.java

@@ -194,6 +194,20 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
         return true;
         return true;
     }
     }
 
 
+    @Override
+    public String createZipArchives(String studentNumber) {
+        String path = archivesSavePath + separator + studentNumber;
+        String tempPath = archivesSavePath + separator + "zip" ;
+        fileManager.createPath(tempPath);
+        fileManager.createPath(path);
+        String userArchivePath = tempPath + separator + studentNumber + ".zip";
+        boolean zipFile = fileManager.createZipFile(userArchivePath, path);
+        if ( zipFile ) {
+            return tempPath;
+        }
+        return null;
+    }
+
     private ArchivesDto saveArchiveDocumentFile(String studentNumber, XWPFDocument document, String type) {
     private ArchivesDto saveArchiveDocumentFile(String studentNumber, XWPFDocument document, String type) {
         String archiveCode = ArchiveManager.generateArchiveCode(studentNumber, String.valueOf(FileType.valueOf(type).getValue()));
         String archiveCode = ArchiveManager.generateArchiveCode(studentNumber, String.valueOf(FileType.valueOf(type).getValue()));
         String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
         String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());

+ 9 - 0
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -16,6 +16,7 @@ import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
 import com.koobietech.eas.mbg.mapper.EasArcTlsStudentsMapper;
 import com.koobietech.eas.mbg.mapper.EasArcTlsStudentsMapper;
 import com.koobietech.eas.mbg.mapper.EasSysStudentMapper;
 import com.koobietech.eas.mbg.mapper.EasSysStudentMapper;
 import com.koobietech.eas.mbg.model.*;
 import com.koobietech.eas.mbg.model.*;
+import com.koobietech.eas.service.EasArchiveFileDownloadService;
 import com.koobietech.eas.service.EasArchivesFilesService;
 import com.koobietech.eas.service.EasArchivesFilesService;
 import com.koobietech.eas.service.EasStuProfileService;
 import com.koobietech.eas.service.EasStuProfileService;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -58,6 +59,8 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
     private EasArcArchivesMapper easArcArchivesMapper;
     private EasArcArchivesMapper easArcArchivesMapper;
     @Resource
     @Resource
     private EasArchivesFilesService easArchivesFilesService;
     private EasArchivesFilesService easArchivesFilesService;
+    @Resource
+    private EasArchiveFileDownloadService  easArchiveFileDownloadService;
 
 
     final String FILETYPE = "prefile";
     final String FILETYPE = "prefile";
 
 
@@ -164,6 +167,12 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
         return easArcArchivesMapper.deleteByPrimaryKey(id) == 1;
         return easArcArchivesMapper.deleteByPrimaryKey(id) == 1;
     }
     }
 
 
+    @Override
+    public String downloadArchives(String studentNumber) {
+        String zipArchives = easArchivesFilesService.createZipArchives(studentNumber);
+        return easArchiveFileDownloadService.getArchiveDownloadToken( studentNumber , zipArchives);
+    }
+
     @Override
     @Override
     public boolean add(EasArcTlsStudents easArcTlsStudents) {
     public boolean add(EasArcTlsStudents easArcTlsStudents) {