Skip to content

Commit 0f3e94f

Browse files
committed
feat: 重构公告及消息,公告支持系统消息推送提醒、定时发布、置顶、记录读取状态
1 parent e2deb99 commit 0f3e94f

47 files changed

Lines changed: 1267 additions & 542 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

continew-extension/continew-extension-schedule-server/src/main/resources/db/changelog/mysql/snail-job_data.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ VALUES ('admin', '465c194afb65670f38322df087f0a9bb225cc257e43eb4ac5a0c98ef5b3173
1212
-- 默认分组:continew-admin
1313
INSERT INTO `sj_group_config` (`id`, `namespace_id`, `group_name`, `description`, `token`, `group_status`, `version`, `group_partition`, `id_generator_mode`, `init_scene`, `create_dt`, `update_dt`)
1414
VALUES (1, '764d604ec6fc45f68cd92514c40e9e1a', 'continew-admin', '默认分组', 'SJ_Wyz3dmsdbDOkDujOTSSoBjGQP1BMsVnj', 1, 1, 0, 2, 1, NOW(), NOW());
15+
16+
-- 默认任务:NoticePublishJob
17+
INSERT INTO `sj_job`
18+
(`namespace_id`, `group_name`, `job_name`, `args_type`, `next_trigger_at`, `job_status`, `task_type`, `route_key`, `executor_type`, `executor_info`, `trigger_type`, `trigger_interval`, `block_strategy`, `executor_timeout`, `max_retry_times`, `parallel_num`, `retry_interval`, `bucket_index`, `resident`, `notify_ids`, `owner_id`, `description`, `ext_attrs`, `deleted`, `create_dt`, `update_dt`)
19+
VALUES ('764d604ec6fc45f68cd92514c40e9e1a', 'continew-admin', '公告发布', 1, 1747546500000, 1, 1, 4, 1, 'NoticePublishJob', 3, '0 * * * * ?', 1, 60, 3, 1, 1, 27, 0, '', NULL, '定时发布公告', '', 0, NOW(), NOW());

continew-extension/continew-extension-schedule-server/src/main/resources/db/changelog/postgresql/snail-job_data.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ VALUES ('admin', '465c194afb65670f38322df087f0a9bb225cc257e43eb4ac5a0c98ef5b3173
1212
-- 默认分组:continew-admin
1313
INSERT INTO sj_group_config (id, namespace_id, group_name, description, token, group_status, version, group_partition, id_generator_mode, init_scene, create_dt, update_dt)
1414
VALUES (1, '764d604ec6fc45f68cd92514c40e9e1a', 'continew-admin', '默认分组', 'SJ_Wyz3dmsdbDOkDujOTSSoBjGQP1BMsVnj', 1, 1, 0, 2, 1, NOW(), NOW());
15+
16+
-- 默认任务:NoticePublishJob
17+
INSERT INTO sj_job
18+
(namespace_id, group_name, job_name, args_type, next_trigger_at, job_status, task_type, route_key, executor_type, executor_info, trigger_type, trigger_interval, block_strategy, executor_timeout, max_retry_times, parallel_num, retry_interval, bucket_index, resident, notify_ids, owner_id, description, ext_attrs, deleted, create_dt, update_dt)
19+
VALUES ('764d604ec6fc45f68cd92514c40e9e1a', 'continew-admin', '公告发布', 1, 1747546500000, 1, 1, 4, 1, 'NoticePublishJob', 3, '0 * * * * ?', 1, 60, 3, 1, 1, 27, 0, '', NULL, '定时发布公告', '', 0, NOW(), NOW());

continew-module-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import cn.hutool.core.util.ReUtil;
2525
import cn.hutool.json.JSONUtil;
2626
import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
27-
2827
import jakarta.servlet.http.HttpServletRequest;
2928
import lombok.RequiredArgsConstructor;
3029
import me.zhyd.oauth.AuthRequestBuilder;
@@ -54,11 +53,9 @@
5453
import top.continew.starter.core.autoconfigure.project.ProjectProperties;
5554
import top.continew.starter.core.exception.BadRequestException;
5655
import top.continew.starter.core.validation.ValidationUtils;
57-
import top.continew.starter.messaging.websocket.util.WebSocketUtils;
5856

5957
import java.time.LocalDateTime;
6058
import java.util.Collections;
61-
import java.util.List;
6259
import java.util.Objects;
6360

6461
/**
@@ -168,15 +165,10 @@ private AuthRequest getAuthRequest(String source) {
168165
* @param user 用户信息
169166
*/
170167
private void sendSecurityMsg(UserDO user) {
171-
MessageReq req = new MessageReq();
172-
MessageTemplateEnum socialRegister = MessageTemplateEnum.SOCIAL_REGISTER;
173-
req.setTitle(socialRegister.getTitle().formatted(projectProperties.getName()));
174-
req.setContent(socialRegister.getContent().formatted(user.getNickname()));
175-
req.setType(MessageTypeEnum.SECURITY);
176-
messageService.add(req, CollUtil.toList(user.getId()));
177-
List<String> tokenList = StpUtil.getTokenValueListByLoginId(user.getId());
178-
for (String token : tokenList) {
179-
WebSocketUtils.sendMessage(token, "1");
180-
}
168+
MessageTemplateEnum template = MessageTemplateEnum.SOCIAL_REGISTER;
169+
MessageReq req = new MessageReq(MessageTypeEnum.SECURITY);
170+
req.setTitle(template.getTitle().formatted(projectProperties.getName()));
171+
req.setContent(template.getContent().formatted(user.getNickname()));
172+
messageService.add(req, CollUtil.toList(user.getId().toString()));
181173
}
182174
}

continew-module-system/src/main/java/top/continew/admin/system/enums/MessageTemplateEnum.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ public enum MessageTemplateEnum {
3232
/**
3333
* 第三方登录
3434
*/
35-
SOCIAL_REGISTER("欢迎注册 %s", "尊敬的 %s,欢迎注册使用,请及时配置您的密码。");
35+
SOCIAL_REGISTER("欢迎注册 %s", "尊敬的 %s,欢迎注册使用,请及时配置您的密码。", "/user/profile"),
36+
37+
/**
38+
* 公告发布
39+
*/
40+
NOTICE_PUBLISH("您有一条新的公告", "公告《%s》已发布,请及时查看。", "/user/notice?id=%s");
3641

3742
private final String title;
3843
private final String content;
44+
private final String path;
3945
}

continew-module-system/src/main/java/top/continew/admin/system/enums/MessageTypeEnum.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@
3131
@RequiredArgsConstructor
3232
public enum MessageTypeEnum implements BaseEnum<Integer> {
3333

34+
/**
35+
* 系统消息
36+
*/
37+
SYSTEM(1, "系统消息", UiConstants.COLOR_PRIMARY),
38+
3439
/**
3540
* 安全消息
3641
*/
37-
SECURITY(1, "安全消息", UiConstants.COLOR_PRIMARY),;
42+
SECURITY(2, "安全消息", UiConstants.COLOR_WARNING),;
3843

3944
private final Integer value;
4045
private final String description;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.system.enums;
18+
19+
import lombok.Getter;
20+
import lombok.RequiredArgsConstructor;
21+
import top.continew.starter.core.enums.BaseEnum;
22+
23+
/**
24+
* 公告通知方式枚举
25+
*
26+
* @author Charles7c
27+
* @since 2025/5/8 21:18
28+
*/
29+
@Getter
30+
@RequiredArgsConstructor
31+
public enum NoticeMethodEnum implements BaseEnum<Integer> {
32+
33+
/**
34+
* 系统消息
35+
*/
36+
SYSTEM_MESSAGE(1, "系统消息"),;
37+
38+
private final Integer value;
39+
private final String description;
40+
}

continew-module-system/src/main/java/top/continew/admin/system/enums/NoticeStatusEnum.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import top.continew.admin.common.constant.UiConstants;
2222
import top.continew.starter.core.enums.BaseEnum;
2323

24-
import java.time.LocalDateTime;
25-
2624
/**
2725
* 公告状态枚举
2826
*
@@ -34,39 +32,21 @@
3432
public enum NoticeStatusEnum implements BaseEnum<Integer> {
3533

3634
/**
37-
* 待发布
35+
* 草稿
3836
*/
39-
PENDING_RELEASE(1, "待发布", UiConstants.COLOR_PRIMARY),
37+
DRAFT(1, "草稿", UiConstants.COLOR_WARNING),
4038

4139
/**
42-
* 已发布
40+
* 待发布
4341
*/
44-
PUBLISHED(2, "已发布", UiConstants.COLOR_SUCCESS),
42+
PENDING(2, "待发布", UiConstants.COLOR_PRIMARY),
4543

4644
/**
47-
* 已过期
45+
* 已发布
4846
*/
49-
EXPIRED(3, "已过期", UiConstants.COLOR_ERROR),;
47+
PUBLISHED(3, "已发布", UiConstants.COLOR_SUCCESS),;
5048

5149
private final Integer value;
5250
private final String description;
5351
private final String color;
54-
55-
/**
56-
* 获取公告状态
57-
*
58-
* @param effectiveTime 生效时间
59-
* @param terminateTime 终止时间
60-
* @return 公告状态
61-
*/
62-
public static NoticeStatusEnum getStatus(LocalDateTime effectiveTime, LocalDateTime terminateTime) {
63-
LocalDateTime now = LocalDateTime.now();
64-
if (effectiveTime != null && effectiveTime.isAfter(now)) {
65-
return PENDING_RELEASE;
66-
}
67-
if (terminateTime != null && terminateTime.isBefore(now)) {
68-
return EXPIRED;
69-
}
70-
return PUBLISHED;
71-
}
7252
}

continew-module-system/src/main/java/top/continew/admin/system/mapper/MessageUserMapper.java renamed to continew-module-system/src/main/java/top/continew/admin/system/mapper/MessageLogMapper.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,15 @@
1616

1717
package top.continew.admin.system.mapper;
1818

19-
import org.apache.ibatis.annotations.Param;
20-
import top.continew.admin.system.model.entity.MessageUserDO;
19+
import top.continew.admin.system.model.entity.MessageLogDO;
2120
import top.continew.starter.data.mp.base.BaseMapper;
2221

2322
/**
24-
* 消息和用户 Mapper
23+
* 消息日志 Mapper
2524
*
2625
* @author Bull-BCLS
26+
* @author Charles7c
2727
* @since 2023/10/15 20:25
2828
*/
29-
public interface MessageUserMapper extends BaseMapper<MessageUserDO> {
30-
31-
/**
32-
* 根据用户 ID 和消息类型查询未读消息数量
33-
*
34-
* @param userId 用户 ID
35-
* @param type 消息类型
36-
* @return 未读消息信息
37-
*/
38-
Long selectUnreadCountByUserIdAndType(@Param("userId") Long userId, @Param("type") Integer type);
29+
public interface MessageLogMapper extends BaseMapper<MessageLogDO> {
3930
}

continew-module-system/src/main/java/top/continew/admin/system/mapper/MessageMapper.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616

1717
package top.continew.admin.system.mapper;
1818

19-
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
2019
import com.baomidou.mybatisplus.core.metadata.IPage;
21-
import com.baomidou.mybatisplus.core.toolkit.Constants;
20+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
2221
import org.apache.ibatis.annotations.Param;
2322
import top.continew.admin.system.model.entity.MessageDO;
23+
import top.continew.admin.system.model.query.MessageQuery;
2424
import top.continew.admin.system.model.resp.message.MessageResp;
2525
import top.continew.starter.data.mp.base.BaseMapper;
2626

27+
import java.util.List;
28+
2729
/**
2830
* 消息 Mapper
2931
*
@@ -33,12 +35,28 @@
3335
public interface MessageMapper extends BaseMapper<MessageDO> {
3436

3537
/**
36-
* 分页查询列表
38+
* 分页查询消息列表
39+
*
40+
* @param page 分页参数
41+
* @param query 查询条件
42+
* @return 消息列表
43+
*/
44+
IPage<MessageResp> selectMessagePage(@Param("page") Page<MessageDO> page, @Param("query") MessageQuery query);
45+
46+
/**
47+
* 查询未读消息列表
48+
*
49+
* @param userId 用户 ID
50+
* @return 消息列表
51+
*/
52+
List<MessageDO> selectUnreadListByUserId(@Param("userId") Long userId);
53+
54+
/**
55+
* 查询未读消息数量
3756
*
38-
* @param page 分页查询条件
39-
* @param queryWrapper 查询条件
40-
* @return 分页信息
57+
* @param userId 用户 ID
58+
* @param type 消息类型
59+
* @return 未读消息数量
4160
*/
42-
IPage<MessageResp> selectPageByUserId(@Param("page") IPage<Object> page,
43-
@Param(Constants.WRAPPER) QueryWrapper<MessageDO> queryWrapper);
61+
Long selectUnreadCountByUserIdAndType(@Param("userId") Long userId, @Param("type") Integer type);
4462
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.system.mapper;
18+
19+
import top.continew.admin.system.model.entity.NoticeLogDO;
20+
import top.continew.starter.data.mp.base.BaseMapper;
21+
22+
/**
23+
* 公告日志 Mapper
24+
*
25+
* @author Charles7c
26+
* @since 2025/5/18 19:17
27+
*/
28+
public interface NoticeLogMapper extends BaseMapper<NoticeLogDO> {
29+
}

0 commit comments

Comments
 (0)