diff --git a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/WebSocketConfig.java b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/WebSocketConfig.java index c9cb6137..321c94c4 100644 --- a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/WebSocketConfig.java +++ b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/WebSocketConfig.java @@ -2,12 +2,10 @@ package com.ruoyi.common.websocket.config; import cn.hutool.core.util.StrUtil; import com.ruoyi.common.websocket.config.properties.WebSocketProperties; -import com.ruoyi.common.websocket.constant.WebSocketConstants; import com.ruoyi.common.websocket.handler.PlusWebSocketHandler; import com.ruoyi.common.websocket.interceptor.PlusWebSocketInterceptor; import com.ruoyi.common.websocket.listener.WebSocketTopicListener; import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; diff --git a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/properties/WebSocketProperties.java b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/properties/WebSocketProperties.java index ed57b9ca..97ce9929 100644 --- a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/properties/WebSocketProperties.java +++ b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/properties/WebSocketProperties.java @@ -2,7 +2,6 @@ package com.ruoyi.common.websocket.config.properties; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; /** * WebSocket 配置项 @@ -13,7 +12,7 @@ import org.springframework.validation.annotation.Validated; @Data public class WebSocketProperties { - private Boolean enable; + private Boolean enabled; /** * 路径 diff --git a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/dto/WebSocketMessageDto.java b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/dto/WebSocketMessageDto.java index c3b1b33b..afb75c20 100644 --- a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/dto/WebSocketMessageDto.java +++ b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/dto/WebSocketMessageDto.java @@ -3,6 +3,7 @@ package com.ruoyi.common.websocket.dto; import lombok.Builder; import lombok.Data; +import java.io.Serial; import java.io.Serializable; import java.util.List; @@ -15,6 +16,7 @@ import java.util.List; @Data public class WebSocketMessageDto implements Serializable { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/handler/PlusWebSocketHandler.java b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/handler/PlusWebSocketHandler.java index 8f4c8664..1017e329 100644 --- a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/handler/PlusWebSocketHandler.java +++ b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/handler/PlusWebSocketHandler.java @@ -22,8 +22,6 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler { /** * 连接成功后 - * - * @param session */ @Override public void afterConnectionEstablished(WebSocketSession session) { diff --git a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/utils/WebSocketUtils.java b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/utils/WebSocketUtils.java index b92ebc4e..00a26d5e 100644 --- a/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/utils/WebSocketUtils.java +++ b/ruoyi-common/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/utils/WebSocketUtils.java @@ -2,9 +2,7 @@ package com.ruoyi.common.websocket.utils; import cn.hutool.core.collection.CollUtil; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.json.utils.JsonUtils; import com.ruoyi.common.redis.utils.RedisUtils; -import com.ruoyi.common.satoken.utils.LoginHelper; import com.ruoyi.common.websocket.dto.WebSocketMessageDto; import com.ruoyi.common.websocket.holder.WebSocketSessionHolder; import lombok.AccessLevel; @@ -34,8 +32,9 @@ public class WebSocketUtils { /** * 发送消息 - * @param sessionKey - * @param message + * + * @param sessionKey session主键 一般为用户id + * @param message 消息文本 */ public static void sendMessage(Long sessionKey, String message) { WebSocketSession session = WebSocketSessionHolder.getSessions(sessionKey); @@ -45,7 +44,7 @@ public class WebSocketUtils { /** * 订阅消息 * - * @param consumer + * @param consumer 自定义处理 */ public static void subscribeMessage(Consumer consumer) { RedisUtils.subscribe(WEB_SOCKET_TOPIC, WebSocketMessageDto.class, consumer); @@ -54,12 +53,12 @@ public class WebSocketUtils { /** * 发布订阅的消息 * - * @param webSocketMessage + * @param webSocketMessage 消息对象 */ public static void publishMessage(WebSocketMessageDto webSocketMessage) { List unsentSessionKeys = new ArrayList<>(); // 当前服务内session,直接发送消息 - for (Long sessionKey: webSocketMessage.getSessionKeys()) { + for (Long sessionKey : webSocketMessage.getSessionKeys()) { if (WebSocketSessionHolder.existSession(sessionKey)) { WebSocketUtils.sendMessage(sessionKey, webSocketMessage.getMessage()); continue; @@ -70,7 +69,7 @@ public class WebSocketUtils { if (CollUtil.isNotEmpty(unsentSessionKeys)) { WebSocketMessageDto broadcastMessage = WebSocketMessageDto.builder() .message(webSocketMessage.getMessage()).sessionKeys(unsentSessionKeys).build(); - RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> { + RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> { log.info(" WebSocket发送主题订阅消息topic:{} session keys:{} message:{}", WEB_SOCKET_TOPIC, unsentSessionKeys, webSocketMessage.getMessage()); });