|
@@ -9,6 +9,7 @@ import com.koobietech.eas.common.exception.EasException;
|
|
|
import com.koobietech.eas.common.result.PageDataResult;
|
|
|
import com.koobietech.eas.common.utils.ArchiveManager;
|
|
|
import com.koobietech.eas.common.utils.DateManager;
|
|
|
+import com.koobietech.eas.common.utils.FileManager;
|
|
|
import com.koobietech.eas.common.utils.SecurityManager;
|
|
|
import com.koobietech.eas.dao.dto.ArchivesDto;
|
|
|
import com.koobietech.eas.dao.dto.EasArcTlsStudentsDto;
|
|
@@ -19,6 +20,7 @@ import com.koobietech.eas.mbg.model.*;
|
|
|
import com.koobietech.eas.service.EasArchiveFileDownloadService;
|
|
|
import com.koobietech.eas.service.EasArchivesFilesService;
|
|
|
import com.koobietech.eas.service.EasStuProfileService;
|
|
|
+import com.koobietech.eas.service.EasSysUserInfoService;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.util.Units;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
@@ -34,6 +36,8 @@ import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.time.LocalDate;
|
|
@@ -50,7 +54,7 @@ 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 PHOTO_PATH = "temp/avatar.jpeg";
|
|
|
@Resource
|
|
|
private EasArcTlsStudentsMapper easArcTlsStudentsMapper;
|
|
|
@Resource
|
|
@@ -63,12 +67,29 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
private EasArchivesFilesService easArchivesFilesService;
|
|
|
@Resource
|
|
|
private EasArchiveFileDownloadService easArchiveFileDownloadService;
|
|
|
+ @Resource
|
|
|
+ private EasSysUserInfoService easSysUserInfoService;
|
|
|
|
|
|
final String FILETYPE = "prefile";
|
|
|
|
|
|
@Override
|
|
|
- public ArchivesDto saveUserFile(EasArcTlsStudents easArcTlsStudents){
|
|
|
- ArchivesDto archivesDto = null;
|
|
|
+ public ArchivesDto saveUserFile(EasArcTlsStudents easArcTlsStudents, String avatar){
|
|
|
+
|
|
|
+ if ( Objects.isNull(easArcTlsStudents.getEnrollmentDate()) ) {
|
|
|
+ easArcTlsStudents.setEnrollmentDate(new Date());
|
|
|
+ }
|
|
|
+ if ( Objects.isNull(easArcTlsStudents.getGraduationDate()) ) {
|
|
|
+ easArcTlsStudents.setGraduationDate(new Date(LocalDate.now().plusYears(2)
|
|
|
+ .atStartOfDay().toInstant(ZoneOffset.of("+8")).toEpochMilli()));
|
|
|
+ }
|
|
|
+ if ( Objects.isNull(easArcTlsStudents.getBirthdate()) ) {
|
|
|
+ easArcTlsStudents.setBirthdate(
|
|
|
+ new Date(ArchiveManager.extractBirthDate(
|
|
|
+ easArcTlsStudents.getStudentIdnumber()
|
|
|
+ ).atStartOfDay()
|
|
|
+ .toInstant(ZoneOffset.of("+8")).toEpochMilli()) );
|
|
|
+ }
|
|
|
+ ArchivesDto archivesDto;
|
|
|
try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
|
|
|
assert wordStream != null;
|
|
|
try (XWPFDocument doc = new XWPFDocument(wordStream)) {
|
|
@@ -81,7 +102,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
studentNumber = easArcTlsStudents.getStudentNumber();
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> map = generateDataMap(easArcTlsStudents, studentNumber);
|
|
|
+ Map<String, Object> map = generateDataMap(easArcTlsStudents, studentNumber, avatar);
|
|
|
replacePlaceholders(doc, map);
|
|
|
//这里会生成一个学生档案保存本地 目前这里有bug保存不成功 而且文件后缀有错误
|
|
|
archivesDto = insertEasArcArchives(easArcTlsStudents, doc);
|
|
@@ -114,7 +135,23 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
catch (IllegalArgumentException e) {
|
|
|
type = FileType.FILE.toString();
|
|
|
}
|
|
|
- archivesDto = easArchivesFilesService.saveArchiveFile(studentNumber, inputStream, type);
|
|
|
+ archivesDto = easArchivesFilesService.saveArchiveFileTemp(studentNumber, inputStream, type);
|
|
|
+ if (archivesDto.isStatus()) {
|
|
|
+ if ( fileType.equals("avatar") ) {
|
|
|
+ EasSysStudentExample easSysStudentExample = new EasSysStudentExample();
|
|
|
+ easSysStudentExample.createCriteria().andStudentNumberEqualTo(studentNumber);
|
|
|
+ EasSysStudent easSysStudent = new EasSysStudent();
|
|
|
+ easSysStudent.setAvatar(archivesDto.getPath());
|
|
|
+ easSysStudentMapper.updateByExampleSelective(easSysStudent, easSysStudentExample);
|
|
|
+ }
|
|
|
+ EasArcTlsStudentsExample easArcTlsStudentsExample = new EasArcTlsStudentsExample();
|
|
|
+ easArcTlsStudentsExample.createCriteria().andStudentNumberEqualTo(studentNumber);
|
|
|
+ List<EasArcTlsStudents> easArcTlsStudents = easArcTlsStudentsMapper.selectByExample(easArcTlsStudentsExample);
|
|
|
+ EasArcTlsStudents arcStudent = easArcTlsStudents.stream().findFirst().orElse(null);
|
|
|
+ if ( Objects.nonNull(arcStudent) ) {
|
|
|
+ saveUserFile(arcStudent, archivesDto.getPath() );
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (IOException ignore) {
|
|
|
} finally {
|
|
|
if (inputStream != null) {
|
|
@@ -141,21 +178,38 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
}
|
|
|
@Override
|
|
|
public boolean addArchives(EasArcArchives arc) {
|
|
|
- String arctype = "";
|
|
|
+
|
|
|
+ FileManager fileManager = new FileManager();
|
|
|
+
|
|
|
+ if ( Objects.isNull(arc) || Objects.isNull(arc.getFilePath()) ||
|
|
|
+ !StringUtils.hasText(arc.getFilePath()) || !fileManager.isFileExists(arc.getFilePath()) ) {
|
|
|
+ throw new EasException("档案不能为空");
|
|
|
+ }
|
|
|
+ String fileType = arc.getFilePath().substring(arc.getFilePath().lastIndexOf(".") + 1).toUpperCase();
|
|
|
+ String arctype = fileType;
|
|
|
if ( isImage(arc.getFilePath()) ) {
|
|
|
arctype = "IMAGE";
|
|
|
- } else {
|
|
|
- arctype = arc.getFilePath().substring(arc.getFilePath().lastIndexOf(".") + 1).toUpperCase();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //如果抛异常 则类型不识别
|
|
|
+ FileType.valueOf(fileType);
|
|
|
+ }catch (IllegalArgumentException e) {
|
|
|
+ arctype = FileType.FILE.toString();
|
|
|
}
|
|
|
String archiveNumber = arc.getFilePath().substring(
|
|
|
arc.getFilePath().lastIndexOf("\\") + 1,
|
|
|
arc.getFilePath().lastIndexOf("."));
|
|
|
+
|
|
|
+ String archiveSavePath = easArchivesFilesService.getArchiveSavePath(arc.getStudentNumber(), archiveNumber, fileType);
|
|
|
+ fileManager.moveFile( arc.getFilePath(), archiveSavePath, true );
|
|
|
+
|
|
|
+ arc.setFilePath( archiveSavePath );
|
|
|
arc.setArctype(arctype);
|
|
|
arc.setCreateTime(new Date());
|
|
|
arc.setModifyTime(new Date());
|
|
|
arc.setArchiveNumber( archiveNumber );
|
|
|
arc.setValidityTime( new Date(LocalDate.now().plusMonths(20)
|
|
|
- .atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()) );
|
|
|
+ .atStartOfDay().toInstant(ZoneOffset.of("+8")).toEpochMilli()) );
|
|
|
arc.setManagerId( SecurityManager.getLoginUid().intValue() );
|
|
|
arc.setCreateUid( SecurityManager.getLoginUid().intValue() );
|
|
|
arc.setCreateDate(new Date());
|
|
@@ -194,7 +248,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
@Override
|
|
|
public boolean add(EasArcTlsStudents easArcTlsStudents) {
|
|
|
|
|
|
- ArchivesDto archivesDto = saveUserFile(easArcTlsStudents);
|
|
|
+ ArchivesDto archivesDto = saveUserFile(easArcTlsStudents, PHOTO_PATH);
|
|
|
|
|
|
//将easArcTlsStudents 保存到数据库
|
|
|
easArcTlsStudents.setArchiveNumber(archivesDto.getArchiveCode());
|
|
@@ -206,7 +260,6 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
if (!isSysStudentsInsert) {
|
|
|
throw new EasException("EasSysStudents保存失败", 8001);
|
|
|
}
|
|
|
-
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -251,12 +304,29 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
|
|
|
@Override
|
|
|
public boolean update(EasArcTlsStudents studentDto) {
|
|
|
- return easArcTlsStudentsMapper.updateByPrimaryKey(studentDto) == 1;
|
|
|
+ EasSysStudent easSysStudent = new EasSysStudent();
|
|
|
+ if ( studentDto.getGraduation().equals("Y") ) {
|
|
|
+ easSysStudent.setDisabled("Y");
|
|
|
+ } else {
|
|
|
+ easSysStudent.setDisabled("N");
|
|
|
+ }
|
|
|
+ EasSysStudentExample easSysStudentExample = new EasSysStudentExample();
|
|
|
+ easSysStudentExample.createCriteria().andStudentNumberEqualTo(studentDto.getStudentNumber());
|
|
|
+ easSysStudentMapper.updateByExampleSelective(easSysStudent, easSysStudentExample);
|
|
|
+ return easArcTlsStudentsMapper.updateByPrimaryKeySelective (studentDto) == 1;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean delete(int id) {
|
|
|
- return easArcTlsStudentsMapper.deleteByPrimaryKey(id) == 1;
|
|
|
+ EasArcTlsStudents easArcTlsStudents = easArcTlsStudentsMapper.selectByPrimaryKey(id);
|
|
|
+ if ( Objects.nonNull(easArcTlsStudents) ) {
|
|
|
+ EasSysStudentExample easSysStudentExample = new EasSysStudentExample();
|
|
|
+ easSysStudentExample.createCriteria().andStudentNumberEqualTo( easArcTlsStudents.getStudentNumber() );
|
|
|
+ int i = easSysStudentMapper.deleteByExample(easSysStudentExample);
|
|
|
+ int i1 = easArcTlsStudentsMapper.deleteByPrimaryKey(id);
|
|
|
+ return i == 1 && i1 == 1;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -290,7 +360,21 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
|
|
|
@Override
|
|
|
public List<EasSysStudent> getAll() {
|
|
|
- return easSysStudentMapper.selectByExample(null);
|
|
|
+ EasSysStudentExample easSysStudentExample = new EasSysStudentExample();
|
|
|
+ EasSysStudentExample.Criteria criteria = easSysStudentExample.createCriteria();
|
|
|
+ criteria.andDisabledEqualTo("N");
|
|
|
+ return easSysStudentMapper.selectByExample(easSysStudentExample);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EasSysStudent> getAllOrStudentNumber(String studentNumber){
|
|
|
+ EasSysStudentExample easSysStudentExample = new EasSysStudentExample();
|
|
|
+ EasSysStudentExample.Criteria criteria = easSysStudentExample.createCriteria();
|
|
|
+ criteria.andDisabledEqualTo("N");
|
|
|
+ if ( Objects.nonNull(studentNumber) ) {
|
|
|
+ criteria.andStudentNumberEqualTo(studentNumber);
|
|
|
+ }
|
|
|
+ return easSysStudentMapper.selectByExample(easSysStudentExample);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -321,18 +405,23 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
return matcher.matches();
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber) {
|
|
|
+ private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber, String avatar) {
|
|
|
+ EasSysUserinfo easSysUserinfo = null;
|
|
|
+ if ( Objects.nonNull(easArcTlsStudents.getAdmissionsId()) ) {
|
|
|
+ easSysUserinfo = easSysUserInfoService.queryByUid(easArcTlsStudents.getAdmissionsId().longValue());
|
|
|
+ }
|
|
|
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", DateManager.convertToYearMonthDay(easArcTlsStudents.getEnrollmentDate()));
|
|
|
+ map.put("graduation_date", DateManager.convertToYearMonthDay(easArcTlsStudents.getGraduationDate()));
|
|
|
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("avatar", avatar);
|
|
|
map.put("student_number", studentNumber);
|
|
|
+ map.put("birthdate", DateManager.convertToYearMonthDay(easArcTlsStudents.getBirthdate()));
|
|
|
+ map.put("admissionsd", ( Objects.nonNull(easSysUserinfo) && Objects.nonNull(easSysUserinfo.getRelname()) ) ? easSysUserinfo.getRelname() : "");
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -403,6 +492,9 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
|
|
|
private String generateStudentNumber(EasArcTlsStudents easArcTlsStudents) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
+ if ( Objects.isNull(easArcTlsStudents.getEnrollmentDate()) ) {
|
|
|
+ easArcTlsStudents.setEnrollmentDate(new Date());
|
|
|
+ }
|
|
|
calendar.setTime(easArcTlsStudents.getEnrollmentDate());
|
|
|
String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
|
|
|
@@ -415,33 +507,51 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
}
|
|
|
|
|
|
private void replacePlaceholders(XWPFDocument document, Map<String, Object> map) {
|
|
|
- for (XWPFTable table : document.getTables()) {
|
|
|
- for (XWPFTableRow row : table.getRows()) {
|
|
|
- for (XWPFTableCell cell : row.getTableCells()) {
|
|
|
- String cellText = cell.getText();
|
|
|
- if (!cellText.contains("${")) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- map.forEach((key, value) -> {
|
|
|
- String placeholder = "${" + key + "}";
|
|
|
- if (cellText.contains(placeholder) && Objects.nonNull(value)) {
|
|
|
- try {
|
|
|
- cell.removeParagraph(0);
|
|
|
- if (value instanceof InputStream) {
|
|
|
- cell.addParagraph().createRun().addPicture((InputStream) value,
|
|
|
- XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg",
|
|
|
- Units.pixelToEMU(110), Units.pixelToEMU(140));
|
|
|
- } else {
|
|
|
- cell.setText(cellText.replace(placeholder, value.toString()));
|
|
|
- }
|
|
|
- } catch (IOException | InvalidFormatException e) {
|
|
|
- throw new EasException("学员导入失败");
|
|
|
+ InputStream resourceAsStream = null;
|
|
|
+ FileManager fileManager = new FileManager();
|
|
|
+ try {
|
|
|
+ if (map.get("avatar").toString().equals(PHOTO_PATH)
|
|
|
+ || Objects.isNull(map.get("avatar"))
|
|
|
+ || map.get("avatar").toString().equals("") ) {
|
|
|
+ resourceAsStream = getClass().getClassLoader().getResourceAsStream(PHOTO_PATH);
|
|
|
+ } else if ( fileManager.isFileExists(map.get("avatar").toString()) ) {
|
|
|
+ resourceAsStream = new FileInputStream(new File(map.get("avatar").toString()));
|
|
|
+ }
|
|
|
+ map.put("avatar", resourceAsStream);
|
|
|
+ for (XWPFTable table : document.getTables()) {
|
|
|
+ for (XWPFTableRow row : table.getRows()) {
|
|
|
+ for (XWPFTableCell cell : row.getTableCells()) {
|
|
|
+ String cellText = cell.getText();
|
|
|
+ if (!cellText.contains("${")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ map.forEach((key, value) -> {
|
|
|
+ String placeholder = "${" + key + "}";
|
|
|
+ if (cellText.contains(placeholder) && Objects.nonNull(value)) {
|
|
|
+ try {
|
|
|
+ cell.removeParagraph(0);
|
|
|
+ if (value instanceof InputStream) {
|
|
|
+ cell.addParagraph().createRun().addPicture((InputStream) value,
|
|
|
+ XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg",
|
|
|
+ Units.pixelToEMU(110), Units.pixelToEMU(140));
|
|
|
+ } else {
|
|
|
+ cell.setText(cellText.replace(placeholder, value.toString()));
|
|
|
+ }
|
|
|
+ } catch (IOException | InvalidFormatException e) {
|
|
|
+ throw new EasException("学员导入失败");
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception ignored) {} finally {
|
|
|
+ if ( Objects.nonNull(resourceAsStream) ) {
|
|
|
+ try {
|
|
|
+ resourceAsStream.close();
|
|
|
+ } catch (IOException ignored) {}
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|