|
@@ -1,8 +1,8 @@
|
|
|
package com.koobietech.eas.service.impl;
|
|
|
|
|
|
import com.koobietech.eas.common.constant.FileType;
|
|
|
+import com.koobietech.eas.common.constant.Gender;
|
|
|
import com.koobietech.eas.common.exception.EasException;
|
|
|
-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;
|
|
@@ -20,8 +20,6 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
|
|
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;
|
|
@@ -36,90 +34,43 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
|
|
|
private static final String TEMPLATE_PATH = "temp/StuRegistTemp.docx";
|
|
|
private static final String PHOTO_PATH = "temp/kun.jpeg";
|
|
|
-
|
|
|
@Resource
|
|
|
private EasArcTlsStudentsMapper easArcTlsStudentsMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private PasswordEncoder passwordEncoder;
|
|
|
-
|
|
|
@Resource
|
|
|
private EasSysStudentMapper easSysStudentMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private EasArcArchivesMapper easArcArchivesMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private EasArchivesFilesService easArchivesFilesService;
|
|
|
|
|
|
@Override
|
|
|
- public boolean StuProfileDownload(EasArcTlsStudents easArcTlsStudents,Integer manager_id) {
|
|
|
+ public boolean StuProfileDownload(EasArcTlsStudents easArcTlsStudents, Integer manager_id) {
|
|
|
+
|
|
|
+ //使用try-with-resources 语句 保证流的关闭
|
|
|
try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
|
|
|
assert wordStream != null;
|
|
|
try (XWPFDocument doc = new XWPFDocument(wordStream)) {
|
|
|
-
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("student_name", easArcTlsStudents.getStudentName());
|
|
|
-
|
|
|
- //调用内部类方法 把MF转换成 男女
|
|
|
- map.put("gender", convertToGender(easArcTlsStudents.getGender()));
|
|
|
-
|
|
|
- map.put("major", easArcTlsStudents.getMajor());
|
|
|
- map.put("grade", easArcTlsStudents.getGrade());
|
|
|
-
|
|
|
- //调用自定义的时间格式转换器 把前端传过来的带时分秒时间转换成 2019年12月12日
|
|
|
- map.put("enrollment_date", DateUtils.convertToYearMonthDay(easArcTlsStudents.getEnrollmentDate()));
|
|
|
-
|
|
|
- map.put("phone", easArcTlsStudents.getPhone());
|
|
|
- map.put("university", easArcTlsStudents.getUniversity());
|
|
|
- map.put("student_idnumber", easArcTlsStudents.getStudentIdnumber());
|
|
|
- map.put("avatar", getClass().getClassLoader().getResourceAsStream(PHOTO_PATH));
|
|
|
-
|
|
|
//调用内部类方法 生成学号
|
|
|
String studentNumber = generateStudentNumber(easArcTlsStudents);
|
|
|
- map.put("student_number", studentNumber);
|
|
|
|
|
|
+ Map<String, Object> map = generateDataMap(easArcTlsStudents, studentNumber);
|
|
|
replacePlaceholders(doc, map);
|
|
|
-
|
|
|
//将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);
|
|
|
-
|
|
|
- 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();
|
|
|
- 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);
|
|
|
+ boolean isTlsStudentsInsert = insertEasArcTlsStudents(easArcTlsStudents);
|
|
|
+ if (!isTlsStudentsInsert) {
|
|
|
+ throw new EasException("EasArcTlsStudents保存失败", 8000);
|
|
|
+ }
|
|
|
+ boolean isSysStudentsInsert = insertEasSysStudents(easArcTlsStudents);
|
|
|
+ if (!isSysStudentsInsert) {
|
|
|
+ throw new EasException("EasSysStudents保存失败", 8001);
|
|
|
+ }
|
|
|
+ //这里会生成一个学生档案保存本地 目前这里有bug保存不成功 而且文件后缀有错误
|
|
|
+ boolean isEasArcArchives = insertEasArcArchives(easArcTlsStudents, studentNumber, manager_id, doc);
|
|
|
+ if (!isEasArcArchives) {
|
|
|
+ throw new EasException("EasArcArchives保存失败", 8002);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
return false;
|
|
@@ -127,6 +78,75 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("student_name", easArcTlsStudents.getStudentName());
|
|
|
+ map.put("gender", convertToGender(easArcTlsStudents.getGender()));
|
|
|
+ map.put("major", easArcTlsStudents.getMajor());
|
|
|
+ map.put("grade", easArcTlsStudents.getGrade());
|
|
|
+ map.put("enrollment_date", DateUtils.convertToYearMonthDay(easArcTlsStudents.getEnrollmentDate()));
|
|
|
+ map.put("phone", easArcTlsStudents.getPhone());
|
|
|
+ map.put("university", easArcTlsStudents.getUniversity());
|
|
|
+ map.put("student_idnumber", easArcTlsStudents.getStudentIdnumber());
|
|
|
+ map.put("avatar", getClass().getClassLoader().getResourceAsStream(PHOTO_PATH));
|
|
|
+ map.put("student_number", studentNumber);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean insertEasArcArchives(EasArcTlsStudents easArcTlsStudents, String studentNumber, Integer managerId, XWPFDocument doc) {
|
|
|
+ // 生成档案号
|
|
|
+ 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 createTime = DateUtils.convertToYearMonthDayToDate(new Date());
|
|
|
+ Date modifyTime = new Date();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ assert createTime != null;
|
|
|
+ calendar.setTime(createTime);
|
|
|
+ calendar.add(Calendar.YEAR, 1);
|
|
|
+ Date validityTime = calendar.getTime();
|
|
|
+
|
|
|
+ // 创建 EasArcArchives 对象并设置属性
|
|
|
+ EasArcArchives easArcArchives = new EasArcArchives();
|
|
|
+ easArcArchives.setArchiveNumber(archiveCode);
|
|
|
+ easArcArchives.setStudentNumber(studentNumber);
|
|
|
+ easArcArchives.setFilePath(filePath);
|
|
|
+ easArcArchives.setArctype(arcType);
|
|
|
+ easArcArchives.setCreateTime(createTime);
|
|
|
+ easArcArchives.setModifyTime(modifyTime);
|
|
|
+ easArcArchives.setValidityTime(validityTime);
|
|
|
+ easArcArchives.setManagerId(managerId);
|
|
|
+ easArcArchives.setCreateUid(1);
|
|
|
+ easArcArchives.setCreateDate(new Date());
|
|
|
+
|
|
|
+ // 插入到数据库
|
|
|
+ int result = easArcArchivesMapper.insert(easArcArchives);
|
|
|
+
|
|
|
+ // 返回是否成功插入数据库
|
|
|
+ return result > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean insertEasSysStudents(EasArcTlsStudents easArcTlsStudents) {
|
|
|
+ EasSysStudent easSysStudents = new EasSysStudent();
|
|
|
+ BeanUtils.copyProperties(easArcTlsStudents, easSysStudents);
|
|
|
+ //设置初始密码 使用 passwordEncoder 设置初始密码为123456
|
|
|
+ easSysStudents.setPasswd(passwordEncoder.encode("123456"));
|
|
|
+ easSysStudents.setDisabled("N");
|
|
|
+ easSysStudents.setAvatar("占位图片.jpg");
|
|
|
+ return easSysStudentMapper.insert(easSysStudents) == 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean insertEasArcTlsStudents(EasArcTlsStudents easArcTlsStudents) {
|
|
|
+ //判断是否插入成功 成功的话返回true 不成功的话返回false
|
|
|
+ return easArcTlsStudentsMapper.insert(easArcTlsStudents) == 1;
|
|
|
+ }
|
|
|
+
|
|
|
private String generateStudentNumber(EasArcTlsStudents easArcTlsStudents) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(easArcTlsStudents.getEnrollmentDate());
|
|
@@ -137,13 +157,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
}
|
|
|
|
|
|
private String convertToGender(String gender) {
|
|
|
- if (gender.equals("M")) {
|
|
|
- return "男";
|
|
|
- } else if (gender.equals("F")) {
|
|
|
- return "女";
|
|
|
- } else {
|
|
|
- return "未知";
|
|
|
- }
|
|
|
+ return Gender.getkeyByString(gender);
|
|
|
}
|
|
|
|
|
|
private void replacePlaceholders(XWPFDocument document, Map<String, Object> map) {
|
|
@@ -168,6 +182,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
}
|
|
|
} catch (IOException | InvalidFormatException e) {
|
|
|
throw new EasException("学员导入失败");
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
});
|