From f7a3e2cf5bc7c570ec996c38c08e7e704d4043c0 Mon Sep 17 00:00:00 2001 From: Kylin Date: Tue, 27 Aug 2024 17:51:53 +0800 Subject: [PATCH 01/15] =?UTF-8?q?feat:=20=E6=96=B0=E5=BB=BA=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=80=9A=E7=9F=A5=E5=90=8E=E7=AB=AF=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新建根据websocket的后端部分代码.其中包含sql数据库文件 --- sql/mysql5/youlai_boot.sql | 549 +++++++++++------- .../system/controller/NoticeController.java | 81 +++ .../controller/NoticeStatusController.java | 81 +++ .../controller/WebsocketController.java | 1 + .../converter/NoticeStatusConverter.java | 20 + .../system/mapper/NoticeStatusMapper.java | 28 + .../youlai/system/model/entity/Notice.java | 73 +++ .../system/model/entity/NoticeStatus.java | 38 ++ .../youlai/system/model/form/NoticeForm.java | 66 +++ .../system/model/form/NoticeStatusForm.java | 26 + .../system/model/query/NoticeQuery.java | 41 ++ .../system/model/query/NoticeStatusQuery.java | 21 + .../system/model/vo/NoticeStatusVO.java | 25 + .../com/youlai/system/model/vo/NoticeVO.java | 48 ++ .../youlai/system/service/NoticeService.java | 58 ++ .../system/service/NoticeStatusService.java | 58 ++ .../system/service/WebsocketService.java | 5 + .../service/impl/NoticeServiceImpl.java | 140 +++++ .../service/impl/NoticeStatusServiceImpl.java | 103 ++++ .../service/impl/WebsocketServiceImpl.java | 6 + src/main/resources/mapper/NoticeMapper.xml | 67 +++ .../resources/mapper/NoticeStatusMapper.xml | 14 + 22 files changed, 1329 insertions(+), 220 deletions(-) create mode 100644 src/main/java/com/youlai/system/controller/NoticeController.java create mode 100644 src/main/java/com/youlai/system/controller/NoticeStatusController.java create mode 100644 src/main/java/com/youlai/system/converter/NoticeStatusConverter.java create mode 100644 src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java create mode 100644 src/main/java/com/youlai/system/model/entity/Notice.java create mode 100644 src/main/java/com/youlai/system/model/entity/NoticeStatus.java create mode 100644 src/main/java/com/youlai/system/model/form/NoticeForm.java create mode 100644 src/main/java/com/youlai/system/model/form/NoticeStatusForm.java create mode 100644 src/main/java/com/youlai/system/model/query/NoticeQuery.java create mode 100644 src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java create mode 100644 src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java create mode 100644 src/main/java/com/youlai/system/model/vo/NoticeVO.java create mode 100644 src/main/java/com/youlai/system/service/NoticeService.java create mode 100644 src/main/java/com/youlai/system/service/NoticeStatusService.java create mode 100644 src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java create mode 100644 src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java create mode 100644 src/main/resources/mapper/NoticeMapper.xml create mode 100644 src/main/resources/mapper/NoticeStatusMapper.xml diff --git a/sql/mysql5/youlai_boot.sql b/sql/mysql5/youlai_boot.sql index acd7f106..93d5c605 100644 --- a/sql/mysql5/youlai_boot.sql +++ b/sql/mysql5/youlai_boot.sql @@ -1,61 +1,139 @@ /* -* youlai_boot 权限系统数据库(MySQL5.x) -* @author youlai -* @date 2024/06/24 + Navicat Premium Dump SQL + + Source Server : 本地数据库 + Source Server Type : MySQL + Source Server Version : 50744 (5.7.44) + Source Host : localhost:3306 + Source Schema : youlai_boot + + Target Server Type : MySQL + Target Server Version : 50744 (5.7.44) + File Encoding : 65001 + + Date: 27/08/2024 16:44:13 */ --- ---------------------------- --- 1. 创建数据库 --- ---------------------------- -CREATE DATABASE IF NOT EXISTS youlai_boot DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; - - --- ---------------------------- --- 2. 创建表 && 数据初始化 --- ---------------------------- -use youlai_boot; - -SET NAMES utf8; +SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; +-- ---------------------------- +-- Table structure for gen_config +-- ---------------------------- +DROP TABLE IF EXISTS `gen_config`; +CREATE TABLE `gen_config` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `table_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '表名', + `module_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '模块名', + `package_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '包名', + `business_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务名', + `entity_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '实体类名', + `author` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '作者', + `parent_menu_id` bigint(20) NULL DEFAULT NULL COMMENT '上级菜单ID,对应sys_menu的id ', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_tablename_deleted`(`table_name`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '代码生成基础配置表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of gen_config +-- ---------------------------- +INSERT INTO `gen_config` VALUES (1, 'sys_notice_status', 'system', 'com.youlai', '用户公告状态', 'NoticeStatus', 'youlaitech', 1, '2024-08-24 13:38:48', '2024-08-24 13:38:48'); +INSERT INTO `gen_config` VALUES (2, 'sys_notice', 'system', 'com.youlai', '通知公告', 'Notice', 'youlaitech', 1, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); + +-- ---------------------------- +-- Table structure for gen_field_config +-- ---------------------------- +DROP TABLE IF EXISTS `gen_field_config`; +CREATE TABLE `gen_field_config` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `config_id` bigint(20) NOT NULL COMMENT '关联的配置ID', + `column_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `column_type` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `max_length` int(11) NULL DEFAULT NULL COMMENT '最大长度', + `field_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '字段名称', + `field_type` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '字段类型', + `field_sort` int(11) NULL DEFAULT NULL COMMENT '字段排序', + `field_comment` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '字段描述', + `is_required` tinyint(1) NULL DEFAULT NULL COMMENT '是否必填', + `is_show_in_list` tinyint(1) NULL DEFAULT 0 COMMENT '是否在列表显示', + `is_show_in_form` tinyint(1) NULL DEFAULT 0 COMMENT '是否在表单显示', + `is_show_in_query` tinyint(1) NULL DEFAULT 0 COMMENT '是否在查询条件显示', + `query_type` tinyint(4) NULL DEFAULT NULL COMMENT '查询方式', + `form_type` tinyint(4) NULL DEFAULT NULL COMMENT '表单类型', + `dict_type` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '字典类型(sys_dict表的code)', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 21 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '代码生成字段配置表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of gen_field_config +-- ---------------------------- +INSERT INTO `gen_field_config` VALUES (1, 1, 'id', 'bigint', NULL, 'id', 'Long', 1, 'id', 0, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48'); +INSERT INTO `gen_field_config` VALUES (2, 1, 'notice_id', 'bigint', NULL, 'noticeId', 'Long', 2, '公共通知id', 0, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48'); +INSERT INTO `gen_field_config` VALUES (3, 1, 'user_id', 'int', NULL, 'userId', 'Integer', 3, '用户id', 0, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48'); +INSERT INTO `gen_field_config` VALUES (4, 1, 'read_status', 'bigint', NULL, 'readStatus', 'Long', 4, '读取状态,0未读,1已读取', 1, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48'); +INSERT INTO `gen_field_config` VALUES (5, 1, 'read_tiem', 'datetime', NULL, 'readTiem', 'LocalDateTime', 5, '用户阅读时间', 1, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48'); +INSERT INTO `gen_field_config` VALUES (6, 2, 'id', 'bigint', NULL, 'id', 'Long', 1, '', 0, 1, 1, 0, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (7, 2, 'title', 'varchar', 50, 'title', 'String', 2, '通知标题', 1, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (8, 2, 'content', 'text', 65535, 'content', 'String', 3, '通知内容', 1, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (9, 2, 'notice_type', 'int', NULL, 'noticeType', 'Integer', 4, '通知类型', 0, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (10, 2, 'release', 'bigint', NULL, 'release', 'Long', 5, '发布人', 1, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (11, 2, 'priority', 'tinyint', NULL, 'priority', 'Integer', 6, '优先级(0-低 1-中 2-高)', 0, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (12, 2, 'tar_type', 'tinyint', NULL, 'tarType', 'Integer', 7, '目标类型(0-全体 1-指定)', 0, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (13, 2, 'send_status', 'tinyint', NULL, 'sendStatus', 'Integer', 8, '发布状态(0-未发布 1已发布 2已撤回)', 0, 1, 1, 1, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (14, 2, 'send_time', 'datetime', NULL, 'sendTime', 'LocalDateTime', 9, '发布时间', 1, 1, 1, 1, 4, 9, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (15, 2, 'recall_time', 'datetime', NULL, 'recallTime', 'LocalDateTime', 10, '撤回时间', 1, 1, 1, 1, 4, 9, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (16, 2, 'create_by', 'bigint', NULL, 'createBy', 'Long', 11, '创建人ID', 0, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (17, 2, 'create_time', 'datetime', NULL, 'createTime', 'LocalDateTime', 12, '创建时间', 0, 1, 0, 0, 4, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (18, 2, 'update_by', 'bigint', NULL, 'updateBy', 'Long', 13, '更新人ID', 1, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (19, 2, 'update_time', 'datetime', NULL, 'updateTime', 'LocalDateTime', 14, '更新时间', 1, 1, 0, 0, 4, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); +INSERT INTO `gen_field_config` VALUES (20, 2, 'is_delete', 'tinyint', NULL, 'isDelete', 'Integer', 15, '逻辑删除标识(0-未删除 1-已删除)', 0, 0, 0, 0, 1, 1, NULL, '2024-08-24 13:39:03', '2024-08-27 10:30:57'); -- ---------------------------- -- Table structure for sys_config -- ---------------------------- DROP TABLE IF EXISTS `sys_config`; -CREATE TABLE `sys_config` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `config_name` varchar(50) NOT NULL COMMENT '配置名称', - `config_key` varchar(50) NOT NULL COMMENT '配置key', - `config_value` varchar(100) NOT NULL COMMENT '配置值', - `remark` varchar(200) DEFAULT NULL COMMENT '描述、备注', - `create_time` datetime NOT NULL COMMENT '创建时间', - `create_by` bigint NOT NULL COMMENT '创建人ID', - `update_time` datetime DEFAULT NULL COMMENT '更新时间', - `update_by` bigint DEFAULT NULL COMMENT '更新人ID', - `is_deleted` tinyint(1) NOT NULL COMMENT '逻辑删除标识(0-未删除 1-已删除)', - PRIMARY KEY (`id`) -) ENGINE=InnoDB COMMENT='系统配置'; +CREATE TABLE `sys_config` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `config_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '配置名称', + `config_key` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '配置key', + `config_value` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '配置值', + `remark` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '描述、备注', + `create_time` datetime NOT NULL COMMENT '创建时间', + `create_by` bigint(20) NOT NULL COMMENT '创建人ID', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `update_by` bigint(20) NULL DEFAULT NULL COMMENT '更新人ID', + `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '系统配置' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sys_config +-- ---------------------------- +INSERT INTO `sys_config` VALUES (1, 'IP请求限制QPS阈值', 'IP_QPS_THRESHOLD_LIMIT', '10', 'IP请求限制QPS阈值', '2024-08-10 14:31:34', 2, '2024-08-10 14:53:51', 2, 0); -- ---------------------------- -- Table structure for sys_dept -- ---------------------------- DROP TABLE IF EXISTS `sys_dept`; CREATE TABLE `sys_dept` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '部门名称', - `code` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '部门编号', - `parent_id` bigint NOT NULL DEFAULT 0 COMMENT '父节点id', - `tree_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '父节点id路径', - `sort` smallint NULL DEFAULT 0 COMMENT '显示顺序', - `status` tinyint NOT NULL DEFAULT 1 COMMENT '状态(1-正常 0-禁用)', - `create_by` bigint NULL DEFAULT NULL COMMENT '创建人ID', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `update_by` bigint NULL DEFAULT NULL COMMENT '修改人ID', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(1-已删除 0-未删除)', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `uk_code`(`code` ASC) USING BTREE COMMENT '部门编号唯一索引' + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '部门名称', + `code` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '部门编号', + `parent_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '父节点id', + `tree_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '父节点id路径', + `sort` smallint(6) NULL DEFAULT 0 COMMENT '显示顺序', + `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态(1-正常 0-禁用)', + `create_by` bigint(20) NULL DEFAULT NULL COMMENT '创建人ID', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_by` bigint(20) NULL DEFAULT NULL COMMENT '修改人ID', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(1-已删除 0-未删除)', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_code`(`code`) USING BTREE COMMENT '部门编号唯一索引' ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '部门表' ROW_FORMAT = DYNAMIC; -- ---------------------------- @@ -70,17 +148,17 @@ INSERT INTO `sys_dept` VALUES (3, '测试部门', 'QA001', 1, '0,1', 1, 1, 2, NU -- ---------------------------- DROP TABLE IF EXISTS `sys_dict`; CREATE TABLE `sys_dict` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键 ', - `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '类型名称', - `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '类型编码', - `status` tinyint(1) NULL DEFAULT 0 COMMENT '状态(0:正常;1:禁用)', - `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `is_deleted` tinyint NULL DEFAULT 0 COMMENT '是否删除(1-删除,0-未删除)', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `uk_code`(`code` ASC) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 89 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '字典类型表' ROW_FORMAT = DYNAMIC; + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键 ', + `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '类型名称', + `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '类型编码', + `status` tinyint(1) NULL DEFAULT 0 COMMENT '状态(0:正常;1:禁用)', + `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `is_deleted` tinyint(4) NULL DEFAULT 0 COMMENT '是否删除(1-删除,0-未删除)', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_code`(`code`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '字典类型表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_dict @@ -92,17 +170,17 @@ INSERT INTO `sys_dict` VALUES (1, '性别', 'gender', 1, NULL, '2019-12-06 19:03 -- ---------------------------- DROP TABLE IF EXISTS `sys_dict_item`; CREATE TABLE `sys_dict_item` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `dict_id` bigint NULL DEFAULT NULL COMMENT '字典ID', - `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '字典项名称', - `value` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '字典项值', - `status` tinyint NULL DEFAULT 0 COMMENT '状态(1-正常,0-禁用)', - `sort` int NULL DEFAULT 0 COMMENT '排序', - `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 70 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '字典数据表' ROW_FORMAT = DYNAMIC; + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `dict_id` bigint(20) NULL DEFAULT NULL COMMENT '字典ID', + `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '字典项名称', + `value` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '字典项值', + `status` tinyint(4) NULL DEFAULT 0 COMMENT '状态(1-正常,0-禁用)', + `sort` int(11) NULL DEFAULT 0 COMMENT '排序', + `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '字典数据表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_dict_item @@ -116,48 +194,82 @@ INSERT INTO `sys_dict_item` VALUES (3, 1, '保密', '0', 1, 3, NULL, '2020-10-17 -- ---------------------------- DROP TABLE IF EXISTS `sys_log`; CREATE TABLE `sys_log` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `type` tinyint NULL DEFAULT NULL COMMENT '日志类型(1-操作日志 2-登录日志)', - `title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '日志标题', - `ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'IP地址', - `content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '日志内容', - `create_by` bigint NULL DEFAULT NULL COMMENT '创建人ID', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `update_by` bigint NULL DEFAULT NULL COMMENT '修改人ID', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(1-已删除 0-未删除)', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '系统日志' ROW_FORMAT = DYNAMIC; + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `module` enum('LOGIN','USER','ROLE','DEPT','MENU','DICT','OTHER') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '日志模块', + `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '日志内容', + `request_uri` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '请求路径', + `ip` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'IP地址', + `province` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '省份', + `city` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '城市', + `execution_time` bigint(20) NULL DEFAULT NULL COMMENT '执行时间(ms)', + `browser` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '浏览器', + `browser_version` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '浏览器版本', + `os` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '终端系统', + `create_by` bigint(20) NULL DEFAULT NULL COMMENT '创建人ID', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(1-已删除 0-未删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 31 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '系统日志表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_log -- ---------------------------- +INSERT INTO `sys_log` VALUES (1, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 176, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:38:33', 0); +INSERT INTO `sys_log` VALUES (2, 'OTHER', '生成代码', '/api/v1/generator/sys_notice_status/config', '192.168.2.34', '0', '内网IP', 340, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:38:48', 0); +INSERT INTO `sys_log` VALUES (3, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice_status/preview', '192.168.2.34', '0', '内网IP', 492, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:38:49', 0); +INSERT INTO `sys_log` VALUES (4, 'OTHER', '生成代码', '/api/v1/generator/sys_notice/config', '192.168.2.34', '0', '内网IP', 234, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:03', 0); +INSERT INTO `sys_log` VALUES (5, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice/preview', '192.168.2.34', '0', '内网IP', 66, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:04', 0); +INSERT INTO `sys_log` VALUES (6, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 12, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:07', 0); +INSERT INTO `sys_log` VALUES (7, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 7, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:15', 0); +INSERT INTO `sys_log` VALUES (8, 'ROLE', '角色分页列表', '/api/v1/roles/page', '192.168.2.34', '0', '内网IP', 7, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:23', 0); +INSERT INTO `sys_log` VALUES (9, 'ROLE', '角色分页列表', '/api/v1/roles/page', '192.168.2.34', '0', '内网IP', 7, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:33', 0); +INSERT INTO `sys_log` VALUES (10, 'ROLE', '角色分页列表', '/api/v1/roles/page', '192.168.2.34', '0', '内网IP', 5, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 2, '2024-08-24 13:39:36', 0); +INSERT INTO `sys_log` VALUES (11, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 44, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:52:17', 0); +INSERT INTO `sys_log` VALUES (12, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 12, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:52:27', 0); +INSERT INTO `sys_log` VALUES (13, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 14, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:52:29', 0); +INSERT INTO `sys_log` VALUES (14, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice_status/preview', '192.168.2.34', '0', '内网IP', 624, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:52:32', 0); +INSERT INTO `sys_log` VALUES (15, 'OTHER', '下载代码', '/api/v1/generator/sys_notice_status/download', '192.168.2.34', '0', '内网IP', 93, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:53:01', 0); +INSERT INTO `sys_log` VALUES (16, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice/preview', '192.168.2.34', '0', '内网IP', 67, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:53:09', 0); +INSERT INTO `sys_log` VALUES (17, 'OTHER', '下载代码', '/api/v1/generator/sys_notice/download', '192.168.2.34', '0', '内网IP', 51, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:53:11', 0); +INSERT INTO `sys_log` VALUES (18, 'ROLE', '角色分页列表', '/api/v1/roles/page', '192.168.2.34', '0', '内网IP', 7, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:53:31', 0); +INSERT INTO `sys_log` VALUES (19, 'ROLE', '角色分页列表', '/api/v1/roles/page', '192.168.2.34', '0', '内网IP', 6, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 09:53:40', 0); +INSERT INTO `sys_log` VALUES (20, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 32, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:25:20', 0); +INSERT INTO `sys_log` VALUES (21, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice/preview', '192.168.2.34', '0', '内网IP', 214, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:25:23', 0); +INSERT INTO `sys_log` VALUES (22, 'LOGIN', '登录', '/api/v1/auth/login', '192.168.2.34', '0', '内网IP', 941, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:29:30', 0); +INSERT INTO `sys_log` VALUES (23, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 43, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:29:31', 0); +INSERT INTO `sys_log` VALUES (24, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice/preview', '192.168.2.34', '0', '内网IP', 211, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:29:36', 0); +INSERT INTO `sys_log` VALUES (25, 'OTHER', '生成代码', '/api/v1/generator/sys_notice/config', '192.168.2.34', '0', '内网IP', 168, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:30:57', 0); +INSERT INTO `sys_log` VALUES (26, 'OTHER', '预览生成代码', '/api/v1/generator/sys_notice/preview', '192.168.2.34', '0', '内网IP', 102, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:30:57', 0); +INSERT INTO `sys_log` VALUES (27, 'OTHER', '下载代码', '/api/v1/generator/sys_notice/download', '192.168.2.34', '0', '内网IP', 68, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:31:05', 0); +INSERT INTO `sys_log` VALUES (28, 'OTHER', '代码生成分页列表', '/api/v1/generator/table/page', '192.168.2.34', '0', '内网IP', 55, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 10:54:53', 0); +INSERT INTO `sys_log` VALUES (29, 'LOGIN', '登录', '/api/v1/auth/login', '192.168.2.34', '0', '内网IP', 283, 'MSEdge', '128.0.0.0', 'Windows 10 or Windows Server 2016', 2, '2024-08-27 13:55:37', 0); +INSERT INTO `sys_log` VALUES (30, 'LOGIN', '登录', '/api/v1/auth/login', '192.168.2.34', '0', '内网IP', 121, 'QQBrowser', '13.0.6069.400', 'Windows 10 or Windows Server 2016', 1, '2024-08-27 13:56:26', 0); -- ---------------------------- -- Table structure for sys_menu -- ---------------------------- DROP TABLE IF EXISTS `sys_menu`; CREATE TABLE `sys_menu` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', - `parent_id` bigint NOT NULL COMMENT '父菜单ID', - `tree_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '父节点ID路径', - `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '菜单名称', - `type` tinyint NOT NULL COMMENT '菜单类型(1-菜单 2-目录 3-外链 4-按钮)', - `route_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '路由名称(Vue Router 中用于命名路由)', - `route_path` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '路由路径(Vue Router 中定义的 URL 路径)', - `component` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '组件路径(组件页面完整路径,相对于 src/views/,缺省后缀 .vue)', - `perm` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '【按钮】权限标识', - `always_show` tinyint NULL DEFAULT NULL COMMENT '【目录】只有一个子路由是否始终显示(1-是 0-否)', - `keep_alive` tinyint NULL DEFAULT NULL COMMENT '【菜单】是否开启页面缓存(1-是 0-否)', - `visible` tinyint(1) NOT NULL DEFAULT 1 COMMENT '显示状态(1-显示 0-隐藏)', - `sort` int NULL DEFAULT 0 COMMENT '排序', - `icon` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '菜单图标', - `redirect` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '跳转路径', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `params` text NULL COMMENT '路由参数', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 117 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '菜单管理' ROW_FORMAT = DYNAMIC; + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `parent_id` bigint(20) NOT NULL COMMENT '父菜单ID', + `tree_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '父节点ID路径', + `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '菜单名称', + `type` tinyint(4) NOT NULL COMMENT '菜单类型(1-菜单 2-目录 3-外链 4-按钮)', + `route_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '路由名称(Vue Router 中用于命名路由)', + `route_path` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '路由路径(Vue Router 中定义的 URL 路径)', + `component` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '组件路径(组件页面完整路径,相对于 src/views/,缺省后缀 .vue)', + `perm` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '【按钮】权限标识', + `always_show` tinyint(4) NULL DEFAULT NULL COMMENT '【目录】只有一个子路由是否始终显示(1-是 0-否)', + `keep_alive` tinyint(4) NULL DEFAULT NULL COMMENT '【菜单】是否开启页面缓存(1-是 0-否)', + `visible` tinyint(1) NOT NULL DEFAULT 1 COMMENT '显示状态(1-显示 0-隐藏)', + `sort` int(11) NULL DEFAULT 0 COMMENT '排序', + `icon` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '菜单图标', + `redirect` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '跳转路径', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `params` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '路由参数', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 136 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '菜单管理' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_menu @@ -217,45 +329,106 @@ INSERT INTO `sys_menu` VALUES (112, 110, '0,110', '参数(type=2)', 1, NULL, 'ro INSERT INTO `sys_menu` VALUES (117, 1, '0,1', '系统日志', 1, 'Log', 'log', 'system/log/index', NULL, 0, 1, 1, 6, 'document', NULL, '2024-06-28 07:43:16', '2024-06-28 07:43:16', NULL); INSERT INTO `sys_menu` VALUES (118, 0, '0', '系统工具', 2, NULL, '/tool', 'Layout', NULL, 0, 1, 1, 2, 'menu', NULL, '2024-07-13 08:41:07', '2024-07-13 08:41:07', NULL); INSERT INTO `sys_menu` VALUES (119, 118, '0,118', '代码生成(Alpha)', 1, 'Generator', 'generator', 'generator/index', NULL, 0, 1, 1, 1, 'code', NULL, '2024-07-13 08:44:51', '2024-07-13 08:44:51', NULL); +INSERT INTO `sys_menu` VALUES (120, 1, '0,1', '系统配置', 1, 'Config', 'config', 'system/config/index', NULL, 0, 1, 1, 7, 'setting', NULL, '2024-07-30 16:29:24', '2024-07-30 16:29:32', NULL); +INSERT INTO `sys_menu` VALUES (121, 120, '0,1,120', '查询系统配置', 4, NULL, '', NULL, 'sys:config:query', 0, 1, 1, 1, '', NULL, '2024-07-30 16:29:54', '2024-07-30 16:29:54', NULL); +INSERT INTO `sys_menu` VALUES (122, 120, '0,1,120', '新增系统配置', 4, NULL, '', NULL, 'sys:config:add', 0, 1, 1, 2, '', NULL, '2024-07-30 16:30:12', '2024-07-30 16:30:48', NULL); +INSERT INTO `sys_menu` VALUES (123, 120, '0,1,120', '修改系统配置', 4, NULL, '', NULL, 'sys:config:update', 0, 1, 1, 3, '', NULL, '2024-07-30 16:30:31', '2024-07-30 16:30:31', NULL); +INSERT INTO `sys_menu` VALUES (124, 120, '0,1,120', '删除系统配置', 4, NULL, '', NULL, 'sys:config:delete', 0, 1, 1, 4, '', NULL, '2024-07-30 16:31:07', '2024-07-30 16:31:07', NULL); +INSERT INTO `sys_menu` VALUES (125, 120, '0,1,120', '刷新系统配置', 4, NULL, '', NULL, 'sys:config:refresh', 0, 1, 1, 5, '', NULL, '2024-07-30 16:31:25', '2024-07-30 16:31:25', NULL); +INSERT INTO `sys_menu` VALUES (126, 1, '0,1', '用户公告状态', 1, 'NoticeStatus', 'notice-status', 'system/notice-status/index', NULL, NULL, NULL, 1, 8, '', NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48', NULL); +INSERT INTO `sys_menu` VALUES (127, 126, '0,1,127', '查询', 4, NULL, '', NULL, 'system:noticeStatus:query', NULL, NULL, 1, 1, '', NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48', NULL); +INSERT INTO `sys_menu` VALUES (128, 126, '0,1,128', '新增', 4, NULL, '', NULL, 'system:noticeStatus:add', NULL, NULL, 1, 2, '', NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48', NULL); +INSERT INTO `sys_menu` VALUES (129, 126, '0,1,129', '编辑', 4, NULL, '', NULL, 'system:noticeStatus:edit', NULL, NULL, 1, 3, '', NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48', NULL); +INSERT INTO `sys_menu` VALUES (130, 126, '0,1,130', '删除', 4, NULL, '', NULL, 'system:noticeStatus:delete', NULL, NULL, 1, 4, '', NULL, '2024-08-24 13:38:48', '2024-08-24 13:38:48', NULL); +INSERT INTO `sys_menu` VALUES (131, 1, '0,1', '通知公告', 1, 'Notice', 'notice', 'system/notice/index', NULL, NULL, NULL, 1, 9, '', NULL, '2024-08-24 13:39:03', '2024-08-24 13:39:03', NULL); +INSERT INTO `sys_menu` VALUES (132, 131, '0,1,132', '查询', 4, NULL, '', NULL, 'system:notice:query', NULL, NULL, 1, 1, '', NULL, '2024-08-24 13:39:03', '2024-08-24 13:39:03', NULL); +INSERT INTO `sys_menu` VALUES (133, 131, '0,1,133', '新增', 4, NULL, '', NULL, 'system:notice:add', NULL, NULL, 1, 2, '', NULL, '2024-08-24 13:39:03', '2024-08-24 13:39:03', NULL); +INSERT INTO `sys_menu` VALUES (134, 131, '0,1,134', '编辑', 4, NULL, '', NULL, 'system:notice:edit', NULL, NULL, 1, 3, '', NULL, '2024-08-24 13:39:03', '2024-08-24 13:39:03', NULL); +INSERT INTO `sys_menu` VALUES (135, 131, '0,1,135', '删除', 4, NULL, '', NULL, 'system:notice:delete', NULL, NULL, 1, 4, '', NULL, '2024-08-24 13:39:03', '2024-08-24 13:39:03', NULL); -- ---------------------------- -- Table structure for sys_message -- ---------------------------- DROP TABLE IF EXISTS `sys_message`; CREATE TABLE `sys_message` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `create_by` bigint NULL DEFAULT NULL COMMENT '创建人ID', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `update_by` bigint NULL DEFAULT NULL COMMENT '修改人ID', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(1-已删除 0-未删除)', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '系统消息' ROW_FORMAT = DYNAMIC; + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `create_by` bigint(20) NULL DEFAULT NULL COMMENT '创建人ID', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_by` bigint(20) NULL DEFAULT NULL COMMENT '修改人ID', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(1-已删除 0-未删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '系统消息' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_message -- ---------------------------- +-- ---------------------------- +-- Table structure for sys_notice +-- ---------------------------- +DROP TABLE IF EXISTS `sys_notice`; +CREATE TABLE `sys_notice` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `title` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '通知标题', + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '通知内容', + `notice_type` int(11) NOT NULL COMMENT '通知类型', + `release_by` bigint(20) NULL DEFAULT NULL COMMENT '发布人', + `priority` tinyint(4) NOT NULL COMMENT '优先级(0-低 1-中 2-高)', + `tar_type` tinyint(4) NOT NULL COMMENT '目标类型(0-全体 1-指定)', + `send_status` tinyint(4) NOT NULL COMMENT '发布状态(0-未发布 1已发布 2已撤回)', + `send_time` datetime NULL DEFAULT NULL COMMENT '发布时间', + `recall_time` datetime NULL DEFAULT NULL COMMENT '撤回时间', + `create_by` bigint(20) NOT NULL COMMENT '创建人ID', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_by` bigint(20) NULL DEFAULT NULL COMMENT '更新人ID', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '通知公告' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of sys_notice +-- ---------------------------- +INSERT INTO `sys_notice` VALUES (1, '11', '1', 1, 2, 1, 1, 2, '2024-08-27 11:20:38', '2024-08-27 11:20:39', 2, '2024-08-27 11:22:03', 2, '2024-08-27 11:27:01', 0); + +-- ---------------------------- +-- Table structure for sys_notice_status +-- ---------------------------- +DROP TABLE IF EXISTS `sys_notice_status`; +CREATE TABLE `sys_notice_status` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `notice_id` bigint(20) NOT NULL COMMENT '公共通知id', + `user_id` int(11) NOT NULL COMMENT '用户id', + `read_status` bigint(4) NULL DEFAULT NULL COMMENT '读取状态,0未读,1已读取', + `read_tiem` datetime NULL DEFAULT NULL COMMENT '用户阅读时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户公告状态表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sys_notice_status +-- ---------------------------- + -- ---------------------------- -- Table structure for sys_role -- ---------------------------- DROP TABLE IF EXISTS `sys_role`; CREATE TABLE `sys_role` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '角色名称', - `code` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色编码', - `sort` int NULL DEFAULT NULL COMMENT '显示顺序', - `status` tinyint(1) NULL DEFAULT 1 COMMENT '角色状态(1-正常 0-停用)', - `data_scope` tinyint NULL DEFAULT NULL COMMENT '数据权限(0-所有数据 1-部门及子部门数据 2-本部门数据3-本人数据)', - `create_by` bigint NULL DEFAULT NULL COMMENT '创建人 ID', - `create_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `update_by` bigint NULL DEFAULT NULL COMMENT '更新人ID', - `update_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `uk_name`(`name` ASC) USING BTREE COMMENT '角色名称唯一索引', - UNIQUE INDEX `uk_code`(`code` ASC) USING BTREE COMMENT '角色编码唯一索引' -) ENGINE = InnoDB AUTO_INCREMENT = 128 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '角色表' ROW_FORMAT = DYNAMIC; + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '角色名称', + `code` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色编码', + `sort` int(11) NULL DEFAULT NULL COMMENT '显示顺序', + `status` tinyint(1) NULL DEFAULT 1 COMMENT '角色状态(1-正常 0-停用)', + `data_scope` tinyint(4) NULL DEFAULT NULL COMMENT '数据权限(0-所有数据 1-部门及子部门数据 2-本部门数据3-本人数据)', + `create_by` bigint(20) NULL DEFAULT NULL COMMENT '创建人 ID', + `create_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `update_by` bigint(20) NULL DEFAULT NULL COMMENT '更新人ID', + `update_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `is_deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_name`(`name`) USING BTREE COMMENT '角色名称唯一索引', + UNIQUE INDEX `uk_code`(`code`) USING BTREE COMMENT '角色编码唯一索引' +) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '角色表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_role @@ -278,9 +451,9 @@ INSERT INTO `sys_role` VALUES (12, '系统管理员9', 'ADMIN9', 12, 1, 1, NULL, -- ---------------------------- DROP TABLE IF EXISTS `sys_role_menu`; CREATE TABLE `sys_role_menu` ( - `role_id` bigint NOT NULL COMMENT '角色ID', - `menu_id` bigint NOT NULL COMMENT '菜单ID', - UNIQUE INDEX `uk_roleid_menuid`(`role_id` ASC, `menu_id` ASC) USING BTREE COMMENT '角色菜单唯一索引' + `role_id` bigint(20) NOT NULL COMMENT '角色ID', + `menu_id` bigint(20) NOT NULL COMMENT '菜单ID', + UNIQUE INDEX `uk_roleid_menuid`(`role_id`, `menu_id`) USING BTREE COMMENT '角色菜单唯一索引' ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '角色和菜单关联表' ROW_FORMAT = DYNAMIC; -- ---------------------------- @@ -338,35 +511,44 @@ INSERT INTO `sys_role_menu` VALUES (2, 109); INSERT INTO `sys_role_menu` VALUES (2, 110); INSERT INTO `sys_role_menu` VALUES (2, 111); INSERT INTO `sys_role_menu` VALUES (2, 112); -INSERT INTO `sys_role_menu` VALUES (2, 114); -INSERT INTO `sys_role_menu` VALUES (2, 115); -INSERT INTO `sys_role_menu` VALUES (2, 116); INSERT INTO `sys_role_menu` VALUES (2, 117); INSERT INTO `sys_role_menu` VALUES (2, 118); INSERT INTO `sys_role_menu` VALUES (2, 119); +INSERT INTO `sys_role_menu` VALUES (2, 120); +INSERT INTO `sys_role_menu` VALUES (2, 121); +INSERT INTO `sys_role_menu` VALUES (2, 122); +INSERT INTO `sys_role_menu` VALUES (2, 123); +INSERT INTO `sys_role_menu` VALUES (2, 124); +INSERT INTO `sys_role_menu` VALUES (2, 125); +INSERT INTO `sys_role_menu` VALUES (2, 131); +INSERT INTO `sys_role_menu` VALUES (2, 132); +INSERT INTO `sys_role_menu` VALUES (2, 133); +INSERT INTO `sys_role_menu` VALUES (2, 134); +INSERT INTO `sys_role_menu` VALUES (2, 135); + -- ---------------------------- -- Table structure for sys_user -- ---------------------------- DROP TABLE IF EXISTS `sys_user`; CREATE TABLE `sys_user` ( - `id` int NOT NULL AUTO_INCREMENT, - `username` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名', - `nickname` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '昵称', - `gender` tinyint(1) NULL DEFAULT 1 COMMENT '性别((1-男 2-女 0-保密)', - `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码', - `dept_id` int NULL DEFAULT NULL COMMENT '部门ID', - `avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户头像', - `mobile` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联系方式', - `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态((1-正常 0-禁用)', - `email` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户邮箱', - `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', - `create_by` bigint NULL DEFAULT NULL COMMENT '创建人ID', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', - `update_by` bigint NULL DEFAULT NULL COMMENT '修改人ID', - `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `login_name`(`username` ASC) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 288 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户信息表' ROW_FORMAT = DYNAMIC; + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名', + `nickname` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '昵称', + `gender` tinyint(1) NULL DEFAULT 1 COMMENT '性别((1-男 2-女 0-保密)', + `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码', + `dept_id` int(11) NULL DEFAULT NULL COMMENT '部门ID', + `avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户头像', + `mobile` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联系方式', + `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态((1-正常 0-禁用)', + `email` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户邮箱', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `create_by` bigint(20) NULL DEFAULT NULL COMMENT '创建人ID', + `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `update_by` bigint(20) NULL DEFAULT NULL COMMENT '修改人ID', + `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `login_name`(`username`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户信息表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of sys_user @@ -380,10 +562,10 @@ INSERT INTO `sys_user` VALUES (3, 'test', '测试小用户', 1, '$2a$10$xVWsNOhH -- ---------------------------- DROP TABLE IF EXISTS `sys_user_role`; CREATE TABLE `sys_user_role` ( - `user_id` bigint NOT NULL COMMENT '用户ID', - `role_id` bigint NOT NULL COMMENT '角色ID', - PRIMARY KEY (`user_id`, `role_id`) USING BTREE, - UNIQUE INDEX `uk_userid_roleid`(`user_id` ASC, `role_id` ASC) USING BTREE COMMENT '用户角色唯一索引' + `user_id` bigint(20) NOT NULL COMMENT '用户ID', + `role_id` bigint(20) NOT NULL COMMENT '角色ID', + PRIMARY KEY (`user_id`, `role_id`) USING BTREE, + UNIQUE INDEX `uk_userid_roleid`(`user_id`, `role_id`) USING BTREE COMMENT '用户角色唯一索引' ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户和角色关联表' ROW_FORMAT = DYNAMIC; -- ---------------------------- @@ -393,77 +575,4 @@ INSERT INTO `sys_user_role` VALUES (1, 1); INSERT INTO `sys_user_role` VALUES (2, 2); INSERT INTO `sys_user_role` VALUES (3, 3); --- ---------------------------- --- Table structure for sys_log --- ---------------------------- -DROP TABLE IF EXISTS `sys_log`; -CREATE TABLE `sys_log` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `module` enum('LOGIN','USER','ROLE','DEPT','MENU','DICT','OTHER') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '日志模块', - `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '日志内容', - `request_uri` varchar(255) COLLATE utf8_general_ci DEFAULT NULL COMMENT '请求路径', - `ip` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT 'IP地址', - `province` varchar(100) COLLATE utf8_general_ci DEFAULT NULL COMMENT '省份', - `city` varchar(100) COLLATE utf8_general_ci DEFAULT NULL COMMENT '城市', - `execution_time` bigint DEFAULT NULL COMMENT '执行时间(ms)', - `browser` varchar(100) COLLATE utf8_general_ci DEFAULT NULL COMMENT '浏览器', - `browser_version` varchar(100) COLLATE utf8_general_ci DEFAULT NULL COMMENT '浏览器版本', - `os` varchar(100) COLLATE utf8_general_ci DEFAULT NULL COMMENT '终端系统', - `create_by` bigint DEFAULT NULL COMMENT '创建人ID', - `create_time` datetime DEFAULT NULL COMMENT '创建时间', - `is_deleted` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标识(1-已删除 0-未删除)', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC COMMENT='系统日志表'; - - - --- ---------------------------- --- Table structure for gen_config --- ---------------------------- -DROP TABLE IF EXISTS `gen_config`; -CREATE TABLE `gen_config` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `table_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '表名', - `module_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '模块名', - `package_name` varchar(255) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '包名', - `business_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '业务名', - `entity_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '实体类名', - `author` varchar(50) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '作者', - `parent_menu_id` bigint DEFAULT NULL COMMENT '上级菜单ID,对应sys_menu的id ', - `create_time` datetime DEFAULT NULL COMMENT '创建时间', - `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - PRIMARY KEY (`id`), - UNIQUE KEY `uk_tablename` (`table_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='代码生成基础配置表'; - --- ---------------------------- --- Table structure for gen_field_config --- ---------------------------- -DROP TABLE IF EXISTS `gen_field_config`; -CREATE TABLE `gen_field_config` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `config_id` bigint NOT NULL COMMENT '关联的配置ID', - `column_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, - `column_type` varchar(50) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, - `column_length` int DEFAULT NULL, - `field_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '字段名称', - `field_type` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '字段类型', - `field_sort` int DEFAULT NULL COMMENT '字段排序', - `field_comment` varchar(255) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '字段描述', - `max_length` int NULL DEFAULT NULL, - `is_required` tinyint(1) DEFAULT NULL COMMENT '是否必填', - `is_show_in_list` tinyint(1) DEFAULT '0' COMMENT '是否在列表显示', - `is_show_in_form` tinyint(1) DEFAULT '0' COMMENT '是否在表单显示', - `is_show_in_query` tinyint(1) DEFAULT '0' COMMENT '是否在查询条件显示', - `query_type` tinyint DEFAULT NULL COMMENT '查询方式', - `form_type` tinyint DEFAULT NULL COMMENT '表单类型', - `dict_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '字典类型', - `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`), - KEY `config_id` (`config_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='代码生成字段配置表'; - - SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/java/com/youlai/system/controller/NoticeController.java b/src/main/java/com/youlai/system/controller/NoticeController.java new file mode 100644 index 00000000..01154098 --- /dev/null +++ b/src/main/java/com/youlai/system/controller/NoticeController.java @@ -0,0 +1,81 @@ +package com.youlai.system.controller; + +import com.youlai.system.service.NoticeService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.youlai.system.model.form.NoticeForm; +import com.youlai.system.model.query.NoticeQuery; +import com.youlai.system.model.vo.NoticeVO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.youlai.system.common.result.PageResult; +import com.youlai.system.common.result.Result; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import jakarta.validation.Valid; + +/** + * 通知公告前端控制层 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Tag(name = "通知公告接口") +@RestController +@RequestMapping("/api/v1/notices") +@RequiredArgsConstructor +public class NoticeController { + + private final NoticeService noticeService; + + @Operation(summary = "通知公告分页列表") + @GetMapping("/page") + @PreAuthorize("@ss.hasPerm('system:notice:query')") + public PageResult getNoticePage(NoticeQuery queryParams ) { + IPage result = noticeService.getNoticePage(queryParams); + return PageResult.success(result); + } + + @Operation(summary = "新增通知公告") + @PostMapping + @PreAuthorize("@ss.hasPerm('system:notice:add')") + public Result saveNotice(@RequestBody @Valid NoticeForm formData ) { + boolean result = noticeService.saveNotice(formData); + return Result.judge(result); + } + + @Operation(summary = "获取通知公告表单数据") + @GetMapping("/{id}/form") + @PreAuthorize("@ss.hasPerm('system:notice:edit')") + public Result getNoticeForm( + @Parameter(description = "通知公告ID") @PathVariable Long id + ) { + NoticeForm formData = noticeService.getNoticeFormData(id); + return Result.success(formData); + } + + @Operation(summary = "修改通知公告") + @PutMapping(value = "/{id}") + @PreAuthorize("@ss.hasPerm('system:notice:edit')") + public Result updateNotice( + @Parameter(description = "通知公告ID") @PathVariable Long id, + @RequestBody @Validated NoticeForm formData + ) { + boolean result = noticeService.updateNotice(id, formData); + return Result.judge(result); + } + + @Operation(summary = "删除通知公告") + @DeleteMapping("/{ids}") + @PreAuthorize("@ss.hasPerm('system:notice:delete')") + public Result deleteNotices( + @Parameter(description = "通知公告ID,多个以英文逗号(,)分割") @PathVariable String ids + ) { + boolean result = noticeService.deleteNotices(ids); + return Result.judge(result); + } +} diff --git a/src/main/java/com/youlai/system/controller/NoticeStatusController.java b/src/main/java/com/youlai/system/controller/NoticeStatusController.java new file mode 100644 index 00000000..18d241c1 --- /dev/null +++ b/src/main/java/com/youlai/system/controller/NoticeStatusController.java @@ -0,0 +1,81 @@ +package com.youlai.system.controller; + +import com.youlai.system.service.NoticeStatusService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.youlai.system.model.form.NoticeStatusForm; +import com.youlai.system.model.query.NoticeStatusQuery; +import com.youlai.system.model.vo.NoticeStatusVO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.youlai.system.common.result.PageResult; +import com.youlai.system.common.result.Result; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import jakarta.validation.Valid; + +/** + * 用户公告状态前端控制层 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Tag(name = "用户公告状态接口") +@RestController +@RequestMapping("/api/v1/noticeStatuss") +@RequiredArgsConstructor +public class NoticeStatusController { + + private final NoticeStatusService noticeStatusService; + + @Operation(summary = "用户公告状态分页列表") + @GetMapping("/page") + @PreAuthorize("@ss.hasPerm('system:noticeStatus:query')") + public PageResult getNoticeStatusPage(NoticeStatusQuery queryParams ) { + IPage result = noticeStatusService.getNoticeStatusPage(queryParams); + return PageResult.success(result); + } + + @Operation(summary = "新增用户公告状态") + @PostMapping + @PreAuthorize("@ss.hasPerm('system:noticeStatus:add')") + public Result saveNoticeStatus(@RequestBody @Valid NoticeStatusForm formData ) { + boolean result = noticeStatusService.saveNoticeStatus(formData); + return Result.judge(result); + } + + @Operation(summary = "获取用户公告状态表单数据") + @GetMapping("/{id}/form") + @PreAuthorize("@ss.hasPerm('system:noticeStatus:edit')") + public Result getNoticeStatusForm( + @Parameter(description = "用户公告状态ID") @PathVariable Long id + ) { + NoticeStatusForm formData = noticeStatusService.getNoticeStatusFormData(id); + return Result.success(formData); + } + + @Operation(summary = "修改用户公告状态") + @PutMapping(value = "/{id}") + @PreAuthorize("@ss.hasPerm('system:noticeStatus:edit')") + public Result updateNoticeStatus( + @Parameter(description = "用户公告状态ID") @PathVariable Long id, + @RequestBody @Validated NoticeStatusForm formData + ) { + boolean result = noticeStatusService.updateNoticeStatus(id, formData); + return Result.judge(result); + } + + @Operation(summary = "删除用户公告状态") + @DeleteMapping("/{ids}") + @PreAuthorize("@ss.hasPerm('system:noticeStatus:delete')") + public Result deleteNoticeStatuss( + @Parameter(description = "用户公告状态ID,多个以英文逗号(,)分割") @PathVariable String ids + ) { + boolean result = noticeStatusService.deleteNoticeStatuss(ids); + return Result.judge(result); + } +} diff --git a/src/main/java/com/youlai/system/controller/WebsocketController.java b/src/main/java/com/youlai/system/controller/WebsocketController.java index 1e082faa..3d871715 100644 --- a/src/main/java/com/youlai/system/controller/WebsocketController.java +++ b/src/main/java/com/youlai/system/controller/WebsocketController.java @@ -27,6 +27,7 @@ public class WebsocketController { private final SimpMessagingTemplate messagingTemplate; + /** * 广播发送消息 * diff --git a/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java b/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java new file mode 100644 index 00000000..b2195e5a --- /dev/null +++ b/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java @@ -0,0 +1,20 @@ +package com.youlai.system.converter; + +import org.mapstruct.Mapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.system.model.entity.NoticeStatus; +import com.youlai.system.model.form.NoticeStatusForm; + +/** + * 用户公告状态对象转换器 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Mapper(componentModel = "spring") +public interface NoticeStatusConverter{ + + NoticeStatusForm toForm(NoticeStatus entity); + + NoticeStatus toEntity(NoticeStatusForm formData); +} \ No newline at end of file diff --git a/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java b/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java new file mode 100644 index 00000000..097d8eff --- /dev/null +++ b/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java @@ -0,0 +1,28 @@ +package com.youlai.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.youlai.system.model.entity.NoticeStatus; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.system.model.query.NoticeStatusQuery; +import com.youlai.system.model.vo.NoticeStatusVO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 用户公告状态Mapper接口 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Mapper +public interface NoticeStatusMapper extends BaseMapper { + + /** + * 获取用户公告状态分页数据 + * + * @param page 分页对象 + * @param queryParams 查询参数 + * @return + */ + Page getNoticeStatusPage(Page page, NoticeStatusQuery queryParams); + +} diff --git a/src/main/java/com/youlai/system/model/entity/Notice.java b/src/main/java/com/youlai/system/model/entity/Notice.java new file mode 100644 index 00000000..860e2cb9 --- /dev/null +++ b/src/main/java/com/youlai/system/model/entity/Notice.java @@ -0,0 +1,73 @@ +package com.youlai.system.model.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableName; +import com.youlai.system.common.base.BaseEntity; + +/** + * 通知公告实体对象 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Getter +@Setter +@TableName("sys_notice") +public class Notice extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 通知标题 + */ + private String title; + /** + * 通知内容 + */ + private String content; + /** + * 通知类型 + */ + private Integer noticeType; + /** + * 发布人 + */ + private Long releaseBy; + /** + * 优先级(0-低 1-中 2-高) + */ + private Integer priority; + /** + * 目标类型(0-全体 1-指定) + */ + private Integer tarType; + /** + * 发布状态(0-未发布 1已发布 2已撤回) + */ + private Integer sendStatus; + /** + * 发布时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime sendTime; + /** + * 撤回时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime recallTime; + /** + * 创建人ID + */ + private Long createBy; + /** + * 更新人ID + */ + private Long updateBy; + /** + * 逻辑删除标识(0-未删除 1-已删除) + */ + private Integer isDelete; +} diff --git a/src/main/java/com/youlai/system/model/entity/NoticeStatus.java b/src/main/java/com/youlai/system/model/entity/NoticeStatus.java new file mode 100644 index 00000000..6615291b --- /dev/null +++ b/src/main/java/com/youlai/system/model/entity/NoticeStatus.java @@ -0,0 +1,38 @@ +package com.youlai.system.model.entity; + +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableName; +import com.youlai.system.common.base.BaseEntity; + +/** + * 用户公告状态实体对象 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Getter +@Setter +@TableName("sys_notice_status") +public class NoticeStatus extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 公共通知id + */ + private Long noticeId; + /** + * 用户id + */ + private Integer userId; + /** + * 读取状态,0未读,1已读取 + */ + private Long readStatus; + /** + * 用户阅读时间 + */ + private LocalDateTime readTiem; +} diff --git a/src/main/java/com/youlai/system/model/form/NoticeForm.java b/src/main/java/com/youlai/system/model/form/NoticeForm.java new file mode 100644 index 00000000..a1ce24dc --- /dev/null +++ b/src/main/java/com/youlai/system/model/form/NoticeForm.java @@ -0,0 +1,66 @@ +package com.youlai.system.model.form; + +import java.io.Serial; +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; +import jakarta.validation.constraints.*; + +/** + * 通知公告表单对象 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Getter +@Setter +@Schema(description = "通知公告表单对象") +public class NoticeForm implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private Long id; + + @Schema(description = "通知标题") + @NotBlank(message = "通知标题不能为空") + @Size(max=50, message="通知标题长度不能超过50个字符") + private String title; + + @Schema(description = "通知内容") + @NotBlank(message = "通知内容不能为空") + @Size(max=65535, message="通知内容长度不能超过65535个字符") + private String content; + + @Schema(description = "通知类型") + private Integer noticeType; + + @Schema(description = "发布人") + @NotNull(message = "发布人不能为空") + private Long releaseBy; + + @Schema(description = "优先级(0-低 1-中 2-高)") + private Integer priority; + + @Schema(description = "目标类型(0-全体 1-指定)") + private Integer tarType; + + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") + private Integer sendStatus; + + @Schema(description = "发布时间") + @NotNull(message = "发布时间不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime sendTime; + + @Schema(description = "撤回时间") + @NotNull(message = "撤回时间不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime recallTime; + + +} diff --git a/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java b/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java new file mode 100644 index 00000000..d8c2b370 --- /dev/null +++ b/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java @@ -0,0 +1,26 @@ +package com.youlai.system.model.form; + +import java.io.Serial; +import java.io.Serializable; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; +import jakarta.validation.constraints.*; + +/** + * 用户公告状态表单对象 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Getter +@Setter +@Schema(description = "用户公告状态表单对象") +public class NoticeStatusForm implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + +} diff --git a/src/main/java/com/youlai/system/model/query/NoticeQuery.java b/src/main/java/com/youlai/system/model/query/NoticeQuery.java new file mode 100644 index 00000000..0ce1432b --- /dev/null +++ b/src/main/java/com/youlai/system/model/query/NoticeQuery.java @@ -0,0 +1,41 @@ +package com.youlai.system.model.query; + +import com.youlai.system.common.base.BasePageQuery; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 通知公告分页查询对象 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Schema(description ="通知公告查询对象") +@Getter +@Setter +public class NoticeQuery extends BasePageQuery { + + private static final long serialVersionUID = 1L; + + @Schema(description = "通知标题") + private String title; + @Schema(description = "通知内容") + private String content; + @Schema(description = "通知类型") + private Integer noticeType; + @Schema(description = "发布人") + private Long releaseBy; + @Schema(description = "优先级(0-低 1-中 2-高)") + private Integer priority; + @Schema(description = "目标类型(0-全体 1-指定)") + private Integer tarType; + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") + private Integer sendStatus; + @Schema(description = "发布时间") + private List sendTime; + @Schema(description = "撤回时间") + private List recallTime; +} diff --git a/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java b/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java new file mode 100644 index 00000000..36fbd346 --- /dev/null +++ b/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java @@ -0,0 +1,21 @@ +package com.youlai.system.model.query; + +import com.youlai.system.common.base.BasePageQuery; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; + +/** + * 用户公告状态分页查询对象 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Schema(description ="用户公告状态查询对象") +@Getter +@Setter +public class NoticeStatusQuery extends BasePageQuery { + + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java new file mode 100644 index 00000000..8659716e --- /dev/null +++ b/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java @@ -0,0 +1,25 @@ +package com.youlai.system.model.vo; + +import java.io.Serial; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; + +/** + * 用户公告状态视图对象 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Getter +@Setter +@Schema( description = "用户公告状态视图对象") +public class NoticeStatusVO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/java/com/youlai/system/model/vo/NoticeVO.java b/src/main/java/com/youlai/system/model/vo/NoticeVO.java new file mode 100644 index 00000000..152bcb9c --- /dev/null +++ b/src/main/java/com/youlai/system/model/vo/NoticeVO.java @@ -0,0 +1,48 @@ +package com.youlai.system.model.vo; + +import java.io.Serial; +import java.io.Serializable; +import java.time.LocalDateTime; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDateTime; + +/** + * 通知公告视图对象 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Getter +@Setter +@Schema( description = "通知公告视图对象") +public class NoticeVO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private Long id; + @Schema(description = "通知标题") + private String title; + @Schema(description = "通知内容") + private String content; + @Schema(description = "通知类型") + private Integer noticeType; + @Schema(description = "发布人") + private Long releaseBy; + @Schema(description = "优先级(0-低 1-中 2-高)") + private Integer priority; + @Schema(description = "目标类型(0-全体 1-指定)") + private Integer tarType; + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") + private Integer sendStatus; + @Schema(description = "发布时间") + private LocalDateTime sendTime; + @Schema(description = "撤回时间") + private LocalDateTime recallTime; + @Schema(description = "创建时间") + private LocalDateTime createTime; + @Schema(description = "更新时间") + private LocalDateTime updateTime; +} diff --git a/src/main/java/com/youlai/system/service/NoticeService.java b/src/main/java/com/youlai/system/service/NoticeService.java new file mode 100644 index 00000000..13c09abc --- /dev/null +++ b/src/main/java/com/youlai/system/service/NoticeService.java @@ -0,0 +1,58 @@ +package com.youlai.system.service; + +import com.youlai.system.model.entity.Notice; +import com.youlai.system.model.form.NoticeForm; +import com.youlai.system.model.query.NoticeQuery; +import com.youlai.system.model.vo.NoticeVO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 通知公告服务类 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +public interface NoticeService extends IService { + + /** + *通知公告分页列表 + * + * @return + */ + IPage getNoticePage(NoticeQuery queryParams); + + /** + * 获取通知公告表单数据 + * + * @param id 通知公告ID + * @return + */ + NoticeForm getNoticeFormData(Long id); + + /** + * 新增通知公告 + * + * @param formData 通知公告表单对象 + * @return + */ + boolean saveNotice(NoticeForm formData); + + /** + * 修改通知公告 + * + * @param id 通知公告ID + * @param formData 通知公告表单对象 + * @return + */ + boolean updateNotice(Long id, NoticeForm formData); + + /** + * 删除通知公告 + * + * @param ids 通知公告ID,多个以英文逗号(,)分割 + * @return + */ + boolean deleteNotices(String ids); + +} diff --git a/src/main/java/com/youlai/system/service/NoticeStatusService.java b/src/main/java/com/youlai/system/service/NoticeStatusService.java new file mode 100644 index 00000000..b6193e76 --- /dev/null +++ b/src/main/java/com/youlai/system/service/NoticeStatusService.java @@ -0,0 +1,58 @@ +package com.youlai.system.service; + +import com.youlai.system.model.entity.NoticeStatus; +import com.youlai.system.model.form.NoticeStatusForm; +import com.youlai.system.model.query.NoticeStatusQuery; +import com.youlai.system.model.vo.NoticeStatusVO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 用户公告状态服务类 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +public interface NoticeStatusService extends IService { + + /** + *用户公告状态分页列表 + * + * @return + */ + IPage getNoticeStatusPage(NoticeStatusQuery queryParams); + + /** + * 获取用户公告状态表单数据 + * + * @param id 用户公告状态ID + * @return + */ + NoticeStatusForm getNoticeStatusFormData(Long id); + + /** + * 新增用户公告状态 + * + * @param formData 用户公告状态表单对象 + * @return + */ + boolean saveNoticeStatus(NoticeStatusForm formData); + + /** + * 修改用户公告状态 + * + * @param id 用户公告状态ID + * @param formData 用户公告状态表单对象 + * @return + */ + boolean updateNoticeStatus(Long id, NoticeStatusForm formData); + + /** + * 删除用户公告状态 + * + * @param ids 用户公告状态ID,多个以英文逗号(,)分割 + * @return + */ + boolean deleteNoticeStatuss(String ids); + +} diff --git a/src/main/java/com/youlai/system/service/WebsocketService.java b/src/main/java/com/youlai/system/service/WebsocketService.java index b9b4254d..fb0da4e5 100644 --- a/src/main/java/com/youlai/system/service/WebsocketService.java +++ b/src/main/java/com/youlai/system/service/WebsocketService.java @@ -6,4 +6,9 @@ public interface WebsocketService { void removeUser(String username) ; + /** + * 发送消息到前端 + * @param message + */ + void sendStringToFrontend(String message); } diff --git a/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java new file mode 100644 index 00000000..caa42c51 --- /dev/null +++ b/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java @@ -0,0 +1,140 @@ +package com.youlai.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.google.gson.*; +import com.youlai.system.security.util.SecurityUtils; +import com.youlai.system.service.WebsocketService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.system.mapper.NoticeMapper; +import com.youlai.system.service.NoticeService; +import com.youlai.system.model.entity.Notice; +import com.youlai.system.model.form.NoticeForm; +import com.youlai.system.model.query.NoticeQuery; +import com.youlai.system.model.vo.NoticeVO; +import com.youlai.system.converter.NoticeConverter; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; + +/** + * 通知公告服务实现类 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Service +@RequiredArgsConstructor +public class NoticeServiceImpl extends ServiceImpl implements NoticeService { + + private final NoticeConverter noticeConverter; + + private final WebsocketService webSocketServer; + private final Gson gson = new GsonBuilder() + .registerTypeAdapter(LocalDateTime.class, (JsonSerializer) (localDateTime, type, jsonSerializationContext) -> + new JsonPrimitive(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))) + .registerTypeAdapter(LocalDateTime.class, (JsonDeserializer) (jsonElement, type, jsonDeserializationContext) -> + LocalDateTime.parse(jsonElement.getAsString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME)) + .create(); + + private void sendWebSocketMsg(Notice notice) { + if(notice.getSendStatus() > 0){ + String jsonNotice = gson.toJson(noticeConverter.toVO(notice)); + webSocketServer.sendStringToFrontend(jsonNotice); + } + } + + /** + * 获取通知公告分页列表 + * + * @param queryParams 查询参数 + * @return {@link IPage} 通知公告分页列表 + */ + @Override + public IPage getNoticePage(NoticeQuery queryParams) { + Page pageVO = this.baseMapper.getNoticePage( + new Page<>(queryParams.getPageNum(), queryParams.getPageSize()), + queryParams + ); + return pageVO; + } + + /** + * 获取通知公告表单数据 + * + * @param id 通知公告ID + * @return + */ + @Override + public NoticeForm getNoticeFormData(Long id) { + Notice entity = this.getById(id); + return noticeConverter.toForm(entity); + } + + /** + * 新增通知公告 + * + * @param formData 通知公告表单对象 + * @return + */ + @Override + public boolean saveNotice(NoticeForm formData) { + Notice entity = noticeConverter.toEntity(formData); + entity.setCreateBy(SecurityUtils.getUserId()); + entity.setReleaseBy(SecurityUtils.getUserId()); + entity.setUpdateBy(SecurityUtils.getUserId()); + entity.setIsDelete(0); + boolean result = this.save(entity); + if(result){ + sendWebSocketMsg(entity); + } + return result; + } + + /** + * 更新通知公告 + * + * @param id 通知公告ID + * @param formData 通知公告表单对象 + * @return + */ + @Override + public boolean updateNotice(Long id,NoticeForm formData) { + Notice entity = noticeConverter.toEntity(formData); + entity.setUpdateBy(SecurityUtils.getUserId()); + entity.setIsDelete(0); + boolean result = this.updateById(entity); + if(result) { + sendWebSocketMsg(entity); + } + return result; + } + + /** + * 删除通知公告 + * + * @param ids 通知公告ID,多个以英文逗号(,)分割 + * @return + */ + @Override + public boolean deleteNotices(String ids) { + Assert.isTrue(StrUtil.isNotBlank(ids), "删除的通知公告数据为空"); + // 逻辑删除 + List idList = Arrays.stream(ids.split(",")) + .map(Long::parseLong) + .toList(); + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.in(Notice::getId, idList).set(Notice::getIsDelete, 1); + return this.update(wrapper); + } + +} diff --git a/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java new file mode 100644 index 00000000..e01a77ab --- /dev/null +++ b/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java @@ -0,0 +1,103 @@ +package com.youlai.system.service.impl; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.system.mapper.NoticeStatusMapper; +import com.youlai.system.service.NoticeStatusService; +import com.youlai.system.model.entity.NoticeStatus; +import com.youlai.system.model.form.NoticeStatusForm; +import com.youlai.system.model.query.NoticeStatusQuery; +import com.youlai.system.model.vo.NoticeStatusVO; +import com.youlai.system.converter.NoticeStatusConverter; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; + +/** + * 用户公告状态服务实现类 + * + * @author youlaitech + * @since 2024-08-27 09:53 + */ +@Service +@RequiredArgsConstructor +public class NoticeStatusServiceImpl extends ServiceImpl implements NoticeStatusService { + + private final NoticeStatusConverter noticeStatusConverter; + + /** + * 获取用户公告状态分页列表 + * + * @param queryParams 查询参数 + * @return {@link IPage} 用户公告状态分页列表 + */ + @Override + public IPage getNoticeStatusPage(NoticeStatusQuery queryParams) { + Page pageVO = this.baseMapper.getNoticeStatusPage( + new Page<>(queryParams.getPageNum(), queryParams.getPageSize()), + queryParams + ); + return pageVO; + } + + /** + * 获取用户公告状态表单数据 + * + * @param id 用户公告状态ID + * @return + */ + @Override + public NoticeStatusForm getNoticeStatusFormData(Long id) { + NoticeStatus entity = this.getById(id); + return noticeStatusConverter.toForm(entity); + } + + /** + * 新增用户公告状态 + * + * @param formData 用户公告状态表单对象 + * @return + */ + @Override + public boolean saveNoticeStatus(NoticeStatusForm formData) { + NoticeStatus entity = noticeStatusConverter.toEntity(formData); + return this.save(entity); + } + + /** + * 更新用户公告状态 + * + * @param id 用户公告状态ID + * @param formData 用户公告状态表单对象 + * @return + */ + @Override + public boolean updateNoticeStatus(Long id,NoticeStatusForm formData) { + NoticeStatus entity = noticeStatusConverter.toEntity(formData); + return this.updateById(entity); + } + + /** + * 删除用户公告状态 + * + * @param ids 用户公告状态ID,多个以英文逗号(,)分割 + * @return + */ + @Override + public boolean deleteNoticeStatuss(String ids) { + Assert.isTrue(StrUtil.isNotBlank(ids), "删除的用户公告状态数据为空"); + // 逻辑删除 + List idList = Arrays.stream(ids.split(",")) + .map(Long::parseLong) + .toList(); + return this.removeByIds(idList); + } + +} diff --git a/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java b/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java index 8593761e..94cc1de6 100644 --- a/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java +++ b/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java @@ -49,4 +49,10 @@ public class WebsocketServiceImpl implements WebsocketService { public void sendOnlineUserCount() { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } + + @Override + public void sendStringToFrontend(String message) { + messagingTemplate.convertAndSend("/topic/chat", message); + } + } diff --git a/src/main/resources/mapper/NoticeMapper.xml b/src/main/resources/mapper/NoticeMapper.xml new file mode 100644 index 00000000..51dc2a48 --- /dev/null +++ b/src/main/resources/mapper/NoticeMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml new file mode 100644 index 00000000..2d8c04d5 --- /dev/null +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + From 1971516f8022072683e2abe437b7a4c9231071a2 Mon Sep 17 00:00:00 2001 From: Kylin Date: Wed, 28 Aug 2024 09:18:30 +0800 Subject: [PATCH 02/15] =?UTF-8?q?perf:=20=E8=A1=A5=E5=85=85=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 发现有漏提交 --- .../system/converter/NoticeConverter.java | 23 +++++++++++++++ .../youlai/system/mapper/NoticeMapper.java | 28 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/main/java/com/youlai/system/converter/NoticeConverter.java create mode 100644 src/main/java/com/youlai/system/mapper/NoticeMapper.java diff --git a/src/main/java/com/youlai/system/converter/NoticeConverter.java b/src/main/java/com/youlai/system/converter/NoticeConverter.java new file mode 100644 index 00000000..93cbd793 --- /dev/null +++ b/src/main/java/com/youlai/system/converter/NoticeConverter.java @@ -0,0 +1,23 @@ +package com.youlai.system.converter; + +import com.youlai.system.model.vo.NoticeVO; +import org.mapstruct.Mapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.system.model.entity.Notice; +import com.youlai.system.model.form.NoticeForm; + +/** + * 通知公告对象转换器 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Mapper(componentModel = "spring") +public interface NoticeConverter{ + + NoticeForm toForm(Notice entity); + + Notice toEntity(NoticeForm formData); + + NoticeVO toVO(Notice notice); +} \ No newline at end of file diff --git a/src/main/java/com/youlai/system/mapper/NoticeMapper.java b/src/main/java/com/youlai/system/mapper/NoticeMapper.java new file mode 100644 index 00000000..81e3b9eb --- /dev/null +++ b/src/main/java/com/youlai/system/mapper/NoticeMapper.java @@ -0,0 +1,28 @@ +package com.youlai.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.youlai.system.model.entity.Notice; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.system.model.query.NoticeQuery; +import com.youlai.system.model.vo.NoticeVO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 通知公告Mapper接口 + * + * @author youlaitech + * @since 2024-08-27 10:31 + */ +@Mapper +public interface NoticeMapper extends BaseMapper { + + /** + * 获取通知公告分页数据 + * + * @param page 分页对象 + * @param queryParams 查询参数 + * @return + */ + Page getNoticePage(Page page, NoticeQuery queryParams); + +} From 226757d4f8046aa493af39f0f83a203eb204f2b7 Mon Sep 17 00:00:00 2001 From: Kylin Date: Wed, 28 Aug 2024 16:14:05 +0800 Subject: [PATCH 03/15] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dindex.vue?= =?UTF-8?q?=E7=9A=84=E6=A8=A1=E6=9D=BF=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 我记得修复过。这次再修复一次吧。 --- .../templates/generator/index.vue.vm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/resources/templates/generator/index.vue.vm b/src/main/resources/templates/generator/index.vue.vm index 247a8ba2..cc369d0f 100644 --- a/src/main/resources/templates/generator/index.vue.vm +++ b/src/main/resources/templates/generator/index.vue.vm @@ -122,7 +122,8 @@ key="$fieldConfig.fieldName" label="$fieldConfig.fieldComment" prop="$fieldConfig.fieldName" - min-width="100" + min-width="150" + align="center" /> #end #end @@ -174,7 +175,7 @@ #if($fieldConfig.formType == "INPUT") #end #elseif($fieldConfig.formType == "RADIO") - + 选项一 选项二 #elseif($fieldConfig.formType == "CHECK_BOX") - + 选项一 选项二 #elseif($fieldConfig.formType == "INPUT_NUMBER") #elseif($fieldConfig.formType == "SWITCH") #elseif($fieldConfig.formType == "TEXT_AREA") #elseif($fieldConfig.formType == "DATE_TIME") Date: Wed, 28 Aug 2024 18:03:42 +0800 Subject: [PATCH 04/15] =?UTF-8?q?fix:=20=E4=BB=8E=E6=96=B0=E7=94=9F?= =?UTF-8?q?=E6=88=90NoticeStatus=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 从新生成NoticeStatus模块。并开始写相关代码。 --- .../controller/NoticeStatusController.java | 2 +- .../converter/NoticeStatusConverter.java | 2 +- .../system/mapper/NoticeStatusMapper.java | 2 +- .../system/model/entity/NoticeStatus.java | 2 +- .../system/model/form/NoticeStatusForm.java | 2 +- .../system/model/query/NoticeStatusQuery.java | 14 +++++++++- .../system/model/vo/NoticeStatusVO.java | 12 ++++++++- .../system/service/NoticeStatusService.java | 2 +- .../service/impl/NoticeStatusServiceImpl.java | 2 +- .../resources/mapper/NoticeStatusMapper.xml | 27 +++++++++++++++++++ 10 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/youlai/system/controller/NoticeStatusController.java b/src/main/java/com/youlai/system/controller/NoticeStatusController.java index 18d241c1..8969c541 100644 --- a/src/main/java/com/youlai/system/controller/NoticeStatusController.java +++ b/src/main/java/com/youlai/system/controller/NoticeStatusController.java @@ -22,7 +22,7 @@ import jakarta.validation.Valid; * 用户公告状态前端控制层 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Tag(name = "用户公告状态接口") @RestController diff --git a/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java b/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java index b2195e5a..94ea63df 100644 --- a/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java +++ b/src/main/java/com/youlai/system/converter/NoticeStatusConverter.java @@ -9,7 +9,7 @@ import com.youlai.system.model.form.NoticeStatusForm; * 用户公告状态对象转换器 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Mapper(componentModel = "spring") public interface NoticeStatusConverter{ diff --git a/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java b/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java index 097d8eff..a3e1d01c 100644 --- a/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java +++ b/src/main/java/com/youlai/system/mapper/NoticeStatusMapper.java @@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Mapper; * 用户公告状态Mapper接口 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Mapper public interface NoticeStatusMapper extends BaseMapper { diff --git a/src/main/java/com/youlai/system/model/entity/NoticeStatus.java b/src/main/java/com/youlai/system/model/entity/NoticeStatus.java index 6615291b..39d4cedf 100644 --- a/src/main/java/com/youlai/system/model/entity/NoticeStatus.java +++ b/src/main/java/com/youlai/system/model/entity/NoticeStatus.java @@ -10,7 +10,7 @@ import com.youlai.system.common.base.BaseEntity; * 用户公告状态实体对象 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Getter @Setter diff --git a/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java b/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java index d8c2b370..d53689aa 100644 --- a/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java +++ b/src/main/java/com/youlai/system/model/form/NoticeStatusForm.java @@ -12,7 +12,7 @@ import jakarta.validation.constraints.*; * 用户公告状态表单对象 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Getter @Setter diff --git a/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java b/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java index 36fbd346..e56fcbef 100644 --- a/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java +++ b/src/main/java/com/youlai/system/model/query/NoticeStatusQuery.java @@ -5,12 +5,13 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; import java.time.LocalDateTime; +import java.util.List; /** * 用户公告状态分页查询对象 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Schema(description ="用户公告状态查询对象") @Getter @@ -18,4 +19,15 @@ import java.time.LocalDateTime; public class NoticeStatusQuery extends BasePageQuery { private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + @Schema(description = "公共通知id") + private Long noticeId; + @Schema(description = "用户id") + private Integer userId; + @Schema(description = "读取状态,0未读,1已读取") + private Long readStatus; + @Schema(description = "用户阅读时间") + private List readTiem; } diff --git a/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java index 8659716e..8265e020 100644 --- a/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java +++ b/src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java @@ -12,7 +12,7 @@ import java.time.LocalDateTime; * 用户公告状态视图对象 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Getter @Setter @@ -22,4 +22,14 @@ public class NoticeStatusVO implements Serializable { @Serial private static final long serialVersionUID = 1L; + @Schema(description = "id") + private Long id; + @Schema(description = "公共通知id") + private Long noticeId; + @Schema(description = "用户id") + private Integer userId; + @Schema(description = "读取状态,0未读,1已读取") + private Long readStatus; + @Schema(description = "用户阅读时间") + private LocalDateTime readTiem; } diff --git a/src/main/java/com/youlai/system/service/NoticeStatusService.java b/src/main/java/com/youlai/system/service/NoticeStatusService.java index b6193e76..7e785f6c 100644 --- a/src/main/java/com/youlai/system/service/NoticeStatusService.java +++ b/src/main/java/com/youlai/system/service/NoticeStatusService.java @@ -11,7 +11,7 @@ import com.baomidou.mybatisplus.extension.service.IService; * 用户公告状态服务类 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ public interface NoticeStatusService extends IService { diff --git a/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java index e01a77ab..10f90cd1 100644 --- a/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/system/service/impl/NoticeStatusServiceImpl.java @@ -24,7 +24,7 @@ import cn.hutool.core.util.StrUtil; * 用户公告状态服务实现类 * * @author youlaitech - * @since 2024-08-27 09:53 + * @since 2024-08-28 16:56 */ @Service @RequiredArgsConstructor diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml index 2d8c04d5..e3be239e 100644 --- a/src/main/resources/mapper/NoticeStatusMapper.xml +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -5,9 +5,36 @@ From 936fc24b2ea41762011fe4acc77892bdf450e62c Mon Sep 17 00:00:00 2001 From: Kylin Date: Thu, 29 Aug 2024 17:39:10 +0800 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=E5=BC=80=E5=A7=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E4=BA=86=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 目前出现了BUG。我修改代码后。前端websocket收不到消息了。 --- .../system/model/entity/NoticeStatus.java | 14 ++++- .../system/service/WebsocketService.java | 5 +- .../service/impl/NoticeServiceImpl.java | 53 +++++++++++++------ .../service/impl/WebsocketServiceImpl.java | 42 +++++++++++++-- 4 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/youlai/system/model/entity/NoticeStatus.java b/src/main/java/com/youlai/system/model/entity/NoticeStatus.java index 39d4cedf..579934a0 100644 --- a/src/main/java/com/youlai/system/model/entity/NoticeStatus.java +++ b/src/main/java/com/youlai/system/model/entity/NoticeStatus.java @@ -1,7 +1,11 @@ package com.youlai.system.model.entity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import lombok.Getter; import lombok.Setter; + +import java.io.Serializable; import java.time.LocalDateTime; import com.baomidou.mybatisplus.annotation.TableName; import com.youlai.system.common.base.BaseEntity; @@ -15,10 +19,16 @@ import com.youlai.system.common.base.BaseEntity; @Getter @Setter @TableName("sys_notice_status") -public class NoticeStatus extends BaseEntity { +public class NoticeStatus implements Serializable { private static final long serialVersionUID = 1L; + /** + * 主键ID + */ + @TableId(type = IdType.AUTO) + private Long id; + /** * 公共通知id */ @@ -26,7 +36,7 @@ public class NoticeStatus extends BaseEntity { /** * 用户id */ - private Integer userId; + private Long userId; /** * 读取状态,0未读,1已读取 */ diff --git a/src/main/java/com/youlai/system/service/WebsocketService.java b/src/main/java/com/youlai/system/service/WebsocketService.java index fb0da4e5..d3657a29 100644 --- a/src/main/java/com/youlai/system/service/WebsocketService.java +++ b/src/main/java/com/youlai/system/service/WebsocketService.java @@ -1,14 +1,17 @@ package com.youlai.system.service; +import java.util.Set; + public interface WebsocketService { void addUser(String username); void removeUser(String username) ; + Set getUsers(); /** * 发送消息到前端 * @param message */ - void sendStringToFrontend(String message); + void sendStringToFrontend(String sender,String message); } diff --git a/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java index caa42c51..8dc4d12a 100644 --- a/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/system/service/impl/NoticeServiceImpl.java @@ -1,9 +1,15 @@ package com.youlai.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.google.gson.*; +import com.youlai.system.model.entity.NoticeStatus; +import com.youlai.system.model.entity.SysUser; import com.youlai.system.security.util.SecurityUtils; +import com.youlai.system.service.NoticeStatusService; +import com.youlai.system.service.SysUserService; import com.youlai.system.service.WebsocketService; +import jodd.util.StringUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -39,6 +45,11 @@ public class NoticeServiceImpl extends ServiceImpl impleme private final NoticeConverter noticeConverter; private final WebsocketService webSocketServer; + + private final NoticeStatusService noticeStatusService; + + private final SysUserService sysUserService; + private final Gson gson = new GsonBuilder() .registerTypeAdapter(LocalDateTime.class, (JsonSerializer) (localDateTime, type, jsonSerializationContext) -> new JsonPrimitive(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))) @@ -47,18 +58,30 @@ public class NoticeServiceImpl extends ServiceImpl impleme .create(); private void sendWebSocketMsg(Notice notice) { - if(notice.getSendStatus() > 0){ + if (notice.getSendStatus() > 0) { String jsonNotice = gson.toJson(noticeConverter.toVO(notice)); - webSocketServer.sendStringToFrontend(jsonNotice); + webSocketServer.sendStringToFrontend(SecurityUtils.getUsername(), jsonNotice); + List list = sysUserService.list(); + for (SysUser sysUser : list) { + NoticeStatus noticeStatus = noticeStatusService.getOne(new LambdaQueryWrapper().eq(NoticeStatus::getUserId, sysUser.getId()).eq(NoticeStatus::getNoticeId, notice.getId())); + if (noticeStatus == null) { + noticeStatus = new NoticeStatus(); + noticeStatus.setUserId(sysUser.getId()); + noticeStatus.setNoticeId(notice.getId()); + noticeStatus.setReadStatus(0L); + noticeStatusService.save(noticeStatus); + } + } + } } /** - * 获取通知公告分页列表 - * - * @param queryParams 查询参数 - * @return {@link IPage} 通知公告分页列表 - */ + * 获取通知公告分页列表 + * + * @param queryParams 查询参数 + * @return {@link IPage} 通知公告分页列表 + */ @Override public IPage getNoticePage(NoticeQuery queryParams) { Page pageVO = this.baseMapper.getNoticePage( @@ -67,7 +90,7 @@ public class NoticeServiceImpl extends ServiceImpl impleme ); return pageVO; } - + /** * 获取通知公告表单数据 * @@ -79,7 +102,7 @@ public class NoticeServiceImpl extends ServiceImpl impleme Notice entity = this.getById(id); return noticeConverter.toForm(entity); } - + /** * 新增通知公告 * @@ -94,31 +117,31 @@ public class NoticeServiceImpl extends ServiceImpl impleme entity.setUpdateBy(SecurityUtils.getUserId()); entity.setIsDelete(0); boolean result = this.save(entity); - if(result){ + if (result) { sendWebSocketMsg(entity); } return result; } - + /** * 更新通知公告 * - * @param id 通知公告ID + * @param id 通知公告ID * @param formData 通知公告表单对象 * @return */ @Override - public boolean updateNotice(Long id,NoticeForm formData) { + public boolean updateNotice(Long id, NoticeForm formData) { Notice entity = noticeConverter.toEntity(formData); entity.setUpdateBy(SecurityUtils.getUserId()); entity.setIsDelete(0); boolean result = this.updateById(entity); - if(result) { + if (result) { sendWebSocketMsg(entity); } return result; } - + /** * 删除通知公告 * diff --git a/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java b/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java index 94cc1de6..e5799aea 100644 --- a/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java +++ b/src/main/java/com/youlai/system/service/impl/WebsocketServiceImpl.java @@ -1,6 +1,7 @@ package com.youlai.system.service.impl; import com.youlai.system.event.UserConnectionEvent; +import com.youlai.system.model.dto.ChatMessage; import com.youlai.system.service.WebsocketService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -8,7 +9,9 @@ import org.springframework.context.event.EventListener; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.web.socket.messaging.SessionDisconnectEvent; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -19,8 +22,14 @@ public class WebsocketServiceImpl implements WebsocketService { private final SimpMessagingTemplate messagingTemplate; + // 在线用户 private final Set onlineUsers = ConcurrentHashMap.newKeySet(); + // 离线消息 + private final Set offlineMessages = ConcurrentHashMap.newKeySet(); + + private final Map> messageReceiptStatus = new ConcurrentHashMap<>(); + @Override public void addUser(String username) { onlineUsers.add(username); @@ -31,12 +40,22 @@ public class WebsocketServiceImpl implements WebsocketService { onlineUsers.remove(username); } + @Override + public Set getUsers() { + return onlineUsers; + } + @EventListener public void handleUserConnectionEvent(UserConnectionEvent event) { String username = event.getUsername(); if (event.isConnected()) { onlineUsers.add(username); log.info("User connected: {}", username); + // 发送离线消息 + offlineMessages.forEach(message -> { + messagingTemplate.convertAndSendToUser(username, "/topic/chat", message); + messageReceiptStatus.computeIfAbsent(message, k -> ConcurrentHashMap.newKeySet()).add(username); + }); } else { onlineUsers.remove(username); log.info("User disconnected: {}", username); @@ -45,14 +64,31 @@ public class WebsocketServiceImpl implements WebsocketService { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } + @EventListener + public void handleSessionDisconnect(SessionDisconnectEvent event) { + String username = event.getUser().getName(); + onlineUsers.remove(username); + } + @Scheduled(fixedRate = 5000) public void sendOnlineUserCount() { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } @Override - public void sendStringToFrontend(String message) { - messagingTemplate.convertAndSend("/topic/chat", message); - } + public void sendStringToFrontend(String sender, String message) { + ChatMessage chatMessage = new ChatMessage(sender, message); + offlineMessages.add(chatMessage); + messageReceiptStatus.putIfAbsent(chatMessage, ConcurrentHashMap.newKeySet()); + onlineUsers.forEach(receiver -> { + messagingTemplate.convertAndSendToUser(receiver, "/topic/chat", chatMessage); + messageReceiptStatus.get(chatMessage).add(receiver); + }); + if(messageReceiptStatus.get(chatMessage).size() == onlineUsers.size()) { + //记录完成状态 + offlineMessages.remove(chatMessage);//从离线消息中移除已发送的消息 + messageReceiptStatus.remove(chatMessage);//从消息接收状态集合总移除已发送的消息 + } + } } From 8804480c673918fbff46bd1152254179bd72a4e9 Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Sun, 1 Sep 2024 01:27:41 +0800 Subject: [PATCH 06/15] =?UTF-8?q?wip:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告开发 --- .../youlai/boot/common/result/PageResult.java | 2 +- .../core/security/model/SysUserDetails.java | 15 -- .../service/impl/WebsocketServiceImpl.java | 34 +--- .../system/controller/NoticeController.java | 44 +++-- .../controller/NoticeStatusController.java | 81 -------- .../system/converter/NoticeConverter.java | 9 +- .../converter/NoticeStatusConverter.java | 20 -- .../boot/system/mapper/NoticeMapper.java | 13 +- .../system/mapper/NoticeStatusMapper.java | 16 +- .../boot/system/model/entity/Config.java | 4 +- .../youlai/boot/system/model/entity/Dict.java | 4 +- .../boot/system/model/entity/Notice.java | 24 ++- .../system/model/entity/NoticeStatus.java | 11 +- .../boot/system/model/form/NoticeForm.java | 39 ++-- .../system/model/query/DictPageQuery.java | 4 +- .../boot/system/model/query/NoticeQuery.java | 32 ++-- .../system/model/query/NoticeStatusQuery.java | 11 +- .../system/model/query/PermPageQuery.java | 4 +- .../system/model/query/UserPageQuery.java | 4 +- .../boot/system/model/vo/NoticeStatusVO.java | 35 ---- .../youlai/boot/system/model/vo/NoticeVO.java | 30 +-- .../boot/system/service/NoticeService.java | 35 +++- .../system/service/NoticeStatusService.java | 48 +---- .../service/impl/NoticeServiceImpl.java | 173 +++++++++++------- .../service/impl/NoticeStatusServiceImpl.java | 93 +--------- src/main/resources/mapper/NoticeMapper.xml | 81 +++----- .../resources/mapper/NoticeStatusMapper.xml | 38 +--- 27 files changed, 299 insertions(+), 605 deletions(-) delete mode 100644 src/main/java/com/youlai/boot/system/controller/NoticeStatusController.java delete mode 100644 src/main/java/com/youlai/boot/system/converter/NoticeStatusConverter.java delete mode 100644 src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java diff --git a/src/main/java/com/youlai/boot/common/result/PageResult.java b/src/main/java/com/youlai/boot/common/result/PageResult.java index 5e0f2779..693fcb64 100644 --- a/src/main/java/com/youlai/boot/common/result/PageResult.java +++ b/src/main/java/com/youlai/boot/common/result/PageResult.java @@ -25,7 +25,7 @@ public class PageResult implements Serializable { PageResult result = new PageResult<>(); result.setCode(ResultCode.SUCCESS.getCode()); - Data data = new Data(); + Data data = new Data<>(); data.setList(page.getRecords()); data.setTotal(page.getTotal()); diff --git a/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java b/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java index e7801e8e..64ae9353 100644 --- a/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java +++ b/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java @@ -78,21 +78,6 @@ public class SysUserDetails implements UserDetails { return this.username; } - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - @Override public boolean isEnabled() { return this.enabled; diff --git a/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java b/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java index 84348481..5ab04a31 100644 --- a/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java +++ b/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java @@ -1,17 +1,15 @@ package com.youlai.boot.platform.websocket.service.impl; -import com.youlai.system.event.UserConnectionEvent; -import com.youlai.system.model.dto.ChatMessage; -import com.youlai.system.service.WebsocketService; +import com.youlai.boot.platform.websocket.service.WebsocketService; +import com.youlai.boot.system.event.UserConnectionEvent; +import com.youlai.boot.system.model.dto.ChatMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.EventListener; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import org.springframework.web.socket.messaging.SessionDisconnectEvent; -import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -22,14 +20,8 @@ public class WebsocketServiceImpl implements WebsocketService { private final SimpMessagingTemplate messagingTemplate; - // 在线用户 private final Set onlineUsers = ConcurrentHashMap.newKeySet(); - // 离线消息 - private final Set offlineMessages = ConcurrentHashMap.newKeySet(); - - private final Map> messageReceiptStatus = new ConcurrentHashMap<>(); - @Override public void addUser(String username) { onlineUsers.add(username); @@ -51,11 +43,6 @@ public class WebsocketServiceImpl implements WebsocketService { if (event.isConnected()) { onlineUsers.add(username); log.info("User connected: {}", username); - // 发送离线消息 - offlineMessages.forEach(message -> { - messagingTemplate.convertAndSendToUser(username, "/topic/chat", message); - messageReceiptStatus.computeIfAbsent(message, k -> ConcurrentHashMap.newKeySet()).add(username); - }); } else { onlineUsers.remove(username); log.info("User disconnected: {}", username); @@ -64,12 +51,6 @@ public class WebsocketServiceImpl implements WebsocketService { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } - @EventListener - public void handleSessionDisconnect(SessionDisconnectEvent event) { - String username = event.getUser().getName(); - onlineUsers.remove(username); - } - @Scheduled(fixedRate = 5000) public void sendOnlineUserCount() { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); @@ -78,17 +59,8 @@ public class WebsocketServiceImpl implements WebsocketService { @Override public void sendStringToFrontend(String sender, String message) { ChatMessage chatMessage = new ChatMessage(sender, message); - offlineMessages.add(chatMessage); - messageReceiptStatus.putIfAbsent(chatMessage, ConcurrentHashMap.newKeySet()); onlineUsers.forEach(receiver -> { messagingTemplate.convertAndSendToUser(receiver, "/topic/chat", chatMessage); - messageReceiptStatus.get(chatMessage).add(receiver); }); - if(messageReceiptStatus.get(chatMessage).size() == onlineUsers.size()) { - //记录完成状态 - offlineMessages.remove(chatMessage);//从离线消息中移除已发送的消息 - messageReceiptStatus.remove(chatMessage);//从消息接收状态集合总移除已发送的消息 - - } } } diff --git a/src/main/java/com/youlai/boot/system/controller/NoticeController.java b/src/main/java/com/youlai/boot/system/controller/NoticeController.java index 01154098..fed866b5 100644 --- a/src/main/java/com/youlai/boot/system/controller/NoticeController.java +++ b/src/main/java/com/youlai/boot/system/controller/NoticeController.java @@ -1,22 +1,20 @@ -package com.youlai.system.controller; +package com.youlai.boot.system.controller; -import com.youlai.system.service.NoticeService; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import com.youlai.system.model.form.NoticeForm; -import com.youlai.system.model.query.NoticeQuery; -import com.youlai.system.model.vo.NoticeVO; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.youlai.system.common.result.PageResult; -import com.youlai.system.common.result.Result; +import com.youlai.boot.common.result.PageResult; +import com.youlai.boot.common.result.Result; +import com.youlai.boot.system.model.form.NoticeForm; +import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeVO; +import com.youlai.boot.system.service.NoticeService; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Operation; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.validation.Valid; /** * 通知公告前端控制层 @@ -43,7 +41,7 @@ public class NoticeController { @Operation(summary = "新增通知公告") @PostMapping @PreAuthorize("@ss.hasPerm('system:notice:add')") - public Result saveNotice(@RequestBody @Valid NoticeForm formData ) { + public Result saveNotice(@RequestBody @Valid NoticeForm formData ) { boolean result = noticeService.saveNotice(formData); return Result.judge(result); } @@ -61,7 +59,7 @@ public class NoticeController { @Operation(summary = "修改通知公告") @PutMapping(value = "/{id}") @PreAuthorize("@ss.hasPerm('system:notice:edit')") - public Result updateNotice( + public Result updateNotice( @Parameter(description = "通知公告ID") @PathVariable Long id, @RequestBody @Validated NoticeForm formData ) { @@ -69,10 +67,26 @@ public class NoticeController { return Result.judge(result); } + @Operation(summary = "发布通知公告") + @PatchMapping(value = "/release/{id}") + @PreAuthorize("@ss.hasPerm('system:notice:release')") + public Result releaseNotice(@Parameter(description = "通知公告ID") @PathVariable Long id) { + boolean result = noticeService.releaseNotice(id); + return Result.judge(result); + } + + @Operation(summary = "撤回通知公告") + @PatchMapping(value = "/recall/{id}") + @PreAuthorize("@ss.hasPerm('system:notice:recall')") + public Result recallNotice(@Parameter(description = "通知公告ID") @PathVariable Long id) { + boolean result = noticeService.recallNotice(id); + return Result.judge(result); + } + @Operation(summary = "删除通知公告") @DeleteMapping("/{ids}") @PreAuthorize("@ss.hasPerm('system:notice:delete')") - public Result deleteNotices( + public Result deleteNotices( @Parameter(description = "通知公告ID,多个以英文逗号(,)分割") @PathVariable String ids ) { boolean result = noticeService.deleteNotices(ids); diff --git a/src/main/java/com/youlai/boot/system/controller/NoticeStatusController.java b/src/main/java/com/youlai/boot/system/controller/NoticeStatusController.java deleted file mode 100644 index 8969c541..00000000 --- a/src/main/java/com/youlai/boot/system/controller/NoticeStatusController.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.youlai.system.controller; - -import com.youlai.system.service.NoticeStatusService; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import com.youlai.system.model.form.NoticeStatusForm; -import com.youlai.system.model.query.NoticeStatusQuery; -import com.youlai.system.model.vo.NoticeStatusVO; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.youlai.system.common.result.PageResult; -import com.youlai.system.common.result.Result; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Operation; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import jakarta.validation.Valid; - -/** - * 用户公告状态前端控制层 - * - * @author youlaitech - * @since 2024-08-28 16:56 - */ -@Tag(name = "用户公告状态接口") -@RestController -@RequestMapping("/api/v1/noticeStatuss") -@RequiredArgsConstructor -public class NoticeStatusController { - - private final NoticeStatusService noticeStatusService; - - @Operation(summary = "用户公告状态分页列表") - @GetMapping("/page") - @PreAuthorize("@ss.hasPerm('system:noticeStatus:query')") - public PageResult getNoticeStatusPage(NoticeStatusQuery queryParams ) { - IPage result = noticeStatusService.getNoticeStatusPage(queryParams); - return PageResult.success(result); - } - - @Operation(summary = "新增用户公告状态") - @PostMapping - @PreAuthorize("@ss.hasPerm('system:noticeStatus:add')") - public Result saveNoticeStatus(@RequestBody @Valid NoticeStatusForm formData ) { - boolean result = noticeStatusService.saveNoticeStatus(formData); - return Result.judge(result); - } - - @Operation(summary = "获取用户公告状态表单数据") - @GetMapping("/{id}/form") - @PreAuthorize("@ss.hasPerm('system:noticeStatus:edit')") - public Result getNoticeStatusForm( - @Parameter(description = "用户公告状态ID") @PathVariable Long id - ) { - NoticeStatusForm formData = noticeStatusService.getNoticeStatusFormData(id); - return Result.success(formData); - } - - @Operation(summary = "修改用户公告状态") - @PutMapping(value = "/{id}") - @PreAuthorize("@ss.hasPerm('system:noticeStatus:edit')") - public Result updateNoticeStatus( - @Parameter(description = "用户公告状态ID") @PathVariable Long id, - @RequestBody @Validated NoticeStatusForm formData - ) { - boolean result = noticeStatusService.updateNoticeStatus(id, formData); - return Result.judge(result); - } - - @Operation(summary = "删除用户公告状态") - @DeleteMapping("/{ids}") - @PreAuthorize("@ss.hasPerm('system:noticeStatus:delete')") - public Result deleteNoticeStatuss( - @Parameter(description = "用户公告状态ID,多个以英文逗号(,)分割") @PathVariable String ids - ) { - boolean result = noticeStatusService.deleteNoticeStatuss(ids); - return Result.judge(result); - } -} diff --git a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java index 93cbd793..605fd55a 100644 --- a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java +++ b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java @@ -1,10 +1,9 @@ -package com.youlai.system.converter; +package com.youlai.boot.system.converter; -import com.youlai.system.model.vo.NoticeVO; +import com.youlai.boot.system.model.entity.Notice; +import com.youlai.boot.system.model.form.NoticeForm; +import com.youlai.boot.system.model.vo.NoticeVO; import org.mapstruct.Mapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.youlai.system.model.entity.Notice; -import com.youlai.system.model.form.NoticeForm; /** * 通知公告对象转换器 diff --git a/src/main/java/com/youlai/boot/system/converter/NoticeStatusConverter.java b/src/main/java/com/youlai/boot/system/converter/NoticeStatusConverter.java deleted file mode 100644 index 94ea63df..00000000 --- a/src/main/java/com/youlai/boot/system/converter/NoticeStatusConverter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.youlai.system.converter; - -import org.mapstruct.Mapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.youlai.system.model.entity.NoticeStatus; -import com.youlai.system.model.form.NoticeStatusForm; - -/** - * 用户公告状态对象转换器 - * - * @author youlaitech - * @since 2024-08-28 16:56 - */ -@Mapper(componentModel = "spring") -public interface NoticeStatusConverter{ - - NoticeStatusForm toForm(NoticeStatus entity); - - NoticeStatus toEntity(NoticeStatusForm formData); -} \ No newline at end of file diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java index 81e3b9eb..5f61bff4 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java @@ -1,11 +1,12 @@ -package com.youlai.system.mapper; +package com.youlai.boot.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.youlai.system.model.entity.Notice; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.youlai.system.model.query.NoticeQuery; -import com.youlai.system.model.vo.NoticeVO; +import com.youlai.boot.system.model.entity.Notice; +import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeVO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 通知公告Mapper接口 @@ -21,8 +22,8 @@ public interface NoticeMapper extends BaseMapper { * * @param page 分页对象 * @param queryParams 查询参数 - * @return + * @return 通知公告分页数据 */ - Page getNoticePage(Page page, NoticeQuery queryParams); + Page getNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java index a3e1d01c..b0b6e6bb 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java @@ -1,10 +1,7 @@ -package com.youlai.system.mapper; +package com.youlai.boot.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.youlai.system.model.entity.NoticeStatus; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.youlai.system.model.query.NoticeStatusQuery; -import com.youlai.system.model.vo.NoticeStatusVO; +import com.youlai.boot.system.model.entity.NoticeStatus; import org.apache.ibatis.annotations.Mapper; /** @@ -16,13 +13,4 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface NoticeStatusMapper extends BaseMapper { - /** - * 获取用户公告状态分页数据 - * - * @param page 分页对象 - * @param queryParams 查询参数 - * @return - */ - Page getNoticeStatusPage(Page page, NoticeStatusQuery queryParams); - } diff --git a/src/main/java/com/youlai/boot/system/model/entity/Config.java b/src/main/java/com/youlai/boot/system/model/entity/Config.java index a82a515c..1100ee96 100644 --- a/src/main/java/com/youlai/boot/system/model/entity/Config.java +++ b/src/main/java/com/youlai/boot/system/model/entity/Config.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.*; import com.youlai.boot.common.base.BaseEntity; import lombok.Data; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** * 系统配置 实体 @@ -11,9 +12,10 @@ import io.swagger.v3.oas.annotations.media.Schema; * @author Theo * @since 2024-07-29 11:17:26 */ +@Data +@EqualsAndHashCode(callSuper = true) @Schema(description = "系统配置") @TableName("sys_config") -@Data public class Config extends BaseEntity { @Schema(description = "配置名称") diff --git a/src/main/java/com/youlai/boot/system/model/entity/Dict.java b/src/main/java/com/youlai/boot/system/model/entity/Dict.java index 586b4fa4..6604f801 100644 --- a/src/main/java/com/youlai/boot/system/model/entity/Dict.java +++ b/src/main/java/com/youlai/boot/system/model/entity/Dict.java @@ -3,6 +3,7 @@ package com.youlai.boot.system.model.entity; import com.baomidou.mybatisplus.annotation.TableName; import com.youlai.boot.common.base.BaseEntity; import lombok.Data; +import lombok.EqualsAndHashCode; /** * 字典实体 @@ -10,8 +11,9 @@ import lombok.Data; * @author haoxr * @since 2022/12/17 */ -@TableName("sys_dict") @Data +@TableName("sys_dict") +@EqualsAndHashCode(callSuper = true) public class Dict extends BaseEntity { /** diff --git a/src/main/java/com/youlai/boot/system/model/entity/Notice.java b/src/main/java/com/youlai/boot/system/model/entity/Notice.java index 860e2cb9..2290dc96 100644 --- a/src/main/java/com/youlai/boot/system/model/entity/Notice.java +++ b/src/main/java/com/youlai/boot/system/model/entity/Notice.java @@ -1,12 +1,15 @@ -package com.youlai.system.model.entity; +package com.youlai.boot.system.model.entity; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; +import com.youlai.boot.common.base.BaseEntity; import lombok.Getter; import lombok.Setter; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.TableName; -import com.youlai.system.common.base.BaseEntity; +import java.time.LocalDateTime; /** * 通知公告实体对象 * @@ -44,15 +47,19 @@ public class Notice extends BaseEntity { * 目标类型(0-全体 1-指定) */ private Integer tarType; + /** + * 目标ID + */ + private String tarIds; /** * 发布状态(0-未发布 1已发布 2已撤回) */ - private Integer sendStatus; + private Integer releaseStatus; /** * 发布时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime sendTime; + private LocalDateTime releaseTime; /** * 撤回时间 */ @@ -61,13 +68,16 @@ public class Notice extends BaseEntity { /** * 创建人ID */ + @TableField(fill = FieldFill.INSERT) private Long createBy; /** * 更新人ID */ + @TableField(fill = FieldFill.UPDATE) private Long updateBy; /** * 逻辑删除标识(0-未删除 1-已删除) */ - private Integer isDelete; + @TableLogic(value = "0", delval = "1") + private Integer isDeleted; } diff --git a/src/main/java/com/youlai/boot/system/model/entity/NoticeStatus.java b/src/main/java/com/youlai/boot/system/model/entity/NoticeStatus.java index 579934a0..4cdc34c9 100644 --- a/src/main/java/com/youlai/boot/system/model/entity/NoticeStatus.java +++ b/src/main/java/com/youlai/boot/system/model/entity/NoticeStatus.java @@ -1,14 +1,13 @@ -package com.youlai.system.model.entity; +package com.youlai.boot.system.model.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Getter; import lombok.Setter; import java.io.Serializable; import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.TableName; -import com.youlai.system.common.base.BaseEntity; /** * 用户公告状态实体对象 @@ -38,11 +37,11 @@ public class NoticeStatus implements Serializable { */ private Long userId; /** - * 读取状态,0未读,1已读取 + * 读取状态,0未读,1已读 */ - private Long readStatus; + private Integer readStatus; /** * 用户阅读时间 */ - private LocalDateTime readTiem; + private LocalDateTime readTime; } diff --git a/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java b/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java index a1ce24dc..e1560437 100644 --- a/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java +++ b/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java @@ -1,14 +1,15 @@ -package com.youlai.system.model.form; +package com.youlai.boot.system.model.form; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.validator.constraints.Range; import java.io.Serial; import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; -import java.time.LocalDateTime; -import jakarta.validation.constraints.*; +import java.util.List; /** * 通知公告表单对象 @@ -24,6 +25,7 @@ public class NoticeForm implements Serializable { @Serial private static final long serialVersionUID = 1L; + @Schema(description = "通知ID") private Long id; @Schema(description = "通知标题") @@ -39,28 +41,15 @@ public class NoticeForm implements Serializable { @Schema(description = "通知类型") private Integer noticeType; - @Schema(description = "发布人") - @NotNull(message = "发布人不能为空") - private Long releaseBy; - @Schema(description = "优先级(0-低 1-中 2-高)") + @Range(min = 0, max = 2, message = "优先级取值范围[0,2]") private Integer priority; @Schema(description = "目标类型(0-全体 1-指定)") + @Range(min = 0, max = 1, message = "目标类型取值范围[0,1]") private Integer tarType; - @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") - private Integer sendStatus; - - @Schema(description = "发布时间") - @NotNull(message = "发布时间不能为空") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime sendTime; - - @Schema(description = "撤回时间") - @NotNull(message = "撤回时间不能为空") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime recallTime; - + @Schema(description = "接收人ID集合") + private List userIds; } diff --git a/src/main/java/com/youlai/boot/system/model/query/DictPageQuery.java b/src/main/java/com/youlai/boot/system/model/query/DictPageQuery.java index 282e7947..3e4696b4 100644 --- a/src/main/java/com/youlai/boot/system/model/query/DictPageQuery.java +++ b/src/main/java/com/youlai/boot/system/model/query/DictPageQuery.java @@ -4,9 +4,11 @@ package com.youlai.boot.system.model.query; import com.youlai.boot.common.base.BasePageQuery; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import lombok.EqualsAndHashCode; -@Schema(description ="字典数据项分页查询对象") @Data +@EqualsAndHashCode(callSuper = true) +@Schema(description ="字典数据项分页查询对象") public class DictPageQuery extends BasePageQuery { @Schema(description="关键字(字典项名称)") diff --git a/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java b/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java index 0ce1432b..b2df83a2 100644 --- a/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java +++ b/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java @@ -1,10 +1,10 @@ -package com.youlai.system.model.query; +package com.youlai.boot.system.model.query; -import com.youlai.system.common.base.BasePageQuery; +import com.youlai.boot.common.base.BasePageQuery; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; -import java.time.LocalDateTime; +import lombok.Data; +import lombok.EqualsAndHashCode; + import java.util.List; /** @@ -13,29 +13,19 @@ import java.util.List; * @author youlaitech * @since 2024-08-27 10:31 */ +@Data +@EqualsAndHashCode(callSuper = true) @Schema(description ="通知公告查询对象") -@Getter -@Setter public class NoticeQuery extends BasePageQuery { private static final long serialVersionUID = 1L; @Schema(description = "通知标题") private String title; - @Schema(description = "通知内容") - private String content; - @Schema(description = "通知类型") - private Integer noticeType; - @Schema(description = "发布人") - private Long releaseBy; - @Schema(description = "优先级(0-低 1-中 2-高)") - private Integer priority; - @Schema(description = "目标类型(0-全体 1-指定)") - private Integer tarType; + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") - private Integer sendStatus; + private Integer releaseStatus; + @Schema(description = "发布时间") - private List sendTime; - @Schema(description = "撤回时间") - private List recallTime; + private List releaseTime; } diff --git a/src/main/java/com/youlai/boot/system/model/query/NoticeStatusQuery.java b/src/main/java/com/youlai/boot/system/model/query/NoticeStatusQuery.java index e56fcbef..cfc1d5be 100644 --- a/src/main/java/com/youlai/boot/system/model/query/NoticeStatusQuery.java +++ b/src/main/java/com/youlai/boot/system/model/query/NoticeStatusQuery.java @@ -1,10 +1,9 @@ -package com.youlai.system.model.query; +package com.youlai.boot.system.model.query; -import com.youlai.system.common.base.BasePageQuery; +import com.youlai.boot.common.base.BasePageQuery; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; -import java.time.LocalDateTime; import java.util.List; /** @@ -22,12 +21,16 @@ public class NoticeStatusQuery extends BasePageQuery { @Schema(description = "id") private Long id; + @Schema(description = "公共通知id") private Long noticeId; + @Schema(description = "用户id") private Integer userId; + @Schema(description = "读取状态,0未读,1已读取") private Long readStatus; + @Schema(description = "用户阅读时间") - private List readTiem; + private List readTime; } diff --git a/src/main/java/com/youlai/boot/system/model/query/PermPageQuery.java b/src/main/java/com/youlai/boot/system/model/query/PermPageQuery.java index 95cb5485..07e02011 100644 --- a/src/main/java/com/youlai/boot/system/model/query/PermPageQuery.java +++ b/src/main/java/com/youlai/boot/system/model/query/PermPageQuery.java @@ -3,6 +3,7 @@ package com.youlai.boot.system.model.query; import com.youlai.boot.common.base.BasePageQuery; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import lombok.EqualsAndHashCode; /** * 权限分页查询对象 @@ -11,7 +12,8 @@ import lombok.Data; * @since 2022/1/14 22:22 */ @Data -@Schema +@Schema +@EqualsAndHashCode(callSuper = true) public class PermPageQuery extends BasePageQuery { @Schema(description="权限名称") diff --git a/src/main/java/com/youlai/boot/system/model/query/UserPageQuery.java b/src/main/java/com/youlai/boot/system/model/query/UserPageQuery.java index 5d7f7157..3e2e7f74 100644 --- a/src/main/java/com/youlai/boot/system/model/query/UserPageQuery.java +++ b/src/main/java/com/youlai/boot/system/model/query/UserPageQuery.java @@ -3,6 +3,7 @@ package com.youlai.boot.system.model.query; import com.youlai.boot.common.base.BasePageQuery; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.List; @@ -12,8 +13,9 @@ import java.util.List; * @author haoxr * @since 2022/1/14 */ -@Schema(description ="用户分页查询对象") @Data +@EqualsAndHashCode(callSuper = true) +@Schema(description ="用户分页查询对象") public class UserPageQuery extends BasePageQuery { @Schema(description="关键字(用户名/昵称/手机号)") diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java deleted file mode 100644 index 8265e020..00000000 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.youlai.system.model.vo; - -import java.io.Serial; -import java.io.Serializable; -import java.time.LocalDateTime; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; -import java.time.LocalDateTime; - -/** - * 用户公告状态视图对象 - * - * @author youlaitech - * @since 2024-08-28 16:56 - */ -@Getter -@Setter -@Schema( description = "用户公告状态视图对象") -public class NoticeStatusVO implements Serializable { - - @Serial - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - @Schema(description = "公共通知id") - private Long noticeId; - @Schema(description = "用户id") - private Integer userId; - @Schema(description = "读取状态,0未读,1已读取") - private Long readStatus; - @Schema(description = "用户阅读时间") - private LocalDateTime readTiem; -} diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java index 152bcb9c..488c254b 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java @@ -1,11 +1,12 @@ -package com.youlai.system.model.vo; +package com.youlai.boot.system.model.vo; -import java.io.Serial; -import java.io.Serializable; -import java.time.LocalDateTime; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; + +import java.io.Serial; +import java.io.Serializable; import java.time.LocalDateTime; /** @@ -25,24 +26,23 @@ public class NoticeVO implements Serializable { private Long id; @Schema(description = "通知标题") private String title; - @Schema(description = "通知内容") - private String content; + @Schema(description = "通知类型") private Integer noticeType; + @Schema(description = "发布人") - private Long releaseBy; + private String releaseBy; + @Schema(description = "优先级(0-低 1-中 2-高)") private Integer priority; + @Schema(description = "目标类型(0-全体 1-指定)") private Integer tarType; + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") - private Integer sendStatus; + private Integer releaseStatus; + @Schema(description = "发布时间") - private LocalDateTime sendTime; - @Schema(description = "撤回时间") - private LocalDateTime recallTime; - @Schema(description = "创建时间") - private LocalDateTime createTime; - @Schema(description = "更新时间") - private LocalDateTime updateTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime releaseTime; } diff --git a/src/main/java/com/youlai/boot/system/service/NoticeService.java b/src/main/java/com/youlai/boot/system/service/NoticeService.java index 13c09abc..4d7c6381 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeService.java @@ -1,11 +1,11 @@ -package com.youlai.system.service; +package com.youlai.boot.system.service; -import com.youlai.system.model.entity.Notice; -import com.youlai.system.model.form.NoticeForm; -import com.youlai.system.model.query.NoticeQuery; -import com.youlai.system.model.vo.NoticeVO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.youlai.boot.system.model.entity.Notice; +import com.youlai.boot.system.model.form.NoticeForm; +import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeVO; /** * 通知公告服务类 @@ -18,7 +18,7 @@ public interface NoticeService extends IService { /** *通知公告分页列表 * - * @return + * @return 通知公告分页列表 */ IPage getNoticePage(NoticeQuery queryParams); @@ -26,7 +26,7 @@ public interface NoticeService extends IService { * 获取通知公告表单数据 * * @param id 通知公告ID - * @return + * @return 通知公告表单对象 */ NoticeForm getNoticeFormData(Long id); @@ -34,7 +34,7 @@ public interface NoticeService extends IService { * 新增通知公告 * * @param formData 通知公告表单对象 - * @return + * @return 是否新增成功 */ boolean saveNotice(NoticeForm formData); @@ -43,7 +43,7 @@ public interface NoticeService extends IService { * * @param id 通知公告ID * @param formData 通知公告表单对象 - * @return + * @return 是否修改成功 */ boolean updateNotice(Long id, NoticeForm formData); @@ -51,8 +51,23 @@ public interface NoticeService extends IService { * 删除通知公告 * * @param ids 通知公告ID,多个以英文逗号(,)分割 - * @return + * @return 是否删除成功 */ boolean deleteNotices(String ids); + /** + * 发布通知公告 + * + * @param id 通知公告ID + * @return 是否发布成功 + */ + boolean releaseNotice(Long id); + + /** + * 撤回通知公告 + * + * @param id 通知公告ID + * @return 是否撤回成功 + */ + boolean recallNotice(Long id); } diff --git a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java index 7e785f6c..454c5427 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java @@ -1,11 +1,7 @@ -package com.youlai.system.service; +package com.youlai.boot.system.service; -import com.youlai.system.model.entity.NoticeStatus; -import com.youlai.system.model.form.NoticeStatusForm; -import com.youlai.system.model.query.NoticeStatusQuery; -import com.youlai.system.model.vo.NoticeStatusVO; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.youlai.boot.system.model.entity.NoticeStatus; /** * 用户公告状态服务类 @@ -15,44 +11,4 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface NoticeStatusService extends IService { - /** - *用户公告状态分页列表 - * - * @return - */ - IPage getNoticeStatusPage(NoticeStatusQuery queryParams); - - /** - * 获取用户公告状态表单数据 - * - * @param id 用户公告状态ID - * @return - */ - NoticeStatusForm getNoticeStatusFormData(Long id); - - /** - * 新增用户公告状态 - * - * @param formData 用户公告状态表单对象 - * @return - */ - boolean saveNoticeStatus(NoticeStatusForm formData); - - /** - * 修改用户公告状态 - * - * @param id 用户公告状态ID - * @param formData 用户公告状态表单对象 - * @return - */ - boolean updateNoticeStatus(Long id, NoticeStatusForm formData); - - /** - * 删除用户公告状态 - * - * @param ids 用户公告状态ID,多个以英文逗号(,)分割 - * @return - */ - boolean deleteNoticeStatuss(String ids); - } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index 8dc4d12a..7ef81cf4 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -1,36 +1,34 @@ -package com.youlai.system.service.impl; +package com.youlai.boot.system.service.impl; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.google.gson.*; -import com.youlai.system.model.entity.NoticeStatus; -import com.youlai.system.model.entity.SysUser; -import com.youlai.system.security.util.SecurityUtils; -import com.youlai.system.service.NoticeStatusService; -import com.youlai.system.service.SysUserService; -import com.youlai.system.service.WebsocketService; -import jodd.util.StringUtil; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.youlai.system.mapper.NoticeMapper; -import com.youlai.system.service.NoticeService; -import com.youlai.system.model.entity.Notice; -import com.youlai.system.model.form.NoticeForm; -import com.youlai.system.model.query.NoticeQuery; -import com.youlai.system.model.vo.NoticeVO; -import com.youlai.system.converter.NoticeConverter; +import com.google.gson.*; +import com.youlai.boot.common.constant.SymbolConstant; +import com.youlai.boot.core.security.util.SecurityUtils; +import com.youlai.boot.platform.websocket.service.WebsocketService; +import com.youlai.boot.system.converter.NoticeConverter; +import com.youlai.boot.system.mapper.NoticeMapper; +import com.youlai.boot.system.model.entity.Notice; +import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.entity.User; +import com.youlai.boot.system.model.form.NoticeForm; +import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeVO; +import com.youlai.boot.system.service.NoticeService; +import com.youlai.boot.system.service.NoticeStatusService; +import com.youlai.boot.system.service.UserService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; - -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; /** * 通知公告服务实现类 @@ -44,11 +42,11 @@ public class NoticeServiceImpl extends ServiceImpl impleme private final NoticeConverter noticeConverter; - private final WebsocketService webSocketServer; + private final WebsocketService websocketService; private final NoticeStatusService noticeStatusService; - private final SysUserService sysUserService; + private final UserService userService; private final Gson gson = new GsonBuilder() .registerTypeAdapter(LocalDateTime.class, (JsonSerializer) (localDateTime, type, jsonSerializationContext) -> @@ -58,44 +56,29 @@ public class NoticeServiceImpl extends ServiceImpl impleme .create(); private void sendWebSocketMsg(Notice notice) { - if (notice.getSendStatus() > 0) { - String jsonNotice = gson.toJson(noticeConverter.toVO(notice)); - webSocketServer.sendStringToFrontend(SecurityUtils.getUsername(), jsonNotice); - List list = sysUserService.list(); - for (SysUser sysUser : list) { - NoticeStatus noticeStatus = noticeStatusService.getOne(new LambdaQueryWrapper().eq(NoticeStatus::getUserId, sysUser.getId()).eq(NoticeStatus::getNoticeId, notice.getId())); - if (noticeStatus == null) { - noticeStatus = new NoticeStatus(); - noticeStatus.setUserId(sysUser.getId()); - noticeStatus.setNoticeId(notice.getId()); - noticeStatus.setReadStatus(0L); - noticeStatusService.save(noticeStatus); - } - } - - } + String jsonNotice = gson.toJson(noticeConverter.toVO(notice)); + websocketService.sendStringToFrontend(SecurityUtils.getUsername(), jsonNotice); } /** * 获取通知公告分页列表 * * @param queryParams 查询参数 - * @return {@link IPage} 通知公告分页列表 + * @return {@link IPage} 通知公告分页列表 */ @Override public IPage getNoticePage(NoticeQuery queryParams) { - Page pageVO = this.baseMapper.getNoticePage( + return this.baseMapper.getNoticePage( new Page<>(queryParams.getPageNum(), queryParams.getPageSize()), queryParams ); - return pageVO; } /** * 获取通知公告表单数据 * * @param id 通知公告ID - * @return + * @return {@link NoticeForm} 通知公告表单对象 */ @Override public NoticeForm getNoticeFormData(Long id) { @@ -107,20 +90,15 @@ public class NoticeServiceImpl extends ServiceImpl impleme * 新增通知公告 * * @param formData 通知公告表单对象 - * @return + * @return {@link Boolean} 是否新增成功 */ @Override public boolean saveNotice(NoticeForm formData) { Notice entity = noticeConverter.toEntity(formData); - entity.setCreateBy(SecurityUtils.getUserId()); - entity.setReleaseBy(SecurityUtils.getUserId()); - entity.setUpdateBy(SecurityUtils.getUserId()); - entity.setIsDelete(0); - boolean result = this.save(entity); - if (result) { - sendWebSocketMsg(entity); + if (entity.getTarType() == 1) { + Assert.notBlank(entity.getTarIds(), "指定用户不能为空"); } - return result; + return this.save(entity); } /** @@ -128,36 +106,99 @@ public class NoticeServiceImpl extends ServiceImpl impleme * * @param id 通知公告ID * @param formData 通知公告表单对象 - * @return + * @return {@link Boolean} 是否更新成功 */ @Override public boolean updateNotice(Long id, NoticeForm formData) { Notice entity = noticeConverter.toEntity(formData); - entity.setUpdateBy(SecurityUtils.getUserId()); - entity.setIsDelete(0); - boolean result = this.updateById(entity); - if (result) { - sendWebSocketMsg(entity); + if (entity.getTarType() == 1) { + Assert.notBlank(entity.getTarIds(), "指定用户不能为空"); } - return result; + return this.updateById(entity); } /** * 删除通知公告 * * @param ids 通知公告ID,多个以英文逗号(,)分割 - * @return + * @return {@link Boolean} 是否删除成功 */ @Override + @Transactional(rollbackFor = Exception.class) public boolean deleteNotices(String ids) { Assert.isTrue(StrUtil.isNotBlank(ids), "删除的通知公告数据为空"); // 逻辑删除 - List idList = Arrays.stream(ids.split(",")) + List idList = Arrays.stream(ids.split(SymbolConstant.COMMA)) .map(Long::parseLong) .toList(); - LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); - wrapper.in(Notice::getId, idList).set(Notice::getIsDelete, 1); - return this.update(wrapper); + boolean b = this.removeByIds(idList); + if (b) { + //删除通知公告的同时,需要删除通知公告对应的用户通知状态 + noticeStatusService.remove(new LambdaQueryWrapper().in(NoticeStatus::getNoticeId, idList)); + } + + return true; + } + + /** + * 发布通知公告 + * @param id 通知公告ID + * @return 是否发布成功 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean releaseNotice(Long id) { + Notice notice = this.getById(id); + Assert.notNull(notice, "通知公告不存在"); + Assert.isTrue(notice.getReleaseStatus() == 0, "通知公告已发布"); + notice.setReleaseStatus(1); + notice.setReleaseTime(LocalDateTime.now()); + this.updateById(notice); + //发布通知公告的同时,需要将通知公告发送给目标用户 + //先删除掉该通知公告之前对应的用户信息 + noticeStatusService.remove(new LambdaQueryWrapper().eq(NoticeStatus::getNoticeId, id)); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (notice.getTarType() == 1) { + Assert.notBlank(notice.getTarIds(), "指定用户不能为空"); + queryWrapper.in(User::getId, Arrays.asList(notice.getTarIds().split(SymbolConstant.COMMA))); + } + //查询出目标用户,增加用户通知状态 + List list = userService.list(queryWrapper); + List needSaveList = list.stream().map(user -> { + NoticeStatus noticeStatus = new NoticeStatus(); + noticeStatus.setNoticeId(id); + noticeStatus.setUserId(user.getId()); + noticeStatus.setReadStatus(0); + return noticeStatus; + }).toList(); + if(needSaveList.size() > 0){ + noticeStatusService.saveBatch(needSaveList); + } + //最后,给当前在线的用户发送websocket消息 + //TODO: 通知公告的websocket消息发送 + return this.updateById(notice); + } + + /** + * 撤回通知公告 + * + * @param id 通知公告ID + * @return 是否撤回成功 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean recallNotice(Long id) { + Notice notice = this.getById(id); + Assert.notNull(notice, "通知公告不存在"); + Assert.isTrue(notice.getReleaseStatus() == 1, "通知公告未发布"); + notice.setReleaseStatus(2); + notice.setRecallTime(LocalDateTime.now()); + if (!this.updateById(notice)) { + return false; + } + //先删除掉该通知公告之前对应的用户信息 + noticeStatusService.remove(new LambdaQueryWrapper().eq(NoticeStatus::getNoticeId, id)); + return true; } } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java index 10f90cd1..a89f21c4 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java @@ -1,24 +1,11 @@ -package com.youlai.system.service.impl; +package com.youlai.boot.system.service.impl; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.boot.system.mapper.NoticeStatusMapper; +import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.service.NoticeStatusService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.youlai.system.mapper.NoticeStatusMapper; -import com.youlai.system.service.NoticeStatusService; -import com.youlai.system.model.entity.NoticeStatus; -import com.youlai.system.model.form.NoticeStatusForm; -import com.youlai.system.model.query.NoticeStatusQuery; -import com.youlai.system.model.vo.NoticeStatusVO; -import com.youlai.system.converter.NoticeStatusConverter; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; /** * 用户公告状态服务实现类 @@ -30,74 +17,4 @@ import cn.hutool.core.util.StrUtil; @RequiredArgsConstructor public class NoticeStatusServiceImpl extends ServiceImpl implements NoticeStatusService { - private final NoticeStatusConverter noticeStatusConverter; - - /** - * 获取用户公告状态分页列表 - * - * @param queryParams 查询参数 - * @return {@link IPage} 用户公告状态分页列表 - */ - @Override - public IPage getNoticeStatusPage(NoticeStatusQuery queryParams) { - Page pageVO = this.baseMapper.getNoticeStatusPage( - new Page<>(queryParams.getPageNum(), queryParams.getPageSize()), - queryParams - ); - return pageVO; - } - - /** - * 获取用户公告状态表单数据 - * - * @param id 用户公告状态ID - * @return - */ - @Override - public NoticeStatusForm getNoticeStatusFormData(Long id) { - NoticeStatus entity = this.getById(id); - return noticeStatusConverter.toForm(entity); - } - - /** - * 新增用户公告状态 - * - * @param formData 用户公告状态表单对象 - * @return - */ - @Override - public boolean saveNoticeStatus(NoticeStatusForm formData) { - NoticeStatus entity = noticeStatusConverter.toEntity(formData); - return this.save(entity); - } - - /** - * 更新用户公告状态 - * - * @param id 用户公告状态ID - * @param formData 用户公告状态表单对象 - * @return - */ - @Override - public boolean updateNoticeStatus(Long id,NoticeStatusForm formData) { - NoticeStatus entity = noticeStatusConverter.toEntity(formData); - return this.updateById(entity); - } - - /** - * 删除用户公告状态 - * - * @param ids 用户公告状态ID,多个以英文逗号(,)分割 - * @return - */ - @Override - public boolean deleteNoticeStatuss(String ids) { - Assert.isTrue(StrUtil.isNotBlank(ids), "删除的用户公告状态数据为空"); - // 逻辑删除 - List idList = Arrays.stream(ids.split(",")) - .map(Long::parseLong) - .toList(); - return this.removeByIds(idList); - } - } diff --git a/src/main/resources/mapper/NoticeMapper.xml b/src/main/resources/mapper/NoticeMapper.xml index 51dc2a48..e82544e1 100644 --- a/src/main/resources/mapper/NoticeMapper.xml +++ b/src/main/resources/mapper/NoticeMapper.xml @@ -1,67 +1,44 @@ - + - SELECT - id, - title, - content, - notice_type, - release_by, - priority, - tar_type, - send_status, - send_time, - recall_time, - create_time, - update_time + sn.id, + sn.title, + sn.notice_type, + su.nickname AS release_by, + sn.priority, + sn.tar_type, + sn.release_status, + sn.release_time, + sn.recall_time FROM - sys_notice - + sys_notice sn + LEFT JOIN + sys_user su ON su.id = sn.release_by + where + sn.is_deleted = 0 - AND title = #{queryParams.title} + AND sn.title LIKE CONCAT('%',#{queryParams.title},'%') - - AND content = #{queryParams.content} + + AND sn.release_status = #{queryParams.releaseStatus} - - AND notice_type = #{queryParams.noticeType} - - - AND release_by = #{queryParams.releaseBy} - - - AND priority = #{queryParams.priority} - - - AND tar_type = #{queryParams.tarType} - - - AND send_status = #{queryParams.sendStatus} - - - - - AND send_time >= #{startDate} + + + + AND sn.release_time >= #{startDate} - - - AND send_time <= #{endDate} + + + AND sn.release_time <= #{endDate} - - - - AND recall_time >= #{startDate} - - - - AND recall_time <= #{endDate} - - - + ORDER BY + id + DESC diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml index e3be239e..506c53d7 100644 --- a/src/main/resources/mapper/NoticeStatusMapper.xml +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -1,41 +1,5 @@ - - - - + From 2ec2eb91b50913361b9d20388c0ad688eaede1f8 Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Mon, 2 Sep 2024 00:01:07 +0800 Subject: [PATCH 07/15] =?UTF-8?q?wip:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E5=BC=80=E5=8F=91=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告开发临时提交 --- .../boot/common/enums/NoticeTypeEnum.java | 31 +++++++++ .../youlai/boot/common/util/CommonUtil.java | 63 +++++++++++++++++++ .../core/security/model/SysUserDetails.java | 2 +- .../system/controller/UserController.java | 38 ++++++----- .../system/converter/NoticeConverter.java | 18 ++++++ .../boot/system/mapper/NoticeMapper.java | 3 +- .../youlai/boot/system/model/bo/NoticeBO.java | 46 ++++++++++++++ .../boot/system/model/entity/Notice.java | 4 -- .../boot/system/model/form/NoticeForm.java | 2 +- .../youlai/boot/system/model/vo/NoticeVO.java | 6 +- .../boot/system/service/UserService.java | 10 ++- .../service/impl/NoticeServiceImpl.java | 10 ++- .../system/service/impl/UserServiceImpl.java | 16 +++++ src/main/resources/mapper/NoticeMapper.xml | 2 +- 14 files changed, 222 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java create mode 100644 src/main/java/com/youlai/boot/common/util/CommonUtil.java create mode 100644 src/main/java/com/youlai/boot/system/model/bo/NoticeBO.java diff --git a/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java b/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java new file mode 100644 index 00000000..30b41f10 --- /dev/null +++ b/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java @@ -0,0 +1,31 @@ +package com.youlai.boot.common.enums; + +import com.youlai.boot.common.base.IBaseEnum; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * 通知类型枚举 + * 1-系统通知 0-系统消息 + * + * @since 2024-9-1 17:33:06 + * @author Theo + */ +@Getter +@RequiredArgsConstructor +public enum NoticeTypeEnum implements IBaseEnum { + + SYSTEM_NOTICE(1, "系统通知"), + SYSTEM_MESSAGE (0, "系统消息"); + + @Getter + private Integer value; + + @Getter + private String label; + + NoticeTypeEnum(Integer value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/src/main/java/com/youlai/boot/common/util/CommonUtil.java b/src/main/java/com/youlai/boot/common/util/CommonUtil.java new file mode 100644 index 00000000..055da5ae --- /dev/null +++ b/src/main/java/com/youlai/boot/common/util/CommonUtil.java @@ -0,0 +1,63 @@ +package com.youlai.boot.common.util; + +import com.youlai.boot.common.constant.SymbolConstant; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 通用工具类 + * + * @author Theo + * @since 2024-9-1 23:42:33 + * @version 1.0.0 + */ +public class CommonUtil { + + private CommonUtil(){} + + + + /** + * 将List转换为字符串 + * + * @param list List + * @param separator 分隔符 + * @return 字符串 + */ + public static String listToStr(List list, String separator) { + return list.stream().collect(Collectors.joining(separator)); + } + + /** + * 将字符串转换为List + * + * @param list List + * @return List + */ + public static String listToStr(List list) { + return listToStr(list, SymbolConstant.COMMA); + } + + /** + * 将字符串转换为List + * + * @param str 字符串 + * @return List + */ + public static List strToList(String str) { + return strToList(str, SymbolConstant.COMMA); + } + + /** + * 将字符串转换为List + * + * @param str 字符串 + * @param separator 分隔符 + * @return List + */ + public static List strToList(String str, String separator) { + return List.of(str.split(separator)); + } + +} diff --git a/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java b/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java index 64ae9353..5fbf1f6c 100644 --- a/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java +++ b/src/main/java/com/youlai/boot/core/security/model/SysUserDetails.java @@ -51,7 +51,7 @@ public class SysUserDetails implements UserDetails { .map(role -> new SimpleGrantedAuthority("ROLE_" + role)) // 标识角色 .collect(Collectors.toSet()); } else { - authorities = Collections.EMPTY_SET; + authorities = Collections.emptySet(); } this.authorities = authorities; this.username = user.getUsername(); diff --git a/src/main/java/com/youlai/boot/system/controller/UserController.java b/src/main/java/com/youlai/boot/system/controller/UserController.java index 90586df2..0f2d2427 100644 --- a/src/main/java/com/youlai/boot/system/controller/UserController.java +++ b/src/main/java/com/youlai/boot/system/controller/UserController.java @@ -4,35 +4,35 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.youlai.boot.system.model.entity.User; -import com.youlai.boot.system.model.form.*; +import com.youlai.boot.common.annotation.Log; +import com.youlai.boot.common.annotation.RepeatSubmit; +import com.youlai.boot.common.enums.ContactType; +import com.youlai.boot.common.enums.LogModuleEnum; +import com.youlai.boot.common.model.Option; import com.youlai.boot.common.result.PageResult; import com.youlai.boot.common.result.Result; -import com.youlai.boot.common.enums.ContactType; -import com.youlai.boot.system.model.vo.UserProfileVO; -import com.youlai.boot.core.security.util.SecurityUtils; import com.youlai.boot.common.util.ExcelUtils; -import com.youlai.boot.common.enums.LogModuleEnum; -import com.youlai.boot.system.model.dto.UserImportDTO; -import com.youlai.boot.common.annotation.RepeatSubmit; +import com.youlai.boot.core.security.util.SecurityUtils; import com.youlai.boot.system.listener.UserImportListener; -import com.youlai.boot.system.model.query.UserPageQuery; import com.youlai.boot.system.model.dto.UserExportDTO; +import com.youlai.boot.system.model.dto.UserImportDTO; +import com.youlai.boot.system.model.entity.User; +import com.youlai.boot.system.model.form.*; +import com.youlai.boot.system.model.query.UserPageQuery; import com.youlai.boot.system.model.vo.UserInfoVO; import com.youlai.boot.system.model.vo.UserPageVO; -import com.youlai.boot.common.annotation.Log; +import com.youlai.boot.system.model.vo.UserProfileVO; import com.youlai.boot.system.service.UserService; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Operation; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; import org.springframework.web.multipart.MultipartFile; import java.io.File; @@ -228,6 +228,10 @@ public class UserController { } - - + @Operation(summary = "用户下拉选项") + @GetMapping("/options") + public Result>> listUserOptions() { + List> list = userService.listUserOptions(); + return Result.success(list); + } } diff --git a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java index 605fd55a..ae493c0e 100644 --- a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java +++ b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java @@ -1,9 +1,13 @@ package com.youlai.boot.system.converter; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.boot.system.model.bo.NoticeBO; import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.vo.NoticeVO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; /** * 通知公告对象转换器 @@ -14,9 +18,23 @@ import org.mapstruct.Mapper; @Mapper(componentModel = "spring") public interface NoticeConverter{ + @Mappings({ + @Mapping(target = "tarIds", expression = "java(com.youlai.boot.common.util.CommonUtil.strToList(entity.getTarIds()))") + }) NoticeForm toForm(Notice entity); + @Mappings({ + @Mapping(target = "tarIds", expression = "java(com.youlai.boot.common.util.CommonUtil.listToStr(formData.getTarIds()))") + }) Notice toEntity(NoticeForm formData); NoticeVO toVO(Notice notice); + + Page toPageVo(Page noticePage); + + @Mappings({ + @Mapping(target = "noticeTypeLabel", expression = "java(com.youlai.boot.common.base.IBaseEnum.getLabelByValue(bo.getNoticeType(), com.youlai.boot.common.enums.NoticeTypeEnum.class))") + }) + NoticeVO toPageVo(NoticeBO bo); + } \ No newline at end of file diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java index 5f61bff4..db146013 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java @@ -2,6 +2,7 @@ package com.youlai.boot.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.youlai.boot.system.model.bo.NoticeBO; import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeVO; @@ -24,6 +25,6 @@ public interface NoticeMapper extends BaseMapper { * @param queryParams 查询参数 * @return 通知公告分页数据 */ - Page getNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); + Page getNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/model/bo/NoticeBO.java b/src/main/java/com/youlai/boot/system/model/bo/NoticeBO.java new file mode 100644 index 00000000..e6f9fbc8 --- /dev/null +++ b/src/main/java/com/youlai/boot/system/model/bo/NoticeBO.java @@ -0,0 +1,46 @@ +package com.youlai.boot.system.model.bo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.time.LocalDateTime; + +/** + * 通知公告业务对象 + * + * @author Theo + * @since 2024-09-01 10:31 + * @version 1.0.0 + */ +@Data +public class NoticeBO { + + @Serial + private static final long serialVersionUID = 1L; + + private Long id; + @Schema(description = "通知标题") + private String title; + + @Schema(description = "通知类型") + private Integer noticeType; + + @Schema(description = "发布人") + private String releaseBy; + + @Schema(description = "优先级(0-低 1-中 2-高)") + private Integer priority; + + @Schema(description = "目标类型(0-全体 1-指定)") + private Integer tarType; + + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回)") + private Integer releaseStatus; + + @Schema(description = "发布时间") + private LocalDateTime releaseTime; + + @Schema(description = "撤回时间") + private LocalDateTime recallTime; +} diff --git a/src/main/java/com/youlai/boot/system/model/entity/Notice.java b/src/main/java/com/youlai/boot/system/model/entity/Notice.java index 2290dc96..d8f6a2d9 100644 --- a/src/main/java/com/youlai/boot/system/model/entity/Notice.java +++ b/src/main/java/com/youlai/boot/system/model/entity/Notice.java @@ -1,7 +1,5 @@ package com.youlai.boot.system.model.entity; -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; @@ -68,12 +66,10 @@ public class Notice extends BaseEntity { /** * 创建人ID */ - @TableField(fill = FieldFill.INSERT) private Long createBy; /** * 更新人ID */ - @TableField(fill = FieldFill.UPDATE) private Long updateBy; /** * 逻辑删除标识(0-未删除 1-已删除) diff --git a/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java b/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java index e1560437..980517bd 100644 --- a/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java +++ b/src/main/java/com/youlai/boot/system/model/form/NoticeForm.java @@ -50,6 +50,6 @@ public class NoticeForm implements Serializable { private Integer tarType; @Schema(description = "接收人ID集合") - private List userIds; + private List tarIds; } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java index 488c254b..12269e3e 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java @@ -28,7 +28,7 @@ public class NoticeVO implements Serializable { private String title; @Schema(description = "通知类型") - private Integer noticeType; + private String noticeTypeLabel; @Schema(description = "发布人") private String releaseBy; @@ -45,4 +45,8 @@ public class NoticeVO implements Serializable { @Schema(description = "发布时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime releaseTime; + + @Schema(description = "撤回时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime recallTime; } diff --git a/src/main/java/com/youlai/boot/system/service/UserService.java b/src/main/java/com/youlai/boot/system/service/UserService.java index 45eadd78..0cecd5a2 100644 --- a/src/main/java/com/youlai/boot/system/service/UserService.java +++ b/src/main/java/com/youlai/boot/system/service/UserService.java @@ -4,6 +4,7 @@ package com.youlai.boot.system.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.boot.common.enums.ContactType; +import com.youlai.boot.common.model.Option; import com.youlai.boot.system.model.dto.UserAuthInfo; import com.youlai.boot.system.model.dto.UserExportDTO; import com.youlai.boot.system.model.entity.User; @@ -147,7 +148,14 @@ public interface UserService extends IService { * 修改当前用户邮箱 * * @param data 表单数据 - * @return + * @return {@link Boolean} 是否绑定成功 */ boolean bindEmail(EmailChangeForm data); + + /** + * 获取用户选项列表 + * + * @return {@link List>} 用户选项列表 + */ + List> listUserOptions(); } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index 7ef81cf4..f13e1f33 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -12,6 +12,7 @@ import com.youlai.boot.core.security.util.SecurityUtils; import com.youlai.boot.platform.websocket.service.WebsocketService; import com.youlai.boot.system.converter.NoticeConverter; import com.youlai.boot.system.mapper.NoticeMapper; +import com.youlai.boot.system.model.bo.NoticeBO; import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.entity.NoticeStatus; import com.youlai.boot.system.model.entity.User; @@ -68,10 +69,11 @@ public class NoticeServiceImpl extends ServiceImpl impleme */ @Override public IPage getNoticePage(NoticeQuery queryParams) { - return this.baseMapper.getNoticePage( + Page noticePage = this.baseMapper.getNoticePage( new Page<>(queryParams.getPageNum(), queryParams.getPageSize()), queryParams ); + return noticeConverter.toPageVo(noticePage); } /** @@ -95,6 +97,8 @@ public class NoticeServiceImpl extends ServiceImpl impleme @Override public boolean saveNotice(NoticeForm formData) { Notice entity = noticeConverter.toEntity(formData); + entity.setReleaseStatus(0); + entity.setCreateBy(SecurityUtils.getUserId()); if (entity.getTarType() == 1) { Assert.notBlank(entity.getTarIds(), "指定用户不能为空"); } @@ -111,6 +115,7 @@ public class NoticeServiceImpl extends ServiceImpl impleme @Override public boolean updateNotice(Long id, NoticeForm formData) { Notice entity = noticeConverter.toEntity(formData); + entity.setUpdateBy(SecurityUtils.getUserId()); if (entity.getTarType() == 1) { Assert.notBlank(entity.getTarIds(), "指定用户不能为空"); } @@ -150,8 +155,9 @@ public class NoticeServiceImpl extends ServiceImpl impleme public boolean releaseNotice(Long id) { Notice notice = this.getById(id); Assert.notNull(notice, "通知公告不存在"); - Assert.isTrue(notice.getReleaseStatus() == 0, "通知公告已发布"); + Assert.isTrue(notice.getReleaseStatus() != 1, "通知公告已发布"); notice.setReleaseStatus(1); + notice.setReleaseBy(SecurityUtils.getUserId()); notice.setReleaseTime(LocalDateTime.now()); this.updateById(notice); //发布通知公告的同时,需要将通知公告发送给目标用户 diff --git a/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java index 7cc5f3c2..e9642a50 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java @@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.boot.common.constant.RedisConstants; import com.youlai.boot.common.constant.SystemConstants; import com.youlai.boot.common.enums.ContactType; +import com.youlai.boot.common.model.Option; import com.youlai.boot.platform.mail.service.MailService; import com.youlai.boot.platform.sms.service.SmsService; import com.youlai.boot.system.model.entity.User; @@ -39,6 +40,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -419,4 +421,18 @@ public class UserServiceImpl extends ServiceImpl implements Us .set(User::getEmail, email) ); } + + /** + * 获取用户选项列表 + * + * @return {@link List>} 用户选项列表 + */ + @Override + public List> listUserOptions() { + List list = this.list(); + if (CollectionUtil.isNotEmpty(list)) { + return list.stream().map(user -> new Option<>(user.getId().toString(), user.getNickname())).collect(Collectors.toList()); + } + return Collections.emptyList(); + } } diff --git a/src/main/resources/mapper/NoticeMapper.xml b/src/main/resources/mapper/NoticeMapper.xml index e82544e1..08fec56f 100644 --- a/src/main/resources/mapper/NoticeMapper.xml +++ b/src/main/resources/mapper/NoticeMapper.xml @@ -3,7 +3,7 @@ - SELECT sn.id, sn.title, From b649eacba53139495760c9861ff32757afd6ebfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Mon, 2 Sep 2024 16:23:48 +0800 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告临时提交 --- .../boot/common/enums/MessageTypeEnum.java | 19 +++++ .../youlai/boot/common/util/CommonUtil.java | 4 + .../websocket/service/MessageService.java | 29 +++++++ .../websocket/service/WebsocketService.java | 17 ----- .../service/impl/WebsocketServiceImpl.java | 75 +++++++++++++------ .../boot/system/handler/MessageHandler.java | 35 +++++++++ .../boot/system/model/dto/MessageDTO.java | 30 ++++++++ .../service/impl/NoticeServiceImpl.java | 51 +++++++++---- 8 files changed, 206 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java create mode 100644 src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java delete mode 100644 src/main/java/com/youlai/boot/platform/websocket/service/WebsocketService.java create mode 100644 src/main/java/com/youlai/boot/system/handler/MessageHandler.java create mode 100644 src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java diff --git a/src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java b/src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java new file mode 100644 index 00000000..d642f757 --- /dev/null +++ b/src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java @@ -0,0 +1,19 @@ +package com.youlai.boot.common.enums; + +/** + * 消息类型枚举 + * @author Theo + * @since 2024-9-2 14:32:58 + */ +public enum MessageTypeEnum { + WEBSOCKET("webScoket", "websocket消息"); + + private String value; + + private String label; + + MessageTypeEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/src/main/java/com/youlai/boot/common/util/CommonUtil.java b/src/main/java/com/youlai/boot/common/util/CommonUtil.java index 055da5ae..f039ed48 100644 --- a/src/main/java/com/youlai/boot/common/util/CommonUtil.java +++ b/src/main/java/com/youlai/boot/common/util/CommonUtil.java @@ -60,4 +60,8 @@ public class CommonUtil { return List.of(str.split(separator)); } + + public static String delHtmlTags(String htmlStr) { + return htmlStr.replaceAll("<[^>]+>", ""); + } } diff --git a/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java b/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java new file mode 100644 index 00000000..0f6fcc14 --- /dev/null +++ b/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java @@ -0,0 +1,29 @@ +package com.youlai.boot.platform.websocket.service; + +import com.youlai.boot.common.enums.MessageTypeEnum; +import com.youlai.boot.system.model.dto.MessageDTO; + +/** + * 消息服务接口 + * + * @author Theo + * @since 2024-9-2 14:32:58 + */ +public interface MessageService { + + + /** + * 检查消息类型 + * + * @param messageType 消息类型 + * @return 是否支持 + */ + boolean check(MessageTypeEnum messageType); + + /** + * 发送消息 + * + * @param message 消息 + */ + void sendMessage(MessageDTO message); +} diff --git a/src/main/java/com/youlai/boot/platform/websocket/service/WebsocketService.java b/src/main/java/com/youlai/boot/platform/websocket/service/WebsocketService.java deleted file mode 100644 index 4e23d583..00000000 --- a/src/main/java/com/youlai/boot/platform/websocket/service/WebsocketService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.youlai.boot.platform.websocket.service; - -import java.util.Set; - -public interface WebsocketService { - - void addUser(String username); - - void removeUser(String username) ; - - Set getUsers(); - /** - * 发送消息到前端 - * @param message - */ - void sendStringToFrontend(String sender,String message); -} diff --git a/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java b/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java index 5ab04a31..1ed4a900 100644 --- a/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java +++ b/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java @@ -1,42 +1,47 @@ package com.youlai.boot.platform.websocket.service.impl; -import com.youlai.boot.platform.websocket.service.WebsocketService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.youlai.boot.common.enums.MessageTypeEnum; +import com.youlai.boot.platform.websocket.service.MessageService; import com.youlai.boot.system.event.UserConnectionEvent; import com.youlai.boot.system.model.dto.ChatMessage; +import com.youlai.boot.system.model.dto.MessageDTO; +import com.youlai.boot.system.model.entity.User; +import com.youlai.boot.system.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.catalina.security.SecurityUtil; import org.springframework.context.event.EventListener; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +/** + * WebSocket消息服务实现类 + * + * @author ray + * @since 2024-9-2 14:32:58 + */ @Service @Slf4j @RequiredArgsConstructor -public class WebsocketServiceImpl implements WebsocketService { +public class WebsocketServiceImpl implements MessageService { private final SimpMessagingTemplate messagingTemplate; private final Set onlineUsers = ConcurrentHashMap.newKeySet(); - @Override - public void addUser(String username) { - onlineUsers.add(username); - } - - @Override - public void removeUser(String username) { - onlineUsers.remove(username); - } - - @Override - public Set getUsers() { - return onlineUsers; - } - + /** + * 用户连接事件处理 + * + * @param event 用户连接事件 + */ @EventListener public void handleUserConnectionEvent(UserConnectionEvent event) { String username = event.getUsername(); @@ -51,16 +56,44 @@ public class WebsocketServiceImpl implements WebsocketService { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } + /** + * 定时推送在线用户人数 + */ @Scheduled(fixedRate = 5000) public void sendOnlineUserCount() { messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } + + /** + * 策略模式检查 + * + * @param messageType 消息类型 + * @return boolean + */ @Override - public void sendStringToFrontend(String sender, String message) { - ChatMessage chatMessage = new ChatMessage(sender, message); - onlineUsers.forEach(receiver -> { - messagingTemplate.convertAndSendToUser(receiver, "/topic/chat", chatMessage); + public boolean check(MessageTypeEnum messageType) { + return messageType.equals(MessageTypeEnum.WEBSOCKET); + } + + /** + * 发送消息 + * + * @param message 消息 + */ + @Override + public void sendMessage(MessageDTO message) { + List users = null; + if(message.getReceiver() == null || message.getReceiver().isEmpty()){ + // 发送给所有在线用户 离线用户不发送,因为离线用户下次登录会直接查询未读消息 + users = new ArrayList<>(onlineUsers); + }else{ + users = message.getReceiver().stream().filter(onlineUsers::contains).collect(Collectors.toList()); + } + //获取当前用户 + ChatMessage chatMessage = new ChatMessage(message.getSender(), message.getContent()); + users.forEach(receiver -> { + messagingTemplate.convertAndSendToUser(receiver, "/queue/message", chatMessage); }); } } diff --git a/src/main/java/com/youlai/boot/system/handler/MessageHandler.java b/src/main/java/com/youlai/boot/system/handler/MessageHandler.java new file mode 100644 index 00000000..e66ca7db --- /dev/null +++ b/src/main/java/com/youlai/boot/system/handler/MessageHandler.java @@ -0,0 +1,35 @@ +package com.youlai.boot.system.handler; + +import com.youlai.boot.platform.websocket.service.MessageService; +import com.youlai.boot.system.model.dto.MessageDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 消息处理器 + * + * @author Theo + * @since 2024-9-2 14:32:58 + */ +@Component +@RequiredArgsConstructor +public class MessageHandler { + + private final List messageServices; + + + /** + * 发送消息 + * + * @param messageDTO 消息载体 + */ + public void sendMessage(MessageDTO messageDTO) { + messageServices.forEach(messageService -> { + if (messageService.check(messageDTO.getMessageType())) { + messageService.sendMessage(messageDTO); + } + }); + } +} diff --git a/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java b/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java new file mode 100644 index 00000000..4f7e7f7e --- /dev/null +++ b/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java @@ -0,0 +1,30 @@ +package com.youlai.boot.system.model.dto; + +import com.youlai.boot.common.enums.MessageTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +/** + * 消息载体 + * + * @author Theo + * @since 2024-9-2 14:32:58 + * @version 1.0.0 + */ +@Data +public class MessageDTO { + + @Schema(description = "消息内容") + private String content; + + @Schema(description = "发送者") + private String sender; + + @Schema(description = "接收者") + private List receiver; + + @Schema(description = "消息类型") + private MessageTypeEnum messageType; +} diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index f13e1f33..120f1fac 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -2,17 +2,20 @@ package com.youlai.boot.system.service.impl; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.google.gson.*; import com.youlai.boot.common.constant.SymbolConstant; +import com.youlai.boot.common.enums.MessageTypeEnum; +import com.youlai.boot.common.util.CommonUtil; import com.youlai.boot.core.security.util.SecurityUtils; -import com.youlai.boot.platform.websocket.service.WebsocketService; import com.youlai.boot.system.converter.NoticeConverter; +import com.youlai.boot.system.handler.MessageHandler; import com.youlai.boot.system.mapper.NoticeMapper; import com.youlai.boot.system.model.bo.NoticeBO; +import com.youlai.boot.system.model.dto.MessageDTO; import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.entity.NoticeStatus; import com.youlai.boot.system.model.entity.User; @@ -30,6 +33,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; /** * 通知公告服务实现类 @@ -43,24 +47,12 @@ public class NoticeServiceImpl extends ServiceImpl impleme private final NoticeConverter noticeConverter; - private final WebsocketService websocketService; + private final MessageHandler messageHandler; private final NoticeStatusService noticeStatusService; private final UserService userService; - private final Gson gson = new GsonBuilder() - .registerTypeAdapter(LocalDateTime.class, (JsonSerializer) (localDateTime, type, jsonSerializationContext) -> - new JsonPrimitive(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))) - .registerTypeAdapter(LocalDateTime.class, (JsonDeserializer) (jsonElement, type, jsonDeserializationContext) -> - LocalDateTime.parse(jsonElement.getAsString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME)) - .create(); - - private void sendWebSocketMsg(Notice notice) { - String jsonNotice = gson.toJson(noticeConverter.toVO(notice)); - websocketService.sendStringToFrontend(SecurityUtils.getUsername(), jsonNotice); - } - /** * 获取通知公告分页列表 * @@ -181,10 +173,37 @@ public class NoticeServiceImpl extends ServiceImpl impleme noticeStatusService.saveBatch(needSaveList); } //最后,给当前在线的用户发送websocket消息 - //TODO: 通知公告的websocket消息发送 + List usernameList = null; + if(notice.getTarType() == 1){ + List collect = needSaveList.stream().map(NoticeStatus::getUserId).collect(Collectors.toList()); + List userList = userService.list(new LambdaQueryWrapper().in(User::getId, collect).select(User::getUsername)); + usernameList = userList.stream().map(User::getUsername).collect(Collectors.toList()); + } + MessageDTO message = new MessageDTO(); + message.setMessageType(MessageTypeEnum.WEBSOCKET); + message.setReceiver(usernameList); + message.setContent(getNoticeContent(notice)); + message.setSender(SecurityUtils.getUsername()); + messageHandler.sendMessage(message); return this.updateById(notice); } + /** + * 自定义组合公告内容 + * + * @param notice 通知公告 + * @return 自定义组合通知公告内容 + */ + private String getNoticeContent(Notice notice) { + JSONObject jsonObject = new JSONObject(); + jsonObject.set("id", notice.getId()); + jsonObject.set("title", notice.getTitle()); + jsonObject.set("messageType", notice.getNoticeType()); + jsonObject.set("releaseTime", notice.getReleaseTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + jsonObject.set("type", "release"); + return jsonObject.toString(); + } + /** * 撤回通知公告 * From 6f662dcde9a3e3f53cd1df47eba8e83d9edbb2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Thu, 5 Sep 2024 17:33:24 +0800 Subject: [PATCH 09/15] =?UTF-8?q?feat:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告临时提交 --- .../boot/system/controller/NoticeController.java | 9 +++++++++ .../youlai/boot/system/model/vo/NoticeStatusVO.java | 10 ++++++++++ .../boot/system/service/NoticeStatusService.java | 5 +++++ .../system/service/impl/NoticeStatusServiceImpl.java | 9 +++++++++ 4 files changed, 33 insertions(+) create mode 100644 src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java diff --git a/src/main/java/com/youlai/boot/system/controller/NoticeController.java b/src/main/java/com/youlai/boot/system/controller/NoticeController.java index fed866b5..dc1eb691 100644 --- a/src/main/java/com/youlai/boot/system/controller/NoticeController.java +++ b/src/main/java/com/youlai/boot/system/controller/NoticeController.java @@ -7,6 +7,7 @@ import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeVO; import com.youlai.boot.system.service.NoticeService; +import com.youlai.boot.system.service.NoticeStatusService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -30,6 +31,8 @@ public class NoticeController { private final NoticeService noticeService; + private final NoticeStatusService noticeStatusService; + @Operation(summary = "通知公告分页列表") @GetMapping("/page") @PreAuthorize("@ss.hasPerm('system:notice:query')") @@ -92,4 +95,10 @@ public class NoticeController { boolean result = noticeService.deleteNotices(ids); return Result.judge(result); } + + @Operation(summary = "获取我的通知公告") + @GetMapping("/notice/{count}") + public Result listNotices(@PathVariable Integer count) { + return Result.success(noticeStatusService.listNotices(count)); + } } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java new file mode 100644 index 00000000..a91bd67d --- /dev/null +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java @@ -0,0 +1,10 @@ +package com.youlai.boot.system.model.vo; + +/** + * 用户公告状态VO + * + * @auther Theo + * @since 2024-08-28 16:56 + */ +public class NoticeStatusVO { +} diff --git a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java index 454c5427..332a1818 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java @@ -1,7 +1,11 @@ package com.youlai.boot.system.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.youlai.boot.common.result.Result; import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.vo.NoticeStatusVO; + +import java.util.List; /** * 用户公告状态服务类 @@ -11,4 +15,5 @@ import com.youlai.boot.system.model.entity.NoticeStatus; */ public interface NoticeStatusService extends IService { + List listNotices(Integer count); } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java index a89f21c4..04e52275 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java @@ -1,12 +1,16 @@ package com.youlai.boot.system.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.boot.common.result.Result; import com.youlai.boot.system.mapper.NoticeStatusMapper; import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.vo.NoticeStatusVO; import com.youlai.boot.system.service.NoticeStatusService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + /** * 用户公告状态服务实现类 * @@ -17,4 +21,9 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class NoticeStatusServiceImpl extends ServiceImpl implements NoticeStatusService { + @Override + public List listNotices(Integer count) { + + return null; + } } From 3dae203dadea0da535007349c67d83af181a8fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Fri, 6 Sep 2024 18:02:07 +0800 Subject: [PATCH 10/15] =?UTF-8?q?feat:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告临时提交 --- .../boot/common/enums/MessageTypeEnum.java | 19 ------------- .../boot/common/enums/NoticeTypeEnum.java | 8 ++++-- .../boot/common/enums/NoticeWayEnum.java | 28 +++++++++++++++++++ .../controller/WebsocketController.java | 3 +- .../websocket/service/MessageService.java | 4 +-- .../service/impl/WebsocketServiceImpl.java | 18 ++++++------ .../system/converter/NoticeConverter.java | 4 +-- .../boot/system/handler/MessageHandler.java | 4 +-- .../boot/system/model/dto/ChatMessage.java | 8 +++++- .../boot/system/model/dto/MessageDTO.java | 6 ++-- .../boot/system/model/vo/NoticeStatusVO.java | 14 +++++++++- .../service/impl/NoticeServiceImpl.java | 5 ++-- .../service/impl/NoticeStatusServiceImpl.java | 8 +++++- 13 files changed, 81 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java create mode 100644 src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java diff --git a/src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java b/src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java deleted file mode 100644 index d642f757..00000000 --- a/src/main/java/com/youlai/boot/common/enums/MessageTypeEnum.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.youlai.boot.common.enums; - -/** - * 消息类型枚举 - * @author Theo - * @since 2024-9-2 14:32:58 - */ -public enum MessageTypeEnum { - WEBSOCKET("webScoket", "websocket消息"); - - private String value; - - private String label; - - MessageTypeEnum(String value, String label) { - this.value = value; - this.label = label; - } -} diff --git a/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java b/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java index 30b41f10..2bf5b176 100644 --- a/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java +++ b/src/main/java/com/youlai/boot/common/enums/NoticeTypeEnum.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; /** * 通知类型枚举 - * 1-系统通知 0-系统消息 + * 0-系统消息 * * @since 2024-9-1 17:33:06 * @author Theo @@ -15,8 +15,10 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public enum NoticeTypeEnum implements IBaseEnum { - SYSTEM_NOTICE(1, "系统通知"), - SYSTEM_MESSAGE (0, "系统消息"); + /** + * 通知类型 + */ + SYSTEM_MESSAGE(0, "系统消息"); @Getter private Integer value; diff --git a/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java b/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java new file mode 100644 index 00000000..3a42a207 --- /dev/null +++ b/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java @@ -0,0 +1,28 @@ +package com.youlai.boot.common.enums; + +import com.youlai.boot.common.base.IBaseEnum; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * 通知方式枚举 + * @author Theo + * @since 2024-9-2 14:32:58 + */ +@Getter +@RequiredArgsConstructor +public enum NoticeWayEnum implements IBaseEnum { + /** + * 通知方式 + */ + WEBSOCKET("webSocket", "发送websocket消息"); + + private String value; + + private String label; + + NoticeWayEnum(String value, String label) { + this.value = value; + this.label = label; + } +} diff --git a/src/main/java/com/youlai/boot/platform/websocket/controller/WebsocketController.java b/src/main/java/com/youlai/boot/platform/websocket/controller/WebsocketController.java index 50caff79..8e3ff019 100644 --- a/src/main/java/com/youlai/boot/platform/websocket/controller/WebsocketController.java +++ b/src/main/java/com/youlai/boot/platform/websocket/controller/WebsocketController.java @@ -1,5 +1,6 @@ package com.youlai.boot.platform.websocket.controller; +import com.youlai.boot.common.enums.NoticeTypeEnum; import com.youlai.boot.system.model.dto.ChatMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -56,7 +57,7 @@ public class WebsocketController { log.info("发送人:{}; 接收人:{}", sender, receiver); // 发送消息给指定用户,拼接后路径 /user/{receiver}/queue/greeting - messagingTemplate.convertAndSendToUser(receiver, "/queue/greeting", new ChatMessage(sender, message)); + messagingTemplate.convertAndSendToUser(receiver, "/queue/greeting", new ChatMessage(sender, message, NoticeTypeEnum.SYSTEM_MESSAGE)); } } diff --git a/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java b/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java index 0f6fcc14..084d6825 100644 --- a/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java +++ b/src/main/java/com/youlai/boot/platform/websocket/service/MessageService.java @@ -1,6 +1,6 @@ package com.youlai.boot.platform.websocket.service; -import com.youlai.boot.common.enums.MessageTypeEnum; +import com.youlai.boot.common.enums.NoticeWayEnum; import com.youlai.boot.system.model.dto.MessageDTO; /** @@ -18,7 +18,7 @@ public interface MessageService { * @param messageType 消息类型 * @return 是否支持 */ - boolean check(MessageTypeEnum messageType); + boolean check(NoticeWayEnum messageType); /** * 发送消息 diff --git a/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java b/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java index 1ed4a900..2a6cf7c8 100644 --- a/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java +++ b/src/main/java/com/youlai/boot/platform/websocket/service/impl/WebsocketServiceImpl.java @@ -1,16 +1,13 @@ package com.youlai.boot.platform.websocket.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.youlai.boot.common.enums.MessageTypeEnum; +import com.youlai.boot.common.enums.NoticeWayEnum; +import com.youlai.boot.common.enums.NoticeTypeEnum; import com.youlai.boot.platform.websocket.service.MessageService; import com.youlai.boot.system.event.UserConnectionEvent; import com.youlai.boot.system.model.dto.ChatMessage; import com.youlai.boot.system.model.dto.MessageDTO; -import com.youlai.boot.system.model.entity.User; -import com.youlai.boot.system.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.catalina.security.SecurityUtil; import org.springframework.context.event.EventListener; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.scheduling.annotation.Scheduled; @@ -61,6 +58,7 @@ public class WebsocketServiceImpl implements MessageService { */ @Scheduled(fixedRate = 5000) public void sendOnlineUserCount() { + log.info("Send online user count: {}", onlineUsers.size()); messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } @@ -68,12 +66,12 @@ public class WebsocketServiceImpl implements MessageService { /** * 策略模式检查 * - * @param messageType 消息类型 - * @return boolean + * @param noticeWayEnum 通知方式 + * @return boolean 是否支持 */ @Override - public boolean check(MessageTypeEnum messageType) { - return messageType.equals(MessageTypeEnum.WEBSOCKET); + public boolean check(NoticeWayEnum noticeWayEnum) { + return noticeWayEnum.equals(NoticeWayEnum.WEBSOCKET); } /** @@ -91,7 +89,7 @@ public class WebsocketServiceImpl implements MessageService { users = message.getReceiver().stream().filter(onlineUsers::contains).collect(Collectors.toList()); } //获取当前用户 - ChatMessage chatMessage = new ChatMessage(message.getSender(), message.getContent()); + ChatMessage chatMessage = new ChatMessage(message.getSender(), message.getContent(), NoticeTypeEnum.SYSTEM_MESSAGE); users.forEach(receiver -> { messagingTemplate.convertAndSendToUser(receiver, "/queue/message", chatMessage); }); diff --git a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java index ae493c0e..c7b1c4e5 100644 --- a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java +++ b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java @@ -33,8 +33,8 @@ public interface NoticeConverter{ Page toPageVo(Page noticePage); @Mappings({ - @Mapping(target = "noticeTypeLabel", expression = "java(com.youlai.boot.common.base.IBaseEnum.getLabelByValue(bo.getNoticeType(), com.youlai.boot.common.enums.NoticeTypeEnum.class))") + @Mapping(target = "noticeTypeLabel", expression = "java(com.youlai.boot.common.base.IBaseEnum.getLabelByValue(bo.getNoticeType(), com.youlai.boot.common.enums.NoticeWayEnum.class))") }) NoticeVO toPageVo(NoticeBO bo); -} \ No newline at end of file +} diff --git a/src/main/java/com/youlai/boot/system/handler/MessageHandler.java b/src/main/java/com/youlai/boot/system/handler/MessageHandler.java index e66ca7db..21ae2421 100644 --- a/src/main/java/com/youlai/boot/system/handler/MessageHandler.java +++ b/src/main/java/com/youlai/boot/system/handler/MessageHandler.java @@ -22,12 +22,12 @@ public class MessageHandler { /** * 发送消息 - * + * 如果后面有多种消息发送方式,可以设置MessageDTO中的noticeWay,调用不同的消息发送方式,实现消息多种发送方式 * @param messageDTO 消息载体 */ public void sendMessage(MessageDTO messageDTO) { messageServices.forEach(messageService -> { - if (messageService.check(messageDTO.getMessageType())) { + if (messageService.check(messageDTO.getNoticeWay())) { messageService.sendMessage(messageDTO); } }); diff --git a/src/main/java/com/youlai/boot/system/model/dto/ChatMessage.java b/src/main/java/com/youlai/boot/system/model/dto/ChatMessage.java index 7e2a6e79..e4ce3db4 100644 --- a/src/main/java/com/youlai/boot/system/model/dto/ChatMessage.java +++ b/src/main/java/com/youlai/boot/system/model/dto/ChatMessage.java @@ -1,11 +1,12 @@ package com.youlai.boot.system.model.dto; +import com.youlai.boot.common.enums.NoticeTypeEnum; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** - * WebSocket 消息体 + * 系统消息体 */ @Data @AllArgsConstructor @@ -22,4 +23,9 @@ public class ChatMessage { */ private String content; + /** + * 消息类型 + */ + private NoticeTypeEnum noticeType; + } diff --git a/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java b/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java index 4f7e7f7e..5b792c71 100644 --- a/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java +++ b/src/main/java/com/youlai/boot/system/model/dto/MessageDTO.java @@ -1,6 +1,6 @@ package com.youlai.boot.system.model.dto; -import com.youlai.boot.common.enums.MessageTypeEnum; +import com.youlai.boot.common.enums.NoticeWayEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -25,6 +25,6 @@ public class MessageDTO { @Schema(description = "接收者") private List receiver; - @Schema(description = "消息类型") - private MessageTypeEnum messageType; + @Schema(description = "通知方式") + private NoticeWayEnum noticeWay; } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java index a91bd67d..a1d0c6e9 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java @@ -1,10 +1,22 @@ package com.youlai.boot.system.model.vo; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + /** * 用户公告状态VO * - * @auther Theo + * @author Theo * @since 2024-08-28 16:56 */ +@Data +@Schema(description = "用户公告状态VO") public class NoticeStatusVO { + + @Schema(description = "公告ID") + private Long noticeId; + + @Schema(description = "是否已读") + private Boolean read; + } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index 120f1fac..471d13b7 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -8,8 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.boot.common.constant.SymbolConstant; -import com.youlai.boot.common.enums.MessageTypeEnum; -import com.youlai.boot.common.util.CommonUtil; +import com.youlai.boot.common.enums.NoticeWayEnum; import com.youlai.boot.core.security.util.SecurityUtils; import com.youlai.boot.system.converter.NoticeConverter; import com.youlai.boot.system.handler.MessageHandler; @@ -180,7 +179,7 @@ public class NoticeServiceImpl extends ServiceImpl impleme usernameList = userList.stream().map(User::getUsername).collect(Collectors.toList()); } MessageDTO message = new MessageDTO(); - message.setMessageType(MessageTypeEnum.WEBSOCKET); + message.setNoticeWay(NoticeWayEnum.WEBSOCKET); message.setReceiver(usernameList); message.setContent(getNoticeContent(notice)); message.setSender(SecurityUtils.getUsername()); diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java index 04e52275..0fc725e5 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java @@ -1,10 +1,12 @@ package com.youlai.boot.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.boot.common.result.Result; import com.youlai.boot.system.mapper.NoticeStatusMapper; import com.youlai.boot.system.model.entity.NoticeStatus; import com.youlai.boot.system.model.vo.NoticeStatusVO; +import com.youlai.boot.system.service.NoticeService; import com.youlai.boot.system.service.NoticeStatusService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -21,9 +23,13 @@ import java.util.List; @RequiredArgsConstructor public class NoticeStatusServiceImpl extends ServiceImpl implements NoticeStatusService { + private final NoticeService noticeService; + @Override public List listNotices(Integer count) { - + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + //获取当前用户 + queryWrapper.eq(NoticeStatus::getUserId, 1L); return null; } } From f5977783ff6816600c36749efae1634efbb38992 Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Sun, 8 Sep 2024 02:22:32 +0800 Subject: [PATCH 11/15] =?UTF-8?q?wip:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E5=BC=80=E5=8F=91=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告开发临时提交 --- .../boot/common/enums/NoticeWayEnum.java | 4 +- .../system/controller/NoticeController.java | 27 ++++++++++-- .../system/converter/NoticeConverter.java | 1 - .../boot/system/mapper/NoticeMapper.java | 7 ++++ .../system/mapper/NoticeStatusMapper.java | 10 +++++ .../boot/system/model/vo/NoticeDetailVO.java | 42 +++++++++++++++++++ .../boot/system/model/vo/NoticeStatusVO.java | 7 +++- .../youlai/boot/system/model/vo/NoticeVO.java | 1 + .../boot/system/service/NoticeService.java | 16 +++++++ .../system/service/NoticeStatusService.java | 13 +++++- .../service/impl/NoticeServiceImpl.java | 38 +++++++++++++++++ .../service/impl/NoticeStatusServiceImpl.java | 35 ++++++++++++---- src/main/resources/mapper/NoticeMapper.xml | 21 ++++++++++ .../resources/mapper/NoticeStatusMapper.xml | 18 ++++++++ 14 files changed, 221 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java diff --git a/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java b/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java index 3a42a207..bf11e68c 100644 --- a/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java +++ b/src/main/java/com/youlai/boot/common/enums/NoticeWayEnum.java @@ -11,14 +11,16 @@ import lombok.RequiredArgsConstructor; */ @Getter @RequiredArgsConstructor -public enum NoticeWayEnum implements IBaseEnum { +public enum NoticeWayEnum implements IBaseEnum { /** * 通知方式 */ WEBSOCKET("webSocket", "发送websocket消息"); + @Getter private String value; + @Getter private String label; NoticeWayEnum(String value, String label) { diff --git a/src/main/java/com/youlai/boot/system/controller/NoticeController.java b/src/main/java/com/youlai/boot/system/controller/NoticeController.java index dc1eb691..263ac43f 100644 --- a/src/main/java/com/youlai/boot/system/controller/NoticeController.java +++ b/src/main/java/com/youlai/boot/system/controller/NoticeController.java @@ -58,6 +58,12 @@ public class NoticeController { NoticeForm formData = noticeService.getNoticeFormData(id); return Result.success(formData); } + @Operation(summary = "管理页面查看通知公告") + @GetMapping("/detail/{id}") + public Result getReadNoticeDetail( + @Parameter(description = "通知公告ID")@PathVariable Long id) { + return Result.success(noticeService.getReadNoticeDetail(id)); + } @Operation(summary = "修改通知公告") @PutMapping(value = "/{id}") @@ -96,9 +102,22 @@ public class NoticeController { return Result.judge(result); } - @Operation(summary = "获取我的通知公告") - @GetMapping("/notice/{count}") - public Result listNotices(@PathVariable Integer count) { - return Result.success(noticeStatusService.listNotices(count)); + @Operation(summary = "获取未读的通知公告") + @GetMapping("/unread") + public Result listUnreadNotices() { + return Result.success(noticeStatusService.listUnreadNotices()); + } + + @Operation(summary = "阅读通知公告") + @PatchMapping("/read/{id}") + public Result readNotice(@PathVariable Long id) { + return Result.success(noticeService.readNotice(id)); + } + + @Operation(summary = "全部已读") + @PatchMapping("/readAll") + public Result readAll() { + noticeStatusService.readAll(); + return Result.success(); } } diff --git a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java index c7b1c4e5..3ba79b45 100644 --- a/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java +++ b/src/main/java/com/youlai/boot/system/converter/NoticeConverter.java @@ -33,7 +33,6 @@ public interface NoticeConverter{ Page toPageVo(Page noticePage); @Mappings({ - @Mapping(target = "noticeTypeLabel", expression = "java(com.youlai.boot.common.base.IBaseEnum.getLabelByValue(bo.getNoticeType(), com.youlai.boot.common.enums.NoticeWayEnum.class))") }) NoticeVO toPageVo(NoticeBO bo); diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java index db146013..5a11f119 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeMapper.java @@ -6,6 +6,7 @@ import com.youlai.boot.system.model.bo.NoticeBO; import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeVO; +import com.youlai.boot.system.model.vo.NoticeDetailVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -27,4 +28,10 @@ public interface NoticeMapper extends BaseMapper { */ Page getNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); + /** + * 获取阅读时通知公告详情 + * @param id 通知公告ID + * @return 通知公告详情 + */ + NoticeDetailVO getReadNoticeVO(@Param("id") Long id); } diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java index b0b6e6bb..4858c8e9 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java @@ -2,7 +2,11 @@ package com.youlai.boot.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.vo.NoticeStatusVO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 用户公告状态Mapper接口 @@ -13,4 +17,10 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface NoticeStatusMapper extends BaseMapper { + /** + * 获取未读的通知公告 + * @param userId 用户ID + * @return 公告列表 + */ + List listUnreadNotices(@Param("userId")Long userId); } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java new file mode 100644 index 00000000..27bb9f26 --- /dev/null +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java @@ -0,0 +1,42 @@ +package com.youlai.boot.system.model.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 阅读通知公告VO + * + * @author Theo + * @since 2024-9-8 01:25:06 + */ +@Data +public class NoticeDetailVO { + + @Schema(description = "通知ID") + private Long id; + + @Schema(description = "通知标题") + private String title; + + @Schema(description = "通知内容") + private String content; + + @Schema(description = "通知类型") + private String noticeTypeLabel; + + @Schema(description = "发布人") + private String releaseBy; + + @Schema(description = "优先级(0-低 1-中 2-高)") + private Integer priority; + + @Schema(description = "发布状态(0-未发布 1已发布 2已撤回) 冗余字段,方便判断是否已经发布") + private Integer releaseStatus; + + @Schema(description = "发布时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime releaseTime; +} diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java index a1d0c6e9..320e99fc 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java @@ -14,9 +14,12 @@ import lombok.Data; public class NoticeStatusVO { @Schema(description = "公告ID") - private Long noticeId; + private Long id; + + @Schema(description = "公告标题") + private String title; @Schema(description = "是否已读") - private Boolean read; + private Integer readStatus; } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java index 12269e3e..f0d86ffb 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java @@ -24,6 +24,7 @@ public class NoticeVO implements Serializable { private static final long serialVersionUID = 1L; private Long id; + @Schema(description = "通知标题") private String title; diff --git a/src/main/java/com/youlai/boot/system/service/NoticeService.java b/src/main/java/com/youlai/boot/system/service/NoticeService.java index 4d7c6381..1613796b 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeService.java @@ -6,6 +6,7 @@ import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeVO; +import com.youlai.boot.system.model.vo.NoticeDetailVO; /** * 通知公告服务类 @@ -70,4 +71,19 @@ public interface NoticeService extends IService { * @return 是否撤回成功 */ boolean recallNotice(Long id); + + /** + * 阅读通知公告 + * + * @param id 通知公告ID + * @return 通知公告对象 + */ + NoticeDetailVO readNotice(Long id); + + /** + * 获取阅读时通知公告详情 + * @param id 通知公告ID + * @return 通知公告详情 + */ + NoticeDetailVO getReadNoticeDetail(Long id); } diff --git a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java index 332a1818..e767712b 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java @@ -1,7 +1,6 @@ package com.youlai.boot.system.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.youlai.boot.common.result.Result; import com.youlai.boot.system.model.entity.NoticeStatus; import com.youlai.boot.system.model.vo.NoticeStatusVO; @@ -15,5 +14,15 @@ import java.util.List; */ public interface NoticeStatusService extends IService { - List listNotices(Integer count); + /** + * 获取未读的通知公告 + * @return 公告列表 + */ + List listUnreadNotices(); + + /** + * 全部标记为已读 + * @return 是否成功 + */ + boolean readAll(); } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index 471d13b7..7cd6ad48 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -21,6 +21,7 @@ import com.youlai.boot.system.model.entity.User; import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeVO; +import com.youlai.boot.system.model.vo.NoticeDetailVO; import com.youlai.boot.system.service.NoticeService; import com.youlai.boot.system.service.NoticeStatusService; import com.youlai.boot.system.service.UserService; @@ -225,4 +226,41 @@ public class NoticeServiceImpl extends ServiceImpl impleme return true; } + /** + * 阅读通知公告 + * @param id 通知公告ID + * @return 通知公告表单对象 + */ + @Override + public NoticeDetailVO readNotice(Long id) { + NoticeDetailVO noticeDetailVO = this.getReadNoticeDetail(id); + Assert.isTrue(noticeDetailVO != null && noticeDetailVO.getReleaseStatus() == 1, "公告不存在或未发布"); + //获取当前登录用户 + Long userId = SecurityUtils.getUserId(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(NoticeStatus::getUserId, userId) + .eq(NoticeStatus::getNoticeId, id) + .eq(NoticeStatus::getReadStatus, 0); + NoticeStatus noticeStatus = noticeStatusService.getOne(queryWrapper); + if (noticeStatus != null) { + noticeStatus.setReadStatus(1); + noticeStatusService.updateById(noticeStatus); + } + return noticeDetailVO; + } + + /** + * 获取阅读时通知公告详情 + * @param id 通知公告ID + * @return + */ + @Override + public NoticeDetailVO getReadNoticeDetail(Long id) { + Assert.notNull(id, "公告ID不能为空"); + NoticeDetailVO noticeDetailVO = this.baseMapper.getReadNoticeVO(id); + Assert.isTrue(noticeDetailVO != null, "公告不存在"); + return noticeDetailVO; + } + + } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java index 0fc725e5..6e220c01 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java @@ -1,12 +1,11 @@ package com.youlai.boot.system.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.youlai.boot.common.result.Result; +import com.youlai.boot.core.security.util.SecurityUtils; import com.youlai.boot.system.mapper.NoticeStatusMapper; import com.youlai.boot.system.model.entity.NoticeStatus; import com.youlai.boot.system.model.vo.NoticeStatusVO; -import com.youlai.boot.system.service.NoticeService; import com.youlai.boot.system.service.NoticeStatusService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,13 +22,31 @@ import java.util.List; @RequiredArgsConstructor public class NoticeStatusServiceImpl extends ServiceImpl implements NoticeStatusService { - private final NoticeService noticeService; + private final NoticeStatusMapper noticeStatusMapper; + /** + * 获取未读的通知公告 + * @return 公告列表 + */ @Override - public List listNotices(Integer count) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - //获取当前用户 - queryWrapper.eq(NoticeStatus::getUserId, 1L); - return null; + public List listUnreadNotices() { + //获取当前登录用户 + Long userId = SecurityUtils.getUserId(); + return noticeStatusMapper.listUnreadNotices(userId); } + + /** + * 全部标记为已读 + * @return 是否成功 + */ + @Override + public boolean readAll() { + Long userId = SecurityUtils.getUserId(); + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(NoticeStatus::getUserId, userId); + updateWrapper.set(NoticeStatus::getReadStatus, 1); + return this.update(updateWrapper); + } + + } diff --git a/src/main/resources/mapper/NoticeMapper.xml b/src/main/resources/mapper/NoticeMapper.xml index 08fec56f..74969f36 100644 --- a/src/main/resources/mapper/NoticeMapper.xml +++ b/src/main/resources/mapper/NoticeMapper.xml @@ -41,4 +41,25 @@ DESC + + diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml index 506c53d7..0704802d 100644 --- a/src/main/resources/mapper/NoticeStatusMapper.xml +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -2,4 +2,22 @@ + + From 9c765bda2460f3fcbc2e97591bc45dfd64a3d34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Thu, 12 Sep 2024 18:08:02 +0800 Subject: [PATCH 12/15] =?UTF-8?q?feat:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告临时提交 --- .../system/controller/DictController.java | 3 ++- .../system/controller/NoticeController.java | 7 ++++++ .../system/mapper/NoticeStatusMapper.java | 12 ++++++++++ .../boot/system/model/query/NoticeQuery.java | 3 +++ .../boot/system/model/vo/NoticeStatusVO.java | 20 +++++++++++++++-- .../boot/system/service/NoticeService.java | 7 ++++++ .../system/service/NoticeStatusService.java | 12 ++++++++++ .../service/impl/NoticeServiceImpl.java | 12 ++++++++++ .../service/impl/NoticeStatusServiceImpl.java | 15 +++++++++++++ .../system/service/impl/UserServiceImpl.java | 2 -- .../resources/mapper/NoticeStatusMapper.xml | 22 +++++++++++++++++++ 11 files changed, 110 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/youlai/boot/system/controller/DictController.java b/src/main/java/com/youlai/boot/system/controller/DictController.java index 1d79d993..71d2e6c0 100644 --- a/src/main/java/com/youlai/boot/system/controller/DictController.java +++ b/src/main/java/com/youlai/boot/system/controller/DictController.java @@ -14,6 +14,7 @@ import com.youlai.boot.system.service.DictService; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -73,7 +74,7 @@ public class DictController { @PostMapping @PreAuthorize("@ss.hasPerm('sys:dict:add')") @RepeatSubmit - public Result saveDict(@RequestBody DictForm formData) { + public Result saveDict(@Valid @RequestBody DictForm formData) { boolean result = dictService.saveDict(formData); return Result.judge(result); } diff --git a/src/main/java/com/youlai/boot/system/controller/NoticeController.java b/src/main/java/com/youlai/boot/system/controller/NoticeController.java index 263ac43f..78bb8f53 100644 --- a/src/main/java/com/youlai/boot/system/controller/NoticeController.java +++ b/src/main/java/com/youlai/boot/system/controller/NoticeController.java @@ -120,4 +120,11 @@ public class NoticeController { noticeStatusService.readAll(); return Result.success(); } + + @Operation(summary = "获取我的通知公告") + @GetMapping("/my/page") + public PageResult getMyNoticePage(NoticeQuery queryParams) { + IPage result = noticeService.getMyNoticePage(queryParams); + return PageResult.success(result); + } } diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java index 4858c8e9..779fa830 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java @@ -1,8 +1,12 @@ package com.youlai.boot.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeStatusVO; +import com.youlai.boot.system.model.vo.NoticeVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -23,4 +27,12 @@ public interface NoticeStatusMapper extends BaseMapper { * @return 公告列表 */ List listUnreadNotices(@Param("userId")Long userId); + + /** + * 分页获取我的通知公告 + * @param page 分页对象 + * @param queryParams 查询参数 + * @return 通知公告分页列表 + */ + IPage getMyNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java b/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java index b2df83a2..f58a9f6e 100644 --- a/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java +++ b/src/main/java/com/youlai/boot/system/model/query/NoticeQuery.java @@ -28,4 +28,7 @@ public class NoticeQuery extends BasePageQuery { @Schema(description = "发布时间") private List releaseTime; + + @Schema(description = "查询人ID") + private Long userId; } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java index 320e99fc..7fc953e1 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java @@ -1,8 +1,11 @@ package com.youlai.boot.system.model.vo; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.time.LocalDateTime; + /** * 用户公告状态VO * @@ -13,12 +16,25 @@ import lombok.Data; @Schema(description = "用户公告状态VO") public class NoticeStatusVO { - @Schema(description = "公告ID") + @Schema(description = "通知ID") private Long id; - @Schema(description = "公告标题") + @Schema(description = "通知标题") private String title; + @Schema(description = "通知类型") + private String noticeTypeLabel; + + @Schema(description = "发布人") + private String releaseBy; + + @Schema(description = "优先级(0-低 1-中 2-高)") + private Integer priority; + + @Schema(description = "发布时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime releaseTime; + @Schema(description = "是否已读") private Integer readStatus; diff --git a/src/main/java/com/youlai/boot/system/service/NoticeService.java b/src/main/java/com/youlai/boot/system/service/NoticeService.java index 1613796b..66e31f32 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeService.java @@ -86,4 +86,11 @@ public interface NoticeService extends IService { * @return 通知公告详情 */ NoticeDetailVO getReadNoticeDetail(Long id); + + /** + * 获取我的通知公告分页列表 + * @param queryParams 查询参数 + * @return 通知公告分页列表 + */ + IPage getMyNoticePage(NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java index e767712b..5cd748c6 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java @@ -1,8 +1,12 @@ package com.youlai.boot.system.service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeStatusVO; +import com.youlai.boot.system.model.vo.NoticeVO; import java.util.List; @@ -25,4 +29,12 @@ public interface NoticeStatusService extends IService { * @return 是否成功 */ boolean readAll(); + + /** + * 分页获取我的通知公告 + * @param page 分页对象 + * @param queryParams 查询参数 + * @return 通知公告分页列表 + */ + IPage getMyNoticePage(Page page, NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index 7cd6ad48..cde91ba8 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -20,6 +20,7 @@ import com.youlai.boot.system.model.entity.NoticeStatus; import com.youlai.boot.system.model.entity.User; import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeStatusVO; import com.youlai.boot.system.model.vo.NoticeVO; import com.youlai.boot.system.model.vo.NoticeDetailVO; import com.youlai.boot.system.service.NoticeService; @@ -262,5 +263,16 @@ public class NoticeServiceImpl extends ServiceImpl impleme return noticeDetailVO; } + /** + * 获取当前登录用户的通知公告列表 + * @param queryParams 查询参数 + * @return 通知公告分页列表 + */ + @Override + public IPage getMyNoticePage(NoticeQuery queryParams) { + Long userId = SecurityUtils.getUserId(); + queryParams.setUserId(userId); + return noticeStatusService.getMyNoticePage(new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),queryParams); + } } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java index 6e220c01..fd54e3e1 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java @@ -1,11 +1,15 @@ package com.youlai.boot.system.service.impl; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.boot.core.security.util.SecurityUtils; import com.youlai.boot.system.mapper.NoticeStatusMapper; import com.youlai.boot.system.model.entity.NoticeStatus; +import com.youlai.boot.system.model.query.NoticeQuery; import com.youlai.boot.system.model.vo.NoticeStatusVO; +import com.youlai.boot.system.model.vo.NoticeVO; import com.youlai.boot.system.service.NoticeStatusService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -48,5 +52,16 @@ public class NoticeStatusServiceImpl extends ServiceImpl getMyNoticePage(Page page, NoticeQuery queryParams) { + return this.getBaseMapper().getMyNoticePage(new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),queryParams); + } + } diff --git a/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java index f0749cf9..a1f7b8f1 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/UserServiceImpl.java @@ -12,8 +12,6 @@ import com.youlai.boot.common.constant.RedisConstants; import com.youlai.boot.common.constant.SystemConstants; import com.youlai.boot.common.enums.ContactType; import com.youlai.boot.common.model.Option; -import com.youlai.boot.platform.mail.service.MailService; -import com.youlai.boot.platform.sms.service.SmsService; import com.youlai.boot.module.mail.service.MailService; import com.youlai.boot.module.sms.service.SmsService; import com.youlai.boot.system.model.entity.User; diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml index 0704802d..d08025ee 100644 --- a/src/main/resources/mapper/NoticeStatusMapper.xml +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -20,4 +20,26 @@ sn.release_time DESC + From a7131263c6e10207b233a53fb6bdb0caebe2fc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Sat, 14 Sep 2024 11:14:23 +0800 Subject: [PATCH 13/15] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=85=AC=E5=91=8A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增通知公告功能 --- sql/mysql5/youlai_boot.sql | 33 ++++++++++++++++++- sql/mysql8/youlai_boot.sql | 31 +++++++++++++++++ .../websocket/service/MessageService.java | 2 +- .../WebsocketServiceImpl.java} | 3 +- .../boot/system/handler/MessageHandler.java | 2 +- src/main/resources/mapper/NoticeMapper.xml | 2 -- .../resources/mapper/NoticeStatusMapper.xml | 3 ++ 7 files changed, 69 insertions(+), 7 deletions(-) rename src/main/java/com/youlai/boot/module/websocket/service/{OnlineUserService.java => impl/WebsocketServiceImpl.java} (95%) diff --git a/sql/mysql5/youlai_boot.sql b/sql/mysql5/youlai_boot.sql index b9e1aaab..35ffe067 100644 --- a/sql/mysql5/youlai_boot.sql +++ b/sql/mysql5/youlai_boot.sql @@ -85,7 +85,8 @@ CREATE TABLE `sys_dict` ( -- ---------------------------- -- Records of sys_dict -- ---------------------------- -INSERT INTO `sys_dict` VALUES (1, '性别', 'gender', 1, NULL, '2019-12-06 19:03:32', '2024-06-22 21:14:47', 0); +INSERT INTO `sys_dict` VALUES (1,'性别','gender',1,NULL,'2019-12-06 19:03:32','2024-06-22 21:14:47',0); +INSERT INTO `sys_dict` VALUES (2,'通知类型','notice_type',1,NULL,'2024-09-01 17:23:48','2024-09-01 17:23:54',0); -- ---------------------------- -- Table structure for sys_dict_item @@ -110,6 +111,8 @@ CREATE TABLE `sys_dict_item` ( INSERT INTO `sys_dict_item` VALUES (1, 1, '男', '1', 1, 1, NULL, '2019-05-05 13:07:52', '2022-06-12 23:20:39'); INSERT INTO `sys_dict_item` VALUES (2, 1, '女', '2', 1, 2, NULL, '2019-04-19 11:33:00', '2019-07-02 14:23:05'); INSERT INTO `sys_dict_item` VALUES (3, 1, '保密', '0', 1, 3, NULL, '2020-10-17 08:09:31', '2020-10-17 08:09:31'); +INSERT INTO `sys_dict_item` VALUES (4, 2,'系统通知','1',1, 1, NULL,'2020-10-17 08:09:31', '2020-10-17 08:09:31'); +INSERT INTO `sys_dict_item` VALUES (5, 2,'通知消息','2',1, 2, NULL,'2020-10-17 08:09:31', '2020-10-17 08:09:31'); -- ---------------------------- -- Table structure for sys_log @@ -478,5 +481,33 @@ CREATE TABLE `gen_field_config` ( KEY `config_id` (`config_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='代码生成字段配置表'; +CREATE TABLE `sys_notice` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `title` VARCHAR(50) DEFAULT NULL COMMENT '通知标题', + `content` TEXT COMMENT '通知内容', + `notice_type` INT NOT NULL COMMENT '通知类型', + `release_by` BIGINT DEFAULT NULL COMMENT '发布人', + `priority` TINYINT NOT NULL COMMENT '优先级(0-低 1-中 2-高)', + `tar_type` TINYINT NOT NULL COMMENT '目标类型(0-全体 1-指定)', + `tar_ids` TEXT COMMENT '目标人id', + `release_status` TINYINT NOT NULL COMMENT '发布状态(0-未发布 1已发布 2已撤回)', + `release_time` DATETIME DEFAULT NULL COMMENT '发布时间', + `recall_time` DATETIME DEFAULT NULL COMMENT '撤回时间', + `create_by` BIGINT NOT NULL COMMENT '创建人ID', + `create_time` DATETIME NOT NULL COMMENT '创建时间', + `update_by` BIGINT DEFAULT NULL COMMENT '更新人ID', + `update_time` DATETIME DEFAULT NULL COMMENT '更新时间', + `is_deleted` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除标识(0-未删除 1-已删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB COMMENT='通知公告'; + +CREATE TABLE `sys_notice_status` ( + `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id', + `notice_id` BIGINT NOT NULL COMMENT '公共通知id', + `user_id` INT NOT NULL COMMENT '用户id', + `read_status` BIGINT DEFAULT NULL COMMENT '读取状态,0未读,1已读取', + `read_time` DATETIME DEFAULT NULL COMMENT '用户阅读时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB COMMENT='用户公告状态表'; SET FOREIGN_KEY_CHECKS = 1; diff --git a/sql/mysql8/youlai_boot.sql b/sql/mysql8/youlai_boot.sql index 2cfdc939..192fa6dc 100644 --- a/sql/mysql8/youlai_boot.sql +++ b/sql/mysql8/youlai_boot.sql @@ -87,6 +87,7 @@ CREATE TABLE `sys_dict` ( -- Records of sys_dict -- ---------------------------- INSERT INTO `sys_dict` VALUES (1, '性别', 'gender', 1, NULL, '2019-12-06 19:03:32', '2024-06-22 21:14:47', 0); +INSERT INTO `sys_dict` VALUES (2,'通知类型','notice_type',1,NULL,'2024-09-01 17:23:48','2024-09-01 17:23:54',0); -- ---------------------------- -- Table structure for sys_dict_item @@ -111,6 +112,8 @@ CREATE TABLE `sys_dict_item` ( INSERT INTO `sys_dict_item` VALUES (1, 1, '男', '1', 1, 1, NULL, '2019-05-05 13:07:52', '2022-06-12 23:20:39'); INSERT INTO `sys_dict_item` VALUES (2, 1, '女', '2', 1, 2, NULL, '2019-04-19 11:33:00', '2019-07-02 14:23:05'); INSERT INTO `sys_dict_item` VALUES (3, 1, '保密', '0', 1, 3, NULL, '2020-10-17 08:09:31', '2020-10-17 08:09:31'); +INSERT INTO `sys_dict_item` VALUES (4, 2,'系统通知','1',1, 1, NULL,'2020-10-17 08:09:31', '2020-10-17 08:09:31'); +INSERT INTO `sys_dict_item` VALUES (5, 2,'通知消息','2',1, 2, NULL,'2020-10-17 08:09:31', '2020-10-17 08:09:31'); -- ---------------------------- -- Table structure for sys_log @@ -466,5 +469,33 @@ CREATE TABLE `gen_field_config` ( KEY `config_id` (`config_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='代码生成字段配置表'; +CREATE TABLE `sys_notice` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `title` VARCHAR(50) DEFAULT NULL COMMENT '通知标题', + `content` TEXT COMMENT '通知内容', + `notice_type` INT NOT NULL COMMENT '通知类型', + `release_by` BIGINT DEFAULT NULL COMMENT '发布人', + `priority` TINYINT NOT NULL COMMENT '优先级(0-低 1-中 2-高)', + `tar_type` TINYINT NOT NULL COMMENT '目标类型(0-全体 1-指定)', + `tar_ids` TEXT COMMENT '目标人id', + `release_status` TINYINT NOT NULL COMMENT '发布状态(0-未发布 1已发布 2已撤回)', + `release_time` DATETIME DEFAULT NULL COMMENT '发布时间', + `recall_time` DATETIME DEFAULT NULL COMMENT '撤回时间', + `create_by` BIGINT NOT NULL COMMENT '创建人ID', + `create_time` DATETIME NOT NULL COMMENT '创建时间', + `update_by` BIGINT DEFAULT NULL COMMENT '更新人ID', + `update_time` DATETIME DEFAULT NULL COMMENT '更新时间', + `is_deleted` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除标识(0-未删除 1-已删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB COMMENT='通知公告'; + +CREATE TABLE `sys_notice_status` ( + `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id', + `notice_id` BIGINT NOT NULL COMMENT '公共通知id', + `user_id` INT NOT NULL COMMENT '用户id', + `read_status` BIGINT DEFAULT NULL COMMENT '读取状态,0未读,1已读取', + `read_time` DATETIME DEFAULT NULL COMMENT '用户阅读时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB COMMENT='用户公告状态表'; SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/java/com/youlai/boot/module/websocket/service/MessageService.java b/src/main/java/com/youlai/boot/module/websocket/service/MessageService.java index 084d6825..040990b7 100644 --- a/src/main/java/com/youlai/boot/module/websocket/service/MessageService.java +++ b/src/main/java/com/youlai/boot/module/websocket/service/MessageService.java @@ -1,4 +1,4 @@ -package com.youlai.boot.platform.websocket.service; +package com.youlai.boot.module.websocket.service; import com.youlai.boot.common.enums.NoticeWayEnum; import com.youlai.boot.system.model.dto.MessageDTO; diff --git a/src/main/java/com/youlai/boot/module/websocket/service/OnlineUserService.java b/src/main/java/com/youlai/boot/module/websocket/service/impl/WebsocketServiceImpl.java similarity index 95% rename from src/main/java/com/youlai/boot/module/websocket/service/OnlineUserService.java rename to src/main/java/com/youlai/boot/module/websocket/service/impl/WebsocketServiceImpl.java index 5b98e4b6..aab4fd50 100644 --- a/src/main/java/com/youlai/boot/module/websocket/service/OnlineUserService.java +++ b/src/main/java/com/youlai/boot/module/websocket/service/impl/WebsocketServiceImpl.java @@ -2,7 +2,7 @@ package com.youlai.boot.module.websocket.service.impl; import com.youlai.boot.common.enums.NoticeWayEnum; import com.youlai.boot.common.enums.NoticeTypeEnum; -import com.youlai.boot.platform.websocket.service.MessageService; +import com.youlai.boot.module.websocket.service.MessageService; import com.youlai.boot.system.event.UserConnectionEvent; import com.youlai.boot.system.model.dto.ChatMessage; import com.youlai.boot.system.model.dto.MessageDTO; @@ -58,7 +58,6 @@ public class WebsocketServiceImpl implements MessageService { */ @Scheduled(fixedRate = 5000) public void sendOnlineUserCount() { - log.info("Send online user count: {}", onlineUsers.size()); messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size()); } diff --git a/src/main/java/com/youlai/boot/system/handler/MessageHandler.java b/src/main/java/com/youlai/boot/system/handler/MessageHandler.java index 21ae2421..689a3816 100644 --- a/src/main/java/com/youlai/boot/system/handler/MessageHandler.java +++ b/src/main/java/com/youlai/boot/system/handler/MessageHandler.java @@ -1,6 +1,6 @@ package com.youlai.boot.system.handler; -import com.youlai.boot.platform.websocket.service.MessageService; +import com.youlai.boot.module.websocket.service.MessageService; import com.youlai.boot.system.model.dto.MessageDTO; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/src/main/resources/mapper/NoticeMapper.xml b/src/main/resources/mapper/NoticeMapper.xml index 74969f36..ef23eaee 100644 --- a/src/main/resources/mapper/NoticeMapper.xml +++ b/src/main/resources/mapper/NoticeMapper.xml @@ -58,8 +58,6 @@ where sn.is_deleted = 0 AND sn.id = #{id} - AND sn.release_status = 1 - diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml index d08025ee..2a2dd71d 100644 --- a/src/main/resources/mapper/NoticeStatusMapper.xml +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -38,6 +38,9 @@ sns.user_id = #{queryParams.userId} + + AND sn.title LIKE CONCAT('%',#{queryParams.title},'%') + ORDER BY sn.release_time DESC From 021ab693e160e4aa6c6a7c5023f0477315d93321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Sat, 14 Sep 2024 11:27:24 +0800 Subject: [PATCH 14/15] =?UTF-8?q?docs:=20SQL=E8=84=9A=E6=9C=AC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SQL脚本更新 --- sql/mysql5/youlai_boot.sql | 30 ++++++++++++++++++++++++++++++ sql/mysql8/youlai_boot.sql | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/sql/mysql5/youlai_boot.sql b/sql/mysql5/youlai_boot.sql index 35ffe067..0d542dcb 100644 --- a/sql/mysql5/youlai_boot.sql +++ b/sql/mysql5/youlai_boot.sql @@ -233,6 +233,21 @@ INSERT INTO `sys_menu` VALUES (118, 0, '0', '系统工具', 2, NULL, '/codegen', INSERT INTO `sys_menu` VALUES (119, 118, '0,118', '代码生成', 1, 'Codegen', 'codegen', 'codegen/index', NULL, 0, 1, 1, 1, 'code', NULL, '2024-07-13 08:44:51', '2024-07-13 08:44:51', NULL); INSERT INTO `sys_menu` VALUES (118, 0, '0', '系统工具', 2, NULL, '/codegen', 'Layout', NULL, 0, 1, 1, 2, 'menu', NULL, '2024-07-13 08:41:07', '2024-07-13 08:41:07', NULL); INSERT INTO `sys_menu` VALUES (119, 118, '0,118', '代码生成', 1, 'Codegen', 'codegen', 'codegen/index', NULL, 0, 1, 1, 1, 'code', NULL, '2024-07-13 08:44:51', '2024-07-13 08:44:51', NULL); +INSERT INTO `sys_menu` VALUES (120,1,'0,1','系统配置',1,'Config','config','system/config/index',NULL,0,1,1,7,'setting',NULL,'2024-07-30 16:29:24','2024-07-30 16:29:32',NULL); +INSERT INTO `sys_menu` VALUES (121,120,'0,1,120','查询系统配置',4,NULL,'',NULL,'sys:config:query',0,1,1,1,'',NULL,'2024-07-30 16:29:54','2024-07-30 16:29:54',NULL); +INSERT INTO `sys_menu` VALUES (122,120,'0,1,120','新增系统配置',4,NULL,'',NULL,'sys:config:add',0,1,1,2,'',NULL,'2024-07-30 16:30:12','2024-07-30 16:30:48',NULL); +INSERT INTO `sys_menu` VALUES (123,120,'0,1,120','修改系统配置',4,NULL,'',NULL,'sys:config:update',0,1,1,3,'',NULL,'2024-07-30 16:30:31','2024-07-30 16:30:31',NULL); +INSERT INTO `sys_menu` VALUES (124,120,'0,1,120','删除系统配置',4,NULL,'',NULL,'sys:config:delete',0,1,1,4,'',NULL,'2024-07-30 16:31:07','2024-07-30 16:31:07',NULL); +INSERT INTO `sys_menu` VALUES (125,120,'0,1,120','刷新系统配置',4,NULL,'',NULL,'sys:config:refresh',0,1,1,5,'',NULL,'2024-07-30 16:31:25','2024-07-30 16:31:25',NULL); +INSERT INTO `sys_menu` VALUES (126,1,'0,1','通知公告',1,'Notice','notice','system/notice/index',NULL,NULL,NULL,1,9,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (127,126,'0,1,132','查询',4,NULL,'',NULL,'system:notice:query',NULL,NULL,1,1,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (128,126,'0,1,133','新增',4,NULL,'',NULL,'system:notice:add',NULL,NULL,1,2,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (129,126,'0,1,134','编辑',4,NULL,'',NULL,'system:notice:edit',NULL,NULL,1,3,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (130,126,'0,1,135','删除',4,NULL,'',NULL,'system:notice:delete',NULL,NULL,1,4,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (131,0,'0','消息中心',2,NULL,'/notice','Layout',NULL,1,1,1,13,'el-icon-Message',NULL,'2024-08-31 21:16:06','2024-08-31 21:16:41',NULL); +INSERT INTO `sys_menu` VALUES (132,131,'0,136','我的消息',1,'MyNotice','notice','notice/index',NULL,0,1,1,1,'',NULL,'2024-08-31 21:17:36','2024-09-12 11:28:42',NULL); +INSERT INTO `sys_menu` VALUES (133,132,'0,1,131','发布',4,NULL,'',NULL,'system:notice:release',0,1,1,5,'',NULL,'2024-09-01 23:53:52','2024-09-01 23:53:52',NULL); +INSERT INTO `sys_menu` VALUES (134,132,'0,1,131','撤回',4,NULL,'',NULL,'system:notice:recall',0,1,1,6,'',NULL,'2024-09-01 23:54:16','2024-09-01 23:54:16',NULL); -- ---------------------------- -- Table structure for sys_message @@ -360,6 +375,21 @@ INSERT INTO `sys_role_menu` VALUES (2, 116); INSERT INTO `sys_role_menu` VALUES (2, 117); INSERT INTO `sys_role_menu` VALUES (2, 118); INSERT INTO `sys_role_menu` VALUES (2, 119); +INSERT INTO `sys_role_menu` VALUES (2, 120); +INSERT INTO `sys_role_menu` VALUES (2, 121); +INSERT INTO `sys_role_menu` VALUES (2, 122); +INSERT INTO `sys_role_menu` VALUES (2, 123); +INSERT INTO `sys_role_menu` VALUES (2, 124); +INSERT INTO `sys_role_menu` VALUES (2, 125); +INSERT INTO `sys_role_menu` VALUES (2, 126); +INSERT INTO `sys_role_menu` VALUES (2, 127); +INSERT INTO `sys_role_menu` VALUES (2, 128); +INSERT INTO `sys_role_menu` VALUES (2, 129); +INSERT INTO `sys_role_menu` VALUES (2, 130); +INSERT INTO `sys_role_menu` VALUES (2, 131); +INSERT INTO `sys_role_menu` VALUES (2, 132); +INSERT INTO `sys_role_menu` VALUES (2, 133); +INSERT INTO `sys_role_menu` VALUES (2, 134); -- ---------------------------- -- Table structure for sys_user -- ---------------------------- diff --git a/sql/mysql8/youlai_boot.sql b/sql/mysql8/youlai_boot.sql index 192fa6dc..370ff92f 100644 --- a/sql/mysql8/youlai_boot.sql +++ b/sql/mysql8/youlai_boot.sql @@ -221,6 +221,21 @@ INSERT INTO `sys_menu` VALUES (112, 110, '0,110', '参数(type=2)', 1, NULL, 'ro INSERT INTO `sys_menu` VALUES (117, 1, '0,1', '系统日志', 1, 'Log', 'log', 'system/log/index', NULL, 0, 1, 1, 6, 'document', NULL, '2024-06-28 07:43:16', '2024-06-28 07:43:16', NULL); INSERT INTO `sys_menu` VALUES (118, 0, '0', '系统工具', 2, NULL, '/codegen', 'Layout', NULL, 0, 1, 1, 2, 'menu', NULL, '2024-07-13 08:41:07', '2024-07-13 08:41:07', NULL); INSERT INTO `sys_menu` VALUES (119, 118, '0,118', '代码生成', 1, 'Codegen', 'codegen', 'codegen/index', NULL, 0, 1, 1, 1, 'code', NULL, '2024-07-13 08:44:51', '2024-07-13 08:44:51', NULL); +INSERT INTO `sys_menu` VALUES (120,1,'0,1','系统配置',1,'Config','config','system/config/index',NULL,0,1,1,7,'setting',NULL,'2024-07-30 16:29:24','2024-07-30 16:29:32',NULL); +INSERT INTO `sys_menu` VALUES (121,120,'0,1,120','查询系统配置',4,NULL,'',NULL,'sys:config:query',0,1,1,1,'',NULL,'2024-07-30 16:29:54','2024-07-30 16:29:54',NULL); +INSERT INTO `sys_menu` VALUES (122,120,'0,1,120','新增系统配置',4,NULL,'',NULL,'sys:config:add',0,1,1,2,'',NULL,'2024-07-30 16:30:12','2024-07-30 16:30:48',NULL); +INSERT INTO `sys_menu` VALUES (123,120,'0,1,120','修改系统配置',4,NULL,'',NULL,'sys:config:update',0,1,1,3,'',NULL,'2024-07-30 16:30:31','2024-07-30 16:30:31',NULL); +INSERT INTO `sys_menu` VALUES (124,120,'0,1,120','删除系统配置',4,NULL,'',NULL,'sys:config:delete',0,1,1,4,'',NULL,'2024-07-30 16:31:07','2024-07-30 16:31:07',NULL); +INSERT INTO `sys_menu` VALUES (125,120,'0,1,120','刷新系统配置',4,NULL,'',NULL,'sys:config:refresh',0,1,1,5,'',NULL,'2024-07-30 16:31:25','2024-07-30 16:31:25',NULL); +INSERT INTO `sys_menu` VALUES (126,1,'0,1','通知公告',1,'Notice','notice','system/notice/index',NULL,NULL,NULL,1,9,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (127,126,'0,1,132','查询',4,NULL,'',NULL,'system:notice:query',NULL,NULL,1,1,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (128,126,'0,1,133','新增',4,NULL,'',NULL,'system:notice:add',NULL,NULL,1,2,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (129,126,'0,1,134','编辑',4,NULL,'',NULL,'system:notice:edit',NULL,NULL,1,3,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (130,126,'0,1,135','删除',4,NULL,'',NULL,'system:notice:delete',NULL,NULL,1,4,'',NULL,'2024-08-24 13:39:03','2024-08-24 13:39:03',NULL); +INSERT INTO `sys_menu` VALUES (131,0,'0','消息中心',2,NULL,'/notice','Layout',NULL,1,1,1,13,'el-icon-Message',NULL,'2024-08-31 21:16:06','2024-08-31 21:16:41',NULL); +INSERT INTO `sys_menu` VALUES (132,131,'0,136','我的消息',1,'MyNotice','notice','notice/index',NULL,0,1,1,1,'',NULL,'2024-08-31 21:17:36','2024-09-12 11:28:42',NULL); +INSERT INTO `sys_menu` VALUES (133,132,'0,1,131','发布',4,NULL,'',NULL,'system:notice:release',0,1,1,5,'',NULL,'2024-09-01 23:53:52','2024-09-01 23:53:52',NULL); +INSERT INTO `sys_menu` VALUES (134,132,'0,1,131','撤回',4,NULL,'',NULL,'system:notice:recall',0,1,1,6,'',NULL,'2024-09-01 23:54:16','2024-09-01 23:54:16',NULL); -- ---------------------------- -- Table structure for sys_message @@ -348,6 +363,21 @@ INSERT INTO `sys_role_menu` VALUES (2, 116); INSERT INTO `sys_role_menu` VALUES (2, 117); INSERT INTO `sys_role_menu` VALUES (2, 118); INSERT INTO `sys_role_menu` VALUES (2, 119); +INSERT INTO `sys_role_menu` VALUES (2, 120); +INSERT INTO `sys_role_menu` VALUES (2, 121); +INSERT INTO `sys_role_menu` VALUES (2, 122); +INSERT INTO `sys_role_menu` VALUES (2, 123); +INSERT INTO `sys_role_menu` VALUES (2, 124); +INSERT INTO `sys_role_menu` VALUES (2, 125); +INSERT INTO `sys_role_menu` VALUES (2, 126); +INSERT INTO `sys_role_menu` VALUES (2, 127); +INSERT INTO `sys_role_menu` VALUES (2, 128); +INSERT INTO `sys_role_menu` VALUES (2, 129); +INSERT INTO `sys_role_menu` VALUES (2, 130); +INSERT INTO `sys_role_menu` VALUES (2, 131); +INSERT INTO `sys_role_menu` VALUES (2, 132); +INSERT INTO `sys_role_menu` VALUES (2, 133); +INSERT INTO `sys_role_menu` VALUES (2, 134); -- ---------------------------- -- Table structure for sys_user -- ---------------------------- From 0691b9311259069f3be074193ba02eeee3655314 Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Sat, 21 Sep 2024 21:43:20 +0800 Subject: [PATCH 15/15] =?UTF-8?q?refactor:=20=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通知公告的优化 --- .../com/youlai/boot/system/controller/NoticeController.java | 5 +++-- .../com/youlai/boot/system/mapper/NoticeStatusMapper.java | 2 +- .../java/com/youlai/boot/system/model/vo/NoticeDetailVO.java | 2 +- .../java/com/youlai/boot/system/model/vo/NoticeStatusVO.java | 2 +- src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java | 2 +- .../java/com/youlai/boot/system/service/NoticeService.java | 3 ++- .../com/youlai/boot/system/service/NoticeStatusService.java | 4 ++-- .../youlai/boot/system/service/impl/NoticeServiceImpl.java | 2 +- .../boot/system/service/impl/NoticeStatusServiceImpl.java | 2 +- src/main/resources/mapper/NoticeStatusMapper.xml | 3 ++- 10 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/youlai/boot/system/controller/NoticeController.java b/src/main/java/com/youlai/boot/system/controller/NoticeController.java index 78bb8f53..3e2ac049 100644 --- a/src/main/java/com/youlai/boot/system/controller/NoticeController.java +++ b/src/main/java/com/youlai/boot/system/controller/NoticeController.java @@ -5,6 +5,7 @@ import com.youlai.boot.common.result.PageResult; import com.youlai.boot.common.result.Result; import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeStatusVO; import com.youlai.boot.system.model.vo.NoticeVO; import com.youlai.boot.system.service.NoticeService; import com.youlai.boot.system.service.NoticeStatusService; @@ -123,8 +124,8 @@ public class NoticeController { @Operation(summary = "获取我的通知公告") @GetMapping("/my/page") - public PageResult getMyNoticePage(NoticeQuery queryParams) { - IPage result = noticeService.getMyNoticePage(queryParams); + public PageResult getMyNoticePage(NoticeQuery queryParams) { + IPage result = noticeService.getMyNoticePage(queryParams); return PageResult.success(result); } } diff --git a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java index 779fa830..7de27f85 100644 --- a/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java +++ b/src/main/java/com/youlai/boot/system/mapper/NoticeStatusMapper.java @@ -34,5 +34,5 @@ public interface NoticeStatusMapper extends BaseMapper { * @param queryParams 查询参数 * @return 通知公告分页列表 */ - IPage getMyNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); + IPage getMyNoticePage(Page page, @Param("queryParams") NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java index 27bb9f26..8070fdea 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeDetailVO.java @@ -25,7 +25,7 @@ public class NoticeDetailVO { private String content; @Schema(description = "通知类型") - private String noticeTypeLabel; + private String noticeType; @Schema(description = "发布人") private String releaseBy; diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java index 7fc953e1..119638f1 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeStatusVO.java @@ -23,7 +23,7 @@ public class NoticeStatusVO { private String title; @Schema(description = "通知类型") - private String noticeTypeLabel; + private String noticeType; @Schema(description = "发布人") private String releaseBy; diff --git a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java index f0d86ffb..70c3789f 100644 --- a/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java +++ b/src/main/java/com/youlai/boot/system/model/vo/NoticeVO.java @@ -29,7 +29,7 @@ public class NoticeVO implements Serializable { private String title; @Schema(description = "通知类型") - private String noticeTypeLabel; + private String noticeType; @Schema(description = "发布人") private String releaseBy; diff --git a/src/main/java/com/youlai/boot/system/service/NoticeService.java b/src/main/java/com/youlai/boot/system/service/NoticeService.java index 66e31f32..8b6ddebf 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeService.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.boot.system.model.entity.Notice; import com.youlai.boot.system.model.form.NoticeForm; import com.youlai.boot.system.model.query.NoticeQuery; +import com.youlai.boot.system.model.vo.NoticeStatusVO; import com.youlai.boot.system.model.vo.NoticeVO; import com.youlai.boot.system.model.vo.NoticeDetailVO; @@ -92,5 +93,5 @@ public interface NoticeService extends IService { * @param queryParams 查询参数 * @return 通知公告分页列表 */ - IPage getMyNoticePage(NoticeQuery queryParams); + IPage getMyNoticePage(NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java index 5cd748c6..aae06907 100644 --- a/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java +++ b/src/main/java/com/youlai/boot/system/service/NoticeStatusService.java @@ -34,7 +34,7 @@ public interface NoticeStatusService extends IService { * 分页获取我的通知公告 * @param page 分页对象 * @param queryParams 查询参数 - * @return 通知公告分页列表 + * @return 我的通知公告分页列表 */ - IPage getMyNoticePage(Page page, NoticeQuery queryParams); + IPage getMyNoticePage(Page page, NoticeQuery queryParams); } diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java index cde91ba8..7a1641d7 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeServiceImpl.java @@ -269,7 +269,7 @@ public class NoticeServiceImpl extends ServiceImpl impleme * @return 通知公告分页列表 */ @Override - public IPage getMyNoticePage(NoticeQuery queryParams) { + public IPage getMyNoticePage(NoticeQuery queryParams) { Long userId = SecurityUtils.getUserId(); queryParams.setUserId(userId); return noticeStatusService.getMyNoticePage(new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),queryParams); diff --git a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java index fd54e3e1..2a1599bd 100644 --- a/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java +++ b/src/main/java/com/youlai/boot/system/service/impl/NoticeStatusServiceImpl.java @@ -59,7 +59,7 @@ public class NoticeStatusServiceImpl extends ServiceImpl getMyNoticePage(Page page, NoticeQuery queryParams) { + public IPage getMyNoticePage(Page page, NoticeQuery queryParams) { return this.getBaseMapper().getMyNoticePage(new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),queryParams); } diff --git a/src/main/resources/mapper/NoticeStatusMapper.xml b/src/main/resources/mapper/NoticeStatusMapper.xml index 2a2dd71d..76b706e9 100644 --- a/src/main/resources/mapper/NoticeStatusMapper.xml +++ b/src/main/resources/mapper/NoticeStatusMapper.xml @@ -20,10 +20,11 @@ sn.release_time DESC - SELECT sn.id, sn.title, + sn.notice_type, sn.release_by, sn.priority, sn.release_time,