Ver código fonte

Merge branch 'wheng' of wuheng/eas-system into master

wuheng 1 ano atrás
pai
commit
fa74ad5f71

+ 91 - 3
common/src/main/java/com/koobietech/eas/common/utils/FileManager.java

@@ -1,7 +1,95 @@
 package com.koobietech.eas.common.utils;
 
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+
+import java.io.*;
+
 public class FileManager {
-//    public boolean saveDocument(XWPFDocument document, String savePath){
-//
-//    }
+    public boolean saveDocument(XWPFDocument document, String savePath){
+        boolean ret = true;
+        FileOutputStream fileOutputStream = null;
+        try {
+            fileOutputStream = new FileOutputStream(savePath);
+            document.write(fileOutputStream);
+        } catch (IOException e) {
+            ret = false;
+        } finally {
+            try {
+                fileOutputStream.close();
+            } catch (IOException e) {}
+        }
+        return ret;
+    }
+
+    public boolean saveDocument(XWPFDocument document, String savePath, String fileName){
+        return saveDocument(document, savePath + fileName);
+    }
+
+    public boolean createPath(String path){
+        File file = new File(path);
+        if (!file.exists()){
+            file.mkdirs();
+        }
+        return true;
+    }
+
+    public boolean saveFile(InputStream stream, String savePath){
+        FileOutputStream fileOutputStream = null;
+        try {
+            fileOutputStream = new FileOutputStream(savePath);
+            int bytesRead;
+            byte[] buffer = new byte[1024];
+            while ((bytesRead = stream.read(buffer)) != -1){
+                fileOutputStream.write(bytesRead);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                fileOutputStream.close();
+            }catch (IOException e){}
+        }
+        return true;
+    }
+
+    public boolean saveFile(InputStream  stream, String savePath, String fileName) {
+        return saveFile(stream, savePath + fileName);
+    }
+
+    public boolean isFileExists(String filePath){
+        File file = new File(filePath);
+        return file.exists();
+    }
+
+    public boolean deleteFile(String filePath){
+        File file = new File(filePath);
+        return file.delete();
+    }
+
+    public boolean isFolderExists(String folderPath){
+        File file = new File(folderPath);
+        return file.exists();
+    }
+
+    public boolean createFolder(String folderPath){
+        File file = new File(folderPath);
+        return file.mkdirs();
+    }
+
+    public boolean deleteFolder(String folderPath){
+        File file = new File(folderPath);
+        return file.delete();
+    }
+
+    public boolean copyFile(String srcFilePath, String destFilePath){
+        File srcFile = new File(srcFilePath);
+        File destFile = new File(destFilePath);
+        return srcFile.renameTo(destFile);
+    }
+
+    public boolean moveFile(String srcFilePath, String destFilePath){
+        File srcFile = new File(srcFilePath);
+        File destFile = new File(destFilePath);
+        return srcFile.renameTo(destFile);
+    }
 }

+ 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);
+    }
+}

+ 4 - 0
controller/pom.xml

@@ -14,6 +14,10 @@
     </parent>
 
     <dependencies>
+        <dependency>
+            <groupId>xerces</groupId>
+            <artifactId>xercesImpl</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.anji-plus</groupId>
             <artifactId>spring-boot-starter-captcha</artifactId>

+ 21 - 4
controller/src/test/java/com/koobietech/eas/controller/ControllerApplicationTests.java

@@ -1,14 +1,19 @@
 package com.koobietech.eas.controller;
 
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
+import cn.afterturn.easypoi.handler.inter.IReadHandler;
 import cn.afterturn.easypoi.handler.inter.IWriter;
 import com.koobietech.eas.common.constant.UserType;
 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;
 import org.junit.jupiter.api.Test;
@@ -17,17 +22,30 @@ 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() throws IOException {
+    void test() {
+        System.out.println(StudentArchiveGenerator.generateStudentCode(
+                "2211",
+                "232126198703194770", "12016", "2020"
+        ));
+        System.out.println(
+                StudentArchiveGenerator.generateArchiveCode(
+                        "ST2211XE6EE36M202412016",
+                        "20"
+                )
+        );
+    }
 
-        InputStream wordStream = this.getClass().getClassLoader().getResourceAsStream("\\temp\\StuRegistTemp.docx");
-        System.out.println( wordStream );
 
 //        List<Map> list = new ArrayList<>();
 //        Workbook workbook = null;
@@ -62,6 +80,5 @@ class ControllerApplicationTests {
 //        fos.close();
 
 
-    }
 
 }

+ 12 - 1
pom.xml

@@ -33,13 +33,24 @@
         <javax.servlet-api.version>4.0.1</javax.servlet-api.version>
         <spring-data-redis.version>2.7.3</spring-data-redis.version>
         <knife4j.version>4.1.0</knife4j.version>
-        <easypoi.version>4.3.0</easypoi.version>
+        <easypoi.version>4.4.0</easypoi.version>
         <pagehelper.starter.version>1.3.1</pagehelper.starter.version>
         <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
         <captcha.version>1.3.0</captcha.version>
+        <xerces.version>2.9.1</xerces.version>
     </properties>
     <dependencyManagement>
         <dependencies>
+            <dependency>
+                <groupId>xerces</groupId>
+                <artifactId>xercesImpl</artifactId>
+                <version>${xerces.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-wps</artifactId>
+                <version>${easypoi.version}</version>
+            </dependency>
             <dependency>
                 <groupId>com.anji-plus</groupId>
                 <artifactId>spring-boot-starter-captcha</artifactId>

+ 7 - 0
upload/src/main/java/com/koobietech/eas/upload/UploadService.java

@@ -1,4 +1,11 @@
 package com.koobietech.eas.upload;
 
 public class UploadService {
+    public boolean uploadFile(){
+        return false;
+    }
+
+    public boolean moveFile(){
+        return false;
+    }
 }