路由更新

This commit is contained in:
2025-10-16 18:03:46 +08:00
parent 1199cbc176
commit 0811af6d03
94 changed files with 9511 additions and 667 deletions

View File

@@ -1,126 +0,0 @@
@echo off
chcp 65001 >nul
echo =====================================================
echo 校园思政新闻平台数据库初始化脚本
echo =====================================================
echo.
REM 设置MySQL连接信息请根据实际情况修改
set MYSQL_HOST=localhost
set MYSQL_PORT=3306
set MYSQL_USER=root
set MYSQL_PASSWORD=
echo 请输入MySQL连接信息:
echo.
set /p MYSQL_HOST=MySQL主机地址 [默认: localhost]:
if "%MYSQL_HOST%"=="" set MYSQL_HOST=localhost
set /p MYSQL_PORT=MySQL端口 [默认: 3306]:
if "%MYSQL_PORT%"=="" set MYSQL_PORT=3306
set /p MYSQL_USER=MySQL用户名 [默认: root]:
if "%MYSQL_USER%"=="" set MYSQL_USER=root
set /p MYSQL_PASSWORD=MySQL密码:
echo.
echo 连接信息:
echo 主机: %MYSQL_HOST%
echo 端口: %MYSQL_PORT%
echo 用户: %MYSQL_USER%
echo.
echo 开始执行数据库初始化...
echo.
REM 切换到sql目录
cd sql
REM 执行SQL文件
echo [1/9] 创建数据库...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createDB.sql
if errorlevel 1 (
echo 错误: 创建数据库失败!
pause
exit /b 1
)
echo [2/9] 创建用户相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableUser.sql
if errorlevel 1 (
echo 错误: 创建用户表失败!
pause
exit /b 1
)
echo [3/9] 创建权限相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTablePermission.sql
if errorlevel 1 (
echo 错误: 创建权限表失败!
pause
exit /b 1
)
echo [4/9] 创建资源管理相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableResource.sql
if errorlevel 1 (
echo 错误: 创建资源表失败!
pause
exit /b 1
)
echo [5/9] 创建课程管理相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableCourse.sql
if errorlevel 1 (
echo 错误: 创建课程表失败!
pause
exit /b 1
)
echo [6/9] 创建学习管理相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableLearning.sql
if errorlevel 1 (
echo 错误: 创建学习表失败!
pause
exit /b 1
)
echo [7/9] 创建个人中心相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableUserCenter.sql
if errorlevel 1 (
echo 错误: 创建个人中心表失败!
pause
exit /b 1
)
echo [8/9] 创建智能体相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableAI.sql
if errorlevel 1 (
echo 错误: 创建智能体表失败!
pause
exit /b 1
)
echo [9/9] 创建系统配置和日志相关表...
mysql -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USER% -p%MYSQL_PASSWORD% < createTableSystem.sql
if errorlevel 1 (
echo 错误: 创建系统表失败!
pause
exit /b 1
)
cd ..
echo.
echo =====================================================
echo 数据库初始化完成!
echo =====================================================
echo 数据库名: school_news
echo 默认用户: admin
echo 默认密码: 详见 createTableUser.sql
echo =====================================================
echo.
pause

View File

@@ -9,7 +9,7 @@ echo ""
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
MYSQL_USER="root"
MYSQL_PASSWORD=""
MYSQL_PASSWORD="123456"
# 读取用户输入
read -p "MySQL主机地址 [默认: localhost]: " input_host
@@ -21,17 +21,8 @@ MYSQL_PORT=${input_port:-$MYSQL_PORT}
read -p "MySQL用户名 [默认: root]: " input_user
MYSQL_USER=${input_user:-$MYSQL_USER}
read -sp "MySQL密码: " MYSQL_PASSWORD
echo ""
echo ""
echo "连接信息:"
echo "主机: $MYSQL_HOST"
echo "端口: $MYSQL_PORT"
echo "用户: $MYSQL_USER"
echo ""
echo "开始执行数据库初始化..."
read -sp "MySQL密码[默认: 123456]: " input_password
MYSQL_PASSWORD=${input_password:-$MYSQL_PASSWORD}
echo ""
# 切换到sql目录

View File

@@ -1,2 +1,16 @@
-- MySQL Script to create the database
CREATE DATABASE IF NOT EXISTS `school_news` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
-- 修复字符编码问题
-- 删除现有数据库(如果存在)
DROP DATABASE IF EXISTS `school_news`;
-- 创建数据库使用utf8mb4字符集
CREATE DATABASE `school_news` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- 使用数据库
USE `school_news`;
-- 设置会话字符集
SET NAMES utf8mb4;
SET CHARACTER SET utf8mb4;
SET character_set_client = utf8mb4;
SET character_set_connection = utf8mb4;
SET character_set_results = utf8mb4;

View File

@@ -21,9 +21,6 @@ CREATE TABLE `tb_ai_agent_config` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='智能体配置表';
-- 插入默认配置
INSERT INTO `tb_ai_agent_config` (id, name, system_prompt, model_name, temperature, max_tokens, status, creator, create_time) VALUES
('1', '思政小帮手', '你是一个专业的思政学习助手,致力于帮助用户学习思想政治理论知识。请基于提供的知识库内容,为用户提供准确、简洁的回答。', 'gpt-3.5-turbo', 0.7, 2000, 1, '1', now());
-- 知识库表
DROP TABLE IF EXISTS `tb_ai_knowledge`;

View File

