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,438 @@
|
|
|
1
|
+
import { invoiceValidationError } from '../errors.js';
|
|
2
|
+
import { asPositiveString, assertBusinessSuccess, normalizeFids, workflow } from './shared.js';
|
|
3
|
+
const RELATION_SAVE_PATH = '/api/esb/server/event/triggerActionFlow';
|
|
4
|
+
const RELATION_SAVE_FLOW_ID = '908258457763844096';
|
|
5
|
+
const RELATION_SAVE_TIMEOUT_MS = 15_000;
|
|
6
|
+
const RELATION_SAVED_MESSAGE = '关联成功';
|
|
7
|
+
const RELATION_LIST_PATH = '/api/ebuilder/form/eblist/getData';
|
|
8
|
+
const RELATION_PAGE_ID = '1336156118298222893';
|
|
9
|
+
const RELATION_COMP_ID = 'deb95f0098754d498843187dcbe50093';
|
|
10
|
+
const RELATION_TABLE_UID = 'ef3603435af34e8aa635374c6610d8ab';
|
|
11
|
+
const RELATION_PAGE_SIZE = 10;
|
|
12
|
+
const RELATION_CONCURRENCY = 4;
|
|
13
|
+
/** 「发票附加信息表」返回行的字段 id。 */
|
|
14
|
+
const RELATION_FIELD = {
|
|
15
|
+
fid: '1336536987380547612',
|
|
16
|
+
customerId: '1336526894274510993',
|
|
17
|
+
customerName: '1336526894274510994',
|
|
18
|
+
projectId: '1336526894274510991',
|
|
19
|
+
projectName: '1336526894274510992',
|
|
20
|
+
preApproval: '1336156560590790875',
|
|
21
|
+
};
|
|
22
|
+
const RELATION_SEARCH_PAGE_SIZE = 20;
|
|
23
|
+
const CUSTOMER_SEARCH_PATH = '/api/ebuilder/coms/nlist/getData';
|
|
24
|
+
const CUSTOMER_SEARCH_PAGE_ID = '1218181956452048911';
|
|
25
|
+
const CUSTOMER_SEARCH_COMP_ID = 'c39b9e14c0034336adf9e9bc39aeed75';
|
|
26
|
+
const CUSTOMER_SEARCH_WORKFLOW_ID = '100003460000000060';
|
|
27
|
+
const CUSTOMER_OBJ_ID = '1173221220888059964';
|
|
28
|
+
/** 客户表「名称」字段 id,返回行里也用它作客户名称的键。 */
|
|
29
|
+
const CUSTOMER_NAME_FIELD = '1173221220888062665';
|
|
30
|
+
const PROJECT_SEARCH_PATH = '/api/ebuilder/form/common/browser/data/ebuilder';
|
|
31
|
+
/** 项目浏览框「项目名称」列的 id,快速搜索用 `field_` 前缀。 */
|
|
32
|
+
const PROJECT_NAME_FIELD = '1020275734718578690';
|
|
33
|
+
const PROJECT_FORM_PARAM = JSON.stringify({
|
|
34
|
+
formId: '100003660000000007',
|
|
35
|
+
layoutId: '925333107626672135',
|
|
36
|
+
fieldId: '100003720000006720',
|
|
37
|
+
filterItems: [],
|
|
38
|
+
module: 'workflow',
|
|
39
|
+
dataDetails: [],
|
|
40
|
+
templateId: '',
|
|
41
|
+
});
|
|
42
|
+
/** 浏览按钮展示名末尾的摘要,如「 (相关客户:, 相关项目:, 起始日期:…)」,不属于流程标题。 */
|
|
43
|
+
const BROWSE_SUMMARY_SUFFIX = /\s+\([^()]*[::][^()]*\)\s*$/u;
|
|
44
|
+
function asRecord(value) {
|
|
45
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
46
|
+
}
|
|
47
|
+
function text(value) {
|
|
48
|
+
if (value === undefined || value === null || typeof value === 'object')
|
|
49
|
+
return '';
|
|
50
|
+
return String(value).trim();
|
|
51
|
+
}
|
|
52
|
+
function errorMessage(error) {
|
|
53
|
+
return error instanceof Error ? error.message : String(error);
|
|
54
|
+
}
|
|
55
|
+
function optionalText(value, name) {
|
|
56
|
+
if (value === undefined || value === null || value === '')
|
|
57
|
+
return '';
|
|
58
|
+
if (typeof value !== 'string' || !value.trim())
|
|
59
|
+
throw invoiceValidationError('input_invalid', `${name} 必须是非空字符串`);
|
|
60
|
+
return value.trim();
|
|
61
|
+
}
|
|
62
|
+
function optionalId(value, name) {
|
|
63
|
+
if (value === undefined || value === null || value === '')
|
|
64
|
+
return '';
|
|
65
|
+
return asPositiveString(typeof value === 'number' ? String(value) : value, name);
|
|
66
|
+
}
|
|
67
|
+
function idNamePair(input, idKey, nameKey) {
|
|
68
|
+
const id = optionalId(input[idKey], idKey);
|
|
69
|
+
const name = optionalText(input[nameKey], nameKey);
|
|
70
|
+
if (Boolean(id) !== Boolean(name)) {
|
|
71
|
+
throw invoiceValidationError('input_invalid', `${idKey} 与 ${nameKey} 必须同时提供`);
|
|
72
|
+
}
|
|
73
|
+
return [id, name];
|
|
74
|
+
}
|
|
75
|
+
function relationValues(input) {
|
|
76
|
+
const [customerId, customerName] = idNamePair(input, 'customerId', 'customerName');
|
|
77
|
+
const [projectId, projectName] = idNamePair(input, 'projectId', 'projectName');
|
|
78
|
+
const flowId = optionalId(input.flowId, 'flowId');
|
|
79
|
+
if (!customerId && !projectId && !flowId) {
|
|
80
|
+
throw invoiceValidationError('input_invalid', '相关客户、相关项目、事前申请(flowId)至少提供一项');
|
|
81
|
+
}
|
|
82
|
+
return { customerId, customerName, projectId, projectName, flowId };
|
|
83
|
+
}
|
|
84
|
+
/** 第 1 个先单独跑(顺带取到发票 Token),其余并发,结果按入参顺序返回。 */
|
|
85
|
+
async function mapInOrder(items, fn) {
|
|
86
|
+
const results = new Array(items.length);
|
|
87
|
+
if (items.length === 0)
|
|
88
|
+
return results;
|
|
89
|
+
results[0] = await fn(items[0]);
|
|
90
|
+
let next = 1;
|
|
91
|
+
const workers = Array.from({ length: Math.min(RELATION_CONCURRENCY, items.length - 1) }, async () => {
|
|
92
|
+
while (next < items.length) {
|
|
93
|
+
const index = next;
|
|
94
|
+
next += 1;
|
|
95
|
+
results[index] = await fn(items[index]);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
await Promise.all(workers);
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
function saveOutcome(value) {
|
|
102
|
+
const record = asRecord(value);
|
|
103
|
+
const message = text(asRecord(asRecord(asRecord(asRecord(record.actionData).responseData).customData).mainTable).msg);
|
|
104
|
+
if (Number(record.resultCode) === 200 && message.includes(RELATION_SAVED_MESSAGE))
|
|
105
|
+
return { saved: true, message };
|
|
106
|
+
return {
|
|
107
|
+
saved: false,
|
|
108
|
+
message: message || text(record.resultMsg) || `动作流没有返回「${RELATION_SAVED_MESSAGE}」(resultCode=${text(record.resultCode) || '无'})`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 上传发票时登记相关客户 / 相关项目 / 事前申请,供 AI 报销自动带出。
|
|
113
|
+
* 尽力而为:每张发票触发一次 ESB 动作流,失败只记在 results 里,不抛错、不重试。
|
|
114
|
+
*/
|
|
115
|
+
export class InvoiceReimRelationSaveOperation {
|
|
116
|
+
name = 'invoice.reim.relation.save';
|
|
117
|
+
async execute(input, { host }) {
|
|
118
|
+
const fids = normalizeFids(input);
|
|
119
|
+
const values = relationValues(input);
|
|
120
|
+
const results = await mapInOrder(fids, async (fid) => {
|
|
121
|
+
try {
|
|
122
|
+
const result = await host.invoiceRequest({
|
|
123
|
+
path: RELATION_SAVE_PATH,
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
|
126
|
+
body: {
|
|
127
|
+
customParams: {
|
|
128
|
+
mainTable: {
|
|
129
|
+
customerId: values.customerId,
|
|
130
|
+
customerName: values.customerName,
|
|
131
|
+
invoiceId: fid,
|
|
132
|
+
projectName: values.projectName,
|
|
133
|
+
projectId: values.projectId,
|
|
134
|
+
flowId: values.flowId,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
moduleSource: '-1',
|
|
138
|
+
esbFlowId: RELATION_SAVE_FLOW_ID,
|
|
139
|
+
},
|
|
140
|
+
timeoutMs: RELATION_SAVE_TIMEOUT_MS,
|
|
141
|
+
operation: this.name,
|
|
142
|
+
});
|
|
143
|
+
return { fid, ...saveOutcome(result) };
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
return { fid, saved: false, message: errorMessage(error) };
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const savedCount = results.filter((item) => item.saved).length;
|
|
150
|
+
const state = savedCount === results.length ? 'COMPLETE' : 'PARTIAL';
|
|
151
|
+
return {
|
|
152
|
+
status: state,
|
|
153
|
+
data: {
|
|
154
|
+
saved: savedCount === results.length,
|
|
155
|
+
savedCount,
|
|
156
|
+
failedCount: results.length - savedCount,
|
|
157
|
+
results,
|
|
158
|
+
relation: values,
|
|
159
|
+
workflow: workflow(this.name, state),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function relationFilter(fid) {
|
|
165
|
+
return [
|
|
166
|
+
{
|
|
167
|
+
conditionType: 'or',
|
|
168
|
+
dataType: 'field',
|
|
169
|
+
id: 'a695d8dd7e0044bd872c51aa7911aa3d',
|
|
170
|
+
conditionComId: `${RELATION_COMP_ID}_quick_EXCLUDECACHE`,
|
|
171
|
+
filterFields: [{
|
|
172
|
+
compId: RELATION_COMP_ID,
|
|
173
|
+
compType: 'Text',
|
|
174
|
+
dataset: {
|
|
175
|
+
isPhysical: true,
|
|
176
|
+
ebuilderDataConfig: { dataSetup: {}, type: 'FORM' },
|
|
177
|
+
detailTable: false,
|
|
178
|
+
groupId: 'weaver-ebuilder-form-service',
|
|
179
|
+
usage: 'all',
|
|
180
|
+
appId: '1120921709084680312',
|
|
181
|
+
id: '1336156113810318140',
|
|
182
|
+
text: '发票附加信息表',
|
|
183
|
+
type: 'LOGIC',
|
|
184
|
+
objType: 'physical',
|
|
185
|
+
},
|
|
186
|
+
fieldName: `field_${RELATION_FIELD.fid}`,
|
|
187
|
+
id: RELATION_FIELD.fid,
|
|
188
|
+
objId: '1336156113810318140',
|
|
189
|
+
type: 'String',
|
|
190
|
+
text: '单子发票ID',
|
|
191
|
+
}],
|
|
192
|
+
value: fid,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
conditionComId: `${RELATION_COMP_ID}_filter_EXCLUDECACHE`,
|
|
196
|
+
conditionType: 'and',
|
|
197
|
+
dataType: 'classification',
|
|
198
|
+
id: 'a8c660ee7bf942148dc44efd5ac498d0',
|
|
199
|
+
useConfig: true,
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
function idNameOf(row, idField, nameField) {
|
|
204
|
+
const id = text(row[idField]);
|
|
205
|
+
if (!/^\d+$/u.test(id))
|
|
206
|
+
return null;
|
|
207
|
+
const name = text(row[nameField]);
|
|
208
|
+
return { id, name, value: name ? `${name}(${id})` : id };
|
|
209
|
+
}
|
|
210
|
+
export function stripBrowseSummary(name) {
|
|
211
|
+
return name.replace(BROWSE_SUMMARY_SUFFIX, '').trim();
|
|
212
|
+
}
|
|
213
|
+
function preApprovalOf(value) {
|
|
214
|
+
const item = asRecord(Array.isArray(value) ? value[0] : value);
|
|
215
|
+
const requestId = text(item.id);
|
|
216
|
+
if (!/^\d+$/u.test(requestId))
|
|
217
|
+
return null;
|
|
218
|
+
const displayName = text(item.name);
|
|
219
|
+
const requestName = stripBrowseSummary(displayName);
|
|
220
|
+
return {
|
|
221
|
+
requestId,
|
|
222
|
+
requestName,
|
|
223
|
+
value: requestName ? `${requestName}(${requestId})` : requestId,
|
|
224
|
+
displayName,
|
|
225
|
+
createTime: text(asRecord(item.custom).createDateTime) || null,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** 同一张发票登记过多次时取最新一条(create_time 是「YYYY-MM-DD HH:mm:ss」,可按字符串比较)。 */
|
|
229
|
+
export function relationItemFromRows(fid, rows) {
|
|
230
|
+
const matched = rows
|
|
231
|
+
.map(asRecord)
|
|
232
|
+
.filter((row) => text(row[RELATION_FIELD.fid]) === fid)
|
|
233
|
+
.sort((a, b) => text(b.create_time).localeCompare(text(a.create_time)));
|
|
234
|
+
const row = matched[0];
|
|
235
|
+
if (!row)
|
|
236
|
+
return { fid, found: false, customer: null, project: null, preApproval: null, recordedAt: null };
|
|
237
|
+
return {
|
|
238
|
+
fid,
|
|
239
|
+
found: true,
|
|
240
|
+
customer: idNameOf(row, RELATION_FIELD.customerId, RELATION_FIELD.customerName),
|
|
241
|
+
project: idNameOf(row, RELATION_FIELD.projectId, RELATION_FIELD.projectName),
|
|
242
|
+
preApproval: preApprovalOf(row[RELATION_FIELD.preApproval]),
|
|
243
|
+
recordedAt: text(row.create_time) || null,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function groupByValue(items, pick) {
|
|
247
|
+
const groups = new Map();
|
|
248
|
+
for (const item of items) {
|
|
249
|
+
const value = pick(item)?.value;
|
|
250
|
+
if (!value)
|
|
251
|
+
continue;
|
|
252
|
+
groups.set(value, [...(groups.get(value) ?? []), item.fid]);
|
|
253
|
+
}
|
|
254
|
+
return [...groups.entries()].map(([value, fids]) => ({ value, fids }));
|
|
255
|
+
}
|
|
256
|
+
async function relationRows(host, fid, operation) {
|
|
257
|
+
const result = await host.invoiceMultipartRequest({
|
|
258
|
+
path: RELATION_LIST_PATH,
|
|
259
|
+
method: 'POST',
|
|
260
|
+
headers: { ebbusinessid: RELATION_PAGE_ID },
|
|
261
|
+
fields: {
|
|
262
|
+
filter: relationFilter(fid),
|
|
263
|
+
compId: RELATION_COMP_ID,
|
|
264
|
+
pageId: RELATION_PAGE_ID,
|
|
265
|
+
pageNo: '1',
|
|
266
|
+
pageSize: String(RELATION_PAGE_SIZE),
|
|
267
|
+
tableuid: RELATION_TABLE_UID,
|
|
268
|
+
},
|
|
269
|
+
operation,
|
|
270
|
+
});
|
|
271
|
+
assertBusinessSuccess(result, 'reim_relation_query_failed', `查询发票 ${fid} 的关联信息失败`);
|
|
272
|
+
const list = asRecord(asRecord(result).data).list;
|
|
273
|
+
if (!Array.isArray(list))
|
|
274
|
+
throw new Error(`发票 ${fid} 的关联信息返回缺少 data.list`);
|
|
275
|
+
return list;
|
|
276
|
+
}
|
|
277
|
+
function relationSearchTarget(value) {
|
|
278
|
+
if (value === 'customer' || value === 'project')
|
|
279
|
+
return value;
|
|
280
|
+
throw invoiceValidationError('input_invalid', 'target 只能是 customer(相关客户)或 project(相关项目)');
|
|
281
|
+
}
|
|
282
|
+
function customerFilter(keywords) {
|
|
283
|
+
return [
|
|
284
|
+
{
|
|
285
|
+
conditionType: 'or',
|
|
286
|
+
dataType: 'field',
|
|
287
|
+
id: 'd030a0a7b33e48e697277d30086126dc',
|
|
288
|
+
conditionComId: `${CUSTOMER_SEARCH_COMP_ID}_quick_EXCLUDECACHE`,
|
|
289
|
+
filterFields: [{
|
|
290
|
+
compId: CUSTOMER_SEARCH_COMP_ID,
|
|
291
|
+
compType: 'Text',
|
|
292
|
+
dataset: {
|
|
293
|
+
isPhysical: true,
|
|
294
|
+
ebuilderDataConfig: { dataSetup: {}, type: 'FORM' },
|
|
295
|
+
detailTable: false,
|
|
296
|
+
groupId: 'weaver-ebuilder-form-service',
|
|
297
|
+
usage: 'all',
|
|
298
|
+
appId: '980180677416657173',
|
|
299
|
+
id: CUSTOMER_OBJ_ID,
|
|
300
|
+
text: '客户',
|
|
301
|
+
type: 'LOGIC',
|
|
302
|
+
objType: 'physical',
|
|
303
|
+
},
|
|
304
|
+
fieldName: `field_${CUSTOMER_NAME_FIELD}`,
|
|
305
|
+
id: CUSTOMER_NAME_FIELD,
|
|
306
|
+
objId: CUSTOMER_OBJ_ID,
|
|
307
|
+
type: 'String',
|
|
308
|
+
text: '名称',
|
|
309
|
+
}],
|
|
310
|
+
value: keywords,
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
conditionComId: `${CUSTOMER_SEARCH_COMP_ID}_filter_EXCLUDECACHE`,
|
|
314
|
+
conditionType: 'and',
|
|
315
|
+
dataType: 'classification',
|
|
316
|
+
id: 'f27488c792f44756b7ef1065f7735fc1',
|
|
317
|
+
useConfig: true,
|
|
318
|
+
},
|
|
319
|
+
];
|
|
320
|
+
}
|
|
321
|
+
async function searchCustomers(host, keywords, operation) {
|
|
322
|
+
const result = await host.invoiceMultipartRequest({
|
|
323
|
+
path: CUSTOMER_SEARCH_PATH,
|
|
324
|
+
method: 'POST',
|
|
325
|
+
headers: { ebbusinessid: CUSTOMER_SEARCH_PAGE_ID },
|
|
326
|
+
fields: {
|
|
327
|
+
workflowId: CUSTOMER_SEARCH_WORKFLOW_ID,
|
|
328
|
+
isCreate: '1',
|
|
329
|
+
filter: customerFilter(keywords),
|
|
330
|
+
compId: CUSTOMER_SEARCH_COMP_ID,
|
|
331
|
+
pageId: CUSTOMER_SEARCH_PAGE_ID,
|
|
332
|
+
pageNo: '1',
|
|
333
|
+
pageSize: String(RELATION_SEARCH_PAGE_SIZE),
|
|
334
|
+
},
|
|
335
|
+
operation,
|
|
336
|
+
});
|
|
337
|
+
assertBusinessSuccess(result, 'reim_relation_search_failed', '搜索相关客户失败');
|
|
338
|
+
const list = asRecord(asRecord(result).data).list;
|
|
339
|
+
return (Array.isArray(list) ? list : []).map((row) => {
|
|
340
|
+
const record = asRecord(row);
|
|
341
|
+
return { id: text(record.id), name: text(record[CUSTOMER_NAME_FIELD]) };
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
async function searchProjects(host, keywords, operation) {
|
|
345
|
+
const result = await host.invoiceRequest({
|
|
346
|
+
path: PROJECT_SEARCH_PATH,
|
|
347
|
+
method: 'POST',
|
|
348
|
+
body: {
|
|
349
|
+
browserMultiple: false,
|
|
350
|
+
current: 1,
|
|
351
|
+
pageSize: RELATION_SEARCH_PAGE_SIZE,
|
|
352
|
+
quickSearchDatas: { [`field_${PROJECT_NAME_FIELD}`]: keywords },
|
|
353
|
+
formParam: PROJECT_FORM_PARAM,
|
|
354
|
+
},
|
|
355
|
+
operation,
|
|
356
|
+
});
|
|
357
|
+
assertBusinessSuccess(result, 'reim_relation_search_failed', '搜索相关项目失败');
|
|
358
|
+
const rows = asRecord(asRecord(result).data).data;
|
|
359
|
+
return (Array.isArray(rows) ? rows : [])
|
|
360
|
+
.map(asRecord)
|
|
361
|
+
.filter((row) => row.disabled !== true)
|
|
362
|
+
.map((row) => ({ id: text(row.id), name: text(row.content) || text(row[PROJECT_NAME_FIELD]) }));
|
|
363
|
+
}
|
|
364
|
+
function uniqueValidItems(items) {
|
|
365
|
+
const seen = new Set();
|
|
366
|
+
return items.filter((item) => {
|
|
367
|
+
if (!/^\d+$/u.test(item.id) || !item.name || seen.has(item.id))
|
|
368
|
+
return false;
|
|
369
|
+
seen.add(item.id);
|
|
370
|
+
return true;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* 上传发票登记关联信息时,按用户说的名称模糊搜索相关客户 / 相关项目,只返回 id 和名称。
|
|
375
|
+
* 不依赖报销表单:客户走客户列表,项目走项目浏览框。
|
|
376
|
+
*/
|
|
377
|
+
export class InvoiceReimRelationSearchOperation {
|
|
378
|
+
name = 'invoice.reim.relation.search';
|
|
379
|
+
async execute(input, { host }) {
|
|
380
|
+
const target = relationSearchTarget(input.target);
|
|
381
|
+
const keywords = optionalText(input.keywords, 'keywords');
|
|
382
|
+
if (!keywords)
|
|
383
|
+
throw invoiceValidationError('input_invalid', 'keywords 必须是非空字符串');
|
|
384
|
+
const found = target === 'customer'
|
|
385
|
+
? await searchCustomers(host, keywords, this.name)
|
|
386
|
+
: await searchProjects(host, keywords, this.name);
|
|
387
|
+
const items = uniqueValidItems(found);
|
|
388
|
+
const exact = items.filter((item) => item.name === keywords);
|
|
389
|
+
const match = items.length === 0 ? 'none' : items.length === 1 ? 'unique' : 'multiple';
|
|
390
|
+
return {
|
|
391
|
+
status: 'COMPLETE',
|
|
392
|
+
data: {
|
|
393
|
+
target,
|
|
394
|
+
keywords,
|
|
395
|
+
match,
|
|
396
|
+
items,
|
|
397
|
+
selected: items.length === 1 ? items[0] : exact.length === 1 ? exact[0] : null,
|
|
398
|
+
workflow: workflow(this.name, 'COMPLETE'),
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* AI 报销时按发票读回上传时登记的相关客户 / 相关项目 / 事前申请。
|
|
405
|
+
* 单张查询失败记在 failed 里,不抛错;调用方按「没有登记」处理。
|
|
406
|
+
*/
|
|
407
|
+
export class InvoiceReimRelationListOperation {
|
|
408
|
+
name = 'invoice.reim.relation.list';
|
|
409
|
+
async execute(input, { host }) {
|
|
410
|
+
const fids = normalizeFids(input);
|
|
411
|
+
const queried = await mapInOrder(fids, async (fid) => {
|
|
412
|
+
try {
|
|
413
|
+
return { ok: true, item: relationItemFromRows(fid, await relationRows(host, fid, this.name)) };
|
|
414
|
+
}
|
|
415
|
+
catch (error) {
|
|
416
|
+
return { ok: false, failure: { fid, error: errorMessage(error) } };
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
const items = queried.flatMap((entry) => (entry.ok ? [entry.item] : []));
|
|
420
|
+
const failed = queried.flatMap((entry) => (entry.ok ? [] : [entry.failure]));
|
|
421
|
+
const found = items.filter((item) => item.found).length;
|
|
422
|
+
const state = failed.length ? 'PARTIAL' : 'COMPLETE';
|
|
423
|
+
return {
|
|
424
|
+
status: state,
|
|
425
|
+
data: {
|
|
426
|
+
items,
|
|
427
|
+
groups: {
|
|
428
|
+
customers: groupByValue(items, (item) => item.customer),
|
|
429
|
+
projects: groupByValue(items, (item) => item.project),
|
|
430
|
+
preApprovals: groupByValue(items, (item) => item.preApproval),
|
|
431
|
+
},
|
|
432
|
+
failed,
|
|
433
|
+
summary: { requested: fids.length, found, notFound: items.length - found, failed: failed.length },
|
|
434
|
+
workflow: workflow(this.name, state),
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
@@ -174,9 +174,8 @@ export function normalizeFids(input) {
|
|
|
174
174
|
return [asPositiveString(String(input.fid), 'fid')];
|
|
175
175
|
return normalizeIdList(input.fids, 'fids');
|
|
176
176
|
}
|
|
177
|
-
export function reqBase(
|
|
178
|
-
|
|
179
|
-
return { trace: numericTrace ? trace : String(trace), dev: 1 };
|
|
177
|
+
export function reqBase() {
|
|
178
|
+
return { trace: String(Date.now()), dev: 1 };
|
|
180
179
|
}
|
|
181
180
|
function canonicalJson(value) {
|
|
182
181
|
if (Array.isArray(value))
|
|
@@ -337,28 +336,13 @@ export function preview(info, baseUrl) {
|
|
|
337
336
|
...(baseUrl && fid ? { detailUrl: invoiceDetailUrl(baseUrl, fid) } : {}),
|
|
338
337
|
};
|
|
339
338
|
}
|
|
340
|
-
export function validationPreview(info, scope, targetFid, baseUrl) {
|
|
341
|
-
const p = info?.comm_info?.pro || {};
|
|
342
|
-
const item = preview(info, baseUrl);
|
|
343
|
-
return {
|
|
344
|
-
...item,
|
|
345
|
-
fid: targetFid,
|
|
346
|
-
targetFid,
|
|
347
|
-
resultFid: item.fid,
|
|
348
|
-
scope,
|
|
349
|
-
validation: p.valid,
|
|
350
|
-
invoiceStatus: p.status,
|
|
351
|
-
saved: false,
|
|
352
|
-
...(baseUrl && targetFid ? { detailUrl: invoiceDetailUrl(baseUrl, targetFid) } : {}),
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
339
|
export function workflow(name, state) {
|
|
356
340
|
return { workflow: name, version: 1, state };
|
|
357
341
|
}
|
|
358
342
|
function stringOrEmpty(value) {
|
|
359
343
|
return value === undefined || value === null ? '' : String(value);
|
|
360
344
|
}
|
|
361
|
-
function numberOrZero(value) {
|
|
345
|
+
export function numberOrZero(value) {
|
|
362
346
|
const parsed = Number(value);
|
|
363
347
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
364
348
|
}
|
|
@@ -1,91 +1,127 @@
|
|
|
1
|
-
import { InvoiceCliError } from '../errors.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { InvoiceCliError, invoicePartialError, isInvoiceNetworkError } from '../errors.js';
|
|
2
|
+
import { parseInvoiceExt } from '../invoice-record.js';
|
|
3
|
+
import { importSource, invoiceDetailUrl, numberOrZero, workflow } from './shared.js';
|
|
4
|
+
/** 这些 ext 键只是印章、大写金额、版式类标记,对理解发票没有帮助。 */
|
|
5
|
+
const EXT_NOISE_KEYS = new Set([
|
|
6
|
+
'totalBig',
|
|
7
|
+
'hdlist',
|
|
8
|
+
'corp_seal',
|
|
9
|
+
'company_seal_mark',
|
|
10
|
+
'agent_mark',
|
|
11
|
+
'form_type',
|
|
12
|
+
'code_confirm',
|
|
13
|
+
'vehicle_mark',
|
|
14
|
+
]);
|
|
15
|
+
function asRecord(value) {
|
|
16
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
17
|
+
}
|
|
18
|
+
function text(value) {
|
|
19
|
+
return value === undefined || value === null ? '' : String(value).trim();
|
|
20
|
+
}
|
|
21
|
+
/** 递归去掉 null、空串、空数组和空对象;`'0'`、`false` 这类票面值保留。 */
|
|
22
|
+
function compact(value) {
|
|
23
|
+
if (value === null || value === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (typeof value === 'string')
|
|
26
|
+
return value.trim() ? value : undefined;
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
const items = value.map(compact).filter((item) => item !== undefined);
|
|
29
|
+
return items.length ? items : undefined;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === 'object') {
|
|
32
|
+
const entries = Object.entries(value)
|
|
33
|
+
.map(([key, item]) => [key, compact(item)])
|
|
34
|
+
.filter(([, item]) => item !== undefined);
|
|
35
|
+
return entries.length ? Object.fromEntries(entries) : undefined;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
function usefulExt(rawExt, cname) {
|
|
40
|
+
const ext = { ...parseInvoiceExt(rawExt) };
|
|
41
|
+
for (const key of EXT_NOISE_KEYS)
|
|
42
|
+
delete ext[key];
|
|
43
|
+
for (const key of ['title', 'category']) {
|
|
44
|
+
if (text(ext[key]) === cname)
|
|
45
|
+
delete ext[key];
|
|
46
|
+
}
|
|
47
|
+
return asRecord(compact(ext));
|
|
48
|
+
}
|
|
49
|
+
function party(value) {
|
|
50
|
+
const record = asRecord(value);
|
|
51
|
+
return { company: text(record.company), tcode: text(record.tcode) };
|
|
52
|
+
}
|
|
53
|
+
function invoiceResult(item, baseUrl) {
|
|
54
|
+
const entry = asRecord(item);
|
|
55
|
+
const info = asRecord(entry.info);
|
|
56
|
+
const comm = asRecord(info.comm_info);
|
|
57
|
+
const pro = asRecord(comm.pro);
|
|
58
|
+
const price = asRecord(comm.price);
|
|
59
|
+
const ret = asRecord(entry.ret);
|
|
60
|
+
const fid = text(info.fid ?? info.id);
|
|
61
|
+
const cname = text(pro.cname);
|
|
62
|
+
const kind = text(pro.kind);
|
|
63
|
+
return {
|
|
64
|
+
fid,
|
|
65
|
+
code: text(info.code),
|
|
66
|
+
number: text(info.number),
|
|
67
|
+
cname,
|
|
68
|
+
type: numberOrZero(pro.type),
|
|
69
|
+
...(kind ? { kind } : {}),
|
|
70
|
+
date: text(pro.date),
|
|
71
|
+
amount: text(price.amount),
|
|
72
|
+
total: text(price.total),
|
|
73
|
+
dtax: text(price.dtax),
|
|
74
|
+
buyer: party(comm.buyer),
|
|
75
|
+
payer: party(comm.payer),
|
|
76
|
+
ext: usefulExt(info.ext, cname),
|
|
77
|
+
ret: { ret: ret.ret, message: text(ret.message) },
|
|
78
|
+
validated: ret.ret === 0,
|
|
79
|
+
...(fid ? { detailUrl: invoiceDetailUrl(baseUrl, fid) } : {}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
4
82
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 输入:file / url + scope
|
|
8
|
-
* 输出:upload 对象 + OCR 识别结果 + 查验结果(每张发票)
|
|
83
|
+
* 上传 + OCR 识别 + 查验一体化:一次 `addInvoiceByFile` 完成,识别出的发票和行程单直接进个人票夹。
|
|
84
|
+
* 每张发票的 `ret.ret === 0` 表示识别并查验成功;非 0 但带 `fid` 的已进票夹,只是查验没通过。
|
|
9
85
|
*/
|
|
10
86
|
export class InvoiceUploadAndValidateOperation {
|
|
11
87
|
name = 'invoice.upload-and-validate';
|
|
12
88
|
async execute(input, { host }) {
|
|
13
|
-
const
|
|
89
|
+
const source = await importSource(input);
|
|
14
90
|
const session = await host.getSession();
|
|
15
|
-
|
|
16
|
-
let
|
|
91
|
+
const fileName = source.kind === 'file' ? source.file.name : source.url;
|
|
92
|
+
let result;
|
|
17
93
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
exitCode: 1,
|
|
94
|
+
result = await host.invoiceMultipartRequest({
|
|
95
|
+
path: '/api/inc/biz/addInvoiceByFile',
|
|
96
|
+
fields: source.fields,
|
|
97
|
+
file: source.kind === 'file' ? source.file : undefined,
|
|
98
|
+
timeoutMs: 90_000,
|
|
24
99
|
});
|
|
25
100
|
}
|
|
26
|
-
// ── Step 2: OCR 识别 ──
|
|
27
|
-
let ocr;
|
|
28
|
-
try {
|
|
29
|
-
ocr = await previewOcr(upload, host);
|
|
30
|
-
}
|
|
31
101
|
catch (error) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
exitCode: 11,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// ── Step 3: 逐张查验 ──
|
|
41
|
-
const validations = [];
|
|
42
|
-
const validationErrors = [];
|
|
43
|
-
for (const item of ocr.invoices) {
|
|
44
|
-
const info = item?.info;
|
|
45
|
-
const fid = info?.fid ?? info?.id;
|
|
46
|
-
if (!fid) {
|
|
47
|
-
validationErrors.push({ fid: null, error: 'OCR 结果中缺少 fid' });
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
const detail = await getDetail({ fid: String(fid) }, host);
|
|
52
|
-
const detailData = detailInfo(detail);
|
|
53
|
-
const result = await host.invoiceRequest({
|
|
54
|
-
path: '/api/inc/valid',
|
|
55
|
-
method: 'POST',
|
|
56
|
-
body: {
|
|
57
|
-
info: detailData,
|
|
58
|
-
flag: 100,
|
|
59
|
-
is_cut: 0,
|
|
60
|
-
is_save: 1,
|
|
61
|
-
operate_type: operateType(scope),
|
|
62
|
-
needLog: true,
|
|
63
|
-
req_base: reqBase({ numericTrace: true }),
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
if (!result?.info) {
|
|
67
|
-
validationErrors.push({ fid: String(fid), error: '查验接口未返回发票信息' });
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (identityFingerprint(result.info) !== identityFingerprint(detailData)) {
|
|
71
|
-
validationErrors.push({ fid: String(fid), error: '查验返回的票面身份字段与目标发票不一致' });
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
validations.push(validationPreview(result.info, scope, String(fid), session.baseUrl));
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
validationErrors.push({ fid: String(fid), error: error.message });
|
|
102
|
+
if (isInvoiceNetworkError(error)) {
|
|
103
|
+
throw invoicePartialError('上传识别请求发出后连接中断,发票可能已进票夹,结果不确定,禁止自动重试', {
|
|
104
|
+
fileName,
|
|
105
|
+
workflow: workflow(this.name, 'EXECUTING'),
|
|
106
|
+
}, { stage: 'upload-and-validate' });
|
|
78
107
|
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
const items = Array.isArray(result?.infos) ? result.infos : [];
|
|
111
|
+
if (!items.length) {
|
|
112
|
+
throw new InvoiceCliError('api', 'recognize_empty', '上传成功但没有识别出任何发票或行程单', {
|
|
113
|
+
details: { fileName, res_base: result?.res_base },
|
|
114
|
+
exitCode: 1,
|
|
115
|
+
});
|
|
79
116
|
}
|
|
117
|
+
const invoices = items.map((item) => invoiceResult(item, session.baseUrl));
|
|
80
118
|
return {
|
|
81
119
|
status: 'COMPLETE',
|
|
82
120
|
data: {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
validationErrors,
|
|
88
|
-
results: ocr.results,
|
|
121
|
+
fileName,
|
|
122
|
+
count: invoices.length,
|
|
123
|
+
validatedCount: invoices.filter((item) => item.validated).length,
|
|
124
|
+
invoices,
|
|
89
125
|
workflow: workflow(this.name, 'COMPLETE'),
|
|
90
126
|
},
|
|
91
127
|
};
|