|
@@ -0,0 +1,132 @@
|
|
|
+package cn.com.qmth.examcloud.core.oe.student.service.impl;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.ExamScoreEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.ExamStudentEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.ExamStudentFinalScoreEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.enums.ExamProperties;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.enums.ExamRecordStatus;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.enums.MarkingType;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.helper.ExamCacheTransferHelper;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.ExamScoreRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.ExamStudentFinalScoreRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.ExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.service.ExamStudentFinalScoreService;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 考生最终分数实现类
|
|
|
+ * @Author lideyin
|
|
|
+ * @Date 2019/11/11 14:30
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreService {
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordDataRepo examRecordDataRepo;
|
|
|
+ @Autowired
|
|
|
+ private ExamScoreRepo examScoreRepo;
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentRepo examStudentRepo;
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentFinalScoreRepo examStudentFinalScoreRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void calculateFinalScore(Long examStudentId) {
|
|
|
+ ExamStudentEntity examStudent = GlobalHelper.getEntity(examStudentRepo, examStudentId, ExamStudentEntity.class);
|
|
|
+ String markingType = ExamCacheTransferHelper.
|
|
|
+ getDefaultCachedExamProperty(examStudent.getExamId(), ExamProperties.MARKING_TYPE.name()).getValue();
|
|
|
+ String examType = ExamCacheTransferHelper.getDefaultCachedExam(examStudent.getExamId()).getExamType();
|
|
|
+ List<ExamRecordDataEntity> allExamRecordDataList = examRecordDataRepo.findByExamStudentId(examStudentId);
|
|
|
+
|
|
|
+ //得到最终考试结果
|
|
|
+ ExamScoreEntity finalEffectiveExamScore = getFinalEffectiveExamScore(allExamRecordDataList, examType, markingType);
|
|
|
+
|
|
|
+ //保存最终考试结果
|
|
|
+ ExamStudentFinalScoreEntity finalScoreEntity = copyExamStudentFinalScoreEntityFrom(finalEffectiveExamScore);
|
|
|
+ examStudentFinalScoreRepo.save(finalScoreEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ExamStudentFinalScoreEntity copyExamStudentFinalScoreEntityFrom(ExamScoreEntity finalEffectiveExamScore) {
|
|
|
+ ExamStudentFinalScoreEntity finalScoreEntity = new ExamStudentFinalScoreEntity();
|
|
|
+
|
|
|
+ finalScoreEntity.setExamRecordDataId(finalEffectiveExamScore.getExamRecordDataId());
|
|
|
+ finalScoreEntity.setExamStudentId(finalEffectiveExamScore.getExamRecordDataId());
|
|
|
+ finalScoreEntity.setObjectiveAccuracy(finalEffectiveExamScore.getObjectiveAccuracy());
|
|
|
+ finalScoreEntity.setObjectiveScore(finalEffectiveExamScore.getObjectiveScore());
|
|
|
+ finalScoreEntity.setSubjectiveScore(finalEffectiveExamScore.getSubjectiveScore());
|
|
|
+ finalScoreEntity.setSuccPercent(finalEffectiveExamScore.getSuccPercent());
|
|
|
+ finalScoreEntity.setTotalScore(finalEffectiveExamScore.getTotalScore());
|
|
|
+
|
|
|
+ return finalScoreEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算得出最终有效成绩
|
|
|
+ */
|
|
|
+ private ExamScoreEntity getFinalEffectiveExamScore(List<ExamRecordDataEntity> examRecordAllList, String examType, String markingType) {
|
|
|
+ /*
|
|
|
+ * 第一次过滤考试记录:
|
|
|
+ * 状态为EXAM_END或EXAM_OVERDUE
|
|
|
+ */
|
|
|
+ List<ExamRecordDataEntity> firstFilterExamRecordList = examRecordAllList.stream().filter(examRecord -> {
|
|
|
+ return examRecord.getExamRecordStatus() == ExamRecordStatus.EXAM_END ||
|
|
|
+ examRecord.getExamRecordStatus() == ExamRecordStatus.EXAM_OVERDUE;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (firstFilterExamRecordList == null || firstFilterExamRecordList.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 第二次过滤考试记录:
|
|
|
+ * 没有违纪的&&(没有警告或有警告已审核通过的)
|
|
|
+ */
|
|
|
+ Stream<ExamRecordDataEntity> secondFilterExamRecordStream = firstFilterExamRecordList.stream().filter(examRecord -> {
|
|
|
+ return !examRecord.getIsIllegality() && (!examRecord.getIsWarn() || (examRecord.getIsWarn() && examRecord.getIsAudit()));
|
|
|
+ });
|
|
|
+
|
|
|
+ List<ExamRecordDataEntity> secondFilterExamRecords = secondFilterExamRecordStream.collect(Collectors.toList());
|
|
|
+ if (secondFilterExamRecords == null || secondFilterExamRecords.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //取出有效记录的成绩
|
|
|
+ List<Long> examRecordDataIds = new ArrayList<>();
|
|
|
+ for (int i = 0; i < secondFilterExamRecords.size(); i++) {
|
|
|
+ examRecordDataIds.add(secondFilterExamRecords.get(i).getId());
|
|
|
+ }
|
|
|
+ List<ExamScoreEntity> effectiveExamScoreList = examScoreRepo.findByExamRecordDataIdIn(examRecordDataIds);
|
|
|
+ if (effectiveExamScoreList == null || effectiveExamScoreList.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //离线考试
|
|
|
+ if ("OFFLINE".equals(examType)) {
|
|
|
+ return effectiveExamScoreList.get(0);
|
|
|
+ } else {
|
|
|
+ if (markingType.equals(MarkingType.ALL.name()) || markingType.equals(MarkingType.OBJECT_SCORE_MAX.name())) {
|
|
|
+ //全部评阅规则或客观分最高规则:取总分最高
|
|
|
+ List<ExamScoreEntity> examScores = effectiveExamScoreList
|
|
|
+ .stream()
|
|
|
+ .sorted((o1, o2) -> o2.getTotalScore().compareTo(o1.getTotalScore()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return examScores.get(0);
|
|
|
+ } else if (markingType.equals(MarkingType.LAST_SUBMIT.name())) {
|
|
|
+ //最后一次提交规则:取最后一次的成绩
|
|
|
+ List<ExamScoreEntity> examScores = effectiveExamScoreList
|
|
|
+ .stream()
|
|
|
+ .sorted((o1, o2) -> o2.getId().compareTo(o1.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return examScores.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|