From 8b4721601fdd70f304ed0ff6dfa663bfa11a6c4d Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 26 Oct 2026 20:26:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(b1b-c3):=20=E8=81=9A=E5=90=88=E4=BD=93?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=94=B1=20spec=20=E5=A3=B0=E6=98=8E=20?= =?UTF-8?q?=E2=80=94=E2=80=94=20=E6=8E=A7=E5=88=B6=E5=99=A8=E9=9B=B6?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E5=AE=9E=E4=BD=93=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - TableSpec 增字段 aggregate_detail: bool - Resource / Dataset 置 true,其余 16 个置 false - controller/crud.rs 删掉 find("Resource")/find("Dataset") + expect,改为遍历 ALL_SPECS 按 flag 注册 - 补单测 aggregate_detail_is_pinned_to_the_resource_side(聚合体 ⊆ 有子表) - 边界账本删掉已失效的两条 CP3(controller/crud.rs find(...)) --- scripts/boundary-ledger.txt | 2 -- src/tdc/controller/crud.rs | 52 +++++++++++------------------- src/tdc/entity/api_consume_log.rs | 1 + src/tdc/entity/audit_log.rs | 1 + src/tdc/entity/contract.rs | 1 + src/tdc/entity/credential.rs | 1 + src/tdc/entity/data_interface.rs | 1 + src/tdc/entity/dataset.rs | 1 + src/tdc/entity/datasource.rs | 1 + src/tdc/entity/delivery_log.rs | 1 + src/tdc/entity/delivery_task.rs | 1 + src/tdc/entity/destroy_log.rs | 1 + src/tdc/entity/identity.rs | 1 + src/tdc/entity/mod.rs | 25 ++++++++++++++ src/tdc/entity/notification.rs | 1 + src/tdc/entity/order.rs | 1 + src/tdc/entity/policy.rs | 1 + src/tdc/entity/policy_check_log.rs | 1 + src/tdc/entity/policy_template.rs | 1 + src/tdc/entity/product.rs | 1 + src/tdc/entity/resource.rs | 1 + 21 files changed, 62 insertions(+), 35 deletions(-) diff --git a/scripts/boundary-ledger.txt b/scripts/boundary-ledger.txt index d461a69..4eff6ed 100644 --- a/scripts/boundary-ledger.txt +++ b/scripts/boundary-ledger.txt @@ -16,6 +16,4 @@ CP1 auth.rs /api/ssw/tdc/ C5:白名单清单待归业务层 src/tdc/support/pu CP1 db.rs tdc_identity C4:schema 探针待通用化(改查 pg_catalog.pg_tables) B1b CP2 session.rs Identity 假阳性:SessionKind::Identity 是**会话口径**,不是业务实体 tdc_identity 永久 CP2 auth.rs SessionKind::Identity 假阳性:Principal::Session 分支里的会话种类,不是业务实体 永久 -CP3 controller/crud.rs find("Resource") C3:聚合详情注册待改成遍历 spec B1b -CP3 controller/crud.rs find("Dataset") C3:聚合详情注册待改成遍历 spec B1b CP4 auth.rs /api/ C5:白名单清单待归业务层(含 /api/oauth/Login 与 /api/health 两条) B1b diff --git a/src/tdc/controller/crud.rs b/src/tdc/controller/crud.rs index 85c05bf..69dfc03 100644 --- a/src/tdc/controller/crud.rs +++ b/src/tdc/controller/crud.rs @@ -94,43 +94,29 @@ pub fn router() -> Router { } // ------------------------------------------------------------------ - // 资源侧只读聚合体(上游 `ResourceController#detailOf` / `DatasetController#detailOf`) + // 只读聚合体(上游 `ResourceController#detailOf` / `DatasetController#detailOf`) // // 🔴 路径里的 `{id}` 与上面的 `/{Entity}/{id}` **同层并存** —— // matchit 允许「参数段 + 更深的静态段」,静态段优先匹配,无冲突。 + // 🔴 **零硬编码实体名**:注册哪些聚合体由 `TableSpec::aggregate_detail` 决定 + // (v3 spec §2.3.1 C3)⇒ 控制器只**遍历 spec**。 // 🔴 `Dataset` 在注册表里 `table = "tdc_resource"`(只读视图)⇒ 聚合体与 Resource 同源。 - { - let res_spec: &'static TableSpec = - entity::find("Resource").expect("Resource 必须在注册表里"); - let ds_spec: &'static TableSpec = - entity::find("Dataset").expect("Dataset 必须在注册表里"); - r = r - .route( - &format!("{}/{{id}}/Detail", res_spec.path), - get( - move |Path(id): Path, - State(st): State, - p: Option>| { - let principal = p.map(|e| e.0); - async move { - crud::detail_aggregate(&st, res_spec, &id, principal.as_ref()).await - } - }, - ), - ) - .route( - &format!("{}/{{id}}/Detail", ds_spec.path), - get( - move |Path(id): Path, - State(st): State, - p: Option>| { - let principal = p.map(|e| e.0); - async move { - crud::detail_aggregate(&st, ds_spec, &id, principal.as_ref()).await - } - }, - ), - ); + for spec in entity::ALL_SPECS { + if !spec.aggregate_detail { + continue; + } + let s: &'static TableSpec = spec; + r = r.route( + &format!("{}/{{id}}/Detail", s.path), + get( + move |Path(id): Path, + State(st): State, + p: Option>| { + let principal = p.map(|e| e.0); + async move { crud::detail_aggregate(&st, s, &id, principal.as_ref()).await } + }, + ), + ); } r } diff --git a/src/tdc/entity/api_consume_log.rs b/src/tdc/entity/api_consume_log.rs index 100f7cd..ad743d0 100644 --- a/src/tdc/entity/api_consume_log.rs +++ b/src/tdc/entity/api_consume_log.rs @@ -33,4 +33,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/audit_log.rs b/src/tdc/entity/audit_log.rs index d76abb3..0e07586 100644 --- a/src/tdc/entity/audit_log.rs +++ b/src/tdc/entity/audit_log.rs @@ -29,4 +29,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/contract.rs b/src/tdc/entity/contract.rs index 932a011..8ae443d 100644 --- a/src/tdc/entity/contract.rs +++ b/src/tdc/entity/contract.rs @@ -34,4 +34,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/credential.rs b/src/tdc/entity/credential.rs index bb070c7..2b3db87 100644 --- a/src/tdc/entity/credential.rs +++ b/src/tdc/entity/credential.rs @@ -30,4 +30,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &["secretKey"], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/data_interface.rs b/src/tdc/entity/data_interface.rs index bc816ec..21d5207 100644 --- a/src/tdc/entity/data_interface.rs +++ b/src/tdc/entity/data_interface.rs @@ -23,4 +23,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/dataset.rs b/src/tdc/entity/dataset.rs index ff55133..67f04a7 100644 --- a/src/tdc/entity/dataset.rs +++ b/src/tdc/entity/dataset.rs @@ -26,4 +26,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[("fieldRules", "tdc_resource_field"), ("maskRules", "tdc_resource_mask_rule")], not_found_msg: "数据集不存在或资源已删除", + aggregate_detail: true, }; diff --git a/src/tdc/entity/datasource.rs b/src/tdc/entity/datasource.rs index 18d1fec..c4defe2 100644 --- a/src/tdc/entity/datasource.rs +++ b/src/tdc/entity/datasource.rs @@ -28,4 +28,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/delivery_log.rs b/src/tdc/entity/delivery_log.rs index 42995e3..c0a5f40 100644 --- a/src/tdc/entity/delivery_log.rs +++ b/src/tdc/entity/delivery_log.rs @@ -25,4 +25,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/delivery_task.rs b/src/tdc/entity/delivery_task.rs index d38f316..5257014 100644 --- a/src/tdc/entity/delivery_task.rs +++ b/src/tdc/entity/delivery_task.rs @@ -47,4 +47,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &["devUrl", "devToken"], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/destroy_log.rs b/src/tdc/entity/destroy_log.rs index 19f4c42..f868e87 100644 --- a/src/tdc/entity/destroy_log.rs +++ b/src/tdc/entity/destroy_log.rs @@ -25,4 +25,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/identity.rs b/src/tdc/entity/identity.rs index be1af0e..68b58b1 100644 --- a/src/tdc/entity/identity.rs +++ b/src/tdc/entity/identity.rs @@ -37,4 +37,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &["secretKey"], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/mod.rs b/src/tdc/entity/mod.rs index 53622e2..056375b 100644 --- a/src/tdc/entity/mod.rs +++ b/src/tdc/entity/mod.rs @@ -105,6 +105,12 @@ pub struct TableSpec { /// 🔴 引擎**零 `match api_name`** ⇒ 文案由**业务 spec 声明** /// (v3 spec §2.3.1 C2;与技能 `EntitySpec.creator_fixed` 同一手法)。 pub not_found_msg: &'static str, + /// 是否注册**只读聚合体**路由 `GET {path}/{id}/Detail`(上游 `ResourceController#detailOf` / + /// `DatasetController#detailOf`)。 + /// + /// 🔴 引擎**零硬编码实体名** ⇒ 控制器**遍历 spec** 决定注册哪条 + /// (v3 spec §2.3.1 C3)。聚合体里挂哪些子表由 [`TableSpec::child_tables`] 决定。 + pub aggregate_detail: bool, } /// `DeliveryTask` 的 41 个服务端权威列。 @@ -544,6 +550,25 @@ mod tests { assert_eq!(find("Product").unwrap().tenant_column, Some("f_tenant_id")); } + /// 🔴 **聚合体路由的注册口径**(C3):只有资源侧两个实体有 `/Detail`, + /// 且**开了聚合体就必须有子表**(否则聚合体与普通详情无异 ⇒ 白开一条路由)。 + #[test] + fn aggregate_detail_is_pinned_to_the_resource_side() { + let agg: Vec<&str> = ALL_SPECS + .iter() + .filter(|s| s.aggregate_detail) + .map(|s| s.api_name) + .collect(); + assert_eq!(agg, vec!["Dataset", "Resource"]); + for s in ALL_SPECS.iter().filter(|s| s.aggregate_detail) { + assert!( + !s.child_tables.is_empty(), + "{} 开了聚合体却没有子表", + s.api_name + ); + } + } + /// 🔴 **不外泄字段清单**(上游 `@JsonIgnore`)**字面钉住**。 /// /// 上游全仓只有 **3 个属性**标了 `@JsonIgnore`(2026-10-25 核对 `ssw-tdc-entity`): diff --git a/src/tdc/entity/notification.rs b/src/tdc/entity/notification.rs index 30c9864..91afb6b 100644 --- a/src/tdc/entity/notification.rs +++ b/src/tdc/entity/notification.rs @@ -28,4 +28,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/order.rs b/src/tdc/entity/order.rs index 80932b0..ab4042e 100644 --- a/src/tdc/entity/order.rs +++ b/src/tdc/entity/order.rs @@ -32,4 +32,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/policy.rs b/src/tdc/entity/policy.rs index f79b68b..9f4be2b 100644 --- a/src/tdc/entity/policy.rs +++ b/src/tdc/entity/policy.rs @@ -25,4 +25,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/policy_check_log.rs b/src/tdc/entity/policy_check_log.rs index fcaf675..fe96e11 100644 --- a/src/tdc/entity/policy_check_log.rs +++ b/src/tdc/entity/policy_check_log.rs @@ -26,4 +26,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/policy_template.rs b/src/tdc/entity/policy_template.rs index 7a821f4..316ee44 100644 --- a/src/tdc/entity/policy_template.rs +++ b/src/tdc/entity/policy_template.rs @@ -21,4 +21,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/product.rs b/src/tdc/entity/product.rs index c58b121..ae2bc0d 100644 --- a/src/tdc/entity/product.rs +++ b/src/tdc/entity/product.rs @@ -32,4 +32,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[], not_found_msg: "记录不存在或已删除", + aggregate_detail: false, }; diff --git a/src/tdc/entity/resource.rs b/src/tdc/entity/resource.rs index 234ccc5..45864f5 100644 --- a/src/tdc/entity/resource.rs +++ b/src/tdc/entity/resource.rs @@ -31,4 +31,5 @@ pub const SPEC: TableSpec = TableSpec { hidden_fields: &[], child_tables: &[("fieldRules", "tdc_resource_field"), ("maskRules", "tdc_resource_mask_rule")], not_found_msg: "记录不存在或已删除", + aggregate_detail: true, };