feat(bill): expose raw filterBy, select, distinct, and join in search API and CLI

This commit is contained in:
gitea committed 2026-09-17 15:08:38 +08:00
1 parent ca713cfafc
commit 139e50395d
4 files changed
+38 -3

No files matched your search

+6
View File
@@ -172,6 +172,9 @@ export async function handleBillCommand(
const endDate = stringOption(parsed.options, ["end-date", "endDate", "to", "end"]);
const rawOrder = stringOption(parsed.options, ["order", "sort", "direction"]);
const order = rawOrder && /asc/i.test(rawOrder) ? "ASC" : "DESC";
const filterBy = stringOption(parsed.options, ["filter-by", "filterBy", "filter"]);
const select = stringOption(parsed.options, ["select", "fields"]);
const distinct = booleanOption(parsed.options, ["distinct"]);
const result = await searchAndFormatBills(await getClient(), corpId, {
code,
@@ -183,6 +186,9 @@ export async function handleBillCommand(
startDate,
endDate,
order,
filterBy,
select,
distinct,
});
if (runtime.jsonMode) {
+14 -1
View File
@@ -317,6 +317,8 @@ export interface RawBillSearchOptions {
filterBy?: string;
orderBy?: Array<{ value: string; order: "ASC" | "DESC" }>;
select?: string;
distinct?: boolean;
join?: string | string[];
}
export async function searchRawBills(
@@ -340,9 +342,20 @@ export async function searchRawBills(
if (options.select) {
jsonBody.select = options.select;
}
if (options.distinct !== undefined) {
jsonBody.distinct = options.distinct;
}
const searchParams: Record<string, string> = {
corporationId: corpId,
corpId,
};
if (options.join) {
searchParams.join = Array.isArray(options.join) ? options.join.join(";") : options.join;
}
const response = await client.post("api/v2/invoice/search", {
searchParams: { corporationId: corpId, corpId },
searchParams,
timeout: options.timeout ?? 30000,
json: jsonBody,
});
+13 -2
View File
@@ -1177,6 +1177,10 @@ export function parseSinceDuration(since: string | undefined): number | undefine
}
export function buildServerBillFilterBy(params: BillQueryParams): string | undefined {
if (params.filterBy && params.filterBy.trim()) {
return params.filterBy.trim();
}
const parts: string[] = [];
// 1. active 软删除过滤 (使用 .in 避免 CloudWAF 误拦截)
@@ -1227,7 +1231,9 @@ export async function searchAndFormatBills(
const filterBy = buildServerBillFilterBy(params);
const sortDirection = (params.order || "DESC").toUpperCase() as "ASC" | "DESC";
const orderBy = [{ value: "createTime", order: sortDirection }];
const orderBy = params.orderBy && params.orderBy.length > 0
? params.orderBy
: [{ value: "createTime", order: sortDirection }];
let searchRes: RawBillSearchResponse;
try {
@@ -1236,7 +1242,9 @@ export async function searchAndFormatBills(
count: params.count ?? 20,
filterBy,
orderBy,
select: "id,code,name,createTime,updateTime,form,active",
select: params.select || "id,code,name,createTime,updateTime,form,active",
distinct: params.distinct,
join: params.join,
});
} catch (err) {
if (String(err).includes("timed out") || (err as any)?.name === "TimeoutError") {
@@ -1325,6 +1333,9 @@ export const billTools = [
since: z.string().optional().describe("相对时间范围,如 7d (7天), 30d (30天), 90d, 1y"),
startDate: z.string().optional().describe("起始时间 (YYYY-MM-DD 或毫秒时间戳)"),
endDate: z.string().optional().describe("截止时间 (YYYY-MM-DD 或毫秒时间戳)"),
filterBy: z.string().optional().describe("原始合思 RQL 检索表达式,如 ((createTime > 1780000000000) && (code.in('BX-001')))"),
select: z.string().optional().describe("按需返回字段(逗号分隔),如 id,code,name,createTime,updateTime,form"),
distinct: z.boolean().optional().describe("是否对单据结果去重"),
stage: z.string().optional().describe("按阶段过滤(如 expense 报销, loan 借款, payment 付款)"),
state: z.string().optional().describe("按审批/支付状态过滤(如 paid 已支付, approving 审批中, draft 草稿)"),
count: z.number().optional().default(20).describe("拉取记录数"),
+5
View File
@@ -109,6 +109,11 @@ export interface BillQueryParams {
endDate?: string;
active?: boolean;
order?: "ASC" | "DESC" | "asc" | "desc";
orderBy?: Array<{ value: string; order: "ASC" | "DESC" }>;
filterBy?: string;
select?: string;
distinct?: boolean;
join?: string | string[];
}
export interface BillFlowEntry {