Selaa lähdekoodia

监考端接口

wangliang 4 vuotta sitten
vanhempi
commit
e8eb205b7f

+ 0 - 1
themis-backend/src/main/java/com/qmth/themis/backend/websocket/WebSocketAdminServer.java

@@ -160,7 +160,6 @@ public class WebSocketAdminServer implements Concurrently {
                     WebSocketAdminMessageTemplete webSocketAdminMessageTemplete = SpringContextHolder.getBean(WebSocketAdminMessageTemplete.class);
                     Gson gson = new Gson();
                     WebsocketDto websocketDto = gson.fromJson(gson.toJson(jsonObject), WebsocketDto.class);
-                    //todo 加入当前时间和time比较的校验
                     Method method = webSocketAdminMessageTemplete.getClass().getDeclaredMethod(WebsocketTypeEnum.valueOf(websocketDto.getType()).getDesc(), String.class);
                     WebsocketDto result = (WebsocketDto) method.invoke(webSocketAdminMessageTemplete, String.valueOf(websocketDto.getBody()));
                     this.sendMessage(result);

+ 9 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallMobileController.java

@@ -15,6 +15,7 @@ import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
+import com.qmth.themis.exam.websocket.WebSocketMobileServer;
 import com.qmth.themis.exam.websocket.WebSocketOeServer;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
@@ -74,6 +75,10 @@ public class TIeInvigilateCallMobileController {
             if (Objects.isNull(mapParameter.get("liveUrl")) || Objects.equals(mapParameter.get("liveUrl"), "")) {
                 throw new BusinessException("观看地址不能为空");
             }
+            ConcurrentHashMap<Long, WebSocketMobileServer> webSocketMap = WebSocketMobileServer.getWebSocketMap();
+            if (Objects.isNull(webSocketMap.get(recordId))) {
+                throw new BusinessException("网络连接失败");
+            }
             String liveUrl = String.valueOf(mapParameter.get("liveUrl"));
             String monitorKey = ExamRecordCacheUtil.getMonitorKey(recordId);
             TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl, MonitorStatusSourceEnum.INIT, monitorKey);
@@ -168,6 +173,10 @@ public class TIeInvigilateCallMobileController {
         if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get("type")) || Objects.equals(mapParameter.get("type"), ""))) {
             throw new BusinessException("异常类型不能为空");
         }
+        ConcurrentHashMap<Long, WebSocketMobileServer> mobileWebSocketMap = WebSocketMobileServer.getWebSocketMap();
+        if (Objects.isNull(mobileWebSocketMap.get(recordId))) {
+            throw new BusinessException("网络连接失败");
+        }
         //获取考试记录缓存
         Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
         String liveUrl = null;

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

@@ -56,6 +56,7 @@ public class WebSocketMobileServer {
     private RedisUtil redisUtil;
     private Long updateTime = null;
     private Map<String, Object> tranMap = null;
+    private MonitorVideoSourceEnum source = null;
 
     /**
      * 连接建立成功调用的方法
@@ -79,6 +80,7 @@ public class WebSocketMobileServer {
         this.Authorization = String.valueOf(mapParameter.get("Authorization").get(0));
         this.time = Long.parseLong(String.valueOf(mapParameter.get("time").get(0)));
         this.recordId = Long.parseLong(String.valueOf(mapParameter.get("recordId").get(0)));
+        this.source = MonitorVideoSourceEnum.valueOf(mapParameter.get("source").get(0));
         String method = SystemConstant.GET;
         final SignatureInfo info = SignatureInfo
                 .parse(Authorization);
@@ -135,28 +137,18 @@ public class WebSocketMobileServer {
             //从set中删除
             subOnlineCount();
             //判断是否是正常退出
-//            Date now = new Date();
-//            //大于等于超时时间,说明规定时间内都没有通信,非正常退出,因为期间会有心跳更新updateTime
-//            if ((now.getTime() - this.updateTime) / 1000 >= SystemConstant.WEBSOCKET_MAX_TIME_OUT / 1000) {
             Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
-            MonitorVideoSourceEnum source = null;
-            if (Objects.nonNull(objectMap.get(SystemConstant.MONITOR_LIVE_URL_ + MonitorVideoSourceEnum.MOBILE_FIRST.name()))) {
-                source = MonitorVideoSourceEnum.MOBILE_FIRST;
-            } else if (Objects.nonNull(objectMap.get(SystemConstant.MONITOR_LIVE_URL_ + MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
-                source = MonitorVideoSourceEnum.MOBILE_SECOND;
-            }
-            objectMap.put(SystemConstant.MONITOR_STATUS_ + source.name(), MonitorStatusSourceEnum.STOP);
+            objectMap.put(SystemConstant.MONITOR_STATUS_ + this.source.name(), MonitorStatusSourceEnum.STOP);
             redisUtil.setForHash(RedisKeyHelper.examRecordCacheKey(recordId), objectMap);
             ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
             if (Objects.nonNull(webSocketMap.get(recordId))) {
                 WebSocketOeServer webSocketOeServer = webSocketMap.get(recordId);
                 Map map = new HashMap<>();
                 map.put(SystemConstant.RECORD_ID, recordId);
-                map.put("monitorVideoSource", source.name());
+                map.put("monitorVideoSource", this.source.name());
                 WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_MONITOR_STOP.name(), map);
                 webSocketOeServer.sendMessage(websocketDto);
             }
-//            }
         }
         log.info("用户退出:{},当前在线人数为:{},updateTime:{}", this.sessionId, getOnlineCount(), this.updateTime);
     }
@@ -180,7 +172,6 @@ public class WebSocketMobileServer {
                     WebSocketMobileMessageTemplete webSocketMobileMessageTemplete = SpringContextHolder.getBean(WebSocketMobileMessageTemplete.class);
                     Gson gson = new Gson();
                     WebsocketDto websocketDto = gson.fromJson(gson.toJson(jsonObject), WebsocketDto.class);
-                    //todo 加入当前时间和time比较的校验
                     jsonObject.getJSONObject("body").put("recordId", this.recordId);
                     websocketDto.setBody(jsonObject.getJSONObject("body"));
                     Method method = webSocketMobileMessageTemplete.getClass().getDeclaredMethod(WebsocketTypeEnum.valueOf(websocketDto.getType()).getDesc(), String.class);

+ 0 - 1
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketOeServer.java

@@ -193,7 +193,6 @@ public class WebSocketOeServer implements Concurrently {
                     WebSocketOeMessageTemplete webSocketOeMessageTemplete = SpringContextHolder.getBean(WebSocketOeMessageTemplete.class);
                     Gson gson = new Gson();
                     WebsocketDto websocketDto = gson.fromJson(gson.toJson(jsonObject), WebsocketDto.class);
-                    //todo 加入当前时间和time比较的校验
                     jsonObject.getJSONObject("body").put("recordId", this.recordId);
                     websocketDto.setBody(jsonObject.getJSONObject("body"));
                     Method method = webSocketOeMessageTemplete.getClass().getDeclaredMethod(WebsocketTypeEnum.valueOf(websocketDto.getType()).getDesc(), String.class);