-- ============================================================ -- 盘古用户平台 - 业务模块建表脚本(适配 RuoYi-Vue-Plus 5.x) -- 作者:pangu -- 创建时间:2026-02-02 -- ============================================================ USE `pguser-db`; -- ============================================================ -- 1. 年级字典表 -- ============================================================ DROP TABLE IF EXISTS `pg_grade`; CREATE TABLE `pg_grade` ( `grade_id` bigint NOT NULL COMMENT '年级ID', `grade_code` varchar(32) NOT NULL COMMENT '年级编码', `grade_name` varchar(50) NOT NULL COMMENT '年级名称', `order_num` int DEFAULT 0 COMMENT '显示顺序', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`grade_id`), UNIQUE KEY `uk_grade_code` (`grade_code`) ) ENGINE=InnoDB COMMENT='年级字典表'; -- 年级初始化数据 INSERT INTO `pg_grade` VALUES (1, 'GRD001', '一年级', 1, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (2, 'GRD002', '二年级', 2, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (3, 'GRD003', '三年级', 3, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (4, 'GRD004', '四年级', 4, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (5, 'GRD005', '五年级', 5, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (6, 'GRD006', '六年级', 6, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (7, 'GRD007', '七年级', 7, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (8, 'GRD008', '八年级', 8, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (9, 'GRD009', '九年级', 9, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (10, 'GRD010', '高一', 10, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (11, 'GRD011', '高二', 11, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (12, 'GRD012', '高三', 12, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL); -- ============================================================ -- 2. 班级字典表 -- ============================================================ DROP TABLE IF EXISTS `pg_class`; CREATE TABLE `pg_class` ( `class_id` bigint NOT NULL COMMENT '班级ID', `class_code` varchar(32) NOT NULL COMMENT '班级编码', `class_name` varchar(50) NOT NULL COMMENT '班级名称', `order_num` int DEFAULT 0 COMMENT '显示顺序', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`class_id`), UNIQUE KEY `uk_class_code` (`class_code`) ) ENGINE=InnoDB COMMENT='班级字典表'; -- 班级初始化数据 INSERT INTO `pg_class` VALUES (1, 'CLS001', '1班', 1, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (2, 'CLS002', '2班', 2, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (3, 'CLS003', '3班', 3, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (4, 'CLS004', '4班', 4, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (5, 'CLS005', '5班', 5, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (6, 'CLS006', '6班', 6, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (7, 'CLS007', '7班', 7, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (8, 'CLS008', '8班', 8, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (9, 'CLS009', '9班', 9, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (10, 'CLS010', '10班', 10, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL); -- ============================================================ -- 3. 学科表 -- ============================================================ DROP TABLE IF EXISTS `pg_subject`; CREATE TABLE `pg_subject` ( `subject_id` bigint NOT NULL COMMENT '学科ID', `subject_code` varchar(32) NOT NULL COMMENT '学科编码', `subject_name` varchar(50) NOT NULL COMMENT '学科名称', `order_num` int DEFAULT 0 COMMENT '显示顺序', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`subject_id`), UNIQUE KEY `uk_subject_code` (`subject_code`) ) ENGINE=InnoDB COMMENT='学科表'; -- 学科初始化数据 INSERT INTO `pg_subject` VALUES (1, 'SUB001', '语文', 1, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (2, 'SUB002', '数学', 2, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (3, 'SUB003', '英语', 3, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (4, 'SUB004', '物理', 4, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (5, 'SUB005', '化学', 5, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (6, 'SUB006', '生物', 6, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (7, 'SUB007', '历史', 7, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (8, 'SUB008', '地理', 8, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL), (9, 'SUB009', '政治', 9, '0', '000000', 103, 1, NOW(), 1, NOW(), '0', NULL); -- ============================================================ -- 4. 区域表 -- ============================================================ DROP TABLE IF EXISTS `pg_region`; CREATE TABLE `pg_region` ( `region_id` bigint NOT NULL COMMENT '区域ID', `parent_id` bigint DEFAULT 0 COMMENT '父区域ID', `ancestors` varchar(500) DEFAULT '' COMMENT '祖级列表', `region_name` varchar(100) NOT NULL COMMENT '区域名称', `region_code` varchar(32) DEFAULT NULL COMMENT '区域编码', `level` int DEFAULT 1 COMMENT '层级(1省 2市 3区县)', `order_num` int DEFAULT 0 COMMENT '显示顺序', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', PRIMARY KEY (`region_id`) ) ENGINE=InnoDB COMMENT='区域表'; -- 区域初始化数据(湖北省示例) INSERT INTO `pg_region` VALUES (420000, 0, '0', '湖北省', '420000', 1, 1, '0', '000000', 103, 1, NOW(), 1, NOW(), '0'), (420100, 420000, '0,420000', '武汉市', '420100', 2, 1, '0', '000000', 103, 1, NOW(), 1, NOW(), '0'), (420102, 420100, '0,420000,420100', '江岸区', '420102', 3, 1, '0', '000000', 103, 1, NOW(), 1, NOW(), '0'), (420103, 420100, '0,420000,420100', '江汉区', '420103', 3, 2, '0', '000000', 103, 1, NOW(), 1, NOW(), '0'), (420104, 420100, '0,420000,420100', '硚口区', '420104', 3, 3, '0', '000000', 103, 1, NOW(), 1, NOW(), '0'); -- ============================================================ -- 5. 学校表 -- ============================================================ DROP TABLE IF EXISTS `pg_school`; CREATE TABLE `pg_school` ( `school_id` bigint NOT NULL COMMENT '学校ID', `school_code` varchar(32) NOT NULL COMMENT '学校编码', `school_name` varchar(100) NOT NULL COMMENT '学校名称', `school_type` char(1) DEFAULT '1' COMMENT '学校类型(1小学 2初中 3高中 4完全中学)', `region_id` bigint DEFAULT NULL COMMENT '所属区域ID', `region_path` varchar(500) DEFAULT NULL COMMENT '区域路径', `address` varchar(500) DEFAULT NULL COMMENT '详细地址', `contact_person` varchar(50) DEFAULT NULL COMMENT '联系人', `contact_phone` varchar(20) DEFAULT NULL COMMENT '联系电话', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`school_id`), UNIQUE KEY `uk_school_code` (`school_code`) ) ENGINE=InnoDB COMMENT='学校表'; -- ============================================================ -- 6. 学校年级关联表 -- ============================================================ DROP TABLE IF EXISTS `pg_school_grade`; CREATE TABLE `pg_school_grade` ( `id` bigint NOT NULL COMMENT '主键', `school_id` bigint NOT NULL COMMENT '学校ID', `grade_id` bigint NOT NULL COMMENT '年级ID', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_school_grade` (`school_id`, `grade_id`) ) ENGINE=InnoDB COMMENT='学校年级关联表'; -- ============================================================ -- 7. 学校班级表 -- ============================================================ DROP TABLE IF EXISTS `pg_school_class`; CREATE TABLE `pg_school_class` ( `id` bigint NOT NULL COMMENT '主键', `school_id` bigint NOT NULL COMMENT '学校ID', `school_grade_id` bigint NOT NULL COMMENT '学校年级ID', `class_id` bigint NOT NULL COMMENT '班级ID', `class_alias` varchar(50) DEFAULT NULL COMMENT '班级别名', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`), KEY `idx_school_grade` (`school_id`, `school_grade_id`) ) ENGINE=InnoDB COMMENT='学校班级表'; -- ============================================================ -- 8. 会员表 -- ============================================================ DROP TABLE IF EXISTS `pg_member`; CREATE TABLE `pg_member` ( `member_id` bigint NOT NULL COMMENT '会员ID', `member_code` varchar(32) NOT NULL COMMENT '会员编码', `phone` varchar(20) DEFAULT NULL COMMENT '手机号', `password` varchar(100) DEFAULT NULL COMMENT '密码', `nickname` varchar(50) DEFAULT NULL COMMENT '昵称', `avatar` varchar(500) DEFAULT NULL COMMENT '头像', `gender` char(1) DEFAULT '0' COMMENT '性别(0未知 1男 2女)', `birthday` date DEFAULT NULL COMMENT '生日', `identity_type` char(1) DEFAULT '1' COMMENT '身份类型(1家长 2教师)', `open_id` varchar(100) DEFAULT NULL COMMENT '微信OpenID', `union_id` varchar(100) DEFAULT NULL COMMENT '微信UnionID', `region_id` bigint DEFAULT NULL COMMENT '区域ID', `school_id` bigint DEFAULT NULL COMMENT '学校ID(教师用)', `school_grade_id` bigint DEFAULT NULL COMMENT '年级ID(教师用)', `school_class_id` bigint DEFAULT NULL COMMENT '班级ID(教师用)', `register_source` char(1) DEFAULT '1' COMMENT '注册来源(1小程序 2H5 3后台 4导入)', `register_time` datetime DEFAULT NULL COMMENT '注册时间', `last_login_time` datetime DEFAULT NULL COMMENT '最后登录时间', `last_login_ip` varchar(50) DEFAULT NULL COMMENT '最后登录IP', `login_count` int DEFAULT 0 COMMENT '登录次数', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`member_id`), UNIQUE KEY `uk_member_code` (`member_code`), KEY `idx_phone` (`phone`), KEY `idx_open_id` (`open_id`) ) ENGINE=InnoDB COMMENT='会员表'; -- ============================================================ -- 9. 学生表 -- ============================================================ DROP TABLE IF EXISTS `pg_student`; CREATE TABLE `pg_student` ( `student_id` bigint NOT NULL COMMENT '学生ID', `student_name` varchar(50) NOT NULL COMMENT '学生姓名', `student_no` varchar(32) DEFAULT NULL COMMENT '学号', `gender` char(1) DEFAULT '0' COMMENT '性别(0未知 1男 2女)', `birthday` date DEFAULT NULL COMMENT '生日', `region_id` bigint DEFAULT NULL COMMENT '区域ID', `region_path` varchar(500) DEFAULT NULL COMMENT '区域路径', `school_id` bigint DEFAULT NULL COMMENT '学校ID', `school_grade_id` bigint DEFAULT NULL COMMENT '学校年级ID', `school_class_id` bigint DEFAULT NULL COMMENT '学校班级ID', `subject_id` bigint DEFAULT NULL COMMENT '学科ID', `member_id` bigint DEFAULT NULL COMMENT '绑定的会员ID', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`student_id`), KEY `idx_student_no` (`student_no`), KEY `idx_school` (`school_id`, `school_grade_id`, `school_class_id`) ) ENGINE=InnoDB COMMENT='学生表'; -- ============================================================ -- 10. 应用表 -- ============================================================ DROP TABLE IF EXISTS `pg_application`; CREATE TABLE `pg_application` ( `app_id` bigint NOT NULL COMMENT '应用ID', `app_code` varchar(32) NOT NULL COMMENT '应用编码', `app_name` varchar(100) NOT NULL COMMENT '应用名称', `app_secret` varchar(100) NOT NULL COMMENT '应用密钥', `contact_person` varchar(50) DEFAULT NULL COMMENT '联系人', `contact_phone` varchar(20) DEFAULT NULL COMMENT '联系电话', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint DEFAULT NULL COMMENT '创建部门', `create_by` bigint DEFAULT NULL COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` bigint DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`app_id`), UNIQUE KEY `uk_app_code` (`app_code`) ) ENGINE=InnoDB COMMENT='第三方应用表'; -- ============================================================ -- 11. API接口字典表 -- ============================================================ DROP TABLE IF EXISTS `pg_api_dict`; CREATE TABLE `pg_api_dict` ( `api_id` bigint NOT NULL COMMENT 'API ID', `api_code` varchar(50) NOT NULL COMMENT 'API编码', `api_name` varchar(100) NOT NULL COMMENT 'API名称', `api_path` varchar(200) NOT NULL COMMENT 'API路径', `api_method` varchar(10) DEFAULT 'GET' COMMENT '请求方法', `api_desc` varchar(500) DEFAULT NULL COMMENT 'API描述', `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', `order_num` int DEFAULT 0 COMMENT '排序', PRIMARY KEY (`api_id`), UNIQUE KEY `uk_api_code` (`api_code`) ) ENGINE=InnoDB COMMENT='API接口字典表'; -- ============================================================ -- 12. 应用API授权表 -- ============================================================ DROP TABLE IF EXISTS `pg_app_api`; CREATE TABLE `pg_app_api` ( `id` bigint NOT NULL COMMENT '主键', `app_id` bigint NOT NULL COMMENT '应用ID', `api_id` bigint NOT NULL COMMENT 'API ID', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_app_api` (`app_id`, `api_id`) ) ENGINE=InnoDB COMMENT='应用API授权表';