From 5abdb8d86161e7bd03ace14b3c899f6ad13020e2 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 11 Jun 2024 23:46:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=A1=A5=E5=85=85=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=B1=BB=E5=9E=8B=E5=AD=97=E5=85=B8=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/common/enums/MessageTypeEnum.java | 4 ++-- .../auth/service/impl/LoginServiceImpl.java | 10 ++++++---- .../admin/webapi/system/MessageController.java | 18 ------------------ .../db/changelog/mysql/continew-admin_data.sql | 13 ++++++++----- .../postgresql/continew-admin_data.sql | 13 ++++++++----- 5 files changed, 24 insertions(+), 34 deletions(-) diff --git a/continew-admin-common/src/main/java/top/continew/admin/common/enums/MessageTypeEnum.java b/continew-admin-common/src/main/java/top/continew/admin/common/enums/MessageTypeEnum.java index 8a45b33e..0aba86c8 100644 --- a/continew-admin-common/src/main/java/top/continew/admin/common/enums/MessageTypeEnum.java +++ b/continew-admin-common/src/main/java/top/continew/admin/common/enums/MessageTypeEnum.java @@ -32,9 +32,9 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; public enum MessageTypeEnum implements IBaseEnum { /** - * 系统消息 + * 安全消息 */ - SYSTEM(1, "系统消息", UiConstants.COLOR_PRIMARY),; + SECURITY(1, "安全消息", UiConstants.COLOR_PRIMARY),; private final Integer value; private final String description; diff --git a/continew-admin-system/src/main/java/top/continew/admin/auth/service/impl/LoginServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/auth/service/impl/LoginServiceImpl.java index 3d4fa592..6b46495c 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/auth/service/impl/LoginServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/auth/service/impl/LoginServiceImpl.java @@ -55,6 +55,7 @@ import top.continew.starter.core.autoconfigure.project.ProjectProperties; import top.continew.starter.core.util.validate.CheckUtils; import top.continew.starter.extension.crud.annotation.TreeField; import top.continew.starter.extension.crud.util.TreeUtils; +import top.continew.starter.messaging.websocket.util.WebSocketUtils; import java.time.Duration; import java.time.LocalDateTime; @@ -139,7 +140,7 @@ public class LoginServiceImpl implements LoginService { userSocial.setUserId(userId); userSocial.setSource(source); userSocial.setOpenId(openId); - this.sendSystemMsg(user); + this.sendSecurityMsg(user); } else { user = BeanUtil.copyProperties(userService.getById(userSocial.getUserId()), UserDO.class); } @@ -243,16 +244,17 @@ public class LoginServiceImpl implements LoginService { } /** - * 发送系统消息 + * 发送安全消息 * * @param user 用户信息 */ - private void sendSystemMsg(UserDO user) { + private void sendSecurityMsg(UserDO user) { MessageReq req = new MessageReq(); MessageTemplateEnum socialRegister = MessageTemplateEnum.SOCIAL_REGISTER; req.setTitle(socialRegister.getTitle().formatted(projectProperties.getName())); req.setContent(socialRegister.getContent().formatted(user.getNickname())); - req.setType(MessageTypeEnum.SYSTEM); + req.setType(MessageTypeEnum.SECURITY); messageService.add(req, CollUtil.toList(user.getId())); + WebSocketUtils.sendMessage(user.getId().toString(), "1"); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/MessageController.java b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/MessageController.java index 43750fb9..eaa9e97f 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/MessageController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/MessageController.java @@ -16,7 +16,6 @@ package top.continew.admin.webapi.system; -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; @@ -24,10 +23,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; 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.helper.LoginHelper; import top.continew.admin.system.model.query.MessageQuery; -import top.continew.admin.system.model.req.MessageReq; import top.continew.admin.system.model.resp.MessageResp; import top.continew.admin.system.model.resp.MessageUnreadResp; import top.continew.admin.system.service.MessageService; @@ -35,10 +32,8 @@ 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.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; /** @@ -86,17 +81,4 @@ public class MessageController { public R countUnreadMessage(@RequestParam(required = false) Boolean detail) { return R.ok(messageUserService.countUnreadMessageByUserId(LoginHelper.getUserId(), detail)); } - - @GetMapping("/testSend") - public R testSend(String msg) { - List userIdList = new ArrayList<>(); - userIdList.add(LoginHelper.getUserId()); - MessageReq req = new MessageReq(); - req.setTitle(msg); - req.setContent(msg); - req.setType(MessageTypeEnum.SYSTEM); - baseService.add(req, userIdList); - WebSocketUtils.sendMessage(Convert.toStr(LoginHelper.getUserId()), msg); - return R.ok(); - } } \ No newline at end of file diff --git a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql index 24e9114c..b573fe7d 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql @@ -135,13 +135,16 @@ VALUES INSERT INTO `sys_dict` (`id`, `name`, `code`, `description`, `is_system`, `create_user`, `create_time`, `update_user`, `update_time`) VALUES -(547889614262632491, '公告类型', 'notice_type', NULL, b'1', 1, NOW(), NULL, NULL); +(1, '公告类型', 'notice_type', NULL, b'1', 1, NOW(), NULL, NULL), +(2, '消息类型', 'message_type', NULL, b'1', 1, NOW(), NULL, NULL); INSERT INTO `sys_dict_item` (`id`, `label`, `value`, `color`, `sort`, `description`, `status`, `dict_id`, `create_user`, `create_time`, `update_user`, `update_time`) VALUES -(547889649658363951, '通知', '1', 'blue', 1, NULL, 1, 547889614262632491, 1, NOW(), NULL, NULL), -(547890124537462835, '活动', '2', 'orangered', 2, NULL, 1, 547889614262632491, 1, NOW(), NULL, NULL); +(1, '通知', '1', 'blue', 1, NULL, 1, 1, 1, NOW(), NULL, NULL), +(2, '活动', '2', 'orangered', 2, NULL, 1, 1, 1, NOW(), NULL, NULL), +(3, '安全消息', '1', 'blue', 1, NULL, 1, 2, 1, NOW(), NULL, NULL), +(4, '活动消息', '2', 'orangered', 2, NULL, 1, 2, 1, NOW(), NULL, NULL); -- 初始化默认用户和角色关联数据 INSERT INTO `sys_user_role` @@ -168,5 +171,5 @@ INSERT INTO `sys_role_dept` (`role_id`, `dept_id`) VALUES (547888897925840928, 5 INSERT INTO `sys_storage` (`id`, `name`, `code`, `type`, `access_key`, `secret_key`, `endpoint`, `bucket_name`, `domain`, `description`, `is_default`, `sort`, `status`, `create_user`, `create_time`, `update_user`, `update_time`) VALUES -(547890346239983671, '开发环境', 'local_dev', 2, NULL, NULL, NULL, 'C:/continew-admin/data/file/', 'http://localhost:8000/file', '本地存储', b'1', 1, 1, 1, NOW(), NULL, NULL), -(547890366586552377, '生产环境', 'local_prod', 2, NULL, NULL, NULL, '../data/file/', 'http://api.continew.top/file', '本地存储', b'0', 2, 2, 1, NOW(), NULL, NULL); \ No newline at end of file +(1, '开发环境', 'local_dev', 2, NULL, NULL, NULL, 'C:/continew-admin/data/file/', 'http://localhost:8000/file', '本地存储', b'1', 1, 1, 1, NOW(), NULL, NULL), +(2, '生产环境', 'local_prod', 2, NULL, NULL, NULL, '../data/file/', 'http://api.continew.top/file', '本地存储', b'0', 2, 2, 1, NOW(), NULL, NULL); \ No newline at end of file diff --git a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql index cbbb1d8a..8e37afe1 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql @@ -135,13 +135,16 @@ VALUES INSERT INTO "sys_dict" ("id", "name", "code", "description", "is_system", "create_user", "create_time", "update_user", "update_time") VALUES -(547889614262632491, '公告类型', 'notice_type', NULL, true, 1, NOW(), NULL, NULL); +(1, '公告类型', 'notice_type', NULL, true, 1, NOW(), NULL, NULL), +(2, '消息类型', 'message_type', NULL, true, 1, NOW(), NULL, NULL); INSERT INTO "sys_dict_item" ("id", "label", "value", "color", "sort", "description", "status", "dict_id", "create_user", "create_time", "update_user", "update_time") VALUES -(547889649658363951, '通知', '1', 'blue', 1, NULL, 1, 547889614262632491, 1, NOW(), NULL, NULL), -(547890124537462835, '活动', '2', 'orangered', 2, NULL, 1, 547889614262632491, 1, NOW(), NULL, NULL); +(1, '通知', '1', 'blue', 1, NULL, 1, 1, 1, NOW(), NULL, NULL), +(2, '活动', '2', 'orangered', 2, NULL, 1, 1, 1, NOW(), NULL, NULL), +(3, '安全消息', '1', 'blue', 1, NULL, 1, 2, 1, NOW(), NULL, NULL), +(4, '活动消息', '2', 'orangered', 2, NULL, 1, 2, 1, NOW(), NULL, NULL); -- 初始化默认用户和角色关联数据 INSERT INTO "sys_user_role" @@ -168,5 +171,5 @@ INSERT INTO "sys_role_dept" ("role_id", "dept_id") VALUES (547888897925840928, 5 INSERT INTO "sys_storage" ("id", "name", "code", "type", "access_key", "secret_key", "endpoint", "bucket_name", "domain", "description", "is_default", "sort", "status", "create_user", "create_time", "update_user", "update_time") VALUES -(547890346239983671, '开发环境', 'local_dev', 2, NULL, NULL, NULL, 'C:/continew-admin/data/file/', 'http://localhost:8000/file', '本地存储', true, 1, 1, 1, NOW(), NULL, NULL), -(547890366586552377, '生产环境', 'local_prod', 2, NULL, NULL, NULL, '../data/file/', 'http://api.continew.top/file', '本地存储', false, 2, 2, 1, NOW(), NULL, NULL); +(1, '开发环境', 'local_dev', 2, NULL, NULL, NULL, 'C:/continew-admin/data/file/', 'http://localhost:8000/file', '本地存储', true, 1, 1, 1, NOW(), NULL, NULL), +(2, '生产环境', 'local_prod', 2, NULL, NULL, NULL, '../data/file/', 'http://api.continew.top/file', '本地存储', false, 2, 2, 1, NOW(), NULL, NULL);