weaver-work-cli 0.1.48 → 0.1.50
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/{archive-oa-EDJDU3V4.js → archive-oa-57R2FYHV.js} +111 -12
- package/dist/chunks/{attachment-content-4KSNBPRO.js → attachment-content-EJYIOJPH.js} +3 -3
- package/dist/chunks/{chunk-FEP6ELMR.js → chunk-3NCFFHB2.js} +1 -1
- package/dist/chunks/chunk-5QYE52LG.js +223 -0
- package/dist/chunks/{chunk-3YV7PKRL.js → chunk-6QYNE6HE.js} +12 -212
- package/dist/chunks/{chunk-NBEWUR7L.js → chunk-6T53BSWZ.js} +158 -44
- package/dist/chunks/{chunk-OCYRVZGN.js → chunk-7AYQJSFY.js} +2 -2
- package/dist/chunks/{chunk-5B5JXTY2.js → chunk-7ECB22G3.js} +221 -30
- package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
- package/dist/chunks/{chunk-WMSAWAWZ.js → chunk-BFKLQLBK.js} +8 -8
- package/dist/chunks/{chunk-EFOUMXIX.js → chunk-HARQF5IP.js} +28 -28
- package/dist/chunks/{chunk-O6CMPO65.js → chunk-IW7A2IQY.js} +16 -146
- package/dist/chunks/chunk-JEQHNNSS.js +158 -0
- package/dist/chunks/{chunk-NK74RE5F.js → chunk-K67FODVC.js} +3 -3
- package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
- package/dist/chunks/{chunk-BCACE6VV.js → chunk-MCZG6HPM.js} +3 -3
- package/dist/chunks/{chunk-SVFG6EMV.js → chunk-RYFRGTUV.js} +5 -5
- package/dist/chunks/{chunk-PSPOFLSU.js → chunk-WNJUGI2F.js} +1 -1
- package/dist/chunks/{chunk-R2HHLJNN.js → chunk-YB3AJYPY.js} +4 -4
- package/dist/chunks/{conflict-APGSD5E7.js → conflict-C4UDHCWV.js} +2 -2
- package/dist/chunks/{contract-N6P2HIIE.js → contract-VUC6JOPG.js} +464 -9
- package/dist/chunks/{create-flow-5TXFOC7X.js → create-flow-6OG2LYBD.js} +6 -6
- package/dist/chunks/data-QO7QWOIV.js +2525 -0
- package/dist/chunks/{employee-NOHNXC46.js → employee-DR5Y64TI.js} +2 -1
- package/dist/chunks/{env-B6GKA2J3.js → env-WP57TF2S.js} +2 -2
- package/dist/chunks/{factory-MFCKLUT6.js → factory-VUXI7N5C.js} +1 -1
- package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
- package/dist/chunks/{group-chat-YE7WIBFO.js → group-chat-UQRGXILK.js} +3 -3
- package/dist/chunks/{hrm-UNKCCCGP.js → hrm-YGIR3HGF.js} +4 -2
- package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
- package/dist/chunks/{invoice-FXWH5GPO.js → invoice-E7GOITEU.js} +1 -1
- package/dist/chunks/{meeting-RYZV2JTQ.js → meeting-4BBLVAWM.js} +10 -10
- package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
- package/dist/chunks/org-NFE7X7FK.js +12 -0
- package/dist/chunks/{reception-VL6TKVAW.js → reception-QGPNTGHG.js} +526 -175
- package/dist/chunks/{recruit-stage-ERZD3ZNB.js → recruit-stage-FKWS5UQF.js} +66 -13
- package/dist/chunks/{registry-VWXWPVAG.js → registry-3UGIWH53.js} +4 -2
- package/dist/chunks/{registry-22O6UG4I.js → registry-5CRCN2TV.js} +10 -10
- package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
- package/dist/chunks/{registry-7VZ6YJUF.js → registry-V4CHRQDI.js} +1 -1
- package/dist/chunks/{room-recommend-IMZPJMYB.js → room-recommend-AYR3UG7R.js} +4 -4
- package/dist/chunks/{schedule-SPPAHER2.js → schedule-JZEFIXUS.js} +4 -4
- package/dist/chunks/{workflow-WVEFJ6KC.js → workflow-3ZAF2J5E.js} +4 -4
- package/dist/index.js +16 -11
- package/dist/shortcuts/archive-oa/operations/contract-modules.js +57 -0
- package/dist/shortcuts/archive-oa/operations/contract.js +23 -8
- package/dist/shortcuts/archive-oa/operations/registry.js +4 -1
- package/dist/shortcuts/archive-oa/operations/shared.js +41 -5
- package/dist/shortcuts/contract/host.js +11 -0
- package/dist/shortcuts/contract/index.js +13 -0
- package/dist/shortcuts/contract/manifest.js +53 -0
- package/dist/shortcuts/contract/operations/performance.js +58 -7
- package/dist/shortcuts/contract/operations/quote.js +283 -1
- package/dist/shortcuts/contract/operations/registry.js +2 -0
- package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
- package/dist/shortcuts/data/errors.js +64 -0
- package/dist/shortcuts/data/host.js +140 -0
- package/dist/shortcuts/data/index.js +429 -0
- package/dist/shortcuts/data/manifest.js +133 -0
- package/dist/shortcuts/data/operations/attend.js +62 -0
- package/dist/shortcuts/data/operations/conf.js +384 -0
- package/dist/shortcuts/data/operations/ds.js +686 -0
- package/dist/shortcuts/data/operations/field.js +68 -0
- package/dist/shortcuts/data/operations/index.js +65 -0
- package/dist/shortcuts/data/operations/module.js +383 -0
- package/dist/shortcuts/data/operations/noun.js +102 -0
- package/dist/shortcuts/data/operations/query.js +85 -0
- package/dist/shortcuts/data/operations/scene.js +235 -0
- package/dist/shortcuts/data/operations/shared.js +279 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/interview-arrange.js +12 -5
- package/dist/shortcuts/ehr/recruit-stage/operations/resume-import.js +21 -13
- package/dist/shortcuts/ehr/recruit-stage/shared.js +57 -0
- package/dist/shortcuts/fna/host.js +4 -2
- package/dist/shortcuts/fna/manifest.js +14 -5
- package/dist/shortcuts/fna/operations/audit.js +334 -0
- package/dist/shortcuts/fna/operations/registry.js +2 -0
- package/dist/shortcuts/im/operations/at-mention.js +6 -3
- package/dist/shortcuts/im/operations/msg-parse.js +35 -5
- package/dist/shortcuts/im/operations/msg-sync.js +3 -1
- package/dist/shortcuts/im/operations/msg-write.js +57 -9
- package/dist/shortcuts/index.js +5 -0
- package/dist/shortcuts/invoice/manifest.js +1 -1
- package/dist/shortcuts/meeting/operations/eb/member-expand.js +200 -0
- package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
- package/dist/shortcuts/meeting/operations/registry.js +2 -0
- package/dist/shortcuts/reception/constants.js +13 -6
- package/dist/shortcuts/reception/index.js +3 -1
- package/dist/shortcuts/reception/manifest.js +3 -2
- package/dist/shortcuts/reception/operations/ask.js +20 -2
- package/dist/shortcuts/reception/operations/compose.js +11 -0
- package/dist/shortcuts/reception/operations/doc.js +59 -0
- package/dist/shortcuts/reception/operations/docrender.js +25 -1
- package/dist/shortcuts/reception/operations/leads.js +31 -7
- package/dist/shortcuts/reception/operations/panels.js +86 -22
- package/dist/shortcuts/reception/operations/render.js +40 -0
- package/dist/shortcuts/reception/operations/restaurant.js +17 -4
- package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +12 -5
- package/dist/shortcuts/recruit-stage/operations/resume-import.js +21 -13
- package/dist/shortcuts/recruit-stage/shared.js +57 -0
- package/dist/shortcuts/workflow/operations/read.js +58 -14
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +140 -24
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +42 -14
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +4 -6
- package/docs/SKILL.md +2 -1
- package/docs/_catalog.md +4 -1
- package/docs/data.md +149 -0
- package/docs/fna.md +11 -4
- package/docs/reception.md +59 -5
- package/package.json +1 -1
- package/scripts/check-skill-sync.mjs +188 -0
- package/scripts/package-skill.mjs +17 -3
- package/skill-template/business-info.json +29 -1
- package/skill-template/domains/data.md +15 -0
- package/skill-template/domains/qiyecheng.md +4 -2
- package/skills/weaver-e10-archive-oa/SKILL.md +7 -6
- package/skills/weaver-e10-archive-oa/references/contract-search.md +83 -14
- package/skills/weaver-e10-archive-oa/references/disabled-capabilities.md +1 -1
- package/skills/weaver-e10-archive-oa/references/qys-contract-search.md +35 -11
- package/skills/weaver-e10-data/SKILL.md +118 -0
- package/skills/weaver-e10-data/references/config-center.md +90 -0
- package/skills/weaver-e10-data/references/datasource.md +136 -0
- package/skills/weaver-e10-data/references/scene-and-misc.md +82 -0
- package/skills/weaver-e10-jinchengda/SKILL.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -5
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +44 -2
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +219 -0
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +50 -30
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +24 -15
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +43 -0
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
- package/skills/weaver-e10-jinchengda/scripts/render_ebdf_list_card.py +265 -0
- package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +83 -0
- package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
- package/skills/weaver-e10-meeting/SKILL.md +39 -7
- package/skills/weaver-e10-qiyecheng/SKILL.md +21 -7
- package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +104 -0
- package/skills/weaver-e10-qiyecheng/references/catalog.md +17 -3
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +136 -30
- package/skills/weaver-e10-reception-flow/SKILL.md +70 -19
- package/skills/weaver-e10-reception-flow/references/guide.md +5 -4
- package/skills/weaver-e10-reception-flow/scripts/render.py +5 -3
- package/skills/weaver-e10-recruit-stage/SKILL.md +1 -1
- package/skills/weaver-e10-recruit-stage/agents/openai.yaml +26 -6
- package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +3 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +6 -4
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +3 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +53 -11
- package/skills/weaver-e10-workflow/SKILL.md +2 -1
- package/skills/weaver-e10-workflow/references/todo-smart-convert.md +29 -6
- package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
- package/skills/weaver-e10-yepiaotong/SKILL.md +10 -5
- package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
- package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +6 -45
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +5 -5
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +4 -37
- package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +2 -2
- package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +4 -4
- package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +22 -35
- package/skills/weaver-e10-yimiaoban/SKILL.md +8 -6
- package/skills/weaver-e10-yimiaoban/references/msg-read.md +20 -0
- package/skills/weaver-e10-yimiaoban/references/msg-write.md +7 -0
- package/skills/weaver-e10-yimiaoban/references/source-manifest.json +18 -15
- package/dist/chunks/{ebuilder-form-I5ZIX4WO.js → ebuilder-form-CBYI6CQ6.js} +4 -4
|
@@ -488,6 +488,22 @@ const quoteContracts = [
|
|
|
488
488
|
includeZero: { type: 'boolean' },
|
|
489
489
|
}, ['path']),
|
|
490
490
|
},
|
|
491
|
+
{
|
|
492
|
+
name: 'contract.quote.extract',
|
|
493
|
+
risk: 'read-with-upload',
|
|
494
|
+
fixed: { local: true, kind: 'docx-extract' },
|
|
495
|
+
inputSchema: readSchema({
|
|
496
|
+
path: { type: 'string', minLength: 1 },
|
|
497
|
+
}, ['path']),
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: 'contract.quote.normalize',
|
|
501
|
+
risk: 'read',
|
|
502
|
+
fixed: { local: true, kind: 'quote-normalize' },
|
|
503
|
+
inputSchema: readSchema({
|
|
504
|
+
data: { type: 'string', minLength: 1 },
|
|
505
|
+
}, ['data']),
|
|
506
|
+
},
|
|
491
507
|
{
|
|
492
508
|
name: 'contract.quote.fill',
|
|
493
509
|
risk: 'read-with-upload',
|
|
@@ -1181,6 +1197,43 @@ export const contractOperations = [
|
|
|
1181
1197
|
path: { type: 'string', minLength: 1, maxLength: 1000 },
|
|
1182
1198
|
}, ['flow', 'path']),
|
|
1183
1199
|
},
|
|
1200
|
+
{
|
|
1201
|
+
name: 'contract.flow.save-recognize-record',
|
|
1202
|
+
risk: 'write',
|
|
1203
|
+
auth: AUTH,
|
|
1204
|
+
fixed: {
|
|
1205
|
+
method: 'POST',
|
|
1206
|
+
path: '/api/ai/application/smartfill/data/saveRecognizeRecord',
|
|
1207
|
+
note: '要素抽取结果先存成识别记录,返回的 aiExtraId 再随 customParams 传给流程组件',
|
|
1208
|
+
},
|
|
1209
|
+
inputSchema: readSchema({
|
|
1210
|
+
flow: {
|
|
1211
|
+
type: 'string',
|
|
1212
|
+
maxLength: 64,
|
|
1213
|
+
description: '可选流程预设(契约锁 / 新客户 / 老客户增值 / 常规二次销售);也可传自定义流程名,此时必须同时给 workflowId',
|
|
1214
|
+
},
|
|
1215
|
+
recognizeResult: {
|
|
1216
|
+
description: '识别结果;传 JSON 对象或其字符串均可,CLI 统一序列化为字符串',
|
|
1217
|
+
anyOf: [{ type: 'string' }, { type: 'object' }],
|
|
1218
|
+
},
|
|
1219
|
+
attachmentIds: { type: 'string', maxLength: 4000, description: '本次全部附件 ID,英文逗号分隔' },
|
|
1220
|
+
attachmentFieldId: {
|
|
1221
|
+
type: 'string',
|
|
1222
|
+
pattern: '^[1-9]\\d*$',
|
|
1223
|
+
description: '合同文件字段 ID(取自该流程表单字段定义);传入后该字段与文件 ID 会一起写进 customParams,由流程组件回填附件',
|
|
1224
|
+
},
|
|
1225
|
+
attachmentFileId: {
|
|
1226
|
+
type: 'string',
|
|
1227
|
+
maxLength: 64,
|
|
1228
|
+
description: '合同文件的 fileId;不传时取 attachmentIds 的首个文件',
|
|
1229
|
+
},
|
|
1230
|
+
workflowId: {
|
|
1231
|
+
type: 'string',
|
|
1232
|
+
pattern: '^[1-9]\\d*$',
|
|
1233
|
+
description: '流程模板 ID;不传时取 flow 的预设 workflowId。与 flow 至少传一个',
|
|
1234
|
+
},
|
|
1235
|
+
}, ['recognizeResult']),
|
|
1236
|
+
},
|
|
1184
1237
|
{
|
|
1185
1238
|
name: 'contract.recommend.doc',
|
|
1186
1239
|
risk: 'read',
|
|
@@ -11,7 +11,18 @@ import { PERFORMANCE_CATALOG, CONTRACT_SOURCES, } from '../data/performance-cata
|
|
|
11
11
|
import { contractValidationError } from '../errors.js';
|
|
12
12
|
import { requireNonEmptyString } from './shared.js';
|
|
13
13
|
const ORIGIN_PLACEHOLDER = '{baseUrl}';
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 六菜单对应的 ebdf 列表页 pageId(2026-11-10 用户确认)。
|
|
16
|
+
* catalog 的 list_id 与部署环境可能错位(「渠道订单-商务」实测不同),这里以确认值覆盖。
|
|
17
|
+
*/
|
|
18
|
+
const EBDF_LIST_PAGE_IDS = {
|
|
19
|
+
'直销合同': '881124906081886244',
|
|
20
|
+
'直销业绩': '846297265322576586',
|
|
21
|
+
'合同收款': '846297265322576589',
|
|
22
|
+
'项目验收': '846297265322576590',
|
|
23
|
+
'渠道订单': '881210951456350225',
|
|
24
|
+
'渠道订单-商务': '881211329321197671',
|
|
25
|
+
};
|
|
15
26
|
const NULL_OPS = new Set(['isNull', 'isNotNull']);
|
|
16
27
|
function catalog() {
|
|
17
28
|
return PERFORMANCE_CATALOG;
|
|
@@ -187,22 +198,62 @@ function buildQuery(menu, conditions, origin) {
|
|
|
187
198
|
warnings.push(`页面可能默认限制${defaultTime}为当年。请用户核对实际范围;要求全部年份/其他时间口径时,由用户清空默认年月再搜索。`);
|
|
188
199
|
}
|
|
189
200
|
const url = origin + route + '?' + params.map(([k, v]) => `${encodeURIComponent0(k)}=${encodeURIComponent0(v)}`).join('&');
|
|
201
|
+
const listPageId = EBDF_LIST_PAGE_IDS[menu.name] ?? menu.list_id;
|
|
202
|
+
if (!listPageId) {
|
|
203
|
+
throw contractValidationError('list_page_missing', `catalog 未记录「${menu.name}」的 ebdf 列表 pageId,无法组件化打开。`);
|
|
204
|
+
}
|
|
190
205
|
return {
|
|
191
206
|
menu: menu.name,
|
|
192
207
|
url,
|
|
193
208
|
filters,
|
|
194
209
|
needs_ui: needsUi,
|
|
195
210
|
warnings,
|
|
196
|
-
|
|
197
|
-
version: '1.0',
|
|
198
|
-
callId: 'performance-query-1',
|
|
199
|
-
toolId: 'open_web',
|
|
200
|
-
arguments: { url, title: menu.name, activate: true, width: BROWSER_WIDTH },
|
|
201
|
-
},
|
|
211
|
+
card: buildEbdfListCard(menu, origin, listPageId, filters),
|
|
202
212
|
page_verified: false,
|
|
203
213
|
execution: needsUi.length ? 'manual-page-filter' : 'filtered-link',
|
|
204
214
|
};
|
|
205
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* 六菜单统一用 ebdf 列表页组件卡打开(fill_form + e10 + sdkOptions)。
|
|
218
|
+
* 原 open_web 落在宿主工作区视图,拿不到 E10 列表组件,已废弃。
|
|
219
|
+
* comParams 键必须是 field_<字段id>,值必须是字符串;无法序列化的条件留在 needs_ui 交用户补填。
|
|
220
|
+
*/
|
|
221
|
+
function buildEbdfListCard(menu, origin, listPageId, filters) {
|
|
222
|
+
const comParams = {};
|
|
223
|
+
for (const f of filters) {
|
|
224
|
+
const key = typeof f.key === 'string' ? f.key : '';
|
|
225
|
+
const value = f.value;
|
|
226
|
+
if (!/^field_\d+$/u.test(key))
|
|
227
|
+
continue;
|
|
228
|
+
if (typeof value !== 'string' || value === '')
|
|
229
|
+
continue;
|
|
230
|
+
comParams[key] = value;
|
|
231
|
+
}
|
|
232
|
+
const now = new Date();
|
|
233
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
234
|
+
const callId = `ebdf-list-${menu.name}-${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}${pad(now.getHours())}${pad(now.getMinutes())}-01`;
|
|
235
|
+
const path = `/list/${listPageId}`;
|
|
236
|
+
return {
|
|
237
|
+
version: 1,
|
|
238
|
+
callId,
|
|
239
|
+
toolId: 'fill_form',
|
|
240
|
+
arguments: {
|
|
241
|
+
type: 'e10',
|
|
242
|
+
title: menu.name,
|
|
243
|
+
src: `${origin}/sp/ebdfpage/list/${listPageId}`,
|
|
244
|
+
sdkRenderType: 'inline',
|
|
245
|
+
sdkOptions: {
|
|
246
|
+
compName: 'ui.CorsComponent',
|
|
247
|
+
routerType: 'MemoryRouter',
|
|
248
|
+
routerProps_pc: { initialEntries: [path] },
|
|
249
|
+
routerProps_mobile: { initialEntries: [path] },
|
|
250
|
+
params_pc: { app: '@weapp/ebdfpage', compName: 'TableViewList', noMDialog: true },
|
|
251
|
+
params_mobile: { app: '@weapp/ebdfpage', compName: 'MTableViewList', noMDialog: true },
|
|
252
|
+
params: { pageId: listPageId, comParams },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
206
257
|
function requireOrigin(input) {
|
|
207
258
|
const raw = String(input.origin ?? '').trim();
|
|
208
259
|
if (!raw) {
|
|
@@ -15,6 +15,7 @@ import { contractValidationError } from '../errors.js';
|
|
|
15
15
|
import { requireNonEmptyString } from './shared.js';
|
|
16
16
|
import { listSheetNames, readGrid } from '../ooxml/xlsx.js';
|
|
17
17
|
import { fillDocx, labelBefore } from '../ooxml/docx.js';
|
|
18
|
+
import { readZipEntry } from '../ooxml/zip.js';
|
|
18
19
|
// ---------------------------------------------------------------- 人民币大写
|
|
19
20
|
const DIGITS = '零壹贰叁肆伍陆柒捌玖';
|
|
20
21
|
const UNITS = ['', '拾', '佰', '仟'];
|
|
@@ -278,6 +279,8 @@ export function parseQuote(buffer, sheetName, keepRemark = false, includeZero =
|
|
|
278
279
|
checks.push({ section: `${s.code}、${s.title}`, sheet_total: s.total, sum_items: s.sum_items, diff: s.sum_items - s.total });
|
|
279
280
|
}
|
|
280
281
|
}
|
|
282
|
+
// 费用总表本身是各明细的汇总,若再累加会与合计额重复计算(实测差额等于合计值),
|
|
283
|
+
// 因此它只用于提供 standard_total / final_total,不参与明细求和。
|
|
281
284
|
const grand = sections.reduce((acc, s) => acc + (s.sum_items ?? 0), 0);
|
|
282
285
|
totals.sum_items_grand = grand;
|
|
283
286
|
const standard = totals.standard_total;
|
|
@@ -299,6 +302,207 @@ export function parseQuote(buffer, sheetName, keepRemark = false, includeZero =
|
|
|
299
302
|
warnings.push('报价单未填写『客户名称』,签约主体必须由用户提供');
|
|
300
303
|
return { source_sheet: sheet, available_sheets: names, meta, totals, sections, checks, warnings };
|
|
301
304
|
}
|
|
305
|
+
// ---------------------------------------------------------------- docx 报价书解析
|
|
306
|
+
/**
|
|
307
|
+
* Word 版报价书解析(2026-11-09 补充)。
|
|
308
|
+
*
|
|
309
|
+
* 背景:`contract.quote.parse` 原先只认 .xlsx,客户实际提交的报价书多为 .docx,
|
|
310
|
+
* 只能报错或让用户手工转格式。本文按「表头识别」而非固定表序解析,兼容
|
|
311
|
+
* 软件功能费用 / 用户授权许可 / 实施服务费用 / 费用总表四类常见表。
|
|
312
|
+
*/
|
|
313
|
+
function decodeXmlEntities(s) {
|
|
314
|
+
return s
|
|
315
|
+
.replace(/</gu, '<')
|
|
316
|
+
.replace(/>/gu, '>')
|
|
317
|
+
.replace(/"/gu, '"')
|
|
318
|
+
.replace(/'/gu, "'")
|
|
319
|
+
.replace(/&/gu, '&');
|
|
320
|
+
}
|
|
321
|
+
/** 取单元格纯文本:只认 <w:t> / <w:t xml:space="preserve">,不能写成 <w:t[^>]*>(会吞掉 <w:tcPr>)。 */
|
|
322
|
+
function cellText(fragment) {
|
|
323
|
+
const re = /<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>/gu;
|
|
324
|
+
const out = [];
|
|
325
|
+
let m;
|
|
326
|
+
while ((m = re.exec(fragment)) !== null)
|
|
327
|
+
out.push(m[1] ?? '');
|
|
328
|
+
return decodeXmlEntities(out.join('')).replace(/\s+/gu, ' ').trim();
|
|
329
|
+
}
|
|
330
|
+
/** 从 document.xml 提取全部表格为「行 → 单元格文本」二维数组。 */
|
|
331
|
+
export function readDocxTablesFromXml(xml) {
|
|
332
|
+
const tables = [];
|
|
333
|
+
const tblRe = /<w:tbl>[\s\S]*?<\/w:tbl>/gu;
|
|
334
|
+
let tm;
|
|
335
|
+
while ((tm = tblRe.exec(xml)) !== null) {
|
|
336
|
+
const rows = [];
|
|
337
|
+
const trRe = /<w:tr[ >][\s\S]*?<\/w:tr>/gu;
|
|
338
|
+
let rm;
|
|
339
|
+
while ((rm = trRe.exec(tm[0])) !== null) {
|
|
340
|
+
const cells = [];
|
|
341
|
+
const tcRe = /<w:tc>[\s\S]*?<\/w:tc>/gu;
|
|
342
|
+
let cm;
|
|
343
|
+
while ((cm = tcRe.exec(rm[0])) !== null)
|
|
344
|
+
cells.push(cellText(cm[0]));
|
|
345
|
+
rows.push(cells);
|
|
346
|
+
}
|
|
347
|
+
if (rows.length)
|
|
348
|
+
tables.push(rows);
|
|
349
|
+
}
|
|
350
|
+
return tables;
|
|
351
|
+
}
|
|
352
|
+
/** 表格以外的段落文本(用于客户名、有效期、备注)。 */
|
|
353
|
+
function docxParagraphs(xml) {
|
|
354
|
+
const noTbl = xml.replace(/<w:tbl>[\s\S]*?<\/w:tbl>/gu, '');
|
|
355
|
+
const re = /<w:p[ >][\s\S]*?<\/w:p>/gu;
|
|
356
|
+
const out = [];
|
|
357
|
+
let m;
|
|
358
|
+
while ((m = re.exec(noTbl)) !== null) {
|
|
359
|
+
const t = cellText(m[0]);
|
|
360
|
+
if (t)
|
|
361
|
+
out.push(t);
|
|
362
|
+
}
|
|
363
|
+
return out;
|
|
364
|
+
}
|
|
365
|
+
function numLoose(s) {
|
|
366
|
+
const t = (s ?? '').replace(/,/gu, '');
|
|
367
|
+
const m = /(-?\d+(?:\.\d+)?)/u.exec(t);
|
|
368
|
+
if (!m)
|
|
369
|
+
return null;
|
|
370
|
+
const v = Number(m[1]);
|
|
371
|
+
return Number.isFinite(v) ? v : null;
|
|
372
|
+
}
|
|
373
|
+
/** 把 Word 报价书无损提取为「表格二维数组 + 段落文本」,不做任何语义判断。 */
|
|
374
|
+
export function extractQuoteDocx(buffer) {
|
|
375
|
+
const xml = readZipEntry(buffer, 'word/document.xml');
|
|
376
|
+
if (!xml) {
|
|
377
|
+
throw contractValidationError('docx_invalid', 'Word 文件缺少 word/document.xml,可能不是合法的 .docx。');
|
|
378
|
+
}
|
|
379
|
+
const tables = readDocxTablesFromXml(xml);
|
|
380
|
+
const paragraphs = docxParagraphs(xml);
|
|
381
|
+
return {
|
|
382
|
+
kind: 'docx',
|
|
383
|
+
tables: tables.map((rows, index) => ({ index, rows })),
|
|
384
|
+
paragraphs,
|
|
385
|
+
counts: { tables: tables.length, paragraphs: paragraphs.length },
|
|
386
|
+
note: '已按原样提取表格与段落,未做语义判断。请由模型理解后产出 ParsedQuote 结构' +
|
|
387
|
+
'(meta.customer/title/validity/tax,sections[].title/items[].name/price/qty/amount/total,' +
|
|
388
|
+
'汇总表所在 section 需标 is_summary=true),再调用 contract.quote.normalize 做校验。',
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function asNumber(v) {
|
|
392
|
+
if (v === null || v === undefined || v === '')
|
|
393
|
+
return null;
|
|
394
|
+
if (typeof v === 'number')
|
|
395
|
+
return Number.isFinite(v) ? v : null;
|
|
396
|
+
return numLoose(String(v));
|
|
397
|
+
}
|
|
398
|
+
function asText(v) {
|
|
399
|
+
return typeof v === 'string' ? v.replace(/\s+/gu, ' ').trim() : v === null || v === undefined ? '' : String(v);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* 校验并归一化模型给出的报价结构。
|
|
403
|
+
*
|
|
404
|
+
* 职责边界:**只验不算语义**——不猜哪张表是什么,只检查模型给的结构是否自洽:
|
|
405
|
+
* - sections 不能为空,items 必须是数组
|
|
406
|
+
* - 金额字段统一转成 number,缺失按 price × qty 补齐
|
|
407
|
+
* - 逐节重算 sum_items 并与 total 比对;汇总表(is_summary)不参与总计
|
|
408
|
+
* - 明细求和与合计额不一致时写入 warnings,供上游决定是否需要人工核对
|
|
409
|
+
*/
|
|
410
|
+
export function normalizeParsedQuote(input) {
|
|
411
|
+
const rawSections = Array.isArray(input.sections) ? input.sections : [];
|
|
412
|
+
if (rawSections.length === 0) {
|
|
413
|
+
throw contractValidationError('quote_normalize_invalid', 'sections 为空:模型必须给出至少一节费用明细(含 title 与 items)。');
|
|
414
|
+
}
|
|
415
|
+
const sections = [];
|
|
416
|
+
const checks = [];
|
|
417
|
+
const summaryCodes = new Set();
|
|
418
|
+
let seq = 0;
|
|
419
|
+
for (const s of rawSections) {
|
|
420
|
+
seq += 1;
|
|
421
|
+
const code = asText(s.code) || `S${seq}`;
|
|
422
|
+
const title = asText(s.title) || `第 ${seq} 节`;
|
|
423
|
+
const rawItems = Array.isArray(s.items) ? s.items : [];
|
|
424
|
+
const items = [];
|
|
425
|
+
for (const it of rawItems) {
|
|
426
|
+
const name = asText(it.name);
|
|
427
|
+
const price = asNumber(it.price);
|
|
428
|
+
const qty = asNumber(it.qty);
|
|
429
|
+
let amount = asNumber(it.amount);
|
|
430
|
+
if (amount === null && price !== null)
|
|
431
|
+
amount = price * (qty ?? 1);
|
|
432
|
+
if (!name && amount === null)
|
|
433
|
+
continue;
|
|
434
|
+
items.push({
|
|
435
|
+
no: asText(it.no),
|
|
436
|
+
name,
|
|
437
|
+
way: asText(it.way),
|
|
438
|
+
desc: asText(it.desc),
|
|
439
|
+
price,
|
|
440
|
+
qty,
|
|
441
|
+
amount,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
const total = asNumber(s.total);
|
|
445
|
+
const section = { code, title, items, total };
|
|
446
|
+
section.sum_items = items.reduce((acc, i) => acc + (Number(i.amount) || 0), 0);
|
|
447
|
+
sections.push(section);
|
|
448
|
+
if (s.is_summary)
|
|
449
|
+
summaryCodes.add(code);
|
|
450
|
+
if (total !== null && section.sum_items !== total) {
|
|
451
|
+
checks.push({
|
|
452
|
+
section: `${code}、${title}`,
|
|
453
|
+
table_total: total,
|
|
454
|
+
sum_items: section.sum_items,
|
|
455
|
+
diff: section.sum_items - total,
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const totalIn = (input.totals ?? {});
|
|
460
|
+
const standard = asNumber(totalIn.standard_total) ?? asNumber(totalIn.final_total) ?? undefined;
|
|
461
|
+
// 汇总表只提供合计额,不参与明细求和;否则会与合计重复计算
|
|
462
|
+
const grand = sections
|
|
463
|
+
.filter((s) => !summaryCodes.has(s.code))
|
|
464
|
+
.reduce((acc, s) => acc + (s.sum_items ?? 0), 0);
|
|
465
|
+
const totals = {
|
|
466
|
+
standard_total: standard ?? null,
|
|
467
|
+
final_total: asNumber(totalIn.final_total) ?? standard ?? null,
|
|
468
|
+
sum_items_grand: grand,
|
|
469
|
+
has_mismatch: false,
|
|
470
|
+
diff_vs_standard: standard === undefined ? null : grand - standard,
|
|
471
|
+
};
|
|
472
|
+
if (totalIn.discount !== undefined)
|
|
473
|
+
totals.discount = totalIn.discount;
|
|
474
|
+
totals.has_mismatch = checks.length > 0 || (standard !== undefined && grand !== standard);
|
|
475
|
+
const warnings = Array.isArray(input.warnings) ? input.warnings.map(asText).filter(Boolean) : [];
|
|
476
|
+
if (checks.length) {
|
|
477
|
+
warnings.push('分节明细求和与所给合计不一致,请与报价人核对:' +
|
|
478
|
+
checks
|
|
479
|
+
.map((c) => `${String(c.section)} 合计${String(c.table_total)}/明细${String(c.sum_items)}`)
|
|
480
|
+
.join(';'));
|
|
481
|
+
}
|
|
482
|
+
if (totals.diff_vs_standard) {
|
|
483
|
+
warnings.push(`全部明细求和 ${grand} 与合计额 ${String(standard)} 不一致,差额 ${String(totals.diff_vs_standard)};` +
|
|
484
|
+
'可能存在没有独立明细表的分项,请核对。');
|
|
485
|
+
}
|
|
486
|
+
const metaRaw = (input.meta ?? {});
|
|
487
|
+
const meta = {};
|
|
488
|
+
for (const [k, v] of Object.entries(metaRaw)) {
|
|
489
|
+
const t = asText(v);
|
|
490
|
+
if (t)
|
|
491
|
+
meta[k] = t;
|
|
492
|
+
}
|
|
493
|
+
if (!meta.customer)
|
|
494
|
+
warnings.push('报价书未给出客户名称,签约主体必须由用户提供');
|
|
495
|
+
return {
|
|
496
|
+
source_sheet: 'docx',
|
|
497
|
+
available_sheets: ['正文'],
|
|
498
|
+
meta,
|
|
499
|
+
totals,
|
|
500
|
+
sections,
|
|
501
|
+
checks,
|
|
502
|
+
warnings,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
// ----------------------------------------------------------------
|
|
302
506
|
// ---------------------------------------------------------------- docx 填充(字段打分)
|
|
303
507
|
const FIELD_ALIASES = {
|
|
304
508
|
party_a: ['甲方', '买方', '客户名称', '客户', '采购方', '需方', '购货方', '甲方名称', '买方名称'],
|
|
@@ -450,10 +654,70 @@ export const contractQuoteOperations = [
|
|
|
450
654
|
},
|
|
451
655
|
async execute(input) {
|
|
452
656
|
const path = resolve(String(input.path));
|
|
657
|
+
// 2026-11-09 用户定稿:报价书格式无法穷举,语义映射交给模型。
|
|
658
|
+
// .docx 到 parse 只做无损提取并明确提示走模型链路,不再由代码猜表头含义。
|
|
659
|
+
if (/\.docx$/iu.test(path)) {
|
|
660
|
+
const extracted = extractQuoteDocx(readFileSync(path));
|
|
661
|
+
return {
|
|
662
|
+
status: 'DONE',
|
|
663
|
+
data: {
|
|
664
|
+
...extracted,
|
|
665
|
+
next_step: 'Word 报价书已无损提取。请模型理解表格与段落语义后产出 meta/sections(汇总表标 is_summary=true),' +
|
|
666
|
+
'再调用 contract.quote.normalize 校验金额与结构。代码不再做表头语义映射。',
|
|
667
|
+
},
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
if (!/\.xlsx$/iu.test(path)) {
|
|
671
|
+
throw contractValidationError('file_type_unsupported', '报价单只支持 .xlsx 或 .docx;.xls / .doc 老格式请先另存为新格式。');
|
|
672
|
+
}
|
|
453
673
|
const parsed = parseQuote(readFileSync(path), input.sheet ? String(input.sheet) : null, Boolean(input.keepRemark), Boolean(input.includeZero));
|
|
454
674
|
return { status: 'DONE', data: parsed };
|
|
455
675
|
},
|
|
456
676
|
},
|
|
677
|
+
{
|
|
678
|
+
name: 'contract.quote.extract',
|
|
679
|
+
risk: 'read-with-upload',
|
|
680
|
+
inputSchema: {
|
|
681
|
+
type: 'object',
|
|
682
|
+
additionalProperties: false,
|
|
683
|
+
properties: {
|
|
684
|
+
path: { type: 'string', description: '.docx 报价书路径' },
|
|
685
|
+
},
|
|
686
|
+
required: ['path'],
|
|
687
|
+
},
|
|
688
|
+
async execute(input) {
|
|
689
|
+
const path = resolve(String(input.path));
|
|
690
|
+
if (!/\.docx$/iu.test(path)) {
|
|
691
|
+
throw contractValidationError('file_type_unsupported', '无损提取只针对 .docx 报价书;.xlsx 结构规整,请直接用 contract.quote.parse。');
|
|
692
|
+
}
|
|
693
|
+
const extracted = extractQuoteDocx(readFileSync(path));
|
|
694
|
+
return { status: 'DONE', data: extracted };
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
name: 'contract.quote.normalize',
|
|
699
|
+
risk: 'read',
|
|
700
|
+
inputSchema: {
|
|
701
|
+
type: 'object',
|
|
702
|
+
additionalProperties: false,
|
|
703
|
+
properties: {
|
|
704
|
+
data: { type: 'string', description: '模型产出的报价 JSON 文件路径' },
|
|
705
|
+
},
|
|
706
|
+
required: ['data'],
|
|
707
|
+
},
|
|
708
|
+
async execute(input) {
|
|
709
|
+
const p = resolve(String(input.data));
|
|
710
|
+
let raw;
|
|
711
|
+
try {
|
|
712
|
+
raw = JSON.parse(readFileSync(p, 'utf8'));
|
|
713
|
+
}
|
|
714
|
+
catch (e) {
|
|
715
|
+
throw contractValidationError('quote_normalize_invalid', `读取模型 JSON 失败:${e instanceof Error ? e.message : String(e)}`);
|
|
716
|
+
}
|
|
717
|
+
const normalized = normalizeParsedQuote(raw);
|
|
718
|
+
return { status: 'DONE', data: normalized };
|
|
719
|
+
},
|
|
720
|
+
},
|
|
457
721
|
{
|
|
458
722
|
name: 'contract.quote.fill',
|
|
459
723
|
risk: 'read-with-upload',
|
|
@@ -530,7 +794,7 @@ export function quoteContractContracts() {
|
|
|
530
794
|
},
|
|
531
795
|
{
|
|
532
796
|
name: 'contract.quote.parse',
|
|
533
|
-
summary: '
|
|
797
|
+
summary: '解析报价单:xlsx 确定性解析;docx 仅无损提取(语义交给模型)',
|
|
534
798
|
risk: 'read-with-upload',
|
|
535
799
|
inputSchema: {
|
|
536
800
|
type: 'object', additionalProperties: false,
|
|
@@ -540,6 +804,24 @@ export function quoteContractContracts() {
|
|
|
540
804
|
}, required: ['path'],
|
|
541
805
|
},
|
|
542
806
|
},
|
|
807
|
+
{
|
|
808
|
+
name: 'contract.quote.extract',
|
|
809
|
+
summary: '把 .docx 报价书无损提取为表格与段落(零语义判断)',
|
|
810
|
+
risk: 'read-with-upload',
|
|
811
|
+
inputSchema: {
|
|
812
|
+
type: 'object', additionalProperties: false,
|
|
813
|
+
properties: { path: { type: 'string' } }, required: ['path'],
|
|
814
|
+
},
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
name: 'contract.quote.normalize',
|
|
818
|
+
summary: '校验并归一化模型产出的报价 JSON(结构 + 金额自校验)',
|
|
819
|
+
risk: 'read',
|
|
820
|
+
inputSchema: {
|
|
821
|
+
type: 'object', additionalProperties: false,
|
|
822
|
+
properties: { data: { type: 'string' } }, required: ['data'],
|
|
823
|
+
},
|
|
824
|
+
},
|
|
543
825
|
{
|
|
544
826
|
name: 'contract.quote.fill',
|
|
545
827
|
summary: '用真实 .docx 模板 + 数据 JSON 生成合同 docx',
|
|
@@ -15,6 +15,7 @@ import { contractQuoteOperations } from './quote.js';
|
|
|
15
15
|
import { contractRecommendOperations } from './recommend.js';
|
|
16
16
|
import { contractRequestOperations } from './request.js';
|
|
17
17
|
import { contractReviewOperations } from './review.js';
|
|
18
|
+
import { contractSaveRecognizeOperations } from './save-recognize.js';
|
|
18
19
|
import { contractSubjectOperations } from './subject.js';
|
|
19
20
|
import { contractSummaryOperations } from './summary.js';
|
|
20
21
|
import { contractTemplateOperations } from './template.js';
|
|
@@ -33,6 +34,7 @@ function buildRegistry() {
|
|
|
33
34
|
...contractReviewOperations,
|
|
34
35
|
...contractFileDownloadOperations,
|
|
35
36
|
...contractFlowOperations,
|
|
37
|
+
...contractSaveRecognizeOperations,
|
|
36
38
|
...contractRecommendOperations,
|
|
37
39
|
...contractCompareOperations,
|
|
38
40
|
...contractCreditPageOperations,
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { contractValidationError } from '../errors.js';
|
|
2
|
+
import { FLOW_PRESETS } from './flow.js';
|
|
3
|
+
import { requireNonEmptyString } from './shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* 智能填单识别记录保存接口。
|
|
6
|
+
*
|
|
7
|
+
* 合同流程发起前的要素抽取结果**不再**以「字段ID:字段值」写进 `customParams`,
|
|
8
|
+
* 而是先由本接口落库,再用返回的 `aiExtraId` 回传流程组件。
|
|
9
|
+
*
|
|
10
|
+
* `customParams` 组成(2026-11-10 修正):
|
|
11
|
+
* - `aiExtraId`:本接口返回的识别记录 ID;
|
|
12
|
+
* - `openSource`:固定 `xiaoE`;
|
|
13
|
+
* - **合同文件字段**:附件字段 ID → fileId。文件必须走 `customParams` 传给流程组件,
|
|
14
|
+
* 只传 `attachmentIds` 不足以让附件挂到表单字段上(2026-11-10 用户指定)。
|
|
15
|
+
* 其余要素字段仍不走 `customParams`。
|
|
16
|
+
*/
|
|
17
|
+
export const SAVE_RECOGNIZE_PATH = '/api/ai/application/smartfill/data/saveRecognizeRecord';
|
|
18
|
+
/** 回传 E10 流程组件时固定使用的来源标识。 */
|
|
19
|
+
export const OPEN_SOURCE = 'xiaoE';
|
|
20
|
+
function asPlainObject(value, name) {
|
|
21
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
22
|
+
throw contractValidationError('recognize_result_invalid', `${name} 必须是 JSON 对象`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 校验识别结果的顶层结构,返回可直接作为接口入参的 JSON 字符串。
|
|
28
|
+
*
|
|
29
|
+
* 接口要求 `recognizeResult` 是**字符串**(不是嵌套对象),且顶层固定
|
|
30
|
+
* `isSuccess` / `mainTable` / `subTables` 三个字段;`subTables` 无明细时必须是 `[]`。
|
|
31
|
+
*/
|
|
32
|
+
export function normalizeRecognizeResult(value) {
|
|
33
|
+
let parsed;
|
|
34
|
+
if (typeof value === 'string') {
|
|
35
|
+
const text = value.trim();
|
|
36
|
+
if (!text)
|
|
37
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult 不能为空');
|
|
38
|
+
try {
|
|
39
|
+
parsed = asPlainObject(JSON.parse(text), 'recognizeResult');
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof Error && error.name === 'ContractCliError')
|
|
43
|
+
throw error;
|
|
44
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult 不是合法 JSON');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parsed = asPlainObject(value, 'recognizeResult');
|
|
49
|
+
}
|
|
50
|
+
if (typeof parsed.isSuccess !== 'boolean') {
|
|
51
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult.isSuccess 必须是布尔值');
|
|
52
|
+
}
|
|
53
|
+
const mainTable = asPlainObject(parsed.mainTable, 'recognizeResult.mainTable');
|
|
54
|
+
if (!Array.isArray(mainTable.rows)) {
|
|
55
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult.mainTable.rows 必须是数组');
|
|
56
|
+
}
|
|
57
|
+
if (!Array.isArray(parsed.subTables)) {
|
|
58
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult.subTables 必须是数组(无明细传 [])');
|
|
59
|
+
}
|
|
60
|
+
return JSON.stringify({ isSuccess: parsed.isSuccess, mainTable, subTables: parsed.subTables });
|
|
61
|
+
}
|
|
62
|
+
function extractAiExtraId(value) {
|
|
63
|
+
const root = (value ?? {});
|
|
64
|
+
const data = (root.data ?? root);
|
|
65
|
+
const candidate = data.aiExtraId ?? data.id ?? root.aiExtraId ?? root.id;
|
|
66
|
+
const text = candidate === undefined || candidate === null ? '' : String(candidate).trim();
|
|
67
|
+
if (!text) {
|
|
68
|
+
throw contractValidationError('ai_extra_id_missing', '保存接口未返回 aiExtraId,不能继续打开流程页');
|
|
69
|
+
}
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 解析可选的流程预设。
|
|
74
|
+
*
|
|
75
|
+
* 与 `flow.ts` 的 `resolveFlow` 不同:**不再强制限定四个预设**。
|
|
76
|
+
* 四类以外的流程(如测试环境的「销售合同起草流程」)可以传自定义名称,
|
|
77
|
+
* 只要同时用 `workflowId` 明确流程模板 ID 即可;不传 `flow` 也允许。
|
|
78
|
+
*/
|
|
79
|
+
function resolveFlowPreset(value) {
|
|
80
|
+
if (value === undefined || value === null || value === '')
|
|
81
|
+
return undefined;
|
|
82
|
+
const raw = requireNonEmptyString(value, 'flow', 64).trim();
|
|
83
|
+
const exact = FLOW_PRESETS.find((preset) => preset.key === raw || preset.label === raw);
|
|
84
|
+
if (exact)
|
|
85
|
+
return { key: exact.key, label: exact.label, workflowId: exact.workflowId };
|
|
86
|
+
const fuzzy = FLOW_PRESETS.filter((preset) => raw.includes(preset.key) || preset.label.includes(raw));
|
|
87
|
+
if (fuzzy.length === 1) {
|
|
88
|
+
return { key: fuzzy[0].key, label: fuzzy[0].label, workflowId: fuzzy[0].workflowId };
|
|
89
|
+
}
|
|
90
|
+
// 非四类预设:当作自定义流程名,workflowId 必须由调用方显式提供。
|
|
91
|
+
return { key: raw, label: raw, workflowId: '' };
|
|
92
|
+
}
|
|
93
|
+
export const contractSaveRecognizeOperations = [
|
|
94
|
+
{
|
|
95
|
+
name: 'contract.flow.save-recognize-record',
|
|
96
|
+
async execute(input, { host }) {
|
|
97
|
+
const flow = resolveFlowPreset(input.flow);
|
|
98
|
+
const explicitWorkflowId = input.workflowId === undefined || input.workflowId === null || input.workflowId === ''
|
|
99
|
+
? ''
|
|
100
|
+
: requireNonEmptyString(input.workflowId, 'workflowId', 64).trim();
|
|
101
|
+
const workflowId = explicitWorkflowId || flow?.workflowId || '';
|
|
102
|
+
if (!workflowId) {
|
|
103
|
+
throw contractValidationError('workflow_id_required', 'flow 与 workflowId 至少传一个;四类预设之外的流程(如销售合同起草流程)必须显式传 workflowId');
|
|
104
|
+
}
|
|
105
|
+
if (!/^[1-9]\d*$/.test(workflowId)) {
|
|
106
|
+
throw contractValidationError('workflow_id_invalid', 'workflowId 必须是纯数字的流程模板 ID');
|
|
107
|
+
}
|
|
108
|
+
const recognizeResult = normalizeRecognizeResult(input.recognizeResult);
|
|
109
|
+
const body = { workflowId, recognizeResult };
|
|
110
|
+
const attachmentIds = typeof input.attachmentIds === 'string' ? input.attachmentIds.trim() : '';
|
|
111
|
+
if (attachmentIds)
|
|
112
|
+
body.attachmentIds = attachmentIds;
|
|
113
|
+
// 合同文件字段:必须随 customParams 交给流程组件,否则附件挂不到表单字段上。
|
|
114
|
+
// 未显式传 attachmentFileId 时,取 attachmentIds 的首个文件。
|
|
115
|
+
const attachmentFieldId = input.attachmentFieldId === undefined
|
|
116
|
+
|| input.attachmentFieldId === null
|
|
117
|
+
|| input.attachmentFieldId === ''
|
|
118
|
+
? ''
|
|
119
|
+
: requireNonEmptyString(input.attachmentFieldId, 'attachmentFieldId', 64).trim();
|
|
120
|
+
if (attachmentFieldId && !/^[1-9]\d*$/.test(attachmentFieldId)) {
|
|
121
|
+
throw contractValidationError('attachment_field_id_invalid', 'attachmentFieldId 必须是从表单字段定义中取得的纯数字字段 ID');
|
|
122
|
+
}
|
|
123
|
+
const explicitFileId = typeof input.attachmentFileId === 'string' ? input.attachmentFileId.trim() : '';
|
|
124
|
+
const attachmentFileId = explicitFileId || (attachmentIds ? attachmentIds.split(',')[0].trim() : '');
|
|
125
|
+
if (attachmentFieldId && !attachmentFileId) {
|
|
126
|
+
throw contractValidationError('attachment_file_id_missing', '传了 attachmentFieldId 就必须有文件 ID:请传 attachmentFileId,或在 attachmentIds 里带上本次文件');
|
|
127
|
+
}
|
|
128
|
+
const response = await host.contractRequest({
|
|
129
|
+
method: 'POST',
|
|
130
|
+
path: SAVE_RECOGNIZE_PATH,
|
|
131
|
+
body,
|
|
132
|
+
});
|
|
133
|
+
const aiExtraId = extractAiExtraId(response);
|
|
134
|
+
const customParams = { aiExtraId, openSource: OPEN_SOURCE };
|
|
135
|
+
if (attachmentFieldId)
|
|
136
|
+
customParams[attachmentFieldId] = attachmentFileId;
|
|
137
|
+
return {
|
|
138
|
+
status: 'COMPLETE',
|
|
139
|
+
data: {
|
|
140
|
+
flow: flow?.key ?? null,
|
|
141
|
+
flowLabel: flow?.label ?? null,
|
|
142
|
+
workflowId,
|
|
143
|
+
aiExtraId,
|
|
144
|
+
attachmentFieldId: attachmentFieldId || null,
|
|
145
|
+
attachmentFileId: attachmentFileId || null,
|
|
146
|
+
customParams,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
];
|