@@ -18,8 +18,6 @@ CREATE TABLE `tb_sys_dept` (
KEY `idx_dept_parent` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_dept` (id,dept_id,name, description) VALUES ('1','root_department', '超级部门', '系统超级部门');
INSERT INTO `tb_sys_dept` (id,dept_id,name, parent_id, description) VALUES ('2','default_department', '默认部门', 'root_department', '系统默认创建的部门');
-- 角色表
DROP TABLE IF EXISTS `tb_sys_role`;
@@ -38,8 +36,6 @@ CREATE TABLE `tb_sys_role` (
UNIQUE KEY `uk_role_id` (`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_role` (id,role_id, name, description) VALUES ('1','admin', '管理员', '系统管理员角色');
INSERT INTO `tb_sys_role` (id,role_id, name, description) VALUES ('2','freedom', '自由角色', '自由角色');
-- 部门-角色关联
DROP TABLE IF EXISTS `tb_sys_dept_role`;
@@ -57,9 +53,6 @@ CREATE TABLE `tb_sys_dept_role` (
UNIQUE KEY `uk_dept_role` (`dept_id`, `role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_dept_role` (id, dept_id, role_id, creator, create_time) VALUES
('1', 'root_department', 'admin', '1', now()),
('2', 'default_department', 'freedom', '1', now());
-- 用户-角色关联
DROP TABLE IF EXISTS `tb_sys_user_dept_role`;
@@ -78,7 +71,28 @@ CREATE TABLE `tb_sys_user_dept_role` (
UNIQUE KEY `uk_user_dept_role` (`user_id`, `dept_id`, `role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_user_dept_role` (id, user_id, dept_id, role_id, creator, create_time) VALUES ('1', '1', 'root_department', 'admin', '1', now());
-- 模块表
DROP TABLE IF EXISTS `tb_sys_module`;
CREATE TABLE `tb_sys_module` (
`id` VARCHAR(50) NOT NULL COMMENT 'id',
`module_id` VARCHAR(50) NOT NULL COMMENT '模块ID',
`name` VARCHAR(100) NOT NULL COMMENT '模块名称',
`code` VARCHAR(100) NOT NULL COMMENT '模块代码',
`description` VARCHAR(255) DEFAULT NULL COMMENT '模块描述',
`icon` VARCHAR(100) DEFAULT NULL COMMENT '模块图标',
`order_num` INT(4) DEFAULT 0 COMMENT '模块排序号',
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '模块状态0禁用 1启用',
`creator` VARCHAR(50) DEFAULT NULL COMMENT '创建者',
`updater` VARCHAR(50) DEFAULT NULL COMMENT '更新者',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_module_id` (`module_id`),
UNIQUE KEY `uk_module_code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- 权限表
DROP TABLE IF EXISTS `tb_sys_permission`;
@@ -88,6 +102,7 @@ CREATE TABLE `tb_sys_permission` (
`name` VARCHAR(100) NOT NULL COMMENT '权限名称',
`code` VARCHAR(100) NOT NULL COMMENT '权限代码',
`description` VARCHAR(255) DEFAULT NULL COMMENT '权限描述',
`module_id` VARCHAR(50) DEFAULT NULL COMMENT '所属模块ID',
`creator` VARCHAR(50) DEFAULT NULL COMMENT '创建者',
`updater` VARCHAR(50) DEFAULT NULL COMMENT '更新者',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
@@ -95,21 +110,10 @@ CREATE TABLE `tb_sys_permission` (
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_permission_id` (`permission_id`)
UNIQUE KEY `uk_permission_id` (`permission_id`),
KEY `idx_permission_module` (`module_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_permission` (id,permission_id, name, code, description, creator, create_time) VALUES
('0','perm_default', '默认权限', 'default', '默认权限', '1', now()),
('1','perm_system_manage', '系统管理', 'system:manage', '系统管理权限', '1', now()),
('2','perm_system_dept_manage', '系统部门查看', 'system:dept:manage', '系统部门查看权限', '1', now()),
('3','perm_system_menu_manage', '系统菜单查看', 'system:menu:manage', '系统菜单查看权限', '1', now()),
('4','perm_system_permission_manage', '系统权限查看', 'system:permission:manage', '系统权限查看权限', '1', now()),
('5','perm_system_role_manage', '系统角色查看', 'system:role:manage', '系统角色查看权限', '1', now()),
('6','perm_system_user_manage', '系统用户查看', 'system:user:manage', '系统用户查看权限', '1', now()),
('7','perm_news_manage', '新闻管理', 'news:manage', '新闻管理权限', '1', now()),
('8','perm_study_manage', '学习管理', 'study:manage', '学习管理权限', '1', now()),
('9','perm_ai_manage', 'AI管理', 'ai:manage', 'AI管理权限', '1', now()),
('10','perm_usercenter_manage', '用户中心管理', 'usercenter:manage', '用户中心管理权限', '1', now());
-- 角色-权限关联
DROP TABLE IF EXISTS `tb_sys_role_permission`;
@@ -127,19 +131,6 @@ CREATE TABLE `tb_sys_role_permission` (
UNIQUE KEY `uk_role_permission` (`role_id`, `permission_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_role_permission` (id, role_id, permission_id, creator, create_time) VALUES
('0', 'admin', 'perm_default', '1', now()),
('1', 'admin', 'perm_system_manage', '1', now()),
('2', 'admin', 'perm_system_dept_manage', '1', now()),
('3', 'admin', 'perm_system_menu_manage', '1', now()),
('4', 'admin', 'perm_system_permission_manage', '1', now()),
('5', 'admin', 'perm_system_role_manage', '1', now()),
('6', 'admin', 'perm_system_user_manage', '1', now()),
('7', 'admin', 'perm_news_manage', '1', now()),
('8', 'admin', 'perm_study_manage', '1', now()),
('9', 'admin', 'perm_ai_manage', '1', now()),
('10', 'admin', 'perm_usercenter_manage', '1', now()),
('11', 'freedom', 'perm_default', '1', now());
-- 菜单表
DROP TABLE IF EXISTS `tb_sys_menu`;
@@ -165,31 +156,6 @@ CREATE TABLE `tb_sys_menu` (
KEY `idx_menu_parent` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- Insert default menus
INSERT INTO `tb_sys_menu` (id,menu_id, name, parent_id, url, component, icon, order_num, type, layout, creator, create_time) VALUES
('1','menu_system_manage', '系统管理', NULL, '', '', 'el-icon-setting', 1, 1, '', '1', now()),
('2','menu_system_dept', '部门管理', 'menu_system_manage', '/manage/system/dept', 'manage/system/DeptManageView', 'el-icon-office-building', 2, 1, 'NavigationLayout', '1', now()),
('3','menu_system_menu', '菜单管理', 'menu_system_manage', '/manage/system/menu', 'manage/system/MenuManageView', 'el-icon-menu', 2, 1, 'NavigationLayout', '1', now()),
('4','menu_system_permission', '权限管理', 'menu_system_manage', '/manage/system/permission', 'manage/system/PermissionManageView', 'el-icon-key', 3, 1, 'NavigationLayout', '1', now()),
('5','menu_system_role', '角色管理', 'menu_system_manage', '/manage/system/role', 'manage/system/RoleManageView', 'el-icon-user', 4, 1, 'NavigationLayout', '1', now()),
('6','menu_system_user', '用户管理', 'menu_system_manage', '/manage/system/user', 'manage/system/UserManageView', 'el-icon-user', 5, 1, 'NavigationLayout', '1', now());
-- ('7','menu_news_manage', '新闻管理', NULL, '', '', 'el-icon-document', 2, 1, '', '1', now()),
-- ('8','menu_news_resource', '资源管理', 'menu_news_manage', '/manage/news/resource', 'manage/news/ResourceManageView', 'el-icon-folder', 1, 1, 'NavigationLayout', '1', now()),
-- ('9','menu_news_category', '分类管理', 'menu_news_manage', '/manage/news/category', 'manage/news/CategoryManageView', 'el-icon-menu', 2, 1, 'NavigationLayout', '1', now()),
-- ('10','menu_news_tag', '标签管理', 'menu_news_manage', '/manage/news/tag', 'manage/news/TagManageView', 'el-icon-price-tag', 3, 1, 'NavigationLayout', '1', now()),
-- ('11','menu_news_banner', '横幅管理', 'menu_news_manage', '/manage/news/banner', 'manage/news/BannerManageView', 'el-icon-picture', 4, 1, 'NavigationLayout', '1', now()),
-- ('12','menu_study_manage', '学习管理', NULL, '', '', 'el-icon-reading', 3, 1, '', '1', now()),
-- ('13','menu_study_course', '课程管理', 'menu_study_manage', '/manage/study/course', 'manage/study/CourseManageView', 'el-icon-video-play', 1, 1, 'NavigationLayout', '1', now()),
-- ('14','menu_study_task', '任务管理', 'menu_study_manage', '/manage/study/task', 'manage/study/TaskManageView', 'el-icon-s-order', 2, 1, 'NavigationLayout', '1', now()),
-- ('15','menu_study_record', '学习记录', 'menu_study_manage', '/manage/study/record', 'manage/study/RecordManageView', 'el-icon-document', 3, 1, 'NavigationLayout', '1', now()),
-- ('16','menu_ai_manage', 'AI管理', NULL, '', '', 'el-icon-cpu', 4, 1, '', '1', now()),
-- ('17','menu_ai_agent', 'AI代理', 'menu_ai_manage', '/manage/ai/agent', 'manage/ai/AgentManageView', 'el-icon-robot', 1, 1, 'NavigationLayout', '1', now()),
-- ('18','menu_ai_conversation', '对话管理', 'menu_ai_manage', '/manage/ai/conversation', 'manage/ai/ConversationManageView', 'el-icon-chat-line-round', 2, 1, 'NavigationLayout', '1', now()),
-- ('19','menu_ai_knowledge', '知识库', 'menu_ai_manage', '/manage/ai/knowledge', 'manage/ai/KnowledgeManageView', 'el-icon-collection', 3, 1, 'NavigationLayout', '1', now()),
-- ('20','menu_usercenter_manage', '用户中心', NULL, '', '', 'el-icon-user', 5, 1, '', '1', now()),
-- ('21','menu_usercenter_points', '积分管理', 'menu_usercenter_manage', '/manage/usercenter/points', 'manage/usercenter/PointsManageView', 'el-icon-coin', 1, 1, 'NavigationLayout', '1', now()),
-- ('22','menu_usercenter_achievement', '成就管理', 'menu_usercenter_manage', '/manage/usercenter/achievement', 'manage/usercenter/AchievementManageView', 'el-icon-trophy', 2, 1, 'NavigationLayout', '1', now()),
-- ('23','menu_usercenter_collection', '收藏管理', 'menu_usercenter_manage', '/manage/usercenter/collection', 'manage/usercenter/CollectionManageView', 'el-icon-star-on', 3, 1, 'NavigationLayout', '1', now());
DROP TABLE IF EXISTS `tb_sys_menu_permission`;
CREATE TABLE `tb_sys_menu_permission` (
@@ -204,12 +170,4 @@ CREATE TABLE `tb_sys_menu_permission` (
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_menu_permission` (`menu_id`, `permission_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- Insert menu-permission associations
INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, create_time) VALUES
('1', 'perm_system_manage', 'menu_system_manage', '1', now()),
('2', 'perm_system_dept_manage', 'menu_system_dept', '1', now()),
('3', 'perm_system_menu_manage', 'menu_system_menu', '1', now()),
('4', 'perm_system_permission_manage', 'menu_system_permission', '1', now()),
('5', 'perm_system_role_manage', 'menu_system_role', '1', now()),
('6', 'perm_system_user_manage', 'menu_system_user', '1', now());
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

View File

@@ -52,14 +52,6 @@ CREATE TABLE `tb_resource_category` (
KEY `idx_parent` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='资源分类表';
-- 插入默认分类(党史学习、领导讲话、政策解读、红色经典、专题报告、思政案例)
INSERT INTO `tb_resource_category` (id, category_id, name, description, order_num, creator, create_time) VALUES
('1', 'party_history', '党史学习', '党史学习相关资源', 1, '1', now()),
('2', 'leader_speech', '领导讲话', '领导讲话相关资源', 2, '1', now()),
('3', 'policy_interpretation', '政策解读', '政策解读相关资源', 3, '1', now()),
('4', 'red_classic', '红色经典', '红色经典相关资源', 4, '1', now()),
('5', 'special_report', '专题报告', '专题报告相关资源', 5, '1', now()),
('6', 'ideological_case', '思政案例', '思政案例相关资源', 6, '1', now());
-- Banner管理表
DROP TABLE IF EXISTS `tb_banner`;

View File

@@ -48,21 +48,6 @@ CREATE TABLE `tb_sys_config` (
KEY `idx_group` (`config_group`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='系统配置表';
-- 插入默认系统配置
INSERT INTO `tb_sys_config` (id, config_key, config_value, config_type, config_group, description, is_system, creator, create_time) VALUES
('1', 'system.platform.name', '思政学习平台', 'string', 'platform', '平台名称', 1, '1', now()),
('2', 'system.platform.logo', '/assets/logo.png', 'string', 'platform', '平台Logo', 1, '1', now()),
('3', 'system.platform.school_badge', '/assets/school_badge.png', 'string', 'platform', '学校校徽', 1, '1', now()),
('4', 'system.menu.home', '首页', 'string', 'menu', '首页菜单名称', 0, '1', now()),
('5', 'system.menu.resource', '资源中心', 'string', 'menu', '资源中心菜单名称', 0, '1', now()),
('6', 'system.menu.learning', '学习计划', 'string', 'menu', '学习计划菜单名称', 0, '1', now()),
('7', 'system.menu.activity', '专题活动', 'string', 'menu', '专题活动菜单名称', 0, '1', now()),
('8', 'system.menu.culture', '红色常信', 'string', 'menu', '红色常信菜单名称', 0, '1', now()),
('9', 'system.banner.auto_play', 'true', 'boolean', 'banner', 'Banner自动播放', 0, '1', now()),
('10', 'system.banner.interval', '5000', 'number', 'banner', 'Banner切换间隔毫秒', 0, '1', now()),
('11', 'system.resource.auto_publish', 'false', 'boolean', 'resource', '资源自动发布', 0, '1', now()),
('12', 'system.resource.auto_publish_time', '08:00', 'string', 'resource', '自动发布时间', 0, '1', now()),
('13', 'system.ai.enabled', 'true', 'boolean', 'ai', '是否启用智能体', 0, '1', now());
-- 系统访问统计表
DROP TABLE IF EXISTS `tb_sys_visit_statistics`;

View File

@@ -20,8 +20,6 @@ CREATE TABLE `tb_sys_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- 推荐:把默认 admin 密码替换为已哈希的值
INSERT INTO `tb_sys_user` (id, username, password, email, status) VALUES
('1', 'admin', '$2a$10$/Bo2SXboVUpYfR6EA.y8puYQaMGBcuNYFY/EkQRY3w27IH56EuEcS', '3223905473@qq.com', 0);
-- 用户信息表
DROP TABLE IF EXISTS `tb_sys_user_info`;
@@ -43,7 +41,6 @@ CREATE TABLE `tb_sys_user_info` (
UNIQUE KEY `uk_user_info_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_user_info` (id, user_id, full_name, avatar) VALUES ('1', '1', '管理员', 'default');
DROP TABLE IF EXISTS `tb_sys_login_log`;
CREATE TABLE `tb_sys_login_log` (

View File

@@ -38,11 +38,33 @@ SOURCE createTableSystem.sql;
-- 11. 创建文件系统相关表
SOURCE createTableFile.sql;
-- =====================================================
-- 插入初始数据
-- =====================================================
-- 12. 插入菜单和权限相关数据
SOURCE initMenuData.sql;
SOURCE initAllData.sql;
-- -- 13. 插入资源相关初始数据
-- SOURCE initResourceData.sql;
-- -- 14. 插入AI相关初始数据
-- SOURCE initAIData.sql;
-- -- 15. 插入系统相关初始数据
-- SOURCE initSystemData.sql;
-- -- 16. 插入用户相关初始数据
-- SOURCE initUserData.sql;
-- =====================================================
-- 初始化完成
-- =====================================================
-- 数据库: school_news
-- 表数量: 50+ 张表
-- 默认用户: admin (密码需要查看 createTableUser.sql)
-- 默认用户: admin (密码: admin123)
-- 默认角色: admin (管理员), freedom (自由角色)
-- 默认部门: root_department (超级部门), default_department (默认部门)
-- =====================================================

View File

@@ -0,0 +1,39 @@
use school_news;
-- 插入AI智能体配置数据
INSERT INTO `tb_ai_agent_config` (id, name, system_prompt, model_name, temperature, max_tokens, status, creator, create_time) VALUES
('1', '思政小帮手', '你是一个专业的思政学习助手,致力于帮助用户学习思想政治理论知识。请基于提供的知识库内容,为用户提供准确、简洁的回答。', 'gpt-3.5-turbo', 0.7, 2000, 1, '1', now());
-- 插入资源分类数据
INSERT INTO `tb_resource_category` (id, category_id, name, description, order_num, creator, create_time) VALUES
('1', 'party_history', '党史学习', '党史学习相关资源', 1, '1', now()),
('2', 'leader_speech', '领导讲话', '领导讲话相关资源', 2, '1', now()),
('3', 'policy_interpretation', '政策解读', '政策解读相关资源', 3, '1', now()),
('4', 'red_classic', '红色经典', '红色经典相关资源', 4, '1', now()),
('5', 'special_report', '专题报告', '专题报告相关资源', 5, '1', now()),
('6', 'world_case', '思政案例', '思政案例相关资源', 6, '1', now());
-- 插入系统配置数据
INSERT INTO `tb_sys_config` (id, config_key, config_value, config_type, config_group, description, is_system, creator, create_time) VALUES
('1', 'system.platform.name', '思政学习平台', 'string', 'platform', '平台名称', 1, '1', now()),
('2', 'system.platform.logo', '/assets/logo.png', 'string', 'platform', '平台Logo', 1, '1', now()),
('3', 'system.platform.school_badge', '/assets/school_badge.png', 'string', 'platform', '学校校徽', 1, '1', now()),
('4', 'system.menu.home', '首页', 'string', 'menu', '首页菜单名称', 0, '1', now()),
('5', 'system.menu.resource', '资源中心', 'string', 'menu', '资源中心菜单名称', 0, '1', now()),
('6', 'system.menu.learning', '学习计划', 'string', 'menu', '学习计划菜单名称', 0, '1', now()),
('7', 'system.menu.activity', '专题活动', 'string', 'menu', '专题活动菜单名称', 0, '1', now()),
('8', 'system.menu.culture', '红色常信', 'string', 'menu', '红色常信菜单名称', 0, '1', now()),
('9', 'system.banner.auto_play', 'true', 'boolean', 'banner', 'Banner自动播放', 0, '1', now()),
('10', 'system.banner.interval', '5000', 'number', 'banner', 'Banner切换间隔毫秒', 0, '1', now()),
('11', 'system.resource.auto_publish', 'false', 'boolean', 'resource', '资源自动发布', 0, '1', now()),
('12', 'system.resource.auto_publish_time', '08:00', 'string', 'resource', '自动发布时间', 0, '1', now()),
('13', 'system.ai.enabled', 'true', 'boolean', 'ai', '是否启用智能体', 0, '1', now());
-- 插入默认用户数据
INSERT INTO `tb_sys_user` (id, username, password, email, status) VALUES
('1', 'superadmin', '$2a$10$/Bo2SXboVUpYfR6EA.y8puYQaMGBcuNYFY/EkQRY3w27IH56EuEcS', '3223905473@qq.com', 0);
-- 插入默认用户信息数据
INSERT INTO `tb_sys_user_info` (id, user_id, full_name, avatar) VALUES
('1', '1', '管理员', 'default');

View File

@@ -0,0 +1,192 @@
use school_news;
-- 插入部门数据
INSERT INTO `tb_sys_dept` (id,dept_id,name, description) VALUES ('1','root_department', '超级部门', '系统超级部门');
INSERT INTO `tb_sys_dept` (id,dept_id,name, parent_id, description) VALUES ('2','default_department', '默认部门', 'root_department', '系统默认创建的部门');
-- 插入角色数据
INSERT INTO `tb_sys_role` (id,role_id, name, description) VALUES ('1','superadmin', '管理员', '系统管理员角色');
INSERT INTO `tb_sys_role` (id,role_id, name, description) VALUES ('2','freedom', '自由角色', '自由角色');
-- 插入部门-角色关联数据
INSERT INTO `tb_sys_dept_role` (id, dept_id, role_id, creator, create_time) VALUES
('1', 'root_department', 'superadmin', '1', now()),
('2', 'default_department', 'freedom', '1', now());
-- 插入用户-角色关联数据
INSERT INTO `tb_sys_user_dept_role` (id, user_id, dept_id, role_id, creator, create_time) VALUES ('1', '1', 'root_department', 'superadmin', '1', now());
-- 插入模块数据
INSERT INTO `tb_sys_module` (id, module_id, name, code, description, icon, order_num, status, creator, create_time) VALUES
('1', 'module_system', '系统管理', 'system', '系统管理模块', 'el-icon-setting', 1, 1, '1', now()),
('2', 'module_news', '新闻管理', 'news', '新闻管理模块', 'el-icon-document', 2, 1, '1', now()),
('3', 'module_study', '学习管理', 'study', '学习管理模块', 'el-icon-reading', 3, 1, '1', now()),
('4', 'module_ai', 'AI管理', 'ai', 'AI管理模块', 'el-icon-cpu', 4, 1, '1', now()),
('5', 'module_usercenter', '用户中心', 'usercenter', '用户中心模块', 'el-icon-user', 5, 1, '1', now()),
('6', 'module_file', '文件管理', 'file', '文件管理模块', 'el-icon-folder', 6, 1, '1', now());
-- 插入权限数据
INSERT INTO `tb_sys_permission` (id,permission_id, name, code, description, module_id, creator, create_time) VALUES
('0','perm_default', '默认权限', 'default', '默认权限', 'module_system', '1', now()),
('1','perm_system_manage', '系统管理', 'system:manage', '系统管理权限', 'module_system', '1', now()),
('2','perm_system_dept_manage', '系统部门查看', 'system:dept:manage', '系统部门查看权限', 'module_system', '1', now()),
('3','perm_system_menu_manage', '系统菜单查看', 'system:menu:manage', '系统菜单查看权限', 'module_system', '1', now()),
('4','perm_system_permission_manage', '系统权限查看', 'system:permission:manage', '系统权限查看权限', 'module_system', '1', now()),
('5','perm_system_role_manage', '系统角色查看', 'system:role:manage', '系统角色查看权限', 'module_system', '1', now()),
('6','perm_system_user_manage', '系统用户查看', 'system:user:manage', '系统用户查看权限', 'module_system', '1', now()),
('7','perm_system_module_manage', '系统模块查看', 'system:module:manage', '系统模块查看权限', 'module_system', '1', now()),
('8','perm_news_manage', '新闻管理', 'news:manage', '新闻管理权限', 'module_news', '1', now()),
('9','perm_study_manage', '学习管理', 'study:manage', '学习管理权限', 'module_study', '1', now()),
('10','perm_ai_manage', 'AI管理', 'ai:manage', 'AI管理权限', 'module_ai', '1', now()),
('11','perm_usercenter_manage', '用户中心管理', 'usercenter:manage', '用户中心管理权限', 'module_usercenter', '1', now()),
('12','perm_file_manage', '文件管理', 'file:manage', '文件管理权限', 'module_file', '1', now());
-- 插入角色-权限关联数据
INSERT INTO `tb_sys_role_permission` (id, role_id, permission_id, creator, create_time) VALUES
('0', 'superadmin', 'perm_default', '1', now()),
('1', 'superadmin', 'perm_system_manage', '1', now()),
('2', 'superadmin', 'perm_system_dept_manage', '1', now()),
('3', 'superadmin', 'perm_system_menu_manage', '1', now()),
('4', 'superadmin', 'perm_system_permission_manage', '1', now()),
('5', 'superadmin', 'perm_system_role_manage', '1', now()),
('6', 'superadmin', 'perm_system_user_manage', '1', now()),
('7', 'superadmin', 'perm_system_module_manage', '1', now()),
('8', 'superadmin', 'perm_news_manage', '1', now()),
('9', 'superadmin', 'perm_study_manage', '1', now()),
('10', 'superadmin', 'perm_ai_manage', '1', now()),
('11', 'superadmin', 'perm_usercenter_manage', '1', now()),
('12', 'superadmin', 'perm_file_manage', '1', now()),
('13', 'freedom', 'perm_default', '1', now());
-- 插入前端菜单数据
INSERT INTO `tb_sys_menu` (id, menu_id, name, parent_id, url, component, icon, order_num, type, layout, creator, create_time) VALUES
-- 资源中心
('200', 'menu_resource_center', '资源中心', NULL, '/resource-center', 'resource-center/ResourceCenterView', 'el-icon-folder-opened', 2, 1, 'BasicLayout', '1', now()),
('201', 'menu_party_history', '党史学习', 'menu_resource_center', '/resource-center/party-history', 'resource-center/PartyHistoryView', 'el-icon-trophy', 1, 1, 'BasicLayout', '1', now()),
('202', 'menu_leader_speech', '领导讲话', 'menu_resource_center', '/resource-center/leader-speech', 'resource-center/LeaderSpeechView', 'el-icon-microphone', 2, 1, 'BasicLayout', '1', now()),
('203', 'menu_policy_interpretation', '政策解读', 'menu_resource_center', '/resource-center/policy-interpretation', 'resource-center/PolicyInterpretationView', 'el-icon-document', 3, 1, 'BasicLayout', '1', now()),
('204', 'menu_red_classic', '红色经典', 'menu_resource_center', '/resource-center/red-classic', 'resource-center/RedClassicView', 'el-icon-star-on', 4, 1, 'BasicLayout', '1', now()),
('205', 'menu_special_report', '专题报告', 'menu_resource_center', '/resource-center/special-report', 'resource-center/SpecialReportView', 'el-icon-document-copy', 5, 1, 'BasicLayout', '1', now()),
('206', 'menu_world_case', '思政案例', 'menu_resource_center', '/resource-center/world-case', 'resource-center/WorldCaseView', 'el-icon-collection', 6, 1, 'BasicLayout', '1', now()),
-- 学习计划
('300', 'menu_study_plan', '学习计划', NULL, '/study-plan', 'study-plan/StudyPlanView', 'el-icon-reading', 3, 1, 'BasicLayout', '1', now()),
('301', 'menu_study_tasks', '学习任务', 'menu_study_plan', '/study-plan/tasks', 'study-plan/StudyTasksView', 'el-icon-s-order', 1, 1, 'BasicLayout', '1', now()),
('302', 'menu_course_center', '课程中心', 'menu_study_plan', '/study-plan/course', 'study-plan/CourseCenterView', 'el-icon-video-play', 2, 1, 'BasicLayout', '1', now()),
-- 个人中心
('400', 'menu_user_center', '个人中心', NULL, '/user-center', 'user-center/UserCenterView', 'el-icon-user', 4, 1, 'BasicLayout', '1', now()),
('401', 'menu_learning_records', '学习记录', 'menu_user_center', '/user-center/learning-records', 'user-center/LearningRecordsView', 'el-icon-document', 1, 1, 'BasicLayout', '1', now()),
('402', 'menu_my_favorites', '我的收藏', 'menu_user_center', '/user-center/favorites', 'user-center/MyFavoritesView', 'el-icon-star-on', 2, 1, 'BasicLayout', '1', now()),
('403', 'menu_my_achievements', '我的成就', 'menu_user_center', '/user-center/achievements', 'user-center/MyAchievementsView', 'el-icon-trophy', 3, 1, 'BasicLayout', '1', now()),
-- 账号中心
('500', 'menu_profile', '账号中心', NULL, '/profile', 'profile/ProfileView', 'el-icon-user-solid', 5, 1, 'BasicLayout', '1', now()),
('501', 'menu_personal_info', '个人信息', 'menu_profile', '/profile/personal-info', 'profile/PersonalInfoView', 'el-icon-user', 1, 1, 'BasicLayout', '1', now()),
('502', 'menu_account_settings', '账号设置', 'menu_profile', '/profile/account-settings', 'profile/AccountSettingsView', 'el-icon-setting', 2, 1, 'BasicLayout', '1', now()),
-- 智能体模块
('600', 'menu_ai_assistant', '智能体模块', NULL, '/ai-assistant', 'ai-assistant/AIAssistantView', 'el-icon-cpu', 6, 1, 'BasicLayout', '1', now());
-- 插入后端管理菜单数据
INSERT INTO `tb_sys_menu` (id, menu_id, name, parent_id, url, component, icon, order_num, type, layout, creator, create_time) VALUES
-- 系统总览
('1000', 'menu_admin_overview', '系统总览', NULL, '/admin/overview', 'admin/overview/SystemOverviewView', 'el-icon-data-analysis', 1, 1, 'NavigationLayout', '1', now()),
-- 用户管理
('2000', 'menu_sys_manage', '系统管理', NULL, '', '', 'el-icon-user', 2, 1, '', '1', now()),
('2001', 'menu_admin_user', '用户管理', 'menu_sys_manage', '/admin/manage/system/user', 'admin/manage/system/UserManageView', 'el-icon-user', 1, 1, 'NavigationLayout', '1', now()),
('2002', 'menu_admin_dept', '部门管理', 'menu_sys_manage', '/admin/manage/system/dept', 'admin/manage/system/DeptManageView', 'el-icon-office-building', 2, 1, 'NavigationLayout', '1', now()),
('2003', 'menu_admin_role', '角色管理', 'menu_sys_manage', '/admin/manage/system/role', 'admin/manage/system/RoleManageView', 'el-icon-user-solid', 3, 1, 'NavigationLayout', '1', now()),
('2004', 'menu_admin_permission', '权限管理', 'menu_sys_manage', '/admin/manage/system/permission', 'admin/manage/system/PermissionManageView', 'el-icon-key', 4, 1, 'NavigationLayout', '1', now()),
('2005', 'menu_admin_menu', '菜单管理', 'menu_sys_manage', '/admin/manage/system/menu', 'admin/manage/system/MenuManageView', 'el-icon-menu', 5, 1, 'NavigationLayout', '1', now()),
('2006', 'menu_admin_module', '模块管理', 'menu_sys_manage', '/admin/manage/system/module', 'admin/manage/system/ModuleManageView', 'el-icon-s-grid', 6, 1, 'NavigationLayout', '1', now()),
-- 资源管理
('3000', 'menu_admin_resource_manage', '资源管理', NULL, '', '', 'el-icon-folder', 3, 1, '', '1', now()),
('3001', 'menu_admin_resource', '资源管理', 'menu_admin_resource_manage', '/admin/manage/resource/resource', 'admin/manage/resource/ResourceManagementView', 'el-icon-folder', 1, 1, 'NavigationLayout', '1', now()),
('3002', 'menu_admin_article', '文章管理', 'menu_admin_resource_manage', '/admin/manage/resource/article', 'admin/manage/resource/ArticleManagementView', 'el-icon-document', 2, 1, 'NavigationLayout', '1', now()),
('3003', 'menu_admin_data_records', '数据记录', 'menu_admin_resource_manage', '/admin/manage/resource/data-records', 'admin/manage/resource/DataRecordsView', 'el-icon-data-line', 3, 1, 'NavigationLayout', '1', now()),
-- 运营管理
('4000', 'menu_admin_content_manage', '运营管理', NULL, '', '', 'el-icon-s-operation', 4, 1, '', '1', now()),
('4001', 'menu_admin_banner', 'Banner管理', 'menu_admin_content_manage', '/admin/manage/content/banner', 'admin/manage/content/BannerManagementView', 'el-icon-picture', 1, 1, 'NavigationLayout', '1', now()),
('4002', 'menu_admin_tag', '标签管理', 'menu_admin_content_manage', '/admin/manage/content/tag', 'admin/manage/content/TagManagementView', 'el-icon-price-tag', 2, 1, 'NavigationLayout', '1', now()),
('4003', 'menu_admin_column', '栏目管理', 'menu_admin_content_manage', '/admin/manage/content/column', 'admin/manage/content/ColumnManagementView', 'el-icon-menu', 3, 1, 'NavigationLayout', '1', now()),
('4004', 'menu_admin_content', '内容管理', 'menu_admin_content_manage', '/admin/manage/content/content', 'admin/manage/content/ContentManagementView', 'el-icon-document', 4, 1, 'NavigationLayout', '1', now()),
-- 学习管理
('5000', 'menu_admin_study_manage', '学习管理', NULL, '', '', 'el-icon-reading', 5, 1, '', '1', now()),
('5001', 'menu_admin_study', '学习管理', 'menu_admin_study_manage', '/admin/manage/study/study', 'admin/manage/study/StudyManagementView', 'el-icon-reading', 1, 1, 'NavigationLayout', '1', now()),
('5002', 'menu_admin_task_publish', '任务发布', 'menu_admin_study_manage', '/admin/manage/study/task-publish', 'admin/manage/study/TaskPublishView', 'el-icon-s-order', 2, 1, 'NavigationLayout', '1', now()),
('5003', 'menu_admin_study_records', '学习记录', 'menu_admin_study_manage', '/admin/manage/study/study-records', 'admin/manage/study/StudyRecordsView', 'el-icon-document', 3, 1, 'NavigationLayout', '1', now()),
-- 智能体管理
('6000', 'menu_admin_ai_manage', '智能体管理', NULL, '', '', 'el-icon-cpu', 6, 1, '', '1', now()),
('6001', 'menu_admin_ai', 'AI管理', 'menu_admin_ai_manage', '/admin/manage/ai/ai', 'admin/manage/ai/AIManagementView', 'el-icon-cpu', 1, 1, 'NavigationLayout', '1', now()),
('6002', 'menu_admin_ai_config', 'AI配置', 'menu_admin_ai_manage', '/admin/manage/ai/config', 'admin/manage/ai/AIConfigView', 'el-icon-setting', 2, 1, 'NavigationLayout', '1', now()),
('6003', 'menu_admin_knowledge', '知识库管理', 'menu_admin_ai_manage', '/admin/manage/ai/knowledge', 'admin/manage/ai/KnowledgeManagementView', 'el-icon-collection', 3, 1, 'NavigationLayout', '1', now()),
-- 系统日志
('7000', 'menu_admin_logs_manage', '系统日志', NULL, '', '', 'el-icon-document', 7, 1, '', '1', now()),
('7001', 'menu_admin_system_logs', '系统日志', 'menu_admin_logs_manage', '/admin/manage/logs/system', 'admin/manage/logs/SystemLogsView', 'el-icon-document', 1, 1, 'NavigationLayout', '1', now()),
('7002', 'menu_admin_login_logs', '登录日志', 'menu_admin_logs_manage', '/admin/manage/logs/login', 'admin/manage/logs/LoginLogsView', 'el-icon-key', 2, 1, 'NavigationLayout', '1', now()),
('7003', 'menu_admin_operation_logs', '操作日志', 'menu_admin_logs_manage', '/admin/manage/logs/operation', 'admin/manage/logs/OperationLogsView', 'el-icon-s-operation', 3, 1, 'NavigationLayout', '1', now()),
('7004', 'menu_admin_system_config', '系统配置', 'menu_admin_logs_manage', '/admin/manage/logs/config', 'admin/manage/logs/SystemConfigView', 'el-icon-setting', 4, 1, 'NavigationLayout', '1', now());
-- 插入菜单权限关联数据
INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, create_time) VALUES
-- 前端菜单权限关联
('100', 'perm_default', 'menu_home', '1', now()),
('101', 'perm_default', 'menu_resource_center', '1', now()),
('102', 'perm_default', 'menu_party_history', '1', now()),
('103', 'perm_default', 'menu_leader_speech', '1', now()),
('104', 'perm_default', 'menu_policy_interpretation', '1', now()),
('105', 'perm_default', 'menu_red_classic', '1', now()),
('106', 'perm_default', 'menu_special_report', '1', now()),
('107', 'perm_default', 'menu_world_case', '1', now()),
('108', 'perm_default', 'menu_study_plan', '1', now()),
('109', 'perm_default', 'menu_study_tasks', '1', now()),
('110', 'perm_default', 'menu_course_center', '1', now()),
('111', 'perm_default', 'menu_user_center', '1', now()),
('112', 'perm_default', 'menu_learning_records', '1', now()),
('113', 'perm_default', 'menu_my_favorites', '1', now()),
('114', 'perm_default', 'menu_my_achievements', '1', now()),
('115', 'perm_default', 'menu_profile', '1', now()),
('116', 'perm_default', 'menu_personal_info', '1', now()),
('117', 'perm_default', 'menu_account_settings', '1', now()),
('118', 'perm_ai_manage', 'menu_ai_assistant', '1', now()),
-- 后端管理菜单权限关联
('200', 'perm_system_manage', 'menu_admin_overview', '1', now()),
('201', 'perm_system_manage', 'menu_sys_manage', '1', now()),
('202', 'perm_system_user_manage', 'menu_admin_user_manage', '1', now()),
('203', 'perm_system_user_manage', 'menu_admin_user', '1', now()),
('204', 'perm_system_dept_manage', 'menu_admin_dept', '1', now()),
('205', 'perm_system_role_manage', 'menu_admin_role', '1', now()),
('206', 'perm_system_permission_manage', 'menu_admin_permission', '1', now()),
('207', 'perm_system_menu_manage', 'menu_admin_menu', '1', now()),
('208', 'perm_system_module_manage', 'menu_admin_module', '1', now()),
('209', 'perm_news_manage', 'menu_admin_resource_manage', '1', now()),
('210', 'perm_news_manage', 'menu_admin_resource', '1', now()),
('211', 'perm_news_manage', 'menu_admin_article', '1', now()),
('212', 'perm_news_manage', 'menu_admin_data_records', '1', now()),
('213', 'perm_news_manage', 'menu_admin_content_manage', '1', now()),
('214', 'perm_news_manage', 'menu_admin_banner', '1', now()),
('215', 'perm_news_manage', 'menu_admin_tag', '1', now()),
('216', 'perm_news_manage', 'menu_admin_column', '1', now()),
('217', 'perm_news_manage', 'menu_admin_content', '1', now()),
('218', 'perm_study_manage', 'menu_admin_study_manage', '1', now()),
('219', 'perm_study_manage', 'menu_admin_study', '1', now()),
('220', 'perm_study_manage', 'menu_admin_task_publish', '1', now()),
('221', 'perm_study_manage', 'menu_admin_study_records', '1', now()),
('222', 'perm_ai_manage', 'menu_admin_ai_manage', '1', now()),
('223', 'perm_ai_manage', 'menu_admin_ai', '1', now()),
('224', 'perm_ai_manage', 'menu_admin_ai_config', '1', now()),
('225', 'perm_ai_manage', 'menu_admin_knowledge', '1', now()),
('226', 'perm_system_manage', 'menu_admin_logs_manage', '1', now()),
('227', 'perm_system_manage', 'menu_admin_system_logs', '1', now()),
('228', 'perm_system_manage', 'menu_admin_login_logs', '1', now()),
('229', 'perm_system_manage', 'menu_admin_operation_logs', '1', now()),
('230', 'perm_system_manage', 'menu_admin_system_config', '1', now());

View File

@@ -0,0 +1,184 @@
#!/bin/bash
# =====================================================
# 校园思政新闻平台数据库重新初始化脚本
# 版本: 1.0.0
# 说明: 该脚本会删除现有数据库,重新创建并初始化所有数据
# 注意: 执行前请确保MySQL服务已启动并且有足够的权限
# =====================================================
# 设置颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 数据库配置
DB_HOST="localhost"
DB_PORT="3306"
DB_USER="root"
DB_PASSWORD="123456"
DB_NAME="school_news"
# 脚本目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 日志文件
LOG_FILE="$SCRIPT_DIR/reInit.log"
# 打印带颜色的消息
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" >> "$LOG_FILE"
}
# 检查MySQL连接
check_mysql_connection() {
print_message $BLUE "检查MySQL连接..."
if command -v mysql &> /dev/null; then
if mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -e "SELECT 1;" &> /dev/null; then
print_message $GREEN "MySQL连接成功"
return 0
else
print_message $RED "MySQL连接失败请检查配置"
return 1
fi
else
print_message $RED "MySQL客户端未安装或不在PATH中"
return 1
fi
}
# 备份现有数据库(如果存在)
backup_database() {
if mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -e "USE $DB_NAME;" &> /dev/null; then
print_message $YELLOW "发现现有数据库,正在备份..."
local backup_file="$SCRIPT_DIR/backup_${DB_NAME}_$(date +%Y%m%d_%H%M%S).sql"
mysqldump -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > "$backup_file"
if [ $? -eq 0 ]; then
print_message $GREEN "数据库备份成功: $backup_file"
else
print_message $YELLOW "数据库备份失败,继续执行..."
fi
fi
}
# 删除现有数据库
drop_database() {
print_message $YELLOW "删除现有数据库..."
mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -e "DROP DATABASE IF EXISTS $DB_NAME;"
if [ $? -eq 0 ]; then
print_message $GREEN "数据库删除成功"
else
print_message $RED "数据库删除失败"
exit 1
fi
}
# 执行初始化脚本
execute_init_script() {
print_message $BLUE "开始执行数据库初始化..."
# 切换到脚本目录
cd "$SCRIPT_DIR"
# 执行initAll.sql
mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" < initAll.sql
if [ $? -eq 0 ]; then
print_message $GREEN "数据库初始化成功"
else
print_message $RED "数据库初始化失败"
exit 1
fi
}
# 验证初始化结果
verify_initialization() {
print_message $BLUE "验证初始化结果..."
# 检查数据库是否存在
if mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -e "USE $DB_NAME;" &> /dev/null; then
print_message $GREEN "数据库创建成功"
else
print_message $RED "数据库创建失败"
exit 1
fi
# 检查表数量
local table_count=$(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -D"$DB_NAME" -e "SHOW TABLES;" | wc -l)
print_message $GREEN "创建了 $table_count 张表"
# 检查默认用户
local user_count=$(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -D"$DB_NAME" -e "SELECT COUNT(*) FROM tb_sys_user WHERE username='admin';" | tail -n 1)
if [ "$user_count" -gt 0 ]; then
print_message $GREEN "默认用户创建成功"
else
print_message $YELLOW "默认用户创建失败"
fi
}
# 显示初始化信息
show_initialization_info() {
print_message $BLUE "====================================================="
print_message $GREEN "数据库初始化完成!"
print_message $BLUE "====================================================="
print_message $YELLOW "数据库信息:"
print_message $YELLOW " 数据库名: $DB_NAME"
print_message $YELLOW " 主机: $DB_HOST"
print_message $YELLOW " 端口: $DB_PORT"
print_message $YELLOW " 用户: $DB_USER"
print_message $BLUE "====================================================="
print_message $YELLOW "默认账户信息:"
print_message $YELLOW " 用户名: admin"
print_message $YELLOW " 密码: admin123"
print_message $YELLOW " 角色: 管理员"
print_message $BLUE "====================================================="
print_message $YELLOW "系统功能:"
print_message $YELLOW " - 用户管理"
print_message $YELLOW " - 权限管理"
print_message $YELLOW " - 资源管理"
print_message $YELLOW " - 学习管理"
print_message $YELLOW " - AI智能体"
print_message $YELLOW " - 系统配置"
print_message $BLUE "====================================================="
}
# 主函数
main() {
print_message $BLUE "====================================================="
print_message $BLUE "校园思政新闻平台数据库重新初始化脚本"
print_message $BLUE "版本: 1.0.0"
print_message $BLUE "====================================================="
# 检查MySQL连接
if ! check_mysql_connection; then
exit 1
fi
# 备份现有数据库
# backup_database
# 删除现有数据库
# drop_database
# 执行初始化脚本
execute_init_script
# 验证初始化结果
verify_initialization
# 显示初始化信息
show_initialization_info
print_message $GREEN "初始化完成!"
}
# 脚本入口
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
main "$@"
fi

View File

@@ -0,0 +1,186 @@
package org.xyzh.api.system.module;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.system.TbSysModule;
import org.xyzh.common.core.domain.ResultDomain;
import java.util.List;
/**
* @description 系统模块服务接口
* @filename ModuleService.java
* @author yslg
* @copyright xyzh
* @since 2025-10-16
*/
public interface ModuleService {
/**
* @description 查询模块列表
* @param filter 过滤条件
* @return ResultDomain<TbSysModule> 模块列表
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> getModuleList(TbSysModule filter);
/**
* @description 根据模块ID查询模块信息
* @param moduleID 模块ID
* @return ResultDomain<TbSysModule> 模块信息
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> getModuleById(String moduleID);
/**
* @description 根据模块代码查询模块信息
* @param code 模块代码
* @return ResultDomain<TbSysModule> 模块信息
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> getModuleByCode(String code);
/**
* @description 查询启用的模块列表
* @return ResultDomain<TbSysModule> 启用的模块列表
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> getActiveModules();
/**
* @description 创建模块
* @param module 模块信息
* @return ResultDomain<TbSysModule> 创建结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> createModule(TbSysModule module);
/**
* @description 更新模块
* @param module 模块信息
* @return ResultDomain<TbSysModule> 更新结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> updateModule(TbSysModule module);
/**
* @description 删除模块
* @param moduleID 模块ID
* @return ResultDomain<Boolean> 删除结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> deleteModule(String moduleID);
/**
* @description 批量删除模块
* @param moduleIDs 模块ID列表
* @return ResultDomain<Boolean> 删除结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> batchDeleteModules(List<String> moduleIDs);
/**
* @description 更新模块状态
* @param moduleID 模块ID
* @param status 状态
* @return ResultDomain<Boolean> 更新结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> updateModuleStatus(String moduleID, Integer status);
/**
* @description 更新模块排序
* @param moduleID 模块ID
* @param orderNum 排序号
* @return ResultDomain<Boolean> 更新结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> updateModuleOrder(String moduleID, Integer orderNum);
/**
* @description 分页查询模块列表
* @param filter 过滤条件
* @param pageParam 分页参数
* @return ResultDomain<TbSysModule> 模块列表
* @author yslg
* @since 2025-10-16
*/
ResultDomain<TbSysModule> getModuleListPage(TbSysModule filter, PageParam pageParam);
/**
* @description 统计模块数量
* @param filter 过滤条件
* @return ResultDomain<Long> 模块数量
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Long> countModules(TbSysModule filter);
/**
* @description 检查模块代码是否存在
* @param code 模块代码
* @param excludeID 排除的模块ID
* @return ResultDomain<Boolean> 是否存在
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> checkModuleCodeExists(String code, String excludeID);
/**
* @description 绑定权限到模块
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 绑定结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> bindPermissionsToModule(String moduleID, List<String> permissionIds);
/**
* @description 解绑模块的权限
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 解绑结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> unbindPermissionsFromModule(String moduleID, List<String> permissionIds);
/**
* @description 获取模块的权限列表
* @param moduleID 模块ID
* @return ResultDomain<List<String>> 权限ID列表
* @author yslg
* @since 2025-10-16
*/
ResultDomain<List<String>> getModulePermissions(String moduleID);
/**
* @description 批量绑定权限到模块
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 绑定结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> batchBindPermissionsToModule(String moduleID, List<String> permissionIds);
/**
* @description 批量解绑模块的权限
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 解绑结果
* @author yslg
* @since 2025-10-16
*/
ResultDomain<Boolean> batchUnbindPermissionsFromModule(String moduleID, List<String> permissionIds);
}

View File

@@ -54,6 +54,13 @@ public class TbSysPermission extends BaseDTO{
*/
private String updater;
/**
* @description 所属模块ID
* @author yslg
* @since 2025-10-16
*/
private String moduleID;
public String getPermissionID() {
return permissionID;
}
@@ -102,6 +109,14 @@ public class TbSysPermission extends BaseDTO{
this.updater = updater;
}
public String getModuleID() {
return moduleID;
}
public void setModuleID(String moduleID) {
this.moduleID = moduleID;
}
@Override
public String toString() {
return "TbSysPermission{" +
@@ -110,6 +125,7 @@ public class TbSysPermission extends BaseDTO{
", name='" + name + '\'' +
", description='" + description + '\'' +
", code='" + code + '\'' +
", moduleID='" + moduleID + '\'' +
", creator='" + creator + '\'' +
", updater='" + updater + '\'' +
", createTime=" + getCreateTime() +

View File

@@ -0,0 +1,146 @@
package org.xyzh.common.dto.system;
import org.xyzh.common.dto.BaseDTO;
/**
* @description 系统模块表
* @filename TbSysModule.java
* @author yslg
* @copyright xyzh
* @since 2025-10-16
*/
public class TbSysModule extends BaseDTO {
private static final long serialVersionUID = 1L;
/**
* @description 模块ID
*/
private String moduleID;
/**
* @description 模块名称
*/
private String name;
/**
* @description 模块代码
*/
private String code;
/**
* @description 模块描述
*/
private String description;
/**
* @description 模块图标
*/
private String icon;
/**
* @description 模块排序号
*/
private Integer orderNum;
/**
* @description 模块状态0禁用 1启用
*/
private Integer status;
/**
* @description 创建者
*/
private String creator;
/**
* @description 更新者
*/
private String updater;
public String getModuleID() {
return moduleID;
}
public void setModuleID(String moduleID) {
this.moduleID = moduleID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public Integer getOrderNum() {
return orderNum;
}
public void setOrderNum(Integer orderNum) {
this.orderNum = orderNum;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getUpdater() {
return updater;
}
public void setUpdater(String updater) {
this.updater = updater;
}
@Override
public String toString() {
return "TbSysModule{" +
"id=" + getID() +
", moduleID='" + moduleID + '\'' +
", name='" + name + '\'' +
", code='" + code + '\'' +
", description='" + description + '\'' +
", icon='" + icon + '\'' +
", orderNum=" + orderNum +
", status=" + status +
'}';
}
}

View File

@@ -0,0 +1,257 @@
package org.xyzh.system.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.system.module.ModuleService;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.system.TbSysModule;
import org.xyzh.common.core.domain.ResultDomain;
import java.util.List;
/**
* @description 系统模块控制器
* @filename ModuleController.java
* @author yslg
* @copyright xyzh
* @since 2025-10-16
*/
@RestController
@RequestMapping("/system/module")
@CrossOrigin(origins = "*")
public class ModuleController {
@Autowired
private ModuleService moduleService;
/**
* @description 查询模块列表
* @param filter 过滤条件
* @return ResultDomain<TbSysModule> 模块列表
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/list")
public ResultDomain<TbSysModule> getModuleList(@RequestBody(required = false) TbSysModule filter) {
return moduleService.getModuleList(filter);
}
/**
* @description 根据模块ID查询模块信息
* @param moduleID 模块ID
* @return ResultDomain<TbSysModule> 模块信息
* @author yslg
* @since 2025-10-16
*/
@GetMapping("/{moduleID}")
public ResultDomain<TbSysModule> getModuleById(@PathVariable String moduleID) {
return moduleService.getModuleById(moduleID);
}
/**
* @description 根据模块代码查询模块信息
* @param code 模块代码
* @return ResultDomain<TbSysModule> 模块信息
* @author yslg
* @since 2025-10-16
*/
@GetMapping("/code/{code}")
public ResultDomain<TbSysModule> getModuleByCode(@PathVariable String code) {
return moduleService.getModuleByCode(code);
}
/**
* @description 查询启用的模块列表
* @return ResultDomain<TbSysModule> 启用的模块列表
* @author yslg
* @since 2025-10-16
*/
@GetMapping("/active")
public ResultDomain<TbSysModule> getActiveModules() {
return moduleService.getActiveModules();
}
/**
* @description 创建模块
* @param module 模块信息
* @return ResultDomain<TbSysModule> 创建结果
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/create")
public ResultDomain<TbSysModule> createModule(@RequestBody TbSysModule module) {
return moduleService.createModule(module);
}
/**
* @description 更新模块
* @param module 模块信息
* @return ResultDomain<TbSysModule> 更新结果
* @author yslg
* @since 2025-10-16
*/
@PutMapping("/update")
public ResultDomain<TbSysModule> updateModule(@RequestBody TbSysModule module) {
return moduleService.updateModule(module);
}
/**
* @description 删除模块
* @param moduleID 模块ID
* @return ResultDomain<Boolean> 删除结果
* @author yslg
* @since 2025-10-16
*/
@DeleteMapping("/{moduleID}")
public ResultDomain<Boolean> deleteModule(@PathVariable String moduleID) {
return moduleService.deleteModule(moduleID);
}
/**
* @description 批量删除模块
* @param moduleIDs 模块ID列表
* @return ResultDomain<Boolean> 删除结果
* @author yslg
* @since 2025-10-16
*/
@DeleteMapping("/batch")
public ResultDomain<Boolean> batchDeleteModules(@RequestBody List<String> moduleIDs) {
return moduleService.batchDeleteModules(moduleIDs);
}
/**
* @description 更新模块状态
* @param moduleID 模块ID
* @param status 状态
* @return ResultDomain<Boolean> 更新结果
* @author yslg
* @since 2025-10-16
*/
@PutMapping("/{moduleID}/status/{status}")
public ResultDomain<Boolean> updateModuleStatus(@PathVariable String moduleID, @PathVariable Integer status) {
return moduleService.updateModuleStatus(moduleID, status);
}
/**
* @description 更新模块排序
* @param moduleID 模块ID
* @param orderNum 排序号
* @return ResultDomain<Boolean> 更新结果
* @author yslg
* @since 2025-10-16
*/
@PutMapping("/{moduleID}/order/{orderNum}")
public ResultDomain<Boolean> updateModuleOrder(@PathVariable String moduleID, @PathVariable Integer orderNum) {
return moduleService.updateModuleOrder(moduleID, orderNum);
}
/**
* @description 分页查询模块列表
* @param filter 过滤条件
* @param pageParam 分页参数
* @return ResultDomain<TbSysModule> 模块列表
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/page")
public ResultDomain<TbSysModule> getModuleListPage(@RequestBody(required = false) TbSysModule filter,
@RequestParam(defaultValue = "1") int pageNumber,
@RequestParam(defaultValue = "10") int pageSize) {
PageParam pageParam = new PageParam(pageNumber, pageSize);
return moduleService.getModuleListPage(filter, pageParam);
}
/**
* @description 统计模块数量
* @param filter 过滤条件
* @return ResultDomain<Long> 模块数量
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/count")
public ResultDomain<Long> countModules(@RequestBody(required = false) TbSysModule filter) {
return moduleService.countModules(filter);
}
/**
* @description 检查模块代码是否存在
* @param code 模块代码
* @param excludeID 排除的模块ID
* @return ResultDomain<Boolean> 是否存在
* @author yslg
* @since 2025-10-16
*/
@GetMapping("/check-code")
public ResultDomain<Boolean> checkModuleCodeExists(@RequestParam String code,
@RequestParam(required = false) String excludeID) {
return moduleService.checkModuleCodeExists(code, excludeID);
}
/**
* @description 绑定权限到模块
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 绑定结果
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/{moduleID}/bind-permissions")
public ResultDomain<Boolean> bindPermissionsToModule(@PathVariable String moduleID,
@RequestBody List<String> permissionIds) {
return moduleService.bindPermissionsToModule(moduleID, permissionIds);
}
/**
* @description 解绑模块的权限
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 解绑结果
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/{moduleID}/unbind-permissions")
public ResultDomain<Boolean> unbindPermissionsFromModule(@PathVariable String moduleID,
@RequestBody List<String> permissionIds) {
return moduleService.unbindPermissionsFromModule(moduleID, permissionIds);
}
/**
* @description 获取模块的权限列表
* @param moduleID 模块ID
* @return ResultDomain<List<String>> 权限ID列表
* @author yslg
* @since 2025-10-16
*/
@GetMapping("/{moduleID}/permissions")
public ResultDomain<List<String>> getModulePermissions(@PathVariable String moduleID) {
return moduleService.getModulePermissions(moduleID);
}
/**
* @description 批量绑定权限到模块
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 绑定结果
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/{moduleID}/batch-bind-permissions")
public ResultDomain<Boolean> batchBindPermissionsToModule(@PathVariable String moduleID,
@RequestBody List<String> permissionIds) {
return moduleService.batchBindPermissionsToModule(moduleID, permissionIds);
}
/**
* @description 批量解绑模块的权限
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return ResultDomain<Boolean> 解绑结果
* @author yslg
* @since 2025-10-16
*/
@PostMapping("/{moduleID}/batch-unbind-permissions")
public ResultDomain<Boolean> batchUnbindPermissionsFromModule(@PathVariable String moduleID,
@RequestBody List<String> permissionIds) {
return moduleService.batchUnbindPermissionsFromModule(moduleID, permissionIds);
}
}

View File

@@ -0,0 +1,149 @@
package org.xyzh.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.system.TbSysModule;
import java.util.List;
/**
* @description 系统模块数据访问层
* @filename ModuleMapper.java
* @author yslg
* @copyright xyzh
* @since 2025-10-16
*/
@Mapper
public interface ModuleMapper extends BaseMapper<TbSysModule> {
/**
* @description 查询模块列表
* @param filter 过滤条件
* @return List<TbSysModule> 模块列表
* @author yslg
* @since 2025-10-16
*/
List<TbSysModule> selectModules(TbSysModule filter);
/**
* @description 根据模块ID查询模块信息
* @param moduleID 模块ID
* @return TbSysModule 模块信息
* @author yslg
* @since 2025-10-16
*/
TbSysModule selectByModuleID(@Param("moduleID") String moduleID);
/**
* @description 根据模块代码查询模块信息
* @param code 模块代码
* @return TbSysModule 模块信息
* @author yslg
* @since 2025-10-16
*/
TbSysModule selectByCode(@Param("code") String code);
/**
* @description 查询启用的模块列表
* @return List<TbSysModule> 启用的模块列表
* @author yslg
* @since 2025-10-16
*/
List<TbSysModule> selectActiveModules();
/**
* @description 检查模块代码是否存在
* @param code 模块代码
* @param excludeID 排除的模块ID
* @return int 存在的数量
* @author yslg
* @since 2025-10-16
*/
int countByCode(@Param("code") String code, @Param("excludeID") String excludeID);
/**
* @description 插入模块
* @param module 模块信息
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int insertModule(TbSysModule module);
/**
* @description 更新模块
* @param module 模块信息
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int updateModule(TbSysModule module);
/**
* @description 删除模块
* @param module 模块信息
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int deleteModule(TbSysModule module);
/**
* @description 批量插入模块
* @param moduleList 模块列表
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int batchInsertModules(@Param("moduleList") List<TbSysModule> moduleList);
/**
* @description 批量删除模块
* @param moduleIDs 模块ID列表
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int batchDeleteModules(@Param("moduleIDs") List<String> moduleIDs);
/**
* @description 分页查询模块列表
* @param filter 过滤条件
* @param pageParam 分页参数
* @return List<TbSysModule> 模块列表
* @author yslg
* @since 2025-10-16
*/
List<TbSysModule> selectModulesPage(@Param("filter") TbSysModule filter, @Param("pageParam") PageParam pageParam);
/**
* @description 统计模块数量
* @param filter 过滤条件
* @return long 模块数量
* @author yslg
* @since 2025-10-16
*/
long countModules(@Param("filter") TbSysModule filter);
/**
* @description 更新模块状态
* @param moduleID 模块ID
* @param status 状态
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int updateModuleStatus(@Param("moduleID") String moduleID, @Param("status") Integer status);
/**
* @description 更新模块排序
* @param moduleID 模块ID
* @param orderNum 排序号
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int updateModuleOrder(@Param("moduleID") String moduleID, @Param("orderNum") Integer orderNum);
}

View File

@@ -58,12 +58,12 @@ public interface PermissionMapper extends BaseMapper<TbSysPermission> {
/**
* @description 根据角色ID查询权限列表
* @param roleId 角色ID
* @param roleID 角色ID
* @return List<TbSysPermission> 权限列表
* @author yslg
* @since 2025-09-28
*/
List<TbSysPermission> selectPermissionsByRoleId(@Param("roleId") String roleId);
List<TbSysPermission> selectPermissionsByRoleID(@Param("roleID") String roleID);
/**
* @description 根据权限编码查询权限
@@ -77,22 +77,22 @@ public interface PermissionMapper extends BaseMapper<TbSysPermission> {
/**
* @description 检查权限名称是否存在
* @param permissionName 权限名称
* @param excludeId 排除的权限ID
* @param excludeID 排除的权限ID
* @return int 存在数量
* @author yslg
* @since 2025-09-28
*/
int countByPermissionName(@Param("permissionName") String permissionName, @Param("excludeId") String excludeId);
int countByPermissionName(@Param("permissionName") String permissionName, @Param("excludeID") String excludeID);
/**
* @description 检查权限编码是否存在
* @param permissionCode 权限编码
* @param excludeId 排除的权限ID
* @param excludeID 排除的权限ID
* @return int 存在数量
* @author yslg
* @since 2025-09-28
*/
int countByPermissionCode(@Param("permissionCode") String permissionCode, @Param("excludeId") String excludeId);
int countByPermissionCode(@Param("permissionCode") String permissionCode, @Param("excludeID") String excludeID);
/**
* @description 批量删除权限(逻辑删除)
@@ -157,4 +157,42 @@ public interface PermissionMapper extends BaseMapper<TbSysPermission> {
* @since 2025-10-08
*/
List<TbSysRole> selectPermissionBindRole(@Param("permission") PermissionVO permission);
/**
* @description 根据模块ID查询权限列表
* @param moduleID 模块ID
* @return List<TbSysPermission> 权限列表
* @author yslg
* @since 2025-10-16
*/
List<TbSysPermission> selectPermissionsByModuleID(@Param("moduleID") String moduleID);
/**
* @description 绑定权限到模块
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int bindPermissionsToModule(@Param("moduleID") String moduleID, @Param("permissionIds") List<String> permissionIds);
/**
* @description 解绑模块的权限
* @param moduleID 模块ID
* @param permissionIds 权限ID列表
* @return int 影响行数
* @author yslg
* @since 2025-10-16
*/
int unbindPermissionsFromModule(@Param("moduleID") String moduleID, @Param("permissionIds") List<String> permissionIds);
/**
* @description 获取模块的权限ID列表
* @param moduleID 模块ID
* @return List<String> 权限ID列表
* @author yslg
* @since 2025-10-16
*/
List<String> getModulePermissionIds(@Param("moduleID") String moduleID);
}

View File

@@ -0,0 +1,14 @@
package org.xyzh.system.module;
import org.xyzh.api.system.module.ModuleService;
/**
* @description 系统模块服务接口
* @filename SysModuleService.java
* @author yslg
* @copyright xyzh
* @since 2025-10-16
*/
public interface SysModuleService extends ModuleService{
}

View File

@@ -0,0 +1,407 @@
package org.xyzh.system.module.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.system.TbSysModule;
import org.xyzh.common.utils.IDUtils;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.system.mapper.ModuleMapper;
import org.xyzh.system.mapper.PermissionMapper;
import org.xyzh.api.system.module.ModuleService;
import java.util.Date;
import java.util.List;
/**
* @description 系统模块服务实现类
* @filename ModuleServiceImpl.java
* @author yslg
* @copyright xyzh
* @since 2025-10-16
*/
@Service
public class ModuleServiceImpl implements ModuleService {
@Autowired
private ModuleMapper moduleMapper;
@Autowired
private PermissionMapper permissionMapper;
@Override
public ResultDomain<TbSysModule> getModuleList(TbSysModule filter) {
try {
List<TbSysModule> modules = moduleMapper.selectModules(filter);
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.success("查询成功", modules);
return result;
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("查询模块列表失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<TbSysModule> getModuleById(String moduleID) {
try {
TbSysModule module = moduleMapper.selectByModuleID(moduleID);
if (module == null) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("模块不存在");
return result;
}
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.success("查询成功", module);
return result;
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("查询模块信息失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<TbSysModule> getModuleByCode(String code) {
try {
TbSysModule module = moduleMapper.selectByCode(code);
if (module == null) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("模块不存在");
return result;
}
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.success("查询成功", module);
return result;
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("查询模块信息失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<TbSysModule> getActiveModules() {
try {
List<TbSysModule> modules = moduleMapper.selectActiveModules();
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.success("查询成功", modules);
return result;
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("查询启用模块列表失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<TbSysModule> createModule(TbSysModule module) {
try {
// 检查模块代码是否已存在
int count = moduleMapper.countByCode(module.getCode(), null);
if (count > 0) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("模块代码已存在");
return result;
}
// 设置ID和创建时间
module.setID(IDUtils.generateID());
module.setModuleID(IDUtils.generateID());
module.setCreateTime(new Date());
module.setUpdateTime(new Date());
module.setDeleted(false);
int result = moduleMapper.insertModule(module);
if (result > 0) {
ResultDomain<TbSysModule> resultDomain = new ResultDomain<>();
resultDomain.success("创建成功", module);
return resultDomain;
} else {
ResultDomain<TbSysModule> resultDomain = new ResultDomain<>();
resultDomain.fail("创建模块失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("创建模块失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<TbSysModule> updateModule(TbSysModule module) {
try {
// 检查模块是否存在
TbSysModule existingModule = moduleMapper.selectByModuleID(module.getModuleID());
if (existingModule == null) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("模块不存在");
return result;
}
// 检查模块代码是否已存在(排除自身)
int count = moduleMapper.countByCode(module.getCode(), existingModule.getID());
if (count > 0) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("模块代码已存在");
return result;
}
// 设置更新时间和ID
module.setID(existingModule.getID());
module.setUpdateTime(new Date());
int result = moduleMapper.updateModule(module);
if (result > 0) {
ResultDomain<TbSysModule> resultDomain = new ResultDomain<>();
resultDomain.success("更新成功", module);
return resultDomain;
} else {
ResultDomain<TbSysModule> resultDomain = new ResultDomain<>();
resultDomain.fail("更新模块失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("更新模块失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> deleteModule(String moduleID) {
try {
TbSysModule module = moduleMapper.selectByModuleID(moduleID);
if (module == null) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("模块不存在");
return result;
}
module.setDeleteTime(new Date());
int result = moduleMapper.deleteModule(module);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("删除成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("删除模块失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("删除模块失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> batchDeleteModules(List<String> moduleIDs) {
try {
int result = moduleMapper.batchDeleteModules(moduleIDs);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("批量删除成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("批量删除模块失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("批量删除模块失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> updateModuleStatus(String moduleID, Integer status) {
try {
int result = moduleMapper.updateModuleStatus(moduleID, status);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("更新状态成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("更新模块状态失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("更新模块状态失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> updateModuleOrder(String moduleID, Integer orderNum) {
try {
int result = moduleMapper.updateModuleOrder(moduleID, orderNum);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("更新排序成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("更新模块排序失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("更新模块排序失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<TbSysModule> getModuleListPage(TbSysModule filter, PageParam pageParam) {
try {
List<TbSysModule> modules = moduleMapper.selectModulesPage(filter, pageParam);
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.success("查询成功", modules);
return result;
} catch (Exception e) {
ResultDomain<TbSysModule> result = new ResultDomain<>();
result.fail("分页查询模块列表失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<Long> countModules(TbSysModule filter) {
try {
long count = moduleMapper.countModules(filter);
ResultDomain<Long> result = new ResultDomain<>();
result.success("统计成功", count);
return result;
} catch (Exception e) {
ResultDomain<Long> result = new ResultDomain<>();
result.fail("统计模块数量失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<Boolean> checkModuleCodeExists(String code, String excludeID) {
try {
int count = moduleMapper.countByCode(code, excludeID);
ResultDomain<Boolean> result = new ResultDomain<>();
result.success("检查成功", count > 0);
return result;
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("检查模块代码失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> bindPermissionsToModule(String moduleID, List<String> permissionIds) {
try {
int result = permissionMapper.bindPermissionsToModule(moduleID, permissionIds);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("绑定成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("绑定权限到模块失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("绑定权限到模块失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> unbindPermissionsFromModule(String moduleID, List<String> permissionIds) {
try {
int result = permissionMapper.unbindPermissionsFromModule(moduleID, permissionIds);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("解绑成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("解绑模块权限失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("解绑模块权限失败:" + e.getMessage());
return result;
}
}
@Override
public ResultDomain<List<String>> getModulePermissions(String moduleID) {
try {
List<String> permissionIds = permissionMapper.getModulePermissionIds(moduleID);
ResultDomain<List<String>> result = new ResultDomain<>();
result.success("查询成功", permissionIds);
return result;
} catch (Exception e) {
ResultDomain<List<String>> result = new ResultDomain<>();
result.fail("获取模块权限失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> batchBindPermissionsToModule(String moduleID, List<String> permissionIds) {
try {
int result = permissionMapper.bindPermissionsToModule(moduleID, permissionIds);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("批量绑定成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("批量绑定权限到模块失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("批量绑定权限到模块失败:" + e.getMessage());
return result;
}
}
@Override
@Transactional
public ResultDomain<Boolean> batchUnbindPermissionsFromModule(String moduleID, List<String> permissionIds) {
try {
int result = permissionMapper.unbindPermissionsFromModule(moduleID, permissionIds);
if (result > 0) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.success("批量解绑成功", true);
return resultDomain;
} else {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
resultDomain.fail("批量解绑模块权限失败");
return resultDomain;
}
} catch (Exception e) {
ResultDomain<Boolean> result = new ResultDomain<>();
result.fail("批量解绑模块权限失败:" + e.getMessage());
return result;
}
}
}

View File

@@ -888,7 +888,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
return resultDomain;
}
List<TbSysPermission> permissions = permissionMapper.selectPermissionsByRoleId(roleId);
List<TbSysPermission> permissions = permissionMapper.selectPermissionsByRoleID(roleId);
logger.info("根据角色ID查询权限列表完成共找到{}个权限", permissions.size());
resultDomain.success("查询成功", permissions);

View File

@@ -0,0 +1,207 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.xyzh.system.mapper.ModuleMapper">
<!-- 基础结果映射 -->
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysModule">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="module_id" property="moduleID" jdbcType="VARCHAR"/>
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="code" property="code" jdbcType="VARCHAR"/>
<result column="description" property="description" jdbcType="VARCHAR"/>
<result column="icon" property="icon" jdbcType="VARCHAR"/>
<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="updater" property="updater" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
</resultMap>
<!-- 基础列列表 -->
<sql id="Base_Column_List">
id, module_id, name, code, description, icon, order_num, status, creator, updater,
create_time, update_time, delete_time, deleted
</sql>
<!-- 基础WHERE条件 -->
<sql id="Base_Where_Clause">
<where>
<if test="filter != null">
<if test="filter.id != null and filter.id != ''">
AND id = #{filter.id}
</if>
<if test="filter.moduleID != null and filter.moduleID != ''">
AND module_id = #{filter.moduleID}
</if>
<if test="filter.name != null and filter.name != ''">
AND name LIKE CONCAT('%', #{filter.name}, '%')
</if>
<if test="filter.code != null and filter.code != ''">
AND code = #{filter.code}
</if>
<if test="filter.status != null">
AND status = #{filter.status}
</if>
<if test="filter.deleted != null">
AND deleted = #{filter.deleted}
</if>
</if>
AND deleted = 0
</where>
</sql>
<!-- 查询模块列表 -->
<select id="selectModules" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_sys_module
<include refid="Base_Where_Clause" />
ORDER BY order_num ASC, create_time DESC
</select>
<!-- 根据模块ID查询模块信息 -->
<select id="selectByModuleID" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_sys_module
WHERE module_id = #{moduleID} AND deleted = 0
</select>
<!-- 根据模块代码查询模块信息 -->
<select id="selectByCode" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_sys_module
WHERE code = #{code} AND deleted = 0
</select>
<!-- 查询启用的模块列表 -->
<select id="selectActiveModules" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_sys_module
WHERE status = 1 AND deleted = 0
ORDER BY order_num ASC, create_time DESC
</select>
<!-- 检查模块代码是否存在 -->
<select id="countByCode" resultType="int">
SELECT COUNT(1)
FROM tb_sys_module
WHERE code = #{code} AND deleted = 0
<if test="excludeID != null and excludeID != ''">
AND id != #{excludeID}
</if>
</select>
<!-- 插入模块 -->
<insert id="insertModule" parameterType="org.xyzh.common.dto.system.TbSysModule">
INSERT INTO tb_sys_module (
id, module_id, name, code, description, icon, order_num, status,
creator, updater, create_time, update_time, deleted
) VALUES (
#{id}, #{moduleID}, #{name}, #{code}, #{description}, #{icon}, #{orderNum}, #{status},
#{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleted}
)
</insert>
<!-- 更新模块 -->
<update id="updateModule" parameterType="org.xyzh.common.dto.system.TbSysModule">
UPDATE tb_sys_module
<set>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="code != null and code != ''">
code = #{code},
</if>
<if test="description != null">
description = #{description},
</if>
<if test="icon != null">
icon = #{icon},
</if>
<if test="orderNum != null">
order_num = #{orderNum},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="updater != null and updater != ''">
updater = #{updater},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
</set>
WHERE id = #{id} AND deleted = 0
</update>
<!-- 删除模块 -->
<update id="deleteModule" parameterType="org.xyzh.common.dto.system.TbSysModule">
UPDATE tb_sys_module
SET deleted = 1, delete_time = #{deleteTime}
WHERE id = #{id} AND deleted = 0
</update>
<!-- 批量插入模块 -->
<insert id="batchInsertModules" parameterType="java.util.List">
INSERT INTO tb_sys_module (
id, module_id, name, code, description, icon, order_num, status,
creator, updater, create_time, update_time, deleted
) VALUES
<foreach collection="moduleList" item="module" separator=",">
(
#{module.id}, #{module.moduleID}, #{module.name}, #{module.code}, #{module.description},
#{module.icon}, #{module.orderNum}, #{module.status}, #{module.creator}, #{module.updater},
#{module.createTime}, #{module.updateTime}, #{module.deleted}
)
</foreach>
</insert>
<!-- 批量删除模块 -->
<update id="batchDeleteModules">
UPDATE tb_sys_module
SET deleted = 1, delete_time = NOW()
WHERE id IN
<foreach collection="moduleIDs" item="moduleID" open="(" separator="," close=")">
#{moduleID}
</foreach>
AND deleted = 0
</update>
<!-- 分页查询模块列表 -->
<select id="selectModulesPage" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_sys_module
<include refid="Base_Where_Clause" />
ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber}
</select>
<!-- 统计模块数量 -->
<select id="countModules" resultType="long">
SELECT COUNT(1)
FROM tb_sys_module
<include refid="Base_Where_Clause" />
</select>
<!-- 更新模块状态 -->
<update id="updateModuleStatus">
UPDATE tb_sys_module
SET status = #{status}, update_time = NOW()
WHERE module_id = #{moduleID} AND deleted = 0
</update>
<!-- 更新模块排序 -->
<update id="updateModuleOrder">
UPDATE tb_sys_module
SET order_num = #{orderNum}, update_time = NOW()
WHERE module_id = #{moduleID} AND deleted = 0
</update>
</mapper>

View File

@@ -9,6 +9,7 @@
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="code" property="code" jdbcType="VARCHAR"/>
<result column="description" property="description" jdbcType="VARCHAR"/>
<result column="module_id" property="moduleID" jdbcType="VARCHAR"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="updater" property="updater" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
@@ -48,7 +49,7 @@
<!-- 基础字段 -->
<sql id="Base_Column_List">
id, permission_id, name, code, description, creator, updater,
id, permission_id, name, code, description, module_id, creator, updater,
create_time, update_time, delete_time, deleted
</sql>
@@ -82,7 +83,7 @@
</select>
<!-- 根据角色ID查询权限列表 -->
<select id="selectPermissionsByRoleId" resultMap="BaseResultMap">
<select id="selectPermissionsByRoleID" resultMap="BaseResultMap">
SELECT
p.id, p.permission_id, p.name, p.code, p.description,
p.creator, p.updater,
@@ -91,7 +92,7 @@
INNER JOIN tb_sys_permission p ON p.permission_id = rp.permission_id
WHERE p.deleted = 0
AND rp.deleted = 0
AND rp.role_id = #{roleId}
AND rp.role_id = #{roleID}
ORDER BY p.create_time ASC
</select>
@@ -111,8 +112,8 @@
FROM tb_sys_permission
WHERE deleted = 0
AND name = #{permissionName}
<if test="excludeId != null and excludeId != ''">
AND id != #{excludeId}
<if test="excludeID != null and excludeID != ''">
AND id != #{excludeID}
</if>
</select>
@@ -122,8 +123,8 @@
FROM tb_sys_permission
WHERE deleted = 0
AND code = #{permissionCode}
<if test="excludeId != null and excludeId != ''">
AND id != #{excludeId}
<if test="excludeID != null and excludeID != ''">
AND id != #{excludeID}
</if>
</select>
@@ -287,4 +288,44 @@
AND tsrp.permission_id = #{permission.permissionID}
ORDER BY tsr.role_id, tsr.create_time ASC
</select>
<!-- 根据模块ID查询权限列表 -->
<select id="selectPermissionsByModuleID" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_sys_permission
WHERE module_id = #{moduleID} AND deleted = 0
ORDER BY create_time DESC
</select>
<!-- 绑定权限到模块 -->
<update id="bindPermissionsToModule">
UPDATE tb_sys_permission
SET module_id = #{moduleID}, update_time = NOW()
WHERE permission_id IN
<foreach collection="permissionIds" item="permissionId" open="(" separator="," close=")">
#{permissionId}
</foreach>
AND deleted = 0
</update>
<!-- 解绑模块的权限 -->
<update id="unbindPermissionsFromModule">
UPDATE tb_sys_permission
SET module_id = NULL, update_time = NOW()
WHERE permission_id IN
<foreach collection="permissionIds" item="permissionId" open="(" separator="," close=")">
#{permissionId}
</foreach>
AND module_id = #{moduleID}
AND deleted = 0
</update>
<!-- 获取模块的权限ID列表 -->
<select id="getModulePermissionIds" resultType="String">
SELECT permission_id
FROM tb_sys_permission
WHERE module_id = #{moduleID} AND deleted = 0
ORDER BY create_time DESC
</select>
</mapper>