weaver-work-cli 0.1.49 → 0.1.52
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/README.md +1 -1
- package/dist/chunks/{attachment-content-MU2LPI5P.js → attachment-content-MBYYSQIX.js} +3 -3
- package/dist/chunks/{chunk-ZKEUGS2U.js → chunk-7UOXOGFL.js} +4 -4
- package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
- package/dist/chunks/{chunk-3NV2ETZR.js → chunk-D3TDNRFE.js} +8 -8
- package/dist/chunks/{chunk-6GWU63YF.js → chunk-DZOC77ZD.js} +1 -1
- package/dist/chunks/{chunk-K3BT54CU.js → chunk-IRMA3GVP.js} +1 -1
- package/dist/chunks/{chunk-3X7VOSBA.js → chunk-KLZ3ULQQ.js} +1 -1
- package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
- package/dist/chunks/{chunk-NBEWUR7L.js → chunk-LALWNK6M.js} +167 -44
- package/dist/chunks/{chunk-BRRW7CWA.js → chunk-LM2H7SZI.js} +26 -26
- package/dist/chunks/{chunk-KV5SOWMS.js → chunk-LTRLF6MM.js} +4 -4
- package/dist/chunks/{chunk-D2QRZUW4.js → chunk-RPRFIG6I.js} +35 -28
- package/dist/chunks/{chunk-GEOMANP7.js → chunk-RWFRZSIP.js} +2 -2
- package/dist/chunks/{chunk-EJVA5ZVB.js → chunk-ZRHKGQRQ.js} +2 -2
- package/dist/chunks/{conflict-6347A7YK.js → conflict-D2HYKBMH.js} +2 -2
- package/dist/chunks/{contract-N6P2HIIE.js → contract-MFOFMM2J.js} +4284 -254
- package/dist/chunks/{create-flow-7WG7LVX5.js → create-flow-7ZATJVTM.js} +6 -6
- package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
- package/dist/chunks/{env-LHRKSLG6.js → env-5DO4YENS.js} +2 -2
- package/dist/chunks/{factory-2H7Z4RWJ.js → factory-3M7D7WJC.js} +1 -1
- package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
- package/dist/chunks/{group-chat-EW6PNDDT.js → group-chat-B2HT5NEO.js} +3 -3
- package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
- package/dist/chunks/{invoice-FXWH5GPO.js → invoice-V7ZTITUO.js} +726 -206
- package/dist/chunks/{meeting-N2FQBHXI.js → meeting-HZOX3CBB.js} +10 -10
- package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
- package/dist/chunks/{reception-MYOKJULO.js → reception-QGPNTGHG.js} +98 -82
- package/dist/chunks/{recruit-stage-FKWS5UQF.js → recruit-stage-XCMVEQA2.js} +718 -131
- package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
- package/dist/chunks/{registry-7VZ6YJUF.js → registry-KYPFFQIH.js} +1 -1
- package/dist/chunks/{registry-CKUVBS53.js → registry-SJHSBO5G.js} +10 -10
- package/dist/chunks/{room-recommend-MBCYENQ2.js → room-recommend-5AHR4YQV.js} +4 -4
- package/dist/chunks/{schedule-5IFMCXME.js → schedule-KZPJUPC2.js} +4 -4
- package/dist/chunks/smart-extract-IXHCZE4R.js +2846 -0
- package/dist/chunks/{workflow-2TRU2ZSP.js → workflow-UHKCZJMY.js} +1 -1
- package/dist/index.js +14 -9
- package/dist/shortcuts/contract/host.js +11 -0
- package/dist/shortcuts/contract/index.js +13 -0
- package/dist/shortcuts/contract/manifest.js +204 -0
- package/dist/shortcuts/contract/operations/card-action.js +585 -0
- package/dist/shortcuts/contract/operations/card-ebdf-list.js +315 -0
- package/dist/shortcuts/contract/operations/card-plan.js +327 -0
- package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
- package/dist/shortcuts/contract/operations/elements-build.js +714 -0
- package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
- package/dist/shortcuts/contract/operations/first-screen.js +563 -0
- package/dist/shortcuts/contract/operations/flow.js +81 -25
- package/dist/shortcuts/contract/operations/modeltext.js +132 -0
- package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
- package/dist/shortcuts/contract/operations/performance.js +58 -7
- package/dist/shortcuts/contract/operations/quote.js +410 -22
- package/dist/shortcuts/contract/operations/registry.js +22 -0
- package/dist/shortcuts/contract/operations/review.js +73 -58
- package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
- package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
- package/dist/shortcuts/contract/operations/summary.js +4 -2
- package/dist/shortcuts/contract/operations/upload.js +48 -7
- package/dist/shortcuts/contract/prewarm-cache.js +90 -0
- package/dist/shortcuts/contract/prewarm.js +88 -0
- package/dist/shortcuts/contract/upload-cache.js +49 -4
- package/dist/shortcuts/data/index.js +1 -6
- package/dist/shortcuts/data/manifest.js +2 -2
- package/dist/shortcuts/data/operations/index.js +1 -1
- package/dist/shortcuts/data/operations/query.js +23 -46
- 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/index.js +0 -12
- package/dist/shortcuts/invoice/manifest.js +201 -50
- package/dist/shortcuts/invoice/operations/registry.js +4 -2
- package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
- package/dist/shortcuts/invoice/operations/shared.js +3 -19
- package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
- package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
- package/dist/shortcuts/reception/constants.js +3 -7
- package/dist/shortcuts/reception/operations/leads.js +30 -6
- package/dist/shortcuts/reception/operations/panels.js +3 -2
- package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
- package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
- package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
- package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
- package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
- package/dist/shortcuts/recruit-stage/shared.js +5 -0
- package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
- package/dist/shortcuts/smart-extract/constants.js +79 -0
- package/dist/shortcuts/smart-extract/continuation.js +71 -0
- package/dist/shortcuts/smart-extract/errors.js +68 -0
- package/dist/shortcuts/smart-extract/host.js +191 -0
- package/dist/shortcuts/smart-extract/index.js +105 -0
- package/dist/shortcuts/smart-extract/ledger.js +70 -0
- package/dist/shortcuts/smart-extract/manifest.js +35 -0
- package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
- package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
- package/dist/shortcuts/smart-extract/operations/config.js +118 -0
- package/dist/shortcuts/smart-extract/operations/fill.js +489 -0
- package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
- package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
- package/dist/shortcuts/smart-extract/operations/save.js +355 -0
- package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
- package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
- package/dist/shortcuts/smart-extract/operations/target.js +167 -0
- package/dist/shortcuts/smart-extract/operations/types.js +22 -0
- package/dist/shortcuts/smart-extract/operations/validate.js +408 -0
- package/dist/shortcuts/workflow/operations/read.js +77 -15
- 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 +1 -1
- package/docs/_catalog.md +4 -1
- package/docs/agent-invoice.md +5 -7
- package/docs/data.md +5 -1
- package/docs/fna.md +24 -4
- package/docs/invoice.md +7 -5
- package/docs/smart-extract.md +156 -0
- package/package.json +1 -1
- package/skill-template/business-info.json +21 -1
- package/skill-template/domains/qiyecheng.md +6 -2
- package/skill-template/domains/smart-extract.md +16 -0
- package/skill-template/domains/yepiaotong.md +2 -2
- package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
- package/skills/weaver-e10-jinchengda/SKILL.md +159 -11
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +13 -8
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +5 -4
- 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 +220 -0
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +68 -33
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +26 -15
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +90 -0
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +167 -5
- package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +200 -0
- package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +572 -0
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
- package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +560 -0
- package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +894 -0
- package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +93 -0
- package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
- package/skills/weaver-e10-qiyecheng/SKILL.md +58 -7
- package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +118 -0
- package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
- package/skills/weaver-e10-qiyecheng/references/catalog.md +42 -3
- package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
- package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
- package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
- package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
- package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +153 -40
- package/skills/weaver-e10-reception-flow/SKILL.md +43 -6
- package/skills/weaver-e10-reception-flow/references/guide.md +1 -1
- package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
- package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
- package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
- package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
- package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -40
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
- package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
- package/skills/weaver-e10-smart-extract/SKILL.md +169 -0
- package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
- package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
- package/skills/weaver-e10-smart-extract/references/troubleshooting.md +105 -0
- 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/references/workflow-query.md +1 -1
- package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
- package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
- package/skills/weaver-e10-yepiaotong/SKILL.md +53 -35
- package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
- package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
- package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
- package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
- package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +18 -53
- package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +96 -7
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +5 -38
- package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +14 -14
- package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
- package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +139 -94
- package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +131 -58
- package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
- 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/shortcuts/invoice/operations/validate-preview.js +0 -40
- package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
- package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
- package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
- package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +0 -40
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
3
|
+
import { contractValidationError } from '../errors.js';
|
|
4
|
+
import { BUILTIN, CHECKBOX_HINTS_RESALE, CHECKBOX_HINTS_UPSALE, COMPANY_OPTIONS, NEW_CUSTOMER, } from './elements-spec.js';
|
|
5
|
+
/**
|
|
6
|
+
* 按流程内置字段表,把 triage.json 的要素自动组装成 recognizeResult。
|
|
7
|
+
*
|
|
8
|
+
* 迁移自 `scripts/fill_elements.py`(2026-11-12 第四批)。
|
|
9
|
+
*
|
|
10
|
+
* origin 出处规则(2026-11-12 用户指定,见「智能填单结果格式」§4):
|
|
11
|
+
* 1) 前缀是实际附件 ID,禁止写死 att001 / 附件名称;
|
|
12
|
+
* 2) 原文片段必须逐字取自正文,禁止概括、禁止截断;
|
|
13
|
+
* 3) 表格来源输出整行,去掉序号列与章节号前缀;
|
|
14
|
+
* 4) 全文推导、无具体来源时为 null(不输出 [null],也不编造片段)。
|
|
15
|
+
*
|
|
16
|
+
* 不写附件字段(2026-11-12 用户指定):recognizeResult 只放要素抽取结果,
|
|
17
|
+
* 附件一律由流程组件 customParams 透传赋值;顶层 attachmentIds /
|
|
18
|
+
* attachmentFieldId / attachmentFileId 保留,仅供 CLI 构造 customParams。
|
|
19
|
+
*/
|
|
20
|
+
/** 章节号/段落号/序号前缀(规范:禁止以序号开头)。 */
|
|
21
|
+
const NUM_PREFIX = /^\s*(?:第[〇零一二三四五六七八九十百0-9]+[章节条款项编部]|[((][〇零一二三四五六七八九十百0-9]+[))]|[〇零一二三四五六七八九十]+、|[0-9]+(?:\.[0-9]+)+[、..]?|[0-9]+[、..]\s*)/u;
|
|
22
|
+
/** Python 真值:None/False/0/""/[]/{} 均为假。 */
|
|
23
|
+
function pyTruthy(value) {
|
|
24
|
+
if (value === null || value === undefined || value === false)
|
|
25
|
+
return false;
|
|
26
|
+
if (value === true)
|
|
27
|
+
return true;
|
|
28
|
+
if (typeof value === 'number')
|
|
29
|
+
return value !== 0 && !Number.isNaN(value);
|
|
30
|
+
if (typeof value === 'string')
|
|
31
|
+
return value.length > 0;
|
|
32
|
+
if (Array.isArray(value))
|
|
33
|
+
return value.length > 0;
|
|
34
|
+
if (typeof value === 'object')
|
|
35
|
+
return Object.keys(value).length > 0;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/** Python `str(x or '')`。 */
|
|
39
|
+
function truthyText(value) {
|
|
40
|
+
return pyTruthy(value) ? String(value) : '';
|
|
41
|
+
}
|
|
42
|
+
/** Python `x or y`(按真值取第一个非假值)。 */
|
|
43
|
+
function orElse(value, fallback) {
|
|
44
|
+
return pyTruthy(value) ? value : fallback;
|
|
45
|
+
}
|
|
46
|
+
/** Python `value in (None, "")`:注意 0 与 False 不算空。 */
|
|
47
|
+
function isEmptyScalar(value) {
|
|
48
|
+
return value === null || value === undefined || value === '';
|
|
49
|
+
}
|
|
50
|
+
/** 全角转半角 + 去除空白与各类括号间隔符(Python `norm`)。 */
|
|
51
|
+
export function norm(input) {
|
|
52
|
+
const text = String(input ?? '');
|
|
53
|
+
const chars = [];
|
|
54
|
+
for (const ch of text) {
|
|
55
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
56
|
+
if (code === 0x3000)
|
|
57
|
+
chars.push(' ');
|
|
58
|
+
else if (code >= 0xff01 && code <= 0xff5e)
|
|
59
|
+
chars.push(String.fromCodePoint(code - 0xfee0));
|
|
60
|
+
else
|
|
61
|
+
chars.push(ch);
|
|
62
|
+
}
|
|
63
|
+
return chars.join('').replace(/[\s()()·・]/gu, '');
|
|
64
|
+
}
|
|
65
|
+
/** 去掉开头的章节号/段落号/序号(规范:禁止以序号开头)。 */
|
|
66
|
+
export function stripNumber(input) {
|
|
67
|
+
let out = truthyText(input);
|
|
68
|
+
let prev = null;
|
|
69
|
+
while (out && out !== prev) {
|
|
70
|
+
prev = out;
|
|
71
|
+
const match = NUM_PREFIX.exec(out);
|
|
72
|
+
if (match && match.index === 0) {
|
|
73
|
+
out = out.slice(match[0].length).trim();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
function isCell(line) {
|
|
82
|
+
return truthyText(line).trim().startsWith('|');
|
|
83
|
+
}
|
|
84
|
+
function cellText(line) {
|
|
85
|
+
let text = truthyText(line).trim();
|
|
86
|
+
if (text.startsWith('|'))
|
|
87
|
+
text = text.replace(/^\|+/u, '').trim();
|
|
88
|
+
return text.replace(/\s+/gu, ' ');
|
|
89
|
+
}
|
|
90
|
+
/** 读合同正文纯文本(contract_text.txt),返回行数组。 */
|
|
91
|
+
export function loadSourceLines(path) {
|
|
92
|
+
if (!path || !isFile(path))
|
|
93
|
+
return [];
|
|
94
|
+
return readFileSync(path, 'utf8').split('\n').map((line) => line.replace(/\r$/u, ''));
|
|
95
|
+
}
|
|
96
|
+
/** 读 triage 产出的 text_sources.json(行号 → 所属文件)。 */
|
|
97
|
+
export function loadSourceMap(outDir) {
|
|
98
|
+
if (!outDir)
|
|
99
|
+
return null;
|
|
100
|
+
const path = join(outDir, 'text_sources.json');
|
|
101
|
+
if (!isFile(path))
|
|
102
|
+
return null;
|
|
103
|
+
try {
|
|
104
|
+
const data = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/u, ''));
|
|
105
|
+
const files = Array.isArray(data.files) ? data.files : [];
|
|
106
|
+
const lineMap = Array.isArray(data.lineMap) ? data.lineMap : [];
|
|
107
|
+
if (!files.length || !lineMap.length)
|
|
108
|
+
return null;
|
|
109
|
+
return { files, lineMap };
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** 按命中行号取所属文件的附件 ID;映射缺失时回退主附件 ID。 */
|
|
116
|
+
function pickFileId(sourceMap, fileIds, lineIndex, fallback) {
|
|
117
|
+
if (!sourceMap || !fileIds || !fileIds.length)
|
|
118
|
+
return fallback;
|
|
119
|
+
const lineMap = sourceMap.lineMap ?? [];
|
|
120
|
+
if (lineIndex >= 0 && lineIndex < lineMap.length) {
|
|
121
|
+
const fileIndex = lineMap[lineIndex];
|
|
122
|
+
if (fileIndex >= 0 && fileIndex < fileIds.length && fileIds[fileIndex])
|
|
123
|
+
return fileIds[fileIndex];
|
|
124
|
+
}
|
|
125
|
+
return fallback;
|
|
126
|
+
}
|
|
127
|
+
/** 取命中行所在表格的整行(单元格拼接、禁止换行);非表格行取该行原文。 */
|
|
128
|
+
function rowSnippet(lines, index) {
|
|
129
|
+
if (!isCell(lines[index]))
|
|
130
|
+
return stripNumber(truthyText(lines[index]).trim());
|
|
131
|
+
let start = index;
|
|
132
|
+
while (start > 0 && isCell(lines[start - 1]))
|
|
133
|
+
start -= 1;
|
|
134
|
+
// 表格首列通常单独成行(不带 |),向前再取一格作为行首
|
|
135
|
+
if (start > 0 && truthyText(lines[start - 1]).trim() && !isCell(lines[start - 1]))
|
|
136
|
+
start -= 1;
|
|
137
|
+
let end = index;
|
|
138
|
+
while (end + 1 < lines.length && isCell(lines[end + 1]))
|
|
139
|
+
end += 1;
|
|
140
|
+
let cells = [];
|
|
141
|
+
for (let i = start; i <= end; i += 1)
|
|
142
|
+
cells.push(cellText(lines[i]));
|
|
143
|
+
cells = cells.filter((cell) => cell);
|
|
144
|
+
// 首列若为纯数字,属序号列,规范要求禁止以序号开头
|
|
145
|
+
while (cells.length && /^[0-9]+$/u.test(cells[0]))
|
|
146
|
+
cells.shift();
|
|
147
|
+
return stripNumber(cells.join(''));
|
|
148
|
+
}
|
|
149
|
+
/** 把 needle 拆成可用于兜底匹配的长片段(仍要求逐字命中原文行)。 */
|
|
150
|
+
function fragments(needle, minLength = 4) {
|
|
151
|
+
const parts = truthyText(needle).split(/[,。;、,;::;||//\s()()#【】[\]]+/u);
|
|
152
|
+
return parts.filter((part) => part.length >= minLength);
|
|
153
|
+
}
|
|
154
|
+
/** 为数字串补充「千分位 / 去千分位」两种字形,供正文逐字匹配。 */
|
|
155
|
+
function numberVariants(value) {
|
|
156
|
+
const text = truthyText(value).trim();
|
|
157
|
+
const match = /^[¥¥$]?\s*(\d{1,3}(?:,\d{3})+|\d+)(\.\d+)?$/u.exec(text);
|
|
158
|
+
if (!match)
|
|
159
|
+
return [];
|
|
160
|
+
const intPart = match[1];
|
|
161
|
+
const dec = match[2] ?? '';
|
|
162
|
+
const digits = intPart.split(',').join('').replace(/^0+(?=\d)/u, '');
|
|
163
|
+
if (!digits)
|
|
164
|
+
return [];
|
|
165
|
+
const grouped = groupThousands(digits) + dec;
|
|
166
|
+
const out = [];
|
|
167
|
+
for (const candidate of [grouped, digits + dec]) {
|
|
168
|
+
if (candidate && !out.includes(candidate))
|
|
169
|
+
out.push(candidate);
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
function groupThousands(digits) {
|
|
174
|
+
let out = '';
|
|
175
|
+
let count = 0;
|
|
176
|
+
for (let i = digits.length - 1; i >= 0; i -= 1) {
|
|
177
|
+
out = digits[i] + out;
|
|
178
|
+
count += 1;
|
|
179
|
+
if (count % 3 === 0 && i > 0)
|
|
180
|
+
out = `,${out}`;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 把字段值转成检索用 needle 列表;空值返回 null(表示无来源)。
|
|
186
|
+
*
|
|
187
|
+
* 除原值外,额外补充去掉括号注释的变体,避免「2026年7月(日留空待填)」
|
|
188
|
+
* 这类带注释的值在正文里匹配不到而丢掉出处;数字补千分位/去千分位变体。
|
|
189
|
+
*/
|
|
190
|
+
function buildNeedles(value) {
|
|
191
|
+
if (isEmptyScalar(value))
|
|
192
|
+
return null;
|
|
193
|
+
const values = Array.isArray(value) ? value : [value];
|
|
194
|
+
const out = [];
|
|
195
|
+
for (const item of values) {
|
|
196
|
+
if (isEmptyScalar(item))
|
|
197
|
+
continue;
|
|
198
|
+
const text = String(item);
|
|
199
|
+
out.push(text);
|
|
200
|
+
const stripped = text.replace(/[((][^))]*[))]/gu, '').trim();
|
|
201
|
+
if (stripped && stripped !== text)
|
|
202
|
+
out.push(stripped);
|
|
203
|
+
for (const candidate of numberVariants(text)) {
|
|
204
|
+
if (!out.includes(candidate))
|
|
205
|
+
out.push(candidate);
|
|
206
|
+
}
|
|
207
|
+
if (stripped && stripped !== text) {
|
|
208
|
+
for (const candidate of numberVariants(stripped)) {
|
|
209
|
+
if (!out.includes(candidate))
|
|
210
|
+
out.push(candidate);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return out.length ? out : null;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 在正文里按 needles 顺序找逐字原文,返回 origin 数组;无来源返回 null。
|
|
218
|
+
*
|
|
219
|
+
* 多文件场景:sourceMap + fileIds 把出处前缀记到命中行真正所属的文件,
|
|
220
|
+
* 避免全部算到主文件头上。
|
|
221
|
+
*/
|
|
222
|
+
export function resolveOrigin(lines, needles, attachmentId, sourceMap, fileIds) {
|
|
223
|
+
if (!lines || !lines.length || !pyTruthy(needles))
|
|
224
|
+
return null;
|
|
225
|
+
// 兼容直接传单个字符串的调用点(避免按字符逐个匹配)
|
|
226
|
+
const needleList = Array.isArray(needles) ? needles : [needles];
|
|
227
|
+
const candidates = [];
|
|
228
|
+
for (const needle of needleList) {
|
|
229
|
+
if (!pyTruthy(needle))
|
|
230
|
+
continue;
|
|
231
|
+
const normalized = norm(needle);
|
|
232
|
+
if (!normalized)
|
|
233
|
+
continue;
|
|
234
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
235
|
+
if (!truthyText(lines[i]).trim())
|
|
236
|
+
continue;
|
|
237
|
+
if (norm(lines[i]).includes(normalized)) {
|
|
238
|
+
const snippet = rowSnippet(lines, i);
|
|
239
|
+
if (snippet)
|
|
240
|
+
candidates.push({ index: i, snippet });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (candidates.length)
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
// 整句匹配不到时,退到原文片段再试(输出仍是逐字原文行,不加工)
|
|
247
|
+
if (!candidates.length) {
|
|
248
|
+
for (const needle of needleList) {
|
|
249
|
+
for (const fragment of fragments(needle)) {
|
|
250
|
+
const normalized = norm(fragment);
|
|
251
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
252
|
+
if (!truthyText(lines[i]).trim())
|
|
253
|
+
continue;
|
|
254
|
+
if (normalized && norm(lines[i]).includes(normalized)) {
|
|
255
|
+
const snippet = rowSnippet(lines, i);
|
|
256
|
+
if (snippet)
|
|
257
|
+
candidates.push({ index: i, snippet });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (candidates.length)
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
if (candidates.length)
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!candidates.length)
|
|
268
|
+
return null;
|
|
269
|
+
// 命中多行时取最短一条(表格/目录中的重复行往往带页码等杂质)
|
|
270
|
+
let best = candidates[0];
|
|
271
|
+
for (const candidate of candidates) {
|
|
272
|
+
if (candidate.snippet.length < best.snippet.length)
|
|
273
|
+
best = candidate;
|
|
274
|
+
}
|
|
275
|
+
return [`${pickFileId(sourceMap, fileIds, best.index, attachmentId)}#${best.snippet}`];
|
|
276
|
+
}
|
|
277
|
+
/** 乙方签约主体全称 → 下拉框可用选项值;无法确定返回空串(不猜)。 */
|
|
278
|
+
export function mapCompany(value) {
|
|
279
|
+
const normalized = norm(value);
|
|
280
|
+
if (!normalized)
|
|
281
|
+
return '';
|
|
282
|
+
for (const [name, keys] of COMPANY_OPTIONS) {
|
|
283
|
+
for (const key of keys) {
|
|
284
|
+
if (normalized.includes(norm(key)))
|
|
285
|
+
return name;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return '';
|
|
289
|
+
}
|
|
290
|
+
/** 按归一化显示名匹配选项 ID;匹配不到返回 null(不猜)。 */
|
|
291
|
+
export function pickOption(table, value) {
|
|
292
|
+
if (!pyTruthy(value))
|
|
293
|
+
return null;
|
|
294
|
+
const normalized = norm(value);
|
|
295
|
+
for (const [name, optionId] of Object.entries(table)) {
|
|
296
|
+
const candidate = norm(name);
|
|
297
|
+
if (normalized === candidate || candidate.includes(normalized) || normalized.includes(candidate)) {
|
|
298
|
+
return optionId;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 流程标题兜底:取合同文件名称并去掉扩展名(2026-11-12 用户指定)。
|
|
305
|
+
*
|
|
306
|
+
* 合同正文常抽不到标题(目录行、页眉、域代码干扰),此时直接用上传文件的
|
|
307
|
+
* 名称去后缀,保证「流程标题」字段不为空;多文件以主文件为准。
|
|
308
|
+
*/
|
|
309
|
+
export function fileStem(triage) {
|
|
310
|
+
if (!triage)
|
|
311
|
+
return '';
|
|
312
|
+
const candidates = [];
|
|
313
|
+
const meta = triage.file;
|
|
314
|
+
if (meta && typeof meta === 'object' && !Array.isArray(meta)) {
|
|
315
|
+
candidates.push(truthyText(meta.name));
|
|
316
|
+
candidates.push(truthyText(meta.path));
|
|
317
|
+
}
|
|
318
|
+
for (const item of Array.isArray(triage.sourceFiles) ? triage.sourceFiles : []) {
|
|
319
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
320
|
+
candidates.push(truthyText(item.name));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
for (const candidate of candidates) {
|
|
324
|
+
if (!candidate)
|
|
325
|
+
continue;
|
|
326
|
+
const stem = basename(candidate).slice(0, basename(candidate).length - extname(basename(candidate)).length).trim();
|
|
327
|
+
if (stem)
|
|
328
|
+
return stem;
|
|
329
|
+
}
|
|
330
|
+
return '';
|
|
331
|
+
}
|
|
332
|
+
/** 金额归一为纯数字字符串;无有效数字返回空串(不猜)。 */
|
|
333
|
+
export function amountOf(value) {
|
|
334
|
+
if (isEmptyScalar(value))
|
|
335
|
+
return '';
|
|
336
|
+
const match = /(\d[\d,,]*(?:\.\d+)?)/u.exec(String(value));
|
|
337
|
+
if (!match)
|
|
338
|
+
return '';
|
|
339
|
+
return match[1].split(',').join('').split(',').join('');
|
|
340
|
+
}
|
|
341
|
+
function makePayload(spec, flow, fileId, results, subtables = []) {
|
|
342
|
+
return {
|
|
343
|
+
flow,
|
|
344
|
+
workflowId: spec.workflowId,
|
|
345
|
+
attachmentIds: fileId,
|
|
346
|
+
attachmentFieldId: spec.attachmentFieldId,
|
|
347
|
+
attachmentFileId: fileId,
|
|
348
|
+
recognizeResult: {
|
|
349
|
+
isSuccess: true,
|
|
350
|
+
mainTable: { rows: [{ mainDataId: 1, fieldResults: results }] },
|
|
351
|
+
subTables: subtables,
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/** 新客户流程:完整 23 项语义映射。 */
|
|
356
|
+
export function buildNewCustomer({ triage, fileId, flow, lines, sourceMap, fileIds }) {
|
|
357
|
+
const spec = NEW_CUSTOMER;
|
|
358
|
+
const fields = spec.fields;
|
|
359
|
+
const elements = (triage.elements && typeof triage.elements === 'object') ? triage.elements : {};
|
|
360
|
+
const results = [];
|
|
361
|
+
const ro = (needles) => resolveOrigin(lines, needles, fileId, sourceMap, fileIds);
|
|
362
|
+
const add = (key, value, reason, origin) => {
|
|
363
|
+
if (isEmptyScalar(value))
|
|
364
|
+
return;
|
|
365
|
+
results.push({ fieldInfo: fields[key], reason, value: String(value), origin: ro(origin) });
|
|
366
|
+
};
|
|
367
|
+
// 购买方式:以「签约相对方是否等于最终用户」判定,不能只看丙方。
|
|
368
|
+
// 判据(references §2.1):实际使用系统的客户通过第三方公司与泛微签约 → 通过伙伴签署;
|
|
369
|
+
// 甲方即最终用户时仍属直签,此前只看 partyC 会把伙伴代签误判成直签。
|
|
370
|
+
const partnerName = orElse(elements.partyC, elements.partyA);
|
|
371
|
+
const finalUserOf = orElse(elements.finalUser, elements.partyA);
|
|
372
|
+
const isPartnerSign = pyTruthy(elements.partyC)
|
|
373
|
+
|| (pyTruthy(elements.finalUser)
|
|
374
|
+
&& pyTruthy(elements.partyA)
|
|
375
|
+
&& norm(elements.finalUser) !== norm(elements.partyA));
|
|
376
|
+
if (isPartnerSign) {
|
|
377
|
+
add('buyMode', spec.options?.buyMode['通过伙伴签署'], '签约相对方与最终用户不是同一主体,属通过伙伴签署', buildNeedles(partnerName));
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
add('buyMode', spec.options?.buyMode['直签'], '泛微与实际使用方直接签署', buildNeedles(elements.partyA));
|
|
381
|
+
}
|
|
382
|
+
// 流程标题:优先取合同标题;抽不到时直接取合同文件名(去后缀)
|
|
383
|
+
if (pyTruthy(elements.title)) {
|
|
384
|
+
add('title', elements.title, '取合同标题', buildNeedles(elements.title));
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
add('title', fileStem(triage), '取合同文件名(去后缀)', null);
|
|
388
|
+
}
|
|
389
|
+
const finalUser = finalUserOf;
|
|
390
|
+
add('finalUser', finalUser, '取合同最终用户全称', buildNeedles(finalUser));
|
|
391
|
+
// 伙伴名称只在「通过伙伴签署」时填,取签约相对方全称;直签场景必须留空
|
|
392
|
+
if (isPartnerSign) {
|
|
393
|
+
add('partner', partnerName, '取签约伙伴(签约相对方)全称', buildNeedles(partnerName));
|
|
394
|
+
}
|
|
395
|
+
add('totalAmount', elements.totalAmount, '取合同总额', buildNeedles(amountOf(elements.totalAmount)));
|
|
396
|
+
// 合同背景说明:客户背景 + 采购标的 + 采购动因(references §1 第 5 项,此前漏实现)
|
|
397
|
+
add('background', elements.background, '由签约主体、最终用户与采购标的归纳', buildNeedles(elements.background));
|
|
398
|
+
const optionId = pickOption(spec.options?.ourCompany ?? {}, elements.partyB);
|
|
399
|
+
if (optionId) {
|
|
400
|
+
add('ourCompany', optionId, '乙方签约主体映射', `乙方:${truthyText(elements.partyB)}`);
|
|
401
|
+
}
|
|
402
|
+
add('address', elements.address, '取合同约定联系/送达地址', orElse(elements.address, '地址'));
|
|
403
|
+
add('receiver', elements.contact, '取合同联系人', orElse(elements.contact, '联系人'));
|
|
404
|
+
add('mobile', elements.phone, '取合同联系电话', orElse(elements.phone, '电话'));
|
|
405
|
+
// 签署信息:抽到就用,抽不到用默认
|
|
406
|
+
let signForm = spec.defaults?.signForm ?? '2';
|
|
407
|
+
const rawSign = norm(orElse(elements.rawSign, ''));
|
|
408
|
+
if (rawSign.includes('电子签') && rawSign.includes('契约锁'))
|
|
409
|
+
signForm = '4';
|
|
410
|
+
add('signForm', signForm, '合同未特别约定,按纸质签署(默认值)', buildNeedles('盖章') ?? buildNeedles('电子签'));
|
|
411
|
+
if (pyTruthy(elements.signDate)) {
|
|
412
|
+
add('signDate', spec.options?.signDate['指定签署日期'], '合同载明签订日期,按指定签署日期', buildNeedles(elements.signDate));
|
|
413
|
+
add('designatedDate', elements.signDate, '合同签订时间', buildNeedles(elements.signDate));
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
add('signDate', spec.defaults?.signDate ?? '2', '合同未载明签署日期,按默认合同办理当天', null);
|
|
417
|
+
}
|
|
418
|
+
add('signWay', spec.defaults?.signWay ?? '0', '未特别约定签署顺序,按我方先盖章', null);
|
|
419
|
+
// 专项购买信息(明细表):只输出合同原文命中的专项,未命中整行不输出;
|
|
420
|
+
// 无专属计价时金额固定填 0,禁止用「有无金额」反推专项是否存在(references §5.1/§5.3)。
|
|
421
|
+
const subtables = [];
|
|
422
|
+
const solutions = Array.isArray(elements.solutions) ? elements.solutions : [];
|
|
423
|
+
if (solutions.length && spec.subFormId) {
|
|
424
|
+
const rows = [];
|
|
425
|
+
solutions.forEach((item) => {
|
|
426
|
+
const name = truthyText(item?.name);
|
|
427
|
+
if (!name)
|
|
428
|
+
return;
|
|
429
|
+
const amount = amountOf(item?.amount) || '0';
|
|
430
|
+
const origin = ro(buildNeedles(name));
|
|
431
|
+
rows.push({
|
|
432
|
+
subDataId: rows.length + 1,
|
|
433
|
+
mainDataId: 1,
|
|
434
|
+
reasons: ['合同标的列明该专项', '按折扣后实际金额计,无专属计价填 0'],
|
|
435
|
+
values: [name, amount],
|
|
436
|
+
origins: [origin ?? null, origin ?? null],
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
if (rows.length) {
|
|
440
|
+
subtables.push({
|
|
441
|
+
subFormId: spec.subFormId,
|
|
442
|
+
subFormName: spec.subFormName,
|
|
443
|
+
fields: [fields.solution, fields.solutionAmt],
|
|
444
|
+
rows,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return makePayload(spec, flow, fileId, results, subtables);
|
|
449
|
+
}
|
|
450
|
+
/** 契约锁 / 常规二次销售 / 老客户增值:只填文本、数字与已实测选项的复选框。 */
|
|
451
|
+
export function buildGeneric({ triage, fileId, flow, lines, sourceMap, fileIds }) {
|
|
452
|
+
const spec = BUILTIN[flow];
|
|
453
|
+
const fields = spec.fields;
|
|
454
|
+
const selects = spec.selects ?? {};
|
|
455
|
+
const elements = (triage.elements && typeof triage.elements === 'object') ? triage.elements : {};
|
|
456
|
+
const results = [];
|
|
457
|
+
const ro = (needles) => resolveOrigin(lines, needles, fileId, sourceMap, fileIds);
|
|
458
|
+
const add = (key, value, reason, origin) => {
|
|
459
|
+
const fieldInfo = fields[key];
|
|
460
|
+
if (!fieldInfo || isEmptyScalar(value))
|
|
461
|
+
return;
|
|
462
|
+
results.push({ fieldInfo, reason, value: String(value), origin: ro(origin) });
|
|
463
|
+
};
|
|
464
|
+
const addSelect = (key, value, reason, origin) => {
|
|
465
|
+
const fieldInfo = selects[key];
|
|
466
|
+
if (!fieldInfo || isEmptyScalar(value))
|
|
467
|
+
return;
|
|
468
|
+
results.push({ fieldInfo, reason, value: String(value), origin: ro(origin) });
|
|
469
|
+
};
|
|
470
|
+
// ① 合同文件:不写入 recognizeResult(附件只走流程组件 customParams)
|
|
471
|
+
// ② 文本类:流程标题优先取合同标题,抽不到用文件名兜底
|
|
472
|
+
const title = orElse(elements.title, elements.contractName);
|
|
473
|
+
if (pyTruthy(title)) {
|
|
474
|
+
add('title', title, '取合同标题', buildNeedles(title));
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
add('title', fileStem(triage), '取合同文件名(去后缀)', null);
|
|
478
|
+
}
|
|
479
|
+
const contractName = orElse(elements.contractName, elements.title);
|
|
480
|
+
add('contractName', contractName, '取合同名称', buildNeedles(contractName));
|
|
481
|
+
// ③ 数字类
|
|
482
|
+
const amount = amountOf(elements.totalAmount);
|
|
483
|
+
add('totalAmount', amount, '取合同总额并归一为数字', buildNeedles(amount) ?? buildNeedles(elements.totalAmount));
|
|
484
|
+
// ④ 联系 / 送达类文本
|
|
485
|
+
add('address', elements.address, '取合同约定联系/送达地址', buildNeedles(elements.address));
|
|
486
|
+
add('receiver', elements.contact, '取合同联系人', buildNeedles(elements.contact));
|
|
487
|
+
add('mobile', elements.phone, '取合同联系电话', buildNeedles(elements.phone));
|
|
488
|
+
// ⑤ 背景说明 / 对方签署人(有则填)
|
|
489
|
+
add('background', elements.background, '取合同背景说明', buildNeedles(elements.background));
|
|
490
|
+
add('partySigner', elements.partySigner, '取对方签署人', buildNeedles(elements.partySigner));
|
|
491
|
+
add('partyContact', elements.partyContact, '取对方签署人联系方式', buildNeedles(elements.partyContact));
|
|
492
|
+
// ⑥ 选项类字段:直接填中文选项值,不转选项 ID(2026-11-11 用户指定规则)
|
|
493
|
+
// 购买方式:有丙方/伙伴 → 通过伙伴签署,否则直签
|
|
494
|
+
addSelect('buyMode', orElse(elements.buyMode, pyTruthy(elements.partyC) ? '通过伙伴签署' : '直签'), '按合同签约结构判定购买方式', buildNeedles(elements.partyC));
|
|
495
|
+
// 我方签约公司:必须映射成下拉框可用选项值,禁止直接填乙方全称
|
|
496
|
+
const company = mapCompany(orElse(elements.ourCompany, elements.partyB));
|
|
497
|
+
addSelect('ourCompany', company, `乙方签约主体映射为下拉选项:${company || '未匹配'}`, buildNeedles(elements.partyB));
|
|
498
|
+
// 客户名称 / 最终用户:浏览型字段同样直接填中文全称
|
|
499
|
+
addSelect('finalUser', orElse(elements.finalUser, elements.partyA), '取合同甲方(最终用户)企业全称', buildNeedles(elements.partyA));
|
|
500
|
+
// 合同相关伙伴:有丙方/伙伴时填中文全称(写文本备份字段,浏览字段只读)
|
|
501
|
+
addSelect('partner', orElse(elements.partner, elements.partyC), '取合同丙方(伙伴)企业全称', buildNeedles(elements.partyC));
|
|
502
|
+
// 签约形式:合同明确电子签/契约锁才改,否则按纸质签署
|
|
503
|
+
let signForm = elements.signForm;
|
|
504
|
+
if (!pyTruthy(signForm)) {
|
|
505
|
+
const raw = norm(orElse(elements.rawSign, ''));
|
|
506
|
+
if (raw.includes('契约锁') && raw.includes('电子签'))
|
|
507
|
+
signForm = '双方电子签署(泛微契约锁平台双方电子签)';
|
|
508
|
+
else if (raw.includes('电子签'))
|
|
509
|
+
signForm = '双方电子签署';
|
|
510
|
+
else
|
|
511
|
+
signForm = '纸质签署';
|
|
512
|
+
}
|
|
513
|
+
addSelect('signForm', signForm, '按合同签署章节判定签约形式', ['本合同经甲乙双方盖章后生效', '盖章']);
|
|
514
|
+
// 合同签署日期:载明签订日期则指定,否则默认合同办理当天
|
|
515
|
+
const signDateNeedles = [...(buildNeedles(elements.signDate) ?? []), '签订时间'];
|
|
516
|
+
addSelect('signDateType', orElse(elements.signDateType, pyTruthy(elements.signDate) ? '指定签署日期' : '默认合同办理当天'), '合同载明签订日期则指定,否则默认合同办理当天', signDateNeedles);
|
|
517
|
+
// 合同签订方式:合同未约定签署顺序,属全文推导,无原文出处
|
|
518
|
+
addSelect('signWay', orElse(elements.signWay, '我方先盖章'), '合同未特别约定签署顺序,按我方先盖章', null);
|
|
519
|
+
// 其余选项字段只在合同有明确依据时填,无依据留空(不猜)
|
|
520
|
+
addSelect('contractType', elements.contractType, '按合同标的产品线判定合同类型', buildNeedles(elements.contractType));
|
|
521
|
+
addSelect('implParty', elements.implParty, '按合同实施主体判定实施方', buildNeedles(elements.implParty));
|
|
522
|
+
addSelect('relatedProduct', elements.relatedProduct, '按合同标的判定相关产品', buildNeedles(elements.relatedProduct));
|
|
523
|
+
addSelect('isXinChuang', elements.isXinChuang, '合同未涉及信创内容则不填', buildNeedles(elements.isXinChuang));
|
|
524
|
+
// ⑦ 合同购买内容(复选框):按正文语义命中勾选,命中不到整条不填
|
|
525
|
+
const checkbox = spec.checkbox;
|
|
526
|
+
if (checkbox) {
|
|
527
|
+
const hints = flow === '常规二次销售' ? CHECKBOX_HINTS_RESALE : CHECKBOX_HINTS_UPSALE;
|
|
528
|
+
const items = Array.isArray(elements.items) ? elements.items : [];
|
|
529
|
+
const itemNames = items.map((item) => truthyText(item?.name));
|
|
530
|
+
const blobParts = [
|
|
531
|
+
elements.title,
|
|
532
|
+
elements.contractName,
|
|
533
|
+
elements.background,
|
|
534
|
+
elements.serviceScope,
|
|
535
|
+
itemNames.join(' '),
|
|
536
|
+
].filter((part) => pyTruthy(part)).map((part) => String(part));
|
|
537
|
+
const blob = blobParts.join(' ');
|
|
538
|
+
const picked = [];
|
|
539
|
+
const hit = [];
|
|
540
|
+
for (const [name, keywords] of hints) {
|
|
541
|
+
if (keywords.some((keyword) => blob.includes(keyword))) {
|
|
542
|
+
picked.push(checkbox.options[name]);
|
|
543
|
+
hit.push(name);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (picked.length) {
|
|
547
|
+
add(checkbox.fieldKey, picked.join(','), `按合同标的关键词命中:${hit.join('、')}`, buildNeedles(itemNames) ?? buildNeedles(hit));
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return makePayload(spec, flow, fileId, results);
|
|
551
|
+
}
|
|
552
|
+
/** 无内置字段表时的兜底:只给顶层附件参数,不写识别记录。 */
|
|
553
|
+
export function buildMinimal(fileId, flow, workflowId, attachmentFieldId) {
|
|
554
|
+
return {
|
|
555
|
+
flow,
|
|
556
|
+
workflowId,
|
|
557
|
+
attachmentIds: fileId,
|
|
558
|
+
attachmentFieldId,
|
|
559
|
+
attachmentFileId: fileId,
|
|
560
|
+
recognizeResult: {
|
|
561
|
+
isSuccess: true,
|
|
562
|
+
mainTable: { rows: [{ mainDataId: 1, fieldResults: [] }] },
|
|
563
|
+
subTables: [],
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
/** 按「智能填单结果格式」§4 自检 origin;违规只告警,便于当场发现回归。 */
|
|
568
|
+
export function checkOrigins(payload, attachmentId) {
|
|
569
|
+
const warns = [];
|
|
570
|
+
const rows = payload.recognizeResult.mainTable.rows ?? [];
|
|
571
|
+
for (const row of rows) {
|
|
572
|
+
for (const result of row.fieldResults ?? []) {
|
|
573
|
+
const fieldInfo = result.fieldInfo || '';
|
|
574
|
+
const origins = result.origin;
|
|
575
|
+
if (origins === null || origins === undefined)
|
|
576
|
+
continue;
|
|
577
|
+
if (!Array.isArray(origins) || !origins.length) {
|
|
578
|
+
warns.push(`${fieldInfo}: origin 必须是非空数组或 null`);
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
for (const origin of origins) {
|
|
582
|
+
if (origin === null || origin === undefined) {
|
|
583
|
+
warns.push(`${fieldInfo}: 禁止输出 [null]`);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
const text = String(origin);
|
|
587
|
+
const sepIndex = text.indexOf('#');
|
|
588
|
+
const sideId = sepIndex >= 0 ? text.slice(0, sepIndex) : text;
|
|
589
|
+
const snippet = sepIndex >= 0 ? text.slice(sepIndex + 1) : '';
|
|
590
|
+
if (sideId === 'att001') {
|
|
591
|
+
warns.push(`${fieldInfo}: 前缀写死 att001,应为实际附件 ID`);
|
|
592
|
+
}
|
|
593
|
+
else if (attachmentId && sideId !== String(attachmentId)) {
|
|
594
|
+
warns.push(`${fieldInfo}: 前缀应为实际附件 ID`);
|
|
595
|
+
}
|
|
596
|
+
if (!snippet.trim())
|
|
597
|
+
warns.push(`${fieldInfo}: 原文片段为空`);
|
|
598
|
+
if (snippet.includes('...') || snippet.includes('…'))
|
|
599
|
+
warns.push(`${fieldInfo}: 原文片段被截断`);
|
|
600
|
+
if (NUM_PREFIX.test(snippet))
|
|
601
|
+
warns.push(`${fieldInfo}: 原文片段以序号开头`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return warns;
|
|
606
|
+
}
|
|
607
|
+
/** 统一入口:按流程分派到对应字段表。 */
|
|
608
|
+
export function buildPayload(args) {
|
|
609
|
+
const { flow } = args;
|
|
610
|
+
if (!Object.prototype.hasOwnProperty.call(BUILTIN, flow)) {
|
|
611
|
+
throw contractValidationError('flow_not_builtin', `流程「${flow}」无内置字段表:${Object.keys(BUILTIN).join(' / ')}`);
|
|
612
|
+
}
|
|
613
|
+
const payload = flow === '新客户' ? buildNewCustomer(args) : buildGeneric(args);
|
|
614
|
+
const warns = checkOrigins(payload, args.fileId);
|
|
615
|
+
return { payload, warns };
|
|
616
|
+
}
|
|
617
|
+
function isFile(path) {
|
|
618
|
+
try {
|
|
619
|
+
return existsSync(path) && statSync(path).isFile();
|
|
620
|
+
}
|
|
621
|
+
catch {
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* 生成 recognizeResult。
|
|
627
|
+
*
|
|
628
|
+
* 产出可直接作为 `flow save-recognize-record` 的入参;`out` 指定时同时落盘。
|
|
629
|
+
* `originWarnings` 非空表示出处规则有疑似回归,需人工核对。
|
|
630
|
+
*/
|
|
631
|
+
export const contractElementsBuildOperation = {
|
|
632
|
+
name: 'contract.elements.build',
|
|
633
|
+
async execute(input) {
|
|
634
|
+
const triagePath = resolve(String(input.triage ?? '').trim());
|
|
635
|
+
if (!isFile(triagePath)) {
|
|
636
|
+
throw contractValidationError('triage_not_found', `triage.json 不存在:${triagePath}`);
|
|
637
|
+
}
|
|
638
|
+
let triage;
|
|
639
|
+
try {
|
|
640
|
+
const parsed = JSON.parse(readFileSync(triagePath, 'utf8').replace(/^\uFEFF/u, ''));
|
|
641
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
642
|
+
throw new Error('根节点必须是对象');
|
|
643
|
+
triage = parsed;
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
647
|
+
throw contractValidationError('triage_invalid', `triage.json 无法解析:${message}`);
|
|
648
|
+
}
|
|
649
|
+
const fileId = String(input.fileId ?? '').trim();
|
|
650
|
+
if (!fileId)
|
|
651
|
+
throw contractValidationError('file_id_required', '缺少 fileId(flow.launch 返回的 workflow fileId)');
|
|
652
|
+
const flow = String(input.flow ?? '').trim();
|
|
653
|
+
if (!flow)
|
|
654
|
+
throw contractValidationError('flow_required', '缺少 flow(新客户 / 契约锁 / 常规二次销售 / 老客户增值)');
|
|
655
|
+
const sourceText = String(input.sourceText ?? '').trim()
|
|
656
|
+
? resolve(String(input.sourceText).trim())
|
|
657
|
+
: join(dirname(triagePath), 'contract_text.txt');
|
|
658
|
+
const lines = loadSourceLines(sourceText);
|
|
659
|
+
const outDir = dirname(triagePath);
|
|
660
|
+
let sourceMap = loadSourceMap(outDir);
|
|
661
|
+
let fileIds = Array.isArray(input.fileIds) && input.fileIds.length
|
|
662
|
+
? input.fileIds.map((item) => String(item))
|
|
663
|
+
: null;
|
|
664
|
+
// 多文件:附件 ID 数量与 text_sources.json 的文件数不一致时,映射不可信,整体丢弃
|
|
665
|
+
if (sourceMap && fileIds && fileIds.length !== (sourceMap.files ?? []).length) {
|
|
666
|
+
sourceMap = null;
|
|
667
|
+
fileIds = null;
|
|
668
|
+
}
|
|
669
|
+
const attachmentFieldId = String(input.attachmentFieldId ?? '').trim();
|
|
670
|
+
const workflowId = String(input.workflowId ?? '').trim();
|
|
671
|
+
let payload;
|
|
672
|
+
let warns = [];
|
|
673
|
+
let mode;
|
|
674
|
+
if (Object.prototype.hasOwnProperty.call(BUILTIN, flow)) {
|
|
675
|
+
const built = buildPayload({ triage, fileId, flow, lines, sourceMap, fileIds });
|
|
676
|
+
payload = built.payload;
|
|
677
|
+
warns = built.warns;
|
|
678
|
+
mode = 'builtin';
|
|
679
|
+
}
|
|
680
|
+
else if (attachmentFieldId) {
|
|
681
|
+
// 无内置字段表:只登记合同文件字段,保证 customParams 一定带上「附件字段:fileId」
|
|
682
|
+
payload = buildMinimal(fileId, flow, workflowId, attachmentFieldId);
|
|
683
|
+
mode = 'minimal';
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
throw contractValidationError('no_builtin_table', `流程「${flow}」暂无内置字段表;请改用 recognizeFile 提供 recognizeResult,或补 attachmentFieldId 走附件兜底`);
|
|
687
|
+
}
|
|
688
|
+
let output;
|
|
689
|
+
const outPath = String(input.out ?? '').trim();
|
|
690
|
+
if (outPath) {
|
|
691
|
+
output = resolve(outPath);
|
|
692
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
693
|
+
writeFileSync(output, JSON.stringify(payload), 'utf8');
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
status: 'COMPLETE',
|
|
697
|
+
data: {
|
|
698
|
+
ok: true,
|
|
699
|
+
flow,
|
|
700
|
+
mode,
|
|
701
|
+
fieldCount: payload.recognizeResult.mainTable.rows[0].fieldResults.length,
|
|
702
|
+
attachmentFieldId: payload.attachmentFieldId,
|
|
703
|
+
sourceLines: lines.length,
|
|
704
|
+
originWarnings: warns,
|
|
705
|
+
payload,
|
|
706
|
+
...(output ? { output } : {}),
|
|
707
|
+
note: mode === 'minimal'
|
|
708
|
+
? '无内置字段表:fieldResults 为空,调用方应跳过 save-recognize-record,附件由 customParams 透传'
|
|
709
|
+
: '附件字段不写入 recognizeResult;顶层 attachmentIds/attachmentFieldId 仅供 customParams 使用',
|
|
710
|
+
},
|
|
711
|
+
};
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
export const contractElementsBuildOperations = [contractElementsBuildOperation];
|