weaver-work-cli 0.1.46 → 0.1.48

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 (187) hide show
  1. package/dist/chunks/{archive-oa-BBDP7AKJ.js → archive-oa-EDJDU3V4.js} +454 -5
  2. package/dist/chunks/{attachment-content-MCXQBD6N.js → attachment-content-4KSNBPRO.js} +3 -3
  3. package/dist/chunks/{chunk-UFIFZ4YC.js → chunk-2BQESR2U.js} +1 -1
  4. package/dist/chunks/{chunk-727FH2NI.js → chunk-2IGZUMNG.js} +15 -2
  5. package/dist/chunks/{chunk-76H3IKH6.js → chunk-5B5JXTY2.js} +35 -35
  6. package/dist/chunks/{chunk-Q4OYAQYH.js → chunk-72MI3MBX.js} +4 -0
  7. package/dist/chunks/{chunk-4RWS2YYL.js → chunk-BCACE6VV.js} +2 -2
  8. package/dist/chunks/{chunk-AD46OMQK.js → chunk-EFOUMXIX.js} +119 -44
  9. package/dist/chunks/{chunk-IRMIEDXN.js → chunk-FEP6ELMR.js} +1 -1
  10. package/dist/chunks/{chunk-JB34OE7R.js → chunk-NBEWUR7L.js} +1 -1
  11. package/dist/chunks/{chunk-6V5ZPKHV.js → chunk-NK74RE5F.js} +2 -2
  12. package/dist/chunks/{chunk-GSZTA43P.js → chunk-OCYRVZGN.js} +2 -2
  13. package/dist/chunks/{chunk-OXHHJWNC.js → chunk-PSPOFLSU.js} +1 -1
  14. package/dist/chunks/{chunk-6AXKWFKG.js → chunk-R2HHLJNN.js} +4 -4
  15. package/dist/chunks/{chunk-PSOMGA3U.js → chunk-SVFG6EMV.js} +35 -6
  16. package/dist/chunks/{chunk-IP4CWQCF.js → chunk-WMSAWAWZ.js} +8 -8
  17. package/dist/chunks/{conflict-H7EHQXYY.js → conflict-APGSD5E7.js} +2 -2
  18. package/dist/chunks/{contract-3QLAGYQL.js → contract-N6P2HIIE.js} +425 -187
  19. package/dist/chunks/{create-flow-VRVJEOBX.js → create-flow-5TXFOC7X.js} +6 -6
  20. package/dist/chunks/{ehr-SH2LM3NK.js → ehr-XI4BIVR2.js} +16 -5
  21. package/dist/chunks/{env-66FPSJDV.js → env-B6GKA2J3.js} +2 -2
  22. package/dist/chunks/{factory-UH2TZBVA.js → factory-MFCKLUT6.js} +1 -1
  23. package/dist/chunks/{group-chat-CAKMMV7K.js → group-chat-YE7WIBFO.js} +3 -3
  24. package/dist/chunks/{im-NJB7ZYMH.js → im-3RCNL5GT.js} +107 -1
  25. package/dist/chunks/{invoice-OQP3TMKQ.js → invoice-FXWH5GPO.js} +209 -0
  26. package/dist/chunks/{lazy-dispatch-DD6ULZ3I.js → lazy-dispatch-XSAHDK6Z.js} +2 -2
  27. package/dist/chunks/{meeting-VTBFW4HI.js → meeting-RYZV2JTQ.js} +10 -10
  28. package/dist/chunks/{reception-5WITA44R.js → reception-VL6TKVAW.js} +480 -26
  29. package/dist/chunks/{recruit-stage-CAKZTUA7.js → recruit-stage-ERZD3ZNB.js} +52 -16
  30. package/dist/chunks/{registry-JVQBLFQ5.js → registry-22O6UG4I.js} +10 -10
  31. package/dist/chunks/{registry-AQVGHUM6.js → registry-7VZ6YJUF.js} +2 -2
  32. package/dist/chunks/{registry-PVUZQDDQ.js → registry-BUTEDK3C.js} +1 -1
  33. package/dist/chunks/{room-recommend-5U55FMXZ.js → room-recommend-IMZPJMYB.js} +4 -4
  34. package/dist/chunks/{schedule-IDETODCA.js → schedule-SPPAHER2.js} +4 -4
  35. package/dist/chunks/{workflow-BSYT5TGL.js → workflow-WVEFJ6KC.js} +2 -2
  36. package/dist/core/refs.js +19 -2
  37. package/dist/index.js +13 -13
  38. package/dist/shortcuts/archive-oa/constants.js +42 -0
  39. package/dist/shortcuts/archive-oa/host.js +2 -2
  40. package/dist/shortcuts/archive-oa/index.js +38 -0
  41. package/dist/shortcuts/archive-oa/operations/borrow-car.js +117 -3
  42. package/dist/shortcuts/archive-oa/operations/my-borrow-contract.js +271 -0
  43. package/dist/shortcuts/archive-oa/operations/registry.js +5 -3
  44. package/dist/shortcuts/contract/index.js +9 -1
  45. package/dist/shortcuts/contract/manifest.js +14 -2
  46. package/dist/shortcuts/contract/operations/card.js +231 -0
  47. package/dist/shortcuts/contract/operations/registry.js +2 -0
  48. package/dist/shortcuts/contract/operations/review.js +16 -5
  49. package/dist/shortcuts/contract/operations/summary.js +25 -17
  50. package/dist/shortcuts/ehr/operations/recruit-write.js +22 -5
  51. package/dist/shortcuts/ehr/recruit-stage/operations/interview-arrange.js +17 -8
  52. package/dist/shortcuts/ehr/recruit-stage/shared.js +33 -8
  53. package/dist/shortcuts/im/index.js +128 -0
  54. package/dist/shortcuts/im/operations/session.js +6 -0
  55. package/dist/shortcuts/invoice/manifest.js +60 -0
  56. package/dist/shortcuts/invoice/operations/registry.js +2 -0
  57. package/dist/shortcuts/invoice/operations/reim-subsidy.js +163 -0
  58. package/dist/shortcuts/meeting/operations/eb/conflict.js +26 -3
  59. package/dist/shortcuts/meeting/operations/eb/continuation-alias.js +63 -0
  60. package/dist/shortcuts/meeting/operations/eb/create-flow.js +71 -12
  61. package/dist/shortcuts/meeting/operations/eb/factory.js +5 -3
  62. package/dist/shortcuts/reception/host.js +33 -1
  63. package/dist/shortcuts/reception/index.js +19 -0
  64. package/dist/shortcuts/reception/manifest.js +53 -1
  65. package/dist/shortcuts/reception/operations/ask.js +18 -0
  66. package/dist/shortcuts/reception/operations/compose.js +113 -3
  67. package/dist/shortcuts/reception/operations/leads.js +245 -0
  68. package/dist/shortcuts/reception/operations/markdown.js +22 -0
  69. package/dist/shortcuts/reception/operations/registry.js +2 -0
  70. package/dist/shortcuts/reception/operations/render.js +36 -3
  71. package/dist/shortcuts/reception/operations/restaurant-rooms.js +118 -0
  72. package/dist/shortcuts/reception/operations/restaurant.js +251 -0
  73. package/dist/shortcuts/reception/operations/restaurantrooms.js +42 -0
  74. package/dist/shortcuts/reception/operations/schedule.js +7 -1
  75. package/dist/shortcuts/reception/upload.js +22 -6
  76. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +17 -8
  77. package/dist/shortcuts/recruit-stage/shared.js +42 -14
  78. package/docs/archive-oa.md +4 -2
  79. package/docs/invoice.md +1 -0
  80. package/package.json +1 -1
  81. package/skill-template/domains/archive-oa.md +2 -1
  82. package/skill-template/master-skill-template.md +1 -0
  83. package/skill-template/skill-template.md +1 -0
  84. package/skills/weaver-e10-archive-oa/SKILL.md +33 -6
  85. package/skills/weaver-e10-archive-oa/references/borrow-car.md +32 -7
  86. package/skills/weaver-e10-archive-oa/references/contract-search.md +32 -0
  87. package/skills/weaver-e10-archive-oa/references/disabled-capabilities.md +1 -1
  88. package/skills/weaver-e10-archive-oa/references/my-borrow-contract.md +97 -0
  89. package/skills/weaver-e10-archive-oa/references/my-borrow.md +6 -1
  90. package/skills/weaver-e10-archive-oa/references/qys-contract-search.md +22 -0
  91. package/skills/weaver-e10-calendar/SKILL.md +1 -1
  92. package/skills/weaver-e10-calendar/references/calendar-query.md +1 -1
  93. package/skills/weaver-e10-calendar/references/calendar-write.md +9 -9
  94. package/skills/weaver-e10-cowork/SKILL.md +9 -6
  95. package/skills/weaver-e10-jinchengda/SKILL.md +10 -7
  96. package/skills/weaver-e10-jinchengda/references/contract-action-card-template.html +17 -0
  97. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +263 -35
  98. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +8 -5
  99. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  100. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +175 -22
  101. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
  102. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +1 -1
  103. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +1 -1
  104. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +124 -19
  105. package/skills/weaver-e10-jinchengda/references/contract-element-extract.md +2 -2
  106. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +4 -4
  107. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +6 -0
  108. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  109. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +1 -1
  110. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +1 -1
  111. package/skills/weaver-e10-jinchengda/references/contract-risk-report-template.html +178 -0
  112. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
  113. package/skills/weaver-e10-jinchengda/references/orchestration.md +7 -7
  114. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +279 -0
  115. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +450 -0
  116. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +358 -0
  117. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +505 -0
  118. package/skills/weaver-e10-jucailin/SKILL.md +7 -4
  119. package/skills/weaver-e10-jucailin/references/recruit-create.md +3 -2
  120. package/skills/weaver-e10-jucailin/references/recruit-read.md +2 -1
  121. package/skills/weaver-e10-jucailin/references/recruit-stage-ops.md +3 -3
  122. package/skills/weaver-e10-jucailin/references/safety-boundaries.md +30 -2
  123. package/skills/weaver-e10-mail/SKILL.md +17 -4
  124. package/skills/weaver-e10-meeting/SKILL.md +94 -409
  125. package/skills/weaver-e10-meeting/references/create-flow.md +188 -0
  126. package/skills/weaver-e10-meeting/references/create-guardrails.md +234 -0
  127. package/skills/weaver-e10-meeting/references/pitfalls.md +40 -0
  128. package/skills/weaver-e10-reception-flow/SKILL.md +62 -18
  129. package/skills/weaver-e10-reception-flow/data/fields-snapshot.json +628 -26
  130. package/skills/weaver-e10-reception-flow/references/fields-snapshot.md +96 -26
  131. package/skills/weaver-e10-reception-flow/scripts/render.py +81 -2
  132. package/skills/weaver-e10-recruit-stage/SKILL.md +45 -12
  133. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +58 -8
  134. package/skills/weaver-e10-recruit-stage/references/position-templates.md +5 -0
  135. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +1 -1
  136. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +1 -1
  137. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +40 -11
  138. package/skills/weaver-e10-recruit-stage/references/recruit-list-candidate.md +1 -1
  139. package/skills/weaver-e10-recruit-stage/references/recruit-list-interview.md +1 -1
  140. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  141. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +16 -0
  142. package/skills/weaver-e10-recruit-stage/references/recruit-resume-parse.md +1 -1
  143. package/skills/weaver-e10-recruit-stage/references/recruit-search-candidate.md +1 -1
  144. package/skills/weaver-e10-recruit-stage/references/recruit-urge-feedback.md +1 -1
  145. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +127 -0
  146. package/skills/weaver-e10-shijingran/SKILL.md +6 -2
  147. package/skills/weaver-e10-shijingran/references/source-manifest.json +5 -4
  148. package/skills/weaver-e10-workflow/SKILL.md +1 -1
  149. package/skills/weaver-e10-yepiaotong/SKILL.md +14 -8
  150. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +1 -1
  151. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +1 -1
  152. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +10 -3
  153. package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +2 -0
  154. package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +2 -0
  155. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +69 -7
  156. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +3 -3
  157. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +9 -16
  158. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +6 -5
  159. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +206 -92
  160. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +27 -21
  161. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +35 -0
  162. package/skills/weaver-e10-yimiaoban/SKILL.md +2 -1
  163. package/skills/weaver-e10-yimiaoban/references/msg-write.md +32 -0
  164. package/skills/weaver-e10-yimiaoban/references/session-sysmsg.md +3 -0
  165. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +11 -11
  166. package/dist/chunks/{ebuilder-form-GWDTKEI2.js → ebuilder-form-I5ZIX4WO.js} +3 -3
  167. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-README.md +0 -0
  168. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-SKILL.md +0 -0
  169. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-openai.yaml +0 -0
  170. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-position-templates.md +0 -0
  171. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-arrange-interview.md +0 -0
  172. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-capability-check.md +0 -0
  173. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-check-install.md +0 -0
  174. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-detail-process.md +0 -0
  175. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-edit-interview-feedback.md +0 -0
  176. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-jd-create.md +0 -0
  177. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-jd-template.md +0 -0
  178. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-list-candidate.md +0 -0
  179. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-list-interview.md +0 -0
  180. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-match-candidates.md +0 -0
  181. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-output-links.md +0 -0
  182. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resolve-creator.md +0 -0
  183. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resolve-metadata.md +0 -0
  184. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resume-import.md +0 -0
  185. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resume-parse.md +0 -0
  186. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-search-candidate.md +0 -0
  187. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-urge-feedback.md +0 -0
