Explorar el Código

清理缓存stream清理更多数据

lideyin hace 5 años
padre
commit
92116be879

+ 38 - 25
examcloud-core-oe-task-service/src/main/java/cn/com/qmth/examcloud/core/oe/task/service/pipeline/ClearExamDataCacheExecutor.java

@@ -6,12 +6,13 @@ import cn.com.qmth.examcloud.commons.helpers.pipeline.NodeExecuter;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.TaskContext;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
-import cn.com.qmth.examcloud.core.oe.task.service.ExamBossService;
 import cn.com.qmth.examcloud.support.Constants;
 import cn.com.qmth.examcloud.support.enums.SyncStatus;
 import cn.com.qmth.examcloud.support.examing.ExamBoss;
 import cn.com.qmth.examcloud.support.examing.ExamRecordData;
+import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
 import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
+import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -27,7 +28,7 @@ import java.util.List;
 public class ClearExamDataCacheExecutor implements NodeExecuter<Long, ExamRecordData, Long, ExamRecordData> {
 
     @Autowired
-    private ExamBossService examBossService;
+    private RedisClient redisClient;
     private static final ExamCloudLog LOG = ExamCloudLogFactory.getLog(ClearExamDataCacheExecutor.class);
 
     /**
@@ -49,49 +50,61 @@ public class ClearExamDataCacheExecutor implements NodeExecuter<Long, ExamRecord
         String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + examRecordData.getStudentId();
 
         try {
-            debugLog("enter executor...", examRecordData.getId());
+            Long examRecordDataId = examRecordData.getId();
+            debugLog("enter executor...", examRecordDataId);
 
             //添加考试控制全局锁
             SequenceLockHelper.getLockSimple(sequenceLockKey);
 
-            debugLog("get locker success...", examRecordData.getId());
+            debugLog("get locker success...", examRecordDataId);
 
             //只有已同步成功的数据,才执行清理操作
             if (SyncStatus.SYNCED == examRecordData.getSyncStatus()) {
 
-                clearExamCache(examRecordData.getExamStudentId());
+                //清除考试次数相关缓存
+                String examBossKey = RedisKeyHelper.getBuilder().examBossKey(examRecordData.getExamStudentId());
+                ExamBoss examBoss = redisClient.get(examBossKey, ExamBoss.class);
+                if (null != examBoss) {
+                    //如果开考次数==考试完结次数,则删除考试基础信息缓存
+                    if (examBoss.getStartCount() == examBoss.getEndCount()) {
+                        redisClient.delete(examBossKey);
+                    }
+                }
 
-                this.debugLog("all is over.", examRecordData.getId());
+                //清除学生最后活动时间缓存
+                redisClient.delete(RedisKeyHelper.getBuilder().examingActiveTimeKey(examRecordDataId));
+
+                //清除心跳缓存
+                redisClient.delete(RedisKeyHelper.getBuilder().examingHeartbeatKey(examRecordDataId));
+
+                //清除考试会话缓存
+                redisClient.delete(RedisKeyHelper.getBuilder().examingSessionKey(examRecordData.getStudentId()));
+
+                //清除文件作答记录缓存
+                Integer quesCount = examRecordData.getQuestionCount();
+                for (int i = 1; i <= quesCount; i++) {
+                    redisClient.delete(RedisKeyHelper.getBuilder().studentFileAnswerKey(examRecordDataId, i));
+                }
+
+                //清除网考试卷结构
+                redisClient.delete(RedisKeyHelper.getBuilder().studentPaperKey(examRecordDataId));
+
+                //清除考试记录缓存
+                redisClient.delete(RedisKeyHelper.getBuilder().examRecordDataKey(examRecordDataId));
+
+                this.debugLog("all is over.", examRecordDataId);
 
                 return;
             }
 
             this.debugLog("current status is '" + examRecordData.getExamRecordStatus().name() +
-                    "'.may be redundant data.", examRecordData.getId());
+                    "'.may be redundant data.", examRecordDataId);
 
         } finally {
             SequenceLockHelper.releaseLockSimple(sequenceLockKey);
         }
     }
 
-    /**
-     * 考试id
-     *
-     * @param examId
-     */
-    private void clearExamCache(Long examId) {
-        ExamBoss examBoss = examBossService.getExamBoss(examId);
-
-        if (null == examBoss) {
-            return;
-        }
-
-        //如果开考次数==考试完结次数,则删除考试基础信息缓存
-        if (examBoss.getStartCount() == examBoss.getEndCount()) {
-            examBossService.deleteExamBoss(examId);
-        }
-    }
-
     private void debugLog(String msg, Long examRecordDataId) {
         if (LOG.isDebugEnabled()) {
             LOG.debug("[CLEAR-EXAM-DATA-CACHE-EXECUTOR-" + examRecordDataId + "]:" + msg);