mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-08 22:57:12 +08:00
feat: 新增查询消息详情接口
This commit is contained in:
@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.continew.admin.system.model.entity.MessageDO;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.resp.message.MessageDetailResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
@@ -43,6 +44,14 @@ public interface MessageMapper extends BaseMapper<MessageDO> {
|
||||
*/
|
||||
IPage<MessageResp> selectMessagePage(@Param("page") Page<MessageDO> page, @Param("query") MessageQuery query);
|
||||
|
||||
/**
|
||||
* 查询消息详情
|
||||
*
|
||||
* @param id ID
|
||||
* @return 消息详情
|
||||
*/
|
||||
MessageDetailResp selectMessageById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询未读消息列表
|
||||
*
|
||||
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp.message;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息详情响应参数
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/6/13 21:22
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "消息详情响应参数")
|
||||
public class MessageDetailResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@Schema(description = "ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@Schema(description = "标题", example = "欢迎注册 xxx")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@Schema(description = "内容", example = "尊敬的 xx,欢迎注册使用,请及时配置您的密码。")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型", example = "1")
|
||||
private MessageTypeEnum type;
|
||||
|
||||
/**
|
||||
* 跳转路径
|
||||
*/
|
||||
@Schema(description = "跳转路径", example = "/user/profile")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@Schema(description = "通知范围", example = "2")
|
||||
private NoticeScopeEnum scope;
|
||||
|
||||
/**
|
||||
* 通知用户
|
||||
*/
|
||||
@Schema(description = "通知用户", example = "[1,2]")
|
||||
private List<String> users;
|
||||
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
@Schema(description = "是否已读", example = "true")
|
||||
private Boolean isRead;
|
||||
|
||||
/**
|
||||
* 读取时间
|
||||
*/
|
||||
@Schema(description = "读取时间", example = "2023-08-08 23:59:59", type = "string")
|
||||
private LocalDateTime readTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2023-08-08 08:08:08", type = "string")
|
||||
private LocalDateTime createTime;
|
||||
}
|
@@ -49,12 +49,6 @@ public class MessageResp implements Serializable {
|
||||
@Schema(description = "标题", example = "欢迎注册 xxx")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@Schema(description = "内容", example = "尊敬的 xx,欢迎注册使用,请及时配置您的密码。")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
|
@@ -18,6 +18,7 @@ package top.continew.admin.system.service;
|
||||
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.resp.message.MessageDetailResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||
@@ -43,6 +44,14 @@ public interface MessageService {
|
||||
*/
|
||||
PageResp<MessageResp> page(MessageQuery query, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @param id ID
|
||||
* @return 详情信息
|
||||
*/
|
||||
MessageDetailResp get(Long id);
|
||||
|
||||
/**
|
||||
* 将消息标记已读
|
||||
*
|
||||
|
@@ -31,6 +31,7 @@ import top.continew.admin.system.mapper.MessageMapper;
|
||||
import top.continew.admin.system.model.entity.MessageDO;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.resp.message.MessageDetailResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageTypeUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
@@ -65,6 +66,11 @@ public class MessageServiceImpl implements MessageService {
|
||||
return PageResp.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageDetailResp get(Long id) {
|
||||
return baseMapper.selectMessageById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMessage(List<Long> ids, Long userId) {
|
||||
// 查询当前用户的未读消息
|
||||
|
@@ -6,7 +6,6 @@
|
||||
SELECT
|
||||
t1.id,
|
||||
t1.title,
|
||||
t1.content,
|
||||
t1.type,
|
||||
t1.path,
|
||||
t1.scope,
|
||||
@@ -33,6 +32,23 @@
|
||||
ORDER BY t1.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectMessageById" resultType="top.continew.admin.system.model.resp.message.MessageDetailResp">
|
||||
SELECT
|
||||
t1.id,
|
||||
t1.title,
|
||||
t1.content,
|
||||
t1.type,
|
||||
t1.path,
|
||||
t1.scope,
|
||||
t1.users,
|
||||
t1.create_time,
|
||||
t2.read_time IS NOT NULL AS isRead,
|
||||
t2.read_time AS readTime
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id
|
||||
WHERE t1.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectUnreadListByUserId" resultType="top.continew.admin.system.model.entity.MessageDO">
|
||||
SELECT
|
||||
t1.*
|
||||
|
@@ -28,6 +28,7 @@ import top.continew.admin.system.enums.NoticeMethodEnum;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.query.NoticeQuery;
|
||||
import top.continew.admin.system.model.resp.message.MessageDetailResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.admin.system.model.resp.notice.NoticeDetailResp;
|
||||
@@ -42,6 +43,7 @@ import top.continew.starter.extension.crud.model.resp.BasePageResp;
|
||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||
import top.continew.starter.log.annotation.Log;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -75,6 +77,18 @@ public class UserMessageController {
|
||||
return messageService.page(query, pageQuery);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询消息", description = "查询消息详情")
|
||||
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
|
||||
@GetMapping("/{id}")
|
||||
public MessageDetailResp getMessage(@PathVariable Long id) {
|
||||
MessageDetailResp detail = messageService.get(id);
|
||||
CheckUtils.throwIf(detail == null || (NoticeScopeEnum.USER.equals(detail.getScope()) && !detail.getUsers()
|
||||
.contains(UserContextHolder.getUserId().toString())), "消息不存在或无权限访问");
|
||||
messageService.readMessage(Collections.singletonList(id), UserContextHolder.getUserId());
|
||||
detail.setIsRead(true);
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Operation(summary = "删除消息", description = "删除消息")
|
||||
@DeleteMapping
|
||||
public void delete(@Validated @RequestBody IdsReq req) {
|
||||
@@ -116,7 +130,7 @@ public class UserMessageController {
|
||||
return noticeService.page(query, pageQuery);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询公告详情", description = "查询公告")
|
||||
@Operation(summary = "查询公告", description = "查询公告详情")
|
||||
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
|
||||
@GetMapping("/notice/{id}")
|
||||
public NoticeDetailResp getNotice(@PathVariable Long id) {
|
||||
|
Reference in New Issue
Block a user