Skip to content

Commit 9269429

Browse files
committed
feat: 新增查询消息详情接口
1 parent a2c1764 commit 9269429

File tree

7 files changed

+157
-8
lines changed

7 files changed

+157
-8
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.ibatis.annotations.Param;
2222
import top.continew.admin.system.model.entity.MessageDO;
2323
import top.continew.admin.system.model.query.MessageQuery;
24+
import top.continew.admin.system.model.resp.message.MessageDetailResp;
2425
import top.continew.admin.system.model.resp.message.MessageResp;
2526
import top.continew.starter.data.mp.base.BaseMapper;
2627

@@ -43,6 +44,14 @@ public interface MessageMapper extends BaseMapper<MessageDO> {
4344
*/
4445
IPage<MessageResp> selectMessagePage(@Param("page") Page<MessageDO> page, @Param("query") MessageQuery query);
4546

47+
/**
48+
* 查询消息详情
49+
*
50+
* @param id ID
51+
* @return 消息详情
52+
*/
53+
MessageDetailResp selectMessageById(@Param("id") Long id);
54+
4655
/**
4756
* 查询未读消息列表
4857
*
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.model.resp.message;
18+
19+
import io.swagger.v3.oas.annotations.media.Schema;
20+
import lombok.Data;
21+
import top.continew.admin.system.enums.MessageTypeEnum;
22+
import top.continew.admin.system.enums.NoticeScopeEnum;
23+
24+
import java.io.Serial;
25+
import java.io.Serializable;
26+
import java.time.LocalDateTime;
27+
import java.util.List;
28+
29+
/**
30+
* 消息详情响应参数
31+
*
32+
* @author Charles7c
33+
* @since 2025/6/13 21:22
34+
*/
35+
@Data
36+
@Schema(description = "消息详情响应参数")
37+
public class MessageDetailResp implements Serializable {
38+
39+
@Serial
40+
private static final long serialVersionUID = 1L;
41+
42+
/**
43+
* ID
44+
*/
45+
@Schema(description = "ID", example = "1")
46+
private Long id;
47+
48+
/**
49+
* 标题
50+
*/
51+
@Schema(description = "标题", example = "欢迎注册 xxx")
52+
private String title;
53+
54+
/**
55+
* 内容
56+
*/
57+
@Schema(description = "内容", example = "尊敬的 xx,欢迎注册使用,请及时配置您的密码。")
58+
private String content;
59+
60+
/**
61+
* 类型
62+
*/
63+
@Schema(description = "类型", example = "1")
64+
private MessageTypeEnum type;
65+
66+
/**
67+
* 跳转路径
68+
*/
69+
@Schema(description = "跳转路径", example = "/user/profile")
70+
private String path;
71+
72+
/**
73+
* 通知范围
74+
*/
75+
@Schema(description = "通知范围", example = "2")
76+
private NoticeScopeEnum scope;
77+
78+
/**
79+
* 通知用户
80+
*/
81+
@Schema(description = "通知用户", example = "[1,2]")
82+
private List<String> users;
83+
84+
/**
85+
* 是否已读
86+
*/
87+
@Schema(description = "是否已读", example = "true")
88+
private Boolean isRead;
89+
90+
/**
91+
* 读取时间
92+
*/
93+
@Schema(description = "读取时间", example = "2023-08-08 23:59:59", type = "string")
94+
private LocalDateTime readTime;
95+
96+
/**
97+
* 创建时间
98+
*/
99+
@Schema(description = "创建时间", example = "2023-08-08 08:08:08", type = "string")
100+
private LocalDateTime createTime;
101+
}

continew-module-system/src/main/java/top/continew/admin/system/model/resp/message/MessageResp.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ public class MessageResp implements Serializable {
4949
@Schema(description = "标题", example = "欢迎注册 xxx")
5050
private String title;
5151

52-
/**
53-
* 内容
54-
*/
55-
@Schema(description = "内容", example = "尊敬的 xx,欢迎注册使用,请及时配置您的密码。")
56-
private String content;
57-
5852
/**
5953
* 类型
6054
*/

continew-module-system/src/main/java/top/continew/admin/system/service/MessageService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import top.continew.admin.system.model.query.MessageQuery;
2020
import top.continew.admin.system.model.req.MessageReq;
21+
import top.continew.admin.system.model.resp.message.MessageDetailResp;
2122
import top.continew.admin.system.model.resp.message.MessageResp;
2223
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
2324
import top.continew.starter.extension.crud.model.query.PageQuery;
@@ -43,6 +44,14 @@ public interface MessageService {
4344
*/
4445
PageResp<MessageResp> page(MessageQuery query, PageQuery pageQuery);
4546

47+
/**
48+
* 查询详情
49+
*
50+
* @param id ID
51+
* @return 详情信息
52+
*/
53+
MessageDetailResp get(Long id);
54+
4655
/**
4756
* 将消息标记已读
4857
*

continew-module-system/src/main/java/top/continew/admin/system/service/impl/MessageServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import top.continew.admin.system.model.entity.MessageDO;
3232
import top.continew.admin.system.model.query.MessageQuery;
3333
import top.continew.admin.system.model.req.MessageReq;
34+
import top.continew.admin.system.model.resp.message.MessageDetailResp;
3435
import top.continew.admin.system.model.resp.message.MessageResp;
3536
import top.continew.admin.system.model.resp.message.MessageTypeUnreadResp;
3637
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
@@ -65,6 +66,11 @@ public PageResp<MessageResp> page(MessageQuery query, PageQuery pageQuery) {
6566
return PageResp.build(page);
6667
}
6768

69+
@Override
70+
public MessageDetailResp get(Long id) {
71+
return baseMapper.selectMessageById(id);
72+
}
73+
6874
@Override
6975
public void readMessage(List<Long> ids, Long userId) {
7076
// 查询当前用户的未读消息

continew-module-system/src/main/resources/mapper/MessageMapper.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
SELECT
77
t1.id,
88
t1.title,
9-
t1.content,
109
t1.type,
1110
t1.path,
1211
t1.scope,
@@ -33,6 +32,23 @@
3332
ORDER BY t1.create_time DESC
3433
</select>
3534

35+
<select id="selectMessageById" resultType="top.continew.admin.system.model.resp.message.MessageDetailResp">
36+
SELECT
37+
t1.id,
38+
t1.title,
39+
t1.content,
40+
t1.type,
41+
t1.path,
42+
t1.scope,
43+
t1.users,
44+
t1.create_time,
45+
t2.read_time IS NOT NULL AS isRead,
46+
t2.read_time AS readTime
47+
FROM sys_message AS t1
48+
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id
49+
WHERE t1.id = #{id}
50+
</select>
51+
3652
<select id="selectUnreadListByUserId" resultType="top.continew.admin.system.model.entity.MessageDO">
3753
SELECT
3854
t1.*

continew-webapi/src/main/java/top/continew/admin/controller/system/UserMessageController.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import top.continew.admin.system.enums.NoticeScopeEnum;
2929
import top.continew.admin.system.model.query.MessageQuery;
3030
import top.continew.admin.system.model.query.NoticeQuery;
31+
import top.continew.admin.system.model.resp.message.MessageDetailResp;
3132
import top.continew.admin.system.model.resp.message.MessageResp;
3233
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
3334
import top.continew.admin.system.model.resp.notice.NoticeDetailResp;
@@ -42,6 +43,7 @@
4243
import top.continew.starter.extension.crud.model.resp.PageResp;
4344
import top.continew.starter.log.annotation.Log;
4445

46+
import java.util.Collections;
4547
import java.util.List;
4648

4749
/**
@@ -75,6 +77,18 @@ public PageResp<MessageResp> page(MessageQuery query, @Validated PageQuery pageQ
7577
return messageService.page(query, pageQuery);
7678
}
7779

80+
@Operation(summary = "查询消息", description = "查询消息详情")
81+
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
82+
@GetMapping("/{id}")
83+
public MessageDetailResp getMessage(@PathVariable Long id) {
84+
MessageDetailResp detail = messageService.get(id);
85+
CheckUtils.throwIf(detail == null || (NoticeScopeEnum.USER.equals(detail.getScope()) && !detail.getUsers()
86+
.contains(UserContextHolder.getUserId().toString())), "消息不存在或无权限访问");
87+
messageService.readMessage(Collections.singletonList(id), UserContextHolder.getUserId());
88+
detail.setIsRead(true);
89+
return detail;
90+
}
91+
7892
@Operation(summary = "删除消息", description = "删除消息")
7993
@DeleteMapping
8094
public void delete(@Validated @RequestBody IdsReq req) {
@@ -116,7 +130,7 @@ public BasePageResp<NoticeResp> pageNotice(@Validated NoticeQuery query, @Valida
116130
return noticeService.page(query, pageQuery);
117131
}
118132

119-
@Operation(summary = "查询公告详情", description = "查询公告")
133+
@Operation(summary = "查询公告", description = "查询公告详情")
120134
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
121135
@GetMapping("/notice/{id}")
122136
public NoticeDetailResp getNotice(@PathVariable Long id) {

0 commit comments

Comments
 (0)