完善 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

@@ -0,0 +1,50 @@
-- 消息表增加被@清单字段JSON 数组字符串)
ALTER TABLE message_archive.messages
ADD COLUMN IF NOT EXISTS mentioned_user_ids LONGTEXT NULL COMMENT '消息中被@用户ID清单JSON数组字符串' AFTER raw_payload;
-- 消息@关系明细表
CREATE TABLE IF NOT EXISTS message_archive.t_message_mentions (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
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 COMMENT '创建时间',
UNIQUE KEY uk_message_sender_mentioned (message_id, sender_id, mentioned_user_id),
KEY idx_group_date (group_id, stat_date),
KEY idx_mentioned_group_date (mentioned_user_id, group_id, stat_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息@关系明细表';
-- 社交关系日边表(用于关系网和搭子榜)
CREATE TABLE IF NOT EXISTS message_archive.t_social_edges_daily (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
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 NOT NULL DEFAULT 0 COMMENT '@次数',
reply_count INT NOT NULL DEFAULT 0 COMMENT '回复次数(预留)',
interaction_score DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '互动强度分(可用于关系网权重)',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
UNIQUE KEY uk_day_group_edge (stat_date, group_id, from_user_id, to_user_id),
KEY idx_group_day_score (group_id, stat_date, interaction_score)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='社交关系日边表(用于关系网和搭子榜)';
-- Value Rank 社交日汇总表(个人维度)
CREATE TABLE IF NOT EXISTS message_archive.t_value_rank_social_daily (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
stat_date DATE NOT NULL COMMENT '统计日期',
group_id VARCHAR(100) NOT NULL COMMENT '群ID',
user_id VARCHAR(100) NOT NULL COMMENT '用户ID',
mentioned_count INT NOT NULL DEFAULT 0 COMMENT '被@次数(入度)',
mention_others_count INT NOT NULL DEFAULT 0 COMMENT '@他人次数(出度)',
unique_interactors INT NOT NULL DEFAULT 0 COMMENT '与其发生互动的去重人数',
interaction_score DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '社交影响力分',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
UNIQUE KEY uk_day_group_user (stat_date, group_id, user_id),
KEY idx_group_day_score (group_id, stat_date, interaction_score)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Value Rank 社交日汇总表';