weaver-work-cli 0.1.52 → 0.1.54
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/chunks/{attachment-content-MBYYSQIX.js → attachment-content-2EPEI4HV.js} +3 -3
- package/dist/chunks/{chunk-DZOC77ZD.js → chunk-6LGLI46Q.js} +1 -1
- package/dist/chunks/{chunk-RWFRZSIP.js → chunk-7KKI5KDY.js} +2 -2
- package/dist/chunks/{chunk-KLZ3ULQQ.js → chunk-CNVZETM5.js} +1 -1
- package/dist/chunks/{chunk-RPRFIG6I.js → chunk-FE3CQAAM.js} +23 -23
- package/dist/chunks/{chunk-ZRHKGQRQ.js → chunk-JJRIT2ZN.js} +2 -2
- package/dist/chunks/{chunk-LTRLF6MM.js → chunk-LYOFRYC4.js} +4 -4
- package/dist/chunks/{chunk-7UOXOGFL.js → chunk-O6RIBG5E.js} +4 -4
- package/dist/chunks/{chunk-LM2H7SZI.js → chunk-QUDHSMG3.js} +37 -25
- package/dist/chunks/{chunk-IRMA3GVP.js → chunk-XHMJBRLZ.js} +1 -1
- package/dist/chunks/{chunk-LALWNK6M.js → chunk-XPQN4E5O.js} +41 -19
- package/dist/chunks/{chunk-D3TDNRFE.js → chunk-Z7B7QSR2.js} +7 -7
- package/dist/chunks/{conflict-D2HYKBMH.js → conflict-K2IAKKFR.js} +2 -2
- package/dist/chunks/{contract-MFOFMM2J.js → contract-LJRAXVZU.js} +5448 -1857
- package/dist/chunks/{create-flow-7ZATJVTM.js → create-flow-UL37MZGP.js} +6 -6
- package/dist/chunks/{env-5DO4YENS.js → env-BZDB5OVZ.js} +2 -2
- package/dist/chunks/{factory-3M7D7WJC.js → factory-VD3YI6N7.js} +1 -1
- package/dist/chunks/{group-chat-B2HT5NEO.js → group-chat-DHNVO76L.js} +3 -3
- package/dist/chunks/{meeting-HZOX3CBB.js → meeting-OWG4O2XH.js} +10 -10
- package/dist/chunks/{registry-SJHSBO5G.js → registry-ASYCWF2U.js} +10 -10
- package/dist/chunks/{registry-KYPFFQIH.js → registry-CJOVECZD.js} +1 -1
- package/dist/chunks/{room-recommend-5AHR4YQV.js → room-recommend-LSVAMGKV.js} +4 -4
- package/dist/chunks/{schedule-KZPJUPC2.js → schedule-7QOPRUU4.js} +4 -4
- package/dist/chunks/{smart-extract-IXHCZE4R.js → smart-extract-FOUYNIG3.js} +44 -8
- package/dist/chunks/{workflow-UHKCZJMY.js → workflow-YHXFIU63.js} +1 -1
- package/dist/index.js +4 -4
- package/dist/shortcuts/contract/manifest.js +105 -5
- package/dist/shortcuts/contract/ooxml/docx-table.js +233 -0
- package/dist/shortcuts/contract/operations/card-action.js +597 -17
- package/dist/shortcuts/contract/operations/card-ebdf-list.js +258 -2
- package/dist/shortcuts/contract/operations/card.js +6 -5
- package/dist/shortcuts/contract/operations/docx-fillfromquote.js +532 -0
- package/dist/shortcuts/contract/operations/docx-verify.js +258 -0
- package/dist/shortcuts/contract/operations/elements-build.js +47 -0
- package/dist/shortcuts/contract/operations/first-screen.js +28 -3
- package/dist/shortcuts/contract/operations/ledger.js +438 -0
- package/dist/shortcuts/contract/operations/performance.js +104 -3
- package/dist/shortcuts/contract/operations/quotescreen.js +529 -0
- package/dist/shortcuts/contract/operations/registry.js +10 -0
- package/dist/shortcuts/contract/operations/triage.js +1100 -0
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +21 -0
- package/dist/shortcuts/smart-extract/operations/fill.js +10 -7
- package/dist/shortcuts/smart-extract/operations/validate.js +49 -3
- package/dist/shortcuts/workflow/operations/form.js +68 -33
- package/docs/smart-extract.md +5 -5
- package/package.json +1 -1
- package/skills/weaver-e10-jinchengda/SKILL.md +139 -99
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +43 -482
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +7 -8
- package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +32 -16
- package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +478 -0
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +39 -61
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +13 -9
- package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +263 -0
- package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +525 -0
- package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +36 -0
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +3 -6
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +80 -54
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +53 -76
- package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +19 -21
- package/skills/weaver-e10-jinchengda/references/orchestration.md +12 -12
- package/skills/weaver-e10-jinchengda/references/source-manifest.json +1 -6
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +2 -1
- package/skills/weaver-e10-meeting/SKILL.md +2 -1
- package/skills/weaver-e10-smart-extract/SKILL.md +15 -4
- package/skills/weaver-e10-smart-extract/references/result-format.md +2 -2
- package/skills/weaver-e10-smart-extract/references/troubleshooting.md +2 -1
- package/skills/weaver-e10-workflow/references/workflow-create.md +6 -5
- package/skills/weaver-e10-workflow/references/workflow-edit.md +1 -1
- package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +0 -200
- package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +0 -572
- package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +0 -560
- package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +0 -894
- package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +0 -598
- package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +0 -118
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
import { contractValidationError } from '../errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* 台账数据处理的本地 operation(2026-11-13 从 scripts/ledger_aggregate.py 与
|
|
7
|
+
* scripts/ledger_guard.py 迁移,遵守「能力下沉 CLI」规范)。
|
|
8
|
+
*
|
|
9
|
+
* 为什么必须做成 operation 而不是技能包里的 Python 脚本:
|
|
10
|
+
* 1) 技能包只应保留「必须依赖 python-docx / PyPDF2 等 Node 无等价库」的脚本,
|
|
11
|
+
* 纯 JSON 读取、分组求和、阈值判定这类逻辑 Node 原生即可完成;
|
|
12
|
+
* 2) 脚本散落在 skills/scripts 下会出现两套入口、两套参数、两份文档,
|
|
13
|
+
* 文档与实现容易漂移(本次事故即为脚本先上线、SKILL.md 白名单未登记);
|
|
14
|
+
* 3) operation 自带 manifest 契约(参数校验、风险标注、schema 可查),
|
|
15
|
+
* 跨平台行为一致,且不需要用户额外准备 Python 运行时。
|
|
16
|
+
*
|
|
17
|
+
* 两者都是纯本地能力:不访问任何业务接口、不读取凭证。
|
|
18
|
+
*/
|
|
19
|
+
// ---------------------------------------------------------------- 公共工具
|
|
20
|
+
/** Python 的 `json.loads` 前会去掉 BOM,这里同样处理。 */
|
|
21
|
+
function readJsonFile(path) {
|
|
22
|
+
const raw = readFileSync(path, 'utf8').replace(/^\uFEFF/u, '');
|
|
23
|
+
return JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
function isRecord(value) {
|
|
26
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
/** 人员字段是 JSON 字符串/数组时解析成「姓名(id)」,其余按文本处理。 */
|
|
29
|
+
function cellText(value) {
|
|
30
|
+
if (value === null || value === undefined)
|
|
31
|
+
return '';
|
|
32
|
+
let raw;
|
|
33
|
+
if (typeof value === 'object') {
|
|
34
|
+
raw = JSON.stringify(value);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
raw = String(value);
|
|
38
|
+
}
|
|
39
|
+
const trimmed = raw.trim();
|
|
40
|
+
if (trimmed.startsWith('[') || trimmed.startsWith('{')) {
|
|
41
|
+
const names = [...trimmed.matchAll(/"name"\s*:\s*"([^"]+)"/gu)].map((m) => m[1]);
|
|
42
|
+
const ids = [...trimmed.matchAll(/"id"\s*:\s*"?(\d+)"?/gu)].map((m) => m[1]);
|
|
43
|
+
if (names.length > 0) {
|
|
44
|
+
if (ids.length === names.length) {
|
|
45
|
+
return names.map((name, index) => `${name}(${ids[index]})`).join('、');
|
|
46
|
+
}
|
|
47
|
+
return names.join('、');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return raw;
|
|
51
|
+
}
|
|
52
|
+
/** 金额是「1,234.00」这类展示串,汇总前必须去千分位。 */
|
|
53
|
+
function toNumber(value) {
|
|
54
|
+
const text = cellText(value).replace(/,/gu, '').replace(/\s/gu, '');
|
|
55
|
+
if (!text || text === '-' || text === '—')
|
|
56
|
+
return 0;
|
|
57
|
+
const num = Number(text);
|
|
58
|
+
return Number.isFinite(num) ? num : 0;
|
|
59
|
+
}
|
|
60
|
+
function matchFilters(row, conditions) {
|
|
61
|
+
for (const cond of conditions) {
|
|
62
|
+
const at = cond.indexOf('=');
|
|
63
|
+
if (at <= 0)
|
|
64
|
+
continue;
|
|
65
|
+
const key = cond.slice(0, at).trim();
|
|
66
|
+
const want = cond.slice(at + 1);
|
|
67
|
+
if (!cellText(row[key]).includes(want))
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
function refsDirDefault() {
|
|
73
|
+
return join(homedir(), '.weaver-work-cli', 'state', 'refs');
|
|
74
|
+
}
|
|
75
|
+
/** refId 可能带后缀,先精确命中,再递归按前缀找。 */
|
|
76
|
+
function findRefFile(refsDir, refId) {
|
|
77
|
+
const direct = join(refsDir, `${refId}.json`);
|
|
78
|
+
if (existsSync(direct))
|
|
79
|
+
return direct;
|
|
80
|
+
const stack = [refsDir];
|
|
81
|
+
while (stack.length > 0) {
|
|
82
|
+
const dir = stack.pop();
|
|
83
|
+
let entries;
|
|
84
|
+
try {
|
|
85
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
const path = join(dir, entry.name);
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
stack.push(path);
|
|
94
|
+
}
|
|
95
|
+
else if (entry.name.startsWith(refId) && entry.name.endsWith('.json')) {
|
|
96
|
+
return path;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
/** refs 落盘结构是 { envelope: { data: { rows, pagination } } };顺序向下钻取。 */
|
|
103
|
+
function loadRows(path) {
|
|
104
|
+
const doc = readJsonFile(path);
|
|
105
|
+
let node = doc;
|
|
106
|
+
if (isRecord(node) && isRecord(node.envelope))
|
|
107
|
+
node = node.envelope;
|
|
108
|
+
if (isRecord(node) && isRecord(node.data))
|
|
109
|
+
node = node.data;
|
|
110
|
+
if (isRecord(node) && isRecord(node.result))
|
|
111
|
+
node = node.result;
|
|
112
|
+
const rawRows = isRecord(node)
|
|
113
|
+
? (Array.isArray(node.rows) ? node.rows : Array.isArray(node.displayData) ? node.displayData : [])
|
|
114
|
+
: [];
|
|
115
|
+
const rows = rawRows.filter(isRecord);
|
|
116
|
+
const pagination = isRecord(node) && isRecord(node.pagination) ? node.pagination : {};
|
|
117
|
+
return { rows, pagination };
|
|
118
|
+
}
|
|
119
|
+
function groupThousands(value) {
|
|
120
|
+
return value.toLocaleString('en-US', { maximumFractionDigits: 2, minimumFractionDigits: 2 });
|
|
121
|
+
}
|
|
122
|
+
// ---------------------------------------------------------------- 量级守卫常量
|
|
123
|
+
/** 单次取数硬上限:pageSize 最大 200 × maxPages 默认 10。 */
|
|
124
|
+
const PAGE_SIZE_MAX = 200;
|
|
125
|
+
const MAX_PAGES_DEFAULT = 10;
|
|
126
|
+
const SINGLE_CALL_CAP = PAGE_SIZE_MAX * MAX_PAGES_DEFAULT;
|
|
127
|
+
const WINDOW_LIMIT = 20_000;
|
|
128
|
+
const HARD_LIMIT = 100_000;
|
|
129
|
+
const CONTEXT_SAFE_KB = 50;
|
|
130
|
+
/** 台账 → 卡片信息(拒绝后兜底打开系统组件用,2026-11-13 实测口径)。 */
|
|
131
|
+
const MENU_CARDS = {
|
|
132
|
+
直销合同: { viewKey: 'ecology', variant: 'ledger', pageId: '846297265322576591' },
|
|
133
|
+
直销业绩: { viewKey: 'directPerf', variant: 'ledger', pageId: '846297265322576586' },
|
|
134
|
+
合同收款: { viewKey: null, variant: 'ebdf-list', pageId: '846297265322576589' },
|
|
135
|
+
项目验收: { viewKey: null, variant: 'ebdf-list', pageId: '846297265322576590' },
|
|
136
|
+
渠道订单: { viewKey: 'etOrder', variant: 'ledger', pageId: '881211097502359554' },
|
|
137
|
+
'渠道订单-商务': { viewKey: 'agree', variant: 'ledger', pageId: '1000604870446374992' },
|
|
138
|
+
};
|
|
139
|
+
const CONDITION_TYPES = ['none', 'time', 'person', 'customer', 'contract'];
|
|
140
|
+
function buildFallbackCard(menu, comParams, origin) {
|
|
141
|
+
const info = MENU_CARDS[menu];
|
|
142
|
+
if (!info) {
|
|
143
|
+
return {
|
|
144
|
+
available: false,
|
|
145
|
+
reason: `未知台账「${menu}」,请从六台账中选择:${Object.keys(MENU_CARDS).join('、')}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const args = { menu, title: `${menu} 台账` };
|
|
149
|
+
if (origin)
|
|
150
|
+
args.origin = origin;
|
|
151
|
+
let note = '打开后请在页面自行选择筛选条件查看数据。';
|
|
152
|
+
if (comParams) {
|
|
153
|
+
if (info.variant === 'ledger') {
|
|
154
|
+
args.comParamsJson = JSON.stringify(comParams);
|
|
155
|
+
note = '已预置筛选条件,打开即可看到对应范围;也可在页面继续调整。';
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
note =
|
|
159
|
+
'该台账为 ebdf 列表卡,预置条件必须用 field_<字段id>(传语义键会报 com_param_key_invalid),' +
|
|
160
|
+
'兜底场景不预置条件,请在页面自行筛选。';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
available: true,
|
|
165
|
+
variant: info.variant,
|
|
166
|
+
viewKey: info.viewKey,
|
|
167
|
+
pageId: info.pageId,
|
|
168
|
+
command: 'weaver-work-cli --json contract run contract.card.ebdf-list --input <args.json>',
|
|
169
|
+
args,
|
|
170
|
+
note,
|
|
171
|
+
usage: '把 args 写入 UTF-8 JSON 文件后执行上面 command,输出即 <browsertool> 卡片',
|
|
172
|
+
...(origin ? {} : { warning: '未取到当前环境域名,请补 origin 后再渲染卡片' }),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// ---------------------------------------------------------------- operations
|
|
176
|
+
export const contractLedgerOperations = [
|
|
177
|
+
{
|
|
178
|
+
name: 'contract.ledger.aggregate',
|
|
179
|
+
async execute(input) {
|
|
180
|
+
const single = typeof input.ref === 'string' && input.ref ? input.ref : null;
|
|
181
|
+
const many = Array.isArray(input.refs)
|
|
182
|
+
? input.refs.map((item, index) => {
|
|
183
|
+
if (typeof item !== 'string' || !item) {
|
|
184
|
+
throw contractValidationError('refs_invalid', `refs[${index}] 必须是非空字符串`);
|
|
185
|
+
}
|
|
186
|
+
return item;
|
|
187
|
+
})
|
|
188
|
+
: [];
|
|
189
|
+
const file = typeof input.file === 'string' && input.file ? input.file : null;
|
|
190
|
+
const refsDir = typeof input.refsDir === 'string' && input.refsDir ? input.refsDir : refsDirDefault();
|
|
191
|
+
const by = Array.isArray(input.by) ? input.by.map(String) : [];
|
|
192
|
+
const sum = Array.isArray(input.sum) ? input.sum.map(String) : [];
|
|
193
|
+
const where = Array.isArray(input.where) ? input.where.map(String) : [];
|
|
194
|
+
const dedupe = input.dedupe === true;
|
|
195
|
+
const detail = input.detail === true;
|
|
196
|
+
const limitRaw = input.limit;
|
|
197
|
+
const limit = typeof limitRaw === 'number' && Number.isFinite(limitRaw) && limitRaw > 0 ? Math.floor(limitRaw) : 20;
|
|
198
|
+
const sources = [];
|
|
199
|
+
if (file) {
|
|
200
|
+
if (!existsSync(file)) {
|
|
201
|
+
throw contractValidationError('file_not_found', `找不到结果文件:${file}`);
|
|
202
|
+
}
|
|
203
|
+
sources.push(file);
|
|
204
|
+
}
|
|
205
|
+
for (const refId of [...(single ? [single] : []), ...many]) {
|
|
206
|
+
const found = findRefFile(refsDir, refId);
|
|
207
|
+
if (!found) {
|
|
208
|
+
throw contractValidationError('ref_not_found', `找不到 refId 对应的结果文件:${refId}`);
|
|
209
|
+
}
|
|
210
|
+
sources.push(found);
|
|
211
|
+
}
|
|
212
|
+
if (sources.length === 0) {
|
|
213
|
+
throw contractValidationError('source_required', '请用 ref、refs 或 file 指定结果来源');
|
|
214
|
+
}
|
|
215
|
+
const allRows = [];
|
|
216
|
+
const seen = new Set();
|
|
217
|
+
const sourceInfo = [];
|
|
218
|
+
let totalSum = 0;
|
|
219
|
+
let totalUnknown = false;
|
|
220
|
+
let truncatedAny = false;
|
|
221
|
+
for (const path of sources) {
|
|
222
|
+
const { rows, pagination } = loadRows(path);
|
|
223
|
+
sourceInfo.push({
|
|
224
|
+
file: basename(path),
|
|
225
|
+
rows: rows.length,
|
|
226
|
+
total: pagination.total ?? null,
|
|
227
|
+
truncated: pagination.truncated === true,
|
|
228
|
+
});
|
|
229
|
+
if (pagination.total === null || pagination.total === undefined) {
|
|
230
|
+
totalUnknown = true;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
totalSum += Number(pagination.total) || 0;
|
|
234
|
+
}
|
|
235
|
+
if (pagination.truncated === true)
|
|
236
|
+
truncatedAny = true;
|
|
237
|
+
for (const row of rows) {
|
|
238
|
+
if (dedupe) {
|
|
239
|
+
let key = null;
|
|
240
|
+
for (const field of ['id', 'form_data_id', 'rowKey', 'ebrecord_rowkey']) {
|
|
241
|
+
const text = cellText(row[field]);
|
|
242
|
+
if (text) {
|
|
243
|
+
key = `${field}|${text}`;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (key) {
|
|
248
|
+
if (seen.has(key))
|
|
249
|
+
continue;
|
|
250
|
+
seen.add(key);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
allRows.push(row);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const rows = allRows.filter((row) => matchFilters(row, where));
|
|
257
|
+
const warnings = [];
|
|
258
|
+
if (truncatedAny) {
|
|
259
|
+
warnings.push('存在 truncated=true 的来源,当前不是全量;请缩小范围重查,或补齐分页后合并。');
|
|
260
|
+
}
|
|
261
|
+
if (!totalUnknown && !dedupe && totalSum !== allRows.length) {
|
|
262
|
+
warnings.push(`台账 total 合计 ${totalSum} 与载入行数 ${allRows.length} 不一致,结果可能不完整。`);
|
|
263
|
+
}
|
|
264
|
+
const data = {
|
|
265
|
+
sources: sourceInfo,
|
|
266
|
+
sourceCount: sources.length,
|
|
267
|
+
dedupe,
|
|
268
|
+
mergedRows: allRows.length,
|
|
269
|
+
totalSum: totalUnknown ? null : totalSum,
|
|
270
|
+
totalUnknown,
|
|
271
|
+
truncated: truncatedAny,
|
|
272
|
+
filteredRows: rows.length,
|
|
273
|
+
warnings,
|
|
274
|
+
};
|
|
275
|
+
if (rows.length > 0) {
|
|
276
|
+
if (by.length > 0) {
|
|
277
|
+
const groups = new Map();
|
|
278
|
+
for (const row of rows) {
|
|
279
|
+
const key = by.map((field) => cellText(row[field]) || '(空)').join(' / ');
|
|
280
|
+
const bucket = groups.get(key);
|
|
281
|
+
if (bucket)
|
|
282
|
+
bucket.push(row);
|
|
283
|
+
else
|
|
284
|
+
groups.set(key, [row]);
|
|
285
|
+
}
|
|
286
|
+
const groupList = [...groups.entries()]
|
|
287
|
+
.sort((a, b) => b[1].length - a[1].length)
|
|
288
|
+
.map(([key, items]) => {
|
|
289
|
+
const sums = {};
|
|
290
|
+
for (const field of sum) {
|
|
291
|
+
sums[field] = Number(items.reduce((acc, item) => acc + toNumber(item[field]), 0).toFixed(2));
|
|
292
|
+
}
|
|
293
|
+
return { key, rows: items.length, sums };
|
|
294
|
+
});
|
|
295
|
+
data.groups = groupList;
|
|
296
|
+
data.groupCount = groupList.length;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
const sums = {};
|
|
300
|
+
for (const field of sum) {
|
|
301
|
+
sums[field] = Number(rows.reduce((acc, row) => acc + toNumber(row[field]), 0).toFixed(2));
|
|
302
|
+
}
|
|
303
|
+
data.totals = { rows: rows.length, sums };
|
|
304
|
+
}
|
|
305
|
+
if (detail) {
|
|
306
|
+
data.detail = rows.slice(0, limit).map((row) => ({
|
|
307
|
+
qdrq: cellText(row.qdrq),
|
|
308
|
+
hth: cellText(row.hth),
|
|
309
|
+
khmc: cellText(row.khmc),
|
|
310
|
+
xsjl: cellText(row.xsjl),
|
|
311
|
+
htzje: cellText(row.htzje),
|
|
312
|
+
}));
|
|
313
|
+
data.detailLimit = limit;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return { status: 'COMPLETE', data };
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: 'contract.ledger.guard',
|
|
321
|
+
async execute(input, { host }) {
|
|
322
|
+
const menu = typeof input.menu === 'string' ? input.menu.trim() : '';
|
|
323
|
+
if (!menu) {
|
|
324
|
+
throw contractValidationError('menu_required', 'menu 必须是台账名称');
|
|
325
|
+
}
|
|
326
|
+
const totalRaw = input.total;
|
|
327
|
+
if (typeof totalRaw !== 'number' || !Number.isFinite(totalRaw) || totalRaw < 0) {
|
|
328
|
+
throw contractValidationError('total_invalid', 'total 必须是探量得到的非负整数');
|
|
329
|
+
}
|
|
330
|
+
const total = Math.floor(totalRaw);
|
|
331
|
+
const condition = typeof input.condition === 'string' ? input.condition : 'none';
|
|
332
|
+
if (!CONDITION_TYPES.includes(condition)) {
|
|
333
|
+
throw contractValidationError('condition_invalid', `condition 只能是 ${CONDITION_TYPES.join(' / ')}`);
|
|
334
|
+
}
|
|
335
|
+
const rowsKbRaw = input.rowsPerRecord;
|
|
336
|
+
const rowsKb = typeof rowsKbRaw === 'number' && Number.isFinite(rowsKbRaw) && rowsKbRaw > 0 ? rowsKbRaw : 3.3;
|
|
337
|
+
let comParams = null;
|
|
338
|
+
let rawParams = typeof input.comParams === 'string' ? input.comParams.trim() : '';
|
|
339
|
+
if (typeof input.comParams === 'object' && input.comParams !== null) {
|
|
340
|
+
comParams = input.comParams;
|
|
341
|
+
}
|
|
342
|
+
if (!rawParams && typeof input.comParamsFile === 'string' && input.comParamsFile) {
|
|
343
|
+
try {
|
|
344
|
+
rawParams = readFileSync(input.comParamsFile, 'utf8').replace(/^\uFEFF/u, '').trim();
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// 与脚本一致:读不到只忽略,不阻断判定
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (!comParams && rawParams) {
|
|
351
|
+
try {
|
|
352
|
+
const parsed = JSON.parse(rawParams);
|
|
353
|
+
if (isRecord(parsed))
|
|
354
|
+
comParams = parsed;
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
// 非合法 JSON 时忽略,避免拿错条件生成兜底卡
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
let origin = typeof input.origin === 'string' && input.origin ? input.origin : null;
|
|
361
|
+
if (!origin) {
|
|
362
|
+
try {
|
|
363
|
+
const session = await host.getSession();
|
|
364
|
+
origin = session.baseUrl ?? null;
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
origin = null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const estMb = Number(((total * rowsKb) / 1024).toFixed(2));
|
|
371
|
+
const capText = groupThousands(SINGLE_CALL_CAP);
|
|
372
|
+
let decision;
|
|
373
|
+
let reason;
|
|
374
|
+
let suggestion;
|
|
375
|
+
let batches = 1;
|
|
376
|
+
if (condition === 'none') {
|
|
377
|
+
decision = 'REFUSE';
|
|
378
|
+
reason =
|
|
379
|
+
`本次查询没有带任何约束条件。${menu} 台账无条件总量达 ${total.toLocaleString('en-US')} 条,` +
|
|
380
|
+
`预计输出约 ${estMb.toFixed(2)} MB,单次调用最多只能取回 ${SINGLE_CALL_CAP.toLocaleString('en-US')} 条,` +
|
|
381
|
+
'必然截断且耗时不可控。';
|
|
382
|
+
suggestion =
|
|
383
|
+
'请至少加一个约束后再查:①时间(如 2026-11);②人员(传人员 ID 做 inC);' +
|
|
384
|
+
'③客户名称;④具体合同号。建议先按月收窄,再把结果给我汇总。';
|
|
385
|
+
batches = null;
|
|
386
|
+
}
|
|
387
|
+
else if (total > HARD_LIMIT) {
|
|
388
|
+
decision = 'REFUSE';
|
|
389
|
+
reason =
|
|
390
|
+
`${menu} 命中 ${total.toLocaleString('en-US')} 条,超过可安全处理上限 ${HARD_LIMIT.toLocaleString('en-US')} 条` +
|
|
391
|
+
`(预计 ${estMb.toFixed(2)} MB)。即使拆窗口也会产生 ${Math.floor(total / SINGLE_CALL_CAP) + 1} 次以上的分页请求` +
|
|
392
|
+
'与超大中间结果,失败风险高、结果不可信。';
|
|
393
|
+
suggestion =
|
|
394
|
+
`请继续收窄到 ${HARD_LIMIT.toLocaleString('en-US')} 条以内:①把时间窗口缩到单月或单周;` +
|
|
395
|
+
'②叠加人员/客户条件;③若确实需要全量,请改为按批分次查询(每次一类条件),由您确认批次范围后再逐批执行。';
|
|
396
|
+
batches = null;
|
|
397
|
+
}
|
|
398
|
+
else if (total > SINGLE_CALL_CAP) {
|
|
399
|
+
decision = 'PROCEED_WITH_WINDOW';
|
|
400
|
+
batches = Math.ceil(total / SINGLE_CALL_CAP);
|
|
401
|
+
reason =
|
|
402
|
+
`${menu} 命中 ${total.toLocaleString('en-US')} 条,超过单次上限 ${capText} 条,` +
|
|
403
|
+
`需要拆成 ${batches} 个窗口分批取数(预计共 ${estMb.toFixed(2)} MB)。`;
|
|
404
|
+
suggestion =
|
|
405
|
+
`建议优先继续收窄(按月/周/人员/客户),把每批压到 ${capText} 条以内再执行;` +
|
|
406
|
+
'若坚持分批,我会逐批取数并用 refs + dedupe 合并后给结论。';
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
decision = 'PROCEED';
|
|
410
|
+
reason = `${menu} 命中 ${total.toLocaleString('en-US')} 条,在单次上限 ${capText} 条以内(预计 ${estMb.toFixed(2)} MB)。`;
|
|
411
|
+
suggestion = '可直接一次取全;返回前会校验 fetched == total 再报总数。';
|
|
412
|
+
}
|
|
413
|
+
const fallbackCard = decision === 'REFUSE' ? buildFallbackCard(menu, comParams, origin) : null;
|
|
414
|
+
return {
|
|
415
|
+
status: 'COMPLETE',
|
|
416
|
+
data: {
|
|
417
|
+
menu,
|
|
418
|
+
total,
|
|
419
|
+
condition,
|
|
420
|
+
decision,
|
|
421
|
+
reason,
|
|
422
|
+
suggestion,
|
|
423
|
+
batches,
|
|
424
|
+
estimatedMB: estMb,
|
|
425
|
+
thresholds: {
|
|
426
|
+
singleCallCap: SINGLE_CALL_CAP,
|
|
427
|
+
windowLimit: WINDOW_LIMIT,
|
|
428
|
+
hardLimit: HARD_LIMIT,
|
|
429
|
+
contextSafeKB: CONTEXT_SAFE_KB,
|
|
430
|
+
},
|
|
431
|
+
mustReportToUser: decision !== 'PROCEED',
|
|
432
|
+
fallbackCard,
|
|
433
|
+
note: '拒绝以 data.decision=REFUSE 表达,不再使用退出码 3(与「登录失效」冲突);本 operation 不访问业务接口。',
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
];
|
|
@@ -24,6 +24,58 @@ const EBDF_LIST_PAGE_IDS = {
|
|
|
24
24
|
'渠道订单-商务': '881211329321197671',
|
|
25
25
|
};
|
|
26
26
|
const NULL_OPS = new Set(['isNull', 'isNotNull']);
|
|
27
|
+
/**
|
|
28
|
+
* 台账页(`@weapp/contract` 的 LedgerPage)标签映射(2026-11-13 用户确认)。
|
|
29
|
+
*
|
|
30
|
+
* 只有这四个菜单在台账页有对应标签;「合同收款」「项目验收」没有标签,继续用 ebdf 列表卡。
|
|
31
|
+
* 渠道订单默认落 e-teams(etOrder),用户可在页面自行切到 e-office。
|
|
32
|
+
*/
|
|
33
|
+
const LEDGER_VIEW_KEYS = {
|
|
34
|
+
'直销合同': 'ecology',
|
|
35
|
+
'直销业绩': 'directPerf',
|
|
36
|
+
'渠道订单': 'etOrder',
|
|
37
|
+
'渠道订单-商务': 'agree',
|
|
38
|
+
};
|
|
39
|
+
/** catalog 字段中文名 → 台账 filters 键(来源:组件说明「默认筛选」)。 */
|
|
40
|
+
const LEDGER_FILTER_LABELS = {
|
|
41
|
+
ecology: {
|
|
42
|
+
'客户名称': 'khmc',
|
|
43
|
+
'合同编号': 'hth',
|
|
44
|
+
'合同号': 'hth',
|
|
45
|
+
'合同名称': 'htmc',
|
|
46
|
+
'签订时间': 'qdrq',
|
|
47
|
+
'合同总金额': 'htzje',
|
|
48
|
+
'销售类型': 'xslx',
|
|
49
|
+
'销售经理': 'xsjl2',
|
|
50
|
+
'大区': 'qy2',
|
|
51
|
+
'核算机构': 'hsjg',
|
|
52
|
+
},
|
|
53
|
+
directPerf: {
|
|
54
|
+
'合同号': 'hth',
|
|
55
|
+
'合同编号': 'hth',
|
|
56
|
+
'客户名称': 'khmc',
|
|
57
|
+
'核算业绩年月': 'yjny',
|
|
58
|
+
'销售经理': 'xsjl',
|
|
59
|
+
'团队负责人': 'tdfzr',
|
|
60
|
+
'机构负责人': 'jgfzr',
|
|
61
|
+
},
|
|
62
|
+
agree: {
|
|
63
|
+
'代理商名称': 'dls',
|
|
64
|
+
'协议编号': 'xyh',
|
|
65
|
+
'签约日期': 'qdrq',
|
|
66
|
+
'合同总金额': 'htzje',
|
|
67
|
+
'代理结束日期': 'sqjsrq',
|
|
68
|
+
},
|
|
69
|
+
etOrder: {
|
|
70
|
+
'客户名称': 'khmc',
|
|
71
|
+
'合同类型': 'htzl',
|
|
72
|
+
'区域': 'qy3',
|
|
73
|
+
'签订日期': 'qdrq',
|
|
74
|
+
'合同总金额': 'htzje',
|
|
75
|
+
'事业合伙人': 'syhhr',
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const LEDGER_ROUTE = '/sp/contract/ledger';
|
|
27
79
|
function catalog() {
|
|
28
80
|
return PERFORMANCE_CATALOG;
|
|
29
81
|
}
|
|
@@ -202,20 +254,69 @@ function buildQuery(menu, conditions, origin) {
|
|
|
202
254
|
if (!listPageId) {
|
|
203
255
|
throw contractValidationError('list_page_missing', `catalog 未记录「${menu.name}」的 ebdf 列表 pageId,无法组件化打开。`);
|
|
204
256
|
}
|
|
257
|
+
const viewKey = LEDGER_VIEW_KEYS[menu.name];
|
|
205
258
|
return {
|
|
206
259
|
menu: menu.name,
|
|
207
260
|
url,
|
|
208
261
|
filters,
|
|
209
262
|
needs_ui: needsUi,
|
|
210
263
|
warnings,
|
|
211
|
-
card:
|
|
264
|
+
card: viewKey
|
|
265
|
+
? buildLedgerCard(menu, origin, viewKey, filters)
|
|
266
|
+
: buildEbdfListCard(menu, origin, listPageId, filters),
|
|
212
267
|
page_verified: false,
|
|
213
268
|
execution: needsUi.length ? 'manual-page-filter' : 'filtered-link',
|
|
214
269
|
};
|
|
215
270
|
}
|
|
216
271
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
272
|
+
* 台账页组件卡:fill_form + e10 + @weapp/contract 的 LedgerPage。
|
|
273
|
+
* viewKey 决定第一次打开的标签;filters 第一层 key 就是 viewKey。
|
|
274
|
+
* 只映射台账页白名单内的字段,其余条件已进 needs_ui 交用户补填。
|
|
275
|
+
*/
|
|
276
|
+
function buildLedgerCard(menu, origin, viewKey, filters) {
|
|
277
|
+
const labelMap = LEDGER_FILTER_LABELS[viewKey] ?? {};
|
|
278
|
+
const inner = {};
|
|
279
|
+
for (const f of filters) {
|
|
280
|
+
const label = typeof f.field === 'string' ? f.field : '';
|
|
281
|
+
const key = labelMap[label];
|
|
282
|
+
if (!key)
|
|
283
|
+
continue;
|
|
284
|
+
const value = f.value;
|
|
285
|
+
if (Array.isArray(value)) {
|
|
286
|
+
if (value.length !== 2 || value.some((item) => typeof item !== 'string'))
|
|
287
|
+
continue;
|
|
288
|
+
inner[key] = [value[0], value[1]];
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (typeof value === 'string' && value !== '')
|
|
292
|
+
inner[key] = value;
|
|
293
|
+
}
|
|
294
|
+
const now = new Date();
|
|
295
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
296
|
+
const callId = `ledger-${menu.name}-${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}${pad(now.getHours())}${pad(now.getMinutes())}-01`;
|
|
297
|
+
return {
|
|
298
|
+
version: 1,
|
|
299
|
+
callId,
|
|
300
|
+
toolId: 'fill_form',
|
|
301
|
+
arguments: {
|
|
302
|
+
type: 'e10',
|
|
303
|
+
title: menu.name,
|
|
304
|
+
src: `${origin}${LEDGER_ROUTE}`,
|
|
305
|
+
width: 1300,
|
|
306
|
+
sdkRenderType: 'inline',
|
|
307
|
+
sdkOptions: {
|
|
308
|
+
compName: 'ui.CorsComponent',
|
|
309
|
+
routerType: 'MemoryRouter',
|
|
310
|
+
routerProps_pc: { initialEntries: [LEDGER_ROUTE] },
|
|
311
|
+
params_pc: { app: '@weapp/contract', compName: 'LedgerPage' },
|
|
312
|
+
params: { viewKey, filters: { [viewKey]: inner } },
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* 台账页没有标签的两个菜单(合同收款、项目验收)继续用 ebdf 列表页组件卡打开
|
|
319
|
+
* (fill_form + e10 + sdkOptions)。
|
|
219
320
|
* comParams 键必须是 field_<字段id>,值必须是字符串;无法序列化的条件留在 needs_ui 交用户补填。
|
|
220
321
|
*/
|
|
221
322
|
function buildEbdfListCard(menu, origin, listPageId, filters) {
|