|
@@ -237,99 +237,92 @@ public class DataUploadService {
|
|
|
@Transactional
|
|
|
public List<ExcelError> uploadStudents(Long workId, final boolean isAbsent, InputStream inputStream) throws Exception {
|
|
|
//有采集数据,不能导入
|
|
|
- List<Paper> papers = paperRepo.findByWorkId(workId);
|
|
|
+ /*List<Paper> papers = paperRepo.findByWorkId(workId);
|
|
|
if (papers != null && papers.size() > 0) {
|
|
|
throw new Exception("已有采集数据,不能导入考生数据");
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
List<Student> studentList = new ArrayList<>();
|
|
|
|
|
|
ExcelReader excelReader = new ExcelReader(StudentDTO.class);
|
|
|
- List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public ExcelError handle(Object obj) {
|
|
|
- try {
|
|
|
- StudentDTO dto = (StudentDTO) obj;
|
|
|
- //校验excel文件中数据是否完整
|
|
|
- if (!checkObjFieldIsNotNull(dto)) {
|
|
|
- throw new RuntimeException("考生信息缺失");
|
|
|
- }
|
|
|
+ List<ExcelError> excelErrors = excelReader.reader(inputStream, obj -> {
|
|
|
+ try {
|
|
|
+ StudentDTO dto = (StudentDTO) obj;
|
|
|
+ //校验excel文件中数据是否完整
|
|
|
+ if (!checkObjFieldIsNotNull(dto)) {
|
|
|
+ throw new RuntimeException("考生信息缺失");
|
|
|
+ }
|
|
|
|
|
|
- String examNumber = dto.getExamNumber();
|
|
|
- //如果没有设置区域代码,用准考证前2位作为区域代码
|
|
|
- String areaCode = null;
|
|
|
- if (dto.getAreaCode() == null || dto.getAreaCode().isEmpty()) {
|
|
|
- areaCode = examNumber.substring(0, 2);
|
|
|
- dto.setAreaCode(areaCode);
|
|
|
- }
|
|
|
+ String examNumber = dto.getExamNumber();
|
|
|
+ //如果没有设置区域代码,用准考证前2位作为区域代码
|
|
|
+ String areaCode = null;
|
|
|
+ if (dto.getAreaCode() == null || dto.getAreaCode().isEmpty()) {
|
|
|
+ areaCode = examNumber.substring(0, 2);
|
|
|
+ dto.setAreaCode(areaCode);
|
|
|
+ }
|
|
|
|
|
|
- long isExist = examQuestionRepo.countByWorkIdAndAreaCode(workId, dto.getAreaCode());
|
|
|
- if (isExist == 0) {
|
|
|
- examQuestionRepo.deleteByWorkIdAndAreaCode(workId, dto.getAreaCode());
|
|
|
- if (!imageConfig.isCustomSubject()) {
|
|
|
- for (Subject subject : Subject.values()) {
|
|
|
- ExamQuestion question = new ExamQuestion(dto.getAreaCode(), subject, workId, dto.getAreaName());
|
|
|
- examQuestionRepo.save(question);
|
|
|
- }
|
|
|
- } else {
|
|
|
- MarkSubject markSubject = markSubjectRepo.findOne(workId + "-" + Subject.CUSTOM.name());
|
|
|
- ExamQuestion question = new ExamQuestion(dto.getAreaCode(), Subject.CUSTOM, markSubject.getName(), workId, dto.getAreaName());
|
|
|
+ long isExist = examQuestionRepo.countByWorkIdAndAreaCode(workId, dto.getAreaCode());
|
|
|
+ if (isExist == 0) {
|
|
|
+ examQuestionRepo.deleteByWorkIdAndAreaCode(workId, dto.getAreaCode());
|
|
|
+ if (!imageConfig.isCustomSubject()) {
|
|
|
+ for (Subject subject : Subject.values()) {
|
|
|
+ ExamQuestion question = new ExamQuestion(dto.getAreaCode(), subject, workId, dto.getAreaName());
|
|
|
examQuestionRepo.save(question);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ MarkSubject markSubject = markSubjectRepo.findOne(workId + "-" + Subject.CUSTOM.name());
|
|
|
+ ExamQuestion question = new ExamQuestion(dto.getAreaCode(), Subject.CUSTOM, markSubject.getName(), workId, dto.getAreaName());
|
|
|
+ examQuestionRepo.save(question);
|
|
|
}
|
|
|
- Student student = studentRepo.findByWorkIdAndExamNumberAndTest(workId, dto.getExamNumber(), String.valueOf(TrialEnum.DEFAULT.getId()));
|
|
|
- if (student == null && !isAbsent) {
|
|
|
- student = new Student(dto.getName(), dto.getExamNumber(), dto.getAreaName(), dto.getAreaCode(),
|
|
|
- workId, dto.getExamRoom(), dto.getSourceName(), String.valueOf(TrialEnum.DEFAULT.getId()), dto.getSchool());
|
|
|
- if (imageConfig.isCustomSubject()) {
|
|
|
+ }
|
|
|
+ Student student = studentRepo.findByWorkIdAndExamNumberAndTest(workId, dto.getExamNumber(), String.valueOf(TrialEnum.DEFAULT.getId()));
|
|
|
+ if (student == null && !isAbsent) {
|
|
|
+ student = new Student(dto.getName(), dto.getExamNumber(), dto.getAreaName(), dto.getAreaCode(),
|
|
|
+ workId, dto.getExamRoom(), dto.getSourceName(), String.valueOf(TrialEnum.DEFAULT.getId()), dto.getSchool());
|
|
|
+ if (imageConfig.isCustomSubject()) {
|
|
|
+ student.setUploadStatus("CUSTOM:0");
|
|
|
+ }
|
|
|
+// studentRepo.save(student);
|
|
|
+ studentList.add(student);
|
|
|
+ } else if (student != null) {
|
|
|
+ if (isAbsent) {
|
|
|
+ student.setAbsent(isAbsent);
|
|
|
+ if (!imageConfig.isCustomSubject()) {
|
|
|
+ student.setUploadStatus("SX:0,SC:0,SM:0");
|
|
|
+ } else {
|
|
|
student.setUploadStatus("CUSTOM:0");
|
|
|
}
|
|
|
-// studentRepo.save(student);
|
|
|
- studentList.add(student);
|
|
|
- } else if (student != null) {
|
|
|
- if (isAbsent) {
|
|
|
- student.setAbsent(isAbsent);
|
|
|
- if (!imageConfig.isCustomSubject()) {
|
|
|
- student.setUploadStatus("SX:0,SC:0,SM:0");
|
|
|
- } else {
|
|
|
- student.setUploadStatus("CUSTOM:0");
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 查询该考生所有paper,若paper无任务则删除,有任务就保留
|
|
|
- */
|
|
|
- List<Paper> papers = paperRepo.findByWorkIdAndExamNumber(workId, student.getExamNumber());
|
|
|
- if (!papers.isEmpty()) {
|
|
|
- for (Paper paper : papers) {
|
|
|
- Long count = markTaskRepo.countByPaperId(paper.getId());
|
|
|
- if (count == 0) {
|
|
|
- paperRepo.delete(paper);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 查询该考生所有paper,若paper无任务则删除,有任务就保留
|
|
|
+ */
|
|
|
+ List<Paper> papers = paperRepo.findByWorkIdAndExamNumber(workId, student.getExamNumber());
|
|
|
+ if (!papers.isEmpty()) {
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ Long count = markTaskRepo.countByPaperId(paper.getId());
|
|
|
+ if (count == 0) {
|
|
|
+ paperRepo.delete(paper);
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- student.setName(dto.getName());
|
|
|
- student.setAreaCode(dto.getAreaCode());
|
|
|
- student.setAreaName(dto.getAreaName());
|
|
|
- student.setExamRoom(dto.getExamRoom());
|
|
|
- student.setSourceName(dto.getSourceName());
|
|
|
- student.setSchool(dto.getSchool());
|
|
|
-// student.setScMissing(false);
|
|
|
-// student.setSxMissing(false);
|
|
|
-// student.setSmMissing(false);
|
|
|
}
|
|
|
-// studentRepo.save(student);
|
|
|
- studentList.add(student);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ /*student.setName(dto.getName());
|
|
|
+ student.setAreaCode(dto.getAreaCode());
|
|
|
+ student.setAreaName(dto.getAreaName());
|
|
|
+ student.setExamRoom(dto.getExamRoom());
|
|
|
+ student.setSourceName(dto.getSourceName());
|
|
|
+ student.setSchool(dto.getSchool());*/
|
|
|
}
|
|
|
- return null;
|
|
|
- } catch (RuntimeException e) {
|
|
|
- //手动回滚
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- ExcelError excelError = new ExcelError();
|
|
|
- excelError.setExcelErrorType(e.getMessage());
|
|
|
- return excelError;
|
|
|
+ studentList.add(student);
|
|
|
}
|
|
|
+ return null;
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ //手动回滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ ExcelError excelError = new ExcelError();
|
|
|
+ excelError.setExcelErrorType(e.getMessage());
|
|
|
+ return excelError;
|
|
|
}
|
|
|
});
|
|
|
String errors = errorsString(excelErrors);
|