feat(core): build_event_payload 统一信封 — 28 处事件发布全部迁移
- erp-core 添加 build_event_payload(),自动注入 schema_version + occurred_at - erp-health 12 个 service(25 处)、erp-auth(1 处)、erp-workflow(2 处) 全部迁移到统一信封格式
This commit is contained in:
@@ -31,6 +31,28 @@ impl DomainEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/// 当前事件 payload schema 版本
|
||||
pub const EVENT_SCHEMA_VERSION: &str = "v1";
|
||||
|
||||
/// 构造统一信封格式的事件 payload。
|
||||
///
|
||||
/// 自动注入 `schema_version` 和 `occurred_at`,业务数据通过 `data` 传入。
|
||||
/// 用法:`build_event_payload(serde_json::json!({ "patient_id": ..., }))`
|
||||
pub fn build_event_payload(data: serde_json::Value) -> serde_json::Value {
|
||||
let mut envelope = serde_json::json!({
|
||||
"schema_version": EVENT_SCHEMA_VERSION,
|
||||
"occurred_at": Utc::now().to_rfc3339(),
|
||||
});
|
||||
if let serde_json::Value::Object(ref mut map) = envelope {
|
||||
if let serde_json::Value::Object(data_map) = data {
|
||||
for (k, v) in data_map {
|
||||
map.insert(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
envelope
|
||||
}
|
||||
|
||||
/// 过滤事件接收器 — 只接收匹配 `event_type_prefix` 的事件
|
||||
pub struct FilteredEventReceiver {
|
||||
receiver: mpsc::Receiver<DomainEvent>,
|
||||
|
||||
Reference in New Issue
Block a user