Files
yunzerwebsiteallinone/go/docs/sql/create_platform_website_notice.sql
T
2026-09-17 23:42:41 +08:00

89 lines
5.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================================
-- 平台官网 - 站点公告
-- 表:yz_platform_website_notice
--
-- 用途:平台端「官网管理 → 内容管理 → 站点公告」维护官网的通知 / 活动 /
-- 系统维护类公告;前台经 GET /site/notices 读取(仅返回「已发布」
-- 且处于有效期内的公告)。
--
-- 执行方式:人工在数据库执行(代码中不做任何自动建表 / 补列)。
-- 说明:下方 DDL 幂等,可重复执行。
-- =============================================================
CREATE TABLE IF NOT EXISTS `yz_platform_website_notice` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '公告标题',
`summary` varchar(500) NOT NULL DEFAULT '' COMMENT '公告摘要(前台卡片展示,留空则前台截取正文)',
`content` mediumtext COMMENT '公告正文(富文本 HTML)',
`type` tinyint NOT NULL DEFAULT 1 COMMENT '公告类型:1 通知公告 2 活动公告 3 系统维护',
`link_url` varchar(500) NOT NULL DEFAULT '' COMMENT '点击跳转地址,站内相对路径或完整 URL;留空表示不可点击',
`is_popup` tinyint NOT NULL DEFAULT 0 COMMENT '是否作为弹窗/侧栏公告:0 否 1 是',
`top` tinyint NOT NULL DEFAULT 0 COMMENT '是否置顶:0 否 1 是',
`sort` int NOT NULL DEFAULT 0 COMMENT '排序,数字越小越靠前',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态:0 草稿 1 已发布 2 已下线',
`start_time` datetime DEFAULT NULL COMMENT '生效开始时间,NULL 表示立即生效',
`end_time` datetime DEFAULT NULL COMMENT '生效结束时间,NULL 表示永久有效',
`views` int NOT NULL DEFAULT 0 COMMENT '浏览量',
`publisher_id` bigint UNSIGNED DEFAULT NULL COMMENT '发布人(平台用户ID)',
`publish_time` datetime DEFAULT NULL COMMENT '发布时间',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间(软删除)',
PRIMARY KEY (`id`),
KEY `idx_status_sort` (`status`, `sort`, `id`),
KEY `idx_popup` (`is_popup`, `status`),
KEY `idx_publish_time` (`publish_time`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '平台官网-站点公告';
-- =============================================================
-- 平台菜单:把「站点公告」挂到「官网管理 → 内容管理」下
--
-- 菜单数据统一维护在 yz_system_menu(平台端 cid=1 的角色可见)。
-- 父级不用写死自增ID,按现有「内容管理」的子菜单反查,可在任意环境重复执行。
-- 若本次不需要自动挂菜单,可只执行上面的建表语句,手动在
-- 「系统管理 → 菜单管理」里添加:路径 /website/content/notice,
-- 组件 /website/content/notice/index.vue
-- =============================================================
-- 父级定位一:取现有「内容管理」子菜单(文章管理)的 pid
SET @notice_pid := (
SELECT `pid` FROM `yz_system_menu`
WHERE `delete_time` IS NULL AND `component_path` LIKE '/website/content/%'
ORDER BY `id` ASC LIMIT 1
);
-- 父级定位二:兜底按「内容管理」的路径或名称查
SET @notice_pid := IFNULL(@notice_pid, (
SELECT `id` FROM `yz_system_menu`
WHERE `delete_time` IS NULL
AND (`path` = '/website/content' OR `title` = '内容管理')
ORDER BY `id` ASC LIMIT 1
));
-- 已存在同路径菜单时跳过,避免重复插入
INSERT INTO `yz_system_menu`
(`pid`, `title`, `path`, `component_path`, `icon`, `sort`, `status`, `is_visible`, `views`, `type`, `creater`, `remark`, `create_time`)
SELECT
@notice_pid, '站点公告', '/website/content/notice', '/website/content/notice/index.vue',
'Bell', 50, 1, 1, '[1]', 2, 'sql', '官网管理 - 站点公告', NOW()
FROM (SELECT 1) AS `t`
WHERE @notice_pid IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM (
SELECT `id` FROM `yz_system_menu`
WHERE `delete_time` IS NULL AND `path` = '/website/content/notice'
LIMIT 1
) AS `exist`
);
-- =============================================================
-- 可选:一条示例公告,便于前台联调(不需要可整段跳过)
-- =============================================================
INSERT INTO `yz_platform_website_notice`
(`title`, `summary`, `content`, `type`, `is_popup`, `top`, `sort`, `status`, `publish_time`)
VALUES
('云泽科技官网全新改版上线', '本次改版聚焦信息架构与访问体验,欢迎反馈建议。',
'<p>云泽科技官网全新改版上线,本次改版聚焦信息架构与访问体验。</p>', 1, 1, 1, 0, 1, NOW());