Forráskód Böngészése

档案进三个数据库,但是代码是屎山,等待优化中

superb 1 éve
szülő
commit
a7ac0cdbb4

+ 9 - 1
common/src/main/java/com/koobietech/eas/common/utils/DateUtils.java

@@ -1,12 +1,20 @@
 package com.koobietech.eas.common.utils;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.Locale;
 
 public class DateUtils {
     public static String convertToYearMonthDay(Date date) {
         SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
         return outputFormat.format(date);
     }
+
+    public static Date convertToYearMonthDayToDate(Date date) {
+        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
+        try {
+            return outputFormat.parse(outputFormat.format(date));
+        } catch (ParseException e) {}
+        return null;
+    }
 }

+ 3 - 6
controller/src/main/java/com/koobietech/eas/controller/EasStuProfileController.java

@@ -4,10 +4,7 @@ package com.koobietech.eas.controller;
 import com.koobietech.eas.common.result.JsonResult;
 import com.koobietech.eas.mbg.model.EasArcTlsStudents;
 import com.koobietech.eas.service.EasStuProfileService;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.io.FileNotFoundException;
@@ -19,9 +16,9 @@ public class EasStuProfileController {
     private EasStuProfileService easStuProfileService;
 
     @PostMapping("/StuProfileDownload")
-    public JsonResult StuProfileDownload(@RequestBody  EasArcTlsStudents easArcTlsStudents) throws FileNotFoundException {
+    public JsonResult StuProfileDownload(@RequestBody  EasArcTlsStudents easArcTlsStudents,@RequestParam Integer manager_id) throws FileNotFoundException {
 
-        return easStuProfileService.StuProfileDownload(easArcTlsStudents);
+        return easStuProfileService.StuProfileDownload(easArcTlsStudents,manager_id);
     }
 
 

+ 4 - 1
dao/src/main/java/com/koobietech/eas/dao/dto/ArchivesDto.java

@@ -8,9 +8,12 @@ public class ArchivesDto {
     private String path;
     private boolean status;
 
-    public ArchivesDto(String path, boolean status, String archiveCode) {
+    private String fileType;
+
+    public ArchivesDto(String path, boolean status, String archiveCode, String fileType) {
         this.archiveCode = archiveCode;
         this.path = path;
         this.status = status;
+        this.fileType = fileType;
     }
 }

+ 8 - 8
mbg/src/main/java/com/koobietech/eas/mbg/model/EasArcArchives.java

@@ -33,12 +33,12 @@ public class EasArcArchives implements Serializable {
     private String filePath;
 
     /**
-     * 文件类型Id
+     * 文件类型
      *
      * @mbg.generated
      */
-    @Schema(description = "文件类型Id")
-    private Integer arctypeId;
+    @Schema(description = "文件类型")
+    private String arctype;
 
     /**
      * 创建时间
@@ -126,12 +126,12 @@ public class EasArcArchives implements Serializable {
         this.filePath = filePath == null ? null : filePath.trim();
     }
 
-    public Integer getArctypeId() {
-        return arctypeId;
+    public String getArctype() {
+        return arctype;
     }
 
-    public void setArctypeId(Integer arctypeId) {
-        this.arctypeId = arctypeId;
+    public void setArctype(String arctype) {
+        this.arctype = arctype == null ? null : arctype.trim();
     }
 
     public Date getCreateTime() {
@@ -192,7 +192,7 @@ public class EasArcArchives implements Serializable {
         sb.append(", archiveNumber=").append(archiveNumber);
         sb.append(", studentNumber=").append(studentNumber);
         sb.append(", filePath=").append(filePath);
-        sb.append(", arctypeId=").append(arctypeId);
+        sb.append(", arctype=").append(arctype);
         sb.append(", createTime=").append(createTime);
         sb.append(", modifyTime=").append(modifyTime);
         sb.append(", validityTime=").append(validityTime);

+ 34 - 24
mbg/src/main/java/com/koobietech/eas/mbg/model/EasArcArchivesExample.java

@@ -402,63 +402,73 @@ public class EasArcArchivesExample {
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdIsNull() {
-            addCriterion("arctype_id is null");
+        public Criteria andArctypeIsNull() {
+            addCriterion("arctype is null");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdIsNotNull() {
-            addCriterion("arctype_id is not null");
+        public Criteria andArctypeIsNotNull() {
+            addCriterion("arctype is not null");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdEqualTo(Integer value) {
-            addCriterion("arctype_id =", value, "arctypeId");
+        public Criteria andArctypeEqualTo(String value) {
+            addCriterion("arctype =", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdNotEqualTo(Integer value) {
-            addCriterion("arctype_id <>", value, "arctypeId");
+        public Criteria andArctypeNotEqualTo(String value) {
+            addCriterion("arctype <>", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdGreaterThan(Integer value) {
-            addCriterion("arctype_id >", value, "arctypeId");
+        public Criteria andArctypeGreaterThan(String value) {
+            addCriterion("arctype >", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdGreaterThanOrEqualTo(Integer value) {
-            addCriterion("arctype_id >=", value, "arctypeId");
+        public Criteria andArctypeGreaterThanOrEqualTo(String value) {
+            addCriterion("arctype >=", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdLessThan(Integer value) {
-            addCriterion("arctype_id <", value, "arctypeId");
+        public Criteria andArctypeLessThan(String value) {
+            addCriterion("arctype <", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdLessThanOrEqualTo(Integer value) {
-            addCriterion("arctype_id <=", value, "arctypeId");
+        public Criteria andArctypeLessThanOrEqualTo(String value) {
+            addCriterion("arctype <=", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdIn(List<Integer> values) {
-            addCriterion("arctype_id in", values, "arctypeId");
+        public Criteria andArctypeLike(String value) {
+            addCriterion("arctype like", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdNotIn(List<Integer> values) {
-            addCriterion("arctype_id not in", values, "arctypeId");
+        public Criteria andArctypeNotLike(String value) {
+            addCriterion("arctype not like", value, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdBetween(Integer value1, Integer value2) {
-            addCriterion("arctype_id between", value1, value2, "arctypeId");
+        public Criteria andArctypeIn(List<String> values) {
+            addCriterion("arctype in", values, "arctype");
             return (Criteria) this;
         }
 
-        public Criteria andArctypeIdNotBetween(Integer value1, Integer value2) {
-            addCriterion("arctype_id not between", value1, value2, "arctypeId");
+        public Criteria andArctypeNotIn(List<String> values) {
+            addCriterion("arctype not in", values, "arctype");
+            return (Criteria) this;
+        }
+
+        public Criteria andArctypeBetween(String value1, String value2) {
+            addCriterion("arctype between", value1, value2, "arctype");
+            return (Criteria) this;
+        }
+
+        public Criteria andArctypeNotBetween(String value1, String value2) {
+            addCriterion("arctype not between", value1, value2, "arctype");
             return (Criteria) this;
         }
 

+ 14 - 14
mbg/src/main/resources/com/koobietech/eas/mbg/mapper/EasArcArchivesMapper.xml

@@ -6,7 +6,7 @@
     <result column="archive_number" jdbcType="VARCHAR" property="archiveNumber" />
     <result column="student_number" jdbcType="VARCHAR" property="studentNumber" />
     <result column="file_path" jdbcType="VARCHAR" property="filePath" />
-    <result column="arctype_id" jdbcType="INTEGER" property="arctypeId" />
+    <result column="arctype" jdbcType="VARCHAR" property="arctype" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
     <result column="validity_time" jdbcType="TIMESTAMP" property="validityTime" />
@@ -73,7 +73,7 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, archive_number, student_number, file_path, arctype_id, create_time, modify_time, 
+    id, archive_number, student_number, file_path, arctype, create_time, modify_time, 
     validity_time, manager_id, create_date, create_uid
   </sql>
   <select id="selectByExample" parameterType="com.koobietech.eas.mbg.model.EasArcArchivesExample" resultMap="BaseResultMap">
@@ -111,11 +111,11 @@
       SELECT LAST_INSERT_ID()
     </selectKey>
     insert into eas_arc_archives (archive_number, student_number, file_path, 
-      arctype_id, create_time, modify_time, 
+      arctype, create_time, modify_time, 
       validity_time, manager_id, create_date, 
       create_uid)
     values (#{archiveNumber,jdbcType=VARCHAR}, #{studentNumber,jdbcType=VARCHAR}, #{filePath,jdbcType=VARCHAR}, 
-      #{arctypeId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP}, 
+      #{arctype,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP}, 
       #{validityTime,jdbcType=TIMESTAMP}, #{managerId,jdbcType=INTEGER}, #{createDate,jdbcType=DATE}, 
       #{createUid,jdbcType=INTEGER})
   </insert>
@@ -134,8 +134,8 @@
       <if test="filePath != null">
         file_path,
       </if>
-      <if test="arctypeId != null">
-        arctype_id,
+      <if test="arctype != null">
+        arctype,
       </if>
       <if test="createTime != null">
         create_time,
@@ -166,8 +166,8 @@
       <if test="filePath != null">
         #{filePath,jdbcType=VARCHAR},
       </if>
-      <if test="arctypeId != null">
-        #{arctypeId,jdbcType=INTEGER},
+      <if test="arctype != null">
+        #{arctype,jdbcType=VARCHAR},
       </if>
       <if test="createTime != null">
         #{createTime,jdbcType=TIMESTAMP},
@@ -210,8 +210,8 @@
       <if test="record.filePath != null">
         file_path = #{record.filePath,jdbcType=VARCHAR},
       </if>
-      <if test="record.arctypeId != null">
-        arctype_id = #{record.arctypeId,jdbcType=INTEGER},
+      <if test="record.arctype != null">
+        arctype = #{record.arctype,jdbcType=VARCHAR},
       </if>
       <if test="record.createTime != null">
         create_time = #{record.createTime,jdbcType=TIMESTAMP},
@@ -242,7 +242,7 @@
       archive_number = #{record.archiveNumber,jdbcType=VARCHAR},
       student_number = #{record.studentNumber,jdbcType=VARCHAR},
       file_path = #{record.filePath,jdbcType=VARCHAR},
-      arctype_id = #{record.arctypeId,jdbcType=INTEGER},
+      arctype = #{record.arctype,jdbcType=VARCHAR},
       create_time = #{record.createTime,jdbcType=TIMESTAMP},
       modify_time = #{record.modifyTime,jdbcType=TIMESTAMP},
       validity_time = #{record.validityTime,jdbcType=TIMESTAMP},
@@ -265,8 +265,8 @@
       <if test="filePath != null">
         file_path = #{filePath,jdbcType=VARCHAR},
       </if>
-      <if test="arctypeId != null">
-        arctype_id = #{arctypeId,jdbcType=INTEGER},
+      <if test="arctype != null">
+        arctype = #{arctype,jdbcType=VARCHAR},
       </if>
       <if test="createTime != null">
         create_time = #{createTime,jdbcType=TIMESTAMP},
@@ -294,7 +294,7 @@
     set archive_number = #{archiveNumber,jdbcType=VARCHAR},
       student_number = #{studentNumber,jdbcType=VARCHAR},
       file_path = #{filePath,jdbcType=VARCHAR},
-      arctype_id = #{arctypeId,jdbcType=INTEGER},
+      arctype = #{arctype,jdbcType=VARCHAR},
       create_time = #{createTime,jdbcType=TIMESTAMP},
       modify_time = #{modifyTime,jdbcType=TIMESTAMP},
       validity_time = #{validityTime,jdbcType=TIMESTAMP},

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

@@ -6,5 +6,5 @@ import com.koobietech.eas.mbg.model.EasArcTlsStudents;
 import java.io.FileNotFoundException;
 
 public interface EasStuProfileService {
-    JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents) throws FileNotFoundException;
+    JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents,Integer manager_id) throws FileNotFoundException;
 }

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

@@ -40,12 +40,13 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
             fileManager.moveFile( path,  path + (new Date()).getTime() + ".back", true );
         }
         boolean status = fileManager.saveDocument(document, path);
-        return new ArchivesDto(path, status, archiveCode);
+        return new ArchivesDto(path, status, archiveCode, FileType.XLSX.getValue());
     }
 
     private String getArchivePath(String studentNumber, String archiveCode) {
-        return archivesSavePath + separator + studentNumber
-                + separator + archiveCode + FileTypeExt.XLSX.getValue();
+        String path = archivesSavePath + separator + studentNumber;
+        fileManager.createPath(path);
+        return path + separator + archiveCode + FileTypeExt.DOCX.getValue();
     }
 
     @Override
@@ -58,7 +59,7 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
         String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.DOCX.getValue());
         String path = getArchivePath(studentNumber, archiveCode);
         boolean status = fileManager.saveDocument(document, path);
-        return new ArchivesDto(path, status, archiveCode);
+        return new ArchivesDto(path, status, archiveCode, FileType.DOCX.getValue());
     }
 
     @Override

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

@@ -1,9 +1,17 @@
 package com.koobietech.eas.service.impl;
 
+import com.koobietech.eas.common.constant.FileType;
 import com.koobietech.eas.common.result.JsonResult;
 import com.koobietech.eas.common.utils.DateUtils;
 import com.koobietech.eas.common.utils.StudentArchiveGenerator;
+import com.koobietech.eas.dao.dto.ArchivesDto;
+import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
+import com.koobietech.eas.mbg.mapper.EasArcTlsStudentsMapper;
+import com.koobietech.eas.mbg.mapper.EasSysStudentMapper;
+import com.koobietech.eas.mbg.model.EasArcArchives;
 import com.koobietech.eas.mbg.model.EasArcTlsStudents;
+import com.koobietech.eas.mbg.model.EasSysStudent;
+import com.koobietech.eas.service.EasArchivesFilesService;
 import com.koobietech.eas.service.EasStuProfileService;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.util.Units;
@@ -13,9 +21,11 @@ import org.apache.poi.xwpf.usermodel.XWPFTableCell;
 import org.apache.poi.xwpf.usermodel.XWPFTableRow;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 
-import java.io.FileOutputStream;
+import javax.annotation.Resource;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
@@ -26,10 +36,24 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
     private static final Logger LOGGER = LoggerFactory.getLogger(EasStuProfileServiceImpl.class);
     private static final String TEMPLATE_PATH = "temp/StuRegistTemp.docx";
     private static final String PHOTO_PATH = "temp/kun.jpeg";
-    private static final String OUTPUT_PATH = "D:\\myDesk\\test.docx";
+
+    @Resource
+    private EasArcTlsStudentsMapper easArcTlsStudentsMapper;
+
+    @Resource
+    private PasswordEncoder passwordEncoder;
+
+    @Resource
+    private EasSysStudentMapper easSysStudentMapper;
+
+    @Resource
+    private EasArcArchivesMapper easArcArchivesMapper;
+
+    @Resource
+    private EasArchivesFilesService easArchivesFilesService;
 
     @Override
-    public JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents) {
+    public JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents,Integer manager_id) {
         LOGGER.info("开始学员档案导出:{}", easArcTlsStudents);
 
         try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
@@ -54,10 +78,72 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
                 map.put("avatar", getClass().getClassLoader().getResourceAsStream(PHOTO_PATH));
 
                 //调用内部类方法 生成学号
-                map.put("student_number", generateStudentNumber(easArcTlsStudents));
+                String studentNumber = generateStudentNumber(easArcTlsStudents);
+                map.put("student_number", studentNumber);
 
                 replacePlaceholders(doc, map);
-                saveDocument(doc);
+                //saveDocument(doc);
+
+                //将easArcTlsStudents 保存到数据库
+                easArcTlsStudentsMapper.insert(easArcTlsStudents);
+
+                //使用BeanUtils 将easArcTlsStudents 转换成 eassysstudent
+                EasSysStudent easSysStudents = new EasSysStudent();
+                BeanUtils.copyProperties(easArcTlsStudents,easSysStudents);
+                //设置初始密码 使用 passwordEncoder 设置初始密码为123456
+                easSysStudents.setPasswd(passwordEncoder.encode("123456"));
+                easSysStudents.setDisabled("N");
+
+                easSysStudentMapper.insert(easSysStudents);
+
+                //组合成档案对象 保存到数据库
+                /**
+                 CREATE TABLE `eas_arc_archives` (
+            1     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+            1     `archive_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '文件电子档案号',
+            1     `student_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '当前电子档案归属那一个学员档案下',
+            1     `file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '文件存储的路径',
+            1     `arctype` int(11) DEFAULT NULL COMMENT '文件类型Id',
+            1     `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+            1     `modify_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+            1     `validity_time` datetime DEFAULT NULL COMMENT '档案有效期截至时间',
+            1     `manager_id` int(11) DEFAULT NULL COMMENT '档案归属负责人',
+            ?     `create_date` date DEFAULT NULL COMMENT '档案创建时间, 用于文件归档用',
+            ?     `create_uid` int(11) DEFAULT NULL COMMENT '创建用户ID',
+                 PRIMARY KEY (`id`) USING BTREE
+                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='文件档案表';
+                 */
+                String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, String.valueOf(FileType.DOCX));
+                ArchivesDto archivesDto = easArchivesFilesService.saveArchiveStudentsFile(easArcTlsStudents.getStudentIdnumber(), doc);
+                String filePath = archivesDto.getPath();
+                String arctype = archivesDto.getFileType();
+                Date creat_time = DateUtils.convertToYearMonthDayToDate(new Date());
+                Date modify_time = new Date();
+
+                //validity_time 暂且设置成create_date + 1年
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTime(creat_time);
+                calendar.add(Calendar.YEAR, 1);
+                Date create_date = calendar.getTime();
+
+                int create_uid = 0;
+
+                EasArcArchives easArcArchives = new EasArcArchives();
+                easArcArchives.setArchiveNumber(archiveCode);
+                easArcArchives.setStudentNumber(studentNumber);
+                easArcArchives.setFilePath(filePath);
+                easArcArchives.setArctype(arctype);
+                easArcArchives.setCreateTime(creat_time);
+                easArcArchives.setModifyTime(modify_time);
+                easArcArchives.setValidityTime(create_date);
+                easArcArchives.setManagerId(manager_id);
+                easArcArchives.setCreateUid(create_uid);
+                easArcArchives.setCreateDate(new Date());
+
+                easArcArchivesMapper.insert(easArcArchives);
+
+
+
             }
         } catch (IOException e) {
             LOGGER.error("学员档案导出失败:{}", e.getMessage(), e);
@@ -116,12 +202,6 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
             }
         }
     }
-
-    private void saveDocument(XWPFDocument document) throws IOException {
-        try (FileOutputStream outputStream = new FileOutputStream(OUTPUT_PATH)) {
-            document.write(outputStream);
-        }
-    }
 }