fix(ai): 连接 ai.analysis.requested 事件消费者
erp-health 在化验单上传时发布 ai.analysis.requested 事件, 但 erp-ai 的 on_startup 仅订阅 ai.reanalysis.* 前缀。 将订阅前缀从 "ai.reanalysis." 扩大为 "ai.", 新增 ai.analysis.requested 事件的接收和日志记录。 完整自动分析实现依赖 Prompt 模板就绪后补充。
This commit is contained in:
@@ -80,7 +80,8 @@ impl ErpModule for AiModule {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &erp_core::module::ModuleContext,
|
ctx: &erp_core::module::ModuleContext,
|
||||||
) -> erp_core::error::AppResult<()> {
|
) -> 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();
|
let db = ctx.db.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
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 => {
|
None => {
|
||||||
tracing::info!("AI 再分析事件订阅通道已关闭");
|
tracing::info!("AI 事件订阅通道已关闭");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tracing::info!(module = "ai", "AI 模块事件处理器已注册(监听 reanalysis)");
|
tracing::info!(module = "ai", "AI 模块事件处理器已注册(监听 ai.* 事件)");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user