Răsfoiți Sursa

考生端接口

wangliang 5 ani în urmă
părinte
comite
812f98c51f

+ 1 - 0
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -119,6 +119,7 @@ public class SystemConstant {
      */
     public static final String WEBSOCKET_OE_ONLINE_COUNT = "websocket:oe:online:count";
     public static final String GET = "get";
+    public static final long WEBSOCKET_MAX_TIME_OUT = 3 * 60 * 1000;
 
     /**
      * 获取过期时间

+ 2 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeImportTemplete.java

@@ -184,6 +184,8 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
                 //新增用户角色
                 TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), RoleEnum.TEACHER.name());
                 tbUserRoleService.save(tbUserRole);
+                tbUserRole = new TBUserRole(tbUser.getId(), RoleEnum.INVIGILATE.name());
+                tbUserRoleService.save(tbUserRole);
                 tbUserRoleList.add(tbUserRole);
             }
             //新增考场

+ 91 - 0
themis-exam/src/main/java/com/qmth/themis/exam/enums/WebsocketTypeEnum.java

@@ -0,0 +1,91 @@
+package com.qmth.themis.exam.enums;
+
+import java.util.Objects;
+
+/**
+ * @Description: webSocket消息类型 enum
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/22
+ */
+public enum WebsocketTypeEnum {
+
+    client_paper_download(0, "客户端已下载试卷"),
+
+    sync_status(1, "状态同步"),
+
+    sync_ack(2, "同步确认"),
+
+    invigilate_liveness_verify(3, "监考强制活体验证"),
+
+    invigilate_notice(4, "监考消息"),
+
+    invigilate_notice_ack(5, "监考消息确认"),
+
+    invigilate_stop_exam(6, "监考强制收卷");
+
+    private int id;
+    private String code;
+
+    private WebsocketTypeEnum(int id, String code) {
+        this.id = id;
+        this.code = code;
+    }
+
+    /**
+     * 状态转换 toId
+     *
+     * @param value
+     * @return
+     */
+    public static String convertToCode(String value) {
+        if (Objects.equals(value.trim(), client_paper_download.name())) {
+            return client_paper_download.getCode();
+        } else if (Objects.equals(value.trim(), sync_status.name())) {
+            return sync_status.getCode();
+        } else if (Objects.equals(value.trim(), sync_ack.name())) {
+            return sync_ack.getCode();
+        } else if (Objects.equals(value.trim(), invigilate_liveness_verify.name())) {
+            return invigilate_liveness_verify.getCode();
+        } else if (Objects.equals(value.trim(), invigilate_notice.name())) {
+            return invigilate_notice.getCode();
+        } else if (Objects.equals(value.trim(), invigilate_notice_ack.name())) {
+            return invigilate_notice_ack.getCode();
+        } else {
+            return invigilate_stop_exam.getCode();
+        }
+    }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param value
+     * @return
+     */
+    public static String convertToName(String value) {
+        if (Objects.equals(value.trim(), client_paper_download.getCode())) {
+            return client_paper_download.name();
+        } else if (Objects.equals(value.trim(), sync_status.getCode())) {
+            return sync_status.name();
+        } else if (Objects.equals(value.trim(), sync_ack.getCode())) {
+            return sync_ack.name();
+        } else if (Objects.equals(value.trim(), invigilate_liveness_verify.getCode())) {
+            return invigilate_liveness_verify.name();
+        } else if (Objects.equals(value.trim(), invigilate_notice.getCode())) {
+            return invigilate_notice.name();
+        } else if (Objects.equals(value.trim(), invigilate_notice_ack.getCode())) {
+            return invigilate_notice_ack.name();
+        } else {
+            return invigilate_stop_exam.name();
+        }
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+}

+ 3 - 4
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketServer.java

@@ -37,9 +37,6 @@ public class WebSocketServer
 //        implements MessageListenerConcurrently
 {
     private final static Logger log = LoggerFactory.getLogger(WebSocketServer.class);
-    /**
-     * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
-     */
     private volatile static ConcurrentHashMap<String, WebSocketServer> webSocketMap = new ConcurrentHashMap<>();
     /**
      * 与某个客户端的连接会话,需要通过它来给客户端发送数据
@@ -84,6 +81,7 @@ public class WebSocketServer
                 if (info.validate(tbSession.getAccessToken()) && info.getTimestamp() < tbSession.getExpireTime().getTime()
                         && platform.equalsIgnoreCase(tbSession.getPlatform()) && Objects.equals(deviceId, tbSession.getDeviceId())) {
                     this.session = session;
+                    session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
                     this.sessionId = tbSession.getId();
                     if (webSocketMap.containsKey(session)) {
                         webSocketMap.remove(sessionId);
@@ -144,6 +142,7 @@ public class WebSocketServer
                 //传送给对应toSessionId用户的websocket
                 if (Objects.nonNull(toSessionId) && webSocketMap.containsKey(toSessionId)) {
                     webSocketMap.get(toSessionId).sendMessage(jsonObject.toJSONString());
+                    log.info("发送消息jsonObject:{}", jsonObject.toJSONString());
                 } else {
                     log.error("请求的sessionId:" + toSessionId + "不在该服务器上");
                     //否则不在这个服务器上,发送到mysql或者redis
@@ -174,7 +173,7 @@ public class WebSocketServer
      * @throws IOException
      */
     public void sendMessage(String message) throws IOException {
-        this.session.getBasicRemote().sendText(message);
+        log.info("message:{}", message);
     }
 
     /**