|
@@ -1,16 +1,22 @@
|
|
|
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.Gender;
|
|
|
import com.koobietech.eas.common.exception.EasException;
|
|
|
import com.koobietech.eas.common.utils.ArchiveManager;
|
|
|
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.EasArcTlsStudentsDto;
|
|
|
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.EasArcTlsStudentsExample;
|
|
|
import com.koobietech.eas.mbg.model.EasSysStudent;
|
|
|
import com.koobietech.eas.service.EasArchivesFilesService;
|
|
|
import com.koobietech.eas.service.EasStuProfileService;
|
|
@@ -23,6 +29,7 @@ import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
@@ -46,7 +53,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
private EasArchivesFilesService easArchivesFilesService;
|
|
|
|
|
|
@Override
|
|
|
- public boolean StuProfileDownload(EasArcTlsStudents easArcTlsStudents, Integer manager_id) {
|
|
|
+ public boolean add(EasArcTlsStudents easArcTlsStudents) {
|
|
|
|
|
|
//使用try-with-resources 语句 保证流的关闭
|
|
|
try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
|
|
@@ -55,9 +62,17 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
//调用内部类方法 生成学号
|
|
|
String studentNumber = generateStudentNumber(easArcTlsStudents);
|
|
|
|
|
|
+ easArcTlsStudents.setStudentNumber(studentNumber);
|
|
|
Map<String, Object> map = generateDataMap(easArcTlsStudents, studentNumber);
|
|
|
replacePlaceholders(doc, map);
|
|
|
+ //这里会生成一个学生档案保存本地 目前这里有bug保存不成功 而且文件后缀有错误
|
|
|
+ ArchivesDto archivesDto = insertEasArcArchives(easArcTlsStudents, doc);
|
|
|
+ if ( !archivesDto.isStatus() ) {
|
|
|
+ throw new EasException("EasArcArchives保存失败", 8002);
|
|
|
+ }
|
|
|
+
|
|
|
//将easArcTlsStudents 保存到数据库
|
|
|
+ easArcTlsStudents.setArchiveNumber(archivesDto.getArchiveCode());
|
|
|
boolean isTlsStudentsInsert = insertEasArcTlsStudents(easArcTlsStudents);
|
|
|
if (!isTlsStudentsInsert) {
|
|
|
throw new EasException("EasArcTlsStudents保存失败", 8000);
|
|
@@ -66,11 +81,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
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;
|
|
@@ -78,6 +89,81 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
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){
|
|
|
+ ignored.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (inputStream != null) {
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (IOException ignored) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("student_name", easArcTlsStudents.getStudentName());
|
|
@@ -93,9 +179,9 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
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);
|
|
@@ -114,21 +200,21 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
|
|
|
// 创建 EasArcArchives 对象并设置属性
|
|
|
EasArcArchives easArcArchives = new EasArcArchives();
|
|
|
easArcArchives.setArchiveNumber(archiveCode);
|
|
|
- easArcArchives.setStudentNumber(studentNumber);
|
|
|
+ easArcArchives.setStudentNumber(easArcTlsStudents.getStudentNumber());
|
|
|
easArcArchives.setFilePath(filePath);
|
|
|
easArcArchives.setArctype(arcType);
|
|
|
easArcArchives.setCreateTime(createTime);
|
|
|
easArcArchives.setModifyTime(modifyTime);
|
|
|
easArcArchives.setValidityTime(validityTime);
|
|
|
- easArcArchives.setManagerId(managerId);
|
|
|
- easArcArchives.setCreateUid(1);
|
|
|
+ easArcArchives.setManagerId(easArcTlsStudents.getManagerId());
|
|
|
+ easArcArchives.setCreateUid(SecurityManager.getLoginUid().intValue());
|
|
|
easArcArchives.setCreateDate(new Date());
|
|
|
|
|
|
// 插入到数据库
|
|
|
int result = easArcArchivesMapper.insert(easArcArchives);
|
|
|
-
|
|
|
+ archivesDto.setStatus( result == 1 );
|
|
|
// 返回是否成功插入数据库
|
|
|
- return result > 0;
|
|
|
+ return archivesDto;
|
|
|
}
|
|
|
|
|
|
|