@lovrabet/sdk 1.2.5-beta.1 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig, SortList, SelectOption, SelectOptionsParams, FilterParams } from '../types';
|
|
1
|
+
import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig, SortList, SelectOption, SelectOptionsParams, FilterParams, AggregateParams } from '../types';
|
|
2
2
|
import type { HttpClient } from '../http/http-client';
|
|
3
3
|
/**
|
|
4
4
|
* 抽象基础模型类
|
|
@@ -31,6 +31,7 @@ export declare abstract class AbstractBaseModel implements BaseModelMethods {
|
|
|
31
31
|
delete(id: string | number): Promise<void>;
|
|
32
32
|
getSelectOptions(params: SelectOptionsParams): Promise<SelectOption[]>;
|
|
33
33
|
excelExport<T = any>(params?: ListParams): Promise<T>;
|
|
34
|
+
aggregate<T = any>(params?: AggregateParams): Promise<ListResponse<T>>;
|
|
34
35
|
getConfig(): ModelConfig;
|
|
35
36
|
getModelName(): string;
|
|
36
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractBaseModel } from './abstract-base-model';
|
|
2
|
-
import type { SortList } from '../types';
|
|
2
|
+
import type { SortList, ListResponse, AggregateParams } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* OpenAPI 模型实现
|
|
5
5
|
* 处理 OpenAPI 模式下的 URL 生成和请求体构建
|
|
@@ -25,4 +25,9 @@ export declare class OpenApiModel extends AbstractBaseModel {
|
|
|
25
25
|
* @throws LovrabetError 当尝试调用 excelExport 时抛出错误
|
|
26
26
|
*/
|
|
27
27
|
excelExport(params?: any): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* OpenAPI 模式暂不支持 aggregate 操作
|
|
30
|
+
* @throws LovrabetError 当尝试调用 aggregate 时抛出错误
|
|
31
|
+
*/
|
|
32
|
+
aggregate<T = any>(params?: AggregateParams): Promise<ListResponse<T>>;
|
|
28
33
|
}
|
|
@@ -140,6 +140,92 @@ export interface FilterParams {
|
|
|
140
140
|
/** 每页数量 */
|
|
141
141
|
pageSize?: number;
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* 聚合类型
|
|
145
|
+
*/
|
|
146
|
+
export type AggregateType = 'SUM' | 'COUNT' | 'AVG';
|
|
147
|
+
/**
|
|
148
|
+
* 聚合字段配置
|
|
149
|
+
*/
|
|
150
|
+
export interface AggregateField {
|
|
151
|
+
/** 聚合类型 */
|
|
152
|
+
type: AggregateType;
|
|
153
|
+
/** 字段名 */
|
|
154
|
+
field: string;
|
|
155
|
+
/** 字段别名 */
|
|
156
|
+
alias?: string;
|
|
157
|
+
/** 是否 distinct */
|
|
158
|
+
distinct?: boolean;
|
|
159
|
+
/** 是否 round */
|
|
160
|
+
round?: boolean;
|
|
161
|
+
/** round 精度 */
|
|
162
|
+
precision?: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Join 类型
|
|
166
|
+
*/
|
|
167
|
+
export type JoinType = 'LEFT' | 'RIGHT' | 'INNER';
|
|
168
|
+
/**
|
|
169
|
+
* Join 配置
|
|
170
|
+
*/
|
|
171
|
+
export interface JoinConfig {
|
|
172
|
+
/** Join 类型 */
|
|
173
|
+
type: JoinType;
|
|
174
|
+
/** 关联表名 */
|
|
175
|
+
table: string;
|
|
176
|
+
/** 关联条件,key 为当前表字段,value 为关联表字段 */
|
|
177
|
+
condition: Record<string, string>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Having 条件
|
|
181
|
+
*/
|
|
182
|
+
export interface HavingCondition {
|
|
183
|
+
/** 列名(通常是聚合字段的别名) */
|
|
184
|
+
columnName: string;
|
|
185
|
+
/** 条件 */
|
|
186
|
+
condition: FieldCondition;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Aggregate 参数接口
|
|
190
|
+
* @description 用于 aggregate 方法的聚合查询参数
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const aggregateParams: AggregateParams = {
|
|
194
|
+
* select: ['category_id'],
|
|
195
|
+
* aggregate: [
|
|
196
|
+
* { type: 'SUM', field: 'amount', alias: 'total_amount', round: true, precision: 2 }
|
|
197
|
+
* ],
|
|
198
|
+
* where: { status: { $eq: 'active' } },
|
|
199
|
+
* groupBy: ['category_id'],
|
|
200
|
+
* having: [
|
|
201
|
+
* { columnName: 'total_amount', condition: { $gte: 1000 } }
|
|
202
|
+
* ],
|
|
203
|
+
* orderBy: [{ total_amount: SortOrder.DESC }],
|
|
204
|
+
* currentPage: 1,
|
|
205
|
+
* pageSize: 20
|
|
206
|
+
* };
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export interface AggregateParams {
|
|
210
|
+
/** 选择返回的字段列表 */
|
|
211
|
+
select?: string[];
|
|
212
|
+
/** 聚合字段配置 */
|
|
213
|
+
aggregate?: AggregateField[];
|
|
214
|
+
/** Where 条件 */
|
|
215
|
+
where?: WhereCondition;
|
|
216
|
+
/** Group By 字段列表 */
|
|
217
|
+
groupBy?: string[];
|
|
218
|
+
/** Having 条件 */
|
|
219
|
+
having?: HavingCondition[];
|
|
220
|
+
/** Join 配置 */
|
|
221
|
+
join?: JoinConfig[];
|
|
222
|
+
/** 排序规则 */
|
|
223
|
+
orderBy?: SortList;
|
|
224
|
+
/** 当前页码,从 1 开始 */
|
|
225
|
+
currentPage?: number;
|
|
226
|
+
/** 每页数量 */
|
|
227
|
+
pageSize?: number;
|
|
228
|
+
}
|
|
143
229
|
/**
|
|
144
230
|
* 下拉选项接口
|
|
145
231
|
* @description 用于 Select 组件的选项数据格式
|
|
@@ -398,6 +484,25 @@ export interface BaseModelMethods {
|
|
|
398
484
|
* ```
|
|
399
485
|
*/
|
|
400
486
|
excelExport<T = string>(params?: ListParams): Promise<T>;
|
|
487
|
+
/**
|
|
488
|
+
* 聚合查询
|
|
489
|
+
* @template T 返回数据的类型
|
|
490
|
+
* @param params 聚合查询参数,支持 SUM、COUNT、AVG 等聚合函数,以及 GROUP BY、HAVING、JOIN
|
|
491
|
+
* @returns 返回分页数据
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* const result = await model.aggregate({
|
|
495
|
+
* select: ['category_id'],
|
|
496
|
+
* aggregate: [
|
|
497
|
+
* { type: 'SUM', field: 'amount', alias: 'total_amount', round: true, precision: 2 }
|
|
498
|
+
* ],
|
|
499
|
+
* groupBy: ['category_id'],
|
|
500
|
+
* having: [{ columnName: 'total_amount', condition: { $gte: 1000 } }],
|
|
501
|
+
* orderBy: [{ total_amount: SortOrder.DESC }]
|
|
502
|
+
* });
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
aggregate<T = any>(params?: AggregateParams): Promise<ListResponse<T>>;
|
|
401
506
|
}
|
|
402
507
|
/**
|
|
403
508
|
* 模型管理器接口
|