|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.jpa.SpecUtils;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.CommonUtil;
|
|
@@ -28,7 +29,11 @@ import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamBoss;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
|
|
|
import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
+import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
+import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -73,6 +78,9 @@ public class ExamScoreServiceImpl implements ExamScoreService {
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExamStudentFinalScoreService examStudentFinalScoreService;
|
|
|
|
|
@@ -486,6 +494,8 @@ public class ExamScoreServiceImpl implements ExamScoreService {
|
|
|
|
|
|
@Override
|
|
|
public List<ObjectiveScoreInfo> queryObjectiveScoreList(Long examStudentId) {
|
|
|
+ Check.isNull(examStudentId, "examStudentId 不能为空");
|
|
|
+
|
|
|
List<ExamRecordDataEntity> examRecordDataList = examRecordDataRepo.findByExamStudentId(examStudentId);
|
|
|
//过滤已完成的考试记录(包括违纪的)
|
|
|
examRecordDataList = examRecordDataList.stream().filter((o -> {
|
|
@@ -495,7 +505,7 @@ public class ExamScoreServiceImpl implements ExamScoreService {
|
|
|
o.getExamRecordStatus() == ExamRecordStatus.EXAM_AUTO_HAND_IN;
|
|
|
})).collect(Collectors.toList());
|
|
|
|
|
|
- List<ObjectiveScoreInfo> objectiveScoreInfoList = new ArrayList<ObjectiveScoreInfo>();
|
|
|
+ List<ObjectiveScoreInfo> objectiveScoreInfoList = new ArrayList<>();
|
|
|
for (ExamRecordDataEntity examRecordDataEntity : examRecordDataList) {
|
|
|
ObjectiveScoreInfo objectiveScoreInfo = new ObjectiveScoreInfo();
|
|
|
objectiveScoreInfo.setExamRecordDataId(examRecordDataEntity.getId());
|
|
@@ -526,9 +536,117 @@ public class ExamScoreServiceImpl implements ExamScoreService {
|
|
|
}
|
|
|
objectiveScoreInfoList.add(objectiveScoreInfo);
|
|
|
}
|
|
|
+
|
|
|
+ processObjectiveScoreList(examStudentId, objectiveScoreInfoList);
|
|
|
+
|
|
|
return objectiveScoreInfoList;
|
|
|
}
|
|
|
|
|
|
+ private void processObjectiveScoreList(Long examStudentId, List<ObjectiveScoreInfo> resultList) {
|
|
|
+ //如果有未处理完成的考试记录,需要将未处理的考试记录数据添加到列表中
|
|
|
+ String examBossKey = RedisKeyHelper.getBuilder().examBossKey(examStudentId);
|
|
|
+ ExamBoss examBoss = redisClient.get(examBossKey, ExamBoss.class);
|
|
|
+ if (null != examBoss) {
|
|
|
+ //未完全同步的考试记录id
|
|
|
+ List<Long> unSyncedExamRecordDataIds = examBoss.getExamRecordDataIds();
|
|
|
+ if (null != unSyncedExamRecordDataIds && !unSyncedExamRecordDataIds.isEmpty()) {
|
|
|
+ //正序排列
|
|
|
+ unSyncedExamRecordDataIds.sort(Long::compareTo);
|
|
|
+
|
|
|
+ //已考次数
|
|
|
+ Integer examUsedNum = 0;
|
|
|
+
|
|
|
+ for (Long examRecordDataId : unSyncedExamRecordDataIds) {
|
|
|
+ ExamRecordData examRecordData =
|
|
|
+ redisClient.get(RedisKeyHelper.getBuilder().examRecordDataKey(examRecordDataId),
|
|
|
+ ExamRecordData.class);
|
|
|
+ if (null == examRecordData) {
|
|
|
+ throw new StatusException("100001", "考试记录的缓存数据有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //考试中的数据不展示
|
|
|
+ if (cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_ING == examRecordData.getExamRecordStatus()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!resultList.isEmpty()) {
|
|
|
+ examUsedNum = resultList.get(resultList.size() - 1).getExamOrder();
|
|
|
+ }
|
|
|
+
|
|
|
+ ObjectiveScoreInfo cachedObjectiveScoreInfo = getCachedObjectiveScoreInfo(examRecordData);
|
|
|
+ cachedObjectiveScoreInfo.setExamOrder(
|
|
|
+ getExamOrder(examRecordData.getExamId(), examRecordData.getStudentId(), examUsedNum));
|
|
|
+
|
|
|
+ resultList.add(cachedObjectiveScoreInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObjectiveScoreInfo getCachedObjectiveScoreInfo(final ExamRecordData examRecordData) {
|
|
|
+ ObjectiveScoreInfo objectiveScoreInfo = new ObjectiveScoreInfo();
|
|
|
+ objectiveScoreInfo.setExamRecordDataId(examRecordData.getId());
|
|
|
+ objectiveScoreInfo.setStartTime(examRecordData.getStartTime());
|
|
|
+ objectiveScoreInfo.setEndTime(examRecordData.getEndTime());
|
|
|
+
|
|
|
+ //如果考试没有结束,则只能返回部分数据
|
|
|
+ if (!isExamRecordEnded(examRecordData)) {
|
|
|
+ objectiveScoreInfo.setIsExamEnded(false);
|
|
|
+ return objectiveScoreInfo;
|
|
|
+ } else {
|
|
|
+ objectiveScoreInfo.setIsExamEnded(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (examRecordData.getIsIllegality() == null || !examRecordData.getIsIllegality()) {
|
|
|
+ if ((null != examRecordData.getIsWarn() && !examRecordData.getIsWarn())
|
|
|
+ || (null != examRecordData.getIsWarn() && examRecordData.getIsWarn()
|
|
|
+ && null != examRecordData.getIsAudit() && examRecordData.getIsAudit())) {
|
|
|
+ objectiveScoreInfo.setIsAuditing(true);
|
|
|
+
|
|
|
+ //缓存中的分数是存储在临时考试记录表中的,所以需要从考试记录缓存中取
|
|
|
+ objectiveScoreInfo.setObjectiveScore(examRecordData.getObjectiveScore());
|
|
|
+ } else {
|
|
|
+ objectiveScoreInfo.setIsAuditing(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ objectiveScoreInfo.setIsIllegality(false);
|
|
|
+ } else {
|
|
|
+ objectiveScoreInfo.setIsIllegality(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ return objectiveScoreInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算考试次数
|
|
|
+ *
|
|
|
+ * @param examId 考试id
|
|
|
+ * @param studentId 学生id
|
|
|
+ * @param usedExamNum 已考次数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Integer getExamOrder(Long examId, Long studentId, Integer usedExamNum) {
|
|
|
+ ExamSettingsCacheBean cachedExam = ExamCacheTransferHelper.getDefaultCachedExam(examId);
|
|
|
+ Integer canExamTimes = cachedExam.getExamTimes() == null ? 0 : cachedExam.getExamTimes().intValue();//可考次数
|
|
|
+
|
|
|
+ //超过可考次数,始终为可考次数+1
|
|
|
+ if (usedExamNum > canExamTimes) {
|
|
|
+ return canExamTimes;
|
|
|
+ }
|
|
|
+
|
|
|
+ return usedExamNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isExamRecordEnded(ExamRecordData examRecordData) {
|
|
|
+ //如果考试记录状态为已处理,则直接返回true.
|
|
|
+ if (examRecordData.getExamRecordStatus() == cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_END ||
|
|
|
+ examRecordData.getExamRecordStatus() == cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_OVERDUE ||
|
|
|
+ examRecordData.getExamRecordStatus() == cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_INVALID) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private boolean isExamRecordEnded(ExamRecordDataEntity examRecordData) {
|
|
|
//如果考试记录状态为已处理,则直接返回true.
|
|
|
if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_END ||
|