下发 preparation capabilities 并与右卡展示同源授权; 库存 RPA 运行态请求内 memo;取消会话 Profile 本地 TTL; 并为 shipping-worker 挂载共享盘。 Co-authored-by: Cursor <cursoragent@cursor.com>
338 lines
28 KiB
Markdown
338 lines
28 KiB
Markdown
# 货代发货通知 — 工作台「展示 & 按钮」唯一契约(冻结 2026-09)
|
||
|
||
> **本文件是订单处理工作台在「展示数据」与「任务级/明细级按钮」两方面唯一权威契约。**
|
||
> 结论基于现有实现(`shipping_processing_projection` / `ui_state` / `process_gate` /
|
||
> `stage_context.preparation`),**不新增投影/抽象**,只做「单一来源 + 去冗余」。
|
||
> 后端只读投影与前端所有消费方都必须遵守,禁止再私自分叉。
|
||
|
||
---
|
||
|
||
## 0. 一句话结论
|
||
|
||
- **展示单源**:右「当前任务」卡、5 阶段页签、批次中心卡 **全部** 以 `shippingProcessingProjection`
|
||
(含其 `ui_state` 子 DTO)为单一来源;`formalTaskDetail.ui_state` **不再**参与「当前阶段 / 用户状态 /
|
||
阻断 / 动作」展示,只保留它独有的**工作面只读事实**(`stage_context.preparation`、`edit_window`、
|
||
`steps/todo/checkpoint`、`business_no`、`export_artifacts`)。
|
||
- **任务级按钮单源 A**:右卡主按钮 / 恢复按钮 **只读** A 的 `primary_action` / `secondary_actions`。
|
||
**禁止**再把 `stage_context.preparation.capabilities` 独立渲成右卡按钮(capabilities 仅可作点击后
|
||
`stageCapabilityBypass` 查找,见 §3.2)。
|
||
- **按钮分域**:只有 **1 个**动作是**明细级**(`override_line_inventory_source`),只出现在库存表格逐行;
|
||
其余全部**任务级**,只出现在右「当前任务」卡。旧 D5 `select_line_inventory_source` **已删除**。
|
||
- **零新动作码**:库存「复用快照 / 强制 RPA / 只读轮询」靠**已有码**映射 `ensure_inventory.mode`
|
||
(见 §3.3),禁止再造 `fetch_inventory` / `force_inventory_rpa` 等新合同。
|
||
- **库存动作语义**:`retry_inventory_preparation` / `retry_inventory_from_preparation` → `mode=retry_rpa`;
|
||
`poll_inventory_preparation` → 只读轮询(`allow_auto_retry=False`);首次 `gate_attempt_passed` 自动投递
|
||
保持默认 `auto`。`retry_inventory_matching` 优先复用快照重匹配(无快照再回退 RPA)。
|
||
`reload_inventory_result` 写契约仍有效,**用户按钮面已下线**(并入 matching,见 §3.3)。
|
||
- **明细级按钮的数据源**:`ui_state.stage_context.preparation.lines[].line_allowed_actions /
|
||
inventory_allowed_actions`(后端已下发,零 N+1,见 §3.4 / §5)。
|
||
- **行级库存作用域**:明细行点击重抓/重匹配携带 `snapshot_line_id` → 后端按该行
|
||
`candidate.source_codes_json` 收窄 RPA/获取/失效;同行源未发通知行可共享新快照;
|
||
已产生发货通知行(`ShippingNoticeLine`)匹配与 Artifact **不得**被行级重抓改写。
|
||
|
||
---
|
||
|
||
## 1. 现有投影「角色」归类
|
||
|
||
| 编号 | 形状 | 产出方 | 唯一用途 | 稳态/运行态 | 底层唯一事实源 |
|
||
|---|---|---|---|---|---|
|
||
| A | `shipping_processing_projection.order_task`(含 `ui_state`) | `_project_order_task_work_item` → `reconcile_processing_projection_facts` → `apply_user_projection_fields` → `_with_processing_ui_state` | 右「当前任务」卡 + 批次中心卡 + 会话卡 | 稳态只读 | `ShippingOrderTask.stage/status/pending_human_reason/review_status/progress_version/active_process_execution_id` + `ShippingProcessExecution.current_gate_code/status` + `ShippingProcessGate` + `ShippingNotice.lifecycle_status` + 库存准备/导出/上传 Attempt |
|
||
| B | `formalTaskDetail.ui_state` | `build_task_ui_state` → `resolve_task_ui_state` → `_task_lifecycle` → `_unified_actions` | 工作面只读事实:`stage_context.preparation`(表格/编辑窗)、`edit_window`、`steps/todo/checkpoint`、`business_no` | 稳态只读 | `ShippingNotice.lifecycle_status/task_no/review_status` + `ShippingOrderTask` + 最新 Export/Upload/Verification/Match/Preparation 行 |
|
||
| C | `process_gate` 摘要 | `project_user_gate_summary` → `_resolve_recovery_next_action` → `recovery_targets` | 唯一「当前能做什么 + 为何阻断」裁决(`execution_no/evaluation_version/recovery_targets` 供**写**请求) | 稳态只读 | `ShippingProcessExecution` + `ShippingProcessGate` + `PROCESS_GATE_DEFINITIONS.default_next_actions` |
|
||
| D | `stage_context.preparation` | `_build_stage_context` → `preparation` | 通知准备面板的库存事实(`frozen_order_lines`/`lines[]`/`source_options`/`inventory_sources`/`capabilities`) | 稳态只读 | `ShippingNoticeLineInventoryMatch(is_current)` + `ShippingInventoryVerification` + `ShippingInventoryPreparationAttempt` + `ShippingExportArtifact` + `ShippingUploadAttempt` |
|
||
| E | `lifecycle_stage`/`stage_label_key` | `project_lifecycle`(`lifecycle_stage/entries/authority`)+ `project_stage_for_task`(`current_stage.code/label_key`) | 5 阶段页签/入口 + 技术阶段码+文案键 | 稳态只读 | `ShippingOrderTask.stage`(优先)+ `map_run_to_processing_stage` + `ShippingProcessExecution.current_gate_code` + 核验上传成功 |
|
||
|
||
**关键澄清(根因)**:`stage` 这个字段名在 A 的 `ui_state` 是**技术阶段码**
|
||
(`shipping_processing_projection.py:3128`),在 B 的 `build_task_ui_state` 是 **5 阶段 DTO**
|
||
(`ui_state.py:1117`)。**同一键、两个无关值域**。契约用不同且唯一的键区分:
|
||
`stage/stage_label_key/current_stage.code` 只承载**技术阶段码**;`lifecycle_stage/lifecycle_entries/lifecycle_authority`
|
||
只承载 **5 阶段业务标签**。
|
||
|
||
---
|
||
|
||
## 2. 展示契约:每个字段的唯一来源
|
||
|
||
> 规则:右卡与 5 阶段页签的字段**全部读 A**,不再读 B。B 只保留工作面事实。
|
||
> 稳态/运行态只影响「是否可能为空/待刷新」,**不改变字段来源**。
|
||
|
||
| 展示值 | 唯一来源(单源) | 稳态/运行态 | 落点 UI |
|
||
|---|---|---|---|
|
||
| 5 阶段当前阶段 | `shippingProcessingProjection.ui_state.lifecycle_stage` | 稳态 | 5 阶段页签头 + 右卡 |
|
||
| 5 阶段入口/授权 | `...ui_state.lifecycle_entries` / `.lifecycle_authority` | 稳态 | 5 阶段页签 |
|
||
| 技术阶段码+文案键 | `shippingProcessingProjection.stage` / `.stage_label_key` | 稳态 | 右卡「当前门禁」行、批次卡 |
|
||
| 用户状态 | `...ui_state.status` | 稳态 | 右卡「状态」行 / 处理详情抽屉 |
|
||
| 阻断原因(下一步) | `...ui_state.blocking_reason` | 稳态 | 右卡「下一步」 |
|
||
| Gate 状态 | `shippingProcessingProjection.current_gate.status` | **运行态** | 右卡(区分未入队/运行/待外部回执) |
|
||
| 主动作/恢复动作 | `...ui_state.primary_action` / `.secondary_actions`(**仅此**;禁止叠加 `preparation.capabilities`) | **运行态** | 右卡主按钮 + 恢复按钮 |
|
||
| 库存准备时间线 | `shippingProcessingProjection.inventory_preparation` + `.facts` | **运行态** | 通知准备时间线 |
|
||
| 工作面表格行/改源/编辑 | `formalTaskDetail.ui_state.stage_context.preparation.*` | 稳态 | 通知准备表格(**明细级**) |
|
||
| 编辑窗(D10) | `formalTaskDetail.ui_state.edit_window` | 稳态 | 编辑面 |
|
||
| 步骤条/todo/checkpoint | `formalTaskDetail.ui_state.steps/todo/checkpoint` | 稳态 | 顶部步骤条 |
|
||
| 业务号/导出产物 | `formalTaskDetail.business_no` / `export_artifacts` | 稳态 | 上传面 |
|
||
|
||
### 稳态 vs 运行态
|
||
- **稳态**(`stage/lifecycle_stage/status/blocking_reason`):由 `ShippingOrderTask.stage/status` +
|
||
`ShippingProcessExecution.current_gate_code` + `project_lifecycle` 派生,不随 RPA 运行而变。
|
||
- **运行态**(`current_gate.status`、`ui_state.primary_action/secondary_actions`):由
|
||
`ShippingProcessExecution/ShippingProcessGate` 当前行派生,随 RPA/执行推进。前端轮询 A
|
||
(`startWorkflowProgressPolling` → `refreshShippingProcessing` → `shippingProcessingProjection`)
|
||
刷新,`progress_version` 单调递增驱动右卡刷新。
|
||
|
||
### 2.1 A↔C 等价性验证结果(已用 `tests/test_shipping_projection_gate_equivalence.py` 锁定)
|
||
|
||
> **结论:历史 D1/D2 漂移已由 STEP8 flatten 消除;A 的 `primary_action`/`blocking_reason` 在有
|
||
> `payload['process_gate']` 时消费 C,与写裁决同源。**
|
||
|
||
| # | Gate | 历史漂移(已修) | 修法 |
|
||
|---|---|---|---|
|
||
| D1 | `artifact_generation` | A 曾用 `regenerate_excel` 别名 | STEP8 取 C 规范码 `regenerate_excel_artifact` |
|
||
| D2 | `inventory_preparation` blocked_retryable | A 曾坍缩为 `technical_failure_present` | STEP8 取 C 的 `inventory_preparation_failed` |
|
||
|
||
**flatten A 的边界(重要)**:A 的 `user_status`(六值展示分组)是 A 独有,**不得**纳入 flatten。
|
||
flatten 只动 `primary_action.code` 与 `blocking_reason.code/i18n_key`。Intake/min 无 C 时保留现有推导。
|
||
|
||
**等价性已锁定(A==B==C)**:harness 覆盖多 Gate × A↔C + B↔C + 生命周期 + 明细按钮 + N+1。
|
||
右卡/对话流/批次进度中心不再各自为政(须与前端右卡仅读 A 同批,已完成)。
|
||
|
||
**动作码 A↔B/C(差异① 已归一)**:A 的 `secondary_actions` 已透传 C 原始 Gate 码(含
|
||
`mark_manual_uploaded`,不再别名成 `open_manual_upload`)。前端 `manualUploadRegistrationAuthorized`
|
||
与右卡恢复入口均读 A,与写契约码一致。详见 §2.5.2。
|
||
|
||
**生命周期阶段 A↔B 同源确认(无伪漂移)**:A(`_processing_ui_state_from_item`)与 B(`_task_lifecycle`)
|
||
**都**调用 `project_lifecycle`。`LIFECYCLE_STAGE_BY_GATE`(`lifecycle_projection.py:30`)是正式 Gate→五阶段
|
||
业务码的唯一表。前端正式 OT 的 5 阶段页签已 **A-first**(§2.5.3 / §6),属收敛而非行为改写。
|
||
|
||
### 2.5 A↔B/C 动作码与生命周期形状归一化(后端前置 → 前端已切)
|
||
|
||
> **一句话**:A 的 `ui_state` 在「动作码」上与 B/C **逐字一致**后,前端已把 §1.1(`lifecycleUiState`
|
||
> 正式 OT 读 A)与 `manualUploadRegistrationAuthorized`(读 A)切过去;blocker 由前端从 A 的
|
||
> `blocking_reason` 解析(优先 `i18nKey`→`te/t`,否则 `code`),不要求后端再造平行 `blocker` 字段。
|
||
> ① 动作码 `mark_manual_uploaded`:**已归一**(§2.5.2)。
|
||
> ② 页签 `lifecycleUiState`:**已落地(方案甲′)**(§2.5.3)。
|
||
|
||
#### 2.5.1 现状(三源逐一对比)
|
||
| 字段 | A(`shippingProcessingProjection.ui_state`) | B(`formalTaskDetail.ui_state`) | C(`project_user_gate_summary`) | 差异 |
|
||
|---|---|---|---|---|
|
||
| 动作码 `mark_manual_uploaded` | `secondary_actions` 透传 **`mark_manual_uploaded`** | `actions.secondary` 同码 | `allowed_actions` 同码 | ✅ 已归一 |
|
||
| 阶段入口 | `lifecycleEntries`(`[]如{code,state,targetSurface}`) | `lifecycle_entries`(同形状) | `lifecycle_entries`(同形状) | ✅ 已同形 |
|
||
| 阻断说明 `blocker` | `blocking_reason`(`{code,i18nKey,details}`) | `reason.message`(已翻译文案) | `blocking_reason_code`+`explainability` | 形状不同;前端读 A 时本地解析,不 flatten 成 message |
|
||
| 阶段码 | `lifecycleStage` | `stage.code` / `lifecycle_stage` | 由 `project_lifecycle` 统一 | ✅ 同源 |
|
||
|
||
**已确认同源的部分**:`lifecycle_stage`(阶段码)3 源均用 `project_lifecycle`。动作码差异①已消除;
|
||
blocker 保持 A 结构化形状,由前端统一解析(§2.5.3)。
|
||
|
||
#### 2.5.2 差异①:`mark_manual_uploaded` 被 A 别名成 `open_manual_upload`(**已归一,验证通过**)
|
||
- **根因**:`processing_projection_invariants._ACTION_CODE_ALIASES['mark_manual_uploaded'] = 'open_manual_upload'`(`:88`)
|
||
与 `derive_available_actions`(`:476-477`)把 `gate_action ∈ {open_manual_upload,wait_manual_upload,mark_manual_uploaded}`
|
||
`_push('open_manual_upload')`,导致 A 的 `secondary_actions` 曾输出别名,而非原始 Gate 码。
|
||
- **影响(历史)**:`manualUploadRegistrationAuthorized` 若读 A 找 `mark_manual_uploaded` 会失效。
|
||
- **修法(已实施 + 验证)**:`shipping_processing_projection` 新增 `_process_gate_allowed_action_codes(item)`,
|
||
`_processing_ui_state_from_item` 用它从 C 摘要(`payload['process_gate'].allowed_actions` / `action_presentation[].code`)
|
||
取**原始 Gate 码**构造 `secondary_actions`(不再经 `_ACTION_CODE_ALIASES` 归一为 `open_manual_upload`)。
|
||
无 C 时回退 `available_actions`(Intake/min 投影路径)。
|
||
- **验收(已绿)**:`test_a_secondary_actions_carry_mark_manual_uploaded` 在 `freight_upload_rpa`
|
||
门禁下断言 **A.secondary_actions 含 `mark_manual_uploaded`** 且与 `C.allowed_actions` 同集。
|
||
|
||
#### 2.5.3 差异②:页签 `lifecycleUiState` 读 A(**已落地,方案甲′**)
|
||
- **形状事实**:A 的 `blocking_reason` 是 `{code,i18nKey,details}`;B 的 `reason.message` 是已翻译文案。
|
||
前端页签需要「可展示阻断字符串」,**不在后端再造平行 `blocker` 字段**。
|
||
- **落地读序(`ShippingOrderReviewView.vue` `lifecycleUiState`)**:
|
||
1. **正式 OT 且 A 已有 lifecycle** → stage / entries / blocker **认 A**(与右卡同源);
|
||
blocker = `te(i18nKey) ? t(...) : code`(禁止直接吐机器 i18nKey 原文)。
|
||
2. **A 尚未落位** → 短暂降级 B,避免页签空窗。
|
||
3. **建单前** → 仍用 `reviewQueue` / `reviewRun` 项的 `lifecycle_entries`(字段明确存在时
|
||
空数组也是后端拒绝结果,禁止回退到会话级其他 PDF 投影)。
|
||
- **历史风险说明**:曾尝试「A 绝对优先」导致 upload/freight 相关 spec 失败;甲′ 用「正式 OT + A 有数据」
|
||
门闩 + B/队列降级,`ShippingOrderReviewView.spec.ts` **103/103 全绿**。
|
||
- **capabilities 不进页签/右卡渲染**:见 §3.2 / §6。
|
||
|
||
#### 2.5.4 落地顺序(已完成)
|
||
1. ~~加守卫测试~~ → 已绿(`mark_manual_uploaded` 透传)。
|
||
2. ~~后端归一~~ → 已绿(A.secondary_actions 原始 Gate 码)。
|
||
3. ~~前端切换~~ → 已绿:`lifecycleUiState` 正式 OT A-first(甲′);`manualUploadRegistrationAuthorized` 读 A;
|
||
右卡恢复动作只读 A.secondary_actions(停 capabilities 叠加)。
|
||
4. ~~全量回归~~ → 前端 `ShippingOrderReviewView.spec.ts` 103/103;相关后端投影/恢复用例已绿。
|
||
5. **性能护栏仍有效**:归一只改读序 / 内存组装,不新增轮询或查询。
|
||
|
||
#### 2.5.5 边界(不改的部分)
|
||
- `user_status`(A 独有的六值展示分组枚举)留在 A,**不**纳入归一。
|
||
- `open_manual_upload` 作为「聊天/通知级手工上传入口」在 `derive_available_actions` 仍保留(它本就是另一层
|
||
展示别名),只是**不得再覆盖 `mark_manual_uploaded` 的原始码**。
|
||
- 写契约(`request_gate_action`)仍只认 `mark_manual_uploaded` 等 `PROCESS_GATE_ACTION_CODES`;
|
||
前端从 A 读到的动作码必须能与写契约对齐。
|
||
- **禁止新增动作码**解决库存语义;用已有码映射 `ensure_inventory.mode`(§3.3)。
|
||
- 行级点击已携带 `snapshot_line_id`;后端按该行 `candidate.source_codes_json` 收窄获取/RPA/
|
||
失效范围;已产生发货通知的行不得被行级重抓改写匹配或 Artifact。
|
||
|
||
|
||
|
||
### 两个展示 bug 的契约修法
|
||
- **「当前门禁 —」**:`resolveShippingProcessingStageLabel('')` 返回 `'—'`(`shippingProcessingLabels.ts:150`),
|
||
当 `currentProcessingStageDisplay` 因投影 `stage/ui_state.lifecycle_stage` 均空(且 `!loading`)返回空时触发。
|
||
**修法**:已知正式 OT 必有阶段,投影恒有 `stage/lifecycle_stage`;投影未就绪由右卡 `:loading`
|
||
(`formalTaskProjectionPending`/`formalTaskDetailLoading`/`caseSwitchLoading`)驱动骨架占位,**禁止**落 `'—'`。
|
||
- **「状态待确认」**:`resolveShippingProcessingStatusLabel` 不认识码时的兜底(`labels.ts:69`),
|
||
仅被 `ReviewProcessDetailDrawer` 消费(读 `projection.status`)。右卡空态用的是 `statusIdle`(待机)、
|
||
表格行数用 `'待确认'`——**三套词汇**。**修法**:状态统一从 `shippingProcessingProjection.ui_state.status`
|
||
(受控 6 值)取,禁止给投影塞不受控码;`resolveShippingProcessingStatusLabel` 仅作不受控码兜底。
|
||
|
||
---
|
||
|
||
## 3. 按钮契约:任务级 vs 明细级
|
||
|
||
### 3.1 动作面与作用域
|
||
`PROCESS_GATE_ACTION_CODES`(`process_gate_contract.py`)∪ `STAGE_CAPABILITY_DEFINITIONS`
|
||
(同文件)。**只有 1 个是明细级**:
|
||
|
||
| 动作码 | 作用域 | 宿主 | 位置 |
|
||
|---|---|---|---|
|
||
| `override_line_inventory_source` | **明细级** | `_handle_override_line_inventory_source` | 库存表格逐行(override 下拉) |
|
||
| ~~`select_line_inventory_source`~~ | ~~明细级~~ | **已删除** | — |
|
||
| 其余全部 | **任务级** | 右「当前任务」卡 | 主按钮 + 恢复按钮 |
|
||
|
||
前端唯一判据:`LINE_SCOPE_INVENTORY_ACTIONS = {override_line_inventory_source}`
|
||
(`ShippingOrderReviewView.vue`)。凡在此集合内的动作一律不进任务级按钮(右卡主/恢复均排除)。
|
||
|
||
### 3.2 步骤/状态 → 动作(按 Gate 阻断归属)
|
||
主动作唯一裁决:`_resolve_recovery_next_action`(`process_gate_projection.py`);侧路:
|
||
`gate_side_recovery_actions`(`process_gate_contract.py`)。二者与校验层 `request_gate_action`
|
||
的 `allowed_side` **共用同一份裁决**(保证「投影放行==校验放行」)。
|
||
|
||
| Gate 阻断 | 主动作 | 侧路 |
|
||
|---|---|---|
|
||
| `inventory_preparation` blocked_manual/retryable | `retry_inventory_preparation` | — |
|
||
| `inventory_preparation` waiting_external | `poll_inventory_preparation` | — |
|
||
| `inventory_preparation` RPA 超时/耗尽 | `retry_inventory_matching`(复用快照重匹配,无则 RPA) | `retry_inventory_preparation` |
|
||
| `inventory_sufficiency` 正式 OT+已确认库存 | `retry_inventory_matching` | — |
|
||
| `inventory_sufficiency` 正式 OT+无确认库存(短缺) | `open_shortage_review` | — |
|
||
| `inventory_matching`/`inventory_sufficiency` 建单前 | `open_inventory_match_review`/`open_shortage_review` | `override_line_inventory_source`(多文件冲突,明细级) |
|
||
| `freight_upload_rpa` 失败 | `retry_freight_upload_rpa` | — |
|
||
| `manual_upload_handoff` | `mark_manual_uploaded` | `retry_freight_upload_rpa` |
|
||
|
||
**任务级常驻能力(`STAGE_CAPABILITY_DEFINITIONS` / `_stage_capabilities_for_task`)**:
|
||
仍可由后端下发到 `stage_context.preparation.capabilities`(如 `retry_inventory_preparation`、
|
||
`reload_inventory_result`、`retry_inventory_matching`;`override_line_inventory_source` 为明细级)。
|
||
**展示契约**:这些能力 **不得**再独立渲成右卡按钮;右卡只读 A 的 `primary_action` /
|
||
`secondary_actions`。若某能力应对用户可见,必须先并进 A(经 C 裁决进投影)。点击路径仍可
|
||
用 capabilities 作 `stageCapabilityBypass` 查找(执行框架不变)。
|
||
|
||
### 3.3 库存动作与 `ensure_inventory.mode` 映射(零新动作码)
|
||
| 动作码 | 用户语义 | `ensure_inventory` | 跑 RPA |
|
||
|---|---|---|---|
|
||
| `retry_inventory_preparation` / `retry_inventory_from_preparation` | 显式强制重抓 | `mode=retry_rpa` | ✅ |
|
||
| `poll_inventory_preparation` | 只读轮询结果 | 默认 mode + `allow_auto_retry=False` | ❌(不自动重试) |
|
||
| 首次 `gate_attempt_passed` 自动投递 | 进入库存准备 | 默认 `auto`(先复用快照) | 视缺文件 |
|
||
| `retry_inventory_matching`(**主恢复合并动作**) | 优先复用快照重匹配;无快照回退 RPA | 经 `match_inventory` → 必要时 `ensure_inventory` | 视情况 |
|
||
|
||
落点:`process_gate_executor._handle_retry_inventory_preparation` 内
|
||
`_FORCE_INVENTORY_RPA_ACTION_CODES`;**禁止**「人工入口一律 `retry_rpa`」。
|
||
|
||
**`reload_inventory_result` 已下线展示**:行为并入 `retry_inventory_matching`;写契约码仍保留防 400。
|
||
已同步 `gate_side_recovery_actions` / `action_belongs_to_gate` / 前端 presentation 与相关测试。
|
||
|
||
**`has_formal_ot`(明细按钮前置)**:以 owner 为 `ShippingOrderTask` **或** 已冻结
|
||
`order_snapshot_id` 判定,**禁止**用「有无 `current_match_rows`」代替(无匹配行时仍须下发行级
|
||
重试/关闭按钮)。落点:`ui_state._build_stage_context`。
|
||
|
||
### 3.4 明细级按钮的数据源(§0 一句话结论的展开)
|
||
通知准备表格**每行**的明细级按钮(库存放行、关闭不可履约、行级重抓/重匹配、下载库存)由
|
||
`ui_state.stage_context.preparation.lines[].{line_allowed_actions, inventory_allowed_actions, inventory_file_no,
|
||
release_required_fields, release_field_resolution_error, decision}` 驱动,**后端必须下发**到该数组。
|
||
前端对应门禁:`formalPreparationLineAllows(line, action)`(`ShippingOrderReviewView.vue:2571`):
|
||
- `close_unfulfillable` / `release_inventory_shortage` → `line_allowed_actions.includes(action)` 且
|
||
`release_inventory_shortage` 需 `!release_field_resolution_error`;
|
||
- `retry_inventory_preparation` / `retry_inventory_matching` → `inventory_allowed_actions.includes(action)`;
|
||
- 下载库存 → `inventory_file_no` 非空(`downloadFormalPreparationLineInventoryFile` `:2647`)。
|
||
|
||
> ~~**当前 BUG**:后端 `_build_stage_context` 生成 `preparation.lines[]`(`ui_state.py:837-862`)**未输出**
|
||
> 上述 `*_allowed_actions`/`inventory_file_no`/`release_*`/`decision` 字段(它们只存在于 Case 快照
|
||
> `line_fulfillment.lines[]`,见 `order_review_fulfillment_decision_service.py:956-973`、`line_inventory_match_projection.py:667-694`),
|
||
> 导致 `formalPreparationLineAllows` 恒 false、明细级按钮全部不渲染。~~
|
||
> **已修复(§1.5)**:`_build_stage_context` 现已在行循环内用内存 `match_row` 事实调用纯函数
|
||
> `project_line_inventory_view` 下发 `line_allowed_actions`/`inventory_allowed_actions`/`inventory_file_no`/
|
||
> `user_line_status`/`is_shortage` 等(零逐行 SQL,见 §6 落地清单)。短缺行另复用
|
||
> `_shortage_release_required_fields` 下发 `release_template_fields`/`release_required_fields`;
|
||
> 解析失败时写 `release_field_resolution_error`(fail-closed,禁止只填原因)。`decision` 仍为 `null`。
|
||
>
|
||
> **RPA 运行中(与 Case 同源)**:行循环外调用一次 `inventory_rpa_is_running(order_task)`(请求级 memo),
|
||
> 再传入各行 `project_line_inventory_view`;禁止逐行查 Attempt,也禁止用阶段 Job / 右卡
|
||
> `userStatus` 推断。运行中 `inventory_allowed_actions=[]`。
|
||
---
|
||
|
||
## 4. 前后端如何配合(冻结)
|
||
|
||
1. **后端只读投影**:A(`shippingProcessingProjection`+`ui_state`)是唯一**展示+动作**合同;
|
||
C(`process_gate`)是唯一**写**裁决(`execution_no/evaluation_version/recovery_targets`);
|
||
B/D 只提供**工作面**事实。三者同一派生事实源,后端负责让它们同源不漂移。
|
||
2. **前端轮询**:`startWorkflowProgressPolling`(`PROGRESS_POLL_MS`)→ `refreshShippingProcessing`
|
||
→ `shippingProcessingProjection`(按 `progress_version` 单调合并)→ 刷新右卡 + 5 阶段页签;
|
||
必要时再 `loadFormalTaskDetail` 拉工作面事实。
|
||
3. **前端职责**:不用 `formalTaskDetail.ui_state` 推展示/动作;右卡与页签只用 A 的 `uiState`,
|
||
工作面表格/编辑窗只用 B 的 `stage_context.preparation`。**禁止**把 `preparation.capabilities`
|
||
渲成右卡按钮。不自行推导阶段/按钮;`stage` 码不与 `lifecycle_stage` 混淆。
|
||
正式 OT 页签读序见 §2.5.3(A-first / 甲′)。
|
||
|
||
---
|
||
|
||
## 5. 效能约束(必须遵守,与功能契约同权)
|
||
|
||
> 核心:展示与按钮单源收敛**不得**以新增查询 / 渲染热路径为代价。`stage_context.preparation`
|
||
> 仍**只在任务详情**下发,不进轮询 / 轻量投影。
|
||
|
||
1. **明细级按钮零 N+1(§3.4)**:`_build_stage_context`(`ui_state.py:735`)已把该任务
|
||
`ShippingNoticeLineInventoryMatch(is_current=True)` 全量加载进内存并建好 `match_by_snapshot_line_id`。
|
||
`preparation.lines[]` 逐行的 `line_allowed_actions / inventory_allowed_actions / inventory_file_no /
|
||
release_required_fields / release_field_resolution_error / decision` 必须**在同一个循环内**、
|
||
复用上述**已加载内存事实**结算(调用 `line_inventory_match_projection.resolve_*_allowed_actions`
|
||
等纯函数),**禁止逐行 SQL / 逐行调用重序列化器**。复杂度保持 O(行数)。
|
||
2. **`stage_context.preparation` 只进任务详情**:不得下放到 `shippingProcessingProjection`(work-item /
|
||
轮询 / 轻量投影),避免 N+1 与轮询膨胀。该限制已有(见 `technical.md`),本次收紧为契约级。
|
||
3. **flatten C 复用单次 `project_user_gate_summary`**:A(`_order_task_current_gate`)与 B
|
||
(`_process_gate_user_summary_for_task`)必须**复用同一份 C 结果**,不得各自再调用 / 再推导
|
||
`primary_action / blocking_reason / next_action`,保证单个 work-item 只调用一次、净减重复推导。
|
||
4. **poll 热路径不变**:轮询 `PROGRESS_POLL_MS`(当前 `5000`,`useShippingOrderReview.ts:86`)与
|
||
`refreshShippingProcessing()` 的调用序列**不因本次收敛改变**;前端读 A 只改读序、不增请求。
|
||
(顺带修正过期的「2.5s/3s」注释为实际 `5000`。)
|
||
5. **验收护栏**:
|
||
- 改前 / 改后对 `GET /shipping-tasks/<no>`(含 `stage_context`)做 SQL 查询次数对比,确认
|
||
**不随行数线性增加**(加 `assert_num_queries` 类测试,或手工 `EXPLAIN` 对比)。
|
||
- 确认单个 work-item 的 `project_user_gate_summary` 调用次数不变(仍 1 次)。
|
||
|
||
---
|
||
|
||
## 6. 落地清单(去冗余,不新增抽象)
|
||
|
||
- [x] 前端:`lifecycleUiState` 正式 OT **优先读 A**(方案甲′:A 有 lifecycle 才认;A 未落位短暂降级 B;
|
||
建单前保留 `reviewRun`/`reviewQueue`)。blocker 从 A.`blocking_reason` 解析(`i18nKey`→`te/t`,否则 `code`)。
|
||
已验证:`ShippingOrderReviewView.spec.ts` 103/103 全绿。
|
||
- [x] 前端:右卡 `currentTaskPrimaryAction`/`currentTaskRecoveryActions` **只用** A 的
|
||
`primary_action` / `secondary_actions`;**停止**叠加 `stage_context.preparation.capabilities`;
|
||
按 code 剔除明细级(`LINE_SCOPE_INVENTORY_ACTIONS`)。i18nKey 统一映射到
|
||
`workspace.shippingNotice.processGate.actionCodes.<code>`。
|
||
- [x] 前端:删除 `formalTaskActions` 对右卡的依赖;`manualUploadRegistrationAuthorized` 已收敛到 A。
|
||
- [x] 前端:把「当前门禁」`--` 收敛为「投影未就绪 → 骨架占位」,禁止空阶段落 `'—'`。
|
||
- [x] 前端:`LINE_SCOPE_INVENTORY_ACTIONS` 只保留 `override_line_inventory_source`(已删 `select_line_inventory_source`)。
|
||
- [x] 后端:`_handle_retry_inventory_preparation` 按**已有动作码**映射 `ensure_inventory.mode`
|
||
(强制 RPA 仅 `retry_inventory_preparation` / `retry_inventory_from_preparation`;poll 只读;
|
||
首次自动投递保持 `auto`)。零新动作码。守门:`test_inventory_preparation_mode_maps_by_action_code`。
|
||
- [x] 后端:`_build_stage_context` 的 `has_formal_ot` 以 owner=`ShippingOrderTask` 或已冻结
|
||
`order_snapshot_id` 判定(禁止用 `current_match_rows`)。守门:`test_stage_context_line_actions_without_match_rows`。
|
||
- [x] **后端(明细级按钮,§1.5 / §5.1 零 N+1)**:`preparation.lines[]` 携带
|
||
`line_allowed_actions`/`inventory_allowed_actions`/`inventory_file_no` 等;内存结算、禁止逐行 SQL。
|
||
短缺行复用 `_shortage_release_required_fields` 投影 `release_template_fields`/
|
||
`release_required_fields`(解析失败写 `release_field_resolution_error`);`decision` 仍为 null。
|
||
N+1 守门已绿。
|
||
- [x] 后端:删除 `select_line_inventory_source`(已被 `override_line_inventory_source` 取代)。
|
||
- [x] 后端:`apply_user_projection_fields` STEP8 条件化消费 C,A 的 `primary_action`/`blocking_reason` 与 C 同源
|
||
(`test_shipping_projection_gate_equivalence.py`)。
|
||
- [x] i18n:四语言 `actionCodes.*` 区分库存动作文案;删除 `select_line_inventory_source` 残留键。
|
||
|
||
### 6.1 按需 / 未强制项(不阻塞本契约)
|
||
|
||
- [x] 行级点击在已有 `snapshot_line_id` 基础上,后端按行 `candidate.source_codes_json` 收窄
|
||
`ensure_inventory` / RPA / 失效范围(`retry_inventory_preparation` 与 `retry_inventory_matching`);
|
||
同行源可共享新快照,**已产生发货通知行**(`ShippingNoticeLine`)的匹配事实与 Notice Artifact
|
||
不得被行级重抓改写。零新动作码。落点:`process_gate_executor._resolve_line_inventory_scope`、
|
||
`recovery_invalidation_service.invalidate_inventory_downstream(source_codes=...)`。
|
||
- capabilities 是否继续出现在 D 载荷:可保留供执行 bypass;**展示面不得再独立渲染**(已冻结)。
|