Răsfoiți Sursa

在线考试考试分数列表优化

lideyin 5 ani în urmă
părinte
comite
a45471fa35

+ 48 - 7
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/ExamScoreController.java

@@ -17,9 +17,11 @@ import cn.com.qmth.examcloud.core.oe.admin.service.ExamScoreService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ExamScoreInfo;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ExamScoreQuery;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ObjectiveScoreInfo;
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
 import cn.com.qmth.examcloud.support.enums.ExamRecordStatus;
 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 cn.com.qmth.examcloud.web.support.ControllerSupport;
@@ -76,6 +78,7 @@ public class ExamScoreController extends ControllerSupport {
 
         List<ObjectiveScoreInfo> resultList = examScoreService.queryObjectiveScoreList(examStudentId);
 
+
         //如果有未处理完成的考试记录,需要将未处理的考试记录数据添加到列表中
         String examBossKey = RedisKeyHelper.getBuilder().examBossKey(examStudentId);
         ExamBoss examBoss = redisClient.get(examBossKey, ExamBoss.class);
@@ -86,8 +89,26 @@ public class ExamScoreController extends ControllerSupport {
                 //正序排列
                 unSyncedExamRecordDataIds.sort(Long::compareTo);
 
+                //已考次数
+                Integer examUsedNum = 0;
+
                 for (Long examRecordDataId : unSyncedExamRecordDataIds) {
-                    resultList.add(0, getCachedObjectiveScoreInfo(examRecordDataId));
+
+                    if (!resultList.isEmpty()) {
+                        examUsedNum = resultList.get(0).getExamOrder();
+                    }
+
+                    ExamRecordData examRecordData =
+                            redisClient.get(RedisKeyHelper.getBuilder().examRecordDataKey(examRecordDataId), ExamRecordData.class);
+                    if (null == examRecordData) {
+                        throw new StatusException("100001", "考试记录的缓存数据有误");
+                    }
+
+                    ObjectiveScoreInfo cachedObjectiveScoreInfo = getCachedObjectiveScoreInfo(examRecordData);
+                    cachedObjectiveScoreInfo.setExamOrder(
+                            getExamOrder(examRecordData.getExamId(), examRecordData.getStudentId(), examUsedNum));
+
+                    resultList.add(0, cachedObjectiveScoreInfo);
                 }
             }
         }
@@ -95,14 +116,13 @@ public class ExamScoreController extends ControllerSupport {
         return resultList;
     }
 
-    private ObjectiveScoreInfo getCachedObjectiveScoreInfo(Long examRecordDataId) {
-        ExamRecordData examRecordData =
-                redisClient.get(RedisKeyHelper.getBuilder().examRecordDataKey(examRecordDataId), ExamRecordData.class);
-        if (null == examRecordData) {
-            throw new StatusException("100001","考试记录的缓存数据有误");
-        }
+    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)) {
@@ -138,4 +158,25 @@ public class ExamScoreController extends ControllerSupport {
         return false;
     }
 
+    /**
+     * 计算考试次数
+     *
+     * @param examId      考试id
+     * @param studentId   学生id
+     * @param usedExamNum 已考次数
+     * @return
+     */
+    private Integer getExamOrder(Long examId, Long studentId, Integer usedExamNum) {
+        ExamSettingsCacheBean cachedExam = ExamCacheTransferHelper.getCachedExam(examId, studentId);
+        Integer canExamTimes = cachedExam.getExamTimes() == null ? 0 : cachedExam.getExamTimes().intValue();//可考次数
+
+        //超过或等于可考次数,始终为可考次数+1
+        if (usedExamNum >= canExamTimes) {
+            return canExamTimes + 1;
+        }
+
+        return usedExamNum + 1;
+
+    }
+
 }