feat(health): 业务链路打通 — 告警自动随访 + 健康数据积分激励

- 迁移 000157: follow_up_task 新增 source_type/source_id 字段追踪任务来源
- 迁移 000157: points_rule 新增 health_data_report/lab_report_upload/streak_7_days 种子规则
- P0-2: follow_up 事件处理器新增 health_data.critical_alert 消费,告警触发时自动创建随访任务
  - 自动查找管床医生分配,critical 级别 1 天内、warning 级别 3 天内
  - 新增 alert_auto 随访类型,source_type 标记来源为 critical_alert
- P1-1: points 事件处理器新增 daily_monitoring.created 消费,日常监测上报自动获取积分
- P1-1: points 事件处理器新增 lab_report.uploaded 消费,化验报告上传自动获取积分
- 更新 HMS 系统设计思路文档 v2.0(实体数/链路图/业务链路章节全面更新)
- 新增业务链路打通讨论记录

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
iven
2026-05-20 12:25:28 +08:00
parent e83101dd23
commit 17114d492e
12 changed files with 744 additions and 58 deletions

View File

@@ -158,6 +158,7 @@ mod m20260518_000153_ai_health_butler_v2;
mod m20260519_000154_seed_ai_knowledge_permissions;
mod m20260519_000155_fix_ai_menus_and_add_chat;
mod m20260519_000156_fix_ai_menus_round2;
mod m20260520_000157_follow_up_source_and_points_rules;
pub struct Migrator;
@@ -323,6 +324,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260519_000154_seed_ai_knowledge_permissions::Migration),
Box::new(m20260519_000155_fix_ai_menus_and_add_chat::Migration),
Box::new(m20260519_000156_fix_ai_menus_round2::Migration),
Box::new(m20260520_000157_follow_up_source_and_points_rules::Migration),
]
}
}

View File

@@ -0,0 +1,104 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// 1. follow_up_task 新增 source_type 和 source_id 字段,追踪任务来源
manager
.alter_table(
Table::alter()
.table(Alias::new("follow_up_task"))
.add_column(ColumnDef::new(Alias::new("source_type")).string().null())
.add_column(ColumnDef::new(Alias::new("source_id")).uuid().null())
.to_owned(),
)
.await?;
// 2. 新增积分规则种子:健康数据上报
let insert_sql = r#"
INSERT INTO points_rule (id, tenant_id, name, event_type, points, daily_cap, is_active, created_at, updated_at, version)
SELECT
gen_random_uuid(),
t.id,
'健康数据上报',
'health_data_report',
5,
10,
true,
NOW(),
NOW(),
1
FROM tenant t
WHERE NOT EXISTS (
SELECT 1 FROM points_rule pr
WHERE pr.event_type = 'health_data_report' AND pr.tenant_id = t.id
);
INSERT INTO points_rule (id, tenant_id, name, event_type, points, daily_cap, is_active, created_at, updated_at, version)
SELECT
gen_random_uuid(),
t.id,
'化验报告上传',
'lab_report_upload',
20,
40,
true,
NOW(),
NOW(),
1
FROM tenant t
WHERE NOT EXISTS (
SELECT 1 FROM points_rule pr
WHERE pr.event_type = 'lab_report_upload' AND pr.tenant_id = t.id
);
INSERT INTO points_rule (id, tenant_id, name, event_type, points, daily_cap, is_active, created_at, updated_at, version)
SELECT
gen_random_uuid(),
t.id,
'连续上报奖励(7天)',
'streak_7_days',
50,
50,
true,
NOW(),
NOW(),
1
FROM tenant t
WHERE NOT EXISTS (
SELECT 1 FROM points_rule pr
WHERE pr.event_type = 'streak_7_days' AND pr.tenant_id = t.id
);
"#;
manager
.get_connection()
.execute_unprepared(insert_sql)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Alias::new("follow_up_task"))
.drop_column(Alias::new("source_type"))
.drop_column(Alias::new("source_id"))
.to_owned(),
)
.await?;
manager
.get_connection()
.execute_unprepared(
"DELETE FROM points_rule WHERE event_type IN ('health_data_report', 'lab_report_upload', 'streak_7_days');",
)
.await?;
Ok(())
}
}