refactor(notification): 更新通知表结构,移除自增主键,手动生成ID

This commit is contained in:
wangzhiwei 2026-05-25 10:01:31 +08:00
parent e22784fe2c
commit f06e895eb1
3 changed files with 17 additions and 17 deletions

View File

@ -63,21 +63,20 @@ CREATE TABLE `edu_teacher` (
-- 4. 通知表
DROP TABLE IF EXISTS `sys_notification`;
CREATE TABLE `sys_notification` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`school_id` BIGINT(20) NOT NULL COMMENT '学校ID数据隔离',
`user_id` BIGINT(20) NOT NULL COMMENT '用户ID',
`title` VARCHAR(100) NOT NULL COMMENT '通知标题',
`content` TEXT NOT NULL COMMENT '通知内容',
`type` TINYINT(1) DEFAULT '1' COMMENT '通知类型1-系统通知2-作业通知3-考试通知4-考勤通知5-用户通知6-课程通知',
`is_read` TINYINT(1) DEFAULT '0' COMMENT '是否已读0-未读1-已读',
`sender_id` BIGINT(20) DEFAULT NULL COMMENT '发送者用户ID',
`sender_name` VARCHAR(100) DEFAULT NULL COMMENT '发送者姓名',
`target_type` TINYINT(1) DEFAULT '1' COMMENT '目标类型1-单个用户2-角色3-课程',
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_school_id` (`school_id`),
`id` BIGINT NOT NULL COMMENT '主键ID',
`school_id` BIGINT DEFAULT NULL COMMENT '学校ID',
`user_id` BIGINT DEFAULT NULL COMMENT '接收用户ID',
`title` VARCHAR(255) DEFAULT NULL COMMENT '通知标题',
`content` TEXT COMMENT '通知内容',
`type` TINYINT DEFAULT NULL COMMENT '通知类型',
`is_read` TINYINT DEFAULT '0' COMMENT '是否已读 0未读 1已读',
`sender_id` BIGINT DEFAULT NULL COMMENT '发送人ID',
`sender_name` VARCHAR(64) DEFAULT NULL COMMENT '发送人姓名',
`target_type` TINYINT DEFAULT NULL COMMENT '目标类型',
`create_time` DATETIME DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_user_id` (`user_id`),
KEY `idx_is_read` (`is_read`)
KEY `idx_school_id` (`school_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='通知表';
-- 5. 课程表

View File

@ -219,6 +219,7 @@ public class SysNotificationServiceImpl implements SysNotificationService {
String content, Integer type, Long senderId,
String senderName, Integer targetType) {
SysNotification notification = new SysNotification();
notification.setId(System.currentTimeMillis());
notification.setSchoolId(schoolId);
notification.setUserId(userId);
notification.setTitle(title);

View File

@ -121,11 +121,11 @@
WHERE user_id = #{userId} AND school_id = #{schoolId} AND is_read = 0
</select>
<insert id="batchInsert" useGeneratedKeys="true" keyProperty="id">
INSERT INTO sys_notification (school_id, user_id, title, content, type, is_read, sender_id, sender_name, target_type, create_time)
<insert id="batchInsert">
INSERT INTO sys_notification (id, school_id, user_id, title, content, type, is_read, sender_id, sender_name, target_type, create_time)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.schoolId}, #{item.userId}, #{item.title}, #{item.content}, #{item.type}, #{item.isRead}, #{item.senderId}, #{item.senderName}, #{item.targetType}, #{item.createTime})
(#{item.id}, #{item.schoolId}, #{item.userId}, #{item.title}, #{item.content}, #{item.type}, #{item.isRead}, #{item.senderId}, #{item.senderName}, #{item.targetType}, #{item.createTime})
</foreach>
</insert>