修正消息中心不显示

This commit is contained in:
2025-11-22 16:01:36 +08:00
parent f3a9926caf
commit 12592c5a24
15 changed files with 331 additions and 380 deletions

View File

@@ -69,8 +69,8 @@ INSERT INTO `tb_sys_permission` (id,permission_id, name, code, description, modu
('19','perm_sensitive_manage', '敏感词管理', 'sensitive:manage', '敏感词管理权限', 'module_sensitive', '1', now());
-- 插入角色-权限关联数据
INSERT INTO `tb_sys_role_permission` (id, role_id, permission_id, creator, create_time) VALUES
-- 超级管理员:拥有所有权限
INSERT INTO `tb_sys_role_permission` (id, role_id, permission_id, creator, create_time) VALUES
('1', 'superadmin', 'perm_default', '1', now()),
('2', 'superadmin', 'perm_system_manage', '1', now()),
('3', 'superadmin', 'perm_system_dept_manage', '1', now()),
@@ -116,8 +116,8 @@ INSERT INTO `tb_sys_role_permission` (id, role_id, permission_id, creator, creat
('45', 'freedom', 'perm_message_view', '1', now());
-- 插入前端菜单数据
INSERT INTO `tb_sys_menu` VALUES
-- 用户前端菜单 (100-699)
INSERT INTO `tb_sys_menu` VALUES
('100', 'menu_home', '首页', NULL, '/home', 'user/home/HomeView', NULL, 1, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('101', 'menu_resource_hot', '热门资源', NULL, '/resource-hot', 'user/resource-center/HotResourceView', NULL, 2, 3, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('200', 'menu_resource_center', '资源中心', NULL, '/resource-center', 'user/resource-center/ResourceCenterView', NULL, 2, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
@@ -128,13 +128,13 @@ INSERT INTO `tb_sys_menu` VALUES
('304', 'menu_course_detail', '课程详情', 'menu_study_plan', '/study-plan/course-detail', 'user/study-plan/CourseDetailView', NULL, 4, 3, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
('305', 'menu_course_study', '课程学习', 'menu_study_plan', '/study-plan/course-study', 'user/study-plan/CourseStudyView', NULL, 5, 3, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
('400', 'menu_user_dropdown', '用户下拉菜单', NULL, '', '', NULL, 4, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('401', 'menu_user_center', '个人中心', 'menu_user_dropdown', '/user-center', 'user/user-center/UserCenterView', NULL, 4, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('401', 'menu_user_center', '个人中心', 'menu_user_dropdown', '/user-center', 'user/user-center/UserCenterLayout', NULL, 4, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('402', 'menu_learning_records', '学习记录', 'menu_user_center', '/user-center/learning-records', 'user/user-center/LearningRecordsView', NULL, 1, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('403', 'menu_my_favorites', '我的收藏', 'menu_user_center', '/user-center/favorites', 'user/user-center/MyFavoritesView', NULL, 2, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('404', 'menu_my_achievements', '我的成就', 'menu_user_center', '/user-center/achievements', 'user/user-center/MyAchievementsView', NULL, 3, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('500', 'menu_profile', '账号中心', 'menu_user_dropdown', '/profile', 'user/profile/ProfileView', NULL, 5, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('501', 'menu_personal_info', '个人信息', 'menu_profile', '/profile/personal-info', 'user/profile/PersonalInfoView', NULL, 1, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
('502', 'menu_account_settings', '账号设置', 'menu_profile', '/profile/account-settings', 'user/profile/AccountSettingsView', NULL, 2, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
('500', 'menu_profile', '账号中心', 'menu_user_dropdown', '/profile', 'user/user-center/UserCenterLayout', NULL, 5, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
('501', 'menu_personal_info', '个人信息', 'menu_profile', '/profile/personal-info', 'user/user-center/profile/PersonalInfoView', NULL, 1, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
('502', 'menu_account_settings', '账号设置', 'menu_profile', '/profile/account-settings', 'user/user-center/profile/AccountSettingsView', NULL, 2, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
('503', 'menu_search', '搜索', NULL, '/search', 'user/resource-center/SearchView', NULL, 3, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
-- 管理后台菜单 (1000-8999)
('1000', 'menu_admin_overview', '系统总览', NULL, '/admin/overview', 'admin/overview/SystemOverviewView', 'admin/overview.svg', 1, 0, 'SidebarLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:52:32', NULL, 0),
@@ -177,8 +177,8 @@ INSERT INTO `tb_sys_menu` VALUES
('651', 'menu_user_message_detail', '消息详情', 'menu_user_message_center', '/user/message/detail/:messageID', 'user/message/MyMessageDetailView', NULL, 1, 3, 'NavigationLayout', '1', NULL, '2025-11-13 10:00:00', '2025-11-13 10:00:00', NULL, 0);
-- 插入菜单权限关联数据
INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, create_time) VALUES
-- 前端菜单权限关联
INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, create_time) VALUES
('100', 'perm_default', 'menu_home', '1', now()),
('102', 'perm_default', 'menu_resource_hot', '1', now()),
('101', 'perm_default', 'menu_resource_center', '1', now()),
@@ -241,11 +241,7 @@ INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, creat
-- 消息通知管理菜单权限关联
('240', 'perm_message_manage', 'menu_admin_message_manage', '1', now()),
('241', 'perm_message_manage', 'menu_admin_message_list', '1', now()),
('242', 'perm_message_send', 'menu_admin_message_create', '1', now()),
('243', 'perm_message_manage', 'menu_admin_message_detail', '1', now()),
-- 用户端消息中心权限关联
('250', 'perm_message_view', 'menu_user_message_center', '1', now()),
('251', 'perm_message_view', 'menu_user_message_detail', '1', now());
('250', 'perm_default', 'menu_user_message_center', '1', now()),
('251', 'perm_default', 'menu_user_message_detail', '1', now());

View File

@@ -97,6 +97,51 @@ execute_init_script() {
fi
}
# 执行敏感词导入
import_sensitive_words() {
print_message $BLUE "开始导入敏感词数据..."
# 检查conda是否可用
if ! command -v conda &> /dev/null; then
print_message $YELLOW "conda命令未找到跳过敏感词导入"
return 0
fi
# 检查schoolNewsCrawler环境是否存在
if ! conda env list | grep -q "schoolNewsCrawler"; then
print_message $YELLOW "conda环境 'schoolNewsCrawler' 不存在,跳过敏感词导入"
print_message $YELLOW "提示: 可以使用以下命令创建环境: conda create -n schoolNewsCrawler python=3.10"
return 0
fi
# 切换到敏感词脚本目录
local sensitive_dir="$SCRIPT_DIR/sensitiveData"
if [ ! -d "$sensitive_dir" ]; then
print_message $YELLOW "敏感词脚本目录不存在: $sensitive_dir"
return 0
fi
if [ ! -f "$sensitive_dir/writeWord.py" ]; then
print_message $YELLOW "敏感词脚本不存在: $sensitive_dir/writeWord.py"
return 0
fi
print_message $BLUE "激活conda环境: schoolNewsCrawler"
cd "$sensitive_dir"
# 使用conda run来在指定环境中执行命令添加-y参数自动确认
conda run -n schoolNewsCrawler python writeWord.py -y
if [ $? -eq 0 ]; then
print_message $GREEN "敏感词数据导入成功"
else
print_message $YELLOW "敏感词数据导入失败,但不影响系统运行"
fi
# 返回脚本目录
cd "$SCRIPT_DIR"
}
# 验证初始化结果
verify_initialization() {
print_message $BLUE "验证初始化结果..."
@@ -120,6 +165,14 @@ verify_initialization() {
else
print_message $YELLOW "默认用户创建失败"
fi
# 检查敏感词数量
local sensitive_count=$(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" -D"$DB_NAME" -e "SELECT COUNT(*) FROM tb_sensitive_word;" 2>/dev/null | tail -n 1)
if [ -n "$sensitive_count" ] && [ "$sensitive_count" -gt 0 ]; then
print_message $GREEN "敏感词数据: $sensitive_count"
else
print_message $YELLOW "敏感词数据: 0 个 (可能未导入或表不存在)"
fi
}
# 显示初始化信息
@@ -146,6 +199,8 @@ show_initialization_info() {
print_message $YELLOW " - AI智能体"
print_message $YELLOW " - 系统配置"
print_message $YELLOW " - 文件管理"
print_message $YELLOW " - 敏感词过滤"
print_message $YELLOW " - 消息通知"
print_message $BLUE "====================================================="
}
@@ -153,7 +208,7 @@ show_initialization_info() {
main() {
print_message $BLUE "====================================================="
print_message $BLUE "校园思政新闻平台数据库重新初始化脚本"
print_message $BLUE "版本: 1.0.0"
print_message $BLUE "版本: 1.1.0"
print_message $BLUE "====================================================="
# 检查MySQL连接
@@ -170,12 +225,15 @@ main() {
# 执行初始化脚本
execute_init_script
# 导入敏感词数据
# 验证初始化结果
verify_initialization
# 显示初始化信息
show_initialization_info
import_sensitive_words
print_message $GREEN "初始化完成!"
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,203 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
敏感词批量导入脚本
从 sensitive_word_dict.txt 文件读取敏感词并批量插入到数据库
"""
import pymysql
import os
import sys
import argparse
from datetime import datetime
# 数据库配置
DB_CONFIG = {
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': '123456',
'database': 'school_news',
'charset': 'utf8mb4'
}
def get_db_connection():
"""获取数据库连接"""
try:
connection = pymysql.connect(**DB_CONFIG)
return connection
except Exception as e:
print(f"数据库连接失败: {e}")
return None
def read_sensitive_words(file_path):
"""读取敏感词文件"""
words = []
try:
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
word = line.strip()
if word and len(word) > 0:
words.append(word)
print(f"成功读取 {len(words)} 个敏感词")
return words
except Exception as e:
print(f"读取敏感词文件失败: {e}")
return []
def batch_insert_words(connection, words, batch_size=1000):
"""批量插入敏感词到数据库"""
cursor = connection.cursor()
try:
# 清空现有的deny类型敏感词可选
print("清理现有的deny类型敏感词...")
cursor.execute("DELETE FROM tb_sensitive_word WHERE type = 'deny'")
# 准备批量插入SQL
insert_sql = "INSERT INTO tb_sensitive_word (word, type) VALUES (%s, %s)"
# 分批插入
total_words = len(words)
inserted_count = 0
for i in range(0, total_words, batch_size):
batch_words = words[i:i + batch_size]
batch_data = [(word, 'deny') for word in batch_words]
try:
cursor.executemany(insert_sql, batch_data)
connection.commit()
inserted_count += len(batch_data)
print(f"已插入 {inserted_count}/{total_words} 个敏感词")
except Exception as e:
print(f"批量插入失败: {e}")
connection.rollback()
break
print(f"批量插入完成,共插入 {inserted_count} 个敏感词")
return inserted_count
except Exception as e:
print(f"批量插入过程中发生错误: {e}")
connection.rollback()
return 0
finally:
cursor.close()
def check_duplicates(connection, words):
"""检查重复的敏感词"""
cursor = connection.cursor()
try:
# 查询已存在的敏感词
cursor.execute("SELECT word FROM tb_sensitive_word WHERE type = 'deny'")
existing_words = set(row[0] for row in cursor.fetchall())
# 过滤重复词
new_words = [word for word in words if word not in existing_words]
duplicate_count = len(words) - len(new_words)
if duplicate_count > 0:
print(f"发现 {duplicate_count} 个重复敏感词,将跳过")
return new_words
except Exception as e:
print(f"检查重复词时发生错误: {e}")
return words
finally:
cursor.close()
def main():
"""主函数"""
# 解析命令行参数
parser = argparse.ArgumentParser(description='敏感词批量导入工具')
parser.add_argument('-y', '--yes', action='store_true',
help='自动确认导入,跳过交互式确认')
parser.add_argument('--file', type=str,
help='指定敏感词文件路径(默认: sensitive_word_dict.txt')
args = parser.parse_args()
print("=" * 50)
print("敏感词批量导入工具")
print("=" * 50)
# 获取敏感词文件路径
if args.file:
dict_file = args.file
else:
script_dir = os.path.dirname(os.path.abspath(__file__))
dict_file = os.path.join(script_dir, 'sensitive_word_dict.txt')
# 检查敏感词文件是否存在
if not os.path.exists(dict_file):
print(f"敏感词文件不存在: {dict_file}")
return
# 读取敏感词
print("正在读取敏感词文件...")
words = read_sensitive_words(dict_file)
if not words:
print("没有读取到有效的敏感词")
return
# 连接数据库
print("正在连接数据库...")
connection = get_db_connection()
if not connection:
print("数据库连接失败,程序退出")
return
try:
# 检查重复词(可选,如果不需要可以注释掉)
# print("正在检查重复敏感词...")
# words = check_duplicates(connection, words)
if not words:
print("所有敏感词都已存在,无需导入")
return
# 确认导入
print(f"准备导入 {len(words)} 个敏感词到数据库")
if args.yes:
print("自动确认模式,开始导入...")
else:
try:
confirm = input("是否继续?(y/N): ").strip().lower()
if confirm != 'y':
print("用户取消导入")
return
except EOFError:
print("检测到非交互式环境,自动确认导入...")
except KeyboardInterrupt:
print("\n用户中断导入")
return
# 批量插入
print("开始批量导入敏感词...")
start_time = datetime.now()
inserted_count = batch_insert_words(connection, words)
end_time = datetime.now()
duration = (end_time - start_time).total_seconds()
print("=" * 50)
print(f"导入完成!")
print(f"成功导入: {inserted_count} 个敏感词")
print(f"耗时: {duration:.2f}")
print("=" * 50)
except Exception as e:
print(f"程序执行过程中发生错误: {e}")
finally:
connection.close()
print("数据库连接已关闭")
if __name__ == "__main__":
main()