weaver-work-cli 0.1.76 → 0.1.78

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.
Files changed (175) hide show
  1. package/README.md +3 -1
  2. package/dist/chunks/{attachment-content-24RL44SE.js → attachment-content-TFOC3Y3X.js} +3 -3
  3. package/dist/chunks/{chunk-FEZK536Z.js → chunk-4PBN7NJY.js} +353 -43
  4. package/dist/chunks/{chunk-SQFKBWTR.js → chunk-5VQ7JHV4.js} +132 -47
  5. package/dist/chunks/{chunk-KJA7CRES.js → chunk-7SQN5IZR.js} +1 -1
  6. package/dist/chunks/{chunk-MS7MKBGJ.js → chunk-BP7BONZO.js} +664 -75
  7. package/dist/chunks/{chunk-L5SCNJKX.js → chunk-DACQKJ6O.js} +1 -1
  8. package/dist/chunks/{chunk-T7HVQ2WP.js → chunk-E2EY3DMS.js} +2 -2
  9. package/dist/chunks/{chunk-WJQJ7YEX.js → chunk-FAC4IFGQ.js} +2 -2
  10. package/dist/chunks/{minute-doc-4BA2R5EA.js → chunk-IBTGXLOT.js} +99 -16
  11. package/dist/chunks/{chunk-OJ4JPD25.js → chunk-LQLIXBJF.js} +6 -8
  12. package/dist/chunks/{chunk-H6N6U2D6.js → chunk-SWFTWNWL.js} +7 -7
  13. package/dist/chunks/{chunk-SU6IJD6D.js → chunk-TD5IOEGN.js} +1 -1
  14. package/dist/chunks/{chunk-Q7RXCK2Y.js → chunk-USYFVIUR.js} +22 -7
  15. package/dist/chunks/{chunk-WHI6YAUE.js → chunk-UZ2E3VNI.js} +1 -1
  16. package/dist/chunks/{chunk-AZC53XSQ.js → chunk-VNEU7OUN.js} +1 -1
  17. package/dist/chunks/{chunk-5QUTQHXF.js → chunk-WNFDR5PC.js} +198 -80
  18. package/dist/chunks/{chunk-NZQRW4KL.js → chunk-Z44YFIN6.js} +2 -2
  19. package/dist/chunks/{chunk-R4PN3OFK.js → chunk-ZOTXXGUM.js} +7 -7
  20. package/dist/chunks/{cli-DFLV57LO.js → cli-WA7FOQKC.js} +10 -10
  21. package/dist/chunks/{conflict-72Q6DM4I.js → conflict-D4GVAURN.js} +2 -2
  22. package/dist/chunks/{contract-IRNRQ5FY.js → contract-GW7US3UF.js} +4399 -3547
  23. package/dist/chunks/{create-flow-UGTDI7SP.js → create-flow-ERDGW3FZ.js} +10 -6
  24. package/dist/chunks/{ehr-PHIBBUIG.js → ehr-P6T7OAAV.js} +1 -1
  25. package/dist/chunks/{entry-mode-5WOXFE67.js → entry-mode-SQU5WTX6.js} +3 -3
  26. package/dist/chunks/{env-H4ALHESA.js → env-DASBNSEM.js} +2 -2
  27. package/dist/chunks/{factory-COX6AVK7.js → factory-A3NAKZAA.js} +1 -1
  28. package/dist/chunks/{group-chat-ZIWQQO4G.js → group-chat-7SEAVAJR.js} +3 -3
  29. package/dist/chunks/{lazy-dispatch-MZ3EZYDL.js → lazy-dispatch-ZDKLS5MR.js} +3 -3
  30. package/dist/chunks/{meeting-XE6CTXYA.js → meeting-7AEQGBAT.js} +18 -12
  31. package/dist/chunks/minute-doc-REI6RUE4.js +20 -0
  32. package/dist/chunks/{project-XREEXFU2.js → project-6PRGBLO2.js} +38 -14
  33. package/dist/chunks/{recruit-stage-TSQWOGQD.js → recruit-stage-TLZJUFHD.js} +543 -463
  34. package/dist/chunks/{registry-F4YFZLOD.js → registry-KQ4TNUWO.js} +1 -1
  35. package/dist/chunks/{registry-7UDUWYB5.js → registry-UVTI323K.js} +12 -11
  36. package/dist/chunks/{room-recommend-FO3HLPNB.js → room-recommend-ELEJUYBN.js} +4 -4
  37. package/dist/chunks/{schedule-DHNNOHVS.js → schedule-XBKY7VEA.js} +4 -4
  38. package/dist/chunks/{update-AV5VOXGY.js → update-77ZUIYSG.js} +2 -2
  39. package/dist/chunks/{workflow-MAGCHWYZ.js → workflow-SYCBS5XD.js} +1 -1
  40. package/dist/index.js +3 -3
  41. package/dist/internal/update/service.js +9 -8
  42. package/dist/shortcuts/contract/data/collection-ledger-html.js +109 -33
  43. package/dist/shortcuts/contract/data/collection-node-catalog.js +26 -2
  44. package/dist/shortcuts/contract/data/report-renderers.js +75 -31
  45. package/dist/shortcuts/contract/data/report-spec.js +17 -3
  46. package/dist/shortcuts/contract/manifest.js +20 -3
  47. package/dist/shortcuts/contract/operations/bizreview-report.js +23 -2
  48. package/dist/shortcuts/contract/operations/collection-node.js +116 -1
  49. package/dist/shortcuts/contract/operations/compare-report.js +27 -5
  50. package/dist/shortcuts/contract/operations/credit-page.js +11 -2
  51. package/dist/shortcuts/contract/operations/docx-slots.js +27 -2
  52. package/dist/shortcuts/contract/operations/draft-submit.js +9 -6
  53. package/dist/shortcuts/contract/operations/elements-build.js +162 -30
  54. package/dist/shortcuts/contract/operations/elements-spec.js +50 -0
  55. package/dist/shortcuts/contract/operations/generated-submit.js +35 -0
  56. package/dist/shortcuts/contract/operations/ledger-card.js +32 -2
  57. package/dist/shortcuts/contract/operations/ledger-stat.js +17 -5
  58. package/dist/shortcuts/contract/operations/ledger.js +88 -16
  59. package/dist/shortcuts/contract/operations/metrics.js +16 -3
  60. package/dist/shortcuts/contract/operations/ops-draft.js +359 -27
  61. package/dist/shortcuts/contract/operations/page.js +23 -0
  62. package/dist/shortcuts/contract/operations/quote-recognize.js +91 -13
  63. package/dist/shortcuts/contract/operations/quote-submit.js +16 -0
  64. package/dist/shortcuts/contract/operations/review-report.js +11 -3
  65. package/dist/shortcuts/contract/operations/save-recognize.js +62 -1
  66. package/dist/shortcuts/contract/operations/triage.js +18 -3
  67. package/dist/shortcuts/contract/operations/viewlink.js +17 -1
  68. package/dist/shortcuts/ehr/operations/recruit.js +255 -90
  69. package/dist/shortcuts/meeting/confirm-gate.js +42 -0
  70. package/dist/shortcuts/meeting/continuation.js +6 -2
  71. package/dist/shortcuts/meeting/minute-doc.js +119 -12
  72. package/dist/shortcuts/meeting/operations/attachment.js +19 -0
  73. package/dist/shortcuts/meeting/operations/compose-outcome.js +24 -2
  74. package/dist/shortcuts/meeting/operations/eb/conflict.js +2 -1
  75. package/dist/shortcuts/meeting/operations/eb/create-flow.js +162 -19
  76. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +22 -3
  77. package/dist/shortcuts/meeting/operations/group-share.js +268 -0
  78. package/dist/shortcuts/meeting/operations/minute-content.js +58 -1
  79. package/dist/shortcuts/meeting/operations/minute-export.js +295 -0
  80. package/dist/shortcuts/meeting/operations/registry.js +4 -0
  81. package/dist/shortcuts/project/operations/read.js +40 -15
  82. package/dist/shortcuts/recruit-stage/context.js +16 -81
  83. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +89 -53
  84. package/dist/shortcuts/recruit-stage/operations/interview-feedback.js +15 -5
  85. package/dist/shortcuts/recruit-stage/operations/jd-create.js +46 -108
  86. package/dist/shortcuts/recruit-stage/operations/list.js +203 -74
  87. package/dist/shortcuts/recruit-stage/operations/resume-import.js +21 -85
  88. package/dist/shortcuts/recruit-stage/operations/search.js +113 -53
  89. package/dist/shortcuts/recruit-stage/shared.js +153 -4
  90. package/dist/shortcuts/workflow/endpoints.js +2 -0
  91. package/dist/shortcuts/workflow/operations/form.js +11 -0
  92. package/dist/shortcuts/workflow/operations/read.js +24 -5
  93. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +2 -2
  94. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +2 -0
  95. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +28 -4
  96. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.node.js +198 -0
  97. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.prepareQuery.js +4 -2
  98. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.subordinate.js +70 -0
  99. package/dist/shortcuts/workflow/operations/todoSmartConvert/workflowClarification.js +15 -5
  100. package/docs/project.md +1 -1
  101. package/package.json +1 -1
  102. package/scripts/pysite/__pycache__/sitecustomize.cpython-312.pyc +0 -0
  103. package/scripts/pysite/__pycache__/sitecustomize.cpython-313.pyc +0 -0
  104. package/scripts/pysite/__pycache__/sitecustomize.cpython-314.pyc +0 -0
  105. package/skills/weaver-e10-jinchengda/SKILL.md +64 -28
  106. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +4 -4
  107. package/skills/weaver-e10-jinchengda/references/contract-bizreview-report-template.html +1 -1
  108. package/skills/weaver-e10-jinchengda/references/contract-bizreview.md +5 -4
  109. package/skills/weaver-e10-jinchengda/references/contract-collection-node.md +26 -2
  110. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  111. package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +9 -8
  112. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +47 -52
  113. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +1 -1
  114. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +5 -5
  115. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +1 -1
  116. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +7 -1
  117. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +21 -12
  118. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +44 -1
  119. package/skills/weaver-e10-jinchengda/references/contract-firstscreen-guide.md +5 -4
  120. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +8 -0
  121. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +33 -3
  122. package/skills/weaver-e10-jinchengda/references/contract-ledger-report.md +1 -1
  123. package/skills/weaver-e10-jinchengda/references/contract-material-gap.md +17 -3
  124. package/skills/weaver-e10-jinchengda/references/contract-object-detect.md +12 -12
  125. package/skills/weaver-e10-jinchengda/references/contract-open-web-pages.md +18 -10
  126. package/skills/weaver-e10-jinchengda/references/contract-ops-draft.md +77 -37
  127. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +7 -0
  128. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +55 -12
  129. package/skills/weaver-e10-jinchengda/references/contract-review-todo.md +102 -0
  130. package/skills/weaver-e10-jinchengda/references/contract-sign-launch.md +1 -17
  131. package/skills/weaver-e10-jinchengda/references/contract-smart-draft.md +11 -8
  132. package/skills/weaver-e10-jinchengda/references/contract-type-fingerprints.md +2 -1
  133. package/skills/weaver-e10-jinchengda/references/orchestration.md +6 -6
  134. package/skills/weaver-e10-meeting/SKILL.md +203 -80
  135. package/skills/weaver-e10-meeting/references/create-quickstart.md +98 -0
  136. package/skills/weaver-e10-meeting/references/delivery-checklist.md +34 -0
  137. package/skills/weaver-e10-meeting/references/error-codes.md +44 -0
  138. package/skills/weaver-e10-meeting/references/minutes-pipeline.md +56 -3
  139. package/skills/weaver-e10-meeting/references/room-recommend.md +2 -0
  140. package/skills/weaver-e10-recruit-stage/SKILL.md +61 -58
  141. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +28 -25
  142. package/skills/weaver-e10-recruit-stage/lib/interview-summary.mjs +20 -14
  143. package/skills/weaver-e10-recruit-stage/lib/recruit-attach-probe.mjs +127 -0
  144. package/skills/weaver-e10-recruit-stage/lib/recruit-shortlist.mjs +71 -25
  145. package/skills/weaver-e10-recruit-stage/lib/recruit-write-helper.mjs +39 -7
  146. package/skills/weaver-e10-recruit-stage/lib/recruit-xiaoe-file.mjs +2 -2
  147. package/skills/weaver-e10-recruit-stage/references/position-templates.md +10 -10
  148. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +8 -5
  149. package/skills/weaver-e10-recruit-stage/references/recruit-capability-check.md +29 -31
  150. package/skills/weaver-e10-recruit-stage/references/recruit-failure-fallback.md +4 -2
  151. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +6 -6
  152. package/skills/weaver-e10-recruit-stage/references/recruit-list-candidate.md +4 -4
  153. package/skills/weaver-e10-recruit-stage/references/recruit-list-interview.md +3 -3
  154. package/skills/weaver-e10-recruit-stage/references/recruit-maint.md +10 -0
  155. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +2 -1
  156. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +1 -0
  157. package/skills/weaver-e10-recruit-stage/references/recruit-report-templates.md +1 -1
  158. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +10 -28
  159. package/skills/weaver-e10-recruit-stage/references/recruit-search-candidate.md +2 -0
  160. package/skills/weaver-e10-recruit-stage/references/recruit-tag-recommend.md +1 -1
  161. package/skills/weaver-e10-recruit-stage/templates/candidate-evidence.html +2 -2
  162. package/skills/weaver-e10-recruit-stage/templates/interview-summary.html +1 -1
  163. package/skills/weaver-e10-recruit-stage/templates/match-report.html +14 -10
  164. package/skills/weaver-e10-shijingran/SKILL.md +2 -2
  165. package/skills/weaver-e10-shijingran/references/operations.md +5 -2
  166. package/skills/weaver-e10-shijingran/references/source-manifest.json +41 -40
  167. package/skills/weaver-e10-workflow/SKILL.md +13 -9
  168. package/skills/weaver-e10-workflow/references/todo-dialogue.md +33 -8
  169. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +19 -14
  170. package/skills/weaver-e10-workflow/references/workflow-create.md +1 -1
  171. package/skills/weaver-e10-workflow/references/workflow-query.md +4 -2
  172. package/skills/weaver-e10-workflow/references/workflow-view.md +3 -3
  173. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +132 -42
  174. package/templates/meeting/minute.docx +0 -0
  175. package/skills/weaver-e10-yepiaotong.zip +0 -0
