Browse Source

未完成考试记录id缓存从学生缓存单独出来

xiatian 4 năm trước cách đây
mục cha
commit
346cdb2221

+ 28 - 0
themis-business/src/main/java/com/qmth/themis/business/cache/ExamingDataCacheUtil.java

@@ -0,0 +1,28 @@
+package com.qmth.themis.business.cache;
+
+import com.qmth.themis.business.constant.SpringContextHolder;
+import com.qmth.themis.business.util.RedisUtil;
+
+/**
+ * 考试中数据缓存值操作
+ *
+ * @Description:
+ * @Author: xiatian
+ * @Date: 2020-07-29
+ */
+public class ExamingDataCacheUtil {
+    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
+
+    public static void deleteUnFinishedRecordId(Long studentId) {
+        redisUtil.delete(RedisKeyHelper.unFinishedRecordIdCacheKey(studentId));
+    }
+    
+    public static void setUnFinishedRecordId(Long studentId, Long examRecordId) {
+        redisUtil.set(RedisKeyHelper.unFinishedRecordIdCacheKey(studentId), examRecordId);
+    }
+
+    public static Long getUnFinishedRecordId(Long studentId) {
+        return (Long) redisUtil.get(RedisKeyHelper.unFinishedRecordIdCacheKey(studentId));
+    }
+
+}

+ 14 - 0
themis-business/src/main/java/com/qmth/themis/business/cache/RedisKeyHelper.java

@@ -55,6 +55,11 @@ public class RedisKeyHelper {
 	 * 移动端临时认证
 	 */
 	private static String mobileAuthKeyPrefix = "mobile_auth::";
+	
+	/**
+	 * 未完成考试记录id
+	 */
+	private static String unFinishedRecordIdKeyPrefix = "un_finished_record_id::student_id_";
 	/**
 	 * 场次
 	 * 
@@ -175,4 +180,13 @@ public class RedisKeyHelper {
 	public static String mobileAuthCacheKey(MobileModeEnum mode,String code) {
 		return mobileAuthKeyPrefix + mode.name().toLowerCase()+underLine+code;
 	}
+	
+	/**未完成考试记录id key
+	 * @param studentId
+	 * @return
+	 */
+	public static String unFinishedRecordIdCacheKey(Long studentId) {
+		return unFinishedRecordIdKeyPrefix + studentId;
+	}
+	
 }

+ 0 - 21
themis-business/src/main/java/com/qmth/themis/business/dto/cache/TEStudentCacheDto.java

@@ -28,12 +28,6 @@ public class TEStudentCacheDto implements Serializable {
     @ApiModelProperty(name = "学生底照")
     private String basePhotoPath;
 
-    @ApiModelProperty(name = "考试记录id")
-    private Long examingRecordId;
-
-    @ApiModelProperty(name = "未完成的考试记录id")
-    private Long unFinishedRecordId;
-
     public Long getId() {
         return id;
     }
@@ -74,19 +68,4 @@ public class TEStudentCacheDto implements Serializable {
         this.basePhotoPath = basePhotoPath;
     }
 
-    public Long getExamingRecordId() {
-        return examingRecordId;
-    }
-
-    public void setExamingRecordId(Long examingRecordId) {
-        this.examingRecordId = examingRecordId;
-    }
-
-    public Long getUnFinishedRecordId() {
-        return unFinishedRecordId;
-    }
-
-    public void setUnFinishedRecordId(Long unFinishedRecordId) {
-        this.unFinishedRecordId = unFinishedRecordId;
-    }
 }

+ 7 - 6
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.bean.exam.*;
 import com.qmth.themis.business.cache.ExamActivityRecordCacheUtil;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
+import com.qmth.themis.business.cache.ExamingDataCacheUtil;
 import com.qmth.themis.business.cache.RedisKeyHelper;
 import com.qmth.themis.business.cache.bean.*;
 import com.qmth.themis.business.config.SystemConfig;
@@ -184,9 +185,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             throw new BusinessException("考生Id和当前登录用户不一致");
         }
         ExamCacheBean examCache = getExamCacheBean(es.getExamId());
