wuheng hace 1 año
padre
commit
25426ad4e8

+ 1 - 0
common/src/main/java/com/koobietech/eas/common/constant/ArchiveFileType.java

@@ -6,6 +6,7 @@ public enum ArchiveFileType {
     DOC(".doc", 11, "application/msword"),
     DOC(".doc", 11, "application/msword"),
     XLS(".xls", 12, "application/vnd.ms-excel"),
     XLS(".xls", 12, "application/vnd.ms-excel"),
     PPT(".ppt", 13, "application/vnd.ms-powerpoint"),
     PPT(".ppt", 13, "application/vnd.ms-powerpoint"),
+    PPTX(".pptx", 13, "application/vnd.ms-powerpoint"),
     XLSX(".xlsx", 14, "application/vnd.openxmlformats-office, document.spreadsheetml.sheet"),
     XLSX(".xlsx", 14, "application/vnd.openxmlformats-office, document.spreadsheetml.sheet"),
     DOCX(".docx", 15, "application/vnd.openxmlformats-office, document.wordprocessingml.document"),
     DOCX(".docx", 15, "application/vnd.openxmlformats-office, document.wordprocessingml.document"),
     PDF(".pdf", 16, "application/pdf"),
     PDF(".pdf", 16, "application/pdf"),

+ 1 - 0
common/src/main/java/com/koobietech/eas/common/constant/FileType.java

@@ -9,6 +9,7 @@ public enum FileType {
     DOC(".doc", 11),
     DOC(".doc", 11),
     XLS(".xls", 12),
     XLS(".xls", 12),
     PPT(".ppt", 13),
     PPT(".ppt", 13),
+    PPTX(".pptx", 13),
     XLSX(".xlsx", 14),
     XLSX(".xlsx", 14),
     DOCX(".docx", 15),
     DOCX(".docx", 15),
     PDF(".pdf", 16),
     PDF(".pdf", 16),

+ 23 - 18
common/src/main/java/com/koobietech/eas/common/utils/FileManager.java

@@ -39,8 +39,9 @@ public class FileManager {
             }
             }
         } catch (IOException e) {}finally {
         } catch (IOException e) {}finally {
             try {
             try {
-                if (Objects.nonNull(stream))
+                if (Objects.nonNull(stream)){
                     stream.close();
                     stream.close();
+                }
             } catch (IOException e) {}
             } catch (IOException e) {}
         }
         }
         if ( size > 0  ) {
         if ( size > 0  ) {
@@ -392,7 +393,7 @@ public class FileManager {
         FileInputStream fileOutputStream = null;
         FileInputStream fileOutputStream = null;
         try {
         try {
             fileOutputStream = new FileInputStream(filePath);
             fileOutputStream = new FileInputStream(filePath);
-        } catch (FileNotFoundException e) {}
+        } catch (FileNotFoundException ignored) {}
         return fileOutputStream;
         return fileOutputStream;
     }
     }
 
 
@@ -441,51 +442,55 @@ public class FileManager {
         try {
         try {
             fileOutputStream = new FileOutputStream(tempZipFilePath);
             fileOutputStream = new FileOutputStream(tempZipFilePath);
             zipOutputStream = new ZipOutputStream(fileOutputStream);
             zipOutputStream = new ZipOutputStream(fileOutputStream);
-            compressFolder(folderToCompress, zipOutputStream);
+            compressFolder(folderToCompress, zipOutputStream,  "");
         } catch (IOException e) {
         } catch (IOException e) {
             result = false;
             result = false;
         } finally {
         } finally {
             try {
             try {
-                if ( Objects.nonNull(fileOutputStream) ) {
-                    fileOutputStream.close();
-                }
                 if ( Objects.nonNull(zipOutputStream)) {
                 if ( Objects.nonNull(zipOutputStream)) {
+                    zipOutputStream.finish();
+                    zipOutputStream.flush();
                     zipOutputStream.close();
                     zipOutputStream.close();
                 }
                 }
+                if ( Objects.nonNull(fileOutputStream) ) {
+                    fileOutputStream.close();
+                }
             } catch (Exception ignored) {}
             } catch (Exception ignored) {}
         }
         }
         return result;
         return result;
     }
     }
 
 
-    private void compressFolder(String sourceFolder, ZipOutputStream zipOutputStream) {
-        System.out.println( "sourceFolder" );
-        System.out.println( sourceFolder );
+    private void compressFolder(String sourceFolder, ZipOutputStream zipOutputStream,  String folderLevel) {
         File folder = new File(sourceFolder);
         File folder = new File(sourceFolder);
         File[] files = folder.listFiles();
         File[] files = folder.listFiles();
         if (files != null) {
         if (files != null) {
             for (File file : files) {
             for (File file : files) {
+                String folderLevelZipEntry = file.getName();
+                if ( !"".equals(folderLevel) ) {
+                    folderLevelZipEntry = folderLevel + File.separator  + file.getName();
+                }
                 if (file.isDirectory()) {
                 if (file.isDirectory()) {
-                    compressFolder( sourceFolder + separator + file.getName(), zipOutputStream);
-                } else {
-                    addToZipFile(file.getName(), sourceFolder + separator + file.getName(), zipOutputStream);
+                    compressFolder( file.getAbsolutePath(), zipOutputStream, folderLevelZipEntry );
+                } else if (file.isFile()) {
+                    addToZipFile(file.getAbsolutePath(), zipOutputStream, folderLevelZipEntry);
                 }
                 }
             }
             }
         }
         }
     }
     }
 
 
-    private void addToZipFile(String fileName, String fileAbsolutePath, ZipOutputStream zipOutputStream) {
-        System.out.println( "fileAbsolutePath" );
-        System.out.println( fileAbsolutePath );
+    private void addToZipFile(String fileAbsolutePath, ZipOutputStream zipOutputStream, String folderLevel) {
         FileInputStream fileInputStream = null;
         FileInputStream fileInputStream = null;
-        ZipEntry entry = new ZipEntry(fileName);
+        ZipEntry entry = new ZipEntry(folderLevel);
         try {
         try {
-            zipOutputStream.putNextEntry(entry);
             fileInputStream = new FileInputStream(fileAbsolutePath);
             fileInputStream = new FileInputStream(fileAbsolutePath);
-            byte[] buffer = new byte[1024];
+            zipOutputStream.putNextEntry(entry);
+            zipOutputStream.setComment("爱扣钉 档案系统");
+            byte[] buffer = new byte[4096];
             int bytesRead;
             int bytesRead;
             while ((bytesRead = fileInputStream.read(buffer)) != -1) {
             while ((bytesRead = fileInputStream.read(buffer)) != -1) {
                 zipOutputStream.write(buffer, 0, bytesRead);
                 zipOutputStream.write(buffer, 0, bytesRead);
             }
             }
+            zipOutputStream.closeEntry();
         } catch (Exception ignored) {}finally {
         } catch (Exception ignored) {}finally {
             try {
             try {
                 if ( Objects.nonNull(fileInputStream)) {
                 if ( Objects.nonNull(fileInputStream)) {

+ 2 - 9
service/src/main/java/com/koobietech/eas/service/impl/EasArchiveFileDownloadServiceImpl.java

@@ -77,22 +77,15 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
 
 
     @Override
     @Override
     public boolean downloadFileByToken(String archiveToken, HttpServletResponse response) {
     public boolean downloadFileByToken(String archiveToken, HttpServletResponse response) {
-        //加入判断
 
 
+        //加入判断
         String filePath = getFilePathByToken(archiveToken);
         String filePath = getFilePathByToken(archiveToken);
-
-        //加一个判断,如果filePath为空,说明token已经过期,抛出异常
         if (filePath == null) {
         if (filePath == null) {
             throw new EasException("获取文件超时,请重新获取token", 4003);
             throw new EasException("获取文件超时,请重新获取token", 4003);
         }
         }
-
-        System.out.println( "fileExtension" + filePath );
-
         String fileExtension = getFileExtension(filePath);
         String fileExtension = getFileExtension(filePath);
-
         String archiveFileType = ArchiveFileType.getContentType(fileExtension.toLowerCase());
         String archiveFileType = ArchiveFileType.getContentType(fileExtension.toLowerCase());
 
 
-
         if (archiveFileType != null) {
         if (archiveFileType != null) {
             response.addHeader("Content-Type", archiveFileType);
             response.addHeader("Content-Type", archiveFileType);
             response.addHeader("Content-Disposition", "attachment; filename=" + getFileSaveName(filePath) );
             response.addHeader("Content-Disposition", "attachment; filename=" + getFileSaveName(filePath) );
@@ -120,7 +113,7 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
                 if (Objects.nonNull(fileInputStream)) {
                 if (Objects.nonNull(fileInputStream)) {
                     fileInputStream.close();
                     fileInputStream.close();
                 }
                 }
-            } catch (IOException e) {}
+            } catch (IOException ignored) {}
         }
         }
         return true;
         return true;
     }
     }

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

@@ -203,7 +203,7 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
         String userArchivePath = tempPath + separator + studentNumber + ".zip";
         String userArchivePath = tempPath + separator + studentNumber + ".zip";
         boolean zipFile = fileManager.createZipFile(userArchivePath, path);
         boolean zipFile = fileManager.createZipFile(userArchivePath, path);
         if ( zipFile ) {
         if ( zipFile ) {
-            return tempPath;
+            return userArchivePath;
         }
         }
         return null;
         return null;
     }
     }

+ 11 - 2
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -36,6 +36,8 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
+import java.time.LocalDate;
+import java.time.ZoneOffset;
 import java.util.*;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.Pattern;
@@ -105,9 +107,14 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
             inputStream = file.getInputStream();
             inputStream = file.getInputStream();
             String type = file.getOriginalFilename().substring(
             String type = file.getOriginalFilename().substring(
                     file.getOriginalFilename().lastIndexOf(".") + 1).toUpperCase();
                     file.getOriginalFilename().lastIndexOf(".") + 1).toUpperCase();
-            if ( FileType.valueOf(type) != null ) {
-                archivesDto = easArchivesFilesService.saveArchiveFile(studentNumber, inputStream, type);
+            try {
+                //如果抛异常 则类型不识别
+                FileType.valueOf(type);
             }
             }
+            catch (IllegalArgumentException e) {
+                type = FileType.FILE.toString();
+            }
+            archivesDto = easArchivesFilesService.saveArchiveFile(studentNumber, inputStream, type);
         } catch (IOException ignore) {
         } catch (IOException ignore) {
         } finally {
         } finally {
             if (inputStream != null) {
             if (inputStream != null) {
@@ -147,6 +154,8 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
         arc.setCreateTime(new Date());
         arc.setCreateTime(new Date());
         arc.setModifyTime(new Date());
         arc.setModifyTime(new Date());
         arc.setArchiveNumber( archiveNumber );
         arc.setArchiveNumber( archiveNumber );
+        arc.setValidityTime( new Date(LocalDate.now().plusMonths(20)
+                .atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()) );
         arc.setManagerId( SecurityManager.getLoginUid().intValue() );
         arc.setManagerId( SecurityManager.getLoginUid().intValue() );
         arc.setCreateUid( SecurityManager.getLoginUid().intValue() );
         arc.setCreateUid( SecurityManager.getLoginUid().intValue() );
         arc.setCreateDate(new Date());
         arc.setCreateDate(new Date());