Bladeren bron

增加考试改变zset

wangliang 1 jaar geleden
bovenliggende
commit
054a2b2dd8

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/service/TEExamSummaryService.java

@@ -21,6 +21,7 @@ public interface TEExamSummaryService extends IService<TEExamSummary> {
      * @param examId
      * @param examActivityId
      * @param roomCodeSet
+     * @return
      */
-    void examSummary(Long examId, Long examActivityId, Set<String> roomCodeSet);
+    boolean examSummary(Long examId, Long examActivityId, Set<String> roomCodeSet);
 }

+ 15 - 0
themis-business/src/main/java/com/qmth/themis/business/service/ThemisCacheService.java

@@ -532,4 +532,19 @@ public interface ThemisCacheService {
      * @param roomCode
      */
     public void removeExamSummaryAllCache(Long examId, Long examActivityId, String roomCode);
+
+    /**
+     * 考试记录改变cache
+     *
+     * @param key
+     * @param timestamp
+     */
+    public void addExamRecordChangeCache(String key, Long timestamp);
+
+    /**
+     * 获取考试记录score
+     *
+     * @param key
+     */
+    public Long getExamRecordChangeCache(String key);
 }

+ 15 - 6
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamSummaryServiceImpl.java

@@ -47,18 +47,27 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
      * @param examId
      * @param examActivityId
      * @param roomCodeSet
+     * @return
      */
     @Override
