feat(data-ana): 完整实现 data-ana 数据分析服务

包含 CDC consumer、analytics/mastery/warning service、grpc server、repository、ClickHouse DDL 等
This commit is contained in:
SpecialX
2026-07-10 19:09:27 +08:00
parent 033057a302
commit ca3780aa24
29 changed files with 5401 additions and 383 deletions

View File

@@ -4,13 +4,17 @@ package next_edu_cloud.events.v1;
// Cross-service event contracts published by CoreEdu via the transactional
// outbox pattern and consumed by downstream services (notifications, analytics,
// audit, etc.). Topics follow the convention edu.{domain}.events.
// audit, etc.).
//
// Event routing (TOPIC_MAP in outbox.publisher.ts):
// edu.exam.events <- exam.created / exam.updated / exam.deleted
// edu.homework.events <- homework.assigned / homework.submitted / homework.graded
// edu.grade.events <- grade.recorded / grade.updated
// edu.class.events <- class.transferred
// edu.teaching.exam.published <- exam.published
// edu.teaching.homework.assigned <- homework.assigned / homework.submitted / homework.graded
// edu.teaching.grade.recorded <- grade.recorded / grade.updated
// edu.teaching.class.transferred <- class.transferred
//
// Derived data events (Outbox exempt, see 004 §12.2):
// edu.insight.mastery.updated <- mastery.updated / warning.triggered (action field distinguishes)
// edu.insight.ai.usage <- ai.usage.recorded
message ClassEvent {
string event_id = 1;
@@ -58,3 +62,40 @@ message GradeEvent {
string action = 8;
map<string, string> metadata = 9;
}
// MasteryEvent 掌握度/预警派生数据事件Outbox 豁免,直接 Kafka producer 发布).
// action 字段区分mastery.updated掌握度更新/ warning.triggered预警触发.
// 两者复用同一 topic edu.insight.mastery.updated总裁裁决 §2.11.
message MasteryEvent {
string event_id = 1;
string action = 2; // mastery.updated / warning.triggered
int64 occurred_at = 3;
string student_id = 4;
string knowledge_point_id = 5;
double mastery_level = 6; // 0.0-1.0mastery.updated 时有效)
double previous_level = 7; // 上一次掌握度mastery.updated 时有效)
// warning.triggered 时以下字段有效
string warning_type = 8; // LOW_MASTERY / CRITICAL_LOW / SCORE_DROP / ABSENT_FREQUENT / TREND_DECLINE
string target_id = 9; // 预警目标(学生 ID
double threshold = 10; // 预警阈值
double current_value = 11; // 当前值
string severity = 12; // INFO / WARN / CRITICAL
map<string, string> metadata = 13;
}
// AIUsageEvent AI 用量计费事件ai 服务发布data-ana 消费落 ai_usage_log.
message AIUsageEvent {
string event_id = 1;
string request_id = 2;
string user_id = 3;
string provider = 4; // openai / anthropic / baichuan / local
string model = 5;
uint32 prompt_tokens = 6;
uint32 completion_tokens = 7;
uint32 total_tokens = 8;
uint32 latency_ms = 9;
bool success = 10;
uint32 cost_cents = 11; // 计费(分)
int64 occurred_at = 12;
map<string, string> metadata = 13;
}