|
@@ -1,6 +1,6 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamScoreRepo;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamStudentFinalScoreRepo;
|
|
@@ -13,6 +13,7 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.enums.MarkingType;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentFinalScoreService;
|
|
|
import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -31,6 +32,8 @@ import java.util.stream.Collectors;
|
|
|
@Service("examStudentFinalScoreService")
|
|
|
public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreService {
|
|
|
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(ExamStudentFinalScoreServiceImpl.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExamRecordDataRepo examRecordDataRepo;
|
|
|
|
|
@@ -43,45 +46,35 @@ public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreSe
|
|
|
@Autowired
|
|
|
private ExamStudentFinalScoreRepo examStudentFinalScoreRepo;
|
|
|
|
|
|
- private static final Logger LOG = LoggerFactory.getLogger(ExamStudentFinalScoreServiceImpl.class);
|
|
|
-
|
|
|
@Override
|
|
|
public ExamStudentFinalScoreEntity calcAndSaveFinalScore(Long examStudentId) {
|
|
|
ExamStudentEntity examStudent = examStudentRepo.findByExamStudentId(examStudentId);
|
|
|
- String markingType = ExamCacheTransferHelper.
|
|
|
- getDefaultCachedExamProperty(examStudent.getExamId(), ExamProperties.MARKING_TYPE.name()).getValue();
|
|
|
+
|
|
|
+ String markingType = ExamCacheTransferHelper.getDefaultCachedExamProperty(examStudent.getExamId(),
|
|
|
+ ExamProperties.MARKING_TYPE.name()).getValue();
|
|
|
String examType = ExamCacheTransferHelper.getDefaultCachedExam(examStudent.getExamId()).getExamType();
|
|
|
- List<ExamRecordDataEntity> effectiveExamRecordDataList = examRecordDataRepo.findEffectiveDataByExamStudentIdList(Arrays.asList(examStudentId));
|
|
|
|
|
|
- if (LOG.isDebugEnabled()) {
|
|
|
- if (null != effectiveExamRecordDataList) {
|
|
|
- LOG.debug("[TEMP-DEBUG1]-effectiveExamRecordDataList: " + JsonUtil.toJson(effectiveExamRecordDataList));
|
|
|
- } else {
|
|
|
- LOG.debug("[TEMP-DEBUG1]-考生id:" + examStudentId + ",找不到任何考试记录");
|
|
|
- }
|
|
|
+ List<ExamRecordDataEntity> effectiveExamRecordDataList = examRecordDataRepo.findEffectiveDataByExamStudentIdList(Arrays.asList(examStudentId));
|
|
|
+ if (CollectionUtils.isEmpty(effectiveExamRecordDataList)) {
|
|
|
+ LOG.warn("calcAndSaveFinalScore examRecordDataList is empty, examStudentId = {}", examStudentId);
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//得到最终考试结果
|
|
|
ExamScoreEntity finalEffectiveExamScore = getFinalEffectiveExamScore(effectiveExamRecordDataList, examType, markingType);
|
|
|
-
|
|
|
- if (LOG.isDebugEnabled()) {
|
|
|
- if (null != finalEffectiveExamScore) {
|
|
|
- LOG.debug("[TEMP-DEBUG2]-finalEffectiveExamScore: " + JsonUtil.toJson(finalEffectiveExamScore));
|
|
|
- } else {
|
|
|
- LOG.debug("[TEMP-DEBUG2]-考生id:" + examStudentId + ",找不到最终考试记录");
|
|
|
- }
|
|
|
+ if (finalEffectiveExamScore == null) {
|
|
|
+ LOG.warn("calcAndSaveFinalScore finalExamScore is null, examStudentId = {}", examStudentId);
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
//保存最终考试结果
|
|
|
- return saveExamStudentFinalScore(examStudent.getExamStudentId(), finalEffectiveExamScore);
|
|
|
+ return saveExamStudentFinalScore(examStudentId, finalEffectiveExamScore);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public ExamStudentFinalScoreEntity getFinalEffectiveExamScore(Long examStudentId) {
|
|
|
ExamStudentFinalScoreEntity finalExamScore = examStudentFinalScoreRepo.findByExamStudentId(examStudentId);
|
|
|
-
|
|
|
if (null != finalExamScore) {
|
|
|
return finalExamScore;
|
|
|
}
|
|
@@ -90,73 +83,63 @@ public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreSe
|
|
|
return this.calcAndSaveFinalScore(examStudentId);
|
|
|
}
|
|
|
|
|
|
- private ExamStudentFinalScoreEntity saveExamStudentFinalScore(Long examStudentId, final ExamScoreEntity finalEffectiveExamScore) {
|
|
|
- ExamStudentFinalScoreEntity finalScoreEntity
|
|
|
- = examStudentFinalScoreRepo.findByExamStudentId(examStudentId);
|
|
|
+ private ExamStudentFinalScoreEntity saveExamStudentFinalScore(Long examStudentId, ExamScoreEntity finalEffectiveExamScore) {
|
|
|
+ if (finalEffectiveExamScore == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamStudentFinalScoreEntity finalScoreEntity = examStudentFinalScoreRepo.findByExamStudentId(examStudentId);
|
|
|
if (finalScoreEntity == null) {
|
|
|
finalScoreEntity = new ExamStudentFinalScoreEntity();
|
|
|
}
|
|
|
|
|
|
- if (null != finalEffectiveExamScore) {
|
|
|
- finalScoreEntity.setExamRecordDataId(finalEffectiveExamScore.getExamRecordDataId());
|
|
|
- finalScoreEntity.setExamStudentId(examStudentId);
|
|
|
- finalScoreEntity.setObjectiveAccuracy(finalEffectiveExamScore.getObjectiveAccuracy());
|
|
|
- finalScoreEntity.setObjectiveScore(finalEffectiveExamScore.getObjectiveScore());
|
|
|
- finalScoreEntity.setSubjectiveScore(finalEffectiveExamScore.getSubjectiveScore());
|
|
|
- finalScoreEntity.setSuccPercent(finalEffectiveExamScore.getSuccPercent());
|
|
|
- finalScoreEntity.setTotalScore(finalEffectiveExamScore.getTotalScore());
|
|
|
-
|
|
|
- return examStudentFinalScoreRepo.save(finalScoreEntity);
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
+ finalScoreEntity.setExamRecordDataId(finalEffectiveExamScore.getExamRecordDataId());
|
|
|
+ finalScoreEntity.setExamStudentId(examStudentId);
|
|
|
+ finalScoreEntity.setObjectiveAccuracy(finalEffectiveExamScore.getObjectiveAccuracy());
|
|
|
+ finalScoreEntity.setObjectiveScore(finalEffectiveExamScore.getObjectiveScore());
|
|
|
+ finalScoreEntity.setSubjectiveScore(finalEffectiveExamScore.getSubjectiveScore());
|
|
|
+ finalScoreEntity.setSuccPercent(finalEffectiveExamScore.getSuccPercent());
|
|
|
+ finalScoreEntity.setTotalScore(finalEffectiveExamScore.getTotalScore());
|
|
|
|
|
|
+ return examStudentFinalScoreRepo.save(finalScoreEntity);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 计算得出最终有效成绩
|
|
|
*/
|
|
|
private ExamScoreEntity getFinalEffectiveExamScore(List<ExamRecordDataEntity> effectiveExamRecordList, String examType, String markingType) {
|
|
|
if (effectiveExamRecordList == null || effectiveExamRecordList.size() == 0) {
|
|
|
- if (LOG.isDebugEnabled()) {
|
|
|
- LOG.debug("[TEMP-DEBUG1]-effectiveExamRecordList-考生找不到满足条件考试记录");
|
|
|
- }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//取出有效记录的id
|
|
|
- List<Long> examRecordDataIds =
|
|
|
- effectiveExamRecordList.stream().map(ExamRecordDataEntity::getId).collect(Collectors.toList());
|
|
|
+ List<Long> examRecordDataIds = effectiveExamRecordList.stream().map(ExamRecordDataEntity::getId).collect(Collectors.toList());
|
|
|
|
|
|
List<ExamScoreEntity> effectiveExamScoreList = examScoreRepo.findByExamRecordDataIdIn(examRecordDataIds);
|
|
|
if (effectiveExamScoreList == null || effectiveExamScoreList.size() == 0) {
|
|
|
- if (LOG.isDebugEnabled()) {
|
|
|
- LOG.debug("[TEMP-DEBUG5]-effectiveExamScoreList-考生找不到满足条件考试分数记录");
|
|
|
- }
|
|
|
+ LOG.warn("effectiveExamScoreList is empty, examRecordDataIds = {}", examRecordDataIds);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//离线考试
|
|
|
- if ("OFFLINE".equals(examType)) {
|
|
|
+ if (ExamType.OFFLINE.name().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);
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
|