diff --git a/data.sql b/data.sql index 6af95d1..aed6fce 100644 --- a/data.sql +++ b/data.sql @@ -12,18 +12,98 @@ VALUES ('00000000-0000-7000-8000-000000000001', 'HOST', '本机构', 1, '#1677ff ON DUPLICATE KEY UPDATE `name`=VALUES(`name`), `is_host`=1, `status`='active'; INSERT INTO `permissions` (`code`, `name`, `group`) VALUES +('dashboard:view', '查看数据面板', 'dashboard'), +('notification:view', '查看通知', 'notification'), +('student:view', '查看学生管理', 'student'), +('student:basic-view', '查看学生基础信息', 'student-scope'), +('teacher-workspace:view', '查看教师工作台', 'teacher-workspace'), +('teacher:view', '查看教师', 'teacher'), +('teacher:edit', '编辑教师', 'teacher'), +('student:create', '新增学生', 'student'), +('student:edit', '编辑学生', 'student'), +('student:delete', '归档学生', 'student'), +('student:import', '导入学生', 'student'), +('student:export', '导出学生', 'student'), +('exam:view', '查看和录入考试成绩', 'exam'), +('room:view', '查看宿舍', 'room'), +('room:inspect', '宿舍查寝', 'room'), +('room:create', '新增宿舍', 'room'), +('room:edit', '编辑宿舍', 'room'), +('room:delete', '归档宿舍', 'room'), +('occupancy:view', '查看入住', 'occupancy'), +('occupancy:checkin', '办理入住', 'occupancy'), +('occupancy:checkout', '办理退宿', 'occupancy'), +('occupancy:transfer', '调换宿舍', 'occupancy'), +('occupancy:delete', '归档入住记录', 'occupancy'), +('expense:view', '查看费用', 'expense'), +('expense:create', '录入费用', 'expense'), +('expense:edit', '编辑费用', 'expense'), +('expense:delete', '归档费用', 'expense'), +('bill:view', '查看账单', 'bill'), +('bill:generate', '生成账单', 'bill'), +('bill:confirm', '确认账单', 'bill'), +('bill:delete', '归档账单', 'bill'), +('bill:export-excel', '导出 Excel', 'bill'), +('bill:export-pdf', '导出 PDF', 'bill'), +('deposit:view', '查看押金', 'deposit'), +('deposit:create', '新增押金', 'deposit'), +('deposit:edit', '编辑押金', 'deposit'), +('deposit:delete', '归档押金', 'deposit'), +('deposit:refund', '直接退还押金', 'deposit'), +('wallet:view', '查看学生余额', 'wallet'), +('wallet:edit', '充值和调账', 'wallet'), +('classroom:view', '查看教室', 'classroom'), +('classroom:create', '新增教室', 'classroom'), +('classroom:edit', '编辑教室', 'classroom'), +('classroom:delete', '归档教室', 'classroom'), +('organization:view', '查看机构', 'organization'), +('organization:create', '新增机构', 'organization'), +('organization:edit', '编辑机构', 'organization'), +('organization:delete', '归档机构', 'organization'), +('rental:view', '查看租赁订单', 'rental'), +('rental:create', '新增租赁订单', 'rental'), +('rental:edit', '编辑租赁订单', 'rental'), +('rental:delete', '归档租赁订单', 'rental'), +('log:view', '查看操作日志', 'log'), +('log:create', '写入操作日志', 'log'), +('user:view', '查看用户', 'user'), +('user:create', '创建用户', 'user'), +('user:edit', '编辑用户', 'user'), +('user:reset-password', '重置密码', 'user'), +('role:view', '查看角色', 'role'), +('role:create', '创建角色', 'role'), +('role:edit', '编辑角色', 'role'), +('role:delete', '停用角色', 'role'), +('class:view', '查看班级', 'class'), +('class:create', '创建班级', 'class'), +('class:edit', '编辑班级', 'class'), +('class:delete', '归档班级', 'class'), ('schedule:view', '查看排课', 'schedule'), +('schedule:create', '创建排课', 'schedule'), +('schedule:edit', '编辑排课', 'schedule'), +('schedule:delete', '停用排课', 'schedule'), ('attendance:view', '查看考勤', 'attendance'), ('attendance:create', '新增考勤', 'attendance'), +('attendance:edit', '编辑全部考勤', 'attendance'), ('attendance:self-edit', '编辑任教班级考勤', 'attendance-scope'), -('teacher-workspace:view', '查看教师工作台', 'teacher-workspace'), -('notification:view', '查看通知', 'notification'), -('exam:view', '查看和录入考试成绩', 'exam') +('attendance:export', '导出考勤', 'attendance'), +('sync:trigger', '触发数据同步', 'sync'), +('sync:read', '查看同步状态', 'sync'), +('integration:trigger', '触发集成', 'integration'), +('integration:read', '查看集成状态', 'integration'), +('ai:config:read', '查看 AI 配置', 'ai'), +('ai:config:write', '修改 AI 配置', 'ai'), +('ai:config:test', '测试 AI 连接', 'ai'), +('ai:chat:use', '使用 AI 助手', 'ai-chat') ON DUPLICATE KEY UPDATE `name`=VALUES(`name`), `group`=VALUES(`group`); INSERT INTO `roles` (`name`, `code`, `description`, `is_system`, `status`) VALUES ('超级管理员', 'super_admin', '系统初始化、应急维护和全局权限处理', 1, 1), -('任课老师', 'teacher', '查看自己的排课、今日课程和任教班级考勤', 1, 1) +('任课老师', 'teacher', '查看自己的排课、今日课程和任教班级考勤', 1, 1), +('教务管理员', 'academic', '管理学生、班级、教师、全局排课和历史考勤', 1, 1), +('住宿运营管理员', 'accommodation_operations', '管理宿舍、入住、住宿费用、账单、押金和退宿结算', 1, 1), +('教室运营管理员', 'classroom_operations', '管理教室、教室排期、外部机构和租赁订单', 1, 1), +('系统管理员', 'system_admin', '管理账号、角色、日志、同步和系统配置', 1, 1) ON DUPLICATE KEY UPDATE `name`=VALUES(`name`), `description`=VALUES(`description`), `is_system`=1, `status`=1; INSERT INTO `users` (`username`, `password_hash`, `name`, `is_active`, `is_archived`) @@ -33,10 +113,40 @@ ON DUPLICATE KEY UPDATE `name`='管理员', `is_active`=1, `is_archived`=0; INSERT IGNORE INTO `user_roles` (`user_id`, `role_id`) SELECT u.id, r.id FROM `users` u JOIN `roles` r ON r.code='super_admin' WHERE u.username='admin'; +-- Preset roles use the same authoritative permission matrix as RbacService.seedData(). +DELETE rp FROM `role_permissions` rp +JOIN `roles` r ON r.id=rp.role_id +WHERE r.code IN ('super_admin','teacher','academic','accommodation_operations','classroom_operations','system_admin'); + INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`) SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p WHERE r.code='super_admin'; + INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`) -SELECT r.id, p.id FROM `roles` r JOIN `permissions` p ON p.code IN ('schedule:view','attendance:view','attendance:create','attendance:self-edit','teacher-workspace:view','notification:view') WHERE r.code='teacher'; +SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p +WHERE r.code='teacher' + AND (p.`group` IN ('notification') OR p.code IN ('teacher-workspace:view','schedule:view','attendance:view','attendance:create','attendance:self-edit')); + +INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`) +SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p +WHERE r.code='academic' + AND (p.`group` IN ('student','exam','class','schedule','attendance','classroom','dashboard','notification') + OR p.code IN ('teacher-workspace:view','teacher:view','teacher:edit','sync:read','sync:trigger')); + +INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`) +SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p +WHERE r.code='accommodation_operations' + AND (p.`group` IN ('room','occupancy','expense','bill','deposit','wallet','dashboard','notification') + OR p.code IN ('student:basic-view')); + +INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`) +SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p +WHERE r.code='classroom_operations' + AND p.`group` IN ('classroom','rental','organization','notification'); + +INSERT IGNORE INTO `role_permissions` (`role_id`, `permission_id`) +SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p +WHERE r.code='system_admin' + AND p.`group` IN ('user','role','log','integration','sync','ai','notification'); INSERT INTO `users` (`username`, `password_hash`, `name`, `is_active`, `is_archived`) VALUES ('summer_teacher_01', '$2b$10$/uXpQttv.Ud7sfUeZmVta./ZwMjHF59JbO4scA6pnHDtUZo1EMzA2', '柴艳', 1, 0),