mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-16 20:57:11 +08:00
refactor: 优化站内信及消息管理
1.新增站内信未读消息轮询 2.优化消息管理 API,移除部分无用 API 3.优化部分代码格式
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
package top.charles7c.cnadmin.webapi.controller.system;
|
||||
|
||||
import static top.charles7c.cnadmin.common.annotation.CrudRequestMapping.Api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -27,14 +25,16 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import top.charles7c.cnadmin.common.annotation.CrudRequestMapping;
|
||||
import top.charles7c.cnadmin.common.base.BaseController;
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
import top.charles7c.cnadmin.common.model.vo.R;
|
||||
import top.charles7c.cnadmin.common.util.helper.LoginHelper;
|
||||
import top.charles7c.cnadmin.monitor.annotation.Log;
|
||||
import top.charles7c.cnadmin.system.model.query.MessageQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.MessageRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.MessageUnreadVO;
|
||||
import top.charles7c.cnadmin.system.model.vo.MessageVO;
|
||||
import top.charles7c.cnadmin.system.service.MessageService;
|
||||
import top.charles7c.cnadmin.system.service.MessageUserService;
|
||||
@@ -48,16 +48,39 @@ import top.charles7c.cnadmin.system.service.MessageUserService;
|
||||
@Tag(name = "消息管理 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@CrudRequestMapping(value = "/system/message", api = {Api.PAGE, Api.GET, Api.DELETE, Api.LIST})
|
||||
public class MessageController
|
||||
extends BaseController<MessageService, MessageVO, MessageVO, MessageQuery, MessageRequest> {
|
||||
@RequestMapping("/system/message")
|
||||
public class MessageController {
|
||||
|
||||
private final MessageService baseService;
|
||||
private final MessageUserService messageUserService;
|
||||
|
||||
@Operation(summary = "分页查询列表", description = "分页查询列表")
|
||||
@GetMapping
|
||||
public PageDataVO<MessageVO> page(MessageQuery query, @Validated PageQuery pageQuery) {
|
||||
query.setUserId(LoginHelper.getUserId());
|
||||
return baseService.page(query, pageQuery);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除数据", description = "删除数据")
|
||||
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R delete(@PathVariable List<Long> ids) {
|
||||
baseService.delete(ids);
|
||||
return R.ok("删除成功");
|
||||
}
|
||||
|
||||
@Operation(description = "标记已读", summary = "将消息标记为已读状态")
|
||||
@Parameter(name = "ids", description = "消息ID列表", example = "1,2", in = ParameterIn.QUERY)
|
||||
@PatchMapping("/read")
|
||||
public void readMessage(@RequestParam(required = false) List<Long> ids) {
|
||||
messageUserService.readMessage(ids);
|
||||
}
|
||||
|
||||
@Log(ignore = true)
|
||||
@Operation(description = "查询未读消息数量", summary = "查询当前用户的未读消息数量")
|
||||
@Parameter(name = "isDetail", description = "是否查询详情", example = "true", in = ParameterIn.QUERY)
|
||||
@GetMapping("/unread")
|
||||
public MessageUnreadVO countUnreadMessage(@RequestParam(required = false) Boolean detail) {
|
||||
return messageUserService.countUnreadMessageByUserId(LoginHelper.getUserId(), detail);
|
||||
}
|
||||
}
|
@@ -7,14 +7,3 @@ INSERT IGNORE INTO `sys_menu`
|
||||
VALUES
|
||||
(1060, '消息管理', 1000, 2, '/system/message', 'Message', 'system/message/index', 'notification', b'0', b'0', b'0', 'system:message:list', 6, 1, 1, NOW(), NULL, NULL),
|
||||
(1061, '消息删除', 1060, 3, NULL, NULL, NULL, NULL, b'0', b'0', b'0', 'system:message:delete', 1, 1, 1, NOW(), NULL, NULL);
|
||||
|
||||
-- 初始化默认字典
|
||||
INSERT IGNORE INTO `sys_dict`
|
||||
(`id`, `name`, `code`, `description`, `is_system`, `create_user`, `create_time`, `update_user`, `update_time`)
|
||||
VALUES
|
||||
(2, '消息类型', 'message_type', NULL, b'1', 1, NOW(), NULL, NULL);
|
||||
|
||||
INSERT IGNORE INTO `sys_dict_item`
|
||||
(`id`, `label`, `value`, `color`, `sort`, `description`, `dict_id`, `create_user`, `create_time`, `update_user`, `update_time`)
|
||||
VALUES
|
||||
(3, '系统消息', '1', 'blue', 1, NULL, 2, 1, NOW(), NULL, NULL);
|
||||
|
@@ -13,19 +13,19 @@ CREATE TABLE IF NOT EXISTS `sys_user_social` (
|
||||
|
||||
-- changeset BUSS_BCLS:2
|
||||
CREATE TABLE IF NOT EXISTS `sys_message` (
|
||||
`id` bigint(20) AUTO_INCREMENT COMMENT 'ID',
|
||||
`title` varchar(50) NOT NULL COMMENT '主题',
|
||||
`content` varchar(255) DEFAULT NULL COMMENT '内容',
|
||||
`type` varchar(30) NOT NULL COMMENT '类型',
|
||||
`create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
`id` bigint(20) AUTO_INCREMENT COMMENT 'ID',
|
||||
`title` varchar(50) NOT NULL COMMENT '标题',
|
||||
`content` varchar(255) DEFAULT NULL COMMENT '内容',
|
||||
`type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '类型(1:系统消息)',
|
||||
`create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_message_user` (
|
||||
`message_id` bigint(20) NOT NULL COMMENT '消息ID',
|
||||
`user_id` bigint(11) NOT NULL COMMENT '用户ID',
|
||||
`read_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已读',
|
||||
`read_time` datetime DEFAULT NULL COMMENT '读取时间',
|
||||
`message_id` bigint(20) NOT NULL COMMENT '消息ID',
|
||||
`user_id` bigint(11) NOT NULL COMMENT '用户ID',
|
||||
`is_read` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已读',
|
||||
`read_time` datetime DEFAULT NULL COMMENT '读取时间',
|
||||
PRIMARY KEY (`message_id`,`user_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息和用户关联表';
|
Reference in New Issue
Block a user