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(()) } }