-- =====================================================
-- 敏感词表检查和初始化脚本
-- 请在 Navicat 中逐步执行以下SQL
-- =====================================================

-- ========== 第1步：检查表是否存在 ==========
SELECT '=== 检查表是否存在 ===' as step;
SHOW TABLES LIKE 'eb_sensitive_word';

-- ========== 第2步：如果表不存在，创建表 ==========
CREATE TABLE IF NOT EXISTS `eb_sensitive_word` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `word` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '敏感词',
  `category` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'default' COMMENT '分类',
  `level` tinyint NOT NULL DEFAULT 1 COMMENT '级别 1=轻度 2=中度 3=重度',
  `action` tinyint NOT NULL DEFAULT 1 COMMENT '处理方式 1=替换 2=拦截 3=警告',
  `replace_text` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '***' COMMENT '替换文本',
  `status` tinyint NOT NULL DEFAULT 1 COMMENT '状态 0=禁用 1=启用',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_word` (`word`) USING BTREE,
  KEY `idx_category` (`category`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '敏感词表' ROW_FORMAT = DYNAMIC;

-- ========== 第3步：查看表结构 ==========
SELECT '=== 表结构 ===' as step;
DESCRIBE eb_sensitive_word;

-- ========== 第4步：查看现有数据数量 ==========
SELECT '=== 现有数据数量 ===' as step;
SELECT COUNT(*) as total FROM eb_sensitive_word;

-- ========== 第5步：插入测试数据（如果没有数据） ==========
-- 使用 INSERT IGNORE 避免重复插入
INSERT IGNORE INTO `eb_sensitive_word` (`word`, `category`, `level`, `action`, `replace_text`, `status`, `create_time`) VALUES
('测试敏感词1', 'default', 1, 1, '***', 1, NOW()),
('测试敏感词2', 'default', 2, 1, '***', 1, NOW()),
('广告', 'spam', 1, 1, '**', 1, NOW()),
('推广', 'spam', 1, 1, '**', 1, NOW()),
('加微信', 'spam', 2, 2, '***', 1, NOW()),
('加QQ', 'spam', 2, 2, '***', 1, NOW()),
('色情', 'illegal', 3, 2, '***', 1, NOW()),
('赌博', 'illegal', 3, 2, '***', 1, NOW()),
('诈骗', 'illegal', 3, 2, '***', 1, NOW()),
('违法', 'illegal', 2, 2, '***', 1, NOW());

-- ========== 第6步：查看所有数据 ==========
SELECT '=== 敏感词数据列表 ===' as step;
SELECT * FROM eb_sensitive_word ORDER BY id DESC;

-- ========== 第7步：最终统计 ==========
SELECT '=== 最终统计 ===' as step;
SELECT COUNT(*) as total_count FROM eb_sensitive_word;
SELECT COUNT(*) as enabled_count FROM eb_sensitive_word WHERE status = 1;
SELECT COUNT(*) as disabled_count FROM eb_sensitive_word WHERE status = 0;
