加入指令数据统计,指令看板内容
This commit is contained in:
64
db/scripts/create_stats_tables.sql
Normal file
64
db/scripts/create_stats_tables.sql
Normal file
@@ -0,0 +1,64 @@
|
||||
-- 插件统计汇总表
|
||||
CREATE TABLE IF NOT EXISTS t_plugin_stats (
|
||||
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||
plugin_name VARCHAR(50) NOT NULL COMMENT '插件名称',
|
||||
command VARCHAR(50) NOT NULL COMMENT '触发的命令',
|
||||
stat_date DATE NOT NULL COMMENT '统计日期',
|
||||
total_calls INT NOT NULL DEFAULT 0 COMMENT '总调用次数',
|
||||
success_calls INT NOT NULL DEFAULT 0 COMMENT '成功调用次数',
|
||||
failed_calls INT NOT NULL DEFAULT 0 COMMENT '失败调用次数',
|
||||
group_calls INT NOT NULL DEFAULT 0 COMMENT '群聊调用次数',
|
||||
private_calls INT NOT NULL DEFAULT 0 COMMENT '私聊调用次数',
|
||||
avg_process_time FLOAT NOT NULL DEFAULT 0 COMMENT '平均处理时间(毫秒)',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
UNIQUE KEY uk_plugin_command_date (plugin_name, command, stat_date),
|
||||
INDEX idx_stat_date (stat_date)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='插件统计汇总表';
|
||||
|
||||
-- 用户使用统计表
|
||||
CREATE TABLE IF NOT EXISTS t_user_stats (
|
||||
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||
user_id VARCHAR(50) NOT NULL COMMENT '用户ID',
|
||||
plugin_name VARCHAR(50) NOT NULL COMMENT '插件名称',
|
||||
command VARCHAR(50) NOT NULL COMMENT '触发的命令',
|
||||
total_calls INT NOT NULL DEFAULT 0 COMMENT '总调用次数',
|
||||
success_calls INT NOT NULL DEFAULT 0 COMMENT '成功调用次数',
|
||||
failed_calls INT NOT NULL DEFAULT 0 COMMENT '失败调用次数',
|
||||
first_used_at DATETIME NOT NULL COMMENT '首次使用时间',
|
||||
last_used_at DATETIME NOT NULL COMMENT '最后使用时间',
|
||||
UNIQUE KEY uk_user_plugin_command (user_id, plugin_name, command),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_last_used_at (last_used_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户使用统计表';
|
||||
|
||||
-- 群组使用统计表
|
||||
CREATE TABLE IF NOT EXISTS t_group_stats (
|
||||
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||
group_id VARCHAR(50) NOT NULL COMMENT '群组ID',
|
||||
plugin_name VARCHAR(50) NOT NULL COMMENT '插件名称',
|
||||
command VARCHAR(50) NOT NULL COMMENT '触发的命令',
|
||||
total_calls INT NOT NULL DEFAULT 0 COMMENT '总调用次数',
|
||||
success_calls INT NOT NULL DEFAULT 0 COMMENT '成功调用次数',
|
||||
failed_calls INT NOT NULL DEFAULT 0 COMMENT '失败调用次数',
|
||||
unique_users INT NOT NULL DEFAULT 0 COMMENT '唯一用户数',
|
||||
first_used_at DATETIME NOT NULL COMMENT '首次使用时间',
|
||||
last_used_at DATETIME NOT NULL COMMENT '最后使用时间',
|
||||
UNIQUE KEY uk_group_plugin_command (group_id, plugin_name, command),
|
||||
INDEX idx_group_id (group_id),
|
||||
INDEX idx_last_used_at (last_used_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='群组使用统计表';
|
||||
|
||||
-- 错误日志表
|
||||
CREATE TABLE IF NOT EXISTS t_error_logs (
|
||||
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||
plugin_name VARCHAR(50) NOT NULL COMMENT '插件名称',
|
||||
command VARCHAR(50) NOT NULL COMMENT '触发的命令',
|
||||
user_id VARCHAR(50) NOT NULL COMMENT '用户ID',
|
||||
group_id VARCHAR(50) COMMENT '群组ID,私聊为NULL',
|
||||
error_message TEXT NOT NULL COMMENT '错误信息',
|
||||
stack_trace TEXT COMMENT '堆栈跟踪',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
INDEX idx_plugin_name (plugin_name),
|
||||
INDEX idx_created_at (created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='错误日志表';
|
||||
119
db/scripts/init.sql
Normal file
119
db/scripts/init.sql
Normal file
@@ -0,0 +1,119 @@
|
||||
-- 创建数据库
|
||||
CREATE DATABASE IF NOT EXISTS message_archive CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE message_archive;
|
||||
CREATE TABLE IF NOT EXISTS message_archive.messages
|
||||
(
|
||||
id int auto_increment comment '自增主键ID'
|
||||
primary key,
|
||||
group_id varchar(20) null comment '群ID',
|
||||
timestamp varchar(20) not null comment '消息时间戳',
|
||||
sender varchar(255) not null comment '发送者微信ID',
|
||||
content text null comment '消息内容',
|
||||
message_type varchar(50) null comment '消息类型(文本、图片、视频等)',
|
||||
attachment_url varchar(512) null comment '附件URL(图片、视频链接)',
|
||||
message_id varchar(32) null comment '消息 id',
|
||||
message_xml text null comment '消息 xml 部分',
|
||||
message_thumb text null comment '视频或图片消息的缩略图路径'
|
||||
)
|
||||
comment '微信群消息存储表,记录所有群聊消息';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.speech_counts
|
||||
(
|
||||
id int auto_increment comment '自增主键ID'
|
||||
primary key,
|
||||
group_id text null comment '群聊ID',
|
||||
wx_id text null comment '用户微信ID',
|
||||
date text null comment '统计日期(YYYY-MM-DD格式)',
|
||||
count int null comment '发言次数',
|
||||
constraint speech_counts_group_id_wx_id_date_uindex
|
||||
unique (group_id, wx_id, date) using hash
|
||||
)
|
||||
comment '群成员每日发言统计表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_active_tasks
|
||||
(
|
||||
active_task_id int auto_increment comment '任务ID'
|
||||
primary key,
|
||||
group_id varchar(50) not null comment '群聊ID',
|
||||
question varchar(255) not null comment '问题内容',
|
||||
answer varchar(100) not null comment '正确答案',
|
||||
score int not null comment '答对可获得的分数',
|
||||
description text null comment '问题描述或提示',
|
||||
holder_id varchar(50) not null comment '出题人ID',
|
||||
assigned_at datetime default current_timestamp() null comment '任务分配时间',
|
||||
status enum ('pending', 'completed') default 'pending' null comment '任务状态',
|
||||
question_id int null comment '问题ID'
|
||||
)
|
||||
comment '百科答题游戏活跃任务表';
|
||||
|
||||
create or replace index group_id
|
||||
on message_archive.t_encyclopedia_active_tasks (group_id);
|
||||
|
||||
create or replace index question_id
|
||||
on message_archive.t_encyclopedia_active_tasks (question_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_groups
|
||||
(
|
||||
group_id varchar(50) not null comment '群聊ID'
|
||||
primary key,
|
||||
created_at datetime default current_timestamp() null comment '记录创建时间'
|
||||
)
|
||||
comment '百科答题游戏群聊表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_players
|
||||
(
|
||||
player_id varchar(50) not null comment '玩家ID(微信ID)',
|
||||
group_id varchar(50) not null comment '群聊ID',
|
||||
player_name varchar(50) not null comment '玩家名称',
|
||||
points int default 0 null comment '玩家积分',
|
||||
created_at datetime default current_timestamp() null comment '记录创建时间',
|
||||
primary key (player_id, group_id)
|
||||
)
|
||||
comment '百科答题游戏玩家表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.t_encyclopedia_task_history
|
||||
(
|
||||
history_id int auto_increment comment '历史记录ID'
|
||||
primary key,
|
||||
group_id varchar(50) not null comment '群聊ID',
|
||||
active_task_id int not null comment '关联的任务ID',
|
||||
player_id varchar(50) not null comment '回答者ID',
|
||||
answer varchar(100) not null comment '玩家的回答',
|
||||
is_correct tinyint(1) default 0 null comment '是否回答正确',
|
||||
points_earned int default 0 null comment '获得的积分',
|
||||
completed_at datetime default current_timestamp() null comment '完成时间'
|
||||
)
|
||||
comment '百科答题游戏任务历史表';
|
||||
|
||||
create or replace index group_id
|
||||
on message_archive.t_encyclopedia_task_history (group_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.t_sign_record
|
||||
(
|
||||
id bigint auto_increment comment '自增主键ID'
|
||||
primary key,
|
||||
wx_id varchar(100) not null comment '用户微信ID',
|
||||
group_id varchar(100) not null comment '群聊ID',
|
||||
wx_nick_name varchar(100) not null comment '用户昵称',
|
||||
points int default 0 null comment '积分数量',
|
||||
sign_stat datetime null comment '最近签到时间',
|
||||
signin_streak int default 0 null comment '连续签到天数',
|
||||
create_time datetime default current_timestamp() null comment '记录创建时间',
|
||||
update_time datetime default current_timestamp() null on update current_timestamp() comment '记录更新时间',
|
||||
constraint unique_sign
|
||||
unique (wx_id, group_id)
|
||||
)
|
||||
comment '用户群内签到记录表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_archive.tasks
|
||||
(
|
||||
task_id int auto_increment comment '任务ID'
|
||||
primary key,
|
||||
task_description varchar(255) not null comment '任务描述',
|
||||
reminder_time time not null comment '提醒时间',
|
||||
task_type enum ('single', 'recurring') default 'single' null comment '任务类型:单次或周期性',
|
||||
status enum ('pending', 'completed') default 'pending' null comment '任务状态:待办或已完成',
|
||||
created_at timestamp default current_timestamp() null comment '创建时间'
|
||||
)
|
||||
comment '机器人定时任务表';
|
||||
|
||||
Reference in New Issue
Block a user