-    public void examSummary(Long examId, Long examActivityId, Set<String> roomCodeSet) {
+    public boolean examSummary(Long examId, Long examActivityId, Set<String> roomCodeSet) {
+        boolean updateCache = false;
         if (!CollectionUtils.isEmpty(roomCodeSet)) {
             for (String s : roomCodeSet) {
-                //根据考试批次、场次、考场编码统计信息
-                TEExamSummary teExamSummary = this.baseMapper.examSummary(examId, examActivityId, s);
-                this.examSummaryCommon(examId, examActivityId, s, teExamSummary);
+                Long l = themisCacheService.getExamRecordChangeCache(examActivityId + "_" + s);
+                if (Objects.nonNull(l) && System.currentTimeMillis() - l.longValue() <= 1000 * 60 * 1) {
+                    //根据考试批次、场次、考场编码统计信息
+                    TEExamSummary teExamSummary = this.baseMapper.examSummary(examId, examActivityId, s);
+                    this.examSummaryCommon(examId, examActivityId, s, teExamSummary);
+                    updateCache = true;
+                }
+            }
+            if (updateCache) {
+                themisCacheService.updateExamSummaryCache(examId);
+                themisCacheService.updateExamSummaryCache(examId, examActivityId);
             }
-            themisCacheService.updateExamSummaryCache(examId);
-            themisCacheService.updateExamSummaryCache(examId, examActivityId);
         }
+        return updateCache;
     }
 
     /**

+ 4 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -439,6 +439,10 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
             }
             themisCacheService.updateOrgSummaryCache(0L);
 
+            Long examActivityId = ExamRecordCacheUtil.getExamActivityId(recordId);
+            String examRecordChangeKey = examActivityId + "_" + examStudentCache.getRoomCode();
+            themisCacheService.addExamRecordChangeCache(examRecordChangeKey, timestamp);
+
             //上传个人试卷结构
             if (Objects.nonNull(struct)) {
                 ossUtil.upload(false, structFilePath, struct.getContent());

+ 23 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java

@@ -1077,4 +1077,27 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
         this.removeExamSummaryCache(examId, examActivityId);
         this.removeExamSummaryCache(examId, examActivityId, roomCode);
     }
+
+    /**
+     * 考试记录改变cache
+     *
+     * @param key
+     * @param timestamp
+     */
+    @Override
+    public void addExamRecordChangeCache(String key, Long timestamp) {
+        redisUtil.setZset(key, key, timestamp);
+    }
+
+    /**
+     * 获取考试记录score
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public Long getExamRecordChangeCache(String key) {
+        Double d = redisUtil.getZset(key, key);
+        return Objects.nonNull(d) ? d.longValue() : null;
+    }
 }

+ 32 - 0
themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java

@@ -90,6 +90,38 @@ public class RedisUtil {
         redisTemplate.opsForHash().put(key, hashKey, hashValue);
     }
 
+    /**
+     * 设置zset
+     *
+     * @param key
+     * @param hashValue
+     * @param score
+     */
+    public void setZset(String key, Object hashValue, double score) {
+        redisTemplate.opsForZSet().add(key, hashValue, score);
+        this.expire(key, 1, TimeUnit.HOURS);
+    }
+
+    /**
+     * 获取zset
+     *
+     * @param key
+     * @param hashValue
+     */
+    public Double getZset(String key, Object hashValue) {
+        return redisTemplate.opsForZSet().score(key, hashValue);
+    }
+
+    /**
+     * 获取zset大小
+     *
+     * @param key
+     */
+    public Long getZsetSize(String key) {
+        return redisTemplate.opsForZSet().size(key);
+    }
+
+
     /**
      * 设置hash
      *

+ 9 - 0
themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

@@ -135,6 +135,9 @@ public class MqLogicServiceImpl implements MqLogicService {
     @Resource
     TIeExamMediaLogService tIeExamMediaLogService;
 
+    @Resource
+    ThemisCacheService themisCacheService;
+
     /**
      * mq最大重试次数逻辑
      *
@@ -669,6 +672,7 @@ public class MqLogicServiceImpl implements MqLogicService {
             Long recordId = Long.parseLong(String.valueOf(param.get(SystemConstant.RECORD_ID)));
             Long studentId = Long.parseLong(String.valueOf(param.get(SystemConstant.STUDENT_ID)));
             commonService.persisted(recordId, studentId);
+
             tmRocketMessageService.saveMqMessageSuccess(mqDto, key);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
@@ -712,6 +716,11 @@ public class MqLogicServiceImpl implements MqLogicService {
                 examRecordService.examRecordDataSave(recordId);
             }
             tIpRegionService.saveIpRegion(recordId);
+            Long examActivityId = ExamRecordCacheUtil.getExamActivityId(recordId);
+            Long examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
+            ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
+            String examRecordChangeKey = examActivityId + "_" + examStudentCacheBean.getRoomCode();
+            themisCacheService.addExamRecordChangeCache(examRecordChangeKey, mqDto.getTimestamp().longValue());
         }
         tmRocketMessageService.saveMqMessageSuccess(mqDto, key);
     }

+ 12 - 10
themis-task/src/main/java/com/qmth/themis/task/quartz/ExamSummaryJob.java

@@ -79,16 +79,18 @@ public class ExamSummaryJob extends QuartzJobBean {
                         log.info("examSummaryJob examId:{},examActivityId:{},startTime:{},endTime:{}", examId, e.getExamActivityId(), DateUtil.format(new Date(startTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(endTime), "yyyy-MM-dd HH:mm:ss"));
                         if (startTime <= timestamp && endTime >= timestamp) {
                             log.info("examSummaryJob examId:{},examActivityId:{},roomCodeSet:{} 开始统计", examId, e.getExamActivityId(), roomCodeSet);
-                            teExamSummaryService.examSummary(examId, e.getExamActivityId(), roomCodeSet);
-                            teRegionSummaryService.regionSummary(examId, e.getExamActivityId());
-                            //统计机构信息
-                            if (orgExamIdMap.size() > 0) {
-                                List<Long> examIdAll = new ArrayList<>();
-                                orgExamIdMap.forEach((k, v) -> {
-                                    teOrgSummaryService.orgSummary(k, v);
-                                    examIdAll.addAll(v);
-                                });
-                                teOrgSummaryService.orgSummary(0L, examIdAll);
+                            boolean change = teExamSummaryService.examSummary(examId, e.getExamActivityId(), roomCodeSet);
+                            if (change) {
+                                teRegionSummaryService.regionSummary(examId, e.getExamActivityId());
+                                //统计机构信息
+                                if (orgExamIdMap.size() > 0) {
+                                    List<Long> examIdAll = new ArrayList<>();
+                                    orgExamIdMap.forEach((k, v) -> {
+                                        teOrgSummaryService.orgSummary(k, v);
+                                        examIdAll.addAll(v);
+                                    });
+                                    teOrgSummaryService.orgSummary(0L, examIdAll);
+                                }
                             }
                         } else if (endTime <= timestamp) {//超过考试结束时间则删除考试场次缓存
                             themisCacheService.removeCurrentExamListCache(entry.getKey(), e.getExamActivityId());