fix(ai): 连接 ai.analysis.requested 事件消费者
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

erp-health 在化验单上传时发布 ai.analysis.requested 事件,
但 erp-ai 的 on_startup 仅订阅 ai.reanalysis.* 前缀。

将订阅前缀从 "ai.reanalysis." 扩大为 "ai.",
新增 ai.analysis.requested 事件的接收和日志记录。
完整自动分析实现依赖 Prompt 模板就绪后补充。
This commit is contained in:
iven
2026-05-04 13:12:47 +08:00
parent 77cf866adf
commit e78eb1af07

View File

@@ -80,7 +80,8 @@ impl ErpModule for AiModule {
&self,
ctx: &erp_core::module::ModuleContext,
) -> erp_core::error::AppResult<()> {
let (mut rx, _handle) = ctx.event_bus.subscribe_filtered("ai.reanalysis.".to_string());
// 订阅 ai.* 前缀的所有事件reanalysis + analysis.requested
let (mut rx, _handle) = ctx.event_bus.subscribe_filtered("ai.".to_string());
let db = ctx.db.clone();
tokio::spawn(async move {
@@ -111,16 +112,38 @@ impl ErpModule for AiModule {
}
}
}
Some(_) => {}
Some(event) if event.event_type == "ai.analysis.requested" => {
let source_type = event.payload.get("source_type").and_then(|v| v.as_str());
let source_id = event.payload.get("source_id")
.and_then(|v| v.as_str())
.and_then(|s| uuid::Uuid::parse_str(s).ok());
let patient_id = event.payload.get("patient_id")
.and_then(|v| v.as_str())
.and_then(|s| uuid::Uuid::parse_str(s).ok());
tracing::info!(
source_type = ?source_type,
source_id = ?source_id,
patient_id = ?patient_id,
tenant_id = %event.tenant_id,
"收到 AI 分析请求事件(化验单上传触发,待 Prompt 模板就绪后实现自动分析)"
);
}
Some(event) => {
tracing::debug!(
event_type = %event.event_type,
"忽略非目标 AI 事件"
);
}
None => {
tracing::info!("AI 再分析事件订阅通道已关闭");
tracing::info!("AI 事件订阅通道已关闭");
break;
}
}
}
});
tracing::info!(module = "ai", "AI 模块事件处理器已注册(监听 reanalysis");
tracing::info!(module = "ai", "AI 模块事件处理器已注册(监听 ai.* 事件");
Ok(())
}
}