From 12b7bf2629926c8acbd451f48aa815a2fb59fa50 Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期三, 13 十一月 2024 11:51:17 +0800
Subject: [PATCH] 优化错题详情
---
src/main/java/com/ycl/jxkg/server/WebsocketServer.java | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/server/WebsocketServer.java b/src/main/java/com/ycl/jxkg/server/WebsocketServer.java
index 3e27189..a5f35a7 100644
--- a/src/main/java/com/ycl/jxkg/server/WebsocketServer.java
+++ b/src/main/java/com/ycl/jxkg/server/WebsocketServer.java
@@ -1,6 +1,13 @@
package com.ycl.jxkg.server;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.ycl.jxkg.domain.query.WebSocketQuery;
+import com.ycl.jxkg.domain.vo.WebsocketDataVO;
+import com.ycl.jxkg.enums.WebsocketCommendEnum;
+import com.ycl.jxkg.service.EducationResourceService;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import javax.websocket.OnClose;
@@ -12,6 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.CopyOnWriteArraySet;
/**
@@ -22,6 +30,12 @@
@Slf4j
@ServerEndpoint("/websocket/{userId}")
public class WebsocketServer {
+
+ private static ApplicationContext applicationContext;
+
+ public static void setApplicationContext(ApplicationContext context) {
+ applicationContext = context;
+ }
/**
* 绾跨▼瀹夊叏鐨勬棤搴忕殑闆嗗悎
@@ -56,6 +70,20 @@
@OnMessage
public void onMessage(String message) {
+ WebSocketQuery webSocketQuery = JSONObject.parseObject(message, WebSocketQuery.class);
+ String command = webSocketQuery.getCommand();
+ Integer userId = webSocketQuery.getId();
+ if(WebsocketCommendEnum.RECORD_STUDY_TIME.getCommand().equals(command)){
+ log.info("瀛樻秷鎭�");
+ EducationResourceService educationResourceService = applicationContext.getBean(EducationResourceService.class);
+ educationResourceService.recordTime(userId);
+ }
+ // 浼氳鎿嶄綔
+ if (WebsocketCommendEnum.MUTE.getCommand().equals(command) || WebsocketCommendEnum.OPEN_CAMERA.getCommand().equals(command) || WebsocketCommendEnum.KICK_OUT.getCommand().equals(command)) {
+ WebsocketDataVO websocketDataVO = new WebsocketDataVO();
+ websocketDataVO.setCommend(command);
+ sendOneMessage(userId, JSON.toJSONString(websocketDataVO));
+ }
log.info("銆怶ebSocket娑堟伅銆戞敹鍒板鎴风娑堟伅锛�" + message);
}
@@ -117,4 +145,15 @@
}
}
+ /**
+ * 鏍¢獙鐢ㄦ埛鏄惁鍦ㄧ嚎
+ *
+ * @param userId
+ * @return
+ */
+ public Boolean checkUserOnline(Integer userId) {
+ Session session = SESSION_POOL.get(userId);
+ return Objects.nonNull(session);
+ }
+
}
--
Gitblit v1.8.0