代码优化

This commit is contained in:
2025-10-13 10:43:08 +08:00
parent b6818b179c
commit bc3ed2d872
40 changed files with 3189 additions and 788 deletions
@@ -8,9 +8,9 @@ spring:
# 数据库配置 - 本地MySQL
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.111.10.27:3306/emotion?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
url: jdbc:mysql://localhost:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: EmotionMuseum2025*#
password: 123456
hikari:
minimum-idle: 5
maximum-pool-size: 20
@@ -8,9 +8,9 @@ spring:
# 数据库配置 - 生产MySQL
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.111.10.27:3306/emotion?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
username: emotion
password: EmotionDB2024!
url: jdbc:mysql://101.200.208.45:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: EmotionMuseum2025*#
hikari:
minimum-idle: 10
maximum-pool-size: 50
@@ -24,7 +24,7 @@ spring:
# Redis配置 - 生产Redis
redis:
host: localhost
host: 101.200.208.45
port: 6379
timeout: 5000ms
database: 0
@@ -8,7 +8,7 @@ spring:
# 数据库配置 - 测试MySQL
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.111.10.27:3306/emotion?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
url: jdbc:mysql://101.200.208.45:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: EmotionMuseum2025*#
hikari:
@@ -24,7 +24,7 @@ spring:
# Redis配置 - 测试Redis
redis:
host: localhost
host: 101.200.208.45
port: 6379
timeout: 3000ms
database: 1
@@ -22,11 +22,11 @@ SET
time_zone = "+00:00";
-- 创建数据库
CREATE DATABASE IF NOT EXISTS emotion DEFAULT CHARACTER
CREATE DATABASE IF NOT EXISTS emotion_museum DEFAULT CHARACTER
SET
utf8mb4 COLLATE utf8mb4_unicode_ci;
USE emotion;
USE emotion_museum;
-- ============================================================================
-- 数据库设计原则
@@ -40,40 +40,44 @@ USE emotion;
-- 删除现有表(开发阶段确保表结构最新)
-- 警告: 这会删除所有数据!
-- ============================================================================
DROP TABLE IF EXISTS user_stats;
DROP TABLE IF EXISTS t_user_stats;
DROP TABLE IF EXISTS guest_user;
DROP TABLE IF EXISTS t_guest_user;
DROP TABLE IF EXISTS reward;
DROP TABLE IF EXISTS t_reward;
DROP TABLE IF EXISTS achievement;
DROP TABLE IF EXISTS t_achievement;
DROP TABLE IF EXISTS comment;
DROP TABLE IF EXISTS t_comment;
DROP TABLE IF EXISTS community_post;
DROP TABLE IF EXISTS t_community_post;
DROP TABLE IF EXISTS location_pin;
DROP TABLE IF EXISTS t_location_pin;
DROP TABLE IF EXISTS topic_interaction;
DROP TABLE IF EXISTS t_topic_interaction;
DROP TABLE IF EXISTS growth_topic;
DROP TABLE IF EXISTS t_growth_topic;
DROP TABLE IF EXISTS emotion_record;
DROP TABLE IF EXISTS t_emotion_record;
DROP TABLE IF EXISTS emotion_analysis;
DROP TABLE IF EXISTS t_emotion_analysis;
DROP TABLE IF EXISTS coze_api_call;
DROP TABLE IF EXISTS t_coze_api_call;
DROP TABLE IF EXISTS message;
DROP TABLE IF EXISTS t_message;
DROP TABLE IF EXISTS conversation;
DROP TABLE IF EXISTS t_conversation;
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS t_diary_post;
DROP TABLE IF EXISTS t_diary_comment;
DROP TABLE IF EXISTS t_user;
-- ============================================================================
-- 1. 用户表 (user)
-- ============================================================================
CREATE TABLE user (
CREATE TABLE t_user (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
account VARCHAR(50) UNIQUE COMMENT '账号', -- 账号
password VARCHAR(255) COMMENT '密码(加密后)', -- 密码(加密后)
@@ -107,15 +111,15 @@ CREATE TABLE user (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户表 (t_user)';
-- ============================================================================
-- 2. 对话表 (conversation)
-- 关联说明: user_id 关联 user.id,通过代码逻辑维护关联关系
-- 2. 对话表 (t_conversation)
-- 关联说明: user_id 关联 t_user.id,通过代码逻辑维护关联关系
-- ============================================================================
CREATE TABLE conversation (
CREATE TABLE t_conversation (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
user_id VARCHAR(64) COMMENT '用户ID (关联user.id)', -- 用户ID (关联user.id)
user_id VARCHAR(64) COMMENT '用户ID (关联t_user.id)', -- 用户ID (关联t_user.id)
user_type VARCHAR(20) DEFAULT 'registered' COMMENT '用户类型: registered-注册用户, guest-访客用户', -- 用户类型: registered-注册用户, guest-访客用户
title VARCHAR(200) COMMENT '对话标题', -- 对话标题
type VARCHAR(50) DEFAULT 'emotion_chat' COMMENT '对话类型', -- 对话类型
@@ -149,15 +153,15 @@ CREATE TABLE conversation (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '对话表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '对话表 (t_conversation)';
-- ============================================================================
-- 3. 消息表 (message)
-- 关联说明: conversation_id 关联 conversation.id,通过代码逻辑维护关联关系
-- 3. 消息表 (t_message)
-- 关联说明: conversation_id 关联 t_conversation.id,通过代码逻辑维护关联关系
-- ============================================================================
CREATE TABLE message (
CREATE TABLE t_message (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
conversation_id VARCHAR(64) COMMENT '对话ID (关联conversation.id)', -- 对话ID (关联conversation.id)
conversation_id VARCHAR(64) COMMENT '对话ID (关联t_conversation.id)', -- 对话ID (关联t_conversation.id)
content TEXT COMMENT '消息内容', -- 消息内容
type VARCHAR(50) DEFAULT 'text' COMMENT '消息类型', -- 消息类型
sender VARCHAR(20) COMMENT '发送者: user-用户, assistant-AI助手', -- 发送者: user-用户, assistant-AI助手
@@ -188,12 +192,12 @@ CREATE TABLE message (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '消息表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '消息表 (t_message)';
-- ============================================================================
-- 4. Coze API调用记录表 (coze_api_call) - 优化版本
-- ============================================================================
CREATE TABLE coze_api_call (
CREATE TABLE t_coze_api_call (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
conversation_id VARCHAR(64) COMMENT '对话ID', -- 对话ID
message_id VARCHAR(64) COMMENT '消息ID', -- 消息ID
@@ -252,12 +256,12 @@ CREATE TABLE coze_api_call (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'Coze API调用记录表 - 完整版本';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'Coze API调用记录表 - 完整版本 (t_coze_api_call)';
-- ============================================================================
-- 5. 情绪分析表 (emotion_analysis)
-- ============================================================================
CREATE TABLE emotion_analysis (
CREATE TABLE t_emotion_analysis (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
user_id VARCHAR(64) COMMENT '用户ID', -- 用户ID
message_id VARCHAR(64) COMMENT '关联消息ID', -- 关联消息ID
@@ -278,12 +282,12 @@ CREATE TABLE emotion_analysis (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '情绪分析表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '情绪分析表 (t_emotion_analysis)';
-- ============================================================================
-- 6. 情绪记录表 (emotion_record)
-- ============================================================================
CREATE TABLE emotion_record (
CREATE TABLE t_emotion_record (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
user_id VARCHAR(64) COMMENT '用户ID', -- 用户ID
record_date DATE COMMENT '记录日期', -- 记录日期
@@ -304,12 +308,12 @@ CREATE TABLE emotion_record (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '情绪记录表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '情绪记录表 (t_emotion_record)';
-- ============================================================================
-- 7. 成长课题表 (growth_topic)
-- ============================================================================
CREATE TABLE growth_topic (
CREATE TABLE t_growth_topic (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
title VARCHAR(100) COMMENT '课题标题', -- 课题标题
category VARCHAR(50) COMMENT '分类', -- 分类
@@ -329,12 +333,12 @@ CREATE TABLE growth_topic (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '成长课题表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '成长课题表 (t_growth_topic)';
-- ============================================================================
-- 8. 课题互动表 (topic_interaction)
-- ============================================================================
CREATE TABLE topic_interaction (
CREATE TABLE t_topic_interaction (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
topic_id VARCHAR(64) COMMENT '课题ID', -- 课题ID
type VARCHAR(50) COMMENT '互动类型', -- 互动类型
@@ -351,12 +355,12 @@ CREATE TABLE topic_interaction (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '课题互动表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '课题互动表 (t_topic_interaction)';
-- ============================================================================
-- 9. 地点标记表 (location_pin)
-- ============================================================================
CREATE TABLE location_pin (
CREATE TABLE t_location_pin (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
name VARCHAR(100) COMMENT '地点名称', -- 地点名称
type VARCHAR(50) COMMENT '地点类型', -- 地点类型
@@ -365,7 +369,6 @@ CREATE TABLE location_pin (
longitude DECIMAL(11, 8) COMMENT '经度', -- 经度
address VARCHAR(200) COMMENT '地址', -- 地址
description TEXT COMMENT '描述', -- 描述
created_by VARCHAR(64) COMMENT '创建者', -- 创建者
likes INT DEFAULT 0 COMMENT '点赞数', -- 点赞数
visits INT DEFAULT 0 COMMENT '访问数', -- 访问数
is_bookmarked TINYINT DEFAULT 0 COMMENT '是否收藏', -- 是否收藏
@@ -377,12 +380,12 @@ CREATE TABLE location_pin (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '地点标记表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '地点标记表 (t_location_pin)';
-- ============================================================================
-- 10. 社区帖子表 (community_post)
-- ============================================================================
CREATE TABLE community_post (
CREATE TABLE t_community_post (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
user_id VARCHAR(64) COMMENT '用户ID', -- 用户ID
location_id VARCHAR(64) COMMENT '地点ID', -- 地点ID
@@ -402,12 +405,12 @@ CREATE TABLE community_post (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '社区帖子表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '社区帖子表 (t_community_post)';
-- ============================================================================
-- 11. 评论表 (comment)
-- ============================================================================
CREATE TABLE comment (
CREATE TABLE t_comment (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
post_id VARCHAR(64) COMMENT '帖子ID', -- 帖子ID
user_id VARCHAR(64) COMMENT '用户ID', -- 用户ID
@@ -421,12 +424,12 @@ CREATE TABLE comment (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '评论表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '评论表 (t_comment)';
-- ============================================================================
-- 12. 成就表 (achievement)
-- ============================================================================
CREATE TABLE achievement (
CREATE TABLE t_achievement (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
title VARCHAR(100) COMMENT '成就标题', -- 成就标题
description TEXT COMMENT '描述', -- 描述
@@ -446,12 +449,12 @@ CREATE TABLE achievement (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '成就表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '成就表 (t_achievement)';
-- ============================================================================
-- 13. 奖励表 (reward)
-- ============================================================================
CREATE TABLE reward (
CREATE TABLE t_reward (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
topic_id VARCHAR(64) COMMENT '课题ID', -- 课题ID
achievement_id VARCHAR(64) COMMENT '成就ID', -- 成就ID
@@ -470,12 +473,12 @@ CREATE TABLE reward (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '奖励表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '奖励表 (t_reward)';
-- ============================================================================
-- 14. 用户统计表 (user_stats)
-- ============================================================================
CREATE TABLE user_stats (
CREATE TABLE t_user_stats (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
user_id VARCHAR(64) UNIQUE COMMENT '用户ID', -- 用户ID
total_conversations INT DEFAULT 0 COMMENT '总对话数', -- 总对话数
@@ -508,15 +511,15 @@ CREATE TABLE user_stats (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户统计表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户统计表 (t_user_stats)';
-- ============================================================================
-- 16. 用户日记表 (diary_post) - 类似朋友圈功能
-- 关联说明: user_id 关联 user.id,通过代码逻辑维护关联关系
-- 16. 用户日记表 (t_diary_post) - 类似朋友圈功能
-- 关联说明: user_id 关联 t_user.id,通过代码逻辑维护关联关系
-- ============================================================================
CREATE TABLE diary_post (
CREATE TABLE t_diary_post (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
user_id VARCHAR(64) COMMENT '用户ID (关联user.id)', -- 用户ID (关联user.id)
user_id VARCHAR(64) COMMENT '用户ID (关联t_user.id)', -- 用户ID (关联t_user.id)
title VARCHAR(200) COMMENT '日记标题', -- 日记标题
content TEXT COMMENT '日记内容', -- 日记内容
images JSON COMMENT '图片列表 (存储图片URL数组)', -- 图片列表 (存储图片URL数组)
@@ -553,16 +556,16 @@ CREATE TABLE diary_post (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户日记表 - 类似朋友圈功能';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户日记表 - 类似朋友圈功能 (t_diary_post)';
-- ============================================================================
-- 17. 日记评论表 (diary_comment)
-- 关联说明: diary_id 关联 diary_post.iduser_id 关联 user.id,通过代码逻辑维护关联关系
-- 17. 日记评论表 (t_diary_comment)
-- 关联说明: diary_id 关联 t_diary_post.iduser_id 关联 t_user.id,通过代码逻辑维护关联关系
-- ============================================================================
CREATE TABLE diary_comment (
CREATE TABLE t_diary_comment (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
diary_id VARCHAR(64) COMMENT '日记ID (关联diary_post.id)', -- 日记ID (关联diary_post.id)
user_id VARCHAR(64) COMMENT '评论用户ID (关联user.id)', -- 评论用户ID (关联user.id)
diary_id VARCHAR(64) COMMENT '日记ID (关联t_diary_post.id)', -- 日记ID (关联t_diary_post.id)
user_id VARCHAR(64) COMMENT '评论用户ID (关联t_user.id)', -- 评论用户ID (关联t_user.id)
parent_comment_id VARCHAR(64) COMMENT '父评论ID (用于回复功能)', -- 父评论ID (用于回复功能)
content TEXT COMMENT '评论内容', -- 评论内容
images JSON COMMENT '评论图片 (存储图片URL数组)', -- 评论图片 (存储图片URL数组)
@@ -585,12 +588,12 @@ CREATE TABLE diary_comment (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '日记评论表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '日记评论表 (t_diary_comment)';
-- ============================================================================
-- 18. 访客用户表 (guest_user)
-- ============================================================================
CREATE TABLE guest_user (
CREATE TABLE t_guest_user (
id VARCHAR(64) PRIMARY KEY COMMENT 'UUID主键', -- UUID主键
guest_user_id VARCHAR(50) UNIQUE COMMENT '访客用户ID (格式: guest_xxx)', -- 访客用户ID (格式: guest_xxx)
ip_address VARCHAR(45) COMMENT '客户端IP地址 (支持IPv6)', -- 客户端IP地址 (支持IPv6)
@@ -609,414 +612,243 @@ CREATE TABLE guest_user (
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', -- 更新时间
is_deleted TINYINT DEFAULT 0 COMMENT '是否删除: 0-未删除, 1-已删除', -- 是否删除: 0-未删除, 1-已删除
remarks VARCHAR(500) COMMENT '备注' -- 备注
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '访客用户表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '访客用户表 (t_guest_user)';
-- ============================================================================
-- 创建索引以提高查询性能
-- 注意: MySQL的CREATE INDEX不支持IF NOT EXISTS
-- 如果索引已存在,重复执行会产生警告但不会中断脚本执行
-- ============================================================================
-- user表索引
CREATE INDEX idx_user_account ON user (account);
CREATE INDEX idx_user_username ON user (username);
CREATE INDEX idx_user_email ON user (email);
CREATE INDEX idx_user_phone ON user (phone);
CREATE INDEX idx_user_last_active_time ON user (last_active_time);
CREATE INDEX idx_user_create_time ON user (create_time);
CREATE INDEX idx_user_member_level ON user (member_level);
CREATE INDEX idx_user_status ON user (status);
CREATE INDEX idx_user_is_verified ON user (is_verified);
CREATE INDEX idx_user_create_by ON user (create_by);
CREATE INDEX idx_user_update_by ON user (update_by);
CREATE INDEX idx_user_is_deleted ON user (is_deleted);
CREATE INDEX idx_user_third_party_id ON user (third_party_id);
CREATE INDEX idx_user_third_party_type ON user (third_party_type);
-- conversation表索引
CREATE INDEX idx_conversation_user_id ON conversation (user_id);
CREATE INDEX idx_conversation_start_time ON conversation (start_time);
CREATE INDEX idx_conversation_user_id_start_time ON conversation (user_id, start_time);
CREATE INDEX idx_conversation_primary_emotion ON conversation (primary_emotion);
CREATE INDEX idx_conversation_end_time ON conversation (end_time);
CREATE INDEX idx_conversation_create_time ON conversation (create_time);
CREATE INDEX idx_conversation_coze_conversation_id ON conversation (coze_conversation_id);
CREATE INDEX idx_conversation_status ON conversation (status);
CREATE INDEX idx_conversation_last_active_time ON conversation (last_active_time);
CREATE INDEX idx_conversation_create_by ON conversation (create_by);
CREATE INDEX idx_conversation_update_by ON conversation (update_by);
CREATE INDEX idx_conversation_is_deleted ON conversation (is_deleted);
CREATE INDEX idx_conversation_user_type ON conversation (user_type);
CREATE INDEX idx_conversation_emotion_trend ON conversation (emotion_trend);
CREATE INDEX idx_conversation_confidence ON conversation (confidence);
CREATE INDEX idx_conversation_client_ip ON conversation (client_ip);
-- message表索引
CREATE INDEX idx_message_conversation_id ON message (conversation_id);
CREATE INDEX idx_message_timestamp ON message (timestamp);
CREATE INDEX idx_message_conversation_id_timestamp ON message (conversation_id, timestamp);
CREATE INDEX idx_message_sender ON message (sender);
CREATE INDEX idx_message_type ON message (type);
CREATE INDEX idx_message_is_read ON message (is_read);
CREATE INDEX idx_message_create_time ON message (create_time);
CREATE INDEX idx_message_coze_chat_id ON message (coze_chat_id);
CREATE INDEX idx_message_status ON message (status);
CREATE INDEX idx_message_parent_message_id ON message (parent_message_id);
CREATE INDEX idx_message_create_by ON message (create_by);
CREATE INDEX idx_message_update_by ON message (update_by);
CREATE INDEX idx_message_is_deleted ON message (is_deleted);
-- coze_api_call表索引
CREATE INDEX idx_coze_api_call_conversation_id ON coze_api_call (conversation_id);
CREATE INDEX idx_coze_api_call_message_id ON coze_api_call (message_id);
CREATE INDEX idx_coze_api_call_coze_chat_id ON coze_api_call (coze_chat_id);
CREATE INDEX idx_coze_api_call_bot_id ON coze_api_call (bot_id);
CREATE INDEX idx_coze_api_call_user_id ON coze_api_call (user_id);
CREATE INDEX idx_coze_api_call_status ON coze_api_call (status);
CREATE INDEX idx_coze_api_call_final_status ON coze_api_call (final_status);
CREATE INDEX idx_coze_api_call_start_time ON coze_api_call (start_time);
CREATE INDEX idx_coze_api_call_request_type ON coze_api_call (request_type);
CREATE INDEX idx_coze_api_call_client_ip ON coze_api_call (client_ip);
CREATE INDEX idx_coze_api_call_session_id ON coze_api_call (session_id);
CREATE INDEX idx_coze_api_call_trace_id ON coze_api_call (trace_id);
CREATE INDEX idx_coze_api_call_user_status ON coze_api_call (user_id, status);
CREATE INDEX idx_coze_api_call_conversation_time ON coze_api_call (conversation_id, start_time);
-- emotion_analysis表索引
CREATE INDEX idx_emotion_analysis_user_id ON emotion_analysis (user_id);
CREATE INDEX idx_emotion_analysis_message_id ON emotion_analysis (message_id);
CREATE INDEX idx_emotion_analysis_primary_emotion ON emotion_analysis (primary_emotion);
CREATE INDEX idx_emotion_analysis_analysis_time ON emotion_analysis (analysis_time);
CREATE INDEX idx_emotion_analysis_create_time ON emotion_analysis (create_time);
CREATE INDEX idx_emotion_analysis_create_by ON emotion_analysis (create_by);
CREATE INDEX idx_emotion_analysis_update_by ON emotion_analysis (update_by);
CREATE INDEX idx_emotion_analysis_is_deleted ON emotion_analysis (is_deleted);
-- emotion_record表索引
CREATE INDEX idx_emotion_record_user_id ON emotion_record (user_id);
CREATE INDEX idx_emotion_record_date ON emotion_record (record_date);
CREATE INDEX idx_emotion_record_emotion_type ON emotion_record (emotion_type);
CREATE INDEX idx_emotion_record_user_id_date ON emotion_record (user_id, record_date);
CREATE INDEX idx_emotion_record_user_id_emotion_type ON emotion_record (user_id, emotion_type);
CREATE INDEX idx_emotion_record_intensity ON emotion_record (intensity);
CREATE INDEX idx_emotion_record_create_time ON emotion_record (create_time);
CREATE INDEX idx_emotion_record_create_by ON emotion_record (create_by);
CREATE INDEX idx_emotion_record_update_by ON emotion_record (update_by);
CREATE INDEX idx_emotion_record_is_deleted ON emotion_record (is_deleted);
-- growth_topic表索引
CREATE INDEX idx_growth_topic_category ON growth_topic (category);
CREATE INDEX idx_growth_topic_difficulty ON growth_topic (difficulty);
CREATE INDEX idx_growth_topic_is_unlocked ON growth_topic (is_unlocked);
CREATE INDEX idx_growth_topic_progress ON growth_topic (progress);
CREATE INDEX idx_growth_topic_completed_time ON growth_topic (completed_time);
CREATE INDEX idx_growth_topic_category_difficulty ON growth_topic (category, difficulty);
CREATE INDEX idx_growth_topic_create_time ON growth_topic (create_time);
-- topic_interaction表索引
CREATE INDEX idx_topic_interaction_topic_id ON topic_interaction (topic_id);
CREATE INDEX idx_topic_interaction_type ON topic_interaction (type);
CREATE INDEX idx_topic_interaction_completed_time ON topic_interaction (completed_time);
CREATE INDEX idx_topic_interaction_rating ON topic_interaction (rating);
CREATE INDEX idx_topic_interaction_topic_id_type ON topic_interaction (topic_id, type);
CREATE INDEX idx_topic_interaction_create_time ON topic_interaction (create_time);
-- location_pin表索引
CREATE INDEX idx_location_pin_latitude_longitude ON location_pin (latitude, longitude);
CREATE INDEX idx_location_pin_type ON location_pin (type);
CREATE INDEX idx_location_pin_category ON location_pin (category);
CREATE INDEX idx_location_pin_created_by ON location_pin (created_by);
CREATE INDEX idx_location_pin_likes ON location_pin (likes);
CREATE INDEX idx_location_pin_visits ON location_pin (visits);
CREATE INDEX idx_location_pin_is_bookmarked ON location_pin (is_bookmarked);
CREATE INDEX idx_location_pin_type_category ON location_pin (type, category);
CREATE INDEX idx_location_pin_create_time ON location_pin (create_time);
CREATE INDEX idx_location_pin_last_visit_time ON location_pin (last_visit_time);
-- community_post表索引
CREATE INDEX idx_community_post_user_id ON community_post (user_id);
CREATE INDEX idx_community_post_location_id ON community_post (location_id);
CREATE INDEX idx_community_post_create_time ON community_post (create_time);
CREATE INDEX idx_community_post_type ON community_post (type);
CREATE INDEX idx_community_post_likes ON community_post (likes);
CREATE INDEX idx_community_post_view_count ON community_post (view_count);
CREATE INDEX idx_community_post_is_private ON community_post (is_private);
CREATE INDEX idx_community_post_user_id_create_time ON community_post (user_id, create_time);
CREATE INDEX idx_community_post_type_create_time ON community_post (type, create_time);
-- comment表索引
CREATE INDEX idx_comment_post_id ON comment (post_id);
CREATE INDEX idx_comment_user_id ON comment (user_id);
CREATE INDEX idx_comment_reply_to_id ON comment (reply_to_id);
CREATE INDEX idx_comment_create_time ON comment (create_time);
CREATE INDEX idx_comment_likes ON comment (likes);
CREATE INDEX idx_comment_post_id_create_time ON comment (post_id, create_time);
-- achievement表索引
CREATE INDEX idx_achievement_category ON achievement (category);
CREATE INDEX idx_achievement_rarity ON achievement (rarity);
CREATE INDEX idx_achievement_unlocked_time ON achievement (unlocked_time);
CREATE INDEX idx_achievement_is_hidden ON achievement (is_hidden);
CREATE INDEX idx_achievement_progress ON achievement (progress);
CREATE INDEX idx_achievement_category_rarity ON achievement (category, rarity);
CREATE INDEX idx_achievement_create_time ON achievement (create_time);
-- reward表索引
CREATE INDEX idx_reward_topic_id ON reward (topic_id);
CREATE INDEX idx_reward_achievement_id ON reward (achievement_id);
CREATE INDEX idx_reward_type ON reward (type);
CREATE INDEX idx_reward_earned_time ON reward (earned_time);
CREATE INDEX idx_reward_rarity ON reward (rarity);
CREATE INDEX idx_reward_is_new ON reward (is_new);
CREATE INDEX idx_reward_type_earned_time ON reward (type, earned_time);
CREATE INDEX idx_reward_create_time ON reward (create_time);
-- user_stats表索引
CREATE INDEX idx_user_stats_user_id ON user_stats (user_id);
CREATE INDEX idx_user_stats_total_points ON user_stats (total_points);
CREATE INDEX idx_user_stats_consecutive_days ON user_stats (consecutive_days);
CREATE INDEX idx_user_stats_max_consecutive_days ON user_stats (max_consecutive_days);
CREATE INDEX idx_user_stats_social_interactions ON user_stats (social_interactions);
CREATE INDEX idx_user_stats_update_time ON user_stats (update_time);
CREATE INDEX idx_user_stats_create_time ON user_stats (create_time);
-- user_stats表日记相关索引
CREATE INDEX idx_user_stats_diary_posts_created ON user_stats (diary_posts_created);
CREATE INDEX idx_user_stats_diary_likes_received ON user_stats (diary_likes_received);
CREATE INDEX idx_user_stats_diary_comments_received ON user_stats (diary_comments_received);
CREATE INDEX idx_user_stats_diary_views_received ON user_stats (diary_views_received);
CREATE INDEX idx_user_stats_featured_diary_count ON user_stats (featured_diary_count);
CREATE INDEX idx_user_stats_ai_comments_received ON user_stats (ai_comments_received);
-- diary_post表索引
CREATE INDEX idx_diary_post_user_id ON diary_post (user_id);
CREATE INDEX idx_diary_post_publish_time ON diary_post (publish_time);
CREATE INDEX idx_diary_post_last_comment_time ON diary_post (last_comment_time);
CREATE INDEX idx_diary_post_status ON diary_post (status);
CREATE INDEX idx_diary_post_priority ON diary_post (priority);
CREATE INDEX idx_diary_post_featured ON diary_post (featured);
CREATE INDEX idx_diary_post_create_time ON diary_post (create_time);
-- diary_comment表索引
CREATE INDEX idx_diary_comment_diary_id ON diary_comment (diary_id);
CREATE INDEX idx_diary_comment_user_id ON diary_comment (user_id);
CREATE INDEX idx_diary_comment_parent_comment_id ON diary_comment (parent_comment_id);
CREATE INDEX idx_diary_comment_publish_time ON diary_comment (publish_time);
CREATE INDEX idx_diary_comment_last_reply_time ON diary_comment (last_reply_time);
CREATE INDEX idx_diary_comment_emotion_score ON diary_comment (emotion_score);
CREATE INDEX idx_diary_comment_sentiment_score ON diary_comment (sentiment_score);
CREATE INDEX idx_diary_comment_create_time ON diary_comment (create_time);
-- diary_post表复合索引和功能索引
CREATE INDEX idx_diary_post_user_publish ON diary_post (user_id, publish_time);
CREATE INDEX idx_diary_post_user_status ON diary_post (user_id, status);
CREATE INDEX idx_diary_post_public_publish ON diary_post (is_public, publish_time);
CREATE INDEX idx_diary_post_featured_publish ON diary_post (featured, publish_time);
CREATE INDEX idx_diary_post_mood_score ON diary_post (mood_score);
CREATE INDEX idx_diary_post_ai_sentiment ON diary_post (ai_sentiment_score);
CREATE INDEX idx_diary_post_location ON diary_post (latitude, longitude);
CREATE INDEX idx_diary_post_like_count ON diary_post (like_count);
CREATE INDEX idx_diary_post_comment_count ON diary_post (comment_count);
CREATE INDEX idx_diary_post_view_count ON diary_post (view_count);
CREATE INDEX idx_diary_post_create_by ON diary_post (create_by);
CREATE INDEX idx_diary_post_update_by ON diary_post (update_by);
CREATE INDEX idx_diary_post_is_deleted ON diary_post (is_deleted);
-- diary_comment表复合索引和功能索引
CREATE INDEX idx_diary_comment_diary_publish ON diary_comment (diary_id, publish_time);
CREATE INDEX idx_diary_comment_diary_type ON diary_comment (diary_id, comment_type);
CREATE INDEX idx_diary_comment_user_publish ON diary_comment (user_id, publish_time);
CREATE INDEX idx_diary_comment_parent_publish ON diary_comment (parent_comment_id, publish_time);
CREATE INDEX idx_diary_comment_type_publish ON diary_comment (comment_type, publish_time);
CREATE INDEX idx_diary_comment_status ON diary_comment (status);
CREATE INDEX idx_diary_comment_is_top ON diary_comment (is_top);
CREATE INDEX idx_diary_comment_like_count ON diary_comment (like_count);
CREATE INDEX idx_diary_comment_reply_count ON diary_comment (reply_count);
CREATE INDEX idx_diary_comment_ai_source ON diary_comment (ai_comment_source);
CREATE INDEX idx_diary_comment_create_by ON diary_comment (create_by);
CREATE INDEX idx_diary_comment_update_by ON diary_comment (update_by);
CREATE INDEX idx_diary_comment_is_deleted ON diary_comment (is_deleted);
-- guest_user表索引
CREATE INDEX idx_guest_user_guest_user_id ON guest_user (guest_user_id);
CREATE INDEX idx_guest_user_ip_address ON guest_user (ip_address);
CREATE INDEX idx_guest_user_last_active_time ON guest_user (last_active_time);
CREATE INDEX idx_guest_user_conversation_count ON guest_user (conversation_count);
CREATE INDEX idx_guest_user_message_count ON guest_user (message_count);
CREATE INDEX idx_guest_user_create_time ON guest_user (create_time);
CREATE INDEX idx_guest_user_create_by ON guest_user (create_by);
CREATE INDEX idx_guest_user_update_by ON guest_user (update_by);
CREATE INDEX idx_guest_user_is_deleted ON guest_user (is_deleted);
-- t_user表索引
CREATE INDEX idx_user_account ON t_user (account);
CREATE INDEX idx_user_username ON t_user (username);
CREATE INDEX idx_user_email ON t_user (email);
CREATE INDEX idx_user_phone ON t_user (phone);
CREATE INDEX idx_user_last_active_time ON t_user (last_active_time);
CREATE INDEX idx_user_create_time ON t_user (create_time);
CREATE INDEX idx_user_member_level ON t_user (member_level);
CREATE INDEX idx_user_status ON t_user (status);
CREATE INDEX idx_user_is_verified ON t_user (is_verified);
CREATE INDEX idx_user_create_by ON t_user (create_by);
CREATE INDEX idx_user_update_by ON t_user (update_by);
CREATE INDEX idx_user_is_deleted ON t_user (is_deleted);
CREATE INDEX idx_user_third_party_id ON t_user (third_party_id);
CREATE INDEX idx_user_third_party_type ON t_user (third_party_type);
-- t_conversation表索引
CREATE INDEX idx_conversation_user_id ON t_conversation (user_id);
CREATE INDEX idx_conversation_start_time ON t_conversation (start_time);
CREATE INDEX idx_conversation_user_id_start_time ON t_conversation (user_id, start_time);
CREATE INDEX idx_conversation_primary_emotion ON t_conversation (primary_emotion);
CREATE INDEX idx_conversation_end_time ON t_conversation (end_time);
CREATE INDEX idx_conversation_create_time ON t_conversation (create_time);
CREATE INDEX idx_conversation_coze_conversation_id ON t_conversation (coze_conversation_id);
CREATE INDEX idx_conversation_status ON t_conversation (status);
CREATE INDEX idx_conversation_last_active_time ON t_conversation (last_active_time);
CREATE INDEX idx_conversation_create_by ON t_conversation (create_by);
CREATE INDEX idx_conversation_update_by ON t_conversation (update_by);
CREATE INDEX idx_conversation_is_deleted ON t_conversation (is_deleted);
CREATE INDEX idx_conversation_user_type ON t_conversation (user_type);
CREATE INDEX idx_conversation_emotion_trend ON t_conversation (emotion_trend);
CREATE INDEX idx_conversation_confidence ON t_conversation (confidence);
CREATE INDEX idx_conversation_client_ip ON t_conversation (client_ip);
-- t_message表索引
CREATE INDEX idx_message_conversation_id ON t_message (conversation_id);
CREATE INDEX idx_message_timestamp ON t_message (timestamp);
CREATE INDEX idx_message_conversation_id_timestamp ON t_message (conversation_id, timestamp);
CREATE INDEX idx_message_sender ON t_message (sender);
CREATE INDEX idx_message_type ON t_message (type);
CREATE INDEX idx_message_is_read ON t_message (is_read);
CREATE INDEX idx_message_create_time ON t_message (create_time);
CREATE INDEX idx_message_coze_chat_id ON t_message (coze_chat_id);
CREATE INDEX idx_message_status ON t_message (status);
CREATE INDEX idx_message_parent_message_id ON t_message (parent_message_id);
CREATE INDEX idx_message_create_by ON t_message (create_by);
CREATE INDEX idx_message_update_by ON t_message (update_by);
CREATE INDEX idx_message_is_deleted ON t_message (is_deleted);
-- t_coze_api_call表索引
CREATE INDEX idx_coze_api_call_conversation_id ON t_coze_api_call (conversation_id);
CREATE INDEX idx_coze_api_call_message_id ON t_coze_api_call (message_id);
CREATE INDEX idx_coze_api_call_coze_chat_id ON t_coze_api_call (coze_chat_id);
CREATE INDEX idx_coze_api_call_bot_id ON t_coze_api_call (bot_id);
CREATE INDEX idx_coze_api_call_user_id ON t_coze_api_call (user_id);
CREATE INDEX idx_coze_api_call_status ON t_coze_api_call (status);
CREATE INDEX idx_coze_api_call_final_status ON t_coze_api_call (final_status);
CREATE INDEX idx_coze_api_call_start_time ON t_coze_api_call (start_time);
CREATE INDEX idx_coze_api_call_request_type ON t_coze_api_call (request_type);
CREATE INDEX idx_coze_api_call_client_ip ON t_coze_api_call (client_ip);
CREATE INDEX idx_coze_api_call_session_id ON t_coze_api_call (session_id);
CREATE INDEX idx_coze_api_call_trace_id ON t_coze_api_call (trace_id);
CREATE INDEX idx_coze_api_call_user_status ON t_coze_api_call (user_id, status);
CREATE INDEX idx_coze_api_call_conversation_time ON t_coze_api_call (conversation_id, start_time);
-- t_emotion_analysis表索引
CREATE INDEX idx_emotion_analysis_user_id ON t_emotion_analysis (user_id);
CREATE INDEX idx_emotion_analysis_message_id ON t_emotion_analysis (message_id);
CREATE INDEX idx_emotion_analysis_primary_emotion ON t_emotion_analysis (primary_emotion);
CREATE INDEX idx_emotion_analysis_analysis_time ON t_emotion_analysis (analysis_time);
CREATE INDEX idx_emotion_analysis_create_time ON t_emotion_analysis (create_time);
CREATE INDEX idx_emotion_analysis_create_by ON t_emotion_analysis (create_by);
CREATE INDEX idx_emotion_analysis_update_by ON t_emotion_analysis (update_by);
CREATE INDEX idx_emotion_analysis_is_deleted ON t_emotion_analysis (is_deleted);
-- t_emotion_record表索引
CREATE INDEX idx_emotion_record_user_id ON t_emotion_record (user_id);
CREATE INDEX idx_emotion_record_date ON t_emotion_record (record_date);
CREATE INDEX idx_emotion_record_emotion_type ON t_emotion_record (emotion_type);
CREATE INDEX idx_emotion_record_user_id_date ON t_emotion_record (user_id, record_date);
CREATE INDEX idx_emotion_record_user_id_emotion_type ON t_emotion_record (user_id, emotion_type);
CREATE INDEX idx_emotion_record_intensity ON t_emotion_record (intensity);
CREATE INDEX idx_emotion_record_create_time ON t_emotion_record (create_time);
CREATE INDEX idx_emotion_record_create_by ON t_emotion_record (create_by);
CREATE INDEX idx_emotion_record_update_by ON t_emotion_record (update_by);
CREATE INDEX idx_emotion_record_is_deleted ON t_emotion_record (is_deleted);
-- t_growth_topic表索引
CREATE INDEX idx_growth_topic_category ON t_growth_topic (category);
CREATE INDEX idx_growth_topic_difficulty ON t_growth_topic (difficulty);
CREATE INDEX idx_growth_topic_is_unlocked ON t_growth_topic (is_unlocked);
CREATE INDEX idx_growth_topic_progress ON t_growth_topic (progress);
CREATE INDEX idx_growth_topic_completed_time ON t_growth_topic (completed_time);
CREATE INDEX idx_growth_topic_category_difficulty ON t_growth_topic (category, difficulty);
CREATE INDEX idx_growth_topic_create_time ON t_growth_topic (create_time);
-- t_topic_interaction表索引
CREATE INDEX idx_topic_interaction_topic_id ON t_topic_interaction (topic_id);
CREATE INDEX idx_topic_interaction_type ON t_topic_interaction (type);
CREATE INDEX idx_topic_interaction_completed_time ON t_topic_interaction (completed_time);
CREATE INDEX idx_topic_interaction_rating ON t_topic_interaction (rating);
CREATE INDEX idx_topic_interaction_topic_id_type ON t_topic_interaction (topic_id, type);
CREATE INDEX idx_topic_interaction_create_time ON t_topic_interaction (create_time);
-- t_location_pin表索引
CREATE INDEX idx_location_pin_latitude_longitude ON t_location_pin (latitude, longitude);
CREATE INDEX idx_location_pin_type ON t_location_pin (type);
CREATE INDEX idx_location_pin_category ON t_location_pin (category);
CREATE INDEX idx_location_pin_create_by ON t_location_pin (create_by);
CREATE INDEX idx_location_pin_likes ON t_location_pin (likes);
CREATE INDEX idx_location_pin_visits ON t_location_pin (visits);
CREATE INDEX idx_location_pin_is_bookmarked ON t_location_pin (is_bookmarked);
CREATE INDEX idx_location_pin_type_category ON t_location_pin (type, category);
CREATE INDEX idx_location_pin_create_time ON t_location_pin (create_time);
CREATE INDEX idx_location_pin_last_visit_time ON t_location_pin (last_visit_time);
-- t_community_post表索引
CREATE INDEX idx_community_post_user_id ON t_community_post (user_id);
CREATE INDEX idx_community_post_location_id ON t_community_post (location_id);
CREATE INDEX idx_community_post_create_time ON t_community_post (create_time);
CREATE INDEX idx_community_post_type ON t_community_post (type);
CREATE INDEX idx_community_post_likes ON t_community_post (likes);
CREATE INDEX idx_community_post_view_count ON t_community_post (view_count);
CREATE INDEX idx_community_post_is_private ON t_community_post (is_private);
CREATE INDEX idx_community_post_user_id_create_time ON t_community_post (user_id, create_time);
CREATE INDEX idx_community_post_type_create_time ON t_community_post (type, create_time);
-- t_comment表索引
CREATE INDEX idx_comment_post_id ON t_comment (post_id);
CREATE INDEX idx_comment_user_id ON t_comment (user_id);
CREATE INDEX idx_comment_reply_to_id ON t_comment (reply_to_id);
CREATE INDEX idx_comment_create_time ON t_comment (create_time);
CREATE INDEX idx_comment_likes ON t_comment (likes);
CREATE INDEX idx_comment_post_id_create_time ON t_comment (post_id, create_time);
-- t_achievement表索引
CREATE INDEX idx_achievement_category ON t_achievement (category);
CREATE INDEX idx_achievement_rarity ON t_achievement (rarity);
CREATE INDEX idx_achievement_unlocked_time ON t_achievement (unlocked_time);
CREATE INDEX idx_achievement_is_hidden ON t_achievement (is_hidden);
CREATE INDEX idx_achievement_progress ON t_achievement (progress);
CREATE INDEX idx_achievement_category_rarity ON t_achievement (category, rarity);
CREATE INDEX idx_achievement_create_time ON t_achievement (create_time);
-- t_reward表索引
CREATE INDEX idx_reward_topic_id ON t_reward (topic_id);
CREATE INDEX idx_reward_achievement_id ON t_reward (achievement_id);
CREATE INDEX idx_reward_type ON t_reward (type);
CREATE INDEX idx_reward_earned_time ON t_reward (earned_time);
CREATE INDEX idx_reward_rarity ON t_reward (rarity);
CREATE INDEX idx_reward_is_new ON t_reward (is_new);
CREATE INDEX idx_reward_type_earned_time ON t_reward (type, earned_time);
CREATE INDEX idx_reward_create_time ON t_reward (create_time);
-- t_user_stats表索引
CREATE INDEX idx_user_stats_user_id ON t_user_stats (user_id);
CREATE INDEX idx_user_stats_total_points ON t_user_stats (total_points);
CREATE INDEX idx_user_stats_consecutive_days ON t_user_stats (consecutive_days);
CREATE INDEX idx_user_stats_max_consecutive_days ON t_user_stats (max_consecutive_days);
CREATE INDEX idx_user_stats_social_interactions ON t_user_stats (social_interactions);
CREATE INDEX idx_user_stats_update_time ON t_user_stats (update_time);
CREATE INDEX idx_user_stats_create_time ON t_user_stats (create_time);
-- t_user_stats表日记相关索引
CREATE INDEX idx_user_stats_diary_posts_created ON t_user_stats (diary_posts_created);
CREATE INDEX idx_user_stats_diary_likes_received ON t_user_stats (diary_likes_received);
CREATE INDEX idx_user_stats_diary_comments_received ON t_user_stats (diary_comments_received);
CREATE INDEX idx_user_stats_diary_views_received ON t_user_stats (diary_views_received);
CREATE INDEX idx_user_stats_featured_diary_count ON t_user_stats (featured_diary_count);
CREATE INDEX idx_user_stats_ai_comments_received ON t_user_stats (ai_comments_received);
-- t_diary_post表索引
CREATE INDEX idx_diary_post_user_id ON t_diary_post (user_id);
CREATE INDEX idx_diary_post_publish_time ON t_diary_post (publish_time);
CREATE INDEX idx_diary_post_last_comment_time ON t_diary_post (last_comment_time);
CREATE INDEX idx_diary_post_status ON t_diary_post (status);
CREATE INDEX idx_diary_post_priority ON t_diary_post (priority);
CREATE INDEX idx_diary_post_featured ON t_diary_post (featured);
CREATE INDEX idx_diary_post_create_time ON t_diary_post (create_time);
-- t_diary_comment表索引
CREATE INDEX idx_diary_comment_diary_id ON t_diary_comment (diary_id);
CREATE INDEX idx_diary_comment_user_id ON t_diary_comment (user_id);
CREATE INDEX idx_diary_comment_parent_comment_id ON t_diary_comment (parent_comment_id);
CREATE INDEX idx_diary_comment_publish_time ON t_diary_comment (publish_time);
CREATE INDEX idx_diary_comment_last_reply_time ON t_diary_comment (last_reply_time);
CREATE INDEX idx_diary_comment_emotion_score ON t_diary_comment (emotion_score);
CREATE INDEX idx_diary_comment_sentiment_score ON t_diary_comment (sentiment_score);
CREATE INDEX idx_diary_comment_create_time ON t_diary_comment (create_time);
-- t_diary_post表复合索引和功能索引
CREATE INDEX idx_diary_post_user_publish ON t_diary_post (user_id, publish_time);
CREATE INDEX idx_diary_post_user_status ON t_diary_post (user_id, status);
CREATE INDEX idx_diary_post_public_publish ON t_diary_post (is_public, publish_time);
CREATE INDEX idx_diary_post_featured_publish ON t_diary_post (featured, publish_time);
CREATE INDEX idx_diary_post_mood_score ON t_diary_post (mood_score);
CREATE INDEX idx_diary_post_ai_sentiment ON t_diary_post (ai_sentiment_score);
CREATE INDEX idx_diary_post_location ON t_diary_post (latitude, longitude);
CREATE INDEX idx_diary_post_like_count ON t_diary_post (like_count);
CREATE INDEX idx_diary_post_comment_count ON t_diary_post (comment_count);
CREATE INDEX idx_diary_post_view_count ON t_diary_post (view_count);
CREATE INDEX idx_diary_post_create_by ON t_diary_post (create_by);
CREATE INDEX idx_diary_post_update_by ON t_diary_post (update_by);
CREATE INDEX idx_diary_post_is_deleted ON t_diary_post (is_deleted);
-- t_diary_comment表复合索引和功能索引
CREATE INDEX idx_diary_comment_diary_publish ON t_diary_comment (diary_id, publish_time);
CREATE INDEX idx_diary_comment_diary_type ON t_diary_comment (diary_id, comment_type);
CREATE INDEX idx_diary_comment_user_publish ON t_diary_comment (user_id, publish_time);
CREATE INDEX idx_diary_comment_parent_publish ON t_diary_comment (parent_comment_id, publish_time);
CREATE INDEX idx_diary_comment_type_publish ON t_diary_comment (comment_type, publish_time);
CREATE INDEX idx_diary_comment_status ON t_diary_comment (status);
CREATE INDEX idx_diary_comment_is_top ON t_diary_comment (is_top);
CREATE INDEX idx_diary_comment_like_count ON t_diary_comment (like_count);
CREATE INDEX idx_diary_comment_reply_count ON t_diary_comment (reply_count);
CREATE INDEX idx_diary_comment_ai_source ON t_diary_comment (ai_comment_source);
CREATE INDEX idx_diary_comment_create_by ON t_diary_comment (create_by);
CREATE INDEX idx_diary_comment_update_by ON t_diary_comment (update_by);
CREATE INDEX idx_diary_comment_is_deleted ON t_diary_comment (is_deleted);
-- t_guest_user表索引
CREATE INDEX idx_guest_user_guest_user_id ON t_guest_user (guest_user_id);
CREATE INDEX idx_guest_user_ip_address ON t_guest_user (ip_address);
CREATE INDEX idx_guest_user_last_active_time ON t_guest_user (last_active_time);
CREATE INDEX idx_guest_user_conversation_count ON t_guest_user (conversation_count);
CREATE INDEX idx_guest_user_message_count ON t_guest_user (message_count);
CREATE INDEX idx_guest_user_create_time ON t_guest_user (create_time);
CREATE INDEX idx_guest_user_create_by ON t_guest_user (create_by);
CREATE INDEX idx_guest_user_update_by ON t_guest_user (update_by);
CREATE INDEX idx_guest_user_is_deleted ON t_guest_user (is_deleted);
-- ============================================================================
-- 数据库统计信息
@@ -1026,7 +858,8 @@ SELECT
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = 'emotion';
TABLE_SCHEMA = 'emotion'
AND TABLE_NAME LIKE 't\_%' ESCAPE '\\';
-- 显示创建的表
SELECT
@@ -1037,6 +870,7 @@ FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = 'emotion'
AND TABLE_NAME LIKE 't\_%' ESCAPE '\\'
ORDER BY
TABLE_NAME;