feat(platform): support native server filterBy, workflow compact list and auto-corp credentials

This commit is contained in:
gitea committed 2026-10-22 16:50:25 +08:00
1 parent deed5a5628
commit 975f76af74
10 files changed
+483 -28

No files matched your search

+45 -9
View File
@@ -3,6 +3,7 @@ import {
auditEntityRecords,
auditLedgerContinuityAndBaseline,
buildKeywordFilter,
buildServerFieldFilter,
calculateEntityRecordStats,
fetchAllEntityRecords,
compileRecordPredicate,
@@ -12,6 +13,7 @@ import {
searchEntityRecords,
selectRecordFields,
} from "../../../domains/datalink/services.js";
import type { DatalinkRecord } from "../../../domains/datalink/types.js";
import type { LedgerContinuityReport } from "../../../domains/datalink/types.js";
import { booleanOption, numberOption, stringOption } from "../../parser.js";
import { printJson, printTable, printKeyValue, redactSensitiveText } from "../../printer.js";
@@ -32,7 +34,17 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
if (!resolved.entity) throw new Error("请提供业务对象 ID、编码或名称: hose-use platform records <应用> <业务对象>");
const keyword = stringOption(parsed.options, ["keyword", "q", "query"]);
const filterBy = stringOption(parsed.options, ["filter", "filter-by", "filterBy"]) || (keyword ? buildKeywordFilter(keyword) : undefined);
const searchFields = splitFields(
stringOption(parsed.options, ["search-fields", "searchFields", "search-field", "searchField"])
);
const rawFilter = stringOption(parsed.options, ["filter", "filter-by", "filterBy"]);
let filterBy: string | undefined;
if (rawFilter) {
filterBy = buildServerFieldFilter(rawFilter, resolved.entity);
} else if (keyword) {
filterBy = buildKeywordFilter(keyword, { entity: resolved.entity, searchFields });
}
const whereClause = stringOption(parsed.options, ["where"]);
const predicate = whereClause ? compileRecordPredicate(whereClause, resolved.entity) : undefined;
const sumOption = stringOption(parsed.options, ["sum", "aggregate"]);
@@ -41,7 +53,7 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
const isFlat = booleanOption(parsed.options, ["flat", "normalize", "normalized"], false);
const isAll = booleanOption(parsed.options, ["all", "a"], false);
const groupBy = stringOption(parsed.options, ["group-by", "groupBy"]);
const fetchAll = isAll || Boolean(whereClause || sumOption || isProfileStats);
const fetchAll = isAll || Boolean(sumOption || isProfileStats);
const start = numberOption(parsed.options, ["start", "offset"], 0);
const count = numberOption(parsed.options, ["count", "limit"], 20);
const pageSize = numberOption(parsed.options, ["page-size", "pageSize"], 500);
@@ -125,12 +137,36 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
return { stdout: lines.join("\n") + "\n", stderr: "", exitCode: 0 };
}
const page = fetchAll
? await fetchAllEntityRecords(resolved.clients.ekbClient, resolved.corpId, resolved.entity.id, { filterBy, pageSize })
: await searchEntityRecords(resolved.clients.ekbClient, resolved.corpId, resolved.entity.id, { start, count, filterBy });
let data: DatalinkRecord[] = [];
let total = 0;
let data = page.data;
if (predicate) data = data.filter(predicate);
if (fetchAll) {
const page = await fetchAllEntityRecords(resolved.clients.ekbClient, resolved.corpId, resolved.entity.id, { filterBy, pageSize });
total = page.total;
data = page.data;
if (predicate) data = data.filter(predicate);
} else if (predicate) {
// 客户端谓词早退机制:一旦匹配到 count 条记录,立即停止拉取后续页面,杜绝无限制全量扫描
let matched = 0;
const targetLimit = count ?? 20;
for await (const record of iterateAllEntityRecords(
resolved.clients.ekbClient,
resolved.corpId,
resolved.entity.id,
{ filterBy, pageSize }
)) {
total++;
if (predicate(record)) {
data.push(record);
matched++;
if (matched >= targetLimit) break;
}
}
} else {
const page = await searchEntityRecords(resolved.clients.ekbClient, resolved.corpId, resolved.entity.id, { start, count, filterBy });
total = page.total;
data = page.data;
}
// 3. 数学聚合核算模式 (--sum="租赁费用,日折旧费")
if (sumOption) {
@@ -191,7 +227,7 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
platform: resolved.platform,
entity: resolved.entity,
query: { start: fetchAll ? 0 : start, count: fetchAll ? data.length : count, all: fetchAll, filterBy, where: whereClause, fields, flat: isFlat },
total: page.total,
total: total || data.length,
returned: data.length,
data,
};
@@ -209,7 +245,7 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
const formattedTime = typeof updateTime === "number" ? new Date(updateTime).toLocaleString("zh-CN", { hour12: false }) : cell(updateTime);
return [i + 1, cell(id), cell(nameVal), cell(codeVal), active === false ? "停用" : "启用", formattedTime];
});
return { stdout: `====== [${resolved.platform.name}] ${resolved.entity.name} 记录 (总数: ${page.total}, 当前: ${data.length}${fetchAll ? ", 全量导出" : ""}) ======\n${printTable(["#", "记录 ID", "名称", "编码", "状态", "更新时间"], rows)}\n`, stderr: "", exitCode: 0 };
return { stdout: `====== [${resolved.platform.name}] ${resolved.entity.name} 记录 (总数: ${total || data.length}, 当前: ${data.length}${fetchAll ? ", 全量导出" : ""}) ======\n${printTable(["#", "记录 ID", "名称", "编码", "状态", "更新时间"], rows)}\n`, stderr: "", exitCode: 0 };
}