Browse Source

Merge branch 'master' into superb

superb 1 year ago
parent
commit
0b06bfda0d

+ 79 - 0
common/src/main/java/com/koobietech/eas/common/utils/StudentArchiveGenerator.java

@@ -0,0 +1,79 @@
+package com.koobietech.eas.common.utils;
+
+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;
+public class StudentArchiveGenerator {
+
+    private static final String ARCHIVE_CODE_PREFIX = "SA";
+    private static final int ARCHIVE_CODE_LENGTH = 25;
+
+    private static final String STUDENT_CODE_PEREFIX = "ST";
+    private static final int STUDENT_CODE_LENGTH = 25;
+    private static final int STUDENT_NUM_LENGTH = 10;
+
+    public  static String generateArchiveCode(String studentNumber, String fileTypeCode) {
+        String studentNum = studentNumber.substring(2, STUDENT_NUM_LENGTH);
+        String nowDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHhmmss", Locale.CHINA));
+        String archiveCode = ARCHIVE_CODE_PREFIX + studentNum + nowDate + fileTypeCode;
+        if (archiveCode.length() < ARCHIVE_CODE_LENGTH) {
+            archiveCode += UUID.randomUUID().toString()
+                    .substring(0, ARCHIVE_CODE_LENGTH - archiveCode.length());
+        }
+        return archiveCode;
+    }
+
+    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 graduationDate = String.valueOf(getStudentGraduationDate(localDateEnrollmentDate).getYear());
+
+        String studentCode = STUDENT_CODE_PEREFIX + studentNum + studentAge +
+                studentGender + graduationDate + schoolName;
+
+        // 如果生成的档案编码长度不足,用UUID填充
+        if (studentCode.length() < STUDENT_CODE_LENGTH) {
+            studentCode += UUID.randomUUID().toString()
+                    .substring(0, STUDENT_CODE_LENGTH - studentCode.length());
+        }
+        return studentCode;
+    }
+
+    private static String getStudentNum(String studentNumber) {
+        if (studentNumber.length() < STUDENT_NUM_LENGTH) {
+            studentNumber = studentNumber + "X" + UUID.randomUUID().toString()
+                    .toUpperCase(Locale.ROOT).substring(0, STUDENT_NUM_LENGTH - studentNumber.length());
+        }
+        return studentNumber;
+    }
+
+    private static int getStudentAge(String studentId) {
+        LocalDate currentDate = LocalDate.now();
+        LocalDate birthDateirthDate = extractBirthDate(studentId);
+        Period period = Period.between(birthDateirthDate, currentDate);
+        return period.getYears();
+    }
+
+    private static String getStudentGender(String studentId) {
+        // 根据身份证号获取性别,这里只取身份证号的倒数第二位判断性别,假设性别代码为奇数表示男性,偶数表示女性
+        int genderCode = Integer.parseInt(studentId.substring(16, 17));
+        return genderCode % 2 == 0 ? "F" : "M";
+    }
+
+    private static LocalDate getStudentGraduationDate(LocalDate enrollmentDate) {
+        // 假设毕业时间为入学时间的四年后
+        LocalDate graduationDate = enrollmentDate.plusYears(4);
+        return graduationDate;
+    }
+    // 提取身份证号码中的出生日期部分
+    private static LocalDate extractBirthDate(String idCard) {
+        String birthdate = idCard.substring(6, 14);
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
+        return LocalDate.parse(birthdate, formatter);
+    }
+}

+ 17 - 14
controller/src/test/java/com/koobietech/eas/controller/ControllerApplicationTests.java

@@ -12,6 +12,7 @@ import com.koobietech.eas.common.pojo.JwtUserDto;
 import com.koobietech.eas.common.service.RedisService;
 import com.koobietech.eas.common.utils.JwtManager;
 import com.koobietech.eas.common.utils.PasswordManager;
+import com.koobietech.eas.common.utils.StudentArchiveGenerator;
 import com.koobietech.eas.mbg.model.EasArcTlsScores;
 import com.koobietech.eas.mbg.model.EasSysLogs;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -21,27 +22,29 @@ import org.springframework.boot.test.context.SpringBootTest;
 
 import javax.annotation.Resource;
 import java.io.*;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 
 @SpringBootTest
 class ControllerApplicationTests {
 
-//    @Test
-//    void contextLoads() {
-//        try {
-//            ImportParams params = new ImportParams();
-//            List<Map<String, Object>> arc = ExcelImportUtil.importExcel(
-//                    new FileInputStream("C:\\Users\\lc\\Desktop\\1.xlsx"),
-//                    Map.class, params);
-//            for (Map<String, Object> map : arc) {
-//                System.out.println(map);
-//            }
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//    }
 
+    @Test
+    void test() {
+        System.out.println(StudentArchiveGenerator.generateStudentCode(
+                "2211",
+                "232126198703194770", "12016", "2020"
+        ));
+        System.out.println(
+                StudentArchiveGenerator.generateArchiveCode(
+                        "ST2211XE6EE36M202412016",
+                        "20"
+                )
+        );
+    }
 
 
 //        List<Map> list = new ArrayList<>();