Skip to content

Commit

Permalink
refactor: 补充消息类型字典初始数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jun 11, 2024
1 parent 48d0f47 commit 5abdb8d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
public enum MessageTypeEnum implements IBaseEnum<Integer> {

/**
* 系统消息
* 安全消息
*/
SYSTEM(1, "系统消息", UiConstants.COLOR_PRIMARY),;
SECURITY(1, "安全消息", UiConstants.COLOR_PRIMARY),;

private final Integer value;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
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;
Expand Down Expand Up @@ -139,7 +140,7 @@ public String socialLogin(AuthUser authUser) {
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);
}
Expand Down Expand Up @@ -243,16 +244,17 @@ private void checkUserLocked(String username, HttpServletRequest request, boolea
}

/**
* 发送系统消息
* 发送安全消息
*
* @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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,24 @@

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;
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;
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;

/**
Expand Down Expand Up @@ -86,17 +81,4 @@ public R<Void> readMessage(@RequestParam(required = false) List<Long> ids) {
public R<MessageUnreadResp> countUnreadMessage(@RequestParam(required = false) Boolean detail) {
return R.ok(messageUserService.countUnreadMessageByUserId(LoginHelper.getUserId(), detail));
}

@GetMapping("/testSend")
public R<Object> testSend(String msg) {
List<Long> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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);
(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);
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);

0 comments on commit 5abdb8d

Please sign in to comment.