diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/base/MyMetaOption.java b/cutejava/cutejava-common/src/main/java/cn/odboy/base/MyMetaOption.java index 94e5f24f..ef50b648 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/base/MyMetaOption.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/base/MyMetaOption.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/context/BeanLoadFinishListener.java b/cutejava/cutejava-common/src/main/java/cn/odboy/context/BeanLoadFinishListener.java index 02a2bada..a7ed1303 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/context/BeanLoadFinishListener.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/context/BeanLoadFinishListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/context/BootApplication.java b/cutejava/cutejava-common/src/main/java/cn/odboy/context/BootApplication.java index f035513e..9bc72136 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/context/BootApplication.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/context/BootApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/monitor/HealthCheckController.java b/cutejava/cutejava-common/src/main/java/cn/odboy/monitor/HealthCheckController.java index 1cf2c97e..308ca168 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/monitor/HealthCheckController.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/monitor/HealthCheckController.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/constant/DataTypeEnum.java b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/constant/DataTypeEnum.java index fe7fdc5e..10e94e9c 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/constant/DataTypeEnum.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/constant/DataTypeEnum.java @@ -1,21 +1,3 @@ -/* - * << - * Davinci - * == - * Copyright (C) 2016 - 2019 EDP - * == - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * >> - * - */ package cn.odboy.mybatis.constant; import lombok.extern.slf4j.Slf4j; diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/context/InsertBatchSqlInjector.java b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/context/InsertBatchSqlInjector.java index 77c6c68f..8bd78de3 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/context/InsertBatchSqlInjector.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/context/InsertBatchSqlInjector.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyMapper.java b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyMapper.java index 4a54fe39..871d1c06 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyMapper.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyService.java b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyService.java index ce8c6709..f3c4501a 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyService.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/EasyService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/impl/EasyServiceImpl.java b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/impl/EasyServiceImpl.java index cabd24e1..17517304 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/impl/EasyServiceImpl.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/interfaces/impl/EasyServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ public class EasyServiceImpl, T> extends ServiceImpl int quickSave(G resources) { - return this.getBaseMapper().insert(BeanUtil.copyProperties(resources, this.getEntityClass())); + return getBaseMapper().insert(BeanUtil.copyProperties(resources, this.getEntityClass())); } /** @@ -59,7 +59,7 @@ public class EasyServiceImpl, T> extends ServiceImpl int quickSaveBatch(List resources) { - return this.getBaseMapper().insertBatchSomeColumn(BeanUtil.copyToList(resources, this.getEntityClass())); + return getBaseMapper().insertBatchSomeColumn(BeanUtil.copyToList(resources, this.getEntityClass())); } /** @@ -68,7 +68,7 @@ public class EasyServiceImpl, T> extends ServiceImpl int quickModifyById(G resources) { - return this.getBaseMapper().updateById(BeanUtil.copyProperties(resources, this.getEntityClass())); + return getBaseMapper().updateById(BeanUtil.copyProperties(resources, this.getEntityClass())); } /** diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/util/CmdGenHelper.java b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/util/CmdGenHelper.java index 96a9e1ed..78abfbe9 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/util/CmdGenHelper.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/mybatis/util/CmdGenHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/Base64SecretUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/Base64SecretUtil.java index 0b1abcc4..177cc228 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/Base64SecretUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/Base64SecretUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/CollUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/CollUtil.java index dda06505..50b13536 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/CollUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/CollUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/JsonUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/JsonUtil.java index 8c5d40ec..4badf88a 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/JsonUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/JsonUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/ListUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/ListUtil.java index 29afa2af..6ff293f6 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/ListUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/ListUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/LogFmtUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/LogFmtUtil.java index 0c736825..62e93c3e 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/LogFmtUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/LogFmtUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/ScriptUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/ScriptUtil.java index 21d0e1b4..8baf55ea 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/ScriptUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/ScriptUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/SqlUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/SqlUtil.java index a3a03091..d25fc285 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/SqlUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/SqlUtil.java @@ -1,18 +1,3 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.odboy.util; import cn.odboy.mybatis.constant.DataTypeEnum; diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/util/ValidationUtil.java b/cutejava/cutejava-common/src/main/java/cn/odboy/util/ValidationUtil.java index d1d9a6f7..4f122e68 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/util/ValidationUtil.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/util/ValidationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2025 Tian Jun + * Copyright 2021-2025 Odboy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketMsg.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketMsg.java deleted file mode 100644 index fc640ed5..00000000 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketMsg.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cn.odboy.websocket; - -import lombok.Data; - -/** - * @author ZhangHouYing - * @date 2019-08-10 9:55 - */ -@Data -public class WebSocketMsg { - private String msg; - private WebSocketMsgTypeEnum msgType; - - public WebSocketMsg(String msg, WebSocketMsgTypeEnum msgType) { - this.msg = msg; - this.msgType = msgType; - } -} diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketMsgTypeEnum.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketMsgTypeEnum.java deleted file mode 100644 index 6dd91c1f..00000000 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketMsgTypeEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cn.odboy.websocket; - -/** - * @author ZhangHouYing - * @date 2019-08-10 9:56 - */ -public enum WebSocketMsgTypeEnum { - /** - * 连接 - */ - CONNECT, - /** - * 关闭 - */ - CLOSE, - /** - * 信息 - */ - INFO, - /** - * 错误 - */ - ERROR -} diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketConfig.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/config/WebSocketConfig.java similarity index 91% rename from cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketConfig.java rename to cutejava/cutejava-common/src/main/java/cn/odboy/websocket/config/WebSocketConfig.java index d4e7d273..069f0c28 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketConfig.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/config/WebSocketConfig.java @@ -1,4 +1,4 @@ -package cn.odboy.websocket; +package cn.odboy.websocket.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketServerFactory.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/config/WebSocketServerFactory.java similarity index 96% rename from cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketServerFactory.java rename to cutejava/cutejava-common/src/main/java/cn/odboy/websocket/config/WebSocketServerFactory.java index 61c1e944..716ff226 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketServerFactory.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/config/WebSocketServerFactory.java @@ -1,4 +1,4 @@ -package cn.odboy.websocket; +package cn.odboy.websocket.config; import io.undertow.server.DefaultByteBufferPool; import io.undertow.websockets.jsr.WebSocketDeploymentInfo; diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/constant/WebSocketMsgTypeEnum.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/constant/WebSocketMsgTypeEnum.java new file mode 100644 index 00000000..ec25116d --- /dev/null +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/constant/WebSocketMsgTypeEnum.java @@ -0,0 +1,21 @@ +package cn.odboy.websocket.constant; + + +public enum WebSocketMsgTypeEnum { + /** + * 连接 + */ + CONNECT, + /** + * 关闭 + */ + CLOSE, + /** + * 信息 + */ + INFO, + /** + * 错误 + */ + ERROR +} diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/context/WebSocketClientManager.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/context/WebSocketClientManager.java new file mode 100644 index 00000000..5bae834b --- /dev/null +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/context/WebSocketClientManager.java @@ -0,0 +1,29 @@ +package cn.odboy.websocket.context; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class WebSocketClientManager { + /** + * concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象。(分布式必出问题) + */ + private static final Map CLIENT = new ConcurrentHashMap<>(); + + public static void addClient(String sid, WebSocketServer webSocketServer) { + // 如果存在就先删除一个,防止重复推送消息 + CLIENT.remove(sid); + CLIENT.put(sid, webSocketServer); + } + + public static void removeClient(String sid) { + CLIENT.remove(sid); + } + + public static Collection getAllClient() { + return CLIENT.values(); + } + + public static WebSocketServer getClientBySid(String sid) { + return CLIENT.get(sid); + } +} diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketServer.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/context/WebSocketServer.java similarity index 58% rename from cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketServer.java rename to cutejava/cutejava-common/src/main/java/cn/odboy/websocket/context/WebSocketServer.java index 5732e619..577e815e 100644 --- a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/WebSocketServer.java +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/context/WebSocketServer.java @@ -1,22 +1,9 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cn.odboy.websocket; +package cn.odboy.websocket.context; +import cn.odboy.websocket.dto.WebSocketMsgDto; import com.alibaba.fastjson2.JSON; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.websocket.*; @@ -27,18 +14,11 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -/** - * @author ZhangHouYing - * @date 2019-08-10 15:46 - */ -@ServerEndpoint("/webSocket/{sid}") + @Slf4j @Component +@ServerEndpoint("/webSocket/{sid}") public class WebSocketServer { - /** - * concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象。(分布式必出问题) - */ - private static final Map CLIENT = new ConcurrentHashMap<>(); /** * 与某个客户端的连接会话,需要通过它来给客户端发送数据 */ @@ -54,10 +34,8 @@ public class WebSocketServer { @OnOpen public void onOpen(Session session, @PathParam("sid") String sid) { this.session = session; - // 如果存在就先删除一个,防止重复推送消息 - CLIENT.remove(sid); - CLIENT.put(sid, this); this.sid = sid; + WebSocketClientManager.addClient(sid, this); } /** @@ -65,7 +43,7 @@ public class WebSocketServer { */ @OnClose public void onClose() { - CLIENT.remove(this.sid); + WebSocketClientManager.removeClient(this.sid); } /** @@ -75,7 +53,7 @@ public class WebSocketServer { */ @OnMessage public void onMessage(String message, Session session) { - log.info("收到来{}的信息:{}", sid, message); + log.info("收到来 sid={} 的信息: {}", sid, message); sendToAll(message); } @@ -85,40 +63,39 @@ public class WebSocketServer { * @param message / */ private static void sendToAll(String message) { - // - for (WebSocketServer item : CLIENT.values()) { + for (WebSocketServer item : WebSocketClientManager.getAllClient()) { try { - item.sendMessage(message); + item.innerSendMessage(message); } catch (IOException e) { - log.error("发送消息给{}失败", item.sid, e); + log.error("发送消息给 sid={} 失败", item.sid, e); } } } @OnError public void onError(Session session, Throwable error) { - log.error("发生错误"); + log.error("WebSocket sid={} 发生错误", this.sid, error); error.printStackTrace(); } /** * 实现服务器主动推送 */ - private void sendMessage(String message) throws IOException { + private void innerSendMessage(String message) throws IOException { this.session.getBasicRemote().sendText(message); } /** * 群发自定义消息 */ - public static void sendInfo(WebSocketMsg webSocketMsg, @PathParam("sid") String sid) throws IOException { - String message = JSON.toJSONString(webSocketMsg); + public static void sendMessage(WebSocketMsgDto webSocketMsgDto, @PathParam("sid") String sid) throws IOException { + String message = JSON.toJSONString(webSocketMsgDto); log.info("推送消息到{},推送内容:{}", sid, message); try { if (sid == null) { sendToAll(message); } else { - CLIENT.get(sid).sendMessage(message); + WebSocketClientManager.getClientBySid(sid).innerSendMessage(message); } } catch (IOException ignored) { } diff --git a/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/dto/WebSocketMsgDto.java b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/dto/WebSocketMsgDto.java new file mode 100644 index 00000000..83765338 --- /dev/null +++ b/cutejava/cutejava-common/src/main/java/cn/odboy/websocket/dto/WebSocketMsgDto.java @@ -0,0 +1,15 @@ +package cn.odboy.websocket.dto; + +import cn.odboy.websocket.constant.WebSocketMsgTypeEnum; +import lombok.Data; + +@Data +public class WebSocketMsgDto { + private String msg; + private WebSocketMsgTypeEnum msgType; + + public WebSocketMsgDto(String msg, WebSocketMsgTypeEnum msgType) { + this.msg = msg; + this.msgType = msgType; + } +}