Jelajahi Sumber

增加读取配置文件

wangliang 4 tahun lalu
induk
melakukan
a77a875b33

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

@@ -138,6 +138,9 @@ public class TEStudentController {
         //mq发送消息end
         //测试
         String test = SignatureInfo.build(SignatureType.TOKEN, sessionId, token);
+        //获取未完/待考列表
+
+        //获取全局考试配置
         TEConfig teConfig = teConfigService.getGlobalConfig();
         Map<String, Object> map = new HashMap<>();
 //        map.put(SystemConstant.ACCESS_TOKEN, token);

+ 23 - 47
themis-exam/src/main/java/com/qmth/themis/exam/enums/WebsocketTypeEnum.java

@@ -11,81 +11,57 @@ import java.util.Objects;
  */
 public enum WebsocketTypeEnum {
 
-    client_paper_download(0, "客户端已下载试卷"),
+    client_paper_download("客户端已下载试卷","clientPaperDownload"),
 
-    sync_status(1, "状态同步"),
+    sync_status("状态同步","syncStatus"),
 
-    sync_ack(2, "同步确认"),
+    sync_ack( "同步确认","syncAck"),
 
-    invigilate_liveness_verify(3, "监考强制活体验证"),
+    invigilate_liveness_verify( "监考强制活体验证","invigilateLivenessVerify"),
 
-    invigilate_notice(4, "监考消息"),
+    invigilate_notice( "监考消息","invigilateNotice"),
 
-    invigilate_notice_ack(5, "监考消息确认"),
+    invigilate_notice_ack( "监考消息确认","invigilateNoticeAck"),
 
-    invigilate_stop_exam(6, "监考强制收卷");
+    invigilate_stop_exam( "监考强制收卷","invigilateStopExam");
 
-    private int id;
     private String code;
+    private String desc;
 
-    private WebsocketTypeEnum(int id, String code) {
-        this.id = id;
+    private WebsocketTypeEnum(String code,String desc) {
         this.code = code;
+        this.desc = desc;
     }
 
     /**
-     * 状态转换 toId
+     * 状态转换 toDesc
      *
      * @param value
      * @return
      */
-    public static String convertToCode(String value) {
+    public static String convertToDesc(String value) {
         if (Objects.equals(value.trim(), client_paper_download.name())) {
-            return client_paper_download.getCode();
+            return client_paper_download.getDesc();
         } else if (Objects.equals(value.trim(), sync_status.name())) {
-            return sync_status.getCode();
+            return sync_status.getDesc();
         } else if (Objects.equals(value.trim(), sync_ack.name())) {
-            return sync_ack.getCode();
+            return sync_ack.getDesc();
         } else if (Objects.equals(value.trim(), invigilate_liveness_verify.name())) {
-            return invigilate_liveness_verify.getCode();
+            return invigilate_liveness_verify.getDesc();
         } else if (Objects.equals(value.trim(), invigilate_notice.name())) {
-            return invigilate_notice.getCode();
+            return invigilate_notice.getDesc();
         } else if (Objects.equals(value.trim(), invigilate_notice_ack.name())) {
-            return invigilate_notice_ack.getCode();
+            return invigilate_notice_ack.getDesc();
         } else {
-            return invigilate_stop_exam.getCode();
+            return invigilate_stop_exam.getDesc();
         }
     }
 
-    /**
-     * 状态转换 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;
     }
+
+    public String getDesc() {
+        return desc;
+    }
 }

+ 23 - 12
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketServer.java

@@ -1,6 +1,5 @@
 package com.qmth.themis.exam.websocket;//package com.qmth.themis.backend.websocket;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
@@ -10,6 +9,8 @@ import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.signature.SignatureInfo;
 import com.qmth.themis.common.signature.SignatureType;
+import com.qmth.themis.exam.enums.WebsocketTypeEnum;
+import com.qmth.themis.exam.websocketTemplete.WebSocketOeMessageTemplete;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -18,6 +19,7 @@ import javax.websocket.*;
 import javax.websocket.server.PathParam;
 import javax.websocket.server.ServerEndpoint;
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -135,18 +137,27 @@ public class WebSocketServer
         if (Objects.nonNull(message)) {
             try {
                 //解析发送的报文
-                JSONObject jsonObject = JSON.parseObject(message);
-                //追加发送人(防止串改)
-                jsonObject.put("fromSessionId", this.sessionId);
-                String toSessionId = jsonObject.getString("toSessionId");
-                //传送给对应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
+                JSONObject jsonObject = JSONObject.parseObject(message);
+                log.info("onMessage:{}", jsonObject.toJSONString());
+                if (Objects.nonNull(jsonObject)) {
+                    WebSocketOeMessageTemplete webSocketOeMessageTemplete = SpringContextHolder.getBean(WebSocketOeMessageTemplete.class);
+                    String type = String.valueOf(jsonObject.get("type"));
+                    Long time = Long.parseLong(String.valueOf(jsonObject.get("time")));
+                    Method method = webSocketOeMessageTemplete.getClass().getDeclaredMethod(WebsocketTypeEnum.valueOf(type).getDesc(), String.class);
+                    method.invoke(webSocketOeMessageTemplete, String.valueOf(jsonObject.get("body")));
+                    session.getAsyncRemote().sendText("123");
                 }
+//                //追加发送人(防止串改)
+//                jsonObject.put("fromSessionId", this.sessionId);
+//                String toSessionId = jsonObject.getString("toSessionId");
+//                //传送给对应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
+//                }
             } catch (Exception e) {
                 e.printStackTrace();
             }

+ 43 - 0
themis-exam/src/main/java/com/qmth/themis/exam/websocketTemplete/WebSocketOeMessageTemplete.java

@@ -0,0 +1,43 @@
+package com.qmth.themis.exam.websocketTemplete;
+
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.exam.websocket.WebSocketServer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class WebSocketOeMessageTemplete {
+    private final static Logger log = LoggerFactory.getLogger(WebSocketOeMessageTemplete.class);
+
+    public Result clientPaperDownload(String body) {
+        JSONObject jsonObject = JSONObject.parseObject(body);
+        log.info("clientPaperDownload jsonObject:{}", jsonObject.toJSONString());
+        return null;
+    }
+
+    public Result syncStatus() {
+        return null;
+    }
+
+    public Result syncAck() {
+        return null;
+    }
+
+    public Result invigilateLivenessVerify() {
+        return null;
+    }
+
+    public Result invigilateNotice() {
+        return null;
+    }
+
+    public Result invigilateNoticeAck() {
+        return null;
+    }
+
+    public Result invigilateStopExam() {
+        return null;
+    }
+}