refactor: 适配 ContiNew Starter WebSocket 模块(消息模块)

This commit is contained in:
2024-06-05 20:52:11 +08:00
parent 51d05a263a
commit 94168e246f
14 changed files with 74 additions and 653 deletions

View File

@@ -16,7 +16,7 @@
package top.continew.admin.webapi.system;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.convert.Convert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -25,8 +25,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.common.enums.MessageTypeEnum;
import top.continew.admin.common.util.NoticeMsgUtils;
import top.continew.admin.common.util.WsUtils;
import top.continew.admin.common.util.helper.LoginHelper;
import top.continew.admin.system.model.query.MessageQuery;
import top.continew.admin.system.model.req.MessageReq;
@@ -36,8 +34,9 @@ import top.continew.admin.system.service.MessageService;
import top.continew.admin.system.service.MessageUserService;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.web.model.R;
import top.continew.starter.log.core.annotation.Log;
import top.continew.starter.messaging.websocket.util.WebSocketUtils;
import top.continew.starter.web.model.R;
import java.util.ArrayList;
import java.util.List;
@@ -97,7 +96,7 @@ public class MessageController {
req.setContent(msg);
req.setType(MessageTypeEnum.SYSTEM);
baseService.add(req, userIdList);
WsUtils.sendToUser(LoginHelper.getUserId().toString(), NoticeMsgUtils.conversion(msg, IdUtil.fastSimpleUUID()));
WebSocketUtils.sendMessage(Convert.toStr(LoginHelper.getUserId()), msg);
return R.ok();
}
}

View File

@@ -184,6 +184,13 @@ springdoc:
swagger-ui:
enabled: true
--- ### WebSocket 配置
continew-starter.messaging.websocket:
enabled: true
path: /websocket
# 配置允许跨域的域名
allowed-origins: '*'
--- ### 短信配置
sms:
# 从 YAML 读取配置
@@ -239,7 +246,7 @@ sa-token.extension:
- /*/*.html
- /*/*.css
- /*/*.js
- /webSocket/**
- /websocket/**
# 接口文档相关资源
- /favicon.ico
- /doc.html

View File

@@ -188,6 +188,14 @@ knife4j:
# 开启生产环境屏蔽
production: true
--- ### WebSocket 配置
continew-starter.messaging.websocket:
enabled: true
path: /websocket
# 配置允许跨域的域名
allowed-origins:
- ${project.url}
--- ### 短信配置
sms:
# 从 YAML 读取配置
@@ -242,7 +250,7 @@ sa-token.extension:
- /*/*.html
- /*/*.css
- /*/*.js
- /webSocket/**
- /websocket/**
# 本地存储资源
- /file/**