fix(health): 设备数据管线 Phase 1 缺陷修复 + AI 产品策略讨论
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- device_readings 批量插入添加 ON CONFLICT 去重唯一索引
- 小程序 BLEManager 增加离线缓存(Storage 持久化 + 启动重传)
- 新增 device_readings 90 天数据保留清理定时任务
- 小米手环适配器增加 RACP 历史心率读取支持
- SSE 告警按医生过滤已确认实现(patient_doctor_relation)
- 新增 AI 产品策略与设备数据医院场景讨论记录
This commit is contained in:
iven
2026-04-29 06:17:23 +08:00
parent a491eb19a6
commit f6ccb8a35c
8 changed files with 389 additions and 9 deletions

View File

@@ -93,6 +93,7 @@ mod m20260428_000090_critical_alerts;
mod m20260428_000091_dead_letter_events;
mod m20260429_000092_device_readings_metric;
mod m20260429_000093_trend_analysis_prompt_v2;
mod m20260429_000094_device_readings_unique_constraint;
pub struct Migrator;
@@ -193,6 +194,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260428_000091_dead_letter_events::Migration),
Box::new(m20260429_000092_device_readings_metric::Migration),
Box::new(m20260429_000093_trend_analysis_prompt_v2::Migration),
Box::new(m20260429_000094_device_readings_unique_constraint::Migration),
]
}
}

View File

@@ -0,0 +1,34 @@
//! device_readings 添加去重唯一约束
//!
// 分区表的唯一约束必须包含分区键 (measured_at)
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> {
let db = manager.get_connection();
// 分区表唯一索引必须包含分区键 measured_at
// 同一患者、同一设备、同一指标、同一测量时间只允许一条记录
db.execute_unprepared(
"CREATE UNIQUE INDEX IF NOT EXISTS uq_device_readings_dedup
ON device_readings (tenant_id, patient_id, device_id, metric, measured_at);"
).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
db.execute_unprepared(
"DROP INDEX IF EXISTS uq_device_readings_dedup;"
).await?;
Ok(())
}
}