-        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
-        if (teStudentCacheDto.getUnFinishedRecordId() != null) {
-            Long recordId = teStudentCacheDto.getUnFinishedRecordId();
+        Long unFinishedRecordId=ExamingDataCacheUtil.getUnFinishedRecordId(studentId);
+        if (unFinishedRecordId != null) {
+            Long recordId = unFinishedRecordId;
             if (examStudentId.equals(ExamRecordCacheUtil.getExamStudentId(recordId))) {//当前考生已存在候考的考试记录
                 ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(ExamRecordCacheUtil.getPaperId(recordId));
                 ExamCourseCacheBean ec = teExamCourseService.getExamCourseCacheBean(es.getExamId(), es.getCourseCode());
@@ -288,9 +289,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         redisUtil.set(RedisKeyHelper.examStudentCacheKey(examStudentId), es);
         //更新场次-考试记录缓存
         ExamActivityRecordCacheUtil.setExamRecordStatus(activityId, recordId, ExamRecordCacheUtil.getStatus(recordId));
-        teStudentCacheDto.setUnFinishedRecordId(recordId);
-        redisUtil.setStudent(studentId, teStudentCacheDto);
+        ExamingDataCacheUtil.setUnFinishedRecordId(studentId,recordId);
         //mq发送消息start
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(studentId);
         MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.STUDENT.name(), SystemOperationEnum.FIRST_PREPARE, MqTagEnum.STUDENT, String.valueOf(teStudentCacheDto.getId()), teStudentCacheDto.getIdentity());
         this.sendOeLogMessage(SystemOperationEnum.FIRST_PREPARE, examStudentId, recordId, mqDto);
         updateExamStudent(examStudentId, alreadyExamCount, recordId);
@@ -749,7 +750,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         ExamActivityRecordCacheUtil.setExamRecordStatus(es.getExamActivityId(), recordId, ExamRecordCacheUtil.getStatus(recordId));
         //更新未完成考试记录id
         TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
-        teStudentCacheDto.setUnFinishedRecordId(null);
+        ExamingDataCacheUtil.deleteUnFinishedRecordId(studentId);
         redisUtil.setStudent(teStudentCacheDto.getId(), teStudentCacheDto);
         //异步持久化
         checkToPersisted(recordId);

+ 3 - 3
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -7,6 +7,7 @@ import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.bean.exam.ExamActivityUnFinishBean;
 import com.qmth.themis.business.bean.exam.ExamUnFinishBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
+import com.qmth.themis.business.cache.ExamingDataCacheUtil;
 import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
@@ -195,14 +196,14 @@ public class TEStudentController {
         String test = SignatureInfo.build(SignatureType.TOKEN, sessionId, token);
         Map<String, Object> map = new HashMap<>();
         //获取未完考试
-        if (Objects.isNull(teStudentCacheDto.getUnFinishedRecordId())) {
+        if (Objects.isNull(ExamingDataCacheUtil.getUnFinishedRecordId(teStudent.getId()))) {
             //获取待考列表
             List<TEExamDto> list = teExamService.getWaitingExam(teStudent.getId(), examId, orgId);
             if (Objects.nonNull(list) && list.size() > 0) {
                 map.put("waiting", list);
             }
         } else {
-            Long recordId = teStudentCacheDto.getUnFinishedRecordId();
+            Long recordId = ExamingDataCacheUtil.getUnFinishedRecordId(teStudent.getId());
             //获取考试记录缓存
             ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(recordId);
             if (Objects.isNull(status)) {
@@ -283,7 +284,6 @@ public class TEStudentController {
         if (Objects.isNull(tbSession)) {
             throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
         }
-        Long recordId = Objects.isNull(teStudent.getExamingRecordId()) ? teStudent.getUnFinishedRecordId() : teStudent.getExamingRecordId();
         AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.studentOauth + "::" + teStudent.getId());
         redisUtil.deleteUserSession(tbSession.getId());
         //循环检查该用户下其他平台是否存在session,不存在则删除用户缓存和鉴权缓存