From 16b7a36bfbfd5056d074561ebddf84ad3e389e01 Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 17 Apr 2026 10:25:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugin):=20list=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=9B=86=E6=88=90=20Generated=20Column=20=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - list 方法新增 cache 参数,使用 resolve_entity_info_cached 替代直接查库 - 查询改用 build_filtered_query_sql_ex,自动路由到 Generated Column - handler 传递 entity_cache 到 list 方法 --- crates/erp-plugin/src/data_service.rs | 11 +++++++---- crates/erp-plugin/src/handler/data_handler.rs | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/erp-plugin/src/data_service.rs b/crates/erp-plugin/src/data_service.rs index d87668f..fd75f27 100644 --- a/crates/erp-plugin/src/data_service.rs +++ b/crates/erp-plugin/src/data_service.rs @@ -59,7 +59,7 @@ impl PluginDataService { }) } - /// 列表查询(支持过滤/搜索/排序) + /// 列表查询(支持过滤/搜索/排序/Generated Column 路由) pub async fn list( plugin_id: Uuid, entity_name: &str, @@ -71,8 +71,10 @@ impl PluginDataService { search: Option, sort_by: Option, sort_order: Option, + cache: &moka::sync::Cache, ) -> AppResult<(Vec, u64)> { - let info = resolve_entity_info(plugin_id, entity_name, tenant_id, db).await?; + let info = + resolve_entity_info_cached(plugin_id, entity_name, tenant_id, db, cache).await?; // 获取 searchable 字段列表 let entity_fields = info.fields()?; @@ -105,9 +107,9 @@ impl PluginDataService { .map(|r| r.count as u64) .unwrap_or(0); - // Query + // Query — 使用 Generated Column 路由 let offset = page.saturating_sub(1) * page_size; - let (sql, values) = DynamicTableManager::build_filtered_query_sql( + let (sql, values) = DynamicTableManager::build_filtered_query_sql_ex( &info.table_name, tenant_id, page_size, @@ -116,6 +118,7 @@ impl PluginDataService { search_tuple, sort_by, sort_order, + &info.generated_fields, ) .map_err(|e| AppError::Validation(e))?; diff --git a/crates/erp-plugin/src/handler/data_handler.rs b/crates/erp-plugin/src/handler/data_handler.rs index a545733..e224dc7 100644 --- a/crates/erp-plugin/src/handler/data_handler.rs +++ b/crates/erp-plugin/src/handler/data_handler.rs @@ -71,6 +71,7 @@ where params.search, params.sort_by, params.sort_order, + &state.entity_cache, ) .await?;