@@ -122,6 +122,30 @@ function sectionHtml(section) {
122
122
  return parts.join('');
123
123
  }
124
124
  const SECTION_TYPES = ['alert', 'reasons', 'grid', 'table', 'checks', 'list', 'next'];
125
+ /**
126
+ * 按固定模板把摘要数据渲染成完整 HTML。
127
+ * 抽成导出函数,供 contract.summary.render 与 contract.card.render(内嵌摘要)共用。
128
+ */
129
+ export function renderSummaryHtml(data) {
130
+ const sections = asArray(data.sections);
131
+ if (sections.length === 0) {
132
+ throw contractValidationError('sections_required', '摘要数据必须包含非空的 sections 数组');
133
+ }
134
+ const unknownTypes = sections
135
+ .map((section) => String(section?.type ?? ''))
136
+ .filter((type) => !SECTION_TYPES.includes(type));
137
+ if (unknownTypes.length) {
138
+ throw contractValidationError('section_type_unknown', `未知的 section 类型:${[...new Set(unknownTypes)].join(', ')};支持 ${SECTION_TYPES.join(' / ')}`);
139
+ }
140
+ const badge = esc(data.badge ?? '合同');
141
+ const title = esc(data.title ?? '合同摘要');
142
+ const meta = esc(data.meta ?? '');
143
+ const body = sections.map((section) => sectionHtml(section)).join('');
144
+ return `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">`
145
+ + `<title>合同摘要 - ${title}</title><style>${CSS}</style></head><body><div class="w">`
146
+ + `<div class="hd"><span class="bd">${badge}</span><h1>${title}</h1><div class="mt">${meta}</div></div>`
147
+ + `${body}</div></body></html>`;
148
+ }
125
149
  export const contractSummaryOperations = [
126
150
  {
127
151
  name: 'contract.summary.render',
@@ -142,23 +166,7 @@ export const contractSummaryOperations = [
142
166
  throw contractValidationError('data_unreadable', `无法读取摘要数据 JSON:${message}`);
143
167
  }
144
168
  const sections = asArray(data.sections);
145
- if (sections.length === 0) {
146
- throw contractValidationError('sections_required', '摘要数据必须包含非空的 sections 数组');
147
- }
148
- const unknownTypes = sections
149
- .map((section) => String(section?.type ?? ''))
150
- .filter((type) => !SECTION_TYPES.includes(type));
151
- if (unknownTypes.length) {
152
- throw contractValidationError('section_type_unknown', `未知的 section 类型:${[...new Set(unknownTypes)].join(', ')};支持 ${SECTION_TYPES.join(' / ')}`);
153
- }
154
- const badge = esc(data.badge ?? '合同');
155
- const title = esc(data.title ?? '合同摘要');
156
- const meta = esc(data.meta ?? '');
157
- const body = sections.map((section) => sectionHtml(section)).join('');
158
- const html = `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">`
159
- + `<title>合同摘要 - ${title}</title><style>${CSS}</style></head><body><div class="w">`
160
- + `<div class="hd"><span class="bd">${badge}</span><h1>${title}</h1><div class="mt">${meta}</div></div>`
161
- + `${body}</div></body></html>`;
169
+ const html = renderSummaryHtml(data);
162
170
  writeFileSync(outPath, html, 'utf8');
163
171
  const bytes = Buffer.byteLength(html, 'utf8');
164
172
  return {
@@ -194,16 +194,29 @@ async function runEsb(host, objId, dataIds, esbActionIds) {
194
194
  }
195
195
  /** ds/options 运行时解析枚举(面试方式/轮次/结果等):name → optionId */
196
196
  export async function getDsOptions(host, objId, fieldId, groupId) {
197
+ const { map } = await getDsOptionsFull(host, objId, fieldId, groupId);
198
+ return map;
199
+ }
200
+ /**
201
+ * 全量版:map 排除 archive=1 的禁用项(实测 AI面试(小程序) 是唯一 archive:"1",选中会被后端
202
+ * 静默丢弃/落脏值),disabled 单独列出供「已禁用」精确报错。2026-11-09 实证。
203
+ */
204
+ export async function getDsOptionsFull(host, objId, fieldId, groupId) {
197
205
  const response = (await host.request({
198
206
  path: '/api/ebuilder/common/ds/options',
199
207
  query: { fieldName: fieldId, objId, sourceType: 'FORM', groupId },
200
208
  }));
201
209
  const map = {};
210
+ const disabled = [];
202
211
  for (const option of response?.data || []) {
203
- if (option?.name && option?.id)
212
+ if (!option?.name || !option?.id)
213
+ continue;
214
+ if (String(option.archive) === '1')
215
+ disabled.push({ name: String(option.name), id: String(option.id) });
216
+ else
204
217
  map[option.name] = String(option.id);
205
218
  }
206
- return map;
219
+ return { map, disabled };
207
220
  }
208
221
  /**
209
222
  * 人员名称 → userId。
@@ -827,10 +840,13 @@ async function buildInterviewPlan(env, cache, args) {
827
840
  throw ehrValidationError('recruit_field_missing', `面试计划表单缺少字段 ${key}(环境缓存 ds/fields 未解析到,请重建环境缓存后重试)`);
828
841
  }
829
842
  }
830
- const typeMap = await getDsOptions(host, objId, fieldIdOf('interview_type'), cache.appId);
831
- const typeOptionId = typeMap[type];
843
+ const typeFull = await getDsOptionsFull(host, objId, fieldIdOf('interview_type'), cache.appId);
844
+ const typeOptionId = typeFull.map[type];
832
845
  if (!typeOptionId) {
833
- throw ehrValidationError('enum_invalid', `面试方式「${type}」不在枚举中(${Object.keys(typeMap).join(' / ')})`);
846
+ if (typeFull.disabled.some((d) => d.name === type)) {
847
+ throw ehrValidationError('enum_disabled', `面试方式「${type}」已禁用(该枚举项 archive=1),请改用其它面试方式`);
848
+ }
849
+ throw ehrValidationError('enum_invalid', `面试方式「${type}」不在枚举中(${Object.keys(typeFull.map).join(' / ')})`);
834
850
  }
835
851
  const sessionMap = await getDsOptions(host, objId, fieldIdOf('interview_session'), cache.appId);
836
852
  const sessionOptionId = sessionMap[session];
@@ -985,6 +1001,7 @@ const interviewArrangePrepare = {
985
1001
  : {}),
986
1002
  notify: notify ? '将触发「新建日程」面试通知动作流(外部通知)' : '面试通知默认不触发',
987
1003
  },
1004
+ deprecated: '本入口副作用不含页面按钮动作流(无新建EB日程/创建视频会议/AI面试提醒)且不并入页面默认值,建议改用 recruit-stage.interview.arrange.*(能力相同、副作用完整)',
988
1005
  willSubmit: { formId: plan.formId, objId: plan.objId, dataDetails: plan.dataDetails },
989
1006
  continuation: token,
990
1007
  expiresInSeconds: CONTINUATION_TTL_SECONDS,
@@ -22,7 +22,7 @@
22
22
  import { randomUUID } from 'node:crypto';
23
23
  import { rsSuccess, schemaOf } from './types.js';
24
24
  import { rsFail, rsValidationError, rsConfirmationError } from '../errors.js';
25
- import { objIdOf, formIdOf, getFormLayout, getFormLayoutMeta, saveFormData, runEsb, getFormButtons, resolvePersonId, getDsOptions, findMenuNode, resolveCurrentUser, buildCardUrl, buildListUrl, talentLinkExtra, pickSaveButtonActions, computeRequiredHint, randHex32, dsOptionsSnapshot, restoreDsOptions, invalidateEnvCache, verifySubmitted, expectedFields, probeCreatePermission, } from '../shared.js';
25
+ import { objIdOf, formIdOf, getFormLayout, getFormLayoutMeta, saveFormData, runEsb, getFormButtons, resolvePersonId, getDsOptions, getDsOptionsFull, findMenuNode, resolveCurrentUser, buildCardUrl, buildListUrl, talentLinkExtra, pickSaveButtonActions, computeRequiredHint, randHex32, dsOptionsSnapshot, restoreDsOptions, invalidateEnvCache, verifySubmitted, expectedFields, probeCreatePermission, } from '../shared.js';
26
26
  // 面试计划表单字段 dataKey(缓存 fields 里取)。
27
27
  // 注意:digital_id 不放入此列表——它只在「面试方式含 AI」时才是必填,
28
28
  // 放进来会让未部署数字人的环境连非 AI 面试都建不了(单独按需校验)。
@@ -266,9 +266,14 @@ async function buildPlan(opts) {
266
266
  getDsOptions(host, objId, fid('interview_type')),
267
267
  getDsOptions(host, objId, fid('interview_session')),
268
268
  ]);
269
- const typeId = typeMap[type];
270
- if (!typeId)
271
- throw rsFail('面试方式「' + type + '」不在枚举中(' + Object.keys(typeMap).join('/') + ')');
269
+ const typeFull = await getDsOptionsFull(host, objId, fid('interview_type'));
270
+ const typeId = typeFull.map[type];
271
+ if (!typeId) {
272
+ if (typeFull.disabled.some(function (d) { return d.name === type; })) {
273
+ throw rsFail('面试方式「' + type + '」已禁用(该枚举项 archive=1),请改用其它面试方式');
274
+ }
275
+ throw rsFail('面试方式「' + type + '」不在枚举中(' + Object.keys(typeFull.map).join('/') + ')');
276
+ }
272
277
  const sessionId = sessionMap[session];
273
278
  if (!sessionId)
274
279
  throw rsFail('面试轮次「' + session + '」不在枚举中(' + Object.keys(sessionMap).join('/') + ')');
@@ -786,10 +791,14 @@ async function prefill(args, env) {
786
791
  const typeFid = fields.interview_type;
787
792
  if (!typeFid)
788
793
  throw rsFail('面试计划缺少字段 interview_type(ds/fields 解析不到)');
789
- const typeMap = await getDsOptions(ctx.host, objId, typeFid);
790
- const typeId = typeMap[typeKey];
791
- if (!typeId)
792
- throw rsFail('面试方式「' + typeKey + '」不在枚举中(' + Object.keys(typeMap).join('/') + ')');
794
+ const typeFull = await getDsOptionsFull(ctx.host, objId, typeFid);
795
+ const typeId = typeFull.map[typeKey];
796
+ if (!typeId) {
797
+ if (typeFull.disabled.some(function (d) { return d.name === typeKey; })) {
798
+ throw rsFail('面试方式「' + typeKey + '」已禁用(该枚举项 archive=1),请改用其它面试方式');
799
+ }
800
+ throw rsFail('面试方式「' + typeKey + '」不在枚举中(' + Object.keys(typeFull.map).join('/') + ')');
801
+ }
793
802
  const cardUrl = resolveTalentCardUrl(ctx, talentId);
794
803
  const listUrl = await resolveInterviewListUrl(ctx).catch(() => null);
795
804
  const jsExpr = `(() => { const W = window.WeFormSDK; const i = W && W.getWeFormInstance('ebuilderform', '${formId}');`
@@ -421,6 +421,12 @@ function ambiguousPerson(keyword, rows) {
421
421
  * prepare 可通过 dsOptionsSnapshot() 把结果放进 continuation,apply 用 restoreDsOptions() 复用,避免重复请求。
422
422
  */
423
423
  const dsOptionsMemo = new Map();
424
+ /**
425
+ * getDsOptionsFull 独立 memo:它返回 {map, disabled},结构与 dsOptionsMemo 的 Record 不同。
426
+ * 混用会让 dsOptionsSnapshot() 把 full 结构写进 continuation,apply 复用时报类型错误,
427
+ * 所以两者分开缓存;full 的结果不进快照,apply 时按需回源。
428
+ */
429
+ const dsOptionsFullMemo = new Map();
424
430
  export function restoreDsOptions(snapshot) {
425
431
  for (const [key, value] of Object.entries(snapshot || {})) {
426
432
  if (value && typeof value === 'object' && Object.keys(value).length) {
@@ -508,6 +514,7 @@ export async function verifySubmitted(opts) {
508
514
  /** 回查/校验失败时清空进程内枚举 memo,并标记磁盘环境缓存失效(下次自动重建)。 */
509
515
  export function invalidateEnvCache(baseUrl, appId) {
510
516
  dsOptionsMemo.clear();
517
+ dsOptionsFullMemo.clear();
511
518
  if (!baseUrl || !appId)
512
519
  return;
513
520
  try {
@@ -518,9 +525,10 @@ export function invalidateEnvCache(baseUrl, appId) {
518
525
  }
519
526
  catch { /* 缓存文件不存在/只读盘:不影响主流程 */ }
520
527
  }
521
- export async function getDsOptions(host, objId, fieldId, groupId = '') {
522
- const key = objId + ':' + fieldId;
523
- const hit = dsOptionsMemo.get(key);
528
+ /** 全量版:map 排除 archive=1 的禁用项,disabled 单独列出供「已禁用」精确报错。 */
529
+ export async function getDsOptionsFull(host, objId, fieldId, groupId = '') {
530
+ const key = objId + ':' + fieldId + (groupId ? ':' + groupId : '') + ':full';
531
+ const hit = dsOptionsFullMemo.get(key);
524
532
  if (hit)
525
533
  return hit;
526
534
  const task = (async () => {
@@ -531,14 +539,31 @@ export async function getDsOptions(host, objId, fieldId, groupId = '') {
531
539
  });
532
540
  const list = r?.data || [];
533
541
  const map = {};
534
- for (const x of list)
535
- if (x?.name && x?.id)
542
+ const disabled = [];
543
+ for (const x of list) {
544
+ if (!x?.name || !x?.id)
545
+ continue;
546
+ if (String(x.archive) === '1')
547
+ disabled.push({ name: String(x.name), id: String(x.id) });
548
+ else
536
549
  map[String(x.name)] = String(x.id);
550
+ }
537
551
  // 空结果不缓存:字典引用类字段可能临时返回空,下次应能重新回源
538
- if (!Object.keys(map).length)
539
- dsOptionsMemo.delete(key);
540
- return map;
552
+ if (!Object.keys(map).length && !disabled.length)
553
+ dsOptionsFullMemo.delete(key);
554
+ return { map, disabled };
541
555
  })();
556
+ dsOptionsFullMemo.set(key, task);
557
+ task.catch(() => { dsOptionsFullMemo.delete(key); });
558
+ return task;
559
+ }
560
+ export async function getDsOptions(host, objId, fieldId, groupId = '') {
561
+ // key 沿用旧口径(不含 groupId),保证 dsOptionsSnapshot() 的键与 apply 复用一致
562
+ const key = objId + ':' + fieldId;
563
+ const hit = dsOptionsMemo.get(key);
564
+ if (hit)
565
+ return hit;
566
+ const task = getDsOptionsFull(host, objId, fieldId, groupId).then((r) => r.map);
542
567
  dsOptionsMemo.set(key, task);
543
568
  task.catch(() => { dsOptionsMemo.delete(key); });
544
569
  return task;
@@ -102,6 +102,126 @@ function boolOption(value) {
102
102
  return undefined;
103
103
  return value === true || value === 'true' || value === '1';
104
104
  }
105
+ const BATCH_MAX_ITEMS = 1000;
106
+ /**
107
+ * 在 item.input 里解析 `$prev.<path>` 引用:字符串值整体形如 "$prev.a.b" 时,
108
+ * 从上一个成功 item 的结果 data 里按点路径取值(典型用法:prepare 的 continuation
109
+ * 传给下一步 apply,同一进程内串行链式执行)。上一个 item 失败或路径取不到值则报错。
110
+ */
111
+ function resolvePrevRefs(input, prevData) {
112
+ const resolved = {};
113
+ for (const [key, value] of Object.entries(input)) {
114
+ if (typeof value === 'string' && value.startsWith('$prev.')) {
115
+ if (!prevData) {
116
+ throw imValidationError('prev_unavailable', `${key}:$prev 引用不可用(上一项失败或不存在)`);
117
+ }
118
+ let cursor = prevData;
119
+ for (const seg of value.slice(6).split('.')) {
120
+ if (cursor && typeof cursor === 'object' && seg in cursor) {
121
+ cursor = cursor[seg];
122
+ }
123
+ else {
124
+ throw imValidationError('prev_ref_missing', `${key}:$prev 路径 "${value.slice(6)}" 在上一项结果中不存在`);
125
+ }
126
+ }
127
+ resolved[key] = cursor;
128
+ }
129
+ else {
130
+ resolved[key] = value;
131
+ }
132
+ }
133
+ return resolved;
134
+ }
135
+ /**
136
+ * `im run-batch`:单进程内**严格串行**执行多个 operation(禁止并发),
137
+ * 等当前项出结果(成功/失败)才执行下一项;每项独立 envelope,最后输出一个聚合 envelope。
138
+ * 目的:把「N 个 operation = N 次 CLI 冷启动」压成 1 次进程启动,批量场景耗时大幅下降。
139
+ * item.input 字符串值支持 "$prev.xxx" 引用上一项结果(prepare→apply 链式场景)。
140
+ */
141
+ async function executeBatchAndPrint(ctx, input, stopOnFailure) {
142
+ const rawItems = input.items;
143
+ if (!Array.isArray(rawItems) || rawItems.length === 0) {
144
+ throw imValidationError('batch_items_required', 'batch 输入必须包含非空 items 数组');
145
+ }
146
+ if (rawItems.length > BATCH_MAX_ITEMS) {
147
+ throw imValidationError('batch_items_too_many', `items 超过上限 ${BATCH_MAX_ITEMS}`);
148
+ }
149
+ const items = [];
150
+ rawItems.forEach((raw, i) => {
151
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw) || typeof raw.operation !== 'string') {
152
+ throw imValidationError('batch_item_invalid', `items[${i}] 必须是含 operation 字符串字段的对象`);
153
+ }
154
+ const item = raw;
155
+ items.push({
156
+ operation: String(item.operation),
157
+ input: (item.input && typeof item.input === 'object' && !Array.isArray(item.input))
158
+ ? { ...item.input }
159
+ : {},
160
+ });
161
+ });
162
+ const results = [];
163
+ let prevData = null;
164
+ let prevFailed = false;
165
+ let okCount = 0;
166
+ let failCount = 0;
167
+ const started = Date.now();
168
+ for (let i = 0; i < items.length; i++) {
169
+ const { operation, input: rawInput } = items[i];
170
+ // 严格串行:上一项未落地(成功/失败)绝不开始下一项;$prev 引用且上一项失败则跳过本项
171
+ let itemError = prevFailed && Object.values(rawInput ?? {}).some((v) => typeof v === 'string' && v.startsWith('$prev.')) ? imValidationError('prev_failed_skipped', '上一项失败,本项依赖 $prev 引用被跳过') : null;
172
+ let envelope;
173
+ if (!itemError) {
174
+ try {
175
+ const merged = resolvePrevRefs(rawInput ?? {}, prevData);
176
+ const result = await executeImOperation(operation, merged, {
177
+ ctx,
178
+ host: createImHost(ctx),
179
+ continuation: createImContinuationSigner(ctx),
180
+ });
181
+ envelope = successEnvelope(operation, result);
182
+ prevData = result.data === undefined ? null : result.data;
183
+ prevFailed = false;
184
+ okCount++;
185
+ }
186
+ catch (error) {
187
+ envelope = failureEnvelope(error);
188
+ prevData = null;
189
+ prevFailed = true;
190
+ failCount++;
191
+ }
192
+ }
193
+ else {
194
+ envelope = failureEnvelope(itemError);
195
+ prevData = null;
196
+ prevFailed = true;
197
+ failCount++;
198
+ }
199
+ results.push({ index: i, operation, ...envelope });
200
+ // 进度走 stderr(不影响 stdout 的单个聚合 JSON)
201
+ process.stderr.write(`[batch ${i + 1}/${items.length}] ${operation} ${envelope.ok ? 'ok' : 'failed'}\n`);
202
+ if (stopOnFailure && !envelope.ok) {
203
+ // 剩余项不再执行,逐项记为 skipped
204
+ for (let j = i + 1; j < items.length; j++) {
205
+ results.push({ index: j, operation: items[j].operation, ok: false, error: { type: 'batch', subtype: 'skipped_stop_on_failure' } });
206
+ }
207
+ failCount += items.length - 1 - i;
208
+ break;
209
+ }
210
+ }
211
+ const ok = failCount === 0;
212
+ ctx.output.write({
213
+ schemaVersion: 1,
214
+ ok,
215
+ operation: 'im.run-batch',
216
+ data: {
217
+ results,
218
+ summary: { total: items.length, ok: okCount, failed: failCount, elapsedMs: Date.now() - started },
219
+ },
220
+ warnings: [],
221
+ }, { json: true });
222
+ if (!ok)
223
+ process.exitCode = ExitCode.GeneralError;
224
+ }
105
225
  /**
106
226
  * 易秒办(即时通讯)CLI 命令注册。
107
227
  * 所有操作统一走 `run <operation> --input-json '{}'`;便捷命令只覆盖高频只读场景,
@@ -127,6 +247,14 @@ export const imShortcut = {
127
247
  .action(action(async (ctx, operation, options) => {
128
248
  await executeAndPrint(ctx, String(operation), await inputFrom(options));
129
249
  }));
250
+ // ---- 单进程批量执行:一次 CLI 冷启动串行跑完 N 个 operation(严格串行,禁止并发) ----
251
+ withJsonInputOptions(im.command('run-batch')
252
+ .description('Run multiple im operations sequentially in one process (strictly serial, no concurrency)')
253
+ .option('--stop-on-failure', 'skip all remaining items after the first failure'))
254
+ .action(action(async (ctx, options) => {
255
+ const opts = asOptions(options);
256
+ await executeBatchAndPrint(ctx, await inputFrom(opts), boolOption(opts.stopOnFailure) === true);
257
+ }));
130
258
  // ---- 高频便捷命令:会话 ----
131
259
  const session = im.command('session').description('Session commands');
132
260
  withJsonInputOptions(session.command('list')
@@ -160,6 +160,12 @@ const sessionList = {
160
160
  sessionType: type,
161
161
  sessionTypeName: typeName,
162
162
  name,
163
+ // 目标 id:单聊对方 uid/cid、群聊 group_id、系统消息分组 group(直接可用于发消息/查消息,不用再按名字反查)
164
+ ...([1, 6, 9].includes(type) && s?.fuser
165
+ ? { toUid: str(s.fuser.uid), toCid: str(s.fuser.cid) }
166
+ : {}),
167
+ ...([2, 3, 7, 11].includes(type) && s?.group_id ? { groupId: str(s.group_id) } : {}),
168
+ ...([4, 10].includes(type) && s?.group ? { group: str(s.group) } : {}),
163
169
  unread: Number(unread),
164
170
  dontDisturb,
165
171
  unreadLabel: Number(unread) > 0 ? (dontDisturb ? `${unread}(免打扰)` : String(unread)) : '',
@@ -931,6 +931,66 @@ export const invoiceOperations = [
931
931
  },
932
932
  outputSchema: reimCandidatesOutputSchema,
933
933
  },
934
+ {
935
+ name: 'invoice.reim.subsidy.submit',
936
+ risk: 'high-risk-write',
937
+ fixed: {
938
+ path: '/api/secondev/fna/expense/reimbursement/aiCreateWf',
939
+ autoCommit: '1',
940
+ currentEmpId: 'session.userId',
941
+ detailList: 'invoices 每张一行 {relatedProcessId, relatedInvoiceId, reimbursedAmount},relatedProcessId 全部相同;reimbursedAmount 取该发票 total,合计不超过 monthlyAllowance,超额那行报「额度 − 前面行累加」,额度用完后剩下的发票不进明细',
942
+ },
943
+ inputSchema: {
944
+ type: 'object',
945
+ additionalProperties: false,
946
+ required: ['processTitle', 'reason', 'relatedProcessId', 'invoices'],
947
+ properties: {
948
+ processTitle: { type: 'string', minLength: 1, description: '报销流程标题,如「龚为明10月话费报销」' },
949
+ reason: { type: 'string', minLength: 1, description: '报销事由,如「10月话费」' },
950
+ relatedProcessId: { ...positiveId, description: '话费 / 油费事前申请的 requestId' },
951
+ invoices: {
952
+ type: 'array',
953
+ minItems: 1,
954
+ maxItems: 100,
955
+ description: '本次报销的发票,每张生成一行明细;顺序即额度扣减顺序',
956
+ items: {
957
+ type: 'object',
958
+ additionalProperties: false,
959
+ required: ['fid', 'total'],
960
+ properties: {
961
+ fid: { ...positiveId, description: '票夹发票 fid' },
962
+ total: { type: 'string', pattern: '^\\d+(\\.\\d{1,2})?$', description: '这张发票的价税合计(invoice.list 的 total)' },
963
+ },
964
+ },
965
+ },
966
+ monthlyAllowance: { type: 'string', pattern: '^\\d+(\\.\\d{1,2})?$', description: '事前申请的「月补贴额度」;不传表示不封顶' },
967
+ customerId: { ...positiveId, default: '100504500000311504', description: '相关客户 ID;不传默认泛微上海 100504500000311504' },
968
+ projectId: { type: 'string', pattern: '^([1-9]\\d*)?$', default: '', description: '相关项目 ID;没有指定时不传或传空字符串' },
969
+ },
970
+ },
971
+ outputSchema: objectSchema({
972
+ requestId: { type: 'string', description: '创建并提交成功的报销流程 requestId' },
973
+ url: { type: 'string', description: '报销流程详情页:{baseUrl}/sp/workflow/flowpage/view/{requestId}' },
974
+ processTitle: { type: 'string' },
975
+ invoiceCount: { type: 'integer', description: '实际进入明细的发票张数' },
976
+ reimbursedAmount: { type: 'string', description: '各行 reimbursedAmount 之和' },
977
+ invoiceTotal: { type: 'string', description: '传入的全部发票 total 之和(含没进明细的)' },
978
+ monthlyAllowance: { type: ['string', 'null'] },
979
+ capped: { type: 'boolean', description: '是否按月补贴额度封顶' },
980
+ details: arrayOf(objectSchema({
981
+ relatedInvoiceId: { type: 'string' },
982
+ invoiceTotal: { type: 'string' },
983
+ reimbursedAmount: { type: 'string' },
984
+ }, ['relatedInvoiceId', 'invoiceTotal', 'reimbursedAmount'])),
985
+ skippedInvoices: arrayOf(objectSchema({
986
+ relatedInvoiceId: { type: 'string' },
987
+ invoiceTotal: { type: 'string' },
988
+ }, ['relatedInvoiceId', 'invoiceTotal']), { description: '额度用完后没进明细、留在票夹的发票' }),
989
+ finalMarkdown: { type: 'string', description: '[processTitle](url),直接展示给用户' },
990
+ result: rawObject,
991
+ workflow: workflowSchema,
992
+ }, ['requestId', 'url', 'processTitle', 'invoiceCount', 'reimbursedAmount', 'invoiceTotal', 'monthlyAllowance', 'capped', 'details', 'skippedInvoices', 'finalMarkdown', 'result', 'workflow']),
993
+ },
934
994
  {
935
995
  name: 'invoice.issuing.contracts.list',
936
996
  risk: 'read',
@@ -12,6 +12,7 @@ import { InvoiceListOperation } from './list.js';
12
12
  import { InvoiceOcrPreviewOperation } from './ocr-preview.js';
13
13
  import { InvoiceReimEmployeeSuperiorsOperation, InvoiceReimFieldSearchOperation, InvoiceReimFileOcrPreviewOperation, InvoiceReimRequestsListOperation, InvoiceReimWorkflowResolveOperation, } from './reim.js';
14
14
  import { InvoiceReimCandidatesListOperation } from './reim-auto.js';
15
+ import { InvoiceReimSubsidySubmitOperation } from './reim-subsidy.js';
15
16
  import { InvoiceUpdateApplyOperation, InvoiceUpdatePrepareOperation } from './update.js';
16
17
  import { InvoiceUploadOperation } from './upload.js';
17
18
  import { InvoiceUploadAndValidateOperation } from './upload-and-validate.js';
@@ -42,6 +43,7 @@ function buildRegistry() {
42
43
  new InvoiceReimCandidatesListOperation(),
43
44
  new InvoiceReimEmployeeSuperiorsOperation(),
44
45
  new InvoiceReimFieldSearchOperation(),
46
+ new InvoiceReimSubsidySubmitOperation(),
45
47
  new InvoiceIssuingContractsListOperation(),
46
48
  new InvoiceIssuingContractDetailOperation(),
47
49
  ];
@@ -0,0 +1,163 @@
1
+ import { InvoiceCliError, invoicePartialError, invoiceValidationError, isInvoiceNetworkError } from '../errors.js';
2
+ import { asNonEmptyString, asPositiveString, workflow } from './shared.js';
3
+ const SUBSIDY_SUBMIT_PATH = '/api/secondev/fna/expense/reimbursement/aiCreateWf';
4
+ /** 泛微上海 */
5
+ const DEFAULT_CUSTOMER_ID = '100504500000311504';
6
+ /** 雪花 ID 超出 JS 安全整数:运行时支持 JSON.rawJSON 时按数字原样发出,否则退回字符串。 */
7
+ function longId(id) {
8
+ const rawJSON = JSON.rawJSON;
9
+ return typeof rawJSON === 'function' ? rawJSON(id) : id;
10
+ }
11
+ function optionalId(value, name) {
12
+ return value === undefined || value === null || value === '' ? '' : asPositiveString(value, name);
13
+ }
14
+ /** 金额按「分」取整比较,避免浮点误差。 */
15
+ function amountCents(value, name) {
16
+ if (value === undefined || value === null || value === '')
17
+ return null;
18
+ const text = typeof value === 'number' ? String(value) : value;
19
+ const match = typeof text === 'string' ? /^(\d+)(?:\.(\d{1,2}))?$/u.exec(text.trim()) : null;
20
+ const cents = match ? Number(match[1]) * 100 + Number((match[2] ?? '').padEnd(2, '0')) : NaN;
21
+ if (!Number.isSafeInteger(cents) || cents <= 0) {
22
+ throw invoiceValidationError('input_invalid', `${name} 必须是大于 0、最多两位小数的金额`);
23
+ }
24
+ return cents;
25
+ }
26
+ function formatCents(cents) {
27
+ return cents % 100 === 0 ? String(cents / 100) : (cents / 100).toFixed(2);
28
+ }
29
+ function normalizeInvoices(value) {
30
+ if (!Array.isArray(value) || value.length === 0)
31
+ throw invoiceValidationError('input_invalid', 'invoices 必须是非空数组');
32
+ if (value.length > 100)
33
+ throw invoiceValidationError('input_invalid', 'invoices 单次最多支持 100 张');
34
+ const invoices = value.map((item, index) => {
35
+ if (!item || typeof item !== 'object')
36
+ throw invoiceValidationError('input_invalid', `invoices[${index}] 必须是 {fid,total}`);
37
+ const fid = asPositiveString(String(item.fid ?? ''), `invoices[${index}].fid`);
38
+ const cents = amountCents(item.total, `invoices[${index}].total`);
39
+ if (cents === null)
40
+ throw invoiceValidationError('input_invalid', `invoices[${index}].total 必填:这张发票的价税合计`);
41
+ return { fid, cents };
42
+ });
43
+ if (new Set(invoices.map((item) => item.fid)).size !== invoices.length) {
44
+ throw invoiceValidationError('input_invalid', 'invoices 不能包含重复 fid');
45
+ }
46
+ return invoices;
47
+ }
48
+ function workflowViewUrl(baseUrl, requestId) {
49
+ return `${baseUrl.replace(/\/+$/, '')}/sp/workflow/flowpage/view/${requestId}`;
50
+ }
51
+ /**
52
+ * 话费 / 油费补贴报销:一次调用直接创建并提交报销流程(autoCommit 固定 "1")。
53
+ * 明细每行 = 一张发票 + 同一条事前申请;当前人员取登录会话。
54
+ * 明细报销金额合计不超过月补贴额度:每行取该发票价税合计,超额的那一行报「额度 − 前面行累加」,
55
+ * 额度用完后剩下的发票不进明细,留在票夹下次再报。
56
+ */
57
+ export class InvoiceReimSubsidySubmitOperation {
58
+ name = 'invoice.reim.subsidy.submit';
59
+ async execute(input, { host }) {
60
+ const processTitle = asNonEmptyString(input.processTitle, 'processTitle');
61
+ const reason = asNonEmptyString(input.reason, 'reason');
62
+ const relatedProcessId = asPositiveString(input.relatedProcessId, 'relatedProcessId');
63
+ const invoices = normalizeInvoices(input.invoices);
64
+ const customerId = optionalId(input.customerId, 'customerId') || DEFAULT_CUSTOMER_ID;
65
+ const projectId = optionalId(input.projectId, 'projectId');
66
+ const allowanceCents = amountCents(input.monthlyAllowance, 'monthlyAllowance');
67
+ let remainingCents = allowanceCents ?? Number.POSITIVE_INFINITY;
68
+ const details = [];
69
+ const skipped = [];
70
+ for (const item of invoices) {
71
+ if (remainingCents <= 0) {
72
+ skipped.push(item);
73
+ continue;
74
+ }
75
+ const reimbursedCents = Math.min(item.cents, remainingCents);
76
+ remainingCents -= reimbursedCents;
77
+ details.push({ ...item, reimbursedCents });
78
+ }
79
+ const relatedInvoiceIds = details.map((item) => item.fid);
80
+ const invoiceTotalCents = invoices.reduce((sum, item) => sum + item.cents, 0);
81
+ const reimbursedTotalCents = details.reduce((sum, item) => sum + item.reimbursedCents, 0);
82
+ const capped = reimbursedTotalCents < invoiceTotalCents;
83
+ const session = await host.getSession();
84
+ const currentEmpId = asPositiveString(session.userId, '当前人员 ID');
85
+ const body = {
86
+ autoCommit: '1',
87
+ projectId: projectId ? longId(projectId) : '',
88
+ customerId: longId(customerId),
89
+ currentEmpId: longId(currentEmpId),
90
+ processTitle,
91
+ reason,
92
+ detailList: details.map((item) => ({
93
+ relatedProcessId: longId(relatedProcessId),
94
+ relatedInvoiceId: longId(item.fid),
95
+ reimbursedAmount: formatCents(item.reimbursedCents),
96
+ })),
97
+ };
98
+ let result;
99
+ try {
100
+ result = await host.invoiceRequest({
101
+ path: SUBSIDY_SUBMIT_PATH,
102
+ method: 'POST',
103
+ body,
104
+ operation: this.name,
105
+ timeoutMs: 90_000,
106
+ });
107
+ }
108
+ catch (error) {
109
+ if (isInvoiceNetworkError(error)) {
110
+ throw invoicePartialError('报销提交请求发出后连接中断,结果不确定,禁止自动重试', {
111
+ processTitle,
112
+ relatedProcessId,
113
+ relatedInvoiceIds,
114
+ workflow: workflow(this.name, 'EXECUTING'),
115
+ }, { stage: 'submit' });
116
+ }
117
+ throw error;
118
+ }
119
+ const data = result?.data && typeof result.data === 'object' ? result.data : {};
120
+ const dataCode = data.code;
121
+ if (result?.status === false || result?.fail === true || (dataCode !== undefined && Number(dataCode) !== 0)) {
122
+ throw new InvoiceCliError('api', 'reim_subsidy_submit_failed', data.msg || result?.msg || '话费 / 油费报销提交失败', {
123
+ code: dataCode ?? result?.code,
124
+ details: { result },
125
+ exitCode: 1,
126
+ });
127
+ }
128
+ const requestId = String(data.requestId ?? '').trim();
129
+ if (!/^\d+$/u.test(requestId)) {
130
+ throw invoicePartialError('报销提交接口返回成功但没有流程 ID,结果不确定,禁止自动重试', {
131
+ processTitle,
132
+ result,
133
+ workflow: workflow(this.name, 'VERIFYING'),
134
+ }, { stage: 'submit-response' });
135
+ }
136
+ const url = workflowViewUrl(session.baseUrl, requestId);
137
+ return {
138
+ status: 'COMPLETE',
139
+ data: {
140
+ requestId,
141
+ url,
142
+ processTitle,
143
+ invoiceCount: relatedInvoiceIds.length,
144
+ reimbursedAmount: formatCents(reimbursedTotalCents),
145
+ invoiceTotal: formatCents(invoiceTotalCents),
146
+ monthlyAllowance: allowanceCents === null ? null : formatCents(allowanceCents),
147
+ capped,
148
+ details: details.map((item) => ({
149
+ relatedInvoiceId: item.fid,
150
+ invoiceTotal: formatCents(item.cents),
151
+ reimbursedAmount: formatCents(item.reimbursedCents),
152
+ })),
153
+ skippedInvoices: skipped.map((item) => ({
154
+ relatedInvoiceId: item.fid,
155
+ invoiceTotal: formatCents(item.cents),
156
+ })),
157
+ finalMarkdown: `[${processTitle}](${url})`,
158
+ result,
159
+ workflow: workflow(this.name, 'COMPLETE'),
160
+ },
161
+ };
162
+ }
163
+ }