@@ -194,7 +194,7 @@ function groupThousands(digits) {
194
194
  * 除原值外,额外补充去掉括号注释的变体,避免「2026年7月(日留空待填)」
195
195
  * 这类带注释的值在正文里匹配不到而丢掉出处;数字补千分位/去千分位变体。
196
196
  */
197
- function buildNeedles(value) {
197
+ export function buildNeedles(value) {
198
198
  if (isEmptyScalar(value))
199
199
  return null;
200
200
  const values = Array.isArray(value) ? value : [value];
@@ -407,7 +407,7 @@ export function buildNewCustomer({ triage, fileId, flow, lines, sourceMap, fileI
407
407
  const add = (key, value, reason, origin) => {
408
408
  if (isEmptyScalar(value))
409
409
  return;
410
- results.push({ fieldInfo: fields[key], reason, value: String(value), origin: ro(origin) });
410
+ results.push({ fieldInfo: fields[key], reason, value: normalizeFieldValue(value), origin: ro(origin) });
411
411
  };
412
412
  // 购买方式:以「签约相对方是否等于最终用户」判定,不能只看丙方。
413
413
  // 判据(references §2.1):实际使用系统的客户通过第三方公司与泛微签约 → 通过伙伴签署;
@@ -514,6 +514,149 @@ export function buildNewCustomer({ triage, fileId, flow, lines, sourceMap, fileI
514
514
  return makePayload(spec, flow, fileId, results, subtables);
515
515
  }
516
516
  /** 契约锁 / 常规二次销售 / 老客户增值:只填文本、数字与已实测选项的复选框。 */
517
+ /**
518
+ * 选项表取值:既接受**表键(显示名 / 口语写法)**,也接受**已经是选项 ID** 的直传值。
519
+ *
520
+ * 用户/上游两种写法都要认:「客户方先盖章」(表键)与「1」(选项 ID)。
521
+ * 返回 `''` 表示取不到(调用方自行决定报错还是留空)。
522
+ */
523
+ export function pickOptionOrId(table, value) {
524
+ const raw = String(value ?? '').trim();
525
+ if (!raw)
526
+ return '';
527
+ if (Object.values(table).includes(raw))
528
+ return raw;
529
+ return pickOption(table, raw) ?? '';
530
+ }
531
+ /**
532
+ * 识别记录字段值归一:**浏览按钮类字段一律落成名称文本**。
533
+ *
534
+ * 🔴 2026-12-01 事故:调用方把 `{"id":"…","name":"韦莱保险经纪有限公司"}` 这种对象当 `value` 传进来,
535
+ * 落库后页面上的客户名称就显示成 `{id,name}` 形态。技能文档明确禁止两种写法——`{id,name}` 对象与纯记录 id。
536
+ *
537
+ * 这里做**兜底**(不等于允许):对象取 `name`(退 `title` / `label` / `text` / `displayName`,再退 `id`),
538
+ * 数组逐项取名称后逗号拼接,其余标量转字符串。归一发生在落库前,调用方仍应直接传名称文本。
539
+ */
540
+ export function normalizeFieldValue(value) {
541
+ if (value === undefined || value === null)
542
+ return '';
543
+ if (typeof value === 'string')
544
+ return value;
545
+ if (typeof value === 'number' || typeof value === 'boolean')
546
+ return String(value);
547
+ if (Array.isArray(value)) {
548
+ return value.map((item) => normalizeFieldValue(item)).filter((item) => item !== '').join(',');
549
+ }
550
+ if (typeof value === 'object') {
551
+ const record = value;
552
+ for (const key of ['name', 'title', 'label', 'text', 'displayName', 'realName', 'khmc']) {
553
+ const picked = record[key];
554
+ if (typeof picked === 'string' && picked.trim())
555
+ return picked.trim();
556
+ }
557
+ const id = record.id;
558
+ if (typeof id === 'string' && id.trim())
559
+ return id.trim();
560
+ if (typeof id === 'number')
561
+ return String(id);
562
+ try {
563
+ return JSON.stringify(value);
564
+ }
565
+ catch {
566
+ return '';
567
+ }
568
+ }
569
+ return '';
570
+ }
571
+ /**
572
+ * 从生成合同正文里挑出**「购买内容」证据行**:只保留带费用/标的语义的行。
573
+ *
574
+ * 为什么要筛:正文里的**服务内容清单**会出现「升级支持」这类服务项,整段扫会把维护合同
575
+ * 误判成"购买了升级包"(复选框语义是"买了什么",不是"服务里提到什么")。
576
+ * 费用明细 / 标的 / 金额 / 许可 / 模块 这类行才是购买证据。
577
+ */
578
+ const PURCHASE_EVIDENCE_LINE = /(费用|价款|标的|购买|金额|维护费|服务费|许可|licen[cs]e|模块|元|¥|¥)/iu;
579
+ export function purchaseEvidenceText(contractText, limit = 60) {
580
+ if (!contractText)
581
+ return '';
582
+ return contractText
583
+ .split(/\r?\n/u)
584
+ .filter((line) => PURCHASE_EVIDENCE_LINE.test(line))
585
+ .slice(0, limit)
586
+ .join(' ');
587
+ }
588
+ /**
589
+ * 字段 ID 串(`<id>#<表单中文名>`)→ **可在正文里检索的表单标签**。
590
+ *
591
+ * 例:`1298278337779310598#流程标题new` → `流程标题`;`100003720000001199#客户名称(最终用户)` → `客户名称`;
592
+ * `1291602365099327623#伙伴名称(文本备份)` → `伙伴名称`。
593
+ *
594
+ * 2026-12-01:报价单 / 运维起草收口要"**全字段过一遍、抽不到留空**",靠的就是
595
+ * 「按表单标签在正文里找『标签:值』」这一条通用机制,避免为每个字段手写一条抽取规则。
596
+ */
597
+ export function fieldLabel(fieldInfo) {
598
+ const raw = String(fieldInfo ?? '').split('#')[1] ?? '';
599
+ return raw
600
+ .replace(/([^)]*)/gu, '')
601
+ .replace(/\([^)]*\)/gu, '')
602
+ .replace(/new$/iu, '')
603
+ .replace(/\s+/gu, '')
604
+ .trim();
605
+ }
606
+ /**
607
+ * 在正文里按**行首标签**取「标签:值」。⛔ 三个硬条件,缺一不可:
608
+ * 1. 标签出现在行首(允许前面有表格竖线 `|`)——避免把叙述句里的「地址按本合同第…」当成送达地址;
609
+ * 2. 标签后必须紧跟冒号(`:` / `:`);
610
+ * 3. 冒号后的值必须非空且有实质内容——模板里那种空标签(`联系人:` / `地址:`)一律视为**抽不到**。
611
+ */
612
+ export function pickLabeledValue(lines, label) {
613
+ const target = norm(label);
614
+ if (!target)
615
+ return null;
616
+ for (let i = 0; i < lines.length; i += 1) {
617
+ const line = String(lines[i] ?? '').replace(/^[\s||]+/u, '');
618
+ const colonAt = line.search(/[::]/u);
619
+ if (colonAt < 0)
620
+ continue;
621
+ const head = norm(line.slice(0, colonAt));
622
+ if (head !== target)
623
+ continue;
624
+ const value = line.slice(colonAt + 1).replace(/[||]/gu, ' ').trim().replace(/[。;;,,]$/u, '');
625
+ if (value.length < 2)
626
+ return null; // 空标签:明确视为抽不到
627
+ return { value: value.slice(0, 60), lineIndex: i };
628
+ }
629
+ return null;
630
+ }
631
+ /**
632
+ * 「合同购买内容」复选框:按语义关键词命中勾选,**命中不到整条不填**(不猜、不落空值)。
633
+ *
634
+ * 🔴 两条链路必须共用本函数(上传合同链路 `buildGeneric` 与报价单/运维起草收口 `buildQuoteFieldResults`):
635
+ * 2026-11-30 事故——运维合同起草走的是**报价单收口**,而该收口的字段表原先没有这一项,
636
+ * 于是识别记录里永远缺「合同购买内容」(合同购买内容本属技能文档 §1「抽取范围」第 2 类)。
637
+ *
638
+ * ⚠️ 关键词表按流程不同(常规二次销售 = RESALE、老客户增值 = UPSALE),
639
+ * 所以**流程选错会直接表现为"这一项是空的"**:年度维护合同只有走常规二次销售才会命中「维护」。
640
+ */
641
+ export function pickPurchaseCheckbox(flow, parts) {
642
+ const checkbox = BUILTIN[flow]?.checkbox;
643
+ if (!checkbox)
644
+ return null;
645
+ const hints = flow === '常规二次销售' ? CHECKBOX_HINTS_RESALE : CHECKBOX_HINTS_UPSALE;
646
+ const blob = parts.filter((part) => pyTruthy(part)).map((part) => String(part)).join(' ');
647
+ const picked = [];
648
+ const hit = [];
649
+ for (const [name, keywords] of hints) {
650
+ if (keywords.some((keyword) => blob.includes(keyword))) {
651
+ const optionId = checkbox.options[name];
652
+ if (optionId === undefined)
653
+ continue;
654
+ picked.push(optionId);
655
+ hit.push(name);
656
+ }
657
+ }
658
+ return picked.length ? { fieldKey: checkbox.fieldKey, value: picked.join(','), hit } : null;
659
+ }
517
660
  export function buildGeneric({ triage, fileId, flow, lines, sourceMap, fileIds }) {
518
661
  const spec = BUILTIN[flow];
519
662
  const fields = spec.fields;
@@ -523,15 +666,17 @@ export function buildGeneric({ triage, fileId, flow, lines, sourceMap, fileIds }
523
666
  const ro = (needles) => resolveOrigin(lines, needles, fileId, sourceMap, fileIds);
524
667
  const add = (key, value, reason, origin) => {
525
668
  const fieldInfo = fields[key];
526
- if (!fieldInfo || isEmptyScalar(value))
669
+ const text = normalizeFieldValue(value);
670
+ if (!fieldInfo || isEmptyScalar(text))
527
671
  return;
528
- results.push({ fieldInfo, reason, value: String(value), origin: ro(origin) });
672
+ results.push({ fieldInfo, reason, value: text, origin: ro(origin) });
529
673
  };
530
674
  const addSelect = (key, value, reason, origin) => {
531
675
  const fieldInfo = selects[key];
532
- if (!fieldInfo || isEmptyScalar(value))
676
+ const text = normalizeFieldValue(value);
677
+ if (!fieldInfo || isEmptyScalar(text))
533
678
  return;
534
- results.push({ fieldInfo, reason, value: String(value), origin: ro(origin) });
679
+ results.push({ fieldInfo, reason, value: text, origin: ro(origin) });
535
680
  };
536
681
  // ① 合同文件:不写入 recognizeResult(附件只走流程组件 customParams)
537
682
  // ② 文本类:流程标题优先取合同标题,抽不到用文件名兜底
@@ -595,30 +740,17 @@ export function buildGeneric({ triage, fileId, flow, lines, sourceMap, fileIds }
595
740
  addSelect('relatedProduct', optionId('relatedProduct', elements.relatedProduct), '按合同标的判定相关产品', buildNeedles(elements.relatedProduct));
596
741
  addSelect('isXinChuang', optionId('isXinChuang', elements.isXinChuang), '合同未涉及信创内容则不填', buildNeedles(elements.isXinChuang));
597
742
  // ⑦ 合同购买内容(复选框):按正文语义命中勾选,命中不到整条不填
598
- const checkbox = spec.checkbox;
599
- if (checkbox) {
600
- const hints = flow === '常规二次销售' ? CHECKBOX_HINTS_RESALE : CHECKBOX_HINTS_UPSALE;
601
- const items = Array.isArray(elements.items) ? elements.items : [];
602
- const itemNames = items.map((item) => truthyText(item?.name));
603
- const blobParts = [
604
- elements.title,
605
- elements.contractName,
606
- elements.background,
607
- elements.serviceScope,
608
- itemNames.join(' '),
609
- ].filter((part) => pyTruthy(part)).map((part) => String(part));
610
- const blob = blobParts.join(' ');
611
- const picked = [];
612
- const hit = [];
613
- for (const [name, keywords] of hints) {
614
- if (keywords.some((keyword) => blob.includes(keyword))) {
615
- picked.push(checkbox.options[name]);
616
- hit.push(name);
617
- }
618
- }
619
- if (picked.length) {
620
- add(checkbox.fieldKey, picked.join(','), `按合同标的关键词命中:${hit.join('、')}`, buildNeedles(itemNames) ?? buildNeedles(hit));
621
- }
743
+ const items = Array.isArray(elements.items) ? elements.items : [];
744
+ const itemNames = items.map((item) => truthyText(item?.name));
745
+ const purchase = pickPurchaseCheckbox(flow, [
746
+ elements.title,
747
+ elements.contractName,
748
+ elements.background,
749
+ elements.serviceScope,
750
+ itemNames.join(' '),
751
+ ]);
752
+ if (purchase) {
753
+ add(purchase.fieldKey, purchase.value, `按合同标的关键词命中:${purchase.hit.join('、')}`, buildNeedles(itemNames) ?? buildNeedles(purchase.hit));
622
754
  }
623
755
  return makePayload(spec, flow, fileId, results);
624
756
  }
@@ -14,6 +14,56 @@
14
14
  * - 复选框选项 ID 各流程**互不相同**,禁止互抄;
15
15
  * - 不登记附件字段到 recognizeResult(附件只走流程组件 customParams)。
16
16
  */
17
+ /**
18
+ * 用户口述的「用印 / 签署顺序」→ 本流程选项表的**标准写法**(四流程键一致:
19
+ * `我方先盖章=0` / `客户方先盖章=1` / `等待确认=2`)。
20
+ *
21
+ * 为什么必须归正(2026-11-30 事故):装配器原先**没有这个入参**,一律写技术性默认「我方先盖章」,
22
+ * 于是用户明确要求的「对方先用印」被落成了我方先盖章——**把对手方的要求写反**,且不报错。
23
+ * 用户口语五花八门(对方先用印 / 客户方先盖章 / 甲方先签 / 对方先签署),这里统一归一到表键。
24
+ */
25
+ const SIGN_WAY_ALIASES = [
26
+ { pattern: /((对方|客户方?|甲方)[^。;;]{0,6}?(先|用印|盖章|签署))/u, label: '客户方先盖章' },
27
+ { pattern: /(等待|待定|暂不|不确定|需确认|再确认)/u, label: '等待确认' },
28
+ { pattern: /((我方|乙方)[^。;;]{0,6}?(先|用印|盖章|签署))/u, label: '我方先盖章' },
29
+ ];
30
+ export function resolveSignWay(value) {
31
+ const raw = String(value ?? '').replace(/\s+/gu, '').trim();
32
+ if (!raw)
33
+ return '';
34
+ for (const { pattern, label } of SIGN_WAY_ALIASES) {
35
+ if (pattern.test(raw))
36
+ return label;
37
+ }
38
+ return raw;
39
+ }
40
+ /**
41
+ * 「合同类型」按**产品线**归一到本流程的选项 ID(常规二次销售 / 老客户增值 / 新客户都有这个下拉)。
42
+ *
43
+ * 2026-12-01:报价单 / 运维起草收口原先不装配这一项(装配器只吃报价单侧数据、不吃正文),
44
+ * 而产品线恰恰写在**生成后的合同正文**里(如「协同办公系统(e-cology)软件年度维护合同」)。
45
+ * 现在由收口把生成合同正文传进来,本函数按产品线锚词命中 → 返回本流程的选项 ID;
46
+ * **命中不到就不填**(不猜),⛔ 不得跨流程套用选项表(各流程 ID 不同)。
47
+ */
48
+ export function pickProductLineContractType(flow, parts) {
49
+ const spec = BUILTIN[flow];
50
+ const table = spec?.options?.contractType ?? {};
51
+ if (!spec?.selects?.contractType || !Object.keys(table).length)
52
+ return null;
53
+ const blob = parts
54
+ .filter((part) => part !== undefined && part !== null && String(part).trim() !== '')
55
+ .map((part) => String(part).toLowerCase())
56
+ .join(' ');
57
+ let best = null;
58
+ for (const [alias, id] of Object.entries(table)) {
59
+ const anchor = alias.toLowerCase().replace(/购买$/u, '').trim();
60
+ if (!anchor || !blob.includes(anchor))
61
+ continue;
62
+ if (!best || anchor.length > best.alias.length)
63
+ best = { alias, id };
64
+ }
65
+ return best ? { fieldKey: 'contractType', value: best.id, hit: best.alias } : null;
66
+ }
17
67
  /** 新客户流程(workflowId 1269716062340284522)字段表。 */
18
68
  export const NEW_CUSTOMER = {
19
69
  workflowId: '1269716062340284522',
@@ -62,6 +62,31 @@ function finalizeRecognizePayload(payload, fileId) {
62
62
  }
63
63
  return payload;
64
64
  }
65
+ /**
66
+ * 发送值快照:`fieldInfo` → `value`(字符串)。
67
+ *
68
+ * 只回传**纯量值的字符串形态**,不改变真正发出去的 payload;
69
+ * 目的是让「实际写了什么」可核对(模型此前看不到收口链的 payload,只能猜)。
70
+ */
71
+ function sentFieldValues(payload) {
72
+ try {
73
+ const rows = (payload.recognizeResult?.mainTable?.rows ?? []);
74
+ const out = [];
75
+ for (const row of rows) {
76
+ for (const item of (row.fieldResults ?? [])) {
77
+ const value = item?.value;
78
+ out.push({
79
+ fieldInfo: String(item?.fieldInfo ?? ''),
80
+ value: typeof value === 'string' ? value : JSON.stringify(value ?? null),
81
+ });
82
+ }
83
+ }
84
+ return out;
85
+ }
86
+ catch {
87
+ return [];
88
+ }
89
+ }
65
90
  /**
66
91
  * 执行收口:上传 ∥ 装配 → 存识别记录 → 拼页面地址。
67
92
  *
@@ -161,6 +186,16 @@ export async function runGeneratedSubmit(args) {
161
186
  attachmentFileId: str(saved.attachmentFileId) || fileId,
162
187
  aiExtraId,
163
188
  customParams: saved.customParams ?? { aiExtraId, openSource: 'xiaoE' },
189
+ /**
190
+ * 实际发送的字段值快照(`fieldInfo` → `value`,全部是字符串)。
191
+ *
192
+ * 为什么要回传:2026-12-01 反复出现「页面里客户名称显示成 `{id,name}`,到底是谁写的」的争论——
193
+ * 收口链在进程内装配、模型看不到 payload,只能猜。把发送值快照放进响应,
194
+ * 写了什么一望即知,不必再开一次会话去查。
195
+ */
196
+ sentValues: sentFieldValues(assembled.payload),
197
+ /** 非字符串值被兜底成名称文本的明细(调用方若传了 `{id,name}` 对象,这里必有记录) */
198
+ valueFixups: Array.isArray(saved.valueFixups) ? saved.valueFixups : [],
164
199
  pageUrl,
165
200
  url: pageUrl,
166
201
  workflowUrl: uploadData.url ?? null,
@@ -76,6 +76,12 @@ export const LEDGER_FILTER_KINDS = {
76
76
  xsjl2: 'person',
77
77
  qy2: 'text',
78
78
  hsjg: 'text',
79
+ /**
80
+ * 风险合同(RadioBox,字段 ID `1342854789687115776`,2026-12-01 实测):
81
+ * `0` = 是(实测 `eq 0` → 50 条,首行 `sffxht=是`、`sffxhtSpan=[{"name":"是","id":"0"}]`);`eq 1` → 0 条。
82
+ * ⛔ 该字段**只能用 `eq`**:`like 0/1` 会静默返回全量(实测 341,968 = 无条件总量)。
83
+ */
84
+ sffxht: 'textList',
79
85
  },
80
86
  directPerf: {
81
87
  hth: 'text',
@@ -403,7 +409,20 @@ function parseLedgerFilters(pairs, rawJson, viewKey) {
403
409
  for (const [key, raw] of Object.entries(merged)) {
404
410
  const kind = allowed[key];
405
411
  if (!kind) {
406
- throw contractValidationError('ledger_filter_key_invalid', `台账标签 ${viewKey} 没有筛选键 ${pyReprText(key)},可用:${Object.keys(allowed).join('、')}`);
412
+ // 2026-12-01 更正:LedgerPage 的 filters **只认台账返回键(dataKey)**——现有键
413
+ // `khmc/hth/htmc/qdrq/htzje/xslx/xsjl2/qy2/hsjg` 全是 dataKey,没有一个 `field_<id>`。
414
+ // `field_<id>` 是**另一条通道**(ebdf 列表卡 comParams 与取数 DSL),⛔ 塞进 LedgerPage 组件不认,
415
+ // 只会表现为"筛选没生效、页面照常打开"这种静默失败。新字段的正解是登记它的 dataKey
416
+ // (用 `contract.performance.list.query` + `includeColumns=true` 读 `data.columns[].dataKey`)。
417
+ throw contractValidationError('ledger_filter_key_invalid', `台账标签 ${viewKey} 没有筛选键 ${pyReprText(key)},可用:${Object.keys(allowed).join('、')}`
418
+ + '(卡片键必须是台账**返回键 dataKey**,不是 field_<字段ID>;新字段请先读 data.columns[].dataKey 再登记)');
419
+ }
420
+ if (kind === 'textList') {
421
+ const list = Array.isArray(raw) ? raw : [raw];
422
+ out[key] = list
423
+ .map((item) => (item === null || item === undefined ? '' : typeof item === 'string' ? item.trim() : pyStr(item)))
424
+ .filter((item) => item !== '');
425
+ continue;
407
426
  }
408
427
  if (kind === 'dateRange' || kind === 'amountRange') {
409
428
  if (!Array.isArray(raw) || raw.length !== 2) {
@@ -535,6 +554,13 @@ function selfCheckLedger(card, viewKey) {
535
554
  bad.push(`filters 人员键元素必须是含 id(人员主键)与 name(姓名的对象):${key}`);
536
555
  }
537
556
  }
557
+ else if (kind === 'textList') {
558
+ // 单选/多选类字段(如 风险合同 `sffxht`):接受字符串或字符串数组
559
+ if (!(typeof value === 'string'
560
+ || (Array.isArray(value) && value.every((item) => typeof item === 'string')))) {
561
+ bad.push(`filters 多值键需要字符串或字符串数组:${key}`);
562
+ }
563
+ }
538
564
  else if (typeof value !== 'string') {
539
565
  bad.push(`filters 值不是字符串:${key}`);
540
566
  }
@@ -655,7 +681,11 @@ export const contractLedgerCardOperation = {
655
681
  card,
656
682
  selfCheck: problems,
657
683
  ...(output ? { output } : {}),
658
- note: '台账页卡:viewKey 决定默认标签,filters 第一层 key 就是 viewKey;渠道订单默认 e-teams(etOrder)',
684
+ note: '台账页卡:viewKey 决定默认标签,filters 第一层 key 就是 viewKey;渠道订单默认 e-teams(etOrder)。'
685
+ + '风险合同:键 `sffxht`(该字段的**返回键**,与 khmc/hth 同层),取值 `["0"]` = 是 → '
686
+ + '`{"menu":"直销合同","title":"风险合同","comParamsJson":"{\\"sffxht\\":[\\"0\\"]}"}`;'
687
+ + '⛔ 卡片 filters 只认返回键,不认 field_<字段ID>(那是 ebdf 列表卡/取数 DSL 的形态);'
688
+ + '⛔ 该字段取数时只能用 eq(like 会静默返回全量)。',
659
689
  },
660
690
  };
661
691
  }
@@ -304,10 +304,12 @@ export function resolveStatSpec(input) {
304
304
  const explicitPeriods = Array.isArray(input.periods) ? input.periods.map((item) => String(item).trim()) : [];
305
305
  let months;
306
306
  if (explicitPeriods.length) {
307
- months = explicitPeriods.map((month) => {
308
- parseMonth(month, 'periods');
309
- return month;
310
- }).sort();
307
+ // 2026-12-01 修复:显式 periods 未去重时,同一月份会被 rows 引擎**累加两次**
308
+ // (BI 引擎因按月建桶不受影响 → 两引擎结果不一致)。这里统一去重后排序。
309
+ months = [...new Set(explicitPeriods.map((month) => {
310
+ parseMonth(month, 'periods');
311
+ return month;
312
+ }))].sort();
311
313
  }
312
314
  else {
313
315
  const from = typeof input.from === 'string' ? input.from.trim() : '';
@@ -616,7 +618,17 @@ export async function runStat(spec, fetcher) {
616
618
  for (const month of win.previousMonths)
617
619
  previousPeriods.push(await runMonth(month, previousAcc));
618
620
  const totals = finalize(totalsAcc, metrics);
619
- const previousTotals = finalize(previousAcc, metrics);
621
+ /**
622
+ * 2026-12-01 修复:未请求同比(`compare: none`)时不得伪造去年同期值。
623
+ *
624
+ * `finalize(空 accumulator)` 对 sum / countDistinct 返回 **0**,于是 `previous = 0 → delta = 当前值`,
625
+ * 报表上会出现假的「去年同期 0.00」与「同比 ↑100%」(BI 引擎同情形返回 null,两引擎还不一致)。
626
+ * 未请求对比时把 previous* 一律置 null,与 BI 引擎对齐。
627
+ */
628
+ const previousTotalsRaw = finalize(previousAcc, metrics);
629
+ const previousTotals = win.compare === 'yoy'
630
+ ? previousTotalsRaw
631
+ : Object.fromEntries(Object.keys(previousTotalsRaw).map((key) => [key, null]));
620
632
  for (const key of incompleteMetrics) {
621
633
  totals[key] = null;
622
634
  previousTotals[key] = null;
@@ -193,6 +193,18 @@ export const contractLedgerOperations = [
193
193
  const sum = Array.isArray(input.sum) ? input.sum.map(String) : [];
194
194
  const where = Array.isArray(input.where) ? input.where.map(String) : [];
195
195
  const dedupe = input.dedupe === true;
196
+ /**
197
+ * **实体级字段的求和口径**(2026-12-01 事故固化)。
198
+ *
199
+ * `sum` 里可以混两种粒度的字段:合同级(`htzje` 合同总金额、`sumsk` 已收款…)与期次级(分期金额)。
200
+ * 前者若按**行**累加,同一合同出现在多行(多期/多窗口重叠)就会被重复计入
201
+ * —— 与收款节点台账 150 万 vs 100 万 是同一类事故。
202
+ *
203
+ * `entityKey` 给实体键(如 `['hth']`),`entitySumFields` 给其中的**合同级**字段;
204
+ * 这些字段按实体去重后**每实体取一次值(取最大,防脏数据放大)**再求和,其余字段照常按行累加。
205
+ */
206
+ const entityKey = Array.isArray(input.entityKey) ? input.entityKey.map(String).filter(Boolean) : [];
207
+ const entitySumFields = new Set(Array.isArray(input.entitySumFields) ? input.entitySumFields.map(String).filter(Boolean) : []);
196
208
  const detail = input.detail === true;
197
209
  const limitRaw = input.limit;
198
210
  const limit = typeof limitRaw === 'number' && Number.isFinite(limitRaw) && limitRaw > 0 ? Math.floor(limitRaw) : 20;
@@ -219,8 +231,11 @@ export const contractLedgerOperations = [
219
231
  let totalSum = 0;
220
232
  let totalUnknown = false;
221
233
  let truncatedAny = false;
234
+ let rawRowCount = 0;
235
+ let droppedByDedupe = 0;
222
236
  for (const path of sources) {
223
237
  const { rows, pagination } = loadRows(path);
238
+ rawRowCount += rows.length;
224
239
  sourceInfo.push({
225
240
  file: basename(path),
226
241
  rows: rows.length,
@@ -238,16 +253,21 @@ export const contractLedgerOperations = [
238
253
  for (const row of rows) {
239
254
  if (dedupe) {
240
255
  let key = null;
256
+ // ⚠️ 键**不带字段名前缀**:同一实体在不同窗口/分片可能分别落在
257
+ // `id` / `form_data_id` / `rowKey` / `ebrecord_rowkey`(实测五键同值),
258
+ // 带前缀会把同一行当成两行,去重形同失效(2026-12-01 修复)。
241
259
  for (const field of ['id', 'form_data_id', 'rowKey', 'ebrecord_rowkey']) {
242
260
  const text = cellText(row[field]);
243
261
  if (text) {
244
- key = `${field}|${text}`;
262
+ key = text;
245
263
  break;
246
264
  }
247
265
  }
248
266
  if (key) {
249
- if (seen.has(key))
267
+ if (seen.has(key)) {
268
+ droppedByDedupe += 1;
250
269
  continue;
270
+ }
251
271
  seen.add(key);
252
272
  }
253
273
  }
@@ -259,20 +279,82 @@ export const contractLedgerOperations = [
259
279
  if (truncatedAny) {
260
280
  warnings.push('存在 truncated=true 的来源,当前不是全量;请缩小范围重查,或补齐分页后合并。');
261
281
  }
262
- if (!totalUnknown && !dedupe && totalSum !== allRows.length) {
263
- warnings.push(`台账 total 合计 ${totalSum} 与载入行数 ${allRows.length} 不一致,结果可能不完整。`);
282
+ // 不完整判定按**去重前**的载入行数与 total 比(原先加了 `!dedupe` 条件,
283
+ // 恰好在最可能重复的场景下把唯一的完整性守卫关掉了)。
284
+ if (!totalUnknown && totalSum !== rawRowCount) {
285
+ warnings.push(`台账 total 合计 ${totalSum} 与载入行数 ${rawRowCount} 不一致,结果可能不完整。`);
286
+ }
287
+ if (droppedByDedupe > 0) {
288
+ warnings.push(`按数据 ID 去重丢弃了 ${droppedByDedupe} 行(来源窗口重叠或同页落入两次)。`);
264
289
  }
265
290
  const data = {
266
291
  sources: sourceInfo,
267
292
  sourceCount: sources.length,
268
293
  dedupe,
269
294
  mergedRows: allRows.length,
295
+ rawRows: rawRowCount,
296
+ droppedByDedupe,
270
297
  totalSum: totalUnknown ? null : totalSum,
271
298
  totalUnknown,
272
299
  truncated: truncatedAny,
273
300
  filteredRows: rows.length,
274
301
  warnings,
275
302
  };
303
+ /**
304
+ * 求和:**区分字段粒度**。
305
+ *
306
+ * - `entitySumFields` 里的字段按 `entityKey` 去重(每实体一次、取最大)后求和 —— 合同级字段;
307
+ * - 其余 `sum` 字段照常按行累加 —— 期次级字段。
308
+ * 另做一次**重复实体探测**:同一 `entityKey` 在本次结果里出现多行、又要对合同级字段求和时,
309
+ * 回一条醒目 warning(不静默给数),并给出修正写法。
310
+ */
311
+ const entityKeyOf = (row) => (entityKey.map((field) => cellText(row[field]) || '(空)').join(' / '));
312
+ const sumsOf = (items) => {
313
+ const out = {};
314
+ for (const field of sum) {
315
+ if (entityKey.length && entitySumFields.has(field)) {
316
+ const perEntity = new Map();
317
+ for (const item of items) {
318
+ const key = entityKeyOf(item);
319
+ perEntity.set(key, Math.max(perEntity.get(key) ?? 0, toNumber(item[field])));
320
+ }
321
+ out[field] = Number([...perEntity.values()].reduce((acc, value) => acc + value, 0).toFixed(2));
322
+ }
323
+ else {
324
+ out[field] = Number(items.reduce((acc, item) => acc + toNumber(item[field]), 0).toFixed(2));
325
+ }
326
+ }
327
+ return out;
328
+ };
329
+ const contractLevelFields = sum.filter((field) => entitySumFields.has(field));
330
+ /** 同一合同号出现多行的实体数(用于"未传 entityKey 时"的定向告警,避免对一行一合同的台账刷屏)。 */
331
+ const duplicateEntities = (() => {
332
+ const keyFields = entityKey.length
333
+ ? entityKey
334
+ : (rows.some((row) => cellText(row.hth)) ? ['hth'] : []);
335
+ if (keyFields.length === 0)
336
+ return 0;
337
+ const counter = new Map();
338
+ for (const row of rows) {
339
+ const values = keyFields.map((field) => cellText(row[field]));
340
+ if (values.every((value) => !value))
341
+ continue;
342
+ const key = values.map((value) => value || '(空)').join(' / ');
343
+ counter.set(key, (counter.get(key) ?? 0) + 1);
344
+ }
345
+ return [...counter.values()].filter((count) => count > 1).length;
346
+ })();
347
+ if (duplicateEntities > 0) {
348
+ if (entityKey.length && contractLevelFields.length > 0) {
349
+ warnings.push(`有 ${duplicateEntities} 个实体(${entityKey.join(' / ')})在本次结果里出现多行;`
350
+ + `合同级字段「${contractLevelFields.join(' / ')}」已按实体去重后求和(每实体取一次),其余字段仍按行累加。`);
351
+ }
352
+ else {
353
+ warnings.push(`有 ${duplicateEntities} 个合同号在本次结果里出现多行(同一合同多期/多分片)。`
354
+ + '当前所有求和字段都按**行**累加——若其中含合同级字段(合同总金额 `htzje` / 已收款 `sumsk` 等),'
355
+ + '数值会重复计入;请补 `entityKey:["hth"]` + `entitySumFields:["<合同级字段>"]` 重跑。');
356
+ }
357
+ }
276
358
  if (rows.length > 0) {
277
359
  if (by.length > 0) {
278
360
  const groups = new Map();
@@ -286,22 +368,12 @@ export const contractLedgerOperations = [
286
368
  }
287
369
  const groupList = [...groups.entries()]
288
370
  .sort((a, b) => b[1].length - a[1].length)
289
- .map(([key, items]) => {
290
- const sums = {};
291
- for (const field of sum) {
292
- sums[field] = Number(items.reduce((acc, item) => acc + toNumber(item[field]), 0).toFixed(2));
293
- }
294
- return { key, rows: items.length, sums };
295
- });
371
+ .map(([key, items]) => ({ key, rows: items.length, sums: sumsOf(items) }));
296
372
  data.groups = groupList;
297
373
  data.groupCount = groupList.length;
298
374
  }
299
375
  else {
300
- const sums = {};
301
- for (const field of sum) {
302
- sums[field] = Number(rows.reduce((acc, row) => acc + toNumber(row[field]), 0).toFixed(2));
303
- }
304
- data.totals = { rows: rows.length, sums };
376
+ data.totals = { rows: rows.length, sums: sumsOf(rows) };
305
377
  }
306
378
  if (detail) {
307
379
  data.detail = rows.slice(0, limit).map((row) => ({
@@ -21,12 +21,25 @@ function buildQueryPlan(metric) {
21
21
  note: cond.note ?? null,
22
22
  }));
23
23
  const unresolved = unresolvedMetricFields(metric);
24
+ /**
25
+ * 口径提示 + **执行器分派**(2026-12-01 修复)。
26
+ *
27
+ * 事故:三种聚合方式原先**一律**指向 `contract.ledger.aggregate`,而那个执行器只会"按行求和"——
28
+ * 于是按计划执行「新签客户数(整窗去重)」会得到"行数"、执行「回款率」会得到"分子之和",
29
+ * 与 note 声明的口径不一致(声明与执行器不匹配)。
30
+ * 现在:`sum` → `contract.ledger.aggregate`(并提示合同级字段需传 entityKey/entitySumFields);
31
+ * `countDistinct` / `ratio` → `contract.ledger.stat`(该引擎按整窗去重 / Σ分子÷Σ分母,分母 0 → null)。
32
+ */
33
+ const aggregateOperation = metric.aggregation === 'sum'
34
+ ? 'contract.ledger.aggregate'
35
+ : 'contract.ledger.stat';
24
36
  const aggregateHint = metric.aggregation === 'countDistinct'
25
- ? `取回结果后按「${metric.distinct?.dataKey ?? metric.metricDataKey}」键去重计数(字段「${metric.distinct?.field ?? metric.metricField}」);跨月合计按整窗去重,不是各月相加。`
37
+ ? `取回结果后按「${metric.distinct?.dataKey ?? metric.metricDataKey}」键去重计数(字段「${metric.distinct?.field ?? metric.metricField}」);跨月合计按整窗去重,不是各月相加。⛔ 不要用 contract.ledger.aggregate 的按行求和代替(那是行数,不是客户数)。`
26
38
  : metric.aggregation === 'ratio'
27
- ? `取回结果后按「${metric.ratio?.numerator.dataKey}」求和 ÷「${metric.ratio?.denominator.dataKey}」求和 ×100%,分子分母必须同台账同窗口;分母为 0 返回 null。`
39
+ ? `取回结果后按「${metric.ratio?.numerator.dataKey}」求和 ÷「${metric.ratio?.denominator.dataKey}」求和 ×100%,分子分母必须同台账同窗口;分母为 0 返回 null。⛔ 不要对各月比率求平均,也不要用按行求和的执行器。`
28
40
  : metric.metricDataKey
29
41
  ? `取回结果后按返回行的「${metric.metricDataKey}」键求和(字段「${metric.metricField}」);该键来自 getListDatas 响应 data.columns 的 dataKey,不是字段中文名。`
42
+ + '⚠️ 若该字段是**合同级**(合同总金额 / 已收款等)而同一合同可能出现多行,必须让 aggregate 带上 `entityKey:["hth"]` + `entitySumFields:["<合同级字段>"]`,否则同一合同会被重复计入。'
30
43
  : `取回结果后按「${metric.metricField}」对应返回键求和;键名未登记,先核对非空键再汇总。`;
31
44
  return {
32
45
  operation: 'contract.performance.list.query',
@@ -42,7 +55,7 @@ function buildQueryPlan(metric) {
42
55
  metricFieldKey: metric.metricFieldId ? `field_${metric.metricFieldId}` : null,
43
56
  metricDataKey: metric.metricDataKey,
44
57
  aggregation: metric.aggregation,
45
- aggregateOperation: 'contract.ledger.aggregate',
58
+ aggregateOperation,
46
59
  aggregateHint,
47
60
  unresolvedFields: unresolved,
48
61
  resolveHint: unresolved.length