Răsfoiți Sursa

修复正在考试IDBUG

wangliang 3 ani în urmă
părinte
comite
85cbeba884

+ 16 - 4
themis-business/src/main/java/com/qmth/themis/business/cache/ExamingDataCacheUtil.java

@@ -26,11 +26,23 @@ public class ExamingDataCacheUtil {
         return (Long) redisUtil.get(RedisKeyHelper.unFinishedRecordIdCacheKey(studentId));
     }
 
-    public static TEStudentCacheDto getStudentExaming(Long studentId) {
-        return (TEStudentCacheDto) redisUtil.get(RedisKeyHelper.studentCacheKey(studentId));
+    public static void deleteExamingRecordId(Long studentId) {
+        redisUtil.delete(RedisKeyHelper.examingRecordIdCacheKey(studentId));
     }
 
-    public static void setStudentExaming(Long studentId, TEStudentCacheDto teStudentCacheDto) {
-        redisUtil.set(RedisKeyHelper.studentCacheKey(studentId), teStudentCacheDto);
+    public static void setExamingRecordId(Long studentId, Long examRecordId) {
+        redisUtil.set(RedisKeyHelper.examingRecordIdCacheKey(studentId), examRecordId);
     }
+
+    public static Long getExamingRecordId(Long studentId) {
+        return (Long) redisUtil.get(RedisKeyHelper.examingRecordIdCacheKey(studentId));
+    }
+
+//    public static TEStudentCacheDto getStudentExaming(Long studentId) {
+//        return (TEStudentCacheDto) redisUtil.get(RedisKeyHelper.studentCacheKey(studentId));
+//    }
+//
+//    public static void setStudentExaming(Long studentId, TEStudentCacheDto teStudentCacheDto) {
+//        redisUtil.set(RedisKeyHelper.studentCacheKey(studentId), teStudentCacheDto);
+//    }
 }

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

@@ -62,6 +62,11 @@ public class RedisKeyHelper {
      */
     private static String unFinishedRecordIdKeyPrefix = "un_finished_record_id:student_id_";
 
+    /**
+     * 正在考试记录id
+     */
+    private static String examingRecordIdKeyPrefix = "examing_record_id:student_id_";
+
     /**
      * 客观题答案
      */
@@ -209,6 +214,16 @@ public class RedisKeyHelper {
         return unFinishedRecordIdKeyPrefix + studentId;
     }
 
+    /**
+     * 正在考试记录id key
+     *
+     * @param studentId
+     * @return
+     */
+    public static String examingRecordIdCacheKey(Long studentId) {
+        return examingRecordIdKeyPrefix + studentId;
+    }
+
     /**
      * 客观题答案大key
      *

+ 7 - 18
themis-business/src/main/java/com/qmth/themis/business/dto/cache/TEStudentCacheDto.java

@@ -6,13 +6,13 @@ import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
 
-/** 
-* @Description: 学生缓存 dto
-* @Param:  
-* @return:  
-* @Author: wangliang
-* @Date: 2020/8/4 
-*/ 
+/**
+ * @Description: 学生缓存 dto
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/8/4
+ */
 public class TEStudentCacheDto implements Serializable {
 
     @JsonSerialize(using = ToStringSerializer.class)
@@ -32,17 +32,6 @@ public class TEStudentCacheDto implements Serializable {
     @ApiModelProperty(name = "学生底照")
     private String basePhotoPath;
 
-    @ApiModelProperty(name = "正在考试的id")
-    private Long examingRecordId;
-
-    public Long getExamingRecordId() {
-        return examingRecordId;
-    }
-
-    public void setExamingRecordId(Long examingRecordId) {
-        this.examingRecordId = examingRecordId;
-    }
-
     public Long getId() {
         return id;
     }

+ 2 - 13
themis-business/src/main/java/com/qmth/themis/business/service/impl/CacheServiceImpl.java

@@ -2,7 +2,6 @@ package com.qmth.themis.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.Gson;
-import com.qmth.themis.business.cache.ExamingDataCacheUtil;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
@@ -274,12 +273,7 @@ public class CacheServiceImpl implements CacheService {
     public TEStudentCacheDto addStudentAccountCache(Long studentId) {
         TEStudent teStudent = teStudentService.getById(studentId);
         Gson gson = new Gson();
-        TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
-        TEStudentCacheDto teStudentCacheDtoCache = ExamingDataCacheUtil.getStudentExaming(teStudentCacheDto.getId());
-        if (Objects.nonNull(teStudentCacheDtoCache) && Objects.nonNull(teStudentCacheDtoCache.getExamingRecordId())) {
-            teStudentCacheDto.setExamingRecordId(teStudentCacheDtoCache.getExamingRecordId());
-        }
-        return teStudentCacheDto;
+        return gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
     }
 
     /**
@@ -293,12 +287,7 @@ public class CacheServiceImpl implements CacheService {
     public TEStudentCacheDto updateStudentAccountCache(Long studentId) {
         TEStudent teStudent = teStudentService.getById(studentId);
         Gson gson = new Gson();
-        TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
-        TEStudentCacheDto teStudentCacheDtoCache = ExamingDataCacheUtil.getStudentExaming(teStudentCacheDto.getId());
-        if (Objects.nonNull(teStudentCacheDtoCache) && Objects.nonNull(teStudentCacheDtoCache.getExamingRecordId())) {
-            teStudentCacheDto.setExamingRecordId(teStudentCacheDtoCache.getExamingRecordId());
-        }
-        return teStudentCacheDto;
+        return gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
     }
 
     /**

+ 0 - 7
themis-business/src/main/java/com/qmth/themis/business/service/impl/CommonServiceImpl.java

@@ -91,13 +91,6 @@ public class CommonServiceImpl implements CommonService {
             redisUtil.delete(RedisKeyHelper.faceVerifyCacheKey(recordId));
             //2021-03-01新增
             redisUtil.delete(RedisKeyHelper.studentPaperStructKey(recordId));
-//            TEStudentCacheDto teStudentCacheDto = ExamingDataCacheUtil.getStudentExaming(studentId);
-//            //2022-04-15新增
-//            if (Objects.nonNull(teStudentCacheDto)) {
-//                teStudentCacheDto.setExamingRecordId(null);
-//                ExamingDataCacheUtil.setStudentExaming(studentId, teStudentCacheDto);
-//            }
-
 //            redisUtil.delete(RedisKeyHelper.examStudentCacheKey(examStudentId));
             //先查询之前的断点记录
             QueryWrapper<TOeExamBreakHistory> tOeExamBreakHistoryQueryWrapper = new QueryWrapper<>();

+ 4 - 3
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -276,6 +276,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
                 TEExamActivityDto teExamActivityDto = new TEExamActivityDto(examCache, ac, examStudentCacheBean,
                         examStudentId, ec, recordId, monitorUtil.getMonitorDomain().getPrefix(), cache);
                 prepare.setTeExamActivityDto(teExamActivityDto);
+                ExamingDataCacheUtil.setExamingRecordId(studentId, recordId);
                 return prepare;
             }
         }
@@ -1195,9 +1196,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         //判断当前结束的考试记录ID是否是未完成的考试记录ID
         if (recordId.equals(ExamingDataCacheUtil.getUnFinishedRecordId(studentId))) {
             ExamingDataCacheUtil.deleteUnFinishedRecordId(studentId);
-            //2022-04-15新增
-            teStudentCacheDto.setExamingRecordId(null);
-            ExamingDataCacheUtil.setStudentExaming(studentId, teStudentCacheDto);
+        }
+        if (Objects.equals(recordId, ExamingDataCacheUtil.getExamingRecordId(studentId))) {
+            ExamingDataCacheUtil.deleteExamingRecordId(studentId);
         }
 
         Map<String, Object> properties = new HashMap<>();

+ 1 - 5
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -200,11 +200,7 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
         sendExamRecordDataSaveMq(er.getId(), System.currentTimeMillis());
 
         //2022-04-15新增
-        TEStudentCacheDto teStudentCacheDto = ExamingDataCacheUtil.getStudentExaming(studentId);
-        if (Objects.nonNull(teStudentCacheDto)) {
-            teStudentCacheDto.setExamingRecordId(er.getId());
-            ExamingDataCacheUtil.setStudentExaming(studentId, teStudentCacheDto);
-        }
+        ExamingDataCacheUtil.setExamingRecordId(studentId, er.getId());
         return er.getId();
     }
 

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

@@ -109,12 +109,12 @@ public class TEStudentController {
 
     @ApiOperation(value = "学生登录接口")
     @RequestMapping(value = "/login", method = RequestMethod.POST)
-    @ApiResponses({ @ApiResponse(code = 200, message = "学生信息", response = TEExamResultDto.class) })
+    @ApiResponses({@ApiResponse(code = 200, message = "学生信息", response = TEExamResultDto.class)})
     public Result login(
-            @ApiJsonObject(name = "loginStudent", value = { @ApiJsonProperty(key = "identity", description = "证件号"),
+            @ApiJsonObject(name = "loginStudent", value = {@ApiJsonProperty(key = "identity", description = "证件号"),
                     @ApiJsonProperty(key = "password", description = "密码"),
                     @ApiJsonProperty(key = "orgId", type = "long", example = "1", description = "机构id"),
-                    @ApiJsonProperty(key = "examId", type = "long", example = "1", description = "批次id") }) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter)
+                    @ApiJsonProperty(key = "examId", type = "long", example = "1", description = "批次id")}) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter)
             throws NoSuchAlgorithmException {
         if (Objects.isNull(mapParameter)) {
             throw new BusinessException(ExceptionResultEnum.STUDENT_IS_NULL);
@@ -172,8 +172,7 @@ public class TEStudentController {
         redisUtil.waitLock(lockKey, SystemConstant.REDIS_LOCK_STUDENT_TIME_OUT);
         try {
             //判断是否有正在考试的记录
-            TEStudentCacheDto teStudentCacheDto = ExamingDataCacheUtil.getStudentExaming(user.getId());
-            Long examingRecordId = teStudentCacheDto != null ? teStudentCacheDto.getExamingRecordId() : null;
+            Long examingRecordId = ExamingDataCacheUtil.getExamingRecordId(user.getId());
             if (Objects.nonNull(examingRecordId)) {
                 WebsocketStatusEnum sta = ExamRecordCacheUtil.getClientWebsocketStatus(examingRecordId);
                 //有正在考试的记录,且考生端websocket在线则不允许登陆
@@ -290,7 +289,7 @@ public class TEStudentController {
 
     @ApiOperation(value = "登出接口")
     @RequestMapping(value = "/logout", method = RequestMethod.POST)
-    @ApiResponses({ @ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class) })
+    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
     public Result logout() throws NoSuchAlgorithmException {
         TEStudentCacheDto teStudent = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
         TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
@@ -333,7 +332,7 @@ public class TEStudentController {
      * @return
      */
     private ExamUnFinishBean unFinishCommon(Long recordId, ExamCacheBean ec, ExamStudentCacheBean examStudentCacheBean,
-            ExamActivityCacheBean examActivityCacheBean, Long examStudentId) {
+                                            ExamActivityCacheBean examActivityCacheBean, Long examStudentId) {
         ExamCourseCacheBean examCourseCacheBean = teExamCourseService
                 .getExamCourseCacheBean(ec.getId(), examStudentCacheBean.getCourseCode());
         TEExamActivityWaitDto teExamActivityWaitDto = new TEExamActivityWaitDto(ec, examActivityCacheBean,

+ 16 - 6
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallOeController.java

@@ -3,6 +3,7 @@ package com.qmth.themis.exam.api;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
+import com.qmth.themis.business.cache.ExamingDataCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
@@ -137,8 +138,11 @@ public class TIeInvigilateCallOeController {
         }
         //2022/04/21加入校验
         TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
-        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
-                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+        Long examingRecordId = null;
+        if (Objects.nonNull(teStudentCacheDto)) {
+            examingRecordId = ExamingDataCacheUtil.getExamingRecordId(teStudentCacheDto.getId());
+        }
+        if (Objects.nonNull(examingRecordId) && examingRecordId.longValue() == recordId.longValue()) {
             String monitorRecord = ExamRecordCacheUtil.getMonitorVideoSource(recordId);
             if (Objects.isNull(monitorRecord)) {
                 TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
@@ -203,8 +207,11 @@ public class TIeInvigilateCallOeController {
         }
         //2022/04/21加入校验
         TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
-        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
-                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+        Long examingRecordId = null;
+        if (Objects.nonNull(teStudentCacheDto)) {
+            examingRecordId = ExamingDataCacheUtil.getExamingRecordId(teStudentCacheDto.getId());
+        }
+        if (Objects.nonNull(examingRecordId) && examingRecordId.longValue() == recordId.longValue()) {
             String monitorRecord = ExamRecordCacheUtil.getMonitorVideoSource(recordId);
             if (Objects.isNull(monitorRecord)) {
                 TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
@@ -258,8 +265,11 @@ public class TIeInvigilateCallOeController {
         }
         //2022/04/21加入校验
         TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
-        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
-                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+        Long examingRecordId = null;
+        if (Objects.nonNull(teStudentCacheDto)) {
+            examingRecordId = ExamingDataCacheUtil.getExamingRecordId(teStudentCacheDto.getId());
+        }
+        if (Objects.nonNull(examingRecordId) && examingRecordId.longValue() == recordId.longValue()) {
             String monitorRecord = ExamRecordCacheUtil.getMonitorVideoSource(recordId);
             if (Objects.isNull(monitorRecord)) {
                 TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);