From 61a5cdb61ed9caab7f77c4b01e35d58bb68cfef6 Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期三, 24 七月 2024 11:24:35 +0800 Subject: [PATCH] feat:用户导入 --- src/main/java/com/ycl/jxkg/server/WebsocketServer.java | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/server/WebsocketServer.java b/src/main/java/com/ycl/jxkg/server/WebsocketServer.java index 9886607..6c94322 100644 --- a/src/main/java/com/ycl/jxkg/server/WebsocketServer.java +++ b/src/main/java/com/ycl/jxkg/server/WebsocketServer.java @@ -8,6 +8,7 @@ import com.ycl.jxkg.service.EducationResourceService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import javax.servlet.http.HttpSession; @@ -20,6 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CopyOnWriteArraySet; /** @@ -31,8 +33,12 @@ @ServerEndpoint("/websocket/{userId}") public class WebsocketServer { - @Autowired - private EducationResourceService educationResourceService; + private static ApplicationContext applicationContext; + + public static void setApplicationContext(ApplicationContext context) { + applicationContext = context; + } + /** * 绾跨▼瀹夊叏鐨勬棤搴忕殑闆嗗悎 */ @@ -67,9 +73,11 @@ @OnMessage public void onMessage(String message) { WebSocketQuery webSocketQuery = JSONObject.parseObject(message, WebSocketQuery.class); - String commend = webSocketQuery.getCommend(); + String command = webSocketQuery.getCommand(); Integer userId = webSocketQuery.getId(); - if(WebsocketCommendEnum.RECORD_STUDY_TIME.getCommend().equals(commend)){ + if(WebsocketCommendEnum.RECORD_STUDY_TIME.getCommand().equals(command)){ + log.info("瀛樻秷鎭�"); + EducationResourceService educationResourceService = applicationContext.getBean(EducationResourceService.class); educationResourceService.recordTime(userId); } log.info("銆怶ebSocket娑堟伅銆戞敹鍒板鎴风娑堟伅锛�" + message); @@ -133,4 +141,15 @@ } } + /** + * 鏍¢獙鐢ㄦ埛鏄惁鍦ㄧ嚎 + * + * @param userId + * @return + */ + public Boolean checkUserOnline(Integer userId) { + Session session = SESSION_POOL.get(userId); + return Objects.nonNull(session); + } + } -- Gitblit v1.8.0