feat(ai): 每日风险快照批量刷新定时任务
- risk_service 新增 refresh_all_patients 方法 - module on_startup 启动每日刷新后台任务
This commit is contained in:
@@ -312,6 +312,25 @@ impl ErpModule for AiModule {
|
||||
let copilot_handles = crate::event::copilot_consumer::spawn(&ctx.db, &ctx.event_bus);
|
||||
std::mem::forget(copilot_handles);
|
||||
|
||||
// 每日凌晨 2:00 批量刷新所有在管患者风险快照
|
||||
let refresh_db = ctx.db.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(86400));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
match crate::service::risk_service::RiskService::refresh_all_patients(&refresh_db)
|
||||
.await
|
||||
{
|
||||
Ok(count) => {
|
||||
tracing::info!(patient_count = count, "每日风险快照刷新完成");
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "每日风险快照刷新失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tracing::info!(
|
||||
module = "ai",
|
||||
"AI 模块事件处理器已注册(监听 ai.* 事件 + Copilot 事件)"
|
||||
|
||||
Reference in New Issue
Block a user