完善 value_rank 社交图设计并落地 @ 结构化存储

- messages 表新增 mentioned_user_ids 字段设计,使用 JSON 数组字符串存储被@用户清单

- 新增社交图相关表设计:t_message_mentions、t_social_edges_daily、t_value_rank_social_daily

- 增加迁移脚本 20260421_add_mentions_and_social_graph_tables.sql,支持现网平滑升级

- 改造 MessageStorageDB 入库流程:解析 msg_source.atuserlist 并写入 mentioned_user_ids

- 更新 value_rank README:补充社交图数据链路、可产出图表及实现说明
This commit is contained in:
liuwei
2026-04-21 13:34:19 +08:00
parent dfa17c5f95
commit 2730595a88
4 changed files with 214 additions and 9 deletions

View File

@@ -40,6 +40,7 @@ create or replace table message_archive.messages
message_id varchar(32) null comment '消息 id',
message_xml text null comment '消息 xml 部分',
raw_payload longtext null comment 'API 原始消息完整负载(完整序列化数据)',
mentioned_user_ids longtext null comment '消息中被@用户ID清单JSON数组字符串',
message_thumb longtext null comment '视频或图片消息的缩略图路径',
image_path varchar(255) null comment '图片URL路径'
)
@@ -60,6 +61,49 @@ create or replace index idx_message_type
create or replace index messages_message_id_index
on message_archive.messages (message_id);
create or replace table message_archive.t_message_mentions
(
id bigint auto_increment
primary key,
message_id varchar(32) not null comment '原始消息ID',
group_id varchar(100) not null comment '群ID',
sender_id varchar(100) not null comment '发送者ID@发起人)',
mentioned_user_id varchar(100) not null comment '被@用户ID',
stat_date date not null comment '统计日期',
msg_time datetime not null comment '消息时间',
create_time datetime default current_timestamp() null comment '创建时间',
constraint uk_message_sender_mentioned
unique (message_id, sender_id, mentioned_user_id)
)
comment '消息@关系明细表';
create or replace index idx_group_date
on message_archive.t_message_mentions (group_id, stat_date);
create or replace index idx_mentioned_group_date
on message_archive.t_message_mentions (mentioned_user_id, group_id, stat_date);
create or replace table message_archive.t_social_edges_daily
(
id bigint auto_increment
primary key,
stat_date date not null comment '统计日期',
group_id varchar(100) not null comment '群ID',
from_user_id varchar(100) not null comment '互动发起方',
to_user_id varchar(100) not null comment '互动接收方',
mention_count int default 0 not null comment '@次数',
reply_count int default 0 not null comment '回复次数(预留)',
interaction_score decimal(10, 2) default 0.00 not null comment '互动强度分(可用于关系网权重)',
create_time datetime default current_timestamp() null comment '创建时间',
update_time datetime default current_timestamp() null on update current_timestamp() comment '更新时间',
constraint uk_day_group_edge
unique (stat_date, group_id, from_user_id, to_user_id)
)
comment '社交关系日边表(用于关系网和搭子榜)';
create or replace index idx_group_day_score
on message_archive.t_social_edges_daily (group_id, stat_date, interaction_score);
create or replace table message_archive.speech_counts
(
id int auto_increment comment '自增主键ID'