|
@@ -1,5 +1,7 @@
|
|
|
package cn.com.qmth.print.manage.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.print.manage.config.PmConstants;
|
|
|
+import cn.com.qmth.print.manage.config.SysProperty;
|
|
|
import cn.com.qmth.print.manage.dao.ExamDao;
|
|
|
import cn.com.qmth.print.manage.dao.ExamStudentDao;
|
|
|
import cn.com.qmth.print.manage.dto.ExamStudentExportDTO;
|
|
@@ -54,21 +56,38 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
@Resource
|
|
|
private ExamDao examDao;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SysProperty sysProperty;
|
|
|
+
|
|
|
@Override
|
|
|
public ExamStudentEntity findByExamIdAndExamNumber(Long examId, String examNumber) {
|
|
|
- // TODO: 2023/10/20 校验更改逻辑
|
|
|
if (examId == null) {
|
|
|
throw new StatusException("examId不能为空");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(examNumber)) {
|
|
|
throw new StatusException("准考证号不能为空");
|
|
|
}
|
|
|
- QueryWrapper<ExamStudentEntity> wrapper = new QueryWrapper<>();
|
|
|
- LambdaQueryWrapper<ExamStudentEntity> lw = wrapper.lambda();
|
|
|
- lw.eq(ExamStudentEntity::getExamId, examId);
|
|
|
- lw.eq(ExamStudentEntity::getExamNumber, examNumber);
|
|
|
- ExamStudentEntity entity = this.getOne(wrapper);
|
|
|
- return entity;
|
|
|
+ ExamStudentEntity result;
|
|
|
+ // 判断examNumber是否为大条码(学号)
|
|
|
+ ExamStudentEntity checkStudentCode = this.getOne(new QueryWrapper<ExamStudentEntity>()
|
|
|
+ .lambda()
|
|
|
+ .eq(ExamStudentEntity::getExamId, examId)
|
|
|
+ .eq(ExamStudentEntity::getStudentCode, examNumber));
|
|
|
+ if (Objects.nonNull(checkStudentCode)) {
|
|
|
+ result = checkStudentCode;
|
|
|
+ } else {
|
|
|
+ // 判断examNumber是否为小条码(去掉末尾和examNumber)
|
|
|
+ examNumber = examNumber.substring(0, examNumber.length() - 1);
|
|
|
+ ExamStudentEntity checkExamNumber = this.getOne(new QueryWrapper<ExamStudentEntity>()
|
|
|
+ .lambda()
|
|
|
+ .eq(ExamStudentEntity::getExamId, examId)
|
|
|
+ .eq(ExamStudentEntity::getExamNumber, examNumber));
|
|
|
+ if (Objects.isNull(checkExamNumber)) {
|
|
|
+ throw new StatusException("未找到考生[" + examNumber + "]");
|
|
|
+ }
|
|
|
+ result = checkExamNumber;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -167,75 +186,83 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public Object analyzeZipAndImportStudents(Long examId ,MultipartFile file) throws IOException {
|
|
|
- String zipPath = "E:\\file\\studentImport2.zip";
|
|
|
- String dirPath = "E:\\file\\studentImport2";
|
|
|
-// File zip = new File("E:\\file\\studentImport2.zip");
|
|
|
-// File zipDir = new File("E:\\file\\studentImport2");
|
|
|
- Zip4jUtil.unzipEncryptFile(zipPath,dirPath,"qmth!@#");
|
|
|
-// File zip = new File("E:\\file\\studentImport2.zip");
|
|
|
- File zipDir = new File("E:\\file\\studentImport2");
|
|
|
- File[] firstDirArr = zipDir.listFiles();
|
|
|
- if (Objects.isNull(firstDirArr) || firstDirArr.length != 1) {
|
|
|
- throw new StatusException("文件解析失败:未找到一级目录");
|
|
|
- }
|
|
|
- List<File> studentFileList = Arrays.stream(Objects.requireNonNull(firstDirArr[0].listFiles()))
|
|
|
- .filter(e -> e.getName().endsWith("xlsx"))
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isEmpty(studentFileList)) {
|
|
|
- throw new StatusException("文件解析失败:未找到导入的excel文件");
|
|
|
- }
|
|
|
- if (studentFileList.size() != 1) {
|
|
|
- throw new StatusException("文件解析失败:存在多个excel文件");
|
|
|
- }
|
|
|
- File studentExcel = studentFileList.get(0);
|
|
|
+ public Object analyzeZipAndImportStudents(Long examId, MultipartFile file) throws IOException {
|
|
|
+ String tempPath = sysProperty.getTempDataDir() + "/examStudent";
|
|
|
+ try {
|
|
|
+ File tempZipFile = new File(tempPath + "/examStudent.zip");
|
|
|
+ if (!tempZipFile.exists()) {
|
|
|
+ tempZipFile.mkdirs();
|
|
|
+ }
|
|
|
+ file.transferTo(tempZipFile);
|
|
|
+ String zipPath = tempZipFile.getPath();
|
|
|
+ String dirPath = tempPath + "/examStudent";
|
|
|
|
|
|
- ExamEntity examEntity = examDao.selectById(examId);
|
|
|
- List<ExamStudentEntity> studentList = new ArrayList<>();
|
|
|
- ExcelReader excelReader = new ExcelReader(ExamStudentImportDTO.class);
|
|
|
- AtomicLong sort = new AtomicLong(1L);
|
|
|
- List<ExcelError> excelErrors = excelReader.reader(FileUtil.getInputStream(studentExcel), obj -> {
|
|
|
- try {
|
|
|
- ExamStudentImportDTO dto = (ExamStudentImportDTO) obj;
|
|
|
- ExamStudentEntity examStudentEntity = new ExamStudentEntity();
|
|
|
- examStudentEntity.setExamId(examId);
|
|
|
- examStudentEntity.setOrgId(examEntity.getOrgId());
|
|
|
- examStudentEntity.setExamNumber(dto.getExamNumber());
|
|
|
- examStudentEntity.setStudentCode(dto.getStudentCode());
|
|
|
- examStudentEntity.setName(dto.getStudentName());
|
|
|
- examStudentEntity.setCourseCode(dto.getCourseCode());
|
|
|
- examStudentEntity.setCourseName(dto.getCourseName());
|
|
|
- examStudentEntity.setExamSite(dto.getExamPlaceName());
|
|
|
- examStudentEntity.setSortNo(sort.getAndIncrement());
|
|
|
- examStudentEntity.setExamUnit(dto.getExamUnit());
|
|
|
- examStudentEntity.setCreateTime(new Date());
|
|
|
- examStudentEntity.setUpdateTime(new Date());
|
|
|
- studentList.add(examStudentEntity);
|
|
|
- return null;
|
|
|
- } catch (RuntimeException e) {
|
|
|
- // 手动回滚
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- ExcelError excelError = new ExcelError();
|
|
|
- excelError.setExcelErrorType(e.getMessage());
|
|
|
- return excelError;
|
|
|
+ Zip4jUtil.unzipEncryptFile(zipPath, dirPath, "qmth!@#");
|
|
|
+
|
|
|
+ File zipDir = new File(dirPath);
|
|
|
+ File[] firstDirArr = zipDir.listFiles();
|
|
|
+ if (Objects.isNull(firstDirArr) || firstDirArr.length != 1) {
|
|
|
+ throw new StatusException("文件解析失败:未找到一级目录");
|
|
|
}
|
|
|
- });
|
|
|
+ List<File> studentFileList = Arrays.stream(Objects.requireNonNull(firstDirArr[0].listFiles()))
|
|
|
+ .filter(e -> e.getName().endsWith("xlsx"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(studentFileList)) {
|
|
|
+ throw new StatusException("文件解析失败:未找到导入的excel文件");
|
|
|
+ }
|
|
|
+ if (studentFileList.size() != 1) {
|
|
|
+ throw new StatusException("文件解析失败:存在多个excel文件");
|
|
|
+ }
|
|
|
+ File studentExcel = studentFileList.get(0);
|
|
|
|
|
|
- String errors = errorsString(excelErrors);
|
|
|
- if (errors.length() > 0) {
|
|
|
- throw new StatusException(errors);
|
|
|
- }
|
|
|
+ ExamEntity examEntity = examDao.selectById(examId);
|
|
|
+ List<ExamStudentEntity> studentList = new ArrayList<>();
|
|
|
+ ExcelReader excelReader = new ExcelReader(ExamStudentImportDTO.class);
|
|
|
+ AtomicLong sort = new AtomicLong(1L);
|
|
|
+ List<ExcelError> excelErrors = excelReader.reader(FileUtil.getInputStream(studentExcel), obj -> {
|
|
|
+ try {
|
|
|
+ ExamStudentImportDTO dto = (ExamStudentImportDTO) obj;
|
|
|
+ ExamStudentEntity examStudentEntity = new ExamStudentEntity();
|
|
|
+ examStudentEntity.setExamId(examId);
|
|
|
+ examStudentEntity.setOrgId(examEntity.getOrgId());
|
|
|
+ examStudentEntity.setExamNumber(dto.getExamNumber());
|
|
|
+ examStudentEntity.setStudentCode(dto.getStudentCode());
|
|
|
+ examStudentEntity.setName(dto.getStudentName());
|
|
|
+ examStudentEntity.setCourseCode(dto.getCourseCode() + PmConstants.LING_SIGN + dto.getCourseName());
|
|
|
+ examStudentEntity.setExamSite(dto.getExamPlaceName());
|
|
|
+ examStudentEntity.setSortNo(sort.getAndIncrement());
|
|
|
+ examStudentEntity.setExamUnit(dto.getExamUnit());
|
|
|
+ examStudentEntity.setCreateTime(new Date());
|
|
|
+ examStudentEntity.setUpdateTime(new Date());
|
|
|
+ studentList.add(examStudentEntity);
|
|
|
+ return null;
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ // 手动回滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ ExcelError excelError = new ExcelError();
|
|
|
+ excelError.setExcelErrorType(e.getMessage());
|
|
|
+ return excelError;
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- if (!CollectionUtils.isEmpty(studentList)) {
|
|
|
- insertData(examEntity, studentList);
|
|
|
+ String errors = errorsString(excelErrors);
|
|
|
+ if (errors.length() > 0) {
|
|
|
+ throw new StatusException(errors);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(studentList)) {
|
|
|
+ insertData(examEntity, studentList);
|
|
|
+ }
|
|
|
+ return excelErrors;
|
|
|
+ } finally {
|
|
|
+ FileUtil.del(tempPath);
|
|
|
}
|
|
|
- return excelErrors;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void exportExamStudent(HttpServletResponse response, Long examId) throws IOException {
|
|
|
List<ExamStudentExportDTO> examStudentExportDTOList = this.baseMapper.findExportData(examId);
|
|
|
- new ExportExcel("考生数据", ExamStudentExportDTO.class).setDataList(examStudentExportDTOList).write(response, "")
|
|
|
+ new ExportExcel("考生数据", ExamStudentExportDTO.class).setDataList(examStudentExportDTOList).write(response, "考生数据.xlsx")
|
|
|
.dispose();
|
|
|
}
|
|
|
|
|
@@ -250,8 +277,8 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
public void insertData(ExamEntity examEntity, List<ExamStudentEntity> studentList) {
|
|
|
// 有校验数据不能删除
|
|
|
if (checkRecordService.count(new QueryWrapper<CheckRecordEntity>().lambda()
|
|
|
- .eq(CheckRecordEntity::getExamId,examEntity.getId())
|
|
|
- .ne(CheckRecordEntity::getStatus,RecordStatus.NONE)) > 0){
|
|
|
+ .eq(CheckRecordEntity::getExamId, examEntity.getId())
|
|
|
+ .ne(CheckRecordEntity::getStatus, RecordStatus.NONE)) > 0) {
|
|
|
throw new StatusException("已有校验数据,不可重复导入");
|
|
|
}
|
|
|
|