|
@@ -24,6 +24,7 @@ import com.qmth.teachcloud.mark.utils.FileStoreUtils;
|
|
|
import com.qmth.teachcloud.task.service.PrintFinishService;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -34,7 +35,9 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
@Service
|
|
|
public class PrintFinishServiceImpl implements PrintFinishService {
|
|
@@ -60,7 +63,7 @@ public class PrintFinishServiceImpl implements PrintFinishService {
|
|
|
@Resource
|
|
|
private FileStoreUtils fileStoreUtils;
|
|
|
@Resource
|
|
|
- private FileService fileService;
|
|
|
+ private MarkFileService markFileService;
|
|
|
|
|
|
/**
|
|
|
* 打印结束后,生成阅卷科目数据
|
|
@@ -83,17 +86,30 @@ public class PrintFinishServiceImpl implements PrintFinishService {
|
|
|
|
|
|
@Override
|
|
|
public void insertMarkStudent(ExamDetailCourseInitMarkDto dto) {
|
|
|
- List<MarkStudent> markStudentList = new ArrayList<>();
|
|
|
- List<ExamStudent> examStudentList = examStudentService.listByExamDetailCourseIdNotIntMarkStudent(dto.getId());
|
|
|
- for (ExamStudent examStudent : examStudentList) {
|
|
|
- MarkStudent markStudent = markStudentService.getById(examStudent.getId());
|
|
|
- if (markStudent != null) {
|
|
|
- continue;
|
|
|
+ try {
|
|
|
+ List<MarkStudent> markStudentList = new ArrayList<>();
|
|
|
+ List<ExamStudent> examStudentList = examStudentService.listByExamDetailCourseIdNotIntMarkStudent(dto.getId());
|
|
|
+ Set<String> secretNumberSet = new HashSet<>();
|
|
|
+ for (ExamStudent examStudent : examStudentList) {
|
|
|
+ MarkStudent markStudent = markStudentService.getById(examStudent.getId());
|
|
|
+ if (markStudent != null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MarkStudent student = new MarkStudent(examStudent.getId(), dto.getExamId(), dto.getCourseCode(), dto.getCourseName(), dto.getPaperNumber(), examStudent.getStudentCode(), examStudent.getStudentName(), dto.getPackageCode(), dto.getExamPlace(), dto.getExamRoom(), examStudent.getCollegeName(), examStudent.getStudentName());
|
|
|
+ if (student.getSecretNumber() == null) {
|
|
|
+ student.randomSecretNumber();
|
|
|
+ while (secretNumberSet.contains(student.getSecretNumber())
|
|
|
+ || markStudentService.countByExamIdAndSecretNumber(student.getExamId(), student.getSecretNumber()) > 0) {
|
|
|
+ student.randomSecretNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ markStudentList.add(student);
|
|
|
}
|
|
|
- markStudentList.add(new MarkStudent(examStudent.getId(), dto.getExamId(), dto.getCourseCode(), dto.getCourseName(), dto.getPaperNumber(), examStudent.getStudentCode(), examStudent.getStudentName(), dto.getPackageCode(), dto.getExamPlace(), dto.getExamRoom(), examStudent.getStudentName()));
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(markStudentList)) {
|
|
|
- markStudentService.saveBatch(markStudentList);
|
|
|
+ if (CollectionUtils.isNotEmpty(markStudentList)) {
|
|
|
+ markStudentService.saveBatch(markStudentList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("考生同步阅卷失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -123,7 +139,7 @@ public class PrintFinishServiceImpl implements PrintFinishService {
|
|
|
FileInputStream inputStream = new FileInputStream(jsonFile);
|
|
|
String md5 = DigestUtils.md5Hex(inputStream);
|
|
|
Integer number = scanAnswerCardService.findMaxCardNumberByExamId(dto.getExamId());
|
|
|
- String path = fileService.getAnswerCardUri(dto.getExamId(), dto.getCoursePaperId(), number);
|
|
|
+ String path = markFileService.getAnswerCardUri(dto.getExamId(), dto.getCoursePaperId(), number);
|
|
|
String uploadPath = fileStoreUtils.uploadFile(inputStream, md5, UploadFileEnum.CARD, path);
|
|
|
|
|
|
scanAnswerCard = new ScanAnswerCard();
|
|
@@ -136,8 +152,15 @@ public class PrintFinishServiceImpl implements PrintFinishService {
|
|
|
scanAnswerCard.setUri(uploadPath);
|
|
|
scanAnswerCard.setMd5(md5);
|
|
|
scanAnswerCard.setNeedAdapte(true);
|
|
|
+ scanAnswerCardService.save(scanAnswerCard);
|
|
|
} catch (IOException e) {
|
|
|
log.info("考试[],试卷编号[],题卡ID[]同步阅卷失败", dto.getExamId(), dto.getPaperNumber(), paperInfoVo.getCardId());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ FileUtils.forceDeleteOnExit(jsonFile);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|