@stalfh233/omc-cli 0.6.87 → 0.6.89
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.
- package/dist/cli.js +44 -11
- package/dist/endpoints.js +14 -0
- package/dist/intent/capabilities/bizservice.js +7 -82
- package/dist/lanes/b2-registration.js +97 -4
- package/dist/lanes/businessrule-contract.js +3 -3
- package/dist/lanes/businessrule.js +403 -9
- package/dist/lanes/online-js.js +1 -1
- package/dist/lanes/runtime-data-contract.js +5 -1
- package/dist/lanes/runtime-data.js +253 -27
- package/dist/method-references.js +134 -0
- package/dist/path-projection.js +120 -37
- package/dist/read-shapes.js +28 -2
- package/dist/tool-types.js +5 -0
- package/package.json +3 -3
- package/skills/omc-refusals.md +1 -0
|
@@ -313,6 +313,70 @@ function emptyBusinessProjection(items) {
|
|
|
313
313
|
return items.length > 0 && businessColumns > 0;
|
|
314
314
|
}
|
|
315
315
|
const VIEW_PROJECTION_HINT = "该面仅回视图投影列;业务字段全 null 不代表未写入,真值用 data.load,或用 listview.configure 配列。";
|
|
316
|
+
/**
|
|
317
|
+
* 从 items 里找「null 业务列」(跨行全 null;任何一行有值就算已投影有数据),
|
|
318
|
+
* 按视图列证据分类。无 null 业务列时返回 undefined(正常读取零噪音,与旧行为一致)。
|
|
319
|
+
*/
|
|
320
|
+
export function projectionHintFace(items, evidence) {
|
|
321
|
+
const allNull = [];
|
|
322
|
+
const hasValue = new Set();
|
|
323
|
+
for (const item of items) {
|
|
324
|
+
for (const [key, value] of Object.entries(item.fields)) {
|
|
325
|
+
if (RUNTIME_SYSTEM_FIELD_CODES.has(key) || key.endsWith("_"))
|
|
326
|
+
continue;
|
|
327
|
+
if (value === null || value === undefined) {
|
|
328
|
+
if (!hasValue.has(key) && !allNull.includes(key))
|
|
329
|
+
allNull.push(key);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
hasValue.add(key);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const nullColumns = allNull.filter((key) => !hasValue.has(key));
|
|
337
|
+
if (items.length === 0 || nullColumns.length === 0)
|
|
338
|
+
return undefined;
|
|
339
|
+
const base = {
|
|
340
|
+
hint: "null 可能=未投影进视图列,判真值用 data.load --args {schemaCode,bizObjectId}",
|
|
341
|
+
projectionKnown: false,
|
|
342
|
+
...(evidence !== undefined ? { viewColumnsCount: evidence.viewColumnsCount } : {}),
|
|
343
|
+
};
|
|
344
|
+
const codes = evidence?.viewColumnCodes;
|
|
345
|
+
if (codes === undefined)
|
|
346
|
+
return base;
|
|
347
|
+
const inView = new Set(codes);
|
|
348
|
+
const projectedFields = nullColumns.filter((code) => inView.has(code));
|
|
349
|
+
const unprojected = nullColumns.filter((code) => !inView.has(code));
|
|
350
|
+
return {
|
|
351
|
+
...base,
|
|
352
|
+
projectionKnown: true,
|
|
353
|
+
...(projectedFields.length > 0 ? { projectedFields } : {}),
|
|
354
|
+
...(unprojected.length > 0 ? { unprojected } : {}),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* data.list 的视图证据读取(query/get 失败/无视图 → undefined = 无证据)。
|
|
359
|
+
* 拿到 queryColumns 数组才算可判定证据;视图对象在但 queryColumns 非数组 →
|
|
360
|
+
* 只保留列数 0 的兼容口径(projectionKnown 仍 false)。
|
|
361
|
+
*/
|
|
362
|
+
async function listViewProjectionEvidence(session, schemaCode, queryCode) {
|
|
363
|
+
try {
|
|
364
|
+
const view = (await wireCall(session, { path: ENDPOINTS.listQueryGet, query: { schemaCode, code: queryCode, clientType: "PC" } })).data;
|
|
365
|
+
if (view === null || typeof view !== "object")
|
|
366
|
+
return undefined;
|
|
367
|
+
if (Array.isArray(view.queryColumns)) {
|
|
368
|
+
const codes = view.queryColumns
|
|
369
|
+
.map((column) => String(column.propertyCode ?? ""))
|
|
370
|
+
.filter((code) => code.length > 0);
|
|
371
|
+
return { viewColumnsCount: codes.length, viewColumnCodes: codes };
|
|
372
|
+
}
|
|
373
|
+
return { viewColumnsCount: 0 };
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
// Projection diagnostics must never make data.list fail.
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
316
380
|
/**
|
|
317
381
|
* Default-compact a runtime record: drop only KNOWN engine noise — `*_` keys are
|
|
318
382
|
* flow-engine internals (`activityName_`, `participants_`, …) and the staff/dept
|
|
@@ -1220,6 +1284,22 @@ function aggregateValue(metric, sum, nonNullCount, min, max) {
|
|
|
1220
1284
|
return aggregateTidy(sum / nonNullCount);
|
|
1221
1285
|
return metric === "min" ? min : max;
|
|
1222
1286
|
}
|
|
1287
|
+
/**
|
|
1288
|
+
* `list_child` 的回执是 `PageVO<Map<String,Object>>`(FormRuntimeController
|
|
1289
|
+
* .list_child:1921 `new PageVO(data, queryData.getSize())`):总数在
|
|
1290
|
+
* `totalElements`(PageVO.java:40-53),`content` 是**扁平行 map**
|
|
1291
|
+
* (`toObjectMap()`),不是 query/list 的 `{bizObjectId,data}` 包装。
|
|
1292
|
+
*/
|
|
1293
|
+
function childPageOf(payload) {
|
|
1294
|
+
const page = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
1295
|
+
const rawTotal = page.totalElements;
|
|
1296
|
+
const total = typeof rawTotal === "number" && Number.isFinite(rawTotal) ? rawTotal : null;
|
|
1297
|
+
const content = Array.isArray(page.content) ? page.content : [];
|
|
1298
|
+
return {
|
|
1299
|
+
total,
|
|
1300
|
+
rows: content.map((row) => (row && typeof row === "object" ? row : {})),
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1223
1303
|
/**
|
|
1224
1304
|
* One property leaf as a level-1 AND group, so it can be appended to ANY base
|
|
1225
1305
|
* condition (leaf / filters / filterGroup) without re-shaping the existing
|
|
@@ -1612,16 +1692,10 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1612
1692
|
});
|
|
1613
1693
|
const preview = dataListItemPreview(items);
|
|
1614
1694
|
const nullProjection = items.some((item) => Object.values(item.fields).some((value) => value === null));
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
viewColumnsCount = Array.isArray(view?.queryColumns) ? view.queryColumns.length : 0;
|
|
1620
|
-
}
|
|
1621
|
-
catch {
|
|
1622
|
-
// Projection diagnostics must never make data.list fail.
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1695
|
+
// F2(retro 24):出现 null 业务列才读视图证据(正常读取零额外 wire);
|
|
1696
|
+
// 证据链见 projectionHintFace 的源码注释。
|
|
1697
|
+
const viewEvidence = nullProjection ? await listViewProjectionEvidence(session, args.schemaCode, args.queryCode ?? args.schemaCode) : undefined;
|
|
1698
|
+
const projectionHintAll = projectionHintFace(items, viewEvidence);
|
|
1625
1699
|
return {
|
|
1626
1700
|
schemaCode: args.schemaCode,
|
|
1627
1701
|
...application,
|
|
@@ -1668,7 +1742,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1668
1742
|
}),
|
|
1669
1743
|
}
|
|
1670
1744
|
: {}),
|
|
1671
|
-
...(
|
|
1745
|
+
...(projectionHintAll !== undefined ? { projectionHint: projectionHintAll } : {}),
|
|
1672
1746
|
items,
|
|
1673
1747
|
};
|
|
1674
1748
|
}
|
|
@@ -1798,17 +1872,11 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1798
1872
|
const data = row.data && typeof row.data === "object" ? row.data : row;
|
|
1799
1873
|
return String(data.sequenceStatus ?? row.sequenceStatus ?? "") === "DRAFT";
|
|
1800
1874
|
}).length;
|
|
1801
|
-
|
|
1875
|
+
// F2(retro 24):出现 null 业务列才读视图证据;证据链与语义见
|
|
1876
|
+
// projectionHintFace / listViewProjectionEvidence 的源码注释。
|
|
1802
1877
|
const hasNullValue = items.some((item) => Object.values(item.fields).some((value) => value === null));
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
const view = (await wireCall(session, { path: ENDPOINTS.listQueryGet, query: { schemaCode: args.schemaCode, code: args.queryCode ?? args.schemaCode, clientType: "PC" } })).data;
|
|
1806
|
-
viewColumnsCount = Array.isArray(view?.queryColumns) ? view.queryColumns.length : 0;
|
|
1807
|
-
}
|
|
1808
|
-
catch {
|
|
1809
|
-
// Keep the data read authoritative if the optional diagnostic read fails.
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1878
|
+
const viewEvidence = hasNullValue ? await listViewProjectionEvidence(session, args.schemaCode, args.queryCode ?? args.schemaCode) : undefined;
|
|
1879
|
+
const projectionHintPaged = projectionHintFace(items, viewEvidence);
|
|
1812
1880
|
const readback = {
|
|
1813
1881
|
schemaCode: args.schemaCode,
|
|
1814
1882
|
...application,
|
|
@@ -1841,7 +1909,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1841
1909
|
return { filter: policy };
|
|
1842
1910
|
})(),
|
|
1843
1911
|
...(choiceFilterFields.length > 0 && Number(total ?? 0) === 0 ? { filterValueHint: choiceFilterValueHint(choiceFilterFields) } : {}),
|
|
1844
|
-
...(
|
|
1912
|
+
...(projectionHintPaged !== undefined ? { projectionHint: projectionHintPaged } : {}),
|
|
1845
1913
|
totalPages,
|
|
1846
1914
|
itemsCount: items.length,
|
|
1847
1915
|
itemsReturned: items.length,
|
|
@@ -1879,6 +1947,12 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1879
1947
|
filter: z.union([z.record(z.string(), z.unknown()), z.array(z.record(z.string(), z.unknown()))]).optional().describe('单子句 {op,field,value?}(或子句数组=AND);op 同 data.list(eq/neq/gt/lt/gte/lte/like/in/notin/isnull/isnotnull 等)'),
|
|
1880
1948
|
filters: z.array(z.record(z.string(), z.unknown())).optional().describe("子句数组=AND"),
|
|
1881
1949
|
filterGroup: z.record(z.string(), z.unknown()).optional().describe('嵌套组 {op:"and"|"or",clauses:[…]}'),
|
|
1950
|
+
child: z.object({
|
|
1951
|
+
childSchemaCode: z.string().min(1).describe("子表编码(模型里 CHILD_TABLE 字段的 code)"),
|
|
1952
|
+
bizObjectId: z.string().min(1).describe("主表记录 id(data.list 的 row.bizObjectId / data.submit 的 objectId)"),
|
|
1953
|
+
pageSize: z.number().int().min(1).max(500).default(500).optional().describe("数值指标翻页的每页行数(默认 500;list_child 必须显式传 size,空/0 平台会当 Integer.MAX_VALUE)"),
|
|
1954
|
+
maxPages: z.number().int().min(1).max(200).default(40).optional().describe("数值指标翻页上限(默认 40 页;打满仍未取空 → complete:false+truncated)"),
|
|
1955
|
+
}).describe("子表目标:count=服务端 totalElements 精确计数(零行内联);sum/avg/min/max=分页拉目标列后本地折叠").optional(),
|
|
1882
1956
|
metric: z.enum(["count", "sum", "avg", "min", "max"]).describe("count=服务端 totalElements 精确计数(不读行,不需要 field);sum/avg/min/max=数值列本地折叠(需 field,翻页 cap 1000)。null 行不进聚合,avg 分母=已扫非 null 行数"),
|
|
1883
1957
|
field: z.string().min(1).optional().describe("metric≠count 时必填:已发布且 propertyType=2(NUMERICAL)的字段 code。未发布→aggregate-field-unresolved(带 publishedFields/didYouMean);非数值→aggregate-field-not-numerical(计数请用 metric:count)"),
|
|
1884
1958
|
groupBy: z.string().min(1).optional().describe("单列分组:count 值域可枚举走「值域×count」,不可枚举降级本地扫描;数值指标一律本地双列扫描(cap 1000,截断时 complete:false+capNotice)"),
|
|
@@ -1889,6 +1963,28 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1889
1963
|
handler: async (ctx, args, self) => {
|
|
1890
1964
|
const metric = args.metric;
|
|
1891
1965
|
const numeric = metric !== "count";
|
|
1966
|
+
const child = args.child;
|
|
1967
|
+
// 子表面 fail-closed(零 wire):分组与子表是两条独立能力(子表分组另案),
|
|
1968
|
+
// 而 list_child 的 filters 是扁平 List<FilterModel>,平台在没有 queryVersion
|
|
1969
|
+
// 时把它们全部 AND 起来(getFiltersByQueryParam:6584-6590)——filterGroup 的
|
|
1970
|
+
// OR 语义无处表达,宁可拒绝也不静默降级成 AND。
|
|
1971
|
+
if (child !== undefined && args.groupBy !== undefined)
|
|
1972
|
+
throw new ToolInputError({
|
|
1973
|
+
status: "error",
|
|
1974
|
+
blocker: "child-groupby-unsupported",
|
|
1975
|
+
tool: "data.aggregate",
|
|
1976
|
+
message: "child 与 groupBy 互斥:data.aggregate 的子表目标只做 count/sum/avg/min/max,不做分组(子表分组另案)。要去掉 child 做主子表分组,或去掉 groupBy 只算子表整体。",
|
|
1977
|
+
});
|
|
1978
|
+
if (child !== undefined && args.filterGroup !== undefined)
|
|
1979
|
+
throw new ToolInputError({
|
|
1980
|
+
status: "error",
|
|
1981
|
+
blocker: "child-filtergroup-unsupported",
|
|
1982
|
+
tool: "data.aggregate",
|
|
1983
|
+
message: "child 暂不支持 filterGroup:list_child 的 filters 是扁平 List<FilterModel>,平台只在没有 queryVersion 时把它们全部 AND(getFiltersByQueryParam:6584-6590),OR 组没有 wire 形状。只支持 AND:用 filter 或 filters(多子句=AND)。",
|
|
1984
|
+
});
|
|
1985
|
+
// 子表目标的元数据(field.list / 过滤字段 propertyType 注入)取子表 schema;
|
|
1986
|
+
// 回执的 schemaCode 仍是主表。
|
|
1987
|
+
const metaSchemaCode = child?.childSchemaCode ?? args.schemaCode;
|
|
1892
1988
|
// 参数面 fail-closed(零 wire、零写入):metric 与 field 的组合只有两种合法形状。
|
|
1893
1989
|
if (metric === "count" && args.field !== undefined)
|
|
1894
1990
|
throw new ToolInputError({
|
|
@@ -1903,12 +1999,14 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1903
1999
|
blocker: "invalid-input",
|
|
1904
2000
|
tool: "data.aggregate",
|
|
1905
2001
|
message: `metric=${metric} 需要 field(已发布且 propertyType=2/NUMERICAL 的字段 code)——不给 field 无法知道聚合哪一列`,
|
|
1906
|
-
nextCommand: `omc call field.list --env <env> --args '{"schemaCode":"${
|
|
2002
|
+
nextCommand: `omc call field.list --env <env> --args '{"schemaCode":"${metaSchemaCode}","published":true}'`,
|
|
1907
2003
|
});
|
|
1908
2004
|
// count+groupBy 要统一 base 与各桶的口径,省略时默认排除草稿;count 省略时保留
|
|
1909
2005
|
// 平台默认(无条件含草稿),只有显式 false 才注入排除条件。数值指标(本地折叠)
|
|
1910
2006
|
// 不做默认注入——结果如实反映平台返回行,要排除须显式 false。
|
|
1911
|
-
|
|
2007
|
+
// 子表没有独立的流程状态(sequenceStatus 属主表),**绝不**给 list_child 注入
|
|
2008
|
+
// 草稿条件——否则会静默过滤掉本应计入的子行。
|
|
2009
|
+
const excludedByRequest = child === undefined && (args.includeDrafts === false || (args.includeDrafts === undefined && args.groupBy !== undefined && !numeric));
|
|
1912
2010
|
const includeDrafts = args.includeDrafts === true;
|
|
1913
2011
|
// 用户条件与草稿注入分开构造:filterGroup 会把 filters 覆盖掉(toQueryCondition
|
|
1914
2012
|
// 的既有语义),所以草稿条件统一按「level1 AND 追加一组」合并,任何 DSL 形状都不丢。
|
|
@@ -1946,7 +2044,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1946
2044
|
return published;
|
|
1947
2045
|
metaCalls += 1;
|
|
1948
2046
|
try {
|
|
1949
|
-
const rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode:
|
|
2047
|
+
const rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: metaSchemaCode, isPublish: "true" } })).data);
|
|
1950
2048
|
const map = new Map();
|
|
1951
2049
|
for (const row of rows) {
|
|
1952
2050
|
const code = String(row.code ?? row.propertyCode ?? "");
|
|
@@ -1967,7 +2065,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1967
2065
|
}
|
|
1968
2066
|
return published;
|
|
1969
2067
|
};
|
|
1970
|
-
const fieldListNext = `omc call field.list --env <env> --args '{"schemaCode":"${
|
|
2068
|
+
const fieldListNext = `omc call field.list --env <env> --args '{"schemaCode":"${metaSchemaCode}","published":true}'`;
|
|
1971
2069
|
// 数值指标:field 必须已发布且 NUMERICAL(2)——fail closed,不做类型猜测。
|
|
1972
2070
|
if (numeric) {
|
|
1973
2071
|
const target = args.field;
|
|
@@ -1978,6 +2076,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1978
2076
|
blocker: "aggregate-field-unresolved",
|
|
1979
2077
|
reason: "metadata-unavailable",
|
|
1980
2078
|
schemaCode: args.schemaCode,
|
|
2079
|
+
...(child !== undefined ? { childSchemaCode: child.childSchemaCode } : {}),
|
|
1981
2080
|
field: target,
|
|
1982
2081
|
message: `读不到已发布字段元数据(field.list),无法确认 ${target} 是 NUMERICAL(2)——数值聚合不做类型猜测`,
|
|
1983
2082
|
nextCommand: fieldListNext,
|
|
@@ -1997,6 +2096,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1997
2096
|
status: "refused",
|
|
1998
2097
|
blocker: "aggregate-field-unresolved",
|
|
1999
2098
|
schemaCode: args.schemaCode,
|
|
2099
|
+
...(child !== undefined ? { childSchemaCode: child.childSchemaCode } : {}),
|
|
2000
2100
|
field: target,
|
|
2001
2101
|
publishedFields: sample,
|
|
2002
2102
|
publishedFieldsTotal: catalog.length,
|
|
@@ -2013,6 +2113,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2013
2113
|
status: "refused",
|
|
2014
2114
|
blocker: "aggregate-field-not-numerical",
|
|
2015
2115
|
schemaCode: args.schemaCode,
|
|
2116
|
+
...(child !== undefined ? { childSchemaCode: child.childSchemaCode } : {}),
|
|
2016
2117
|
field: target,
|
|
2017
2118
|
propertyType: targetMeta.type,
|
|
2018
2119
|
...(numericFields.length > 0 ? { numericFields: numericFields.slice(0, AGGREGATE_FIELD_SAMPLE_LIMIT) } : {}),
|
|
@@ -2036,12 +2137,137 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2036
2137
|
status: "refused",
|
|
2037
2138
|
blocker: "unknown-filter-field",
|
|
2038
2139
|
schemaCode: args.schemaCode,
|
|
2140
|
+
...(child !== undefined ? { childSchemaCode: child.childSchemaCode } : {}),
|
|
2039
2141
|
missing: injected.missing,
|
|
2040
2142
|
message: `filter 字段不在已发布元数据里:${injected.missing.join("、")}(聚合复用 data.list 的 propertyType 注入,不做猜测)`,
|
|
2041
2143
|
nextCommand: fieldListNext,
|
|
2042
2144
|
};
|
|
2043
2145
|
condition = injected.condition;
|
|
2044
2146
|
}
|
|
2147
|
+
// ---- 子表目标(child)------------------------------------------------
|
|
2148
|
+
// count:1 次 list_child(page:0,size:1),只取服务端 totalElements;
|
|
2149
|
+
// sum/avg/min/max:columns 列投影 + 分页,本地折叠。子表没有服务端 sum
|
|
2150
|
+
// (/runtime/query/sum 只认主 schema 的属性表,QueryRuntimeController.java:589-640)。
|
|
2151
|
+
if (child !== undefined) {
|
|
2152
|
+
const childDraftFilter = {
|
|
2153
|
+
draftPolicy: "not-applicable",
|
|
2154
|
+
hint: "子表没有独立的流程状态(sequenceStatus 属主表),未注入草稿条件;includeDrafts 对 child 无效",
|
|
2155
|
+
};
|
|
2156
|
+
// filters 是扁平 List<FilterModel>(FilterModel.java:45-55);filter/filters
|
|
2157
|
+
// 的 DSL 输出是单个 AND 组,展平即平台语义——queryVersion 不传时平台把
|
|
2158
|
+
// filters 全部 AND(BizObjectFacadeImpl.getFiltersByQueryParam:6584-6590)。
|
|
2159
|
+
const childFilters = condition === undefined
|
|
2160
|
+
? undefined
|
|
2161
|
+
: condition.flat(2);
|
|
2162
|
+
const listChildBody = (page, size, columns) => ({
|
|
2163
|
+
schemaCode: args.schemaCode,
|
|
2164
|
+
childSchemaCode: child.childSchemaCode,
|
|
2165
|
+
bizObjectId: child.bizObjectId,
|
|
2166
|
+
page,
|
|
2167
|
+
// QueryDataVO.getSize() 在 size 空/0 时返回 Integer.MAX_VALUE
|
|
2168
|
+
// (QueryDataVO.java:186-191)——size 必须显式传,否则退化成全量。
|
|
2169
|
+
size,
|
|
2170
|
+
...(childFilters !== undefined && childFilters.length > 0 ? { filters: childFilters } : {}),
|
|
2171
|
+
...(columns !== undefined ? { columns: columns.map((propertyCode) => ({ propertyCode })) } : {}),
|
|
2172
|
+
});
|
|
2173
|
+
// 平台错误原样透出(message/errcode 不动),只在 hint 里补上
|
|
2174
|
+
// childSchemaCode/bizObjectId,便于把「主记录不存在/子表不存在」对回目标。
|
|
2175
|
+
const listChildCall = async (body) => {
|
|
2176
|
+
try {
|
|
2177
|
+
return await wireCall(session, { path: ENDPOINTS.runtimeFormListChild, method: "POST", body });
|
|
2178
|
+
}
|
|
2179
|
+
catch (error) {
|
|
2180
|
+
if (error instanceof WireError)
|
|
2181
|
+
throw new WireError(error.kind, error.message, error.errcode, error.diagnostic, `childSchemaCode=${child.childSchemaCode}; bizObjectId=${child.bizObjectId}${error.hint !== undefined ? `;${error.hint}` : ""}`);
|
|
2182
|
+
throw error;
|
|
2183
|
+
}
|
|
2184
|
+
};
|
|
2185
|
+
if (!numeric) {
|
|
2186
|
+
const page = childPageOf((await listChildCall(listChildBody(0, 1))).data);
|
|
2187
|
+
return {
|
|
2188
|
+
schemaCode: args.schemaCode,
|
|
2189
|
+
metric: "count",
|
|
2190
|
+
value: page.total,
|
|
2191
|
+
mode: "server-child",
|
|
2192
|
+
rows: 0,
|
|
2193
|
+
child: { childSchemaCode: child.childSchemaCode, bizObjectId: child.bizObjectId },
|
|
2194
|
+
...(page.total === null ? { note: "list_child 未回 totalElements(PageVO 形状漂移)" } : {}),
|
|
2195
|
+
filter: childDraftFilter,
|
|
2196
|
+
wire: { calls: metaCalls + 1, plan: metaCalls > 0 ? "1 metadata + 1 list_child" : "1 list_child" },
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
const target = args.field;
|
|
2200
|
+
const pageSize = child.pageSize ?? 500;
|
|
2201
|
+
const maxPages = child.maxPages ?? 40;
|
|
2202
|
+
const numericMetric = metric;
|
|
2203
|
+
let count = 0;
|
|
2204
|
+
let nonNullCount = 0;
|
|
2205
|
+
let sum = 0;
|
|
2206
|
+
let min = Number.POSITIVE_INFINITY;
|
|
2207
|
+
let max = Number.NEGATIVE_INFINITY;
|
|
2208
|
+
let pages = 0;
|
|
2209
|
+
let truncated = false;
|
|
2210
|
+
let readFailure;
|
|
2211
|
+
for (let pageIndex = 0; pageIndex < maxPages; pageIndex += 1) {
|
|
2212
|
+
let pageData;
|
|
2213
|
+
try {
|
|
2214
|
+
pageData = childPageOf((await listChildCall(listChildBody(pageIndex, pageSize, [target]))).data);
|
|
2215
|
+
}
|
|
2216
|
+
catch (error) {
|
|
2217
|
+
// 任何一页读取失败 → partial(complete:false),如实报已扫页数,
|
|
2218
|
+
// 不把部分和当全量、也不外推。
|
|
2219
|
+
readFailure = {
|
|
2220
|
+
page: pageIndex,
|
|
2221
|
+
...(error instanceof WireError && error.errcode !== undefined ? { code: error.errcode } : {}),
|
|
2222
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2223
|
+
};
|
|
2224
|
+
break;
|
|
2225
|
+
}
|
|
2226
|
+
pages += 1;
|
|
2227
|
+
for (const row of pageData.rows) {
|
|
2228
|
+
count += 1;
|
|
2229
|
+
const value = aggregateNumeric(row[target]);
|
|
2230
|
+
if (value === null)
|
|
2231
|
+
continue;
|
|
2232
|
+
nonNullCount += 1;
|
|
2233
|
+
sum += value;
|
|
2234
|
+
if (value < min)
|
|
2235
|
+
min = value;
|
|
2236
|
+
if (value > max)
|
|
2237
|
+
max = value;
|
|
2238
|
+
}
|
|
2239
|
+
// 不足一页 = 已取尽;正好一页且已到 maxPages = 无法证明取尽(可能还有)。
|
|
2240
|
+
if (pageData.rows.length < pageSize)
|
|
2241
|
+
break;
|
|
2242
|
+
if (pageIndex === maxPages - 1)
|
|
2243
|
+
truncated = true;
|
|
2244
|
+
}
|
|
2245
|
+
const complete = readFailure === undefined && !truncated;
|
|
2246
|
+
const value = aggregateValue(numericMetric, sum, nonNullCount, min, max);
|
|
2247
|
+
const capNotice = readFailure !== undefined
|
|
2248
|
+
? `子表数值折叠:第 ${readFailure.page} 页(0 起)读取失败(${readFailure.code !== undefined ? `errcode ${readFailure.code} ` : ""}${readFailure.message}),只覆盖已扫 ${pages} 页 / ${count} 行(complete:false,非全集);已扫部分的值不是全量。`
|
|
2249
|
+
: `子表数值折叠:翻到 maxPages=${maxPages} 上限仍未取空(每页 ${pageSize} 行),只覆盖已扫 ${pages} 页 / ${count} 行(complete:false,非全集)。要全集:调大 maxPages/pageSize,或用 filter 按业务键分片重跑。`;
|
|
2250
|
+
return {
|
|
2251
|
+
schemaCode: args.schemaCode,
|
|
2252
|
+
metric,
|
|
2253
|
+
field: target,
|
|
2254
|
+
value,
|
|
2255
|
+
rows: count,
|
|
2256
|
+
nullCount: count - nonNullCount,
|
|
2257
|
+
pages,
|
|
2258
|
+
mode: "local-scan-child",
|
|
2259
|
+
coverage: { complete, pageSize, maxPages, truncated },
|
|
2260
|
+
child: { childSchemaCode: child.childSchemaCode, bizObjectId: child.bizObjectId },
|
|
2261
|
+
...(value === null ? { note: "no numeric values in scanned child rows" } : {}),
|
|
2262
|
+
filter: childDraftFilter,
|
|
2263
|
+
...(complete ? {} : { capNotice }),
|
|
2264
|
+
...(readFailure !== undefined ? { partial: true, readFailure } : {}),
|
|
2265
|
+
wire: {
|
|
2266
|
+
calls: metaCalls + pages + (readFailure !== undefined ? 1 : 0),
|
|
2267
|
+
plan: `${metaCalls} metadata + ${pages} list_child pages${readFailure !== undefined ? " + 1 failed" : ""}`,
|
|
2268
|
+
},
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2045
2271
|
const queryBody = (size, page) => ({
|
|
2046
2272
|
schemaCode: args.schemaCode,
|
|
2047
2273
|
queryCode: args.schemaCode,
|
|
@@ -2364,7 +2590,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2364
2590
|
...(scan.concurrency !== undefined ? { concurrency: scan.concurrency } : {}),
|
|
2365
2591
|
},
|
|
2366
2592
|
};
|
|
2367
|
-
}, { target: `data.aggregate:${JSON.stringify({ schemaCode: args.schemaCode, metric: args.metric, field: args.field, filter: args.filter, filters: args.filters, filterGroup: args.filterGroup, groupBy: args.groupBy, topN: args.topN ?? 10, includeDrafts: args.includeDrafts ?? null })}` });
|
|
2593
|
+
}, { target: `data.aggregate:${JSON.stringify({ schemaCode: args.schemaCode, metric: args.metric, field: args.field, filter: args.filter, filters: args.filters, filterGroup: args.filterGroup, groupBy: args.groupBy, topN: args.topN ?? 10, includeDrafts: args.includeDrafts ?? null, child: args.child ?? null })}` });
|
|
2368
2594
|
},
|
|
2369
2595
|
}));
|
|
2370
2596
|
tools.push(defineTool({
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ENDPOINTS } from "./endpoints.js";
|
|
2
|
+
import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "./json-column.js";
|
|
3
|
+
import { wireCall, wireRows } from "./wire.js";
|
|
4
|
+
export const METHOD_REFERENCE_LIMITS = { models: 25, rules: 50, sites: 8 };
|
|
5
|
+
/** Platform reference count: GET /app/bizmethod/count_mapping → Integer. Failures throw. */
|
|
6
|
+
export async function countMethodMapping(session, serviceCode, methodCode) {
|
|
7
|
+
const response = await wireCall(session, {
|
|
8
|
+
path: ENDPOINTS.bizMethodCountMapping,
|
|
9
|
+
query: { serviceCode, ...(methodCode !== undefined ? { serviceMethodCode: methodCode } : {}) },
|
|
10
|
+
});
|
|
11
|
+
const value = response.data;
|
|
12
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
13
|
+
return value;
|
|
14
|
+
const parsed = Number(value);
|
|
15
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Node codes in one rule graph whose `methodMapping` points at exactly this
|
|
19
|
+
* service+method. The `node` column may arrive as a JSON string or an array;
|
|
20
|
+
* anything else (corrupt column, object, null) yields no hits.
|
|
21
|
+
*/
|
|
22
|
+
function mappedMethodNodeCodes(nodeColumn, serviceCode, methodCode) {
|
|
23
|
+
const decoded = decodeJsonColumn(nodeColumn, JSON_COLUMN_NULL_COALESCE);
|
|
24
|
+
if (!Array.isArray(decoded))
|
|
25
|
+
return [];
|
|
26
|
+
const nodeCodes = [];
|
|
27
|
+
for (const entry of decoded) {
|
|
28
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
29
|
+
continue;
|
|
30
|
+
const node = entry;
|
|
31
|
+
const mapping = node.methodMapping;
|
|
32
|
+
if (!mapping || typeof mapping !== "object" || Array.isArray(mapping))
|
|
33
|
+
continue;
|
|
34
|
+
const mapped = mapping;
|
|
35
|
+
if (String(mapped.serviceCode ?? "") !== serviceCode || String(mapped.serviceMethodCode ?? "") !== methodCode)
|
|
36
|
+
continue;
|
|
37
|
+
const nodeCode = String(node.nodeCode ?? "");
|
|
38
|
+
if (nodeCode !== "")
|
|
39
|
+
nodeCodes.push(nodeCode);
|
|
40
|
+
}
|
|
41
|
+
return nodeCodes;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Best-effort reference identity: viewReference → schemaCodes (≤25) → per-model
|
|
45
|
+
* rule list (≤50 rules) → per-rule graph read → methodMapping match
|
|
46
|
+
* (serviceCode + serviceMethodCode). A single failed read only lands in
|
|
47
|
+
* `coverage`; sites stop at 8 and the coverage says the scan was truncated.
|
|
48
|
+
*/
|
|
49
|
+
export async function scanMethodReferenceSites(session, serviceCode, methodCode) {
|
|
50
|
+
const sites = [];
|
|
51
|
+
const coverage = {
|
|
52
|
+
source: "viewReference+rule.list+rule.get",
|
|
53
|
+
modelsDiscovered: 0,
|
|
54
|
+
modelsScanned: 0,
|
|
55
|
+
rulesScanned: 0,
|
|
56
|
+
modelsReadFailed: 0,
|
|
57
|
+
rulesReadFailed: 0,
|
|
58
|
+
truncated: false,
|
|
59
|
+
sitesReturned: 0,
|
|
60
|
+
};
|
|
61
|
+
let schemaCodes = [];
|
|
62
|
+
try {
|
|
63
|
+
const rows = wireRows((await wireCall(session, {
|
|
64
|
+
path: ENDPOINTS.bizServiceMethodViewReference,
|
|
65
|
+
query: { serviceCode, serviceMethodCode: methodCode },
|
|
66
|
+
})).data);
|
|
67
|
+
const discovered = [...new Set(rows.map((row) => String(row.schemaCode ?? "")).filter((code) => code !== ""))];
|
|
68
|
+
coverage.modelsDiscovered = discovered.length;
|
|
69
|
+
if (discovered.length > METHOD_REFERENCE_LIMITS.models)
|
|
70
|
+
coverage.truncated = true;
|
|
71
|
+
schemaCodes = discovered.slice(0, METHOD_REFERENCE_LIMITS.models);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// No model list: zero sites is all we can say. Callers must label it as a
|
|
75
|
+
// zero-HIT scan (never "no references").
|
|
76
|
+
return { sites, coverage };
|
|
77
|
+
}
|
|
78
|
+
for (const schemaCode of schemaCodes) {
|
|
79
|
+
coverage.modelsScanned += 1;
|
|
80
|
+
let rules = [];
|
|
81
|
+
try {
|
|
82
|
+
rules = wireRows((await wireCall(session, { path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } })).data);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
coverage.modelsReadFailed += 1;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (rules.length > METHOD_REFERENCE_LIMITS.rules)
|
|
89
|
+
coverage.truncated = true;
|
|
90
|
+
for (const rule of rules.slice(0, METHOD_REFERENCE_LIMITS.rules)) {
|
|
91
|
+
const ruleCode = String(rule.code ?? "");
|
|
92
|
+
const id = rule.id;
|
|
93
|
+
if (ruleCode === "" || typeof id !== "string" || id === "")
|
|
94
|
+
continue;
|
|
95
|
+
let record = null;
|
|
96
|
+
try {
|
|
97
|
+
record = (await wireCall(session, { path: ENDPOINTS.businessRuleGet, query: { id } })).data;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
coverage.rulesReadFailed += 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
coverage.rulesScanned += 1;
|
|
104
|
+
if (!record)
|
|
105
|
+
continue;
|
|
106
|
+
for (const nodeCode of mappedMethodNodeCodes(record.node, serviceCode, methodCode)) {
|
|
107
|
+
sites.push({ schemaCode, ruleCode, nodeCode });
|
|
108
|
+
if (sites.length >= METHOD_REFERENCE_LIMITS.sites) {
|
|
109
|
+
coverage.truncated = true;
|
|
110
|
+
coverage.sitesReturned = sites.length;
|
|
111
|
+
return { sites, coverage };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
coverage.sitesReturned = sites.length;
|
|
117
|
+
return { sites, coverage };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The single "this method is referenced" fact sentence: count + 500108 +
|
|
121
|
+
* platform source anchor + "rules and bindings stay untouched" + doNot. Both
|
|
122
|
+
* `method.delete` and the intent warning append `methodReferenceIdentity`.
|
|
123
|
+
*/
|
|
124
|
+
export function methodReferencedCoreMessage(serviceCode, methodCode, count) {
|
|
125
|
+
return `业务方法 ${serviceCode}/${methodCode} 被 ${count} 条规则映射引用——平台删除会回 500108「业务方法已绑定默认方法,不可删除」(BizServiceMethodController.java:248-281),本次零写入:方法、规则与绑定保持原状。要删必须先解绑引用规则(rule.save 去掉对应 BIZ_ACTION 节点、保留其余节点/routes/schedulerSetting,重新发布)再删方法。不要自行解绑规则、不要改调度生效时间后再删方法——解绑属于高危写入,必须用户确认`;
|
|
126
|
+
}
|
|
127
|
+
/** Readable suffix for the reference scan: site identities, or a pointer when the scan hit nothing. */
|
|
128
|
+
export function methodReferenceIdentity(sites, serviceCode) {
|
|
129
|
+
if (sites.length === 0)
|
|
130
|
+
return `;定位:omc call rule.references --args '{"kind":"service","code":"${serviceCode}"}'`;
|
|
131
|
+
const shown = sites.slice(0, 3).map((site) => `${site.schemaCode}/${site.ruleCode}#${site.nodeCode}`).join("、");
|
|
132
|
+
return `;引用点:${shown}${sites.length > 3 ? ` 等 ${sites.length} 处` : ""}`;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=method-references.js.map
|