|
@@ -1,16 +1,23 @@
|
|
package com.koobietech.eas.service.impl;
|
|
package com.koobietech.eas.service.impl;
|
|
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
import com.koobietech.eas.common.constant.FileType;
|
|
import com.koobietech.eas.common.constant.FileType;
|
|
import com.koobietech.eas.common.constant.Gender;
|
|
import com.koobietech.eas.common.constant.Gender;
|
|
|
|
+import com.koobietech.eas.common.constant.UniversityCode;
|
|
import com.koobietech.eas.common.exception.EasException;
|
|
import com.koobietech.eas.common.exception.EasException;
|
|
import com.koobietech.eas.common.utils.ArchiveManager;
|
|
import com.koobietech.eas.common.utils.ArchiveManager;
|
|
import com.koobietech.eas.common.utils.DateManager;
|
|
import com.koobietech.eas.common.utils.DateManager;
|
|
|
|
+import com.koobietech.eas.common.utils.SecurityManager;
|
|
import com.koobietech.eas.dao.dto.ArchivesDto;
|
|
import com.koobietech.eas.dao.dto.ArchivesDto;
|
|
|
|
+import com.koobietech.eas.dao.dto.EasArcTlsStudentsDto;
|
|
import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
|
|
import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
|
|
import com.koobietech.eas.mbg.mapper.EasArcTlsStudentsMapper;
|
|
import com.koobietech.eas.mbg.mapper.EasArcTlsStudentsMapper;
|
|
import com.koobietech.eas.mbg.mapper.EasSysStudentMapper;
|
|
import com.koobietech.eas.mbg.mapper.EasSysStudentMapper;
|
|
import com.koobietech.eas.mbg.model.EasArcArchives;
|
|
import com.koobietech.eas.mbg.model.EasArcArchives;
|
|
import com.koobietech.eas.mbg.model.EasArcTlsStudents;
|
|
import com.koobietech.eas.mbg.model.EasArcTlsStudents;
|
|
|
|
+import com.koobietech.eas.mbg.model.EasArcTlsStudentsExample;
|
|
import com.koobietech.eas.mbg.model.EasSysStudent;
|
|
import com.koobietech.eas.mbg.model.EasSysStudent;
|
|
import com.koobietech.eas.service.EasArchivesFilesService;
|
|
import com.koobietech.eas.service.EasArchivesFilesService;
|
|
import com.koobietech.eas.service.EasStuProfileService;
|
|
import com.koobietech.eas.service.EasStuProfileService;
|
|
@@ -20,9 +27,12 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
|
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
|
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
|
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
|
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
|
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -32,6 +42,8 @@ import java.util.*;
|
|
@Service
|
|
@Service
|
|
public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
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 TEMPLATE_PATH = "temp/StuRegistTemp.docx";
|
|
private static final String PHOTO_PATH = "temp/kun.jpeg";
|
|
private static final String PHOTO_PATH = "temp/kun.jpeg";
|
|
@Resource
|
|
@Resource
|
|
@@ -46,7 +58,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
private EasArchivesFilesService easArchivesFilesService;
|
|
private EasArchivesFilesService easArchivesFilesService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean StuProfileDownload(EasArcTlsStudents easArcTlsStudents, Integer manager_id) {
|
|
|
|
|
|
+ public boolean add(EasArcTlsStudents easArcTlsStudents) {
|
|
|
|
|
|
//使用try-with-resources 语句 保证流的关闭
|
|
//使用try-with-resources 语句 保证流的关闭
|
|
try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
|
|
try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
|
|
@@ -55,9 +67,17 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
//调用内部类方法 生成学号
|
|
//调用内部类方法 生成学号
|
|
String studentNumber = generateStudentNumber(easArcTlsStudents);
|
|
String studentNumber = generateStudentNumber(easArcTlsStudents);
|
|
|
|
|
|
|
|
+ easArcTlsStudents.setStudentNumber(studentNumber);
|
|
Map<String, Object> map = generateDataMap(easArcTlsStudents, studentNumber);
|
|
Map<String, Object> map = generateDataMap(easArcTlsStudents, studentNumber);
|
|
replacePlaceholders(doc, map);
|
|
replacePlaceholders(doc, map);
|
|
|
|
+ //这里会生成一个学生档案保存本地 目前这里有bug保存不成功 而且文件后缀有错误
|
|
|
|
+ ArchivesDto archivesDto = insertEasArcArchives(easArcTlsStudents, doc);
|
|
|
|
+ if ( !archivesDto.isStatus() ) {
|
|
|
|
+ throw new EasException("EasArcArchives保存失败", 8002);
|
|
|
|
+ }
|
|
|
|
+
|
|
//将easArcTlsStudents 保存到数据库
|
|
//将easArcTlsStudents 保存到数据库
|
|
|
|
+ easArcTlsStudents.setArchiveNumber(archivesDto.getArchiveCode());
|
|
boolean isTlsStudentsInsert = insertEasArcTlsStudents(easArcTlsStudents);
|
|
boolean isTlsStudentsInsert = insertEasArcTlsStudents(easArcTlsStudents);
|
|
if (!isTlsStudentsInsert) {
|
|
if (!isTlsStudentsInsert) {
|
|
throw new EasException("EasArcTlsStudents保存失败", 8000);
|
|
throw new EasException("EasArcTlsStudents保存失败", 8000);
|
|
@@ -66,18 +86,92 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
if (!isSysStudentsInsert) {
|
|
if (!isSysStudentsInsert) {
|
|
throw new EasException("EasSysStudents保存失败", 8001);
|
|
throw new EasException("EasSysStudents保存失败", 8001);
|
|
}
|
|
}
|
|
- //这里会生成一个学生档案保存本地 目前这里有bug保存不成功 而且文件后缀有错误
|
|
|
|
- boolean isEasArcArchives = insertEasArcArchives(easArcTlsStudents, studentNumber, manager_id, doc);
|
|
|
|
- if (!isEasArcArchives) {
|
|
|
|
- throw new EasException("EasArcArchives保存失败", 8002);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- return false;
|
|
|
|
|
|
+ logger.error(e.getMessage());
|
|
|
|
+ throw new EasException("生成档案失败", 8003);
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<EasArcTlsStudents> query(EasArcTlsStudents studentDto, Integer pageNum, Integer pageSize) {
|
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
|
+ EasArcTlsStudentsExample easArcTlsStudentsExample = new EasArcTlsStudentsExample();
|
|
|
|
+ EasArcTlsStudentsExample.Criteria criteria = easArcTlsStudentsExample.createCriteria();
|
|
|
|
+ if ( Objects.nonNull(studentDto) ) {
|
|
|
|
+ if (StringUtils.hasText(studentDto.getStudentName())) {
|
|
|
|
+ criteria.andStudentNameLike("%" + studentDto.getStudentName() + "%");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasText(studentDto.getStudentNumber())) {
|
|
|
|
+ criteria.andStudentNumberLike("%" + studentDto.getStudentNumber() + "%");
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(studentDto.getGender())) {
|
|
|
|
+ criteria.andGenderEqualTo(studentDto.getGender());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasText(studentDto.getStudentIdnumber())) {
|
|
|
|
+ criteria.andStudentIdnumberEqualTo(studentDto.getStudentIdnumber());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasText(studentDto.getPhone())) {
|
|
|
|
+ criteria.andPhoneLike("%"+studentDto.getPhone() + "% %" + studentDto.getPhone() + "%");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasText(studentDto.getUniversity())) {
|
|
|
|
+ criteria.andUniversityLike("%" + studentDto.getUniversity() + "%");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasText(studentDto.getAddress())) {
|
|
|
|
+ criteria.andAddressLike("%" + studentDto.getAddress() + "%");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasText(studentDto.getEmail())) {
|
|
|
|
+ criteria.andEmailEqualTo(studentDto.getEmail());
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(studentDto.getEnrollmentDate())) {
|
|
|
|
+ criteria.andEnrollmentDateEqualTo(studentDto.getEnrollmentDate());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<EasArcTlsStudents> easArcTlsStudents = easArcTlsStudentsMapper.selectByExample(easArcTlsStudentsExample);
|
|
|
|
+ return easArcTlsStudents;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean update(EasArcTlsStudents studentDto) {
|
|
|
|
+ return easArcTlsStudentsMapper.updateByPrimaryKey(studentDto) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean delete(int id) {
|
|
|
|
+ return easArcTlsStudentsMapper.deleteByPrimaryKey(id) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean importExcel(InputStream inputStream) {
|
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
|
+ params.setTitleRows(1);
|
|
|
|
+ params.setHeadRows(1);
|
|
|
|
+ try {
|
|
|
|
+ EasArcTlsStudents easArcTlsStudents = null;
|
|
|
|
+ List<EasArcTlsStudentsDto> studentList = ExcelImportUtil.importExcel(
|
|
|
|
+ inputStream, EasArcTlsStudentsDto.class, params);
|
|
|
|
+ for (EasArcTlsStudentsDto studentDto : studentList) {
|
|
|
|
+ easArcTlsStudents = new EasArcTlsStudents();
|
|
|
|
+ BeanUtils.copyProperties(studentDto, easArcTlsStudents);
|
|
|
|
+ add(easArcTlsStudents);
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ } catch (Exception ignored){
|
|
|
|
+ logger.error(ignored.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
+ try {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ } catch (IOException ignored) {
|
|
|
|
+ logger.error(ignored.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber) {
|
|
private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("student_name", easArcTlsStudents.getStudentName());
|
|
map.put("student_name", easArcTlsStudents.getStudentName());
|
|
@@ -93,14 +187,12 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean insertEasArcArchives(EasArcTlsStudents easArcTlsStudents, String studentNumber, Integer managerId, XWPFDocument doc) {
|
|
|
|
|
|
+ public ArchivesDto insertEasArcArchives(EasArcTlsStudents easArcTlsStudents, XWPFDocument doc) {
|
|
// 生成档案号
|
|
// 生成档案号
|
|
- String archiveCode = ArchiveManager.generateArchiveCode(studentNumber, String.valueOf(FileType.DOCX));
|
|
|
|
|
|
+ String archiveCode = ArchiveManager.generateArchiveCode(easArcTlsStudents.getStudentNumber(), String.valueOf(FileType.DOCX.getValue()));
|
|
|
|
|
|
// 保存学员档案文件
|
|
// 保存学员档案文件
|
|
ArchivesDto archivesDto = easArchivesFilesService.saveArchiveStudentsFile(easArcTlsStudents.getStudentIdnumber(), doc);
|
|
ArchivesDto archivesDto = easArchivesFilesService.saveArchiveStudentsFile(easArcTlsStudents.getStudentIdnumber(), doc);
|
|
- String filePath = archivesDto.getPath();
|
|
|
|
- String arcType = archivesDto.getFileType();
|
|
|
|
|
|
|
|
// 设置时间和有效期
|
|
// 设置时间和有效期
|
|
Date createTime = DateManager.convertToYearMonthDayToDate(new Date());
|
|
Date createTime = DateManager.convertToYearMonthDayToDate(new Date());
|
|
@@ -114,21 +206,21 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
// 创建 EasArcArchives 对象并设置属性
|
|
// 创建 EasArcArchives 对象并设置属性
|
|
EasArcArchives easArcArchives = new EasArcArchives();
|
|
EasArcArchives easArcArchives = new EasArcArchives();
|
|
easArcArchives.setArchiveNumber(archiveCode);
|
|
easArcArchives.setArchiveNumber(archiveCode);
|
|
- easArcArchives.setStudentNumber(studentNumber);
|
|
|
|
- easArcArchives.setFilePath(filePath);
|
|
|
|
- easArcArchives.setArctype(arcType);
|
|
|
|
|
|
+ easArcArchives.setStudentNumber(easArcTlsStudents.getStudentNumber());
|
|
|
|
+ easArcArchives.setFilePath(archivesDto.getPath());
|
|
|
|
+ easArcArchives.setArctype(archivesDto.getFileType());
|
|
easArcArchives.setCreateTime(createTime);
|
|
easArcArchives.setCreateTime(createTime);
|
|
easArcArchives.setModifyTime(modifyTime);
|
|
easArcArchives.setModifyTime(modifyTime);
|
|
easArcArchives.setValidityTime(validityTime);
|
|
easArcArchives.setValidityTime(validityTime);
|
|
- easArcArchives.setManagerId(managerId);
|
|
|
|
- easArcArchives.setCreateUid(1);
|
|
|
|
|
|
+ easArcArchives.setManagerId(easArcTlsStudents.getManagerId());
|
|
|
|
+ easArcArchives.setCreateUid(SecurityManager.getLoginUid().intValue());
|
|
easArcArchives.setCreateDate(new Date());
|
|
easArcArchives.setCreateDate(new Date());
|
|
|
|
|
|
// 插入到数据库
|
|
// 插入到数据库
|
|
int result = easArcArchivesMapper.insert(easArcArchives);
|
|
int result = easArcArchivesMapper.insert(easArcArchives);
|
|
-
|
|
|
|
|
|
+ archivesDto.setStatus( result == 1 );
|
|
// 返回是否成功插入数据库
|
|
// 返回是否成功插入数据库
|
|
- return result > 0;
|
|
|
|
|
|
+ return archivesDto;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -153,7 +245,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
|
|
|
|
return ArchiveManager.generateStudentCode("",
|
|
return ArchiveManager.generateStudentCode("",
|
|
- easArcTlsStudents.getStudentIdnumber(), easArcTlsStudents.getUniversity(), year);
|
|
|
|
|
|
+ easArcTlsStudents.getStudentIdnumber(), String.valueOf(UniversityCode.getCode(easArcTlsStudents.getUniversity().trim())), year);
|
|
}
|
|
}
|
|
|
|
|
|
private String convertToGender(String gender) {
|
|
private String convertToGender(String gender) {
|