wuheng пре 1 година
родитељ
комит
68bc2af473

+ 37 - 19
common/src/main/java/com/koobietech/eas/common/constant/FileType.java

@@ -1,31 +1,49 @@
 package com.koobietech.eas.common.constant;
 
+/**
+ * @author lc
+ */
+
 public enum FileType {
-    IMAGE("20"),
-    VIDEO("30"),
-    AUDIO("40"),
-    XLSX("50"),
-    DOCX("51"),
-    PNG("21"),
-    JPEG("22"),
-    ZIP("60"),
-    RAR("61"),
-    MP4("41"),
-    MP3("42"),
-    PDF("80"),
-    FILE("70");
+    //OFFICE 文件
+    DOC(".doc", 11),
+    XLS(".xls", 12),
+    PPT(".ppt", 13),
+    XLSX(".xlsx", 14),
+    DOCX(".docx", 15),
+    PDF(".pdf", 16),
+    //文本文件
+    TXT(".txt", 21),
+    HTML(".html", 22),
+    CSS(".css", 23),
+    JS(".js", 24),
+    //媒体文件
+    JPG(".jpg", 31),
+    JPEG(".jpeg", 36),
+    GIF(".gif", 32),
+    MP4(".mp4", 33),
+    MP3(".mp3", 34),
+    PNG(".png", 35),
+    //压缩文件
+    GZ(".gz", 41),
+    ZIP(".zip", 42),
+    RAR(".rar", 43),
+    //其他文件
+    FILE(".file", 51);
 
-    private String value;
+    private String suffix;
+    private int value;
 
-    FileType(String value) {
+    FileType(String suffix, int value) {
+        this.suffix = suffix;
         this.value = value;
     }
 
-    public String getValue() {
-        return value;
+    public String getSuffix() {
+        return suffix;
     }
 
-    public void setValue(String value) {
-        this.value = value;
+    public int getValue() {
+        return value;
     }
 }

+ 0 - 31
common/src/main/java/com/koobietech/eas/common/constant/FileTypeExt.java

@@ -1,31 +0,0 @@
-package com.koobietech.eas.common.constant;
-
-public enum FileTypeExt {
-    IMAGE(".jpeg"),
-    VIDEO(".mp4"),
-    AUDIO(".mp3"),
-    XLSX(".xlsx"),
-    DOCX(".docx"),
-    PNG(".png"),
-    JPEG(".jpeg"),
-    ZIP(".zip"),
-    RAR(".rar"),
-    MP4(".mp4"),
-    MP3(".mp3"),
-    PDF(".pdf"),
-    FILE(".file");
-
-    private String value;
-
-    FileTypeExt(String value) {
-        this.value = value;
-    }
-
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-}

+ 3 - 1
common/src/main/java/com/koobietech/eas/common/utils/PasswordManager.java

@@ -9,6 +9,9 @@ import org.springframework.stereotype.Component;
 
 import java.nio.charset.StandardCharsets;
 
+/**
+ * @author lc
+ */
 @Component
 public class PasswordManager {
 
@@ -31,5 +34,4 @@ public class PasswordManager {
     }
 
 
-
 }

+ 103 - 7
common/src/main/java/com/koobietech/eas/common/utils/StudentArchiveGenerator.java

@@ -1,11 +1,19 @@
 package com.koobietech.eas.common.utils;
 
+import com.koobietech.eas.common.constant.UniversityCodeUtils;
+import com.koobietech.eas.common.pojo.ArchiveNumberInfo;
+import com.koobietech.eas.common.pojo.StudentNumberInfo;
+
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.Period;
 import java.time.format.DateTimeFormatter;
 import java.util.Locale;
 import java.util.UUID;
+
+/**
+ * @author lc
+ */
 public class StudentArchiveGenerator {
 
     private static final String ARCHIVE_CODE_PREFIX = "SA";
@@ -15,8 +23,14 @@ public class StudentArchiveGenerator {
     private static final int STUDENT_CODE_LENGTH = 25;
     private static final int STUDENT_NUM_LENGTH = 8;
 
-    public  static String generateArchiveCode(String generateStudentCode, String fileTypeCode) {
-        String studentNum = generateStudentCode.substring(2, STUDENT_NUM_LENGTH + 3).replace("X", "");
+    /**
+     * 生成文件档案编号
+     * @param generateStudentCode
+     * @param fileTypeCode
+     * @return
+     */
+    public static String generateArchiveCode(String generateStudentCode, String fileTypeCode) {
+        String studentNum = generateStudentCode.substring(2, STUDENT_NUM_LENGTH + 2);
         String nowDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHhmmss", Locale.CHINA));
         String archiveCode = ARCHIVE_CODE_PREFIX + studentNum + nowDate + fileTypeCode;
         if (archiveCode.length() < ARCHIVE_CODE_LENGTH) {
@@ -26,11 +40,40 @@ public class StudentArchiveGenerator {
         return archiveCode;
     }
 
+    /**
+     *解析档案编号信息
+     *
+     * @param archiveNumber
+     * @return
+     */
+    public static ArchiveNumberInfo parseArchiveNumber(String archiveNumber) {
+        ArchiveNumberInfo archiveInfo = new ArchiveNumberInfo();
+        String studentCode = archiveNumber.substring(2, STUDENT_NUM_LENGTH);
+        String studentId = studentCode.split("X")[0];
+        String createTime = archiveNumber.substring(STUDENT_NUM_LENGTH + 2, 13);
+        String fileTypeCode = archiveNumber.substring(ARCHIVE_CODE_LENGTH - 2);
+        archiveInfo.setStudentId(Integer.parseInt(studentId));
+        archiveInfo.setCreateTime(Long.parseLong(createTime));
+        archiveInfo.setFileTypeCode(Integer.parseInt(fileTypeCode));
+        return archiveInfo;
+    }
+
+
+
+    /**
+     * 生成学生档案编码
+     * @param studentNumber
+     * @param studentId
+     * @param schoolName
+     * @param enrollmentDate
+     * @return
+     */
     public static String generateStudentCode(String studentNumber, String studentId, String schoolName, String enrollmentDate) {
         LocalDate localDateEnrollmentDate = LocalDate.of(Integer.parseInt(enrollmentDate), 1, 1);
         String studentAge = String.valueOf(getStudentAge(studentId));
         String studentNum = getStudentNum(studentNumber);
-        String studentGender = getStudentGender(studentId).substring(0, 1); // 取性别代码的首字母
+        // 取性别代码的首字母
+        String studentGender = getStudentGender(studentId).substring(0, 1);
         String graduationDate = String.valueOf(getStudentGraduationDate(localDateEnrollmentDate).getYear());
 
         String studentCode = STUDENT_CODE_PEREFIX + studentNum + studentAge +
@@ -44,14 +87,52 @@ public class StudentArchiveGenerator {
         return studentCode;
     }
 
+    /**
+     * 解析学生档案编号信息
+     *
+     * @param studentNumber 学生档案编号
+     * @return 学生档案编号信息
+     */
+    public static StudentNumberInfo parseStudentNumber(String studentNumber) {
+        if (studentNumber == null) {
+            return null;
+        }
+        String studentNum = studentNumber.substring(2, STUDENT_CODE_LENGTH);
+        String studentId = studentNum.split("X")[0];
+        String studentAge = studentNumber.substring(STUDENT_CODE_LENGTH + 2, 2);
+        String studentGender = studentNumber.substring(STUDENT_CODE_LENGTH + 4, 1);
+        String graduationDate = studentNumber.substring(STUDENT_CODE_LENGTH + 5, 4);
+        String schoolCode = studentNumber.substring(STUDENT_CODE_LENGTH + 9);
+        StudentNumberInfo info = new StudentNumberInfo();
+        info.setStudentNum(studentNum);
+        info.setStudentId(Long.valueOf(studentId));
+        info.setStudentAge(Integer.parseInt(studentAge));
+        info.setStudentGender(studentGender);
+        info.setGraduationDate(graduationDate);
+        info.setSchoolName(UniversityCodeUtils.getName(Integer.parseInt(schoolCode)));
+        info.setSchoolCode(Integer.parseInt(schoolCode));
+        return info;
+    }
+
+    /**
+     * 获取学生编号,自动补齐
+     * @param studentNumber
+     * @return
+     */
     private static String getStudentNum(String studentNumber) {
         if (studentNumber.length() < STUDENT_NUM_LENGTH) {
-            studentNumber = studentNumber + "X" + UUID.randomUUID().toString()
+            studentNumber = studentNumber + "X" +
+                    (UUID.randomUUID().toString().replace("-", "").replace("X", ""))
                     .toUpperCase(Locale.ROOT).substring(0, STUDENT_NUM_LENGTH - studentNumber.length());
         }
         return studentNumber;
     }
 
+    /**
+     * 获取学生年龄
+     * @param studentId
+     * @return
+     */
     private static int getStudentAge(String studentId) {
         LocalDate currentDate = LocalDate.now();
         LocalDate birthDateirthDate = extractBirthDate(studentId);
@@ -59,19 +140,34 @@ public class StudentArchiveGenerator {
         return period.getYears();
     }
 
+    /**
+     * 获取学生性别
+     * @param studentId
+     * @return
+     */
     private static String getStudentGender(String studentId) {
         // 根据身份证号获取性别,这里只取身份证号的倒数第二位判断性别,假设性别代码为奇数表示男性,偶数表示女性
         int genderCode = Integer.parseInt(studentId.substring(16, 17));
         return genderCode % 2 == 0 ? "F" : "M";
     }
 
+    /**
+     * 获取学生毕业日期
+     * @param enrollmentDate
+     * @return
+     */
     private static LocalDate getStudentGraduationDate(LocalDate enrollmentDate) {
         // 假设毕业时间为入学时间的四年后
-        LocalDate graduationDate = enrollmentDate.plusYears(4);
-        return graduationDate;
+        return enrollmentDate.plusYears(4);
     }
-    // 提取身份证号码中的出生日期部分
+
+    /**
+     * 提取身份证号码的出生日期部分
+     * @param idCard
+     * @return
+     */
     private static LocalDate extractBirthDate(String idCard) {
+        // 提取身份证号码中的出生日期部分
         String birthdate = idCard.substring(6, 14);
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
         return LocalDate.parse(birthdate, formatter);

+ 12 - 8
security/src/main/java/com/koobietech/eas/security/utils/SecurityUtils.java

@@ -1,36 +1,40 @@
 package com.koobietech.eas.security.utils;
+
 import com.koobietech.eas.dao.adminLoginPojo.UserDetail;
 import org.springframework.security.core.context.SecurityContextHolder;
 
 import java.util.Objects;
 
+/**
+ * @author lc
+ */
 public class SecurityUtils {
 
-    public static String getLoginUserName(){
+    public static String getLoginUserName() {
         UserDetail principal = getPrincipal();
-        if ( Objects.nonNull(principal) ) {
+        if (Objects.nonNull(principal)) {
             return principal.getUsername();
         }
         return "anonymousUser";
     }
 
-    public static Long getLoginUid(){
+    public static Long getLoginUid() {
         UserDetail principal = getPrincipal();
-        if ( Objects.nonNull(principal) ) {
+        if (Objects.nonNull(principal)) {
             return principal.getId();
         }
         return 0L;
     }
 
-    public static boolean isLogged(){
+    public static boolean isLogged() {
         UserDetail principal = getPrincipal();
         return Objects.nonNull(principal);
     }
 
-    private static UserDetail getPrincipal(){
+    private static UserDetail getPrincipal() {
         Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        if (Objects.nonNull(principal) ) {
-            if ( principal instanceof UserDetail ) {
+        if (Objects.nonNull(principal)) {
+            if (principal instanceof UserDetail) {
                 return (UserDetail) principal;
             } else {
                 return null;

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

@@ -8,6 +8,9 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+/**
+ * @author lc
+ */
 public interface EasArchivesFilesService {
     /**
      * 获取学生档案文件
@@ -68,4 +71,19 @@ public interface EasArchivesFilesService {
      * @return
      */
     boolean deleteArchiveFile(String filePath);
+
+    /**
+     * 备份档案文件
+     * @param filePath
+     * @return
+     */
+    boolean backupArchiveFile(String filePath);
+
+    /**
+     * 获取档案连接Url地址
+     * @param filePath
+     * @return
+     */
+    String getArchiveUrl(String filePath);
+
 }

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

@@ -1,7 +1,6 @@
 package com.koobietech.eas.service.impl;
 
 import com.koobietech.eas.common.constant.FileType;
-import com.koobietech.eas.common.constant.FileTypeExt;
 import com.koobietech.eas.common.utils.FileManager;
 import com.koobietech.eas.common.utils.StudentArchiveGenerator;
 import com.koobietech.eas.dao.dto.ArchivesDto;
@@ -17,12 +16,17 @@ import javax.annotation.Resource;
 import java.io.*;
 import java.util.List;
 
+/**
+ * @author lc
+ */
 @Service
 public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
 
     @Value("${project.path}")
     String archivesSavePath;
 
+    final String BAKUP_SUFFIX =  ".bak";
+
     @Resource
     FileManager fileManager;
 
@@ -48,8 +52,8 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
 
     @Override
     public ArchivesDto saveArchiveFile(String studentNumber, InputStream stream, String type) {
-        String archiveCode = getArchiveCode(studentNumber, FileType.valueOf(type).getValue() );
-        String path = getArchivePath(studentNumber, archiveCode, FileTypeExt.valueOf(type).getValue());
+        String archiveCode = getArchiveCode(studentNumber, FileType.valueOf(type).getSuffix());
+        String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
         boolean status = fileManager.saveFile(stream, path);
         return new ArchivesDto(path, status, archiveCode, type);
     }
@@ -61,7 +65,7 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
 
     @Override
     public FileInputStream getArchiveFile(String filePath) {
-        return  fileManager.getArchiveFile(filePath);
+        return fileManager.getArchiveFile(filePath);
     }
 
     @Override
@@ -69,7 +73,8 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
         InputStream resourceAsStream = null;
         try {
             resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
-        } catch (Exception e) {}
+        } catch (Exception e) {
+        }
         return resourceAsStream;
     }
 
@@ -81,9 +86,31 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
         return easArcTlsStudents.stream().findFirst().orElse(null);
     }
 
-    private ArchivesDto saveArchiveDocumentFile(String studentNumber, XWPFDocument document, String type ) {
-        String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.valueOf(type).getValue());
-        String path = getArchivePath(studentNumber, archiveCode,  FileTypeExt.valueOf(type).getValue());
+    @Override
+    public boolean backupArchiveFile(String filePath) {
+        boolean ret = false;
+        if (filePath == null || filePath.isEmpty()) {
+            return ret;
+        }
+        if ( fileManager.isFileExists(filePath) ) {
+            long time = System.currentTimeMillis();
+            ret = fileManager.moveFile(filePath, filePath + time + BAKUP_SUFFIX, true);
+        }
+        return ret;
+    }
+
+    @Override
+    public String getArchiveUrl(String filePath) {
+        String url = null;
+        if (filePath == null || filePath.isEmpty()) {
+            return url;
+        }
+        return null;
+    }
+
+    private ArchivesDto saveArchiveDocumentFile(String studentNumber, XWPFDocument document, String type) {
+        String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.valueOf(type).getSuffix());
+        String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
         boolean status = fileManager.saveDocument(document, path);
         return new ArchivesDto(path, status, archiveCode, type);
     }

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

@@ -93,7 +93,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
 
                 easSysStudentMapper.insert(easSysStudents);
 
-                String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, String.valueOf(FileType.DOCX));
+                String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, String.valueOf(FileType.DOCX.getValue()));
                 ArchivesDto archivesDto = easArchivesFilesService.saveArchiveStudentsFile(easArcTlsStudents.getStudentIdnumber(), doc);
                 String filePath = archivesDto.getPath();
                 String arctype = archivesDto.getFileType();