From 9784b6d36c189ea4b5df05a10cbba061d8b869c0 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 04 七月 2024 18:08:37 +0800 Subject: [PATCH] 考试状态修改消费者优化 --- src/main/java/com/ycl/jxkg/server/WebsocketServer.java | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 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..2c3a644 100644 --- a/src/main/java/com/ycl/jxkg/server/WebsocketServer.java +++ b/src/main/java/com/ycl/jxkg/server/WebsocketServer.java @@ -1,8 +1,16 @@ package com.ycl.jxkg.server; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonObject; +import com.ycl.jxkg.domain.entity.Message; +import com.ycl.jxkg.domain.query.WebSocketQuery; +import com.ycl.jxkg.enums.WebsocketCommendEnum; +import com.ycl.jxkg.service.EducationResourceService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.servlet.http.HttpSession; import javax.websocket.OnClose; import javax.websocket.OnMessage; import javax.websocket.OnOpen; @@ -12,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CopyOnWriteArraySet; /** @@ -23,6 +32,8 @@ @ServerEndpoint("/websocket/{userId}") public class WebsocketServer { + @Autowired + private EducationResourceService educationResourceService; /** * 绾跨▼瀹夊叏鐨勬棤搴忕殑闆嗗悎 */ @@ -56,6 +67,12 @@ @OnMessage public void onMessage(String message) { + WebSocketQuery webSocketQuery = JSONObject.parseObject(message, WebSocketQuery.class); + String commend = webSocketQuery.getCommend(); + Integer userId = webSocketQuery.getId(); + if(WebsocketCommendEnum.RECORD_STUDY_TIME.getCommend().equals(commend)){ + educationResourceService.recordTime(userId); + } log.info("銆怶ebSocket娑堟伅銆戞敹鍒板鎴风娑堟伅锛�" + message); } @@ -117,4 +134,15 @@ } } + /** + * 鏍¢獙鐢ㄦ埛鏄惁鍦ㄧ嚎 + * + * @param userId + * @return + */ + public Boolean checkUserOnline(Integer userId) { + Session session = SESSION_POOL.get(userId); + return Objects.nonNull(session); + } + } -- Gitblit v1.8.0