From e78eb1af07e0ad195ddd8963e12f2c0611511f68 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 4 May 2026 13:12:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai):=20=E8=BF=9E=E6=8E=A5=20ai.analysis.req?= =?UTF-8?q?uested=20=E4=BA=8B=E4=BB=B6=E6=B6=88=E8=B4=B9=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit erp-health 在化验单上传时发布 ai.analysis.requested 事件, 但 erp-ai 的 on_startup 仅订阅 ai.reanalysis.* 前缀。 将订阅前缀从 "ai.reanalysis." 扩大为 "ai.", 新增 ai.analysis.requested 事件的接收和日志记录。 完整自动分析实现依赖 Prompt 模板就绪后补充。 --- crates/erp-ai/src/module.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/crates/erp-ai/src/module.rs b/crates/erp-ai/src/module.rs index b25ae00..c9bbb02 100644 --- a/crates/erp-ai/src/module.rs +++ b/crates/erp-ai/src/module.rs @@ -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(()) } }