소스 검색

修复0心跳无法自动交卷的bug

lideyin 5 년 전
부모
커밋
cf60327809

+ 19 - 8
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/ExamControlServiceImpl.java

@@ -322,6 +322,9 @@ public class ExamControlServiceImpl implements ExamControlService {
             log.debug("9 初始化考试会话耗时:" + (System.currentTimeMillis() - startTime) + " ms");
         }
 
+        //设置并保存上次活动时间
+        setAndSaveActiveTime(examRecordData.getId());
+
         if (log.isDebugEnabled()) {
             log.debug("10 合计 耗时:" + (System.currentTimeMillis() - st) + " ms");
         }
@@ -1432,23 +1435,31 @@ public class ExamControlServiceImpl implements ExamControlService {
 
         redisClient.set(examingHeartbeatKey, examingHeartbeat);
 
+        setAndSaveActiveTime(examSessionInfo.getExamRecordDataId());
+
+        // 在线考生心跳打点
+        ReportsUtil.report(new OnlineExamStudentReport(user.getRootOrgId(), user.getUserId(),
+                examSessionInfo.getExamId(), examSessionInfo.getExamStudentId()));
+        // 返回考试剩余时间
+        return examSessionInfo.getExamDuration() - (examingHeartbeat.getCost() * 1000);
+    }
+
+    /**
+     * 设置并保存活动时间
+     * @param examRecrodDataId 考试记录id
+     */
+    private void setAndSaveActiveTime(Long examRecrodDataId) {
         String examingActiveTimeKey = RedisKeyHelper.getBuilder()
-                .examingActiveTimeKey(examSessionInfo.getExamRecordDataId());
+                .examingActiveTimeKey(examRecrodDataId);
         ExamingActivityTime examingActiveTime = redisClient.get(examingActiveTimeKey,
                 ExamingActivityTime.class);
         if (null == examingActiveTime) {
             examingActiveTime = new ExamingActivityTime();
-            examingActiveTime.setExamRecordDataId(examSessionInfo.getExamRecordDataId());
+            examingActiveTime.setExamRecordDataId(examRecrodDataId);
         }
         examingActiveTime.setActiveTime(System.currentTimeMillis());
 
         redisClient.set(examingActiveTimeKey, examingActiveTime);
-
-        // 在线考生心跳打点
-        ReportsUtil.report(new OnlineExamStudentReport(user.getRootOrgId(), user.getUserId(),
-                examSessionInfo.getExamId(), examSessionInfo.getExamStudentId()));
-        // 返回考试剩余时间
-        return examSessionInfo.getExamDuration() - (examingHeartbeat.getCost() * 1000);
     }
 
     /**