Selaa lähdekoodia

移动端websocket修改

wangliang 4 vuotta sitten
vanhempi
commit
69868f1e8b

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

@@ -309,8 +309,8 @@ public class ExamRecordCacheUtil {
         return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_id.getCode());
     }
 
-    public static String getMobileWebsocketId(Long recordId) {
-        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.mobile_websocket_id.getCode());
+    public static String getMobileWebsocketId(Long recordId, MonitorVideoSourceEnum monitorVideoSourceEnum) {
+        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.mobile_websocket_id.getCode() + "_" + monitorVideoSourceEnum.name());
     }
 
     public static void setClientWebsocketStatus(Long recordId, WebsocketStatusEnum websocketStatusEnum, Long timestamp) {
@@ -334,8 +334,8 @@ public class ExamRecordCacheUtil {
         redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_id.getCode(), id);
     }
 
-    public static void setMobileWebsocketId(Long recordId, String id) {
-        redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.mobile_websocket_id.getCode(), id);
+    public static void setMobileWebsocketId(Long recordId, String id, MonitorVideoSourceEnum monitorVideoSourceEnum) {
+        redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.mobile_websocket_id.getCode() + "_" + monitorVideoSourceEnum.name(), id);
     }
 
     public static void setClientLastSyncTime(Long recordId, Long date) {

+ 2 - 1
themis-exam/src/main/java/com/qmth/themis/exam/listener/service/impl/MqOeLogicServiceImpl.java

@@ -259,7 +259,7 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
         if (Objects.equals(MqTagEnum.EXAM_STOP.name(), tag)//考试退出
                 || Objects.equals(MqTagEnum.EXAM_START.name(), tag)) {//考试开始
             Long recordId = Long.parseLong(String.valueOf(mqDto.getBody()));
-            String mobileWebsocketId = ExamRecordCacheUtil.getMobileWebsocketId(recordId);
+            String mobileWebsocketId = ExamRecordCacheUtil.getMobileWebsocketId(recordId, MonitorVideoSourceEnum.MOBILE_FIRST);
             if (Objects.nonNull(mobileWebsocketId) && Objects.nonNull(webSocketMap.get(mobileWebsocketId + "-" + MonitorVideoSourceEnum.MOBILE_FIRST.name()))) {
                 WebSocketMobileServer webSocketMobileServer = webSocketMap.get(mobileWebsocketId + "-" + MonitorVideoSourceEnum.MOBILE_FIRST.name());
                 ExamRecordStatusEnum examRecordStatusEnum = ExamRecordCacheUtil.getStatus(recordId);
@@ -284,6 +284,7 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                     webSocketMobileServer.sendMessage(websocketDto);
                 }
             }
+            mobileWebsocketId = ExamRecordCacheUtil.getMobileWebsocketId(recordId, MonitorVideoSourceEnum.MOBILE_SECOND);
             if (Objects.nonNull(mobileWebsocketId) && Objects.nonNull(webSocketMap.get(mobileWebsocketId + "-" + MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
                 WebSocketMobileServer webSocketMobileServer = webSocketMap.get(mobileWebsocketId + "-" + MonitorVideoSourceEnum.MOBILE_SECOND.name());
                 ExamRecordStatusEnum examRecordStatusEnum = ExamRecordCacheUtil.getStatus(recordId);

+ 2 - 2
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketMobileServer.java

@@ -93,8 +93,8 @@ public class WebSocketMobileServer implements Concurrently {
         this.session = session;
         session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
         this.sessionId = tbSession.getId();
-        this.websocketSessionId = Objects.isNull(ExamRecordCacheUtil.getMobileWebsocketId(this.recordId)) ? String.valueOf(UidUtil.nextId()) : ExamRecordCacheUtil.getMobileWebsocketId(recordId);
-        ExamRecordCacheUtil.setMobileWebsocketId(this.recordId, this.websocketSessionId);
+        this.websocketSessionId = String.valueOf(UidUtil.nextId());
+        ExamRecordCacheUtil.setMobileWebsocketId(this.recordId, this.websocketSessionId, this.source);
         if (webSocketMap.containsKey(this.websocketSessionId + "-" + this.source.name())) {
             webSocketMap.remove(this.websocketSessionId + "-" + this.source.name());
             webSocketMap.put(this.websocketSessionId + "-" + this.source.name(), this);