|
@@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
-import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
+import com.qmth.paper.library.business.entity.PaperScanTask;
|
|
|
import com.qmth.paper.library.business.mapper.ExamStudentMapper;
|
|
|
import com.qmth.paper.library.business.service.ExamCourseService;
|
|
|
import com.qmth.paper.library.business.service.ExamStudentService;
|
|
@@ -59,29 +59,50 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
|
|
|
return this.baseMapper.findStudentPage(new Page<>(pageNumber, pageSize), examId, courseCode, collegeName, majorName, clazzName, queryParams);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public void saveBasicStudent(ExamStudent basicStudent) {
|
|
|
+ public void saveBasicStudent(ExamStudent examStudent) {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
// 验证
|
|
|
- ExamStudent byStudentCode = this.getByExamIdAndCourseCodeAndStudentCode(basicStudent.getExamId(), basicStudent.getCourseCode(), basicStudent.getStudentCode());
|
|
|
- if (basicStudent.getId() == null) {
|
|
|
+ ExamStudent byStudentCode = this.getByExamIdAndCourseCodeAndStudentCode(examStudent.getExamId(), examStudent.getCourseCode(), examStudent.getStudentCode());
|
|
|
+ if (examStudent.getId() == null) {
|
|
|
if (byStudentCode != null) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(String.format("学号[%s]在课程%s(%s)下已存在", basicStudent.getStudentCode(), basicStudent.getCourseName(), basicStudent.getCourseCode()));
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("学号[%s]在课程%s(%s)下已存在", examStudent.getStudentCode(), examStudent.getCourseName(), examStudent.getCourseCode()));
|
|
|
+ }
|
|
|
+ examStudent.setId(SystemConstant.getDbUuid());
|
|
|
+ examStudent.setSchoolId(sysUser.getSchoolId());
|
|
|
+ examStudent.setCreateId(sysUser.getId());
|
|
|
+ examStudent.setCreateTime(System.currentTimeMillis());
|
|
|
+ boolean save = this.save(examStudent);
|
|
|
+
|
|
|
+ if (save) {
|
|
|
+ // 保存课程
|
|
|
+ examCourseService.saveStudentCourse(examStudent.getExamId(), examStudent);
|
|
|
+ // 保存任务(存在则更新考生数量)
|
|
|
+ // 校验是否设置了存储方式
|
|
|
+ SimpleObject recognitionTypeSimpleObject = commonCacheService.getSysSetting(sysUser.getSchoolId()).get(SysSettingConstant.RECOGNITION_TYPE);
|
|
|
+ if (StringUtils.isBlank(recognitionTypeSimpleObject.getValue())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("识别方式未设置");
|
|
|
+ }
|
|
|
+ SimpleObject storeTypeSimpleObject = commonCacheService.getSysSetting(sysUser.getSchoolId()).get(SysSettingConstant.STORE_TYPE);
|
|
|
+ if (StringUtils.isBlank(storeTypeSimpleObject.getValue())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("文件存储方式未设置");
|
|
|
+ }
|
|
|
+ RecognitionTypeEnum recognitionType = RecognitionTypeEnum.valueOf(recognitionTypeSimpleObject.getValue());
|
|
|
+ StoreTypeEnum storeType = StoreTypeEnum.valueOf(storeTypeSimpleObject.getValue());
|
|
|
+ paperScanTaskService.addScanTask(examStudent.getExamId(), recognitionType, storeType, examStudent);
|
|
|
}
|
|
|
- byStudentCode.setId(SystemConstant.getDbUuid());
|
|
|
- byStudentCode.setSchoolId(sysUser.getSchoolId());
|
|
|
- byStudentCode.setCreateId(sysUser.getId());
|
|
|
- byStudentCode.setCreateTime(System.currentTimeMillis());
|
|
|
} else {
|
|
|
- if (!basicStudent.getId().equals(byStudentCode.getId())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(String.format("学号[%s]在课程%s(%s)下已存在", basicStudent.getStudentCode(), basicStudent.getCourseName(), basicStudent.getCourseCode()));
|
|
|
+ if (byStudentCode != null && !examStudent.getId().equals(byStudentCode.getId())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("学号[%s]在课程%s(%s)下已存在", examStudent.getStudentCode(), examStudent.getCourseName(), examStudent.getCourseCode()));
|
|
|
}
|
|
|
- byStudentCode.setId(basicStudent.getId());
|
|
|
- byStudentCode.setEnable(true);
|
|
|
- byStudentCode.setUpdateId(sysUser.getId());
|
|
|
- byStudentCode.setUpdateTime(System.currentTimeMillis());
|
|
|
+ examStudent.setId(examStudent.getId());
|
|
|
+ examStudent.setEnable(true);
|
|
|
+ examStudent.setUpdateId(sysUser.getId());
|
|
|
+ examStudent.setUpdateTime(System.currentTimeMillis());
|
|
|
+ this.updateById(examStudent);
|
|
|
}
|
|
|
- this.saveOrUpdate(byStudentCode);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -98,7 +119,26 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
|
|
|
}
|
|
|
}
|
|
|
// 删除基础学生
|
|
|
- return this.removeByIds(ids);
|
|
|
+ this.removeByIds(ids);
|
|
|
+ Map<String, String> stringMap = examStudentList.stream().collect(Collectors.toMap(ExamStudent::getCourseCode, ExamStudent::getCourseName, (oldValue, newValue) -> oldValue));
|
|
|
+ for (Map.Entry<String, String> entry : stringMap.entrySet()) {
|
|
|
+ Long examId = examStudentList.get(0).getExamId();
|
|
|
+ int count = this.countByExamIdAndCourseCode(examId, entry.getKey());
|
|
|
+ PaperScanTask paperScanTask = paperScanTaskService.getByExamIdAndCourseCode(examId, entry.getKey());
|
|
|
+ if (count == 0) {
|
|
|
+ // 删除课程
|
|
|
+ examCourseService.removeByExamIdAndCourseCode(examId, entry.getKey());
|
|
|
+ // 删除任务
|
|
|
+ if (paperScanTask != null) {
|
|
|
+ paperScanTaskService.removeById(paperScanTask.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (paperScanTask != null) {
|
|
|
+ paperScanTaskService.updateStudentCount(paperScanTask);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -131,9 +171,7 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
|
|
|
throw ExceptionResultEnum.ERROR.exception("已开始扫描,导入失败。请清除扫描数据后重试");
|
|
|
}
|
|
|
try {
|
|
|
- System.out.println("大小:" + file.getSize());
|
|
|
ExcelReader excelReader = ExcelReader.create(ExcelType.XLSX, file.getInputStream(), 0);
|
|
|
-// List<String[]> dataMapList = excelReader.getDataArrayList();
|
|
|
List<ExamStudent> basicStudentList = excelReader.getObjectList(ExamStudent.class);
|
|
|
// 校验excel内容
|
|
|
validStudentData(semesterId, examId, basicStudentList, storeType, sysUser);
|
|
@@ -142,9 +180,9 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
|
|
|
// 保存学生
|
|
|
this.saveBatch(basicStudentList);
|
|
|
// 保存课程
|
|
|
- examCourseService.saveStudentCourse(examId, basicStudentList);
|
|
|
+ examCourseService.saveBatchStudentCourse(examId, basicStudentList);
|
|
|
// 新建任务
|
|
|
- paperScanTaskService.addScanTask(examId, recognitionType, storeType, basicStudentList);
|
|
|
+ paperScanTaskService.addBatchScanTask(examId, recognitionType, storeType, basicStudentList);
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
} catch (Exception e) {
|
|
@@ -167,6 +205,14 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
|
|
|
this.remove(queryWrapper);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int countByExamIdAndCourseCode(Long examId, String courseCode) {
|
|
|
+ QueryWrapper<ExamStudent> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamStudent::getExamId, examId)
|
|
|
+ .eq(ExamStudent::getCourseCode, courseCode);
|
|
|
+ return this.count(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 学生保存公共方法
|
|
|
*/
|