- dynamic_table: 新增 build_filtered_count_sql(带过滤/搜索的 COUNT)和 build_aggregate_sql(按字段分组计数)
- data_service: 新增 count 和 aggregate 方法,支持实时统计查询
- data_handler: 新增 count_plugin_data 和 aggregate_plugin_data REST handler
- data_dto: 新增 AggregateItem、AggregateQueryParams、CountQueryParams 类型
- module: 注册 /plugins/{plugin_id}/{entity}/count 和 /aggregate 路由
- 包含 8 个新增单元测试,全部通过
66 lines
1.7 KiB
Rust
66 lines
1.7 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// 插件数据记录响应
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
|
|
pub struct PluginDataResp {
|
|
pub id: String,
|
|
pub data: serde_json::Value,
|
|
pub created_at: Option<DateTime<Utc>>,
|
|
pub updated_at: Option<DateTime<Utc>>,
|
|
pub version: Option<i32>,
|
|
}
|
|
|
|
/// 创建插件数据请求
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
|
|
pub struct CreatePluginDataReq {
|
|
pub data: serde_json::Value,
|
|
}
|
|
|
|
/// 更新插件数据请求
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
|
|
pub struct UpdatePluginDataReq {
|
|
pub data: serde_json::Value,
|
|
pub version: i32,
|
|
}
|
|
|
|
/// 插件数据列表查询参数
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::IntoParams)]
|
|
pub struct PluginDataListParams {
|
|
pub page: Option<u64>,
|
|
pub page_size: Option<u64>,
|
|
pub search: Option<String>,
|
|
/// JSON 格式过滤: {"field":"value"}
|
|
pub filter: Option<String>,
|
|
pub sort_by: Option<String>,
|
|
/// "asc" or "desc"
|
|
pub sort_order: Option<String>,
|
|
}
|
|
|
|
/// 聚合查询响应项
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
|
|
pub struct AggregateItem {
|
|
/// 分组键(字段值)
|
|
pub key: String,
|
|
/// 计数
|
|
pub count: i64,
|
|
}
|
|
|
|
/// 聚合查询参数
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::IntoParams)]
|
|
pub struct AggregateQueryParams {
|
|
/// 分组字段名
|
|
pub group_by: String,
|
|
/// JSON 格式过滤: {"field":"value"}
|
|
pub filter: Option<String>,
|
|
}
|
|
|
|
/// 统计查询参数
|
|
#[derive(Debug, Serialize, Deserialize, utoipa::IntoParams)]
|
|
pub struct CountQueryParams {
|
|
/// 搜索关键词
|
|
pub search: Option<String>,
|
|
/// JSON 格式过滤: {"field":"value"}
|
|
pub filter: Option<String>,
|
|
}
|