2
This commit is contained in:
commit
21d41acf50
732 files changed
+55672
-15251
No files matched your search
+15
-6
@@ -37,23 +37,22 @@
|
||||
- Header/Line 均支持可选 `reservation_id`;有效值 `effective_reservation_id = line ?? header`,字段层不强制必填,建单门禁另计。
|
||||
- 项次三字段生命周期:
|
||||
- `customer_po_line_no`:客户 PO 原始项次(如 `00010`),识别/复核后永久保留原始事实。
|
||||
- `line_no`:内部业务项次;可识别、可由 Schema `derivation_rules` 派生(首期 `copy_if_empty`)、冻结前可人工覆盖;格式 1–6 位数字并保留前导零。
|
||||
- `export_sequence`:本次 Excel 最终导出行序号(1..N),仅导出期 `system_fact`,不属于订单字段。
|
||||
- 废除 `system_fact → line_no`;Excel 序号统一 `system_fact → export_sequence`。
|
||||
- `line_no`:系统按订单明细顺序生成的不可变项次;不参与 Schema 配置、解析或人工修改。
|
||||
- 发货通知项次:`ShippingNoticeLine.line_no`,每张通知单从 1 重新编号。
|
||||
- 标准字段资产唯一键为 `(field_code, scope)`,允许 Header/Line 同名 Reservation。
|
||||
- 库存匹配键仍为有效 Reservation + Part Number;行级多候选库存源属于后续阶段。
|
||||
|
||||
### STP 阶段 1 模板起行锚点(2026-07-30)
|
||||
|
||||
- 坐标模板以可配置 `line_start_field_code`(默认客户 PO 行号)识别逻辑明细起点;`line_no` 亦可作为可识别内部项次绑定。
|
||||
- 多物理行仍组成一条逻辑明细;Excel 导出行序号在最终导出集上连续生成(`export_sequence`)。
|
||||
- 多物理行仍组成一条逻辑明细;Excel 导出使用发货通知行项次。
|
||||
- 首期两个现有模板须重新绑定并通过盲测。
|
||||
|
||||
### STP 阶段 2 建单前库存源候选(2026-07-30)
|
||||
|
||||
- 行级/任务级已发布路由规则产出 `candidate_inventory_source_codes`;多候选(`ambiguous`)允许建单,零候选或 `require_manual_review` 阻断。
|
||||
- 有效 Reservation(`line ?? header`)与库存源候选共同构成建单门禁;Draft 校验与确认投影 `build_eligibility`。
|
||||
- 复核员可人工选择已启用库存源并填写原因(PUT `.../draft/lines/<line_key>/inventory-candidates`),覆盖规则零候选。
|
||||
- 通知准备阶段可按冻结档项次人工选择已启用库存源并填写原因;库存源未确认不创建正式发货通知。
|
||||
|
||||
### STP 阶段 3 自动建单与复核工作台(2026-07-30)
|
||||
|
||||
@@ -64,7 +63,7 @@
|
||||
### STP 阶段 4 跨候选库存匹配至待人工上传(2026-07-30)
|
||||
|
||||
- 准备全部冻结候选库存文件;按有效 Reservation + Part Number 跨文件匹配。
|
||||
- 唯一命中且数量充足 → 冻结实际库存源与行证据,自动生成 Excel(`export_sequence` 为导出行号,`line_no` 为订单内部项次),止于待人工上传。
|
||||
- 库存门禁通过(无缺口或人工放行)→ 创建正式发货通知及通知明细,再生成 Excel,止于待人工上传。
|
||||
- 多源行级全部成功 → 以主绑定源制单(保留行级 resolved);同键多文件冲突、短缺、缺文件 → 人工例外。
|
||||
- 零规则候选时复核台可从「已启用库存源」多选并填原因;`match_completed` 禁止 partial 制单。
|
||||
|
||||
@@ -167,6 +166,9 @@
|
||||
|
||||
- 管理端按公司级、部门级、班组级三级卡片独立增删培训资料,每条资料保存明确的 `training_level`。
|
||||
- 知识库候选仅允许启用的“员工培训”分组中未删除文档的当前版本,员工端按当前 `safetyStage` 动态过滤并展示对应资料。
|
||||
- 培训管理后台需支持按培训类型配置学员侧 `progress_items`、`progress_hint_text` 与 `step_intro_text`,用于动态渲染培训进度流程和步骤引导文案。
|
||||
- 学员侧仅在后台返回有效 `progress_items` 时渲染培训进度模块;若未配置任何进度项,则整个进度模块隐藏,不显示默认占位内容。
|
||||
- 入职培训、安全培训等存量培训类型需自动补齐预设进度说明与步骤引导文案,保证改造前后的学员体验一致。
|
||||
|
||||
### 3.x.1 Excel/CSV 知识库分段补充需求
|
||||
|
||||
@@ -857,3 +859,10 @@ XFA 模板管理端暂不启用字段脱敏,树、拆分预览和样本验证
|
||||
- Casdoor 登录到 HXOPS 本地用户以 `employee_id`(工号)为主映射键;当前用户名等于工号,仅保留用户名到本地工号/用户名的兼容回退。邮箱和手机号不参与认证映射;工号与用户名命中不同本地用户时拒绝登录。
|
||||
|
||||
---
|
||||
|
||||
## 在途仓自动调拨 Agent(2026-08)
|
||||
|
||||
- 需求:仓库管理人员按收料来源实例(DBS-AWSBI / DBS-AWSSG / CRANE-SZ)核对收料文件与 ERP 账面库存后生成 ERP 调拨单;DBS/Crane 仅分组,来源实例为执行边界。
|
||||
- 手工两步:选择来源实例 → 预检明细核对后直接生成 ERP 调拨单(无独立确认页);当天收料不查询 ERP;数量严格相等才可执行;不支持部分调拨/容差/单位换算/批次拆分。
|
||||
- ERP 写入由后端确定性服务与 Worker 完成,Dify 不得直接调用 ERP;Invoice No 幂等;结果未知只读禁自动重试;通知失败不改变 ERP 结果。
|
||||
- 完整规格见 [features/in-transit-transfer/minimum-implementation-spec.md](features/in-transit-transfer/minimum-implementation-spec.md)。
|
||||
+14
-9
@@ -2,15 +2,20 @@
|
||||
|
||||
按 **业务域** 组织已落地或正在落地的功能手册;**产品原型与该域文档同目录**。**实现状态**见 [funclist.md](../funclist.md)。
|
||||
|
||||
| 域 | 说明 | 入口 |
|
||||
| ----------------------------------------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [shipping-notice](shipping-notice/README.md) | 货代发货通知 Agent | [technical.md](shipping-notice/technical.md) · [客户识别规则改造方案](shipping-notice/customer_identity_rules_plan.md) |
|
||||
| [in-transit-transfer](in-transit-transfer/) | 在途仓自动调拨 Agent | [开发部门需求与原型评审包](in-transit-transfer/mvp-requirements-and-prototype-review-pack.md) · [来源实例 Lean UX Canvas](in-transit-transfer/mvp-source-instance-lean-ux-canvas.md) · [可点击原型](../platform/in-transit-transfer-source-instance-mvp.html) · [PRD](in-transit-transfer/prd.md) · [路线图](in-transit-transfer/roadmap.md) · [完整规格](in-transit-transfer/minimum-implementation-spec.md) · [一期 TDD](in-transit-transfer/in-transit-transfer-tdd.md) |
|
||||
| [auth](auth/README.md) | Casdoor 登录与产品内平级服务无感登录 | [hxops-peer-service-sso.md](auth/hxops-peer-service-sso.md) |
|
||||
| [shipping-notice](shipping-notice/README.md) | 货代发货通知 Agent | [technical.md](shipping-notice/technical.md) · [原型](shipping-notice/shipping_notice_agent_prototype.md) |
|
||||
| [file-check](file-check/README.md) | 文件检核(RoHS / MSDS 等) | [technical.md](file-check/technical.md) |
|
||||
| | | |
|
||||
| [accounting-voucher-check](accounting-voucher-check/README.md) | 立账凭证资料检核 | [需求说明](accounting-voucher-check/demand.md) · [技术设计](accounting-voucher-check/technical-design.md) · [原型](accounting-voucher-check/accounting-voucher-check-prototype.html) |
|
||||
| 域 | 说明 | 入口 |
|
||||
| --- | --- | --- |
|
||||
| [shipping-notice](shipping-notice/README.md) | 货代发货通知 Agent | [technical.md](shipping-notice/technical.md) · [客户识别规则改造方案](shipping-notice/customer_identity_rules_plan.md) |
|
||||
| [in-transit-transfer](in-transit-transfer/) | 在途仓自动调拨 Agent | [开发部门需求与原型评审包](in-transit-transfer/mvp-requirements-and-prototype-review-pack.md) · [来源实例 Lean UX Canvas](in-transit-transfer/mvp-source-instance-lean-ux-canvas.md) · [可点击原型](../platform/in-transit-transfer-source-instance-mvp.html) · [PRD](in-transit-transfer/prd.md) · [路线图](in-transit-transfer/roadmap.md) · [完整规格](in-transit-transfer/minimum-implementation-spec.md) · [一期 TDD](in-transit-transfer/in-transit-transfer-tdd.md) · [运维手册](in-transit-transfer/technical.md) |
|
||||
| [auth](auth/README.md) | Casdoor 登录与产品内平级服务无感登录 | [hxops-peer-service-sso.md](auth/hxops-peer-service-sso.md) |
|
||||
| [shipping-notice](shipping-notice/README.md) | 货代发货通知 Agent | [technical.md](shipping-notice/technical.md) · [原型](shipping-notice/shipping_notice_agent_prototype.md) |
|
||||
| [file-check](file-check/README.md) | 文件检核(RoHS / MSDS 等) | [technical.md](file-check/technical.md) |
|
||||
| [accounting-voucher-check](accounting-voucher-check/README.md) | 立账凭证资料检核 | [需求说明](accounting-voucher-check/demand.md) · [技术设计](accounting-voucher-check/technical-design.md) · [原型](accounting-voucher-check/accounting-voucher-check-prototype.html) |
|
||||
| [fixed-assets](fixed-assets/README.md) | 固资快照同步与本地查询 | [technical.md](fixed-assets/technical.md) · [履历挂载命令](fixed-assets/history-share-mount.md) |
|
||||
| [procurement-contract](procurement-contract/README.md) | 采购合同审查 Agent(模板比对 / 单份审核) | [用户操作手册](procurement-contract/用户操作手册.md) · [demand.md](procurement-contract/demand.md) · [comprehensive-review-technical.md](procurement-contract/comprehensive-review-technical.md) · [原型](procurement-contract/procurement-contract-review-prototype.html) |
|
||||
| [contract-payment-plan](contract-payment-plan/) | 合同付款计划 / 预警 Agent | [方案 V3](contract-payment-plan/contract-payment-warning-proposal-v3.md) · [原型](contract-payment-plan/contract-payment-plan-workspace-prototype-v2.html) |
|
||||
| [equipment-maintenance](equipment-maintenance/README.md) | 设备维保助手 | [聊天原型](equipment-maintenance/equipment-maintenance-agent-chat-lofi.html) |
|
||||
|
||||
**平台级**设计与跨域原型见 [platform/](../platform/README.md)。
|
||||
|
||||
**约定**
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 立账凭证资料检核需求说明
|
||||
|
||||
> 文档版本:v1.7
|
||||
> 更新时间:2026-09-04
|
||||
> 文档版本:v1.9
|
||||
> 更新时间:2026-09-08
|
||||
> 状态:一期销售需求确认中;采购及其它业务方待后续 Profile 配置
|
||||
>
|
||||
> 本文是本期需求权威。仓库里现有「当前自然月 + 单一共享盘 + 固定文件名存在性」是旧实现,不得作为本期验收口径;旧实现部署见 [ops-checklist.md](ops-checklist.md)。
|
||||
@@ -68,19 +68,27 @@
|
||||
| 操作 | 查看详情;进入该批次的执行记录,并可查看企业微信通知附件 Excel |
|
||||
| 任务入口 | 支持新建任务、强制重检(仅上一个月);企微接收人从系统用户多选,可复用排程通知人选择器 |
|
||||
|
||||
### 3.5 企业微信发送记录
|
||||
|
||||
工作台同一入口用 Tab 切换「检核任务」与「企微发送记录」。发送记录以 `voucher_check_notifications` 为真相源,每批一条缺件汇总(已发送 / 失败 / 无缺件未发送 / 未配置接收人 / 通知关闭)。
|
||||
|
||||
| 区域 | 内容 |
|
||||
| -------- | --------------------------------------------------------------------------------------------- |
|
||||
| 筛选条件 | 资料所属期间、发送状态 |
|
||||
| 列表字段 | 批次号、资料所属期间、invoice 总数、invoice 缺件数、缺件文件数、发送状态、未发送原因、接收人、发送时间、Excel |
|
||||
| 操作 | 有附件时可下载该批 Excel;查看详情进入对应批次明细 |
|
||||
|
||||
## 4. 销售一期文件规则
|
||||
|
||||
销售开票附件落在文档管理系统(文档库)中。不论从 ERP 打印、OA 打印还是固定目录扫描,**获取成功后都先写入当月类型存放目录**,再按发票号归档到「所有归档」。
|
||||
|
||||
目录层级(与文档库现状一致):
|
||||
目录层级(销售一期检核涉及的类型目录):
|
||||
|
||||
```text
|
||||
文档库 / 销售开票附件 / {yyyy} / {MM} /
|
||||
├── PO订单/
|
||||
├── 付款回单/ ← 库中已有,一期不检核
|
||||
├── 发票/
|
||||
├── 报关资料/
|
||||
├── 送货单/ ← 库中已有,一期不检核
|
||||
├── 销货单/ ← 销货放行申请单的类型存放目录
|
||||
├── 报关单/
|
||||
├── 提单/
|
||||
|
||||
@@ -58,9 +58,9 @@ VOUCHER_CHECK_SHARE_UNC=\\192.168.100.230\ai_file\vouche
|
||||
VOUCHER_CHECK_LOCAL_ROOT=/mnt/hxops-voucher-check-test # prod 换 prod 路径
|
||||
VOUCHER_CHECK_SHARE_HEALTHCHECK_RELATIVE_PATH=.hxops-share-ready
|
||||
|
||||
# Oracle(只读;DSN 可复用 ERP_DB_DSN)
|
||||
# Oracle(只读;未单独配置 VOUCHER_CHECK_ERP_* 时复用 ERP_DB_DSN / ERP_USERNAME,再回退 CONTRACT_PAYMENT_ERP_*)
|
||||
VOUCHER_CHECK_ERP_DSN=${ERP_DB_DSN}
|
||||
VOUCHER_CHECK_ERP_USERNAME=<readonly-user>
|
||||
VOUCHER_CHECK_ERP_USERNAME=<readonly-user> # 可省略,回退 ERP_USERNAME 或 CONTRACT_PAYMENT_ERP_USERNAME
|
||||
VOUCHER_CHECK_ERP_PASSWORD=<secret>
|
||||
VOUCHER_CHECK_ERP_TIMEOUT_SECONDS=30
|
||||
```
|
||||
@@ -136,7 +136,8 @@ docker exec hxops-backend ls "/mnt/hxops-voucher-check-test/$(date +%Y)/$(date +
|
||||
### 5.4 工作台记录页
|
||||
|
||||
- [ ] 打开 `/workspace/accounting-voucher-check`
|
||||
- [ ] 可按月/状态/发票号筛选
|
||||
- [ ] 「检核任务」可按月/状态筛选
|
||||
- [ ] 「企微发送记录」可按月/发送状态筛选,能看到接收人、未发送原因与 Excel 下载入口
|
||||
- [ ] 缺资料票的缺失材料列非空
|
||||
|
||||
### 5.5 Tool API(可用 curl / Postman)
|
||||
@@ -157,6 +158,39 @@ GET /api/accounting-voucher-check/tools/runs/<run_id>/items?result=missing
|
||||
|
||||
---
|
||||
|
||||
## 5.6 在 jobs 表识别立账凭证检核
|
||||
|
||||
平台排程(含立账凭证)仍走统一 `schedule` 队列,**`domain`/`job_type` 会一直是 `schedule` / `schedule_run`**,这是 worker 认领约定,不要按这两列区分业务。
|
||||
|
||||
升级后新入队的 Job:
|
||||
|
||||
| 列 | 立账凭证检核示例 |
|
||||
| --- | --- |
|
||||
| `business_ref` | `schedule_run:{id}:accounting-voucher-check` |
|
||||
| `payload_json.platform_api_path` | `accounting-voucher-check` |
|
||||
| `payload_json.task_name` | `立账凭证检核` |
|
||||
| `message` | `立账凭证检核等待后台执行` |
|
||||
|
||||
```sql
|
||||
SELECT id, status, business_ref, message, payload_json
|
||||
FROM jobs
|
||||
WHERE domain = 'schedule'
|
||||
AND job_type = 'schedule_run'
|
||||
AND (
|
||||
business_ref LIKE '%:accounting-voucher-check'
|
||||
OR payload_json->>'platform_api_path' = 'accounting-voucher-check'
|
||||
)
|
||||
ORDER BY id DESC
|
||||
LIMIT 20;
|
||||
```
|
||||
|
||||
Worker 日志关键字:`[voucher-check]` 或 `[schedule-run] name=立账凭证检核 path=accounting-voucher-check`。
|
||||
启动 `python worker.py --queues schedule` 时不应再刷「合同付款预警 ERP」;那条只属于 `--queues contract`。
|
||||
|
||||
升级前已写入的旧行仍可能是 `business_ref=schedule_run:{id}`,可按 `payload_json.schedule_task_id` 关联 `schedule_tasks.platform_api_path`。
|
||||
|
||||
---
|
||||
|
||||
## 6. 回滚要点
|
||||
|
||||
- [ ] 代码回滚后:可 `flask db downgrade` 到上一 revision(会删本域两表 + 种子 `schedule_no`)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
| ------------ | ------------------------------------------------------------------------------------------------- |
|
||||
| 支持多业务方 | 新业务方优先新增 Profile,不在通用流程中增加销售/采购分支 |
|
||||
| 支持多来源 | 新文件来源通过 Adapter 接入,不将查询、打印、目录扫描逻辑写死在引擎中 |
|
||||
| 支持周度增量 | **每周二**处理上一个自然月;以 `invoice + 文件规则` 的来源指纹和结果判断是否跳过 |
|
||||
| 支持周度增量 | **每周二**处理上一个自然月;以 `invoice + 文件规则` 的来源指纹和结果判断是否跳过 |
|
||||
| 可审计 | 保存批次、单文件结果、归档结果、缺件汇总、通知状态与配置快照 |
|
||||
| 可汇总 | 明确区分缺件文件总数和缺件 `invoice` 数;通知 Excel 以 `invoice` 为行、以文件规则为动态状态列 |
|
||||
|
||||
@@ -55,23 +55,23 @@ business_profiles/
|
||||
|
||||
生产配置应存放于数据库或受控配置中心,以上目录仅表示逻辑结构;发布后的 Profile 必须生成不可变快照并绑定批次。
|
||||
|
||||
| 配置项 | 说明 |
|
||||
| -------------------------------------- | ------------------------------------------------------------------------ |
|
||||
| `profile_code` / `profile_version` | 业务方及发布版本,例如 `sales:v1` |
|
||||
| 配置项 | 说明 |
|
||||
| -------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| `profile_code` / `profile_version` | 业务方及发布版本,例如 `sales:v1` |
|
||||
| `subject_adapter` | 获取本期 `invoice` 主体清单。销售一期:HXJM `apa_file`(`apa08`/`apa09`),期间为上一个月 |
|
||||
| `file_rules` | 必检标识、命名模板、关联字段、来源 Adapter、查询/扫描条件、临时/归档模板 |
|
||||
| `notification` | 企业微信接收人、启用开关、模板、去重策略 |
|
||||
| `incremental_policy` | 指纹字段、可跳过状态、强制重检规则 |
|
||||
| `file_rules` | 必检标识、命名模板、关联字段、来源 Adapter、查询/扫描条件、临时/归档模板 |
|
||||
| `notification` | 企业微信接收人、启用开关、模板、去重策略 |
|
||||
| `incremental_policy` | 指纹字段、可跳过状态、强制重检规则 |
|
||||
|
||||
### 3.2 Adapter 契约
|
||||
|
||||
| Adapter | 责任 | 统一输出 |
|
||||
| -------------------------- | -------------------------------- | -------------------------------- |
|
||||
| `subject_adapter` | 获取期间内应检主体及关联信息 | `invoice`、主体属性、来源指纹 |
|
||||
| `erp_print_adapter` | 查询业务单据并打印 PDF | 文件临时路径、关联字段、来源指纹 |
|
||||
| `oa_report_adapter` | 一期模拟 OA 页面查询并打印 PDF;预留新 OA 接口 | 文件临时路径、关联字段、来源指纹 |
|
||||
| Adapter | 责任 | 统一输出 |
|
||||
| -------------------------- | ----------------------------------------------------------------- | -------------------------------- |
|
||||
| `subject_adapter` | 获取期间内应检主体及关联信息 | `invoice`、主体属性、来源指纹 |
|
||||
| `erp_print_adapter` | 查询业务单据并打印 PDF | 文件临时路径、关联字段、来源指纹 |
|
||||
| `oa_report_adapter` | 一期模拟 OA 页面查询并打印 PDF;预留新 OA 接口 | 文件临时路径、关联字段、来源指纹 |
|
||||
| `directory_scan_adapter` | 扫描文档库类型目录并匹配命名模板(复用现网 DMS 登录与 Page 接口) | 匹配文件、扫描路径、来源指纹 |
|
||||
| `cloud_drive_adapter` | 按接口检索和下载文件 | 文件临时路径、关联字段、来源指纹 |
|
||||
| `cloud_drive_adapter` | 按接口检索和下载文件 | 文件临时路径、关联字段、来源指纹 |
|
||||
|
||||
Adapter 不负责归档、Excel 或通知;引擎不理解 ERP/OA 的具体页面、SQL、目录规则。
|
||||
|
||||
@@ -120,7 +120,7 @@ OA 销货放行申请单 Adapter 固定使用:上月申请日期、流程状
|
||||
归档:文档库/销售开票附件/{yyyy}/{MM}/所有归档/{invoice}/
|
||||
```
|
||||
|
||||
类型目录与一期文件对应(**已确认固定,不改名**):`PO订单`、`报关资料`、`销货单`(销货放行申请单)、`发票`、`报关单`、`提单`。库中同级的 `付款回单`、`送货单` 一期不检核。
|
||||
类型目录与一期文件对应(**已确认固定,不改名**):`PO订单`、`报关资料`、`销货单`(销货放行申请单)、`发票`、`报关单`、`提单`。
|
||||
|
||||
ERP/OA 打印或目录扫描的成功文件先写入类型存放目录;完成 `invoice` 关联、命名和文件完整性校验后,**复制**到「所有归档」下该发票子目录(不移动类型目录原件)。同一 `invoice` 的所有成功资料必须集中在同一归档子目录。**重复文件策略:同名跳过**——目标子目录已有相同 `LeafName` 时不覆盖、不报缺件,记为已归档。类型目录写入失败或归档复制失败属于技术失败,不可降级为缺件。
|
||||
|
||||
@@ -201,7 +201,7 @@ ERP/OA 打印或目录扫描的成功文件先写入类型存放目录;完成
|
||||
|
||||
## 9. 实施顺序
|
||||
|
||||
1. **已做**:Profile、文件规则、批次/单文件结果表、上月期间、周二 cron、销售 DMS 只读、directory_scan、缺件聚合、批次企微、工作台任务列表。
|
||||
1. **已做**:Profile、文件规则、批次/单文件结果表、上月期间、周二 cron、销售 DMS 只读、directory_scan、缺件聚合、批次企微、工作台任务列表与企微发送记录。
|
||||
2. **已做**:`dms_archive` 建文件夹(`SaveFolder`)+ 复制(`Item/Copy`),重复策略同名跳过;命中文件记 `archived`。
|
||||
3. **已预留**:`erp_po_print`、`oa_sales_release` Adapter,周任务不调用。
|
||||
4. 接入 ERP PO 打印与 OA 模拟页,作为独立抓取任务写入类型目录。
|
||||
@@ -225,13 +225,13 @@ ERP/OA 打印或目录扫描的成功文件先写入类型存放目录;完成
|
||||
|
||||
当前 `backend/app/services/voucher_check/` 仍按旧模型运行,**不是**本期设计的实现:
|
||||
|
||||
| 旧实现 | 本期设计 |
|
||||
| --- | --- |
|
||||
| 每日 `0 6 * * *`,检核**当前自然月** | **每周二** `0 6 * * 2`,检核**上一个自然月** |
|
||||
| HXJM `apa_file.apa08/apa09` 拉发票清单 | **沿用该口径**,仅把期间改为上一个月 |
|
||||
| 旧实现 | 本期设计 |
|
||||
| ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------- |
|
||||
| 每日 `0 6 * * *`,检核**当前自然月** | **每周二** `0 6 * * 2`,检核**上一个自然月** |
|
||||
| HXJM `apa_file.apa08/apa09` 拉发票清单 | **沿用该口径**,仅把期间改为上一个月 |
|
||||
| 共享盘 `vouche/{YYYY}/{MM}/{invoice_no}/` 只做文件名存在性 | 从 ERP/OA/固定目录**获取**,先写入 `销售开票附件/{年}/{月}/{类型}/`,再归档到同月 `所有归档/{invoice}/` |
|
||||
| 必检「核价单.pdf」「采购单.pdf」 | 销售一期:PO、报关资料、销货放行申请单、发票、报关单、提单 |
|
||||
| 一票一状态;缺资料按票发企微 textcard、同票同日节流 | 单文件结果;每批一条汇总通知 + invoice 行 Excel |
|
||||
| 必检「核价单.pdf」「采购单.pdf」 | 销售一期:PO、报关资料、销货放行申请单、发票、报关单、提单 |
|
||||
| 一票一状态;缺资料按票发企微 textcard、同票同日节流 | 单文件结果;每批一条汇总通知 + invoice 行 Excel |
|
||||
|
||||
迁移约束:
|
||||
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,95 @@
|
||||
# 在途仓自动调拨 Agent — 运行维护手册
|
||||
|
||||
> 状态:后端 Phase 0-4 已交付(领域/文件/预检/执行/排程/恢复/通知/归档/指标),前端实施中。
|
||||
> 关联规格:[minimum-implementation-spec.md](./minimum-implementation-spec.md) · [TDD](./in-transit-transfer-tdd.md) · [PRD](./prd.md) · [路线图](./roadmap.md)
|
||||
|
||||
## 1. 架构概览
|
||||
|
||||
- **业务域**:`backend/app/services/in_transit_transfer/`(独立领域模块,不混入 shipping_notice 订单解析)。
|
||||
- **执行边界**:收料来源实例(如 DBS-AWSBI / DBS-AWSSG / CRANE-SZ);DBS/Crane 仅分组。
|
||||
- **真相源**:`TransferRun` / `TransferPrecheck` / `TransferInvoiceItem` / `TransferAttempt`(表:`transfer_*`,迁移 `it1a2b3c4d5e`)。
|
||||
- **ERP 访问唯一出口**:`erp_adapter.py`(query_inventory / create_transfer / verify_duplicate);SOAP 在 WSDL 冻结前 fail-closed(`ErpNotFrozenError`)。
|
||||
- **异步**:`transfer` 队列(`worker_in_transit_transfer.py`)消费预检/执行 Run/执行 Item 三类 Job。
|
||||
- **排程**:`in-transit-receipt-file`(08:00)与 `in-transit-transfer`(09:00)platform job(`schedule/job_registry.py`)。
|
||||
|
||||
## 2. 数据库
|
||||
|
||||
- 迁移链:`it1a2b3c4d5e_add_in_transit_transfer.py`(down_revision=`hw6x7y8z9a0b`)。
|
||||
- 部署:`cd backend && flask db upgrade`(PostgreSQL)。回滚:`flask db downgrade <上一revision>`。
|
||||
- 表:transfer_runs / transfer_source_jobs / transfer_prechecks / transfer_invoice_items / transfer_attempts / transfer_audit_events / transfer_archives。
|
||||
- 审计表只追加(ORM 门禁 + 前端禁止删除);大对象归档 MinIO(transfer_archives 记录 provider/bucket/key/sha256)。
|
||||
|
||||
## 3. 环境变量(⑨业务模块区;凭据只由环境/Secret 注入)
|
||||
|
||||
| 变量 | 默认 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `IN_TRANSIT_TRANSFER_SOURCE_CONCURRENCY` | 2 | 来源并发 |
|
||||
| `IN_TRANSIT_TRANSFER_ERP_QUERY_CONCURRENCY` | 2 | ERP 查询并发 |
|
||||
| `IN_TRANSIT_TRANSFER_ERP_WRITE_CONCURRENCY` | 1 | ERP 写并发(一期恒 1,禁止提升) |
|
||||
| `IN_TRANSIT_TRANSFER_ERP_QUERY_TIMEOUT_SECONDS` | 60 | 查询超时 |
|
||||
| `IN_TRANSIT_TRANSFER_ERP_WRITE_TIMEOUT_SECONDS` | 60 | 写超时 |
|
||||
| `IN_TRANSIT_TRANSFER_CONFIRM_TTL_SECONDS` | 600 | 确认有效期(10 分钟) |
|
||||
| `IN_TRANSIT_TRANSFER_BACKLOG_WARN_DAYS` | 3 | 老化预警阈值 |
|
||||
| `IN_TRANSIT_TRANSFER_BACKLOG_ESCALATE_DAYS` | 5 | 老化升级阈值 |
|
||||
| `IN_TRANSIT_TRANSFER_BACKLOG_CRITICAL_DAYS` | 7 | 老化严重阈值 |
|
||||
| `IN_TRANSIT_TRANSFER_ERP_ENDPOINT` / `_USERNAME` / `_PASSWORD` / `_DEFAULT_ORG` | 空 | ERP SOAP 地址与凭据(WSDL 冻结前留空=fail-closed) |
|
||||
| `IN_TRANSIT_TRANSFER_ARCHIVE_BUCKET` | hxops-transfer | 归档 bucket |
|
||||
| `MINIO_ENDPOINT` / `MINIO_ACCESS_KEY` / `MINIO_SECRET_KEY` / `MINIO_SECURE` | 既有 | MinIO 连接(复用既有变量) |
|
||||
| `SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR` | 既有 | 收料 RPA trigger 目录(复用收料链路) |
|
||||
|
||||
> 凭据纪律:ERP/MinIO 凭据只存在于环境/Secret;不得写入代码、日志、DOM、Excel 或 API 响应。
|
||||
|
||||
## 4. API(`/api/in-transit-transfer`,统一 envelope + requestJson)
|
||||
|
||||
| Method | Path | 说明 |
|
||||
| --- | --- | --- |
|
||||
| POST | `/prechecks` | 创建预检(只读) |
|
||||
| GET | `/prechecks/{id}` | 预检进度恢复 |
|
||||
| POST | `/prechecks/{id}/execute` | 确认范围并直接生成执行 Run |
|
||||
| GET | `/runs/{run_no}` | Run 结果(按 ERP 单号聚合 + 未生成单据异常) |
|
||||
| POST | `/runs/{run_no}/cancel` | 请求停止剩余任务(原因必填) |
|
||||
| POST | `/items/{id}/retry` | 人工重试(erp_recheck,新 Attempt) |
|
||||
| POST | `/items/{id}/manual-close` | 人工关闭(原因必填) |
|
||||
| GET | `/runs/{run_no}/exceptions.xlsx` | 七 Sheet 异常 Excel(下载留审计) |
|
||||
| GET | `/runs/{run_no}/receipt-files` | 收料来源文件 zip(下载留审计) |
|
||||
| GET | `/runs/{run_no}/erp-inventory` | 预检冻结 ERP 库存表 csv(下载留审计) |
|
||||
|
||||
权限:admin 或持有 `in_transit_transfer` Agent 权限;无权限 403。
|
||||
|
||||
## 5. 部署
|
||||
|
||||
```bash
|
||||
# 后端(迁移 + worker)
|
||||
cd backend && flask db upgrade
|
||||
# 新增 transfer worker 服务(docker-compose 增加 hxops-transfer-worker,
|
||||
# command: python workers/worker_in_transit_transfer.py,环境同后端)
|
||||
```
|
||||
|
||||
上线灰度顺序(路线图 §8.6):ERP 测试组织 UAT → 生产只读观察(预检、写=0)→ 小范围对话写入试点 → 正式对话写入 → 单来源自动排程 → 全部来源自动排程;每步留启用人/时间/配置版本/门禁结果/回退条件审计。
|
||||
|
||||
## 6. 告警与运维关注点
|
||||
|
||||
- `result_unknown` 项数量(只读隔离,等待人工核实 SOP;禁止自动重试)。
|
||||
- 待处理池 3/5/7 天老化计数(`metrics.collect_metrics()` / 待处理页)。
|
||||
- `notification_status=failed` 的 Run(ERP 结果不受影响,但通知缺失需人工补发)。
|
||||
- ERP 超时率与 `ErpNotFrozenError` 出现(说明契约/配置未冻结或 endpoint 缺失)。
|
||||
- 归档 Hash 复核(`verify_archive_hash`)与 MinIO 容量。
|
||||
|
||||
## 7. 归档与数据保留
|
||||
|
||||
- 大型快照/Excel/报文经 `archive.py` 归档 MinIO,`transfer_archives` 索引+Hash 留库;归档必须重算 Hash 并写审计。
|
||||
- 审计事件永久保留(到期清理需显式配置,参照既有 shipping 审计保留机制)。
|
||||
|
||||
## 8. 回退策略
|
||||
|
||||
- 停用 `in-transit-transfer` 自动排程(不删除历史 Run);保留对话只读预检与手工执行。
|
||||
- `result_unknown` 继续进入人工核实池;已成功 ERP 单据不自动撤销。
|
||||
- 回退配置走新发布版本 + Diff 审计,不直接改数据库。
|
||||
|
||||
## 9. E2E 与验收(前置:ERP 契约/路由归属/单据分组冻结 + 测试组织/白名单 + Secret 注入 + SOP 确认)
|
||||
|
||||
- 后端专项:`cd backend; pytest -q tests/services/in_transit_transfer; pytest -q tests/api/test_in_transit_transfer_api.py; pytest -q tests/jobs/test_in_transit_transfer_jobs.py; pytest -q tests/workers/test_in_transit_transfer_worker.py`
|
||||
- 性能:`pytest -q tests/performance/test_in_transit_transfer.py`
|
||||
- 前端:`cd frontend; npm run test:unit -- src/features/chat; npm run build`
|
||||
- 端到端场景清单(前端实施后落 Playwright/Vitest 契约):人工执行主路径、自动排程、异常恢复、刷新恢复、权限越权、ERP 沙箱真实单据(创建/审核/过账/作废)。
|
||||
- 上线门禁:P0/P1 缺陷 0;越权写 403 100%;当天收料 ERP 调用 0;审计 Hash 复算一致率 100%;Secret 明文暴露 0。
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 禁止修改 `scripts/rpa/freight_rpa_worker.py`、`shipping_inventory_rpa.v2`、`/api/shipping-notice/rpa/inventory-*` 与库存入库/匹配服务。
|
||||
- 禁止修改 `scripts/rpa/inventory/inventory_rpa_worker.py`、`shipping_inventory_rpa.v2`、`/api/shipping-notice/rpa/inventory-*` 与库存入库/匹配服务。
|
||||
- 首版不实现库存和收料间的登录会话复用、同 Profile 互斥锁或跨排程协调;运维上错开使用同一 Profile 的排程时间。
|
||||
- 收料 Worker 在单次排程内以 `connector_type + rpa_profile_id + login_url` 分组,每个分组登录一次、串行处理其全部单元。
|
||||
- DBS 每个收料配置 Warehouse 展开一条单元;报表日期固定不传。Crane 每站点创建 `Inbound Details`,通过本次唯一 Description 轮询并下载。
|
||||
@@ -88,10 +88,10 @@
|
||||
### Task 4: 实现独立 DBS/Crane 收料 Windows Worker
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/rpa/freight_receipt_rpa_worker.py`
|
||||
- Create: `scripts/rpa/freight_receipt_dbs_export.py`
|
||||
- Create: `scripts/rpa/freight_receipt_crane_export.py`
|
||||
- Create: `scripts/rpa/start_receipt_rpa_worker.ps1`
|
||||
- Create: `scripts/rpa/receipt/receipt_rpa_worker.py`
|
||||
- Create: `scripts/rpa/receipt/receipt_dbs_export.py`
|
||||
- Create: `scripts/rpa/receipt/receipt_crane_export.py`
|
||||
- Create: `scripts/rpa/receipt/start_receipt_worker.ps1`
|
||||
- Modify: `scripts/rpa/README.md`
|
||||
- Test: `backend/tests/test_freight_receipt_worker_contract.py`
|
||||
|
||||
|
||||
@@ -684,3 +684,65 @@ A:可以。现在推荐按**一次业务委托一个 Agent 会话**处理;
|
||||
| 技术文档 | `docs/features/shipping-notice/technical.md` |
|
||||
| 同步维护 | 流程、字段、确认节点变更时 **两份文档一并更新** |
|
||||
| 最近更新 | 2026-07-22:履约策略更新为 `SHIP_AVAILABLE_ROLLING`;允许完整满足的预约单分轮制单,仍禁止按同一预约单拆分可发数量 |
|
||||
|
||||
---
|
||||
|
||||
## 15. 多库存源自动探测与行级选源(一期)
|
||||
|
||||
> 针对一个订单可能命中多个库存源(仓库)的场景。系统会**自动**从各缺失候选源获取库存并匹配,全程零人工;只有在「同一行在多个库存源都命中」这种无法自动裁决时,才会请你人工选源。
|
||||
|
||||
### 15.1 什么时候会自动获取库存
|
||||
|
||||
- 建单后进入「通知准备」,若某些候选源还没有可用库存快照,系统会自动触发一次**批量库存获取**(单批次、逐源、超时与重试沿用既有机制),页面显示「已触发库存获取,等待各库存源回调」。
|
||||
- 已有快照的库存源会直接复用,**不会重复获取**。
|
||||
- 之前“缺文件就停在库存等待”的阻断,现在只在**库存获取本身失败**(超时/用尽)时才出现,且仍可沿用既有的 reload/retry 恢复动作。
|
||||
|
||||
### 15.2 行级匹配与选源
|
||||
|
||||
- 匹配按「数据自证」原则:每条订单明细会在全部候选源快照里比对,按行写回**实际库存源 / 可用量 / 缺口**。
|
||||
- 如果某一行**只在单一库存源**有货,则该行自动确定来源,无需你操作。
|
||||
- 如果某一行**在多个库存源都命中**,系统无法替你决定,会在该行显示一个**库存源下拉**(候选 + 规则首选 + 命中规则提示)。你选择后点击确认,系统**只对该行重新匹配**,其他行不受影响:
|
||||
- 候选源标记为首选(规则首选)的排在前面;
|
||||
- 下拉里只出现该行真正命中的候选源;
|
||||
- 你选定的来源会写入该行,并记入审计(`review_line_source_selected`)。
|
||||
|
||||
### 15.3 何时锁定为只读
|
||||
|
||||
- **边界 = Excel 生成**:通知的 Excel 一旦生成(导出产物落库),该行库存源即转**只读**,页面显示“已锁定”徽标,不再提供下拉。
|
||||
- 生成前的任何时间(含匹配完成后)你都可以改行源:系统只重新匹配该行,**不会重复触发库存获取**。
|
||||
- Excel 生成后想纠错:按既有撤销 / 人工流程处理。
|
||||
|
||||
### 15.4 同一行命中多源的提示
|
||||
|
||||
- 出现下拉行时,系统提示「同一明细在多个库存源命中,请选择实际库存源」。
|
||||
- 若某行**规则未命中任何候选源**,不提供下拉,沿用既有「规则未命中」阻断与重试入口。
|
||||
|
||||
### 15.5 波次通知的库存源(D8 已实现)
|
||||
|
||||
- 波次通知(同 PO 分轮制单产生的后续发货通知)**不再继承首通知的库存源字段**,改为按**波次自己的明细行**重新评估库存源并冻结候选集(同一套自动探测/匹配/反写)。这样「同一订单不同行来自不同仓库」不会因为波次照抄首单源而冲突。
|
||||
- 波次行为设计:若某一行命中了路由规则,就按该规则确定来源;若某一行**一条规则都没命中**,则回退到该订单级(任务级)可用的候选来源,和首张通知的处理方式一致,不会把该行算成“无候选”而卡死。
|
||||
- 若确实极个别订单需要人工确认来源,按既有「无候选/歧义」阻断与人工选源流程处理。
|
||||
|
||||
---
|
||||
|
||||
## 16. 确认后、Excel 前的订单编辑窗(二期)
|
||||
|
||||
> 订单确认后、首通知 Excel **生成前**,业务人员仍可修正少量订单头字段或行字段(如目的地、料号、数量、预约号)。Excel 一旦生成即转只读,纠错走既有撤销/人工流程。
|
||||
|
||||
### 16.1 什么时候可以编辑
|
||||
|
||||
- **头字段**:该订单所有通知都还没有生成 Excel、且没有正在处理的库存获取/匹配(系统不忙)时,可编辑单头字段(如目的地、客户、PO)。
|
||||
- **行字段**:每条明细行可编辑的窗口更宽松——只要该行**所属的通知**还没生成 Excel、且系统不忙即可;尚未进入任何波次的行,即使首张 Excel 已生成,也仍可编辑(D10「未入波次行不受首单 Excel 限制」)。
|
||||
|
||||
### 16.2 编辑后会发生什么
|
||||
|
||||
- 系统按字段类型自动决定下游动作:
|
||||
- **路由字段**(目的地、仓提示等)变更 → 自动**重新路由库存源 + 重新获取(复用已有快照)+ 全单重新匹配**。
|
||||
- **行字段**(料号/数量/预约号)变更 → **仅该行重新匹配**;若该行被行级路由规则引用则同时重路由该行。
|
||||
- 与路由/匹配无关的字段 → 仅保存 + 版本递增 + 审计,无额外动作。
|
||||
- 编辑期间若系统正在处理库存获取或匹配,会提示「系统处理中,请稍后再修改」,待处理结束再改。
|
||||
|
||||
### 16.3 Excel 生成后
|
||||
|
||||
- Excel 一旦生成,头字段、行字段、行源全部转为**只读**;页面按后端 `edit_window` 禁用对应输入。
|
||||
- 若已确认信息有误,只能走既有的撤销 / 人工纠错流程(D12:编辑窗只覆盖「确认后、Excel 前」;客户侧订单变更仍走重新上传/重新解析;上传货代后的纠错仍须人工撤销)。
|
||||
@@ -107,7 +107,7 @@
|
||||
|
||||
- 新增 `backend/app/services/shipping_notice/identity_resolution/`:来源适配器、标准化、匹配、冲突裁决、快照序列化。
|
||||
- `backend/app/services/shipping_notice/customer_shadow_resolution.py`:替换固定权重/固定提取。
|
||||
- `backend/app/services/shipping_notice/order_customer_matching.py`:保留编码优先,名称/地址/联系人使用统一候选。
|
||||
- `backend/app/services/shipping_notice/identity_resolution/` 与 `customer_shadow_resolution.py`:按已发布规则集汇总名称、编码、地址、联系人等指纹证据,生成统一候选与确认快照。
|
||||
- `backend/app/services/shipping_notice/order_schema/runtime.py`:提供仅读取已裁决 Header 值的稳定入口。
|
||||
- `backend/app/models/shipping_customer_resolution.py`:记录规则版本、定义快照、来源字段快照和命中原因。
|
||||
- `backend/app/services/shipping_notice/order_schema/service.py`:把启用识别定义纳入字段引用阻断。
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
# 货代发货通知 — 工作台「展示 & 按钮」唯一契约(冻结 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`。
|
||||
|
||||
---
|
||||
|
||||
## 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;**展示面不得再独立渲染**(已冻结)。
|
||||
@@ -259,7 +259,7 @@ ROUTE_DETECT_MODE.mode == "review"
|
||||
| --- | --- | ---: | --- |
|
||||
| `field_code` | String/Null | 否 | 可读字段编码,不作为身份真相 |
|
||||
| `field_id` | String | 是 | 冻结 Schema 稳定字段 ID |
|
||||
| `line_key` | String/Null | 条件必填 | `scope=line` 时必须为非空字符串 |
|
||||
| `draft_line_id` | String/Null | 条件必填 | `scope=line` 时必须为非空草稿行身份 |
|
||||
| `line_number` | Integer/Null | 否 | 可选显示行号 |
|
||||
| `scope` | String | 是 | 仅允许 `header` 或 `line` |
|
||||
|
||||
@@ -296,8 +296,8 @@ def main(query: str, review_llm_contract: str = "") -> dict:
|
||||
raise ValueError("FIELD_ID_REQUIRED")
|
||||
if target.get("scope") not in ("header", "line"):
|
||||
raise ValueError("INVALID_SCOPE")
|
||||
if target.get("scope") == "line" and not str(target.get("line_key") or "").strip():
|
||||
raise ValueError("LINE_KEY_REQUIRED")
|
||||
if target.get("scope") == "line" and not str(target.get("draft_line_id") or "").strip():
|
||||
raise ValueError("DRAFT_LINE_ID_REQUIRED")
|
||||
if request.get("evidence_level") not in LEVELS:
|
||||
raise ValueError("INVALID_EVIDENCE_LEVEL")
|
||||
pack = request.get("evidence_pack")
|
||||
@@ -458,7 +458,7 @@ System Prompt:
|
||||
|
||||
规则:
|
||||
1. field_id、scope 和 line_number 必须与 target_field_json 完全一致。
|
||||
2. line 字段只能处理目标 line_key 所对应的证据,不得串行。
|
||||
2. line 字段只能处理目标 draft_line_id 所对应的证据,不得串行。
|
||||
3. suggested_value 必须能在该字段证据中逐字证明;quote 必须是证据中的逐字短引文。
|
||||
4. 不得翻译、改写、格式化、补零、推算、合并或猜测字段值。
|
||||
5. confidence 只是建议强度,不能替代逐字证据。
|
||||
@@ -1080,7 +1080,7 @@ Dify 节点级错误使用 Fail Branch;画布不配置循环、自动重试或
|
||||
| R01 | 合法 L1 单字段证据 | REVIEW | 返回一个建议或空建议 JSON |
|
||||
| R02 | 合法 L2/L3 请求 | REVIEW | 只使用命中表/页的最小证据 |
|
||||
| R03 | 两个 target_fields | REVIEW | `INVALID_REQUEST`,不调用 LLM |
|
||||
| R04 | line 字段无 line_key | REVIEW | `INVALID_REQUEST` |
|
||||
| R04 | line 字段无 draft_line_id | REVIEW | `INVALID_REQUEST` |
|
||||
| R05 | 模型返回非 JSON或错 field_id | REVIEW | `INVALID_MODEL_OUTPUT` |
|
||||
| R06 | 模型值不在字段证据中 | REVIEW | 后端 `validation_failed`,不能接受或修改 |
|
||||
| R07 | Dify 超时/不可用 | REVIEW | 后端 `provider_unavailable`,人工复核不中断 |
|
||||
|
||||
@@ -65,7 +65,7 @@ post-OT wave:
|
||||
|
||||
```text
|
||||
shipping_notice / OT
|
||||
line_key
|
||||
snapshot_line_id
|
||||
line_index
|
||||
inventory_snapshot_id
|
||||
match_result
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
- **业务用户**仅可见 `PROCESS_GATE_BUSINESS_USER_ACTION_CODES`;技术重试不对业务投影。
|
||||
- 库存源路由额外动作:`adopt_rule_suggestion`、`keep_manual_inventory_decision`。
|
||||
- **禁止**业务用户人工选择/切换 PDF Profile;`open_profile_review` 仅导航至只读模板区。
|
||||
- **禁止跨 Gate 内嵌产物(2026-09-06)**:Worker Gate 的产物工作(生成 Excel、货代 RPA)必须在本 `gate_code` 的 Attempt 内执行;禁止在上游 Gate Attempt 内通过 `try_auto_chain_after_match` / 直接 workflow 调用完成下游职责。`_orchestrator_internal_dispatch` 仅表示「已在本 Attempt 内直跑本 Gate workflow」,不得用来在 `inventory_matching` Attempt 内生成 Excel。开心路径:`match pass → complete → enqueue → artifact_generation Attempt → generate_excel(_task_payload)`。`SHIPPING_NOTICE_AUTO_GENERATE_EXCEL_ENABLED` / `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 只控制是否自动入队对应 Attempt,不表示在 match 内直跑。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
- 桌面右栏 `ReviewCurrentProcessingCard` 是每个 Gate 唯一全局写入口;主区仅显示事实、行级局部操作或被右栏定位的裁决表单。`TaskTodoPanel` 在生命周期工作台仅作无界面动作执行宿主,禁止重复渲染 Gate 或主按钮。
|
||||
- `stage_context` 不落库、不驱动状态、不授权动作,仅由正式任务详情与单票 `/ui-state` 按需返回;任务列表、聊天轻量投影不加载它,以避免 N+1 查询。
|
||||
- **OT 阶段随 Gate 推进回写(2026-08-26)**:`_refresh_execution_pointers`(Gate 状态/指针刷新的唯一收口)在 Execution 已绑定任务时补调 `sync_order_task_stage_for_notice`,使 `shipping_order_tasks.stage/status` 与当前 Gate 事实一致(如 `manual_upload_handoff` → `freight_uploading/blocked`),避免右侧「当前任务」主卡/批次投影停留在旧技术阶段(如 `excel_generating`)。建单前执行(无 task_id)不触发。
|
||||
- **履约 Gate 编排分离(2026-09-06)**:`inventory_matching` Attempt 只做匹配 + `sync`;`complete(passed)` 后由 `_enqueue_auto_progress_after_gate_pass` 入队独立 `artifact_generation` Attempt,再由 `_handle_regenerate_excel` / `_task_payload` 调用 `generate_excel`。禁止 `try_auto_chain_after_match` 在匹配 Attempt 内嵌 generate/upload;`AUTO_GENERATE_EXCEL` / `AUTO_UPLOAD` 仅控制自动入队。详见 [process-gate-recovery-contract.md](./process-gate-recovery-contract.md) 与计划 `docs/superpowers/plans/2026-09-06-shipping-gate-orchestration-separation.md`。
|
||||
|
||||
### Dify 配置边界(2026-08)
|
||||
|
||||
@@ -29,17 +30,37 @@
|
||||
- `Case/Draft.field_conflicts`、Candidate Qualification 和 Process Gate 必须读取同一份当前开放冲突事实;UI 不得用过滤后的空列表覆盖资格层仍未解决的冲突。真实冲突缺少可裁决值时必须保留为 Review Finding,不能降级为“无冲突”。
|
||||
- “保存订单并校验”是唯一确认入口。后端先保存 Draft,再在同一业务链路重新计算必填、证据、冲突、重复、客户确认和自动建单策略门禁;只有 `auto_create_enabled=true` 且全部自动建单门禁通过时,才返回 `can_auto_create=true` 并进入建单,否则返回稳定阻断原因及可执行的 Review 动作。
|
||||
- Review Gate 或字段冲突发生变化时,即使生命周期 `stage/status` 不变,也必须递增 `progress_version` 并写入对应审计事件。Review 工作台、聊天投影和任务详情均按该版本刷新,禁止以前端旧 Projection 推导按钮。
|
||||
- 上传成功(人工确认或 RPA 回调)必须统一清除历史上传阻断原因并收口正式 Execution 的履约 Gate;`upload_status=uploaded` 是终态成功事实,投影不得被遗留的 `upload_rpa_pending`、失败或未知原因重新降级。
|
||||
- 上传成功(人工确认或 RPA 回调)必须统一清除历史上传阻断原因并收口正式 Execution 的履约 Gate;Notice 面成功词唯一为 `uploaded`(经 `project_notice_upload_status`;Attempt 库内仍写 `succeeded`)。业务完成用 `has_verified_upload_success`;`facts.upload_state` 成功词为 `succeeded`(`project_facts_upload_state`)。禁止调用方再读 Attempt 原词或扩同义词集合。
|
||||
- `resolve_field_conflicts` 仅在当前 Case 仍存在开放字段冲突时展示;Case 已无开放冲突时,旧 Projection 中残留的该动作必须被前端隐藏,同时以后端 `ui_state.actions` 为最终动作契约。
|
||||
- Dify 的 Review 建议只能消费 HXOPS 下发的最小脱敏证据并返回候选建议,不能改变 Gate、Projection、Candidate 或 Task;建议不可用时人工复核和确定性主链仍可继续。
|
||||
|
||||
### 状态契约统一(2026-09-06)
|
||||
|
||||
原则与分期计划见 [`docs/superpowers/plans/2026-09-06-shipping-status-contract-unification.md`](../../superpowers/plans/2026-09-06-shipping-status-contract-unification.md)。**以 Phase A 为模板**:单一判词、单点投影、硬切无历史兼容;禁止在业务/前端用 frozenset 或 `includes([...])` 扩同义词。
|
||||
|
||||
| Phase | 主题 | 状态 | 规范做法摘要 |
|
||||
|---|---|---|---|
|
||||
| **A** | Notice `upload_status` / `facts.upload_state` | **已完成** | 投影成功词分别为 `uploaded` / `succeeded`;完成谓词 `has_verified_upload_success` |
|
||||
| **B** | human-wait 跨层 | **已完成** | Wire `user_status` 只认 F2(含 `waiting_human`);停发 `idle`;`status_label` 不再发 `pending_review`;FE 删 LEGACY-UNIFY / idle 双认 |
|
||||
| **C** | `match_status` 同名多域 | 待做 | 拆 `inventory_match_status` / `profile_match_status`;STP 禁用 `matched`/`shortage` 冒充履约;行级只发 `inventory_matched`;无旧字段双读 |
|
||||
| **D** | reason / automation | **已完成(D1b+D2)** | 货代聚合停发/停读 `pending_human_reason`;`project_job_status_outcome` 为 Job→outcome 唯一 mapper |
|
||||
| **E** | 入口卫生 + 门禁 | **已完成(最小门禁)** | `test_shipping_status_contract_hygiene` 禁 projector 外 synonym 袋;货代 FE 零 `pending_human_reason` 字符串 |
|
||||
|
||||
**故意保留的双层**(勿当同义词债合并):Gate→`user_status`;五段 `lifecycle_stage` vs 15 段 processing stage;`lifecycle_status` vs runtime status;STP 诊断节点 ≠ UI 真源;FileAsset.`upload_status` 属另一产品面。
|
||||
|
||||
### Run 解析期紧凑进度(2026-08-23)
|
||||
|
||||
- `serialize_lifecycle_progress()` 只复用既有 Run、Unit、workspace Progress Event 与健康提示,输出 `lifecycle_stage`、当前/已完成步骤、最后活动、健康和稳定提示键;不新建事件表、SSE/WebSocket、队列或状态机。`layout_parsing_completed` 等完成型 event code 即使为兼容实时实体状态记录为 `running`,也必须作为已完成步骤。
|
||||
- `serialize_review_run()` 只读取轻量进度,禁止为首屏进度加载完整 documents、candidates 或 `handling_items`。有正式 Task/Case 生命周期投影时,工作台继续以现有 `ui_state/lifecycle_entries` 为权威,Run 进度只覆盖解析尚未产生 Case 的窗口。
|
||||
- 页面在标题下使用既有五阶段导航加一行紧凑当前步骤提示;失败、取消、排队和健康阈值提示显示稳定原因文案,禁止暴露 Worker/Provider 错误正文。不得新增独立状态卡或占整行黄色横幅。
|
||||
- (2026-08-31 v2 收口)五阶段导航下方不再渲染常驻进度横幅;Run 级动态说明由右栏 `ReviewCurrentProcessingCard` 状态块内嵌承载(仅 `lifecycle_status ∈ {running, waiting, failed, cancelled}` 白名单;无 Case 瞬态才在导航下保留单行轻提示),失败、取消、排队和健康阈值提示显示稳定原因文案,禁止暴露 Worker/Provider 错误正文。不得新增独立状态卡或占整行黄色横幅。
|
||||
- 重新解析、解析重试、库存/RPA/Excel 等已启动异步任务,以及“重新识别客户”后门禁通过并由后端启动自动推进,都在轮询刷新中复用同一投影;只打开客户选择、确认客户或其他同步人工操作时不显示伪造自动进度。门禁未通过仅显示后端阻断原因。
|
||||
|
||||
### 状态展示统一与动态说明(2026-08-31)
|
||||
|
||||
- 前端展示口径收口:`shippingProcessingLabels.ts` 新增 `resolveRunLifecycleUserStatus`(`RUN_STATUS_FALLBACK_MAP`:review_required→waiting_human,queue_backlog/processing_slow/processing_attention→running;原因码只能补充/细化用户态,不能覆盖 failed/cancelled/completed)与 `resolveExtractionActivityMessage`(白名单 {running, waiting, failed, cancelled};仅 running 可声称自动处理,诊断原因优先于步骤句;failed/cancelled 强制原因 key,禁止复用 step 文案)。`currentTaskUserStatus` 既有链(正式 OT ui_state → Case automation)末尾追加 Run 级兑底;completed/cancelled/未知不映射。
|
||||
- 动态说明内嵌在「当前任务」卡状态行下方(弱文本一行);仅 `REDUNDANT_DETAIL_REASON_CODES`(当前仅 review_required)且映射结果等于当前状态时隐藏,排队/偏慢/需关注等诊断信息一律保留;未知原因默认保留;不做字符串匹配、不做模糊关键词判断。
|
||||
- `current_activity`(聊天页/任务中心消费的文件级快照)与 `lifecycle_progress`(工作台五阶段投影)保持后端双投影不变;聊天页与任务中心的阶段 key 改走 `resolveOrderExtractionRunStageKey` 唯一出口,文案仍为 `shippingOrderExtractionUserStage.*`/`shippingOrderExtractionCardTitle.*`,视觉零变化。设计详见 `docs/superpowers/specs/2026-08-31-shipping-review-status-display-unification-design.md`。
|
||||
|
||||
### 本次 Dify 手工核对(管理员执行)
|
||||
|
||||
本次无需新增 Dify 节点、变量、Prompt 或 Tool,也无需让 Dify 输出进度。管理员只需在发布前核对:`shipping_notice` Chatflow 未订阅 Run/Unit/ProgressEvent、未根据模型判断输出阶段或完成状态、仅保留只读 `get_task_status`(如启用)及隔离的最小 Review 建议分支;任何订单解析、门禁推进、客户确认、库存、Excel、RPA、人工上传确认或写入 Tool 均必须禁用。Dify 不可用不能阻断本次五阶段进度展示或订单主链。
|
||||
@@ -53,6 +74,7 @@
|
||||
- 原 PDF 是不可变源事实。`ensure_on_demand_coordinate_evidence()` 是唯一坐标补全入口:当前 Layout -> Run 快照补缺 -> 原生 PDF -> OCR;返回合并后的当前 Layout。任一关键坐标无法取得时固定输出 `coordinate_evidence_unavailable` 并进入 `review_required`。
|
||||
- **Reservation ID 专区动态锚点(2026-08-25)**:仅当已选中模板定义了 `reservation_id_region` 时启用。该配置不再以保存时的 `page_no/region` 作为正式取值位置,而是补齐全文页面坐标证据后,按阅读顺序从首次 `Vendor Comments` 标题之后累计到首次 `Terms and Condition` / `Terms and Conditions` 标题之前;区块可跨页。只在此封闭区块内解析带 `Reservation` 标签的合法 5/10 位数字,并复用既有行号归属和冲突规则。缺失任一起止锚点、边界顺序异常或值冲突均固定进入 Review,禁止自动猜测;未定义该专区的模板不扫描全文,原解析行为不变。
|
||||
- `matching_features.v1` 在压缩 `page_glyphs` 前持久化页面结构、主表框、表头及顺序、列数/中心/宽度和静态字段关系。它是稳定匹配输入,不升级命名;缺少关键特征不得从评分分母剔除后形成 `hard_match`。
|
||||
- **坐标证据外置为 FileAsset(2026-08-26/30 决策)**:`coordinate_evidence` 不再内联在布局快照的 `payload_json` 中。`record_inline_layout_snapshot` / `complete_layout_version` 在证据含非空 `page_glyphs`/`tables` 时,将其外置为派生 `FileAsset`(`asset_role=layout_coordinate_evidence`、`application/json+gzip`),从 payload 移除 `coordinate_evidence` 并写入轻量 `coordinate_evidence_ref`(`{asset_no, checksum, size, schema_version}`)。PDF 布局仅当 `coordinate_evidence_ref.asset_no` 存在时才视为 ready:否则 `complete_layout_version` 回退 `failed` 并写入 `shipping_document_layout_coordinate_evidence_incomplete`;仅当外置资产持久化失败时才写入 `shipping_document_layout_coordinate_evidence_persist_failed`。读取侧 `current_layout_snapshot()` 经 `_hydrate_coordinate_evidence` 从该资产回填 `coordinate_evidence`;`ensure_on_demand_coordinate_evidence()` 是唯一坐标补全入口,优先使用当前 Layout(坐标来自外置资产 hydration),缺页再从原 PDF 原生字形/OCR 补齐。原 PDF 始终是不可变源事实。
|
||||
- Profile 只识别版式身份;Schema 是唯一业务字段契约。订单头由 `page_glyphs + Profile field layout + Schema` 取值,订单行由 `table_glyphs + Profile table layout + Schema` 重建;两者共享同一个 Profile、Layout、Schema 和 `CoordinateTransform`。
|
||||
- `CoordinateTransform` 统一处理归一化坐标及受限平移、缩放、小角度旋转。锚点不足、残差超限、越界、共线、非法矩阵或局部非线性失真必须 fail-closed,禁止强行命中。
|
||||
- **参考页坐标帧(2026-08-25)**:编辑器继续保存 0..1 的画布区域,但坐标模板保存时必须从 annotation sample 的冻结 `coordinate_evidence.pages` 写入每页 `CropBox` 点尺寸。盲测与正式解析先以“相对区域 × 标注页点尺寸”恢复 PDF 点框,再读取当前页的同一物理点框;不得直接按当前页高度重投影。该规则覆盖“分页页与未分页长页内容位置相同”的场景,不需要复制模板;缺少参考页框的历史模板保持兼容旧投影,重新保存标注样本后才获得新契约。真实整体缩放/平移仍只允许由显式 `anchor_frame` 的稳定文档匹配锚点处理,禁止以订单字段在运行时拟合。
|
||||
@@ -637,6 +659,7 @@ Hxops **货代发货通知 Agent** 的部署、目标架构、Dify 配置、Open
|
||||
- **并发与幂等**:服务端快照计算 idempotency key;相同输入返回同一 Run;同一 Intake 同时只允许一个活动 Run。
|
||||
- **失败 Run 手工重试**:用户在订单识别失败卡片点击“重试失败附件”,调用 `POST /api/workspace/shipping-notice/order-extraction-runs/{run_no}/retry`。仅 `failed` 可重试;复用原 Run、冻结附件/正文、Schema、解析器/策略版本和 Intake 关系,不要求重新上传,也不创建新 Run。
|
||||
- **重新识别版本链**:终态且未消费的 Run 可调用 `POST /api/workspace/shipping-notice/order-extraction-runs/{run_no}/reparse` 创建新的 Run,原因仅允许 `rule_updated/field_mapping_error/document_quality/other`。新版重新冻结当前已发布的 Schema、Profile、解析器/策略和当前 ready 布局快照,不复用旧单元结果;仅当前版本 Candidate 可建单,旧版永远保留审计。
|
||||
- **重解析终态闭环不变式(2026-08-30)**:PDF 级重解析后继 Run 收口时业务必须二选一 —— 新版 Case 已上位 Stream,或旧版 Case 已恢复为可编辑状态;新版缺失或激活被拒时转入既有失败恢复链(`finalize_document_reparse`),禁止旧 Case 停留在 `reparse_pending` 被孤儿化。前端配套:重解析完成后工作台落在历史版本时自动跳转 Stream 当前版本(版本历史面板显式查看除外),跳转失败必有可见报错。
|
||||
- **变更边界**:Run 冻结解析器版本、策略版本、超时和最大尝试次数;运行时版本漂移安全阻断旧 Run。用户态 Run API 不返回正文、解析快照、原始结果或内部配置。
|
||||
|
||||
### 2026-07-21 文档级抽取优化历史阶段与 Review 门禁
|
||||
@@ -765,9 +788,9 @@ Hxops **货代发货通知 Agent** 的部署、目标架构、Dify 配置、Open
|
||||
|
||||
### 阶段 3 客户指纹绑定与冻结(2026-07-22)
|
||||
|
||||
- `ShippingOrderCustomerMatch` 为 Bill-to/Ship-to 分别保存订单原文、标准化组件、`order-customer-fingerprint.v1`、候选快照及确认审计;客户主数据不覆盖订单原文。
|
||||
- Bill-to 作为正式订购客户。人工确认必须指定启用客户并填写理由;Ship-to 仍可独立匹配站点,但不替代订购客户。影子识别仅用于质量评测,不能直接冻结。
|
||||
- `freeze_order_snapshot` 不再接受请求任意传入的客户 ID/简码,只读取当前 Extraction 已确认 Bill-to;Snapshot 同时保存客户 ID、简码和匹配规则快照。客户后续变更不回写已冻结 Snapshot。
|
||||
- 动态订单字段保存 Bill-to/Ship-to 原文及地址、编码等可识别证据;`ShippingCustomerShadowResolution` 保存已发布 Identity Rule Set 的证据、候选和确认审计。客户主数据不覆盖订单原文。
|
||||
- Bill-to/Ship-to 不表示正式客户角色。人工确认必须指定启用客户;唯一候选仅在自动确认门禁满足时写入 Resolution。客户确认是 Resolution 的独立事实。
|
||||
- `freeze_order_snapshot` 不接受请求任意传入的客户 ID/简码,只读取当前 OT 的已确认 Resolution;Snapshot 同时保存客户 ID、简码和 Rule Set 确认快照。客户后续变更不回写已冻结 Snapshot。
|
||||
- 阶段 3 Dify 手工配置:无需修改画布。客户指纹、候选排序、确认理由与 Snapshot 冻结均由 HXOPS 执行;Dify 不返回 customer_id、客户简码或匹配结论。
|
||||
|
||||
**L7 第 4 阶段工程补充验收(2026-07-22)**:人工编辑 Candidate 的业务摘要时,系统在 `structured_result_json.manual_review_history` 追加编辑前摘要、冲突、校验状态、编辑人和编辑时间,避免“修订后清空冲突”丢失审计。自动建单 Binding 和每次 Run 均冻结 `quality_batch_id`;创建 Run 与 Worker 开始执行时都重新校验该批次的 Owner、Schema、阈值和双人批准状态。`auto_create_enabled=true` 的生产 Run 禁止作为影子质量标签样本,防止用生产结果反向证明质量。该子阶段历史 head 为 `a77f8091a2c3`;当前部署还必须继续执行 Snapshot、质量、客户指纹、滚动履约和 Attempt 迁移至 `023a4b5c6d7e`。阶段回归为 `129 passed`,迁移往返和 `git diff --check` 通过。
|
||||
@@ -966,7 +989,7 @@ MinerU 服务地址、无认证方式和 OpenAPI 已确认,并已取得脱敏
|
||||
**表头污染与坐标重建 Review(2026-07-22)**:若样本表头混入明显订单行值(例如 `ITEM NO 00010`),预览返回稳定诊断 `order_profile_header_contaminated_by_data` 并标记不可建 Profile;服务端也拒绝从该表创建草稿,避免浏览器绕过。Profile 页面不是手工修复原始网格的入口。对有 PDF 原生 glyph 坐标且已人工确认列锚点的文档,`coordinate_table_reconstruction` 仅输出 `needs_review` 候选:以 x-overlap/唯一中心距离归属列,以字体高度自适应 y-band 判断新视觉行,内容形态与相邻行连续性只作辅助;无强行号的行只能是续行或复核,`** Item deleted **` 只能附着前一强锚定明细。候选保留 glyph 索引,坐标不足、列归属并列或删除行无前序明细时一律复核,绝不自动接受、发布 Profile 或进入履约。
|
||||
**模板版本中心契约 Review(2026-07-28)**:订单模板管理入口升级为按 `profile_code` 聚合的版本中心。`draft / published / retired` 仍是唯一生命周期,但“查看版本”和“创建新版本”分离:查看任意 `published/retired` 版本只进入独立详情路由 `/admin/shipping-order-document-profiles/:profileCode/versions/:version`,不得隐式创建草稿。默认版本选择顺序固定为 `published -> draft -> 最新 retired`;URL 指定不存在版本时必须返回 404,不允许前端或后端自动改跳其他版本。版本详情固定包含 `配置概览 / 样本画布 / 版本差异 / 审计记录 / 实际使用` 五个页签,其中配置概览优先加载,PDF 画布、审计、使用情况按页签懒加载。
|
||||
|
||||
**历史画布与盲测隔离 Review(2026-07-28)**:历史样本画布必须显式区分 `edit` 与 `readonly` 两种模式,不能靠隐藏保存按钮伪装只读。`published/retired` 详情只允许切换样本、翻页、缩放、查看区域详情和复制为新草稿,禁止新建/拖拽/删除区域、重绑字段、撤销重做、自动建议写入、保存、OCR 重跑及样本解除绑定。画布读取只能使用发布时冻结的 Sample 绑定、Layout 版本、文件 hash、Layout checksum、Schema checksum 和 Parser 身份;缺任一证据时明确失败,不允许回读当前最新布局。普通版本详情 DTO 只返回盲测套件状态、样本数量、通过/失败数量、批准时间和最近运行摘要,不返回 `expected_rows_json`、`expected_order_fields_json`、人工真值、可推导答案的坐标或未执行盲测 PDF 的完整身份。
|
||||
**历史画布与盲测隔离 Review(2026-07-28)**:历史样本画布必须显式区分 `edit` 与 `readonly` 两种模式,不能靠隐藏保存按钮伪装只读。`published/retired` 详情只允许切换样本、翻页、缩放、查看区域详情和复制为新草稿,禁止新建/拖拽/删除区域、重绑字段、撤销重做、自动建议写入、保存、OCR 重跑及样本解除绑定。画布读取只能使用发布时冻结的 Sample 绑定、Layout 版本、文件 hash、Layout checksum、Schema checksum 和 Parser 身份;冻结页数必须来自同一原 PDF 的完整物理页证据,不能退化为含业务表格的页数;缺任一证据或页数不一致时明确失败,不允许回读当前最新布局。普通版本详情 DTO 只返回盲测套件状态、样本数量、通过/失败数量、批准时间和最近运行摘要,不返回 `expected_rows_json`、`expected_order_fields_json`、人工真值、可推导答案的坐标或未执行盲测 PDF 的完整身份。
|
||||
|
||||
|
||||
**模板版本语义差异 Review(2026-07-28)**:版本中心 `diff` 页签已落地,统一通过 `GET /api/admin/shipping-notice/order-document-profiles/{profile_id}/diff?against_profile_id={id}` 由服务端计算。未显式指定对比版本时默认上一版本;显式比较只允许同一 `profile_code`,跨模板立即阻断。差异引擎按 `region_id / layout_id / field_id / anchor_id` 等稳定身份配对,坐标矩形统一使用 `0.001` 容差过滤浮点噪声,避免字段改名、排除区重排或序列化精度造成“删除+新增”误判。前端仅展示结构化 summary、变更项和折叠的安全 JSON 快照,不直接比较整份 definition,更不暴露正文、对象存储地址或盲测真值。
|
||||
@@ -1150,7 +1173,7 @@ OpenCV 当前结论:可保留为 L0/L2 的严格有框表候选和后续人工
|
||||
#### 产品与状态边界
|
||||
|
||||
- Run 是订单抽取的唯一业务真相;Job 仅代表一次执行尝试。Run 终态固定为 `completed / partially_completed / review_required / failed / cancelled`,其中 `review_required` 表示全部 PDF 都是业务拒识,`partially_completed` 表示成功与人工处理并存。
|
||||
- Unit 是 PDF 级处理单元,状态固定为 `pending / routing / matching_profile / extracting / merging_supplement / candidate_ready / review_required / failed / cancelled`;一份 PDF 的拒识或失败不得覆盖其他 PDF 已有结果。EML 父卡只汇总子 Unit:`review_required` 的 PDF 保留自身 Review Case/`open_order_review`,`failed` 的 PDF 只显示自身稳定错误码和 `retry_order_extraction`,不得以 Run 终态撤销兄弟附件入口。
|
||||
- Unit 是 PDF 级处理单元,状态固定为 `pending / routing / matching_profile / extracting / merging_supplement / candidate_ready / review_required / failed / cancelled`;一份 PDF 的拒识或失败不得覆盖其他 PDF 已有结果。EML 父卡只汇总子 Unit:`review_required` 的 PDF 保留自身 Review Case/`open_order_review`,`failed` 的 PDF 只显示自身稳定错误码和 `retry_order_extraction`,不得以 Run 终态撤销兄弟附件入口。**聊天摘要与批次进度中心均按 PDF 状态 → EML → PDF 展示**:混合状态 EML 在对应状态区各显示一张只读聚合卡,每张仅含本区 PDF,并标注“本组 x/共 y”;状态区标题计数统一为文件数,不得用 EML 总体状态或 EML 卡数把未完成附件混入“已完成”或显示为“任务”。
|
||||
- **取消是请求语义,不是即时伪造终态**:Run/Unit 记录 `cancellation_requested_at / cancellation_actor_* / cancellation_reason* / cancellation_completed_at`;排队 Unit 可立即 `cancelled`,执行中 Unit 投影为用户可见阶段 `cancellation_requested`,Worker 仅在文件边界与外部副作用前安全点生效。已完成 Unit 结果保留。
|
||||
- 同一 `user_id + owner_agent_id + conversation_id` 同时最多一个 `queued / processing` Run;不同会话可并行。现有 Intake 单活跃约束继续生效。
|
||||
- 用户卡片只显示后端事实投影:Run 汇总、当前文件、当前业务动作、可操作按钮,以及按 PDF 打开的详情抽屉。用户端不再展示 Workflow、节点、Provider、LLM、伪百分比或内部运行标识。
|
||||
@@ -1210,6 +1233,8 @@ OpenCV 当前结论:可保留为 L0/L2 的严格有框表候选和后续人工
|
||||
|
||||
- 用户工作台主接口固定返回 `summary / current_activity / available_actions`;详情接口固定返回按 PDF 归并的 `documents[]`。所有计数、当前活动和按钮权限均由后端计算,前端不得自行猜测。
|
||||
- 计数必须以 Unit 事实为准,禁止依赖可能滞后的批次摘要自行重算。
|
||||
- 会话级 `summary` 存在两个口径,前端必须分开消费:`summary.submitted_files`(提交基主计数,来自冻结 `attachment_selection.selected_attachment_count` + 直传 PDF Intake 数,物化前即 ≥1、单调,用于「共 N 个文件」与批次总文件数卡)与 `summary.total_files`(已识别/活跃文件数,基于物化 `ShippingOrderDocument` 裁决,用作完成率分母与 `_*_files` 状态明细)。物化前 `total_files` 可为 0,此时前端显示「正在识别附件…」占位,并在「共 N 个文件」标签内联显示「已识别 n / N」,不得把 `total_files` 当作主计数误报「0 个文件」。
|
||||
- EML 聚合卡的子文件列表必须包含冻结选择计划中**已选但尚未物化/未识别**的附件(`facts.recognized=false` 诊断行),否则「已识别 n / N」会出现「少了一份文件」的排查盲区;未识别 PDF 显示「待识别」,`.xls/.xlsx` 显示「已忽略(非订单 PDF,不参与订单识别)」并从其父 EML 的处理中/待人工等状态卡剥离,进入只读「已忽略」分区(聊天摘要和批次进度中心均默认折叠,展开后显示对应 Excel 叶子);两者都只进列表与 `submitted_files`,**不进** `total_files` / `_*_files` 状态数。顶部摘要只要存在已忽略附件,均须在既有“共 x 个文件 · 已识别 n/N”后附加“y 个已忽略”;批次进度中心概览须单列已忽略数,并保持完成率及“已处理 N/M”仅以 `total_files` 的订单文件为分母;若其余订单 PDF 均完成,即使会话 `ui_state.status` 尚未收口,聊天摘要卡也必须显示完成、隐藏当前阶段,并改用“订单文件 x 个已完成 · y 个已忽略”;该展示例外不回写、不改变后端状态。
|
||||
- 事件必须是已经发生并持久化的事实,前端只根据 `event_code` / `user_visible_stage` 做 i18n 文案映射;不允许把 Dify 节点标题或自定义显示文本当作业务阶段。
|
||||
|
||||
#### 事件、健康与恢复
|
||||
@@ -1390,7 +1415,7 @@ OpenCV 当前结论:可保留为 L0/L2 的严格有框表候选和后续人工
|
||||
- 客户合并使用源客户的 `merged_into_customer_id` 和快照审计表 `shipping_customer_merges`。`GET /api/admin/shipping-customers/{source_id}/merge-impact` 返回历史保留引用与可迁移配置;提交合并需目标客户、源简码二次确认和原因。合并事务只迁移 `shipping_customer_identifiers` 与 `shipping_customer_external_refs`,业务单、业务流水、导入行、影子候选和人工标签均保持原引用;源客户状态设为 `merged`,新选客与识别入口只接受 `active` 客户。
|
||||
- 客户创建、编辑、启停、简码变更及识别证据创建/审核/停用/自动匹配授权均写入 `ShippingCustomerLifecycleEvent` 快照;简码、状态和自动匹配授权属于高风险变更,服务端强制要求 `reason`。管理员通过 `/lifecycle-timeline` 查询单客户时间线。
|
||||
- 自动确认除 `SHIPPING_NOTICE_AUTO_CUSTOMER_CONFIRM_ENABLED` 外,还须通过 `SHIPPING_NOTICE_AUTO_CUSTOMER_CONFIRM_MIN_LABELED_SAMPLES`(默认 20)及 `SHIPPING_NOTICE_AUTO_CUSTOMER_CONFIRM_MIN_ACCURACY`(默认 0.98)门禁。统计分母仅包括当前强规则会唯一命中的已人工真值样本;未达标返回降级状态、不绑定客户、不生成业务号。`/governance-quality` 和影子报告均返回门禁状态及阈值快照。
|
||||
- 识别规则发布快照同时冻结订单 Schema 的 `id/version/checksum`。影子解析证据保存 `field_value_id/decision_id/extraction_id/context_field_id/order_schema_version_id`;自动确认时重新读取并校验 FieldValue、accepted/corroborated Decision、Extraction 与历史规则集/Schema 快照,按冻结字段规则重新标准化。影子 JSON、当前 Schema 或当前定义表均不能单独授权自动确认。
|
||||
- 识别规则发布快照同时冻结订单 Schema 的 `id/version/checksum`。影子解析证据保存 `field_value_id/decision_id/extraction_id/context_field_id/order_schema_version_id`;自动确认时重新读取并校验 FieldValue、accepted/corroborated Decision、Extraction 与历史规则集/Schema 快照,按冻结字段规则重新标准化。自动确认规则集自身仍按 `id/version/checksum` 强一致(防篡改);Schema 锚点则从「版本级强一致」放宽为「语义契约一致」——仅要求解析所用 Schema 版本真实存在(published/retired)且规则集冻结定义在新 Schema 中`field_code/scope/value_type/normalizer_key/available_for_customer_identity` 语义兼容,从而容忍 Schema 常规重发布造成的版本错位,但拒绝字段语义变化(此时自动确认 fail-closed 回人工复核)。影子 JSON、当前 Schema 或当前定义表均不能单独授权自动确认。
|
||||
- 业务编号直接归属于 `ShippingNotice`,不再存在独立业务单聚合或 `ShippingCase`;一个 PO 可产生多个 Notice,每个 Notice 持有唯一 `business_no` 并只关联一个 Excel。
|
||||
- 流水表按 `(business_type, customer_id, business_date)` 唯一,使用 PostgreSQL 原子 upsert/returning 分配,`business_no` 唯一约束提供最终保护。
|
||||
|
||||
@@ -1424,11 +1449,11 @@ OpenCV 当前结论:可保留为 L0/L2 的严格有框表候选和后续人工
|
||||
| 3 | 客户影子识别 | 只记录候选不阻断;真实历史样本形成准确率报告;误自动匹配为 0 |
|
||||
| 4 | 客户人工确认 Gate | 所有后续副作用入口均不可绕过;客户确认事件完整审计 |
|
||||
| 5 | 业务编号生成、查询和展示 | PostgreSQL 并发无重复;修订继承、强制新建重新编号;双号查询通过 |
|
||||
| 6 | 有限自动识别、监控和纠错 | 仅已审核强规则自动放行;可降级;质量指标与纠错审计可查询 |
|
||||
| 6 | 有限自动识别与监控 | 仅已审核强规则自动确认 OT 客户;可降级;质量指标可查询 |
|
||||
|
||||
每一阶段完成前必须执行本阶段代码 Review,按严重度列出全部发现、修复后重跑对应测试,并逐条核对验收标准;存在未处理高风险问题时不得进入下一阶段。
|
||||
|
||||
阶段 6 的客户纠错仅限管理员:已编号且尚未上传货代的业务单保留原号并标记 `voided`,创建 `replaces_case_id` 指向原单的替代业务单并按正确客户申请新流水;任务版本链迁移到替代单,旧号查询跟随替代链返回当前版本,纠错原因与新旧编号写入 `ShippingTaskEvent`。已上传货代的任务必须先完成外部作废流程,系统内纠错接口明确阻断。
|
||||
阶段 6 的自动确认仅发生在 OT:满足已审核强规则、唯一命中及质量门禁时写入客户确认结果;不创建 Notice、不分配业务编号。正式 Notice 创建是客户不可变边界,创建后不提供客户替换或重建能力。
|
||||
|
||||
### 第三阶段:业务去重与任务版本(实现摘要)
|
||||
|
||||
@@ -1764,10 +1789,10 @@ GET /api/admin/shipping-order-schema/published-contract
|
||||
- **Crane 初始值**:`enabled=false`(提交按钮、成功提示或上传历史记录的稳定选择器尚未确认,仅有文件选择器不代表可安全自动提交),`entry_url=https://wms-portal.craneww.com/#/shipping-order-upload`,`file_input_selector=input[name="OrderFileUpload"]`,`submit_mode=click_submit`,`submit_selector=null`,`result_mode=page_notice`,`success_texts=[]`,`timeout_seconds=120`。管理员完成页面验证并补全提交/成功判定字段后才可 `enabled=true`。
|
||||
- **不改版本号**:`upload_config_json` 变更不递增 `config_version`,避免库存 RPA 配置测试被误判过期;不维护 `upload_config_version`(无发布流、无并发编辑审批、无历史回放需求)。每个 trigger 固化本次 upload_config 快照即可保证“这次上传用了什么”;需要审计关联时对快照计算 `config_hash`(sha256)。
|
||||
- **Worker 保留两个受控 Adapter**:`DsvUploadAdapter`(DSV 入口、文件选择与结果判定)与 `CraneUploadAdapter`(Crane 入口、文件选择、提交与结果判定),**不再根据环境变量拼接 DSV/Crane 页面动作**。用连接 `login_url` 登录后访问 `upload_config.entry_url` 进入上传页;`upload_config` 决定“该连接使用哪个已支持的受控流程及其页面参数”,浏览器动作与安全边界由代码负责;Worker 上传与最终提交的全局开关(`SHIPPING_NOTICE_RPA_WORKER_UPLOAD_ENABLED` / `..._CONFIRM_SUBMIT`)仍作为部署级二次确认保留,但不再承载页面参数。
|
||||
- **执行链路**:用户触发批量 RPA 上传 → 后端创建 Upload Attempt → 读取任务已确定的系统连接及 `upload_config_json` → 复制发货 Excel 到共享上传队列 → 生成非空 `callback_id` → 原子写入 trigger(复用“临时文件 + fsync + os.replace”,携带 `schema_version / task_no / attempt_id / artifact_id / callback_id / connector_type / upload_config 快照 / upload_config_hash / login_url / credential_envelope`)→ Windows Worker 取 trigger → 按 `connector_type` 进入 DSV/Crane Adapter → 登录、打开 entry_url、选择 Excel、提交 → 以页面提示或上传历史证据判定 → 回调。
|
||||
- **执行链路**:用户触发批量 RPA 上传 → 后端创建 Upload Attempt → 读取任务已确定的系统连接及 `upload_config_json` → 复制发货 Excel 到共享上传队列 → 生成非空 `callback_id` → 原子写入 trigger(复用“临时文件 + fsync + os.replace”,携带 `schema_version / task_no / attempt_id / artifact_id / callback_id / connector_type / upload_config 快照 / upload_config_hash / login_url / credential_envelope`)→ Windows Worker 取 trigger → 按 `connector_type` 进入 DSV/Crane Adapter → 登录、打开 entry_url、选择 Excel、提交 → 以受控页面选择器判定 → 回调。
|
||||
- **结果三态**:`success`(取得可核验成功证据)、`failed`(明确页面失败、浏览器错误、超时或回调失败)、`unknown`(已可能提交但无法确认外部系统结果)。`unknown` 必须转人工处理,禁止自动重试以避免重复上传;成功/失败/未知、页面证据摘要与脱敏错误写入现有 Upload Attempt 与货代审计事件。
|
||||
|
||||
发布门禁:全局只有一个 published 版本;已发布版本不可编辑;字段首次发布后 `scope/value_type` 不可修改,`field_code` 重命名仅影响后续草稿,历史发布快照保留旧名称;证据来源、比较器、规范化器和校验器只能引用后端白名单。
|
||||
发布门禁:全局只有一个 published 版本;已发布版本不可编辑;字段首次发布后 `scope/value_type` 不可修改;**同一 field_id 的 `field_code` 一经发布不可变更**(改名 = 退役旧字段 + 新建字段,允许同一 `field_code` 漂移到新 `field_id`),历史发布快照保留旧名称;证据来源、比较器、规范化器和校验器只能引用后端白名单。
|
||||
|
||||
# 发货 Excel 模板
|
||||
|
||||
@@ -1808,7 +1833,7 @@ GET /api/admin/shipping-order-schema/published-contract
|
||||
|
||||
- 业务人员只看到五阶段:`接收解析 → 订单复核 → 通知准备 → 货代上传 → 通知完成`;Gate/Execution 是业务判断真相,`ui_state` 是唯一前端读模型,任务处置使用独立的 `lifecycle_status=active|voided|archived`。
|
||||
- 用户点击删除时,服务端以任务行锁重算资格并写入 `ShippingTaskEvent` 审计(操作者、请求 ID、原因和处置前后事实)。纯误建任务仅进入回收站;已有业务单、Candidate 消费、库存链接或导出 Artifact 的任务同时设为 `voided` 后进入回收站。存在修订后继的任务禁止 delete/void,只允许 archive,避免破坏版本链。
|
||||
- `upload_status` 为 queued/pending/running/uploading/uploaded/succeeded/success、存在货代参考号/回执时,平台禁止 delete/void,只允许 archive。异步编排、队列、RPA 回调和上传入口必须统一检查 `task_is_active`。
|
||||
- Notice 面 `upload_status`(经 `project_notice_upload_status`)为 pending/uploading/uploaded/failed/unknown 等契约词、或存在货代参考号/回执时,平台禁止 delete/void,只允许 archive;判定成功只认 `uploaded`,禁止再认 Attempt 原词 `succeeded`/`success`。异步编排、队列、RPA 回调和上传入口必须统一检查 `task_is_active`。
|
||||
- 回收站只允许恢复仍为 `active` 的纯误建任务;已作废或已归档任务不得恢复,必须走受控新建/修订业务流程。永久删除仅在第五阶段实现,并重新检查全部引用。
|
||||
- `POST /api/workspace/shipping-tasks/batch-purge` 仅管理员可调用;只允许清除回收站内、仍为 `active` 的纯误建任务。清除前事务内统计业务单/批次/来源文件/Intake/Candidate/Extraction/订单行/冲突/库存链接/Artifact/临时库存会话/修订与重复引用/外部上传事实/非处置事件;任一存在返回 `SHIPPING.TASK_PURGE_BLOCKED`。成功后写入无 `task_id` 外键的 `shipping_task_purge_audits` 快照,再物理删除 Task。
|
||||
- 后台编排器、通用 Job worker、库存 RPA 触发与库存/上传 RPA 回调均先读取 `task_execution_block_reason`。非活动任务作为 `skipped` 收口,迟到的库存回调只完成原始回调文件消费/归档,不能再创建任务库存链接、生成 Excel 或写上传结果。
|
||||
@@ -1817,9 +1842,11 @@ GET /api/admin/shipping-order-schema/published-contract
|
||||
# SHIPPING_NOTICE_AUTO_PROGRESS_ENABLED=true
|
||||
# SHIPPING_NOTICE_AUTO_RPA_INVENTORY_ENABLED=true
|
||||
# SHIPPING_NOTICE_AUTO_MATCH_ENABLED=true
|
||||
# 是否在 match pass 后自动入队独立 artifact_generation Attempt(禁止在匹配 Attempt 内直跑 generate)。
|
||||
# SHIPPING_NOTICE_AUTO_GENERATE_EXCEL_ENABLED=true
|
||||
# 真实上传 Worker 默认关闭。先配置 URL、文件/提交/成功 selector,并在非生产环境 dry-run。
|
||||
# 只有成功标识出现才回调成功;最终提交还须由 Worker 的二次确认开关控制。
|
||||
# 是否在 artifact pass 后自动入队 freight Attempt(禁止在匹配 Attempt 内直跑 upload)。
|
||||
# SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED=false
|
||||
# SHIPPING_NOTICE_AUTO_CHAIN_FALLBACK=true
|
||||
# 当已发布 Excel 模板未定义 filename_pattern 时使用;模板规则优先。
|
||||
@@ -1873,7 +1900,7 @@ GET /api/admin/shipping-order-schema/published-contract
|
||||
$env:HXOPS_API_BASE = "http://127.0.0.1:5052"
|
||||
$env:SHIPPING_NOTICE_TOOL_API_KEY = "your-tool-key"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_MOCK = "true"
|
||||
python scripts/rpa/freight_rpa_worker.py
|
||||
python scripts/rpa/inventory/inventory_rpa_worker.py
|
||||
```
|
||||
|
||||
### 1.5 库存导出 RPA 共享部署(Windows RPA + Ubuntu 后端)
|
||||
@@ -1941,24 +1968,24 @@ foreach ($root in @("C:\HxopsRpaTest", "C:\HxopsRpaProd")) {
|
||||
从项目仓库复制以下文件到 Windows RPA 主机:
|
||||
|
||||
```text
|
||||
scripts\rpa\freight_rpa_worker.py
|
||||
scripts\rpa\dsv_report_parameters.py
|
||||
scripts\rpa\dsv_login_smoke.py
|
||||
scripts\rpa\run_inventory_batch_trigger.py
|
||||
scripts\rpa\inventory\inventory_rpa_worker.py
|
||||
scripts\rpa\connectors\dsv\dsv_report_parameters.py
|
||||
scripts\rpa\connectors\dsv\dsv_login_smoke.py
|
||||
scripts\rpa\inventory\run_inventory_batch_trigger.py
|
||||
```
|
||||
|
||||
放置为:
|
||||
|
||||
```text
|
||||
C:\HxopsRpaTest\scripts\rpa\freight_rpa_worker.py
|
||||
C:\HxopsRpaTest\scripts\rpa\dsv_report_parameters.py
|
||||
C:\HxopsRpaTest\scripts\rpa\dsv_login_smoke.py
|
||||
C:\HxopsRpaTest\scripts\rpa\run_inventory_batch_trigger.py
|
||||
C:\HxopsRpaTest\scripts\rpa\inventory\inventory_rpa_worker.py
|
||||
C:\HxopsRpaTest\scripts\rpa\connectors\dsv\dsv_report_parameters.py
|
||||
C:\HxopsRpaTest\scripts\rpa\connectors\dsv\dsv_login_smoke.py
|
||||
C:\HxopsRpaTest\scripts\rpa\inventory\run_inventory_batch_trigger.py
|
||||
|
||||
C:\HxopsRpaProd\scripts\rpa\freight_rpa_worker.py
|
||||
C:\HxopsRpaProd\scripts\rpa\dsv_report_parameters.py
|
||||
C:\HxopsRpaProd\scripts\rpa\dsv_login_smoke.py
|
||||
C:\HxopsRpaProd\scripts\rpa\run_inventory_batch_trigger.py
|
||||
C:\HxopsRpaProd\scripts\rpa\inventory\inventory_rpa_worker.py
|
||||
C:\HxopsRpaProd\scripts\rpa\connectors\dsv\dsv_report_parameters.py
|
||||
C:\HxopsRpaProd\scripts\rpa\connectors\dsv\dsv_login_smoke.py
|
||||
C:\HxopsRpaProd\scripts\rpa\inventory\run_inventory_batch_trigger.py
|
||||
```
|
||||
|
||||
不要复制 `.env*`、密码文件、`backend\data` 旧运行数据、浏览器 profile、旧 trigger / processed / failed 文件。
|
||||
@@ -2093,7 +2120,7 @@ cat /mnt/hxops-rpa-test-data/inventory_triggers/.hxops_rpa_shared_mount
|
||||
先验证 DSV 登录:
|
||||
|
||||
```powershell
|
||||
python scripts\rpa\dsv_login_smoke.py
|
||||
python scripts\rpa\connectors\dsv\dsv_login_smoke.py
|
||||
```
|
||||
|
||||
成功时会看到:
|
||||
@@ -2105,7 +2132,7 @@ SUCCESS — DSV session ready
|
||||
库存 RPA 必须由 HXOPS 管理端的 Inventory Source + RPA Profile 生成 trigger;如需人工联调,选取已生成的 trigger,执行:
|
||||
|
||||
```powershell
|
||||
python scripts\rpa\run_inventory_batch_trigger.py <trigger.json>
|
||||
python scripts\rpa\inventory\run_inventory_batch_trigger.py <trigger.json>
|
||||
```
|
||||
|
||||
该入口不会读取 YAML 或本地账号密码,Profile 的密文凭据和页面操作均由平台生成的 trigger 提供。
|
||||
@@ -2289,13 +2316,13 @@ volumes:
|
||||
|
||||
同一 Windows 用户通过两个独立计划任务同时运行 test/prod。每个任务调用 `start_rpa_worker.ps1`,只给对应 Worker 子进程注入环境变量;Secret 使用当前用户 DPAPI 文件保存,不写入用户级或机器级环境变量。
|
||||
|
||||
DSV 库存导出默认使用一次性浏览器 Profile。仅在一个对应环境 Worker 运行时,启动命令可显式追加 `-ReuseDsvSession`:Worker 只为 DSV 库存任务保留独立 `dsv360_session` Profile,后续任务会优先复用登录态;会话失效仍回落现有登录流程。Crane 与上传任务保持一次性 Profile,且不得并发启动两个共享同一 WorkerRoot 的 Worker。
|
||||
库存导出默认复用浏览器 Profile:按 `connector_type + rpa_profile_code` 使用独立目录 `{connector}__{profile}_session`,默认 TTL 24 小时(`SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE` / `SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE_TTL_HOURS`)。会话过期或站点侧失效时回落现有登录流程。上传任务保持一次性 Profile。同一 WorkerRoot 只运行一个库存 Worker(串行消费 trigger,浏览器并发上限为 1)。关闭复用可传启动参数 `-NoSessionReuse`;旧参数 `-ReuseDsvSession` 仍兼容。
|
||||
|
||||
Windows 如禁止运行 `.ps1`,仅对单次 Secret 创建使用临时 Bypass:
|
||||
|
||||
```powershell
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\HxopsRpaTest\scripts\rpa\new_rpa_worker_secret.ps1" -Environment test
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\HxopsRpaProd\scripts\rpa\new_rpa_worker_secret.ps1" -Environment prod
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\HxopsRpaTest\scripts\rpa\common\new_rpa_worker_secret.ps1" -Environment test
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\HxopsRpaProd\scripts\rpa\common\new_rpa_worker_secret.ps1" -Environment prod
|
||||
```
|
||||
|
||||
若文件来自网络或压缩包并被标记为阻止,先执行 `Unblock-File`。也可用 `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass` 仅放行当前窗口。禁止永久设置 `Unrestricted` 或修改 `LocalMachine` 策略。
|
||||
@@ -2306,8 +2333,8 @@ Windows PowerShell 5.1 读取无 BOM UTF-8 脚本时可能出现中文变乱和
|
||||
|
||||
```powershell
|
||||
cd C:\HxopsRpaTest
|
||||
.\scripts\rpa\new_rpa_worker_secret.ps1 -Environment test
|
||||
.\scripts\rpa\new_rpa_worker_secret.ps1 -Environment prod
|
||||
.\scripts\rpa\common\new_rpa_worker_secret.ps1 -Environment test
|
||||
.\scripts\rpa\common\new_rpa_worker_secret.ps1 -Environment prod
|
||||
```
|
||||
|
||||
默认 Secret 路径为 `C:\HxopsRpaSecrets\test.xml` 与 `prod.xml`。文件不得进入仓库、SMB 共享、日志或其他 Windows 用户目录。
|
||||
@@ -2320,7 +2347,7 @@ DSV/Crane 登录地址、账号和密码必须先在 HXOPS 管理端的 RPA Prof
|
||||
|
||||
```powershell
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File `
|
||||
"C:\HxopsRpaTest\scripts\rpa\start_rpa_worker.ps1" `
|
||||
"C:\HxopsRpaTest\scripts\rpa\inventory\start_inventory_worker.ps1" `
|
||||
-Environment test `
|
||||
-ApiBase "http://<test后端地址>:<端口>" `
|
||||
-WorkerRoot "C:\HxopsRpaTest" `
|
||||
@@ -2330,8 +2357,8 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass -File `
|
||||
若脚本来自网络或压缩包,先确认路径并按需解除文件阻止:
|
||||
|
||||
```powershell
|
||||
Test-Path "C:\HxopsRpaTest\scripts\rpa\start_rpa_worker.ps1"
|
||||
Unblock-File "C:\HxopsRpaTest\scripts\rpa\start_rpa_worker.ps1"
|
||||
Test-Path "C:\HxopsRpaTest\scripts\rpa\inventory\start_inventory_worker.ps1"
|
||||
Unblock-File "C:\HxopsRpaTest\scripts\rpa\inventory\start_inventory_worker.ps1"
|
||||
```
|
||||
|
||||
`-ApiBase` 必须是 HXOPS 测试业务后端地址。`HXOPS_TOOLS_API_BASE`(例如 `:8890`)是 Tool API,不能填入 Worker 的 `-ApiBase`。如果使用 `http://192.168.100.192:5052`,必须先确认该地址确实是测试后端并可从 Windows Worker 访问:
|
||||
@@ -2346,7 +2373,7 @@ Invoke-WebRequest "http://192.168.100.192:5052/health" -UseBasicParsing
|
||||
连通性确认后,也可以使用仓库原始命令:
|
||||
|
||||
```powershell
|
||||
.\scripts\rpa\start_rpa_worker.ps1 `
|
||||
.\scripts\rpa\inventory\start_inventory_worker.ps1 `
|
||||
-Environment test `
|
||||
-ApiBase "http://测试后端:端口" `
|
||||
-WorkerRoot "C:\HxopsRpaTest" `
|
||||
@@ -2356,7 +2383,7 @@ Invoke-WebRequest "http://192.168.100.192:5052/health" -UseBasicParsing
|
||||
手工启动 prod:
|
||||
|
||||
```powershell
|
||||
C:\HxopsRpaProd\scripts\rpa\start_rpa_worker.ps1 `
|
||||
C:\HxopsRpaProd\scripts\rpa\inventory\start_inventory_worker.ps1 `
|
||||
-Environment prod `
|
||||
-ApiBase "http://正式后端:端口" `
|
||||
-WorkerRoot "C:\HxopsRpaProd" `
|
||||
@@ -2367,7 +2394,7 @@ C:\HxopsRpaProd\scripts\rpa\start_rpa_worker.ps1 `
|
||||
#### 1.5.11 端到端验证
|
||||
|
||||
1. Windows 手工打开 Edge,确认能访问 DSV/Crane。
|
||||
2. Windows 执行 `python scripts\rpa\dsv_login_smoke.py`。
|
||||
2. Windows 执行 `python scripts\rpa\connectors\dsv\dsv_login_smoke.py`。
|
||||
3. 在管理端创建一个库存 RPA trigger,确认其包含 Source、Profile 和密文凭据。
|
||||
4. Ubuntu 执行 `sudo -u hxops touch /mnt/hxops-rpa-test-data/inventory_triggers/test_from_ubuntu.txt`,Windows 确认 `C:\HxopsRpaTest\data\inventory_triggers` 能看到。
|
||||
5. Windows 按当前方案执行 `start_rpa_worker.ps1`;不要直接运行 `freight_rpa_worker.py`。
|
||||
@@ -2435,7 +2462,7 @@ $env:SHIPPING_NOTICE_RPA_SHARED_UPLOAD_QUEUE_DIR = Join-Path $rpaDataRoot "uploa
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR = Join-Path $rpaDataRoot "browser_profile"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_LOG_FILE = Join-Path $rpaDataRoot "logs\worker.log"
|
||||
|
||||
\.\scripts\rpa\start_rpa_worker.ps1 -Environment test -ApiBase "<test后端地址>:<端口>" -WorkerRoot "C:\HxopsRpaTest" -SecretFile "C:\HxopsRpaSecrets\test.xml"
|
||||
\.\scripts\rpa\inventory\start_inventory_worker.ps1 -Environment test -ApiBase "<test后端地址>:<端口>" -WorkerRoot "C:\HxopsRpaTest" -SecretFile "C:\HxopsRpaSecrets\test.xml"
|
||||
```
|
||||
|
||||
启动成功后,控制台会输出 `[freight_rpa_worker] started`,并持续轮询 trigger。另开一个 PowerShell 可检查日志和哨兵;本地未配置 shared scope 时不要求哨兵包含 test/prod scope:
|
||||
@@ -2832,18 +2859,16 @@ pytest tests/test_shipping_notice_state_machine.py tests/test_shipping_notice_ui
|
||||
### STP 阶段 0:字段契约冻结(2026-07-30,项次派生 Phase 0 纠偏)
|
||||
|
||||
- 标准资产 **58** 项;`shipping_order_fields` 唯一键为 `(field_code, scope)`,允许 Header/Line 同名 `reservation_id`。
|
||||
- 运行时投影:`line_key`、`effective_reservation_id = line.reservation_id ?? header.reservation_id`(经 `validated_reservation_id`);`line_no` 为可识别内部项次,不再由 `position+1` 覆盖。
|
||||
- `line_no` / `customer_po_line_no` 均在 `TABLE_FIELD_CODES`;可进入 LLM/坐标抽取。
|
||||
- Excel:废除 `system_fact:line_no`;导出行号为 `system_fact:export_sequence`(最终导出集上连续 1..N)。
|
||||
- Schema `definition_json.derivation_rules`(及 checksum):首期仅 `copy_if_empty`,目标仅 `line_no`;新草稿预置关闭规则 `customer_po_line_no → line_no`。
|
||||
- Snapshot 扩展约定:`rule_versions_json.derivation_rules_*`、`source_manifest_json.field_lineage`;审计事件词典见 `LINE_DERIVATION_AUDIT_EVENT_TYPES`。
|
||||
- 草稿行使用 `draft_line_id`;冻结档/库存准备使用 `snapshot_line_id` 与系统生成的 `line_no`;正式通知使用 `ShippingNoticeLine.line_no`。
|
||||
- `line_no` 不在 `TABLE_FIELD_CODES`,不进入 LLM/坐标抽取;`customer_po_line_no` 仍作为原始客户项次事实保留。
|
||||
- Excel 导出项次只读取 `ShippingNoticeLine.line_no`,每张通知单从 1 开始重新编号。
|
||||
- Schema 不提供派生规则;Snapshot 只保存字段来源血缘,不保存派生规则快照或校验和。
|
||||
- 迁移:`4e7a1c9b2d3f_align_shipping_order_line_contract.py`(含内部项次语义纠偏);`5f8b2d4e6a1c_restore_shipping_context_field_assets.py`(恢复 `general_context` / `deterministic_context` 与 sender 种子)。
|
||||
|
||||
### 项次派生 Phase 1–4(2026-07-30)
|
||||
|
||||
- **规则引擎**:`order_schema/derivation_engine.apply_derivation_rules_to_lines`;Admin `POST .../simulate-derivation` 写 `DERIVATION_SIMULATED`(路由层 commit);支持 `sample_ref=extraction:<id>` 加载历史明细,以及 `GET .../derivation-simulate-samples`。
|
||||
- **运行时**:标准化后执行派生,写 `FIELD_DERIVED` / `FIELD_DERIVATION_SKIPPED`(含来源字段 `evidence_refs`),`normalized_result_json.field_lineage`;required 门禁在派生之后。
|
||||
- **复核覆盖**:`line_no` 须 `override_reason_code`;写入 `manual_override`+`locked` 与 `LINE_NO_OVERRIDDEN`;恢复清除锁定并写 `LINE_NO_RESTORED`(回退 machine_fields 识别/派生投影,不重跑引擎)。
|
||||
- **项次规则**:不再提供 Schema 派生、模拟、项次覆盖或恢复;订单解析/冻结/通知写路径分别按所属单据顺序生成不可变 `line_no`。
|
||||
- **字段血缘**:只保留原文字段来源与人工修改审计,不记录派生规则校验和。
|
||||
- **复核投影**:`order_review_projection` 附加 `field_meta.value_source`;UI `ReviewLineNoOverrideDialog` + 来源徽章。
|
||||
- **冻结与永久审计**:Snapshot 血缘快照;`append_shipping_audit_event` 新写入 `retention_expires_at=None`;迁移 `6a9c3e5f7b2d` 清空历史到期时间。
|
||||
|
||||
@@ -2857,7 +2882,7 @@ pytest tests/test_shipping_notice_state_machine.py tests/test_shipping_notice_ui
|
||||
|
||||
- 路由引擎 `can_build` / `block_reason` 与历史 `status` 解耦:多候选 `ambiguous` 允许建单;零候选或 `require_manual_review` 阻断。
|
||||
- `order_build_eligibility_service` 在 Draft 校验与确认前投影行级候选;人工选择须填写原因且库存源已启用。
|
||||
- API:`PUT .../order-review-cases/{case_no}/draft/lines/{line_key}/inventory-candidates`;Draft 投影含 `build_eligibility`。
|
||||
- API:草稿字段编辑使用 `draft_line_id`;通知准备库存源覆写使用冻结档 `line_no` 定位行;Draft 投影含 `build_eligibility`。
|
||||
|
||||
### 门禁恢复阶段 0:库存源路由独立重算(2026-07-31)
|
||||
|
||||
@@ -2874,9 +2899,9 @@ pytest tests/test_shipping_notice_state_machine.py tests/test_shipping_notice_ui
|
||||
- `keep-manual` 明确保留人工值并清除 `suggestion_pending`;
|
||||
- 无人工决定且规则唯一可用命中时,建议直接成为有效结果。
|
||||
- **API**:
|
||||
- `POST .../draft/inventory-routing/reroute`(可选 `line_key`、`idempotency_key`)
|
||||
- `POST .../draft/lines/{line_key}/inventory-routing/adopt-suggestion`
|
||||
- `POST .../draft/lines/{line_key}/inventory-routing/keep-manual`
|
||||
- `POST .../draft/inventory-routing/reroute`(可选 `draft_line_id`、`idempotency_key`)
|
||||
- `POST .../draft/lines/{draft_line_id}/inventory-routing/adopt-suggestion`
|
||||
- `POST .../draft/lines/{draft_line_id}/inventory-routing/keep-manual`
|
||||
- **审计**:`inventory_routing_*` 事件写入操作人、规则版本、前后候选与幂等键;同一幂等键只产生一次有效副作用;409 版本冲突不执行副作用。
|
||||
- **前端**:复核台 `ReviewInventoryCandidatesPanel` 提供「重新匹配路由 / 采用规则结果 / 保留人工结果」。
|
||||
|
||||
@@ -2906,7 +2931,7 @@ pytest tests/test_shipping_notice_state_machine.py tests/test_shipping_notice_ui
|
||||
|
||||
- `prepare_candidate_inventory_lines` / `match_order_lines_across_candidates` / `apply_line_inventory_resolutions`。
|
||||
- `ensure_inventory` 多候选合并准备;`match_inventory` STP 分支禁止回读路由;头级 Reservation 从 Snapshot Schema Header 字段读取。
|
||||
- Excel:`ALLOWED_SYSTEM_FACTS` 含 `export_sequence`;导出注入 `__export_sequence=1..N`(基于最终导出行集);自动链止于 `wait_manual_upload`。
|
||||
- Excel:导出注入已持久化的 `ShippingNoticeLine.line_no`(每张通知单从 1 开始);自动链止于 `wait_manual_upload`。
|
||||
- 多源行级命中:`multi_source_excel_block`,首期不生成单一 Excel。
|
||||
- **多源恢复入口(闭环)**:`shortage_review` + 多源/多文件冲突时 `ui_state` 前置 `confirm_inventory_source`;写入 `forced_match_source_code` 后过滤库存行并立即重匹配。`stp_facts.recovery_source_codes` 供工作台候选对话框种子;多源阻断时前端**禁止**回退展示 `inventory_source_resolution` 全部冻结候选。首期仍不提供自动拆单 API。
|
||||
- 人工确认库存源与随后重匹配:工作台 `_trusted_user_id` 写入任务事件 `actor_id` 与统一审计;`match_inventory` 兼容 `operator_id` / `actor_id` / `_trusted_user_id`。
|
||||
@@ -2961,7 +2986,7 @@ pytest tests/test_shipping_notice_state_machine.py tests/test_shipping_notice_ui
|
||||
|
||||
| # | 场景 | 工程证据 | 状态 |
|
||||
|---|---|---|---|
|
||||
| 1 | 可信直通停在待人工上传 | `auto_progress` / `try_auto_chain_after_match` 早停 + `forbidden_next_tools` | 工程通过 |
|
||||
| 1 | 可信直通停在待人工上传 | `auto_progress` 早停 + `forbidden_next_tools`;匹配→Excel 经独立 `artifact_generation` Attempt(禁止 `try_auto_chain` 内嵌 generate) | 工程通过 |
|
||||
| 2 | 多 PDF 独立推进 | Unit/Case/Task 隔离;批次无履约门禁(既有抽取回归) | 工程通过 |
|
||||
| 3 | 人工复核后 auto_progress | 复核确认复用同一 `auto_progress` | 工程通过 |
|
||||
| 4 | 歧义/解析待办 | `must_human` + `todo_category=review` | 工程通过 |
|
||||
@@ -3110,7 +3135,7 @@ API 层
|
||||
| `backend/tests/test_shipping_inventory_routing_engine.py` | 通用路由规则引擎单测 |
|
||||
| `backend/tests/test_shipping_notice_inventory_schedule.py` | 定时批量库存 RPA 排程 executor 单测 |
|
||||
| `backend/tests/test_shipping_notice_match_summary.py` | 匹配摘要相关测试 |
|
||||
| `scripts/rpa/freight_rpa_worker.py` | 开发态 RPA worker(支持单条/批量 inventory_export) |
|
||||
| `scripts/rpa/inventory/inventory_rpa_worker.py` | 开发态 RPA worker(支持单条/批量 inventory_export) |
|
||||
|
||||
---
|
||||
|
||||
@@ -3147,7 +3172,7 @@ API 层
|
||||
- **单票 legacy 路径**:`_download_dsv360_inventory` / `_download_crane_inventory` 已委托 `_export_*_inventory_source`,与批量共用 `parameters` 填充
|
||||
- **multi_select**:worker `_fill_dsv_multi_select` 支持多选控件(非仅取第一个值)
|
||||
- **报表控件模板**(2026-08-26):同一参数名在不同报表的 SSRS 控件长相不同(`On Hand Inventory By Location 3lv` 的 Warehouse 是原生 select `ddValue`,JDA 版 `On Hand Inventory by Location` 是 txtValue/toggle/divDropDown 多选框下拉)。控件差异由 Worker 按归一化报表名登记在 `dsv_report_parameters._DSV_REPORT_PARAM_TEMPLATES`,填参时把 `report_name` 透传到模块解析;`selector_env/selectors` 继续不进入数据库,未登记报表回退参数名默认值。填参失败会输出参数区控件探针日志(`[dsv-filter] ... control probe`),便于定位控件 ID/类型漂移。
|
||||
- Worker:`scripts/rpa/freight_rpa_worker.py` → `_handle_inventory_batch_trigger`
|
||||
- Worker:`scripts/rpa/inventory/inventory_rpa_worker.py` → `_handle_inventory_batch_trigger`
|
||||
- 回调:`POST /api/shipping-notice/rpa/inventory-batch-ready`
|
||||
- **回调响应语义**(2026-08):HTTP 回调只做信封校验、成功 Excel 从 RPA shared drop 复制到 HXOPS 受控 `rpa_callback_receipts/<callback_id>/`、创建 `shipping_inventory_callback_process` Job 后立即返回 `status=ok` + 顶层/`data.result_status=accepted`。它**不得**在 HTTP 请求中做 Excel 结构校验、库存行解析、快照/任务关联或 Gate 自动推进;这些业务步骤只由 shipping worker 消费 Job 后执行。这样 Worker 的 30 秒 HTTP 等待只代表“平台已收件”,不再把实际导出成功误判为 callback timeout。Job 的最终 `callback_result.result_status` 才是 `success` / `partial_failed` / `failed`;排程场景(含 `schedule_run_id` 且 finalize 成功)由该异步结果终态化 `ScheduleRun`。worker 回调 payload 顶层含 `status`、`success`(legacy)、`has_success`、`success_count`、`skipped_count`、`failed_count`、`results[]`(每项含 `status`)。
|
||||
- **单票身份与失败收口**(2026-08-20):首次自动库存准备和用户重试均必须经 `ensure_all_required_sources_prepared` 创建逐源 Attempt;禁止写缺少 `source_run_no / lease_token / candidate_set_id / execution_id / gate_id` 的旧 task 级 trigger。Worker 发现 `trigger_identity_invalid` 时必须在 `results[]` 回传可用的 source 身份片段;后端按已定位的 Attempt 立即标记失败、同步 PreparationSourceAttempt、`inventory_preparation` Gate 与 `step3_inventory_prepare=needs_human`,不得等待库存轮询超时。
|
||||
@@ -3240,11 +3265,10 @@ API 层
|
||||
|
||||
匹配顺序:
|
||||
|
||||
1. Bill-to:`source_system + ShippingCustomerExternalRef.legacy_customer_key` → 标准名称 → 已审核名称别名。
|
||||
2. Ship-to:`source_system + ShippingCustomerSiteIdentifier(external_code)` → `ShippingCustomerSite.site_code` → 站点标准名称 → 已审核站点名称别名。
|
||||
3. 结果按角色写入 `shipping_order_customer_matches`,状态为 `unmatched / unique_candidate / ambiguous / confirmed`;Ship-to 人工确认必须同时校验站点属于所选启用客户。
|
||||
4. Candidate API 返回 `customer_matches` 供界面展示原文、标准客户、简称、站点与状态;确认接口为 `POST /api/workspace/shipping-order-extractions/{extraction_id}/customer-matches/{role}/confirm`,并校验 Extraction 所属 Intake 的用户权限。
|
||||
5. 唯一候选不绕过既有客户质量门禁。Task 建立后仍由客户确认链决定是否绑定业务归属客户和生成业务编号。
|
||||
1. 已发布 Identity Rule Set 从订单字段、邮件上下文和其他受控来源提取可识别证据,并按定义匹配客户主数据。
|
||||
2. 识别结果写入每个 Candidate 唯一的 `ShippingCustomerShadowResolution`,状态为 `unmatched / unique_candidate / ambiguous / confirmed`;`confirmed_customer_id` 是唯一确认事实。
|
||||
3. Candidate/复核 API 返回 Resolution 的候选、证据和状态;人工确认仅写入该 Resolution,并校验 Candidate 所属 Intake 的用户权限。
|
||||
4. 唯一候选不绕过既有自动确认质量门禁。OT 建立后仍由已确认 Resolution 决定是否冻结订单和生成业务编号。
|
||||
|
||||
#### Dify 手工配置要求
|
||||
|
||||
@@ -3452,3 +3476,96 @@ DBS 每个 Warehouse 单独导出且不填报表日期;Crane 固定 `Inbound D
|
||||
| `POST /api/admin/receipt-rpa-units/{unit_id}/retry` | 管理员 | 仅 `failed/cancelled`,必填 `reason` | `shipping_receipt_rpa_unit_retried` |
|
||||
| `POST /api/admin/receipt-report-files/{file_id}/resend` | 管理员 | 仅重发归档文件企微消息,不触发 RPA | `shipping_receipt_report_notification_resent` |
|
||||
| `GET /api/admin/receipt-rpa-units?status=failed` | 管理员 | 只查询失败单元,供人工补偿;不返回凭据、对象键或 trigger 内容 | `shipping_receipt_rpa_units_listed` |
|
||||
|
||||
# 2026-08-29 库存源自动探测与数据自证(一期)
|
||||
|
||||
> 关联设计:`docs/superpowers/specs/2026-08-29-shipping-inventory-source-selection-design.md`
|
||||
> 范围:多候选库存源订单在「通知准备」内的自动批次 RPA 探测、匹配数据自证反写、行级歧义兜底与人工选源;锁定边界统一为 Excel 生成。
|
||||
|
||||
## 结论摘要(决策 D1–D12)
|
||||
|
||||
- 源裁决发生在**通知准备**,不阻断建单、不改订单复核契约;`inventory_source_routing` Gate 保持 `fulfillment_prep` 面。
|
||||
- 粒度=**行级**;任务级源=各行所选并集。
|
||||
- 主路径=**多候选自动批次 RPA**:单批次 trigger 文件含全部缺失候选源;已有 ready 快照的源跳过;逐源 Attempt 记录保留(身份/超时/重试/审计)。
|
||||
- 匹配=**数据自证**:全部候选源快照按行打 `__source_code` 标签参与匹配,按行反写 源/可用量/缺口。
|
||||
- 歧义兜底=行级:同一行在多源命中 → `multi_file_conflict` 阻断,该行出**源下拉**(候选 + 首选高亮 + 命中规则提示,写 `override_by_id/override_reason`,方法 `user_confirmed`)→ 该行重匹配;其余行照常。
|
||||
- 零候选行:不提供下拉,提示「规则未命中」,沿用 `retry_with_latest_rules`。
|
||||
- **锁定边界唯一:Excel 生成(Export Artifact 落库)**。此前(含匹配完成后)行源可改 = 换标签重匹配该行(候选快照已在本地,不重新 RPA);此后转只读,纠错走既有撤销/人工流程。
|
||||
- 波次通知(D8,已实现):`post_ot_fulfillment_wave_service` 创建波次通知**不再继承**首通知任务级源字段(`inventory_source_*`/`routing_fingerprint`/`snapshot_id`),仅继承订单级路由上下文(目的地/仓提示);新增 `inventory_candidate_freeze_service.freeze_wave_notice_routing` 按波次自身行评估路由并冻结候选集,行级无规则命中时回退到订单级 task 候选集(与首单 `_collect_order_line_candidates` 行为一致,避免「无规则命中的波次行」卡死),随后走同一套自动探测/匹配/反写。测试:`tests/test_shipping_wave_rerouting.py`。
|
||||
- 订单复核确认/自动建单逻辑不变(多候选照常建单并自动推进)。
|
||||
- 原则边界:编辑窗仅覆盖「确认后、Excel 前」的人工纠错;客户侧订单变更仍走重新上传/重新解析;上传货代后的纠错仍须人工撤销。
|
||||
|
||||
## 通知准备内状态流转
|
||||
|
||||
```
|
||||
inventory_preparation Gate
|
||||
├─ 全部候选源有 ready 快照 → 直接加载匹配(现状)
|
||||
├─ 部分缺失 → 自动批次 RPA(仅缺失源)→ status=running「已触发库存获取」
|
||||
│ ├─ 批次回调逐源成功 → 加载 → 匹配 → 反写 → 续跑(匹配/Excel 门禁)
|
||||
│ ├─ 部分源失败 → 成功源照常匹配;失败源相关行停等,沿用
|
||||
│ │ inventory_rpa_timeout/exhausted 恢复动作(reload/retry)
|
||||
│ └─ 行歧义 → 行级 multi_file_conflict + 该行下拉 → 选定重匹配
|
||||
└─ 行级零候选 → 维持现状阻断 + retry_with_latest_rules
|
||||
```
|
||||
|
||||
`inventory_file_missing` 不再是多候选的终态阻断原因(降为瞬态;RPA 失败仍走既有 `inventory_rpa_timeout`/`inventory_rpa_exhausted` 重试原因)。
|
||||
|
||||
## 实现要点
|
||||
|
||||
- `inventory_workflow.ensure_inventory`(`mode='auto'` 的 STP 多候选分支):删除「缺文件不隐式触发 RPA」,改为自动批次探测。`missing_files`/`partial_missing` 返回改为触发后 `running` + 「已触发库存获取,等待各库存源回调」;无候选集时维持 `needs_human`(`inventory_candidates_missing`)。
|
||||
- `per_source_rpa_service.ensure_all_required_sources_prepared`:不再逐源写 trigger,而是把全部 pending 源合并写入**一个** `inventory_export_batch_*.json`,逐源身份键(`task_no/attempt_no/source_run_no/lease_token/candidate_set_id/execution_id/gate_id/expected_warehouse_id`)进入 `inventory_sources[]`;批次写入失败时本轮新建 Attempt 统一置 `failed/trigger_not_written`。
|
||||
- `stp_line_inventory_match.match_order_lines_across_candidates`:按行打 `__source_code` 标签参与匹配;同一行命中多源 → 行 `disposition=multi_file_conflict` + `candidate_hit_source_codes`,`resolved_inventory_source_code=None`;唯一源命中按行反写 `resolved_inventory_source_code/available_qty/shortage_qty`;人工选源通过行 `allowed_source_codes` 钉住单一源后重匹配该行。
|
||||
- `process_gate_executor` 提供通知准备能力 `override_line_inventory_source`(参数 `line_no/source_code/reason`):校验行处于冲突、源启用、**通知未生成 Excel**(`task.export_file_path` 为空,否则 `SHIPPING.LINE_SOURCE_LOCKED`);写冻结档行覆写 + 仅该行重匹配 + 审计 `review_line_source_overridden`。
|
||||
- `ui_state._build_stage_context` 的 `preparation`:下发 `source_locked`(`task.export_file_path` 非空即锁定)、`lines[].source_ambiguous`(`multi_file_conflict`)、`lines[].source_candidates`(候选编码去重)、`artifact.status`。前端 fail-closed 消费。
|
||||
- 错误解释契约/原因码:行级冲突对应 `inventory_multi_file_conflict`,Owner 动作 `select_line_inventory_source`;「同一明细在多个库存源命中,请选择实际库存源」。
|
||||
- 前端 `ShippingOrderReviewView.vue`:阶段自动跳转成功后一次性 toast(`lifecycle.autoAdvanced`);清理 `workbenchMode==='reparse'` 死守卫;通知准备歧义行渲染源下拉 + 首选高亮 + 确认按钮,`source_locked` 行只读徽标。
|
||||
|
||||
## 既有能力与契约(不新增开关)
|
||||
|
||||
- 沿用 `SHIPPING_NOTICE_AUTO_RPA_INVENTORY_ENABLED` 总开关与既有批次开关;无新增配置开关。
|
||||
- RPA Worker 无需修改(batch v2 契约已支持多源逐源身份)。
|
||||
- 存量终态/已 `uploaded` 通知零影响;非终态停挡单首次进入工作台自动探测续跑(老单治愈)。
|
||||
- 无强制数据迁移:行级覆写复用候选行 `override_by_id/override_reason`;歧义状态入匹配结果 JSON/行决定。
|
||||
|
||||
# 2026-08-29 确认后订单编辑窗(二期)
|
||||
|
||||
> 关联设计:`docs/superpowers/specs/2026-08-29-shipping-inventory-source-selection-design.md` §3。
|
||||
> 范围:确认后、首通知 Excel 生成前的订单人工纠错窗;锁定边界统一为 Excel 生成(D7/D10/D12)。
|
||||
|
||||
## 可编辑矩阵(谓词服务)
|
||||
|
||||
- 谓词收敛于单一服务 `backend/app/services/shipping_notice/order_edit_window_service.py`(`editable_scope` / `order_has_active_attempt` / `assert_field_editable`),前端 fail-closed 渲染,后端保存守卫复用同一谓词(D12 原则边界集中化)。
|
||||
- **头字段**:该订单**任一通知**(含波次)无 Export Artifact **且** 无活动 Gate Attempt → `header=True`。
|
||||
- **行字段**:逐行——行已入某波次 → 该波次通知无 Export Artifact 且无活动 Attempt;行未入波次 → 无活动 Attempt(不受首单 Excel 限制)。
|
||||
- `ui_state.build_task_ui_state` 在 `include_stage_context` 时下发顶层 `edit_window`(同构 `{header, lines}`);前端 `ShippingOrderReviewView.vue` 据此禁用锁定字段/行源下拉。
|
||||
|
||||
## 保存守卫与失效重跑
|
||||
|
||||
- 正式字段编辑走既有 `task_workflow.update_notice_fields` / `update_notice_line` / `add_notice_line` / `remove_notice_line`(不新增 Case 状态);写路径保留 `_assert_order_data_version` 乐观锁(409 语义不变)。
|
||||
- **新增编辑窗守卫**:`_edit_window_busy_error`——订单任一通知有活动 Gate Attempt(库存 RPA / 匹配 queued|running)时返回 `SHIPPING.EDIT_WINDOW_SYSTEM_BUSY`(「系统处理中,请稍后再修改」);活动 Attempt 结束后恢复可编辑。
|
||||
- **失效分类重跑**:沿用 Schema `task_edit_policy.change_effect` → `_apply_notice_edit_change_effects`:
|
||||
- 头部路由字段 → `rerun_inventory_source_resolution`:清候选/匹配/导出、`clear_inventory_source_confirmation`、重裁库存源、OT 同步 `inventory_fetching`(快照复用,无新 RPA 当快照可用)。
|
||||
- 行字段(料号/数量/预约号)→ `rerun_inventory_matching`:仅清匹配并 OT 同步 `inventory_matching`。
|
||||
- 导出相关 → `regenerate_excel`;需重解析 → `require_revision`。
|
||||
- 无路由引用 → `none`(仅保存 + `order_data_version` 递增 + 审计)。
|
||||
- 被失效的匹配结果/缺口标记 superseded,界面显示「重新匹配中」;不产生新 Excel(Excel 尚未生成)。
|
||||
- 审计 `_record_formal_task_edit_audits` 写入 `applied_effects`(失效动作链)与字段 old→new + 操作人 + 证据(D10「不强填原因」)。
|
||||
|
||||
## 前后端契约
|
||||
|
||||
- 新增错误码:`SHIPPING.EDIT_WINDOW_FIELD_LOCKED`(字段超出编辑窗)、`SHIPPING.EDIT_WINDOW_SYSTEM_BUSY`(系统处理中);四语言 `locales/*/errors.json` 已补齐。
|
||||
- 前端类型 `ShippingTaskUiState.edit_window`(`ShippingOrderEditWindow{header,lines}`);`formalHeaderEditable()`/`formalLineEditable(lineKey)` 供模板绑定 `:disabled`。
|
||||
- **原则边界(D12)**:编辑窗仅覆盖「确认后、Excel 前」的人工纠错;客户侧订单变更仍走重新上传/重新解析;上传货代后的纠错仍须人工撤销。用户不修改原始订单的原则不被扩大解释。
|
||||
|
||||
## 验收对照(§3.4)
|
||||
|
||||
1. 首通知 Excel 前改目的地(路由字段)→ 自动重路由+重探测+重匹配,指纹/审计/候选集版本正确(`rerun_inventory_source_resolution`)。
|
||||
2. 改未入波次行的数量/预约号 → 仅该行重匹配;该行已入已出 Excel 的波次 → 拒绝编辑(该行所属通知 Excel 冻结)。
|
||||
3. 匹配运行中保存 → `SHIPPING.EDIT_WINDOW_SYSTEM_BUSY`;活动 Attempt 结束后可编辑。
|
||||
4. Excel 生成后头/行全部只读(`assert_formal_task_not_excel_frozen` / `is_excel_ready_for_task`)。
|
||||
5. 乐观锁版本冲突 409 行为不变(`_assert_order_data_version`);审计含失效动作链(`applied_effects`)。
|
||||
|
||||
## 二期状态补充
|
||||
|
||||
- 一期规划中的「快照重冻结 + `order_data_version` 递增」由既有 `update_notice_*` ⇒ `_commit_notice_edit` ⇒ `_apply_notice_edit_change_effects` 链路承担(编辑落库后依赖 `change_effect` 失效下游);`order_data_version` 由乐观锁 `_assert_order_data_version` 保护,避免重复冻结引入二次状态机。
|
||||
- 波次通知「按自身行重跑路由」(D8)已实现(见一期章节):不再继承首通知源,`freeze_wave_notice_routing` 按波次自身行冻结候选集;本二期不新增二次波次状态机,与一期波次路由冻结复用同一套链路。
|
||||
+123
-79
@@ -85,84 +85,98 @@
|
||||
|
||||
### 货代发货通知(shipping-notice)
|
||||
|
||||
| 功能项 | 状态 | 说明 |
|
||||
| -------------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| **统一 ShippingProcessingProjection(15 阶段)+ 正式任务编辑** | 阶段 0–6 已验收 | 库存源硬门禁;复核台原地 formal_task;Schema `task_edit_policy`/`change_effect`;正式编辑审计矩阵;Dify NONE。验收:`unified-progress-formal-edit-stage0~6` + `final-acceptance` + `dify-config`。 |
|
||||
| 发货通知技术手册 | 已文档化 | 见[docs/features/shipping-notice/technical.md](features/shipping-notice/technical.md) |
|
||||
| 发货通知业务说明 | 已文档化 | 见[docs/features/shipping-notice/business.md](features/shipping-notice/business.md) |
|
||||
| 业务去重与任务版本(Phase 3) | 已实现 | Intake 业务指纹/重复决策、修订版本链、强制新建权限与审计;见技术手册第三节摘要 |
|
||||
| EML 附件提取(阶段一) | 已实现 | 结构化解析主题/发件人/正文与真实附件;`message/rfc822`/附件型 multipart 独立登记;完整性门禁与容器计费;见技术手册「EML 附件提取」 |
|
||||
| EML/附件上传预处理 | 已实现 | 上传后自动创建 Intake 快览:只解析邮件正文、白名单 HTML 表格快照和附件目录;上传阶段不抽取附件全文、不创建附件 FileAsset/Document、不生成 Candidate、不判订单重复;解析失败、超时、取消保持幂等 |
|
||||
| 上传与发送门禁状态一致性 | 已实现 | Intake 状态接口返回 `preview_status / ready_for_extraction / attachment_directory_complete` 等快览事实;聊天附件快览成功后显示“已就绪/已发现 N 个附件”并允许发送,不再因上传阶段版面任务阻塞;真正的订单识别进度在点击发送后单独展示 |
|
||||
| 版面解析并发与耗时诊断 | 已实现 | 独立 `hxops-shipping-worker` 默认双进程并行领取同批版面 Job;PDFium 先轻量预读字符但不裁决表格,MinerU 始终作为 PDF 表格结构首选 Provider;仅 MinerU 空表/失败时允许严格 PDFium 回退。Job `result` 平级保存脱敏 `timings`+`counts`(含 OCR/OpenCV/对齐细分与 `ocr_engine_warm`),worker 日志同步输出;诊断字段不进 layout snapshot,不记录原文/HTML/OCR 原始响应(PR-0)。PR-1:`SHIPPING_NOTICE_LAYOUT_OCR_PAGE_CACHE_ENABLED` 控制同 Job 整页 OCR 复用;PR-2:`SHIPPING_NOTICE_LAYOUT_NATIVE_PAGE_REUSE_ENABLED` 字符预读复用+按需补图,OpenCV geometry Job 内缓存;PR-3:`SHIPPING_NOTICE_LAYOUT_OCR_CROP_ENABLED` 表格裁剪 OCR(prod 默认关) |
|
||||
| 对话输入框多附件统一提交 | 已实现 | 用户可分多次选择 EML/PDF;当前输入框内全部已就绪 Intake 在一次发送中冻结为同一个订单抽取 Run。`uploadBatchId` 仅用于单次上传幂等与状态关联,不再截断发送范围 |
|
||||
| 无框订单明细表原生 PDF 回退 | 已实现 | 仅当 MinerU 未输出表格、PDF 原生文字坐标完整且同页命中多个通用明细表头时,从表头到合计行生成待配置候选表;正常 MinerU 表格路径不变,解析器修订 `v4` 防止复用旧零表格缓存 |
|
||||
| 点击发送完整订单抽取 | 已实现(终态分阶段) | Run 冻结文档、Schema、模板 Profile、路由/评分/门禁与解析器版本;Worker 执行异型模板或通用确定性解析;完整性门禁与紧急停止控制自动冻结;Dify 仅提供复核最小证据建议且不得自动冻结;上线清单见 order-extraction-go-live-checklist.md |
|
||||
| 相同附件跨批次 Workflow 复用 | 已实现 | 同会话完整附件 `content_hash` 集合与 Schema 版本相同时,复用活跃或未关闭 Run/Workflow Item;新上传批次、Intake/Document ID 或文件名不再导致重复 Workflow |
|
||||
| 订单识别生命周期反馈 | 已实现 | Run 状态卡按真实确定性解析进度和终态计数更新并持久化到 `ChatLog.payload`;聊天历史可恢复,侧栏显示未查看终态提醒,处理中不伪造百分比 |
|
||||
| 处理进度细化与全链路审计 | 已实现 | 阶段 0–5 + 正式评审整改:排队/处理中分列、文档级健康提醒与最后活动、管理员取消任意 Run(代取消必填原因)、审计完整筛选(含 conversation/session_item/review_case/owner)、敏感访问审计、取消 operation_id 串联、进度事件真实状态、库存/RPA/导出双写统一审计。Run 级 `handling_items`/`primary_notice` 拆分待补信息/冲突/自动冻结受阻/PDF 复核/技术失败/预算停扩,聊天卡与右侧「本次处理」按原因展示并跳转。灰度开关 `PROGRESS_UI_V3`/`ORDER_EXTRACTION_CANCEL`/`AUDIT_EXPORT`;审计保留 `SHIPPING_NOTICE_AUDIT_RETENTION_DAYS=1095`。Dify 无需改画布 |
|
||||
| 会话 PDF 工作项(阶段 0–4) | 已退役 | 已由 Workflow 台账替换;旧验收文档已删除 |
|
||||
| Workflow 阶段 0–2 底座与投影 | 已实现 | 删除 session work items;Workflow/Item/Version/Event;进度投影与会话轮询;见 `workflow-stage0-acceptance.md` 与 technical.md |
|
||||
| Workflow 阶段 3 确认后自动进度 | 已实现 | 五门禁(批准模板/字段完整/证据/冲突重复/质量)失败仅 Review Case;确认返回 `shipping_notice_no`/`order_task_no` 并推进履约;复核页 `ReviewWorkflowProgressPanel` 读统一 OT 投影;建单后取消 Task `pending_void`+Excel 只读;移除工作台 upload-inventory/mark-manual-uploaded/retry-upload 写入口 |
|
||||
| Workflow 阶段 4 任务中心与审计闭环 | 已实现 | 任务中心进行中 2s/8s 自动刷新;时间线合并 Workflow Event;审计关联链/敏感读权限/哈希日检;删除复核监管台 |
|
||||
| EML 正文补充表合并(阶段 2) | 已实现 | 正文 HTML 表解析为带 DOM 单元格证据的 PO 级补充事实,不创建独立订单或执行 Unit;按 `PO + MPN`、受限 PO 降级补 Reservation/Allocation/库存来源提示,支持 `External reservation ID` 等冻结 Schema 显式别名;每个 Run 从原始 HTML 重建,避免旧的部分解析结果遮蔽新规则;PDF 数量保持权威,歧义统一进入人工复核 |
|
||||
| PDF 模板 PO 拆分与严格拒识(阶段 3) | 已实现 | 已批准模板中每条明细均有唯一 PO 证据时,单 PDF 自动拆为多个独立订单;表级多 PO 未能归属明细、模板歧义、漂移和证据不足统一转人工复核,Route Decision 分别审计四类表计数 |
|
||||
| 订单模板版本中心(阶段 0-7) | 已实现 | 订单文档模板按 `profile_code` 聚合版本族;已落地独立版本详情、历史只读样本画布、服务端语义差异、审计记录页签、实际使用页签,以及阶段 7 的 blind test 隔离与发布治理;只读画布完整展示必需锚点及各受控标签区域的冻结识别值,必需锚点可对照配置值、识别值和匹配状态;标注取字、运行匹配与版本诊断统一按视觉行恢复字符阅读顺序 |
|
||||
| **订单模板版面签名 Matcher** | 代码已落地(待真实样本灰度) | 版面签名存 ValidationRun;Profile 轻量引用;Matcher 三态证据 + Top-N 解析验证;表头签名直接消费既有 `header_layout.region`,签名生成与运行时统一视觉词组和坐标口径;跨模板发布门禁与发布检查页;重识别亲和性校验签名;`SHIPPING_NOTICE_PROFILE_LAYOUT_SIGNATURE_REQUIRED` 控制全量切换。说明:[order-profile-layout-signature.md](features/shipping-notice/order-profile-layout-signature.md) |
|
||||
| **XFA 数据路径 Profile(统一回退)** | 代码收口(2026-08-18) | datasets + 拆分规则为首选;失败进入普通 PDF 共用 PDFium/Widget/OCR 证据链,保留 `fallback_from`、原因码与 `value_source`,回退候选固定 Review、禁止 STP;Dify 主链:**NONE**。 |
|
||||
| **XFA 统一视觉标注 + 字段拆分** | 统一入口已收口 | 普通 PDF/XFA 共用 Editor、`/pdf-automark` Job、保存、验证和发布 DTO;`value_binding` + `visual_binding`、RE2、统一 CQ/STP;XFA 仅在首选 datasets 取值与拆分规则上保留适配器差异。 |
|
||||
| **旧 XFA 合成预览/OCR 专用入口** | 已废弃 | 浏览器不得调用 `/xfa/automark`;内部 XFA 多源执行器由统一 `/pdf-automark` 调用,原生 PDF 页是统一画布。 |
|
||||
| **XFA 字段拆分映射(历史)** | 已被统一方案接管 | 早期 `stages[]` 流水线与独立映射页能力将在统一方案阶段 1/4 对齐并收口;对照文档:[xfa-field-split-mapping.md](features/shipping-notice/xfa-field-split-mapping.md)。 |
|
||||
| 订单模板录入 UX 重构(阶段 0-7) | 已完成 | 已完成 Draft Revision、Lease、向导、独立草稿编辑器自动保存、不可变验证运行与两步发布报告;样本上传仅负责资产保存和 PDF/EML Document 物化,版面解析作为后台预热且不阻断上传。盲测复核区分准备中、兼容性诊断和正式复核:仅 ready Layout 的真实 table_id 可确认,确认时冻结 LayoutVersion/checksum/parser 身份,执行不回读最新布局;临时 PDF 恢复仅作诊断。同模板族历史 annotation/training/新旧 blind test 文档可重新复核复用,当前版本建模样本仍严格排除。编辑器在可见状态自动续租。Dify 无需配置变更。 |
|
||||
| 订单人工复核工作台(阶段 0-7) | 已实现 | 每个 PDF Unit 一个 Review Case,机器 Candidate/Extraction 不可变、人工 Draft 独立版本化;按 PDF 独立处置、证据复核与原子确认建单,不支持多订单 PDF 或跨 PDF 合并/拆分。字段和明细可按冻结 bbox 定位 PDF 原文(明细按 table/cell 反查),版本历史按需展开;确认后展示 `auto_progress` 真实结果/检查点并可直达任务进度工作台。单 PDF 重识别复用 WorkflowItem 真实状态展示已提交/版面解析/字段提取/草稿生成,完成后自动打开新版;“跳转当前版本”点击时强制刷新工作项,目标未就绪时明确提示。 |
|
||||
| **复核工作台布局重构(阶段 0–5)** | 已实现(待真机视觉签署) | 替换旧三栏:主编辑区 + 阻断摘要侧栏;PDF**默认右下角浮动证据面板**(八向 resize、记忆尺寸位置、展开/移侧;用户主动「固定为侧栏」才双栏),不挤占订单网格;Ctrl/Cmd+滚轮与适合宽度/页面;溢出拖拽平移;双击字段定位与证据联动高亮;异常字段 Alt+[/] 导航;真正按需加载;Chat/证据/pdfjs 异步分包;AI/版本历史/完整检查按需抽屉且审计失败阻断展示;确认与自动推进态解耦并可重试;同事务入队 `shipping_notice_run`;单一主滚动 + sticky 底栏。真机三档 viewport 清单见 layout-plan §11.1。权威方案:[review-workbench-layout-plan.md](features/shipping-notice/review-workbench-layout-plan.md)。 |
|
||||
| **复核工作台状态隔离(Case/证据/资格/自动化)** | 进行中(正式 OT 后分层已落地) | Case 切换请求代次 + 瞬态清理;正式 OT 后右侧主卡切自动处理、订单检查折叠、系统等待不冒充人工待办;`profile_match` 四态 + `field_completeness`;`completed_checks` 后端投影;`automation.phase` 区分建单前/后文案。契约:[review-workbench-state-isolation-contract.md](features/shipping-notice/review-workbench-state-isolation-contract.md)。 |
|
||||
| **OT 后行级自动履约(明细合并 + 匹配事实)** | P0+P1+P2+布局/动作分域已落地;flag 默认关 | 明细只读库存源;库存浮层仅 preparation/matching;关闭在更多操作;Case 兜底仅无行投影失败;15 阶等宽+布局清理。flag 保持 false。冻结:[post-ot-line-auto-fulfillment-freeze.md](features/shipping-notice/post-ot-line-auto-fulfillment-freeze.md)。 |
|
||||
| **双工作台架构 + Candidate Qualification(阶段 0–6)** | 阶段 0–6 达标(评审整改后) | **已完成**:双工作台边界;Candidate Qualification(追加式快照 + 审计);模板审批不再硬阻断自动建单;对话「本次处理中」轻量侧栏;复核返回对话;货代上传 RPA 可按 `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 接入自动链;Process Gate 对话内恢复;审计事件字典含 chat_* / qualification / upload_rpa。权威:[review-workbench-layout-plan.md](features/shipping-notice/review-workbench-layout-plan.md) §0。 |
|
||||
| **对话侧 Task 进度与「本次处理中」** | 阶段 2–5 已实现 | 侧栏以用户可见任务(OT)分组为主路径;`ShippingConversationProcessingCard` + processing API;`WF-...` 下沉;发送走统一提交无确认框。 |
|
||||
| **会话多任务聚合与统一提交(阶段 0–5)** | 整改中 | 契约冻结(§1.6.1);统一提交 + 独立 submission 幂等;同 PDF 指纹继承 OT(跨 Schema);投影按「当前有效最新 Run」;未查看 completed 仍可见;任务级取消/重试均走 Run API;状态四语言 + 更新时间。权威:technical.md §1.6.1。 |
|
||||
| **多 EML / 直接 PDF / PDF 优先全链路重构(阶段 0–7)** | 蓝图 §六 表层基本对齐;workflow/batches DROP 推迟 | `co4`–`co7`:接入层、Notice/履约、`order_tasks`/evidences/notice_lines/document_versions、`processing_runs/units/plans/route_decisions`。待:DROP batches/workflows、FE 去旧 Workflow。 |
|
||||
| **Candidate 统一自动建单资格** | 阶段 1 已实现 | 新增 `candidate_qualification_contract/service`、表 `shipping_order_candidate_qualifications`;三种解析来源统一门禁;模板批准仅 parser_trace;移除 LLM 天然阻断;STP 自动建单前持久化资格快照。 |
|
||||
| **后台顺序自动推进 + Process Gate 对话恢复** | 已实现 | 自动链:库存准备→匹配→库存 RPA→Excel;货代上传 RPA 须 `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 显式 true 且通过就绪校验。RPA 中投影 `upload_rpa_pending` / `is_waiting_manual_upload=false`。对话侧 ProcessGateRecoveryCard;技术重试上限 3。 |
|
||||
| **建单前统一恢复协调器(Gate/资格/auto_gate)** | 进行中(P0 缺陷已修,待正式验收) | `order_review_resume_service` + 行级履约 fail-closed(库存重校验、task 行不可 reopen、审计 before/after);复核侧栏置顶业务阻断,履约表格在库存模式;业务审计含白名单快照。权威:[process-gate-recovery-contract.md](features/shipping-notice/process-gate-recovery-contract.md)。 |
|
||||
| **双工作台审计闭环** | 已实现(阶段 6) | 事件字典冻结 chat_* / review_* / process_gate_* / qualification / workflow_node;对话恢复写 `chat_process_gate_*`;审计中心分组与 Candidate/Gate 筛选;普通账本脱敏 + 敏感快照独立鉴权;覆盖率举证见 AUDIT_COVERAGE_MATRIX。 |
|
||||
| **复核字段精确高亮(阶段 0–5)** | 已完成(盲测样本集另立) | 冻结 `shipping-field-highlight-v1`;原生唯一 glyph / OCR candidate / Cell 来源分级;证据 API 全量 `highlight_quality`;工作台 verified 实线 / candidate 虚线;坐标诊断与 list/focus/restore/version 审计齐全;`review_coordinate_corrected` 事件已冻结(人工改框写路径待模板标注扩展)。权威契约:[field-highlight-contract.md](features/shipping-notice/field-highlight-contract.md)。 |
|
||||
| **STP 直通 + 例外工作台** | 已实现(首期) | 可信 PDF 自动建 Task 并推进至「待人工上传」;例外进入人工复核/任务处理;Chat 仅上传与通知。**阶段 0–5 已落地**:字段契约、起行锚点、建单资格与候选、自动建单/复核台、跨候选库存匹配→Excel→待人工上传、统一 `ui_state.stp_facts` 与审计双写/时间线 i18n。**项次派生 Phase 0–4**:`line_no`=内部项次、`export_sequence`=导出行号、Schema 派生模拟、运行时派生审计、复核覆盖锁定与 `field_meta` 投影、冻结血缘。**库存源路由独立恢复(门禁恢复阶段 0)**:复核台可按最新已发布规则与库存源启停重算路由(不重识别 PDF);人工决定优先且不被静默覆盖;支持采用规则建议 / 保留人工结果;幂等键与审计前后快照齐全。首期不触发货代 RPA 上传、不改 Dify |
|
||||
| **全门禁级中断恢复(契约冻结)** | 已实现(P0–P4 代码与自动化;P5 外部条件待签署) | **RecoveryPlan → Attempt → Job → Worker/RPA → 幂等回调 → AutoProgress → Projection** 已收口;20 Gate 均有运行时实施状态,跨阶段恢复、精确失效、多源库存准备、组合指纹、未知上传状态和前端 `recovery_targets` 已覆盖。权威契约:[process-gate-recovery-contract.md](features/shipping-notice/process-gate-recovery-contract.md);验收:[process-gate-recovery-acceptance.md](features/shipping-notice/process-gate-recovery-acceptance.md);最终报告:[process-gate-recovery-final-compliance.md](features/shipping-notice/process-gate-recovery-final-compliance.md)。生产双 Worker、真实 RPA、Dify 手工核对、视觉/E2E 与人工签署仍为发布前条件;不引入 Temporal/Celery。 |
|
||||
| **错误可解释性(阶段 0–4)** | 完全达标 | 分层原因码冻结且主路径全量 EMITTED(仅预留 `inventory_uom_conversion_failed`);`AUDIT_COVERAGE_MATRIX` 统一覆盖率 100%;审计中心业务/技术分层且无强制横滚;库存源复核始终展示 `source_code`;四语言对齐。权威契约:[error-explainability-contract.md](features/shipping-notice/error-explainability-contract.md)。 |
|
||||
| **订单项次派生与血缘审计** | 已实现(Phase 0–4 + 评审纠偏) | 统一 `customer_po_line_no` / `line_no` / `export_sequence`;Schema 派生模拟支持历史 Extraction 样本;运行时派生含 `evidence_refs`;复核覆盖/恢复(`LINE_NO_OVERRIDDEN`/`LINE_NO_RESTORED`);货代统一审计新写入永久保留(`6a9c3e5f7b2d`) |
|
||||
| 模板发布与自动冻结资格分离(阶段 4) | 已实现 | Profile 的发布仅允许确定性解析;每个发布版本独立冻结人工确认资格,首版强制 `manual_confirmation` 且自动冻结关闭,盲测批准、旧版本资格或 checksum 变化均不能越过该门禁 |
|
||||
| Run 自动冻结门禁与执行 | 已实现 | Run 创建时冻结 `manual_confirmation` 初始策略;结果落库后按模板资格、已确认 Bill-to 客户、业务场景、技术失败、预算停止和待处理订单刷新 `auto_freeze_policy_json`。仅资格与全部门禁显式放行时,自动消费当前 Run 的 accepted Candidate 并冻结新建 Task;不触发库存、Excel 或上传履约副作用。 |
|
||||
| 人工复核与字段证据闭环(阶段 5) | 已实现 | 单头、订单行、冲突解决均要求乐观锁、原因和结构化 `document_cell`/`manual_input` 证据;跨订单或伪造证据在写值前拒绝,复核审计保存结构化证据且详情页展示页码、表格、单元格与原文 |
|
||||
| 原 PDF 双层重解析 | 已实现 | “重新识别此 PDF”仅为当前原始文件创建后继 Run;“重新解析本批次”逐 PDF 创建独立子 Run、局部成功替换,按完整 Run 谱系选择每个原文件的当前 Case;已确认/履约文件排除;不支持上传替代 PDF。 |
|
||||
| 多订单 Candidate 判重与自动建批 | 已实现 | Candidate 身份/内容双指纹;高置信 SKU+Qty 订单自动建 Task,低置信/冲突/修订保留待处理;部分消费 Intake 不丢剩余订单;缺 Reservation/Source Type/Hub Code 的 Task 停在自然对话补字段门禁 |
|
||||
| 库存 RPA 源 YAML 配置 | 已实现 | `backend/config/shipping_inventory_sources.yaml`,新增 Warehouse 只改 YAML |
|
||||
| 订单解析阶段库存源判定 | 已实现 | `parse_notice` 内 adjudicate 写线索;低置信度先 `parse_review`,解析通过后再 `inventory_source_review`;稳定态 `resolved`/`user_confirmed` |
|
||||
| 文件解析阶段问题清单 | 已实现 | 步骤 2 工作台/`ui_state.summary.issues` 一次列出解析复核、RSV、库存源门禁与 parse warnings |
|
||||
| 发货通知关键字段真值校验 | 已实现 | LLM 出候选、后端裁决;支持多模板 Reservation 别名,拒绝 32 位 hex/UUID;仅按 TSV 列关系与唯一 SKU/APN/MPN 证据纠错;`parse_validation` 留痕,blocking issue 在解析确认和库存匹配前双重阻断 |
|
||||
| 内部料号库存匹配 | 已实现 | 主匹配键为 `(part_number, reservation_id)`;库存 `Supplier Sku` 对应内部料号,`AWS Sku` 仅作为可选 `aws_part_number`,AWS-only 库存表不能形成有效主匹配行 |
|
||||
| 库存快照身份校验 | 已实现 | link 时校验 `source_code`/`site_id`/`warehouse_id` 与任务一致 |
|
||||
| 库存快照 TTL 复用 | 已实现 | `inventory_snapshot_store`,按需任务优先复用未过期快照 |
|
||||
| 库存 RPA 批量导出(DSV/Crane 一次登录) | 已实现 | `inventory_export_batch` trigger + worker + `/rpa/inventory-batch-ready` |
|
||||
| 库存每日定时导出排程 | 已实现 | `schedule_type=platform_job` + `platform_api_path=shipping-inventory-rpa`,cron 建议 `0 3 * * *` |
|
||||
| 库存源至外部系统仓库映射 | 已实现 | 维护精确与 Source 默认映射;当前仅后台维护和后端内部 Service,不开发 Tool API 或调拨逻辑 |
|
||||
| 建单防重复(第一阶段) | 已实现 | 批次 `create_idempotency_key`、任务 `source_content_hash`、同请求去重、幂等重放 |
|
||||
| 客户身份与业务编号规则 | 已文档化 | 内部 `SN-...` 与业务号分离;业务号固定为 `客户简码 + YYMMDD + 两位流水`,例如 `WYC26071501`,日期口径 `Asia/Shanghai` |
|
||||
| 客户受控合并 | 已实现 | 管理员预览历史保留与未来配置迁移后,输入源简码和原因归并至启用目标客户;历史业务/编号/审计不改写,识别证据和来源键迁移,源客户标记为 merged 并不可再用于新任务 |
|
||||
| 期初客户导入与对账 | 已实现 | 标准 Excel 模板、上传暂存、预检查重、冲突决策、单事务发布、来源键幂等重导和 CSV 对账 |
|
||||
| 客户影子识别 | 已实现 | Candidate 抽取后记录客户候选、证据和版本;Schema 普通升级造成字段 UUID 变化时,按冻结语义安全映射新版 Header 字段;支持人工真值标签与准确率报告,不绑定、不编号、不阻断现有货代流程 |
|
||||
| 客户人工确认与 Gate | 已实现 | `customer_review`;业务用户从标准客户主数据中确认,客户未稳定时阻断库存源、RPA、匹配、Excel 和上传 |
|
||||
| 受控自动客户识别 | 已实现 | 仅对 approved 且允许自动匹配的邮箱/非公共域名/模板指纹开放;唯一命中才自动确认,默认关闭;管理端可查询自动裁决、自动确认、历史回填和“原号作废 + 新号替代”纠错审计 |
|
||||
| 客户治理闭环 | 已实现 | 客户与识别证据关键变更记录快照时间线;简码、状态、自动匹配授权必须填写原因。自动确认在总开关外再受有效人工标注样本量(默认 20)与准确率(默认 98%)门禁约束,未达标保持 `customer_review`;客户主数据页展示时间线和降级原因 |
|
||||
| 字段资产治理与 Schema 契约解耦(阶段 0–5) | 已实现 | 全局标准**58** + 扩展资产库(Header/Line 可共享 `reservation_id`);**唯一**发货订单 Schema(`STANDARD_SHIPPING_NOTICE`)多版本采用/发布门禁;**自动建单总开关随 Schema 版本 definition 冻结**(草稿保存 + 发布生效,含审计);管理端双入口(字段资产库 / 订单 Schema);Run 冻结含 schema_code;表结构保留 `schema_code` 但不开放多族治理。见 [field-governance-plan.md](features/shipping-notice/field-governance-plan.md)。生产切换须停写→迁移→手动勾选建议项发布 V1。 |
|
||||
| 履约治理 UI 重构 | 待续 | 本轮从 Schema 页移出策略卡;库存/Excel/RPA/策略工作台另案 |
|
||||
| 客户识别证据源与订单字段彻底分域(G2/G3) | 待续 | 本轮仅 G1 边界:禁止 mail context 进入订单字段资产;身份 UI 不重做 |
|
||||
| 滚动履约领域契约(阶段 0) | 实施中 | 冻结 `SHIP_AVAILABLE_ROLLING`、预置核心字段与可配置扩展字段、Snapshot 正式真相、预约单全局注册、Artifact/Attempt 拆分、LLM 人工复核门禁;扩展字段是否进入库存/Excel/RPA 由已发布业务配置决定;Excel 命名由已发布模板规则优先、环境变量受控回退,最终规则在 Artifact 审计冻结。 |
|
||||
| 订单冻结就绪门禁(阶段 6) | 已完成 | 冻结前聚合校验已接受抽取、客户确认、字段冲突、最小履约字段、正数数量和版本;Task 行锁与 Snapshot 的 `task_id` 唯一约束保证重复确认只返回同一快照;来源清单冻结字段裁决、文档 hash、证据定位和人工复核历史。 |
|
||||
| 重发版本替代与货代撤销(阶段 7) | 已完成 | 身份固定为客户+PO、内容变化单独版本化;未上传旧版立即作废,已上传旧版必须登记撤销回执后才能解除新版本履约阻断;新旧任务关系和撤销审计永久保留。 |
|
||||
| 库存、Excel 与上传入口门禁(阶段 8) | 已完成 | 履约入口及其底层服务均要求活动的冻结订单,替代/作废/撤销待处理版本无法匹配或导出;人工上传强制货代回执号、私有回执文件和服务端当前用户。 |
|
||||
| 安全 Chatflow(阶段 9) | 已完成 | 仅允许一个启用货代 Chatflow;Dify OpenAPI 只保留短效能力令牌保护的任务/批次状态查询,所有写操作改由 HXOPS 确认卡与服务端状态机执行。 |
|
||||
| 产品原型 | 已文档化 | 见[docs/features/shipping-notice/shipping_notice_agent_prototype.md](features/shipping-notice/shipping_notice_agent_prototype.md) |
|
||||
| 功能项 | 状态 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| **统一 ShippingProcessingProjection(15 阶段)+ 正式任务编辑** | 阶段 0–6 已验收 | 库存源硬门禁;复核台原地 formal_task;Schema `task_edit_policy`/`change_effect`;正式编辑审计矩阵;Dify NONE。验收:`unified-progress-formal-edit-stage0~6` + `final-acceptance` + `dify-config`。 |
|
||||
| 订单生命周期工作台状态展示统一(v2) | 已实现 | 五阶段下方横幅移除;右栏「当前任务」卡为唯一状态宿主:状态行=user_status 短标签(Run 级 lifecycle_status 受控兑底映射)+ 状态块内嵌动态说明(`RUN_STATUS_FALLBACK_MAP`/`REDUNDANT_DETAIL_REASON_CODES` 双常量裁决,诊断信息不隐藏);无 Case 瞬态保留单行白名单轻提示;聊天页/任务中心同源接入零视觉变化。设计:[2026-08-31 状态展示统一设计](superpowers/specs/2026-08-31-shipping-review-status-display-unification-design.md) |
|
||||
| 发货通知技术手册 | 已文档化 | 见 [docs/features/shipping-notice/technical.md](features/shipping-notice/technical.md) |
|
||||
| 发货通知业务说明 | 已文档化 | 见 [docs/features/shipping-notice/business.md](features/shipping-notice/business.md) |
|
||||
| 业务去重与任务版本(Phase 3) | 已实现 | Intake 业务指纹/重复决策、修订版本链、强制新建权限与审计;见技术手册第三节摘要 |
|
||||
| EML 附件提取(阶段一) | 已实现 | 结构化解析主题/发件人/正文与真实附件;`message/rfc822`/附件型 multipart 独立登记;完整性门禁与容器计费;见技术手册「EML 附件提取」 |
|
||||
| EML/附件上传预处理 | 已实现 | 上传后自动创建 Intake 快览:只解析邮件正文、白名单 HTML 表格快照和附件目录;上传阶段不抽取附件全文、不创建附件 FileAsset/Document、不生成 Candidate、不判订单重复;解析失败、超时、取消保持幂等 |
|
||||
| 上传与发送门禁状态一致性 | 已实现 | Intake 状态接口返回 `preview_status / ready_for_extraction / attachment_directory_complete` 等快览事实;聊天附件快览成功后显示“已就绪/已发现 N 个附件”并允许发送,不再因上传阶段版面任务阻塞;真正的订单识别进度在点击发送后单独展示 |
|
||||
| 版面解析并发与耗时诊断 | 已实现 | 独立 `hxops-shipping-worker` 默认双进程并行领取同批版面 Job;PDFium 先轻量预读字符但不裁决表格,MinerU 始终作为 PDF 表格结构首选 Provider;仅 MinerU 空表/失败时允许严格 PDFium 回退。Job `result` 平级保存脱敏 `timings`+`counts`(含 OCR/OpenCV/对齐细分与 `ocr_engine_warm`),worker 日志同步输出;诊断字段不进 layout snapshot,不记录原文/HTML/OCR 原始响应(PR-0)。PR-1:`SHIPPING_NOTICE_LAYOUT_OCR_PAGE_CACHE_ENABLED` 控制同 Job 整页 OCR 复用;PR-2:`SHIPPING_NOTICE_LAYOUT_NATIVE_PAGE_REUSE_ENABLED` 字符预读复用+按需补图,OpenCV geometry Job 内缓存;PR-3:`SHIPPING_NOTICE_LAYOUT_OCR_CROP_ENABLED` 表格裁剪 OCR(prod 默认关) |
|
||||
| 对话输入框多附件统一提交 | 已实现 | 用户可分多次选择 EML/PDF;当前输入框内全部已就绪 Intake 在一次发送中冻结为同一个订单抽取 Run。`uploadBatchId` 仅用于单次上传幂等与状态关联,不再截断发送范围 |
|
||||
| 批次进度中心混合状态 EML 展示 | 已实现 | 状态以 PDF Unit 为准,聊天摘要与批次进度中心均按“状态 → EML → PDF”展示;同一 EML 可在多个状态区出现,但每张卡仅显示本区 PDF,并标注本组/总附件数;所有状态分组标题统一显示本组文件数;未物化附件以工作项标识去重,Excel 诊断附件进入只读“已忽略”分区,不混入处理中或已完成;聊天摘要与批次进度中心均默认折叠已忽略分区,展开后保留 Excel 明细;批次中心顶栏单列已忽略数,与提交文件总数对账,完成率和“已处理 N/M”仅按订单文件计算;其余订单 PDF 全部完成时,对话摘要显示完成且不再展示阶段 |
|
||||
| 无框订单明细表原生 PDF 回退 | 已实现 | 仅当 MinerU 未输出表格、PDF 原生文字坐标完整且同页命中多个通用明细表头时,从表头到合计行生成待配置候选表;正常 MinerU 表格路径不变,解析器修订 `v4` 防止复用旧零表格缓存 |
|
||||
| 点击发送完整订单抽取 | 已实现(终态分阶段) | Run 冻结文档、Schema、模板 Profile、路由/评分/门禁与解析器版本;Worker 执行异型模板或通用确定性解析;完整性门禁与紧急停止控制自动冻结;Dify 仅提供复核最小证据建议且不得自动冻结;上线清单见 order-extraction-go-live-checklist.md |
|
||||
| 相同附件跨批次 Workflow 复用 | 已实现 | 同会话完整附件 `content_hash` 集合与 Schema 版本相同时,复用活跃或未关闭 Run/Workflow Item;新上传批次、Intake/Document ID 或文件名不再导致重复 Workflow |
|
||||
| 订单识别生命周期反馈 | 已实现(2026-08-23) | Run 状态卡与复核工作台复用 Run/Unit/ProgressEvent 的轻量 `lifecycle_progress`:解析/重解析/门禁通过后的自动推进期间,五阶段常驻可见,并显示当前阶段内步骤、已完成步骤及稳定失败/排队/卡住原因;无 Case 时不再只剩黄色横幅。已有正式任务仍以 Process Gate 投影为准;同步人工客户选择不伪造自动处理中;不新增 SSE、进度表或第二状态机。 |
|
||||
| 处理进度细化与全链路审计 | 已实现 | 阶段 0–5 + 正式评审整改:排队/处理中分列、文档级健康提醒与最后活动、管理员取消任意 Run(代取消必填原因)、审计完整筛选(含 conversation/session_item/review_case/owner)、敏感访问审计、取消 operation_id 串联、进度事件真实状态、库存/RPA/导出双写统一审计。Run 级 `handling_items`/`primary_notice` 拆分待补信息/冲突/自动冻结受阻/PDF 复核/技术失败/预算停扩,聊天卡与右侧「本次处理」按原因展示并跳转。灰度开关 `PROGRESS_UI_V3`/`ORDER_EXTRACTION_CANCEL`/`AUDIT_EXPORT`;审计保留 `SHIPPING_NOTICE_AUDIT_RETENTION_DAYS=1095`。Dify 无需改画布 |
|
||||
| 会话 PDF 工作项(阶段 0–4) | 已退役 | 已由 Workflow 台账替换;旧验收文档已删除 |
|
||||
| Workflow 阶段 0–2 底座与投影 | 已实现 | 删除 session work items;Workflow/Item/Version/Event;进度投影与会话轮询;见 `workflow-stage0-acceptance.md` 与 technical.md |
|
||||
| Workflow 阶段 3 确认后自动进度 | 已实现 | 五门禁(批准模板/字段完整/证据/冲突重复/质量)失败仅 Review Case;确认返回 `shipping_notice_no`/`order_task_no` 并推进履约;复核页 `ReviewWorkflowProgressPanel` 读统一 OT 投影;建单后取消 Task `pending_void`+Excel 只读;移除工作台 upload-inventory/mark-manual-uploaded/retry-upload 写入口 |
|
||||
| Workflow 阶段 4 任务中心与审计闭环 | 已实现 | 任务中心进行中 2s/8s 自动刷新;时间线合并 Workflow Event;审计关联链/敏感读权限/哈希日检;删除复核监管台 |
|
||||
| EML 正文补充表合并(阶段 2) | 已实现 | 正文 HTML 表解析为带 DOM 单元格证据的 PO 级补充事实,不创建独立订单或执行 Unit;按 `PO + MPN`、受限 PO 降级补 Reservation/Allocation/库存来源提示,支持 `External reservation ID` 等冻结 Schema 显式别名;每个 Run 从原始 HTML 重建,避免旧的部分解析结果遮蔽新规则;PDF 数量保持权威,歧义统一进入人工复核 |
|
||||
| PDF 模板 PO 拆分与严格拒识(阶段 3) | 已实现 | 已批准模板中每条明细均有唯一 PO 证据时,单 PDF 自动拆为多个独立订单;表级多 PO 未能归属明细、模板歧义、漂移和证据不足统一转人工复核,Route Decision 分别审计四类表计数 |
|
||||
| 订单模板版本中心(阶段 0-7) | 已实现 | 订单文档模板按 `profile_code` 聚合版本族;已落地独立版本详情、历史只读样本画布、服务端语义差异、审计记录页签、实际使用页签,以及阶段 7 的 blind test 隔离与发布治理;只读画布完整展示必需锚点及各受控标签区域的冻结识别值,必需锚点可对照配置值、识别值和匹配状态;标注取字、运行匹配与版本诊断统一按视觉行恢复字符阅读顺序;标注 Reservation ID 专区的模板跨页以 `Vendor Comments` 至首次 `Terms and Condition(s)` 作为语义边界读取预约单号,未标注模板保持原解析路径 |
|
||||
| **订单模板版面签名 Matcher** | 代码已落地(待真实样本灰度) | 版面签名存 ValidationRun;Profile 轻量引用;Matcher 三态证据 + Top-N 解析验证;表头签名直接消费既有 `header_layout.region`,签名生成与运行时统一视觉词组和坐标口径;跨模板发布门禁与发布检查页;重识别亲和性校验签名;`SHIPPING_NOTICE_PROFILE_LAYOUT_SIGNATURE_REQUIRED` 控制全量切换。说明:[order-profile-layout-signature.md](features/shipping-notice/order-profile-layout-signature.md) |
|
||||
| **XFA 数据路径 Profile(统一回退)** | 代码收口(2026-08-18) | datasets + 拆分规则为首选;失败进入普通 PDF 共用 PDFium/Widget/OCR 证据链,保留 `fallback_from`、原因码与 `value_source`,回退候选固定 Review、禁止 STP;Dify 主链:**NONE**。 |
|
||||
| **XFA 统一视觉标注 + 字段拆分** | 统一入口已收口 | 普通 PDF/XFA 共用 Editor、`/pdf-automark` Job、保存、验证和发布 DTO;`value_binding` + `visual_binding`、RE2、统一 CQ/STP;XFA 仅在首选 datasets 取值与拆分规则上保留适配器差异。 |
|
||||
| **XFA 可见值回读补偿** | 已实现(2026-08-25) | 编辑器在原生坐标、服务端 OCR 与唯一 Widget 无值后,OCR 同一 PDF.js XFA 画布的受控裁剪图(`xfa_rendered_ocr`);仍无值保留值框并提示诊断,可继续绑定 datasets。裁剪图不持久化,datasets 仍为唯一正式值源。 |
|
||||
| **PDF 订单解析证据链与冻结 Parse Plan** | 已验收(2026-08-23) | 原 PDF 为不可变事实,`matching_features.v1` 仅用于稳定版式匹配;坐标统一经按需恢复入口取得。普通 PDF 以页级 PDFium glyph 为取值事实,MinerU 仅作结构候选;无起行锚点、坐标缺失、漂移、歧义、引擎冲突和 XFA fallback 均 fail-closed 至 Review,禁止把表头伪装成明细。无真实标签的固定订单字段仅在唯一匹配模板的正式运行或盲测回放中,以原生 PDF 坐标确认;其余场景仍进入 Review。Schema 是唯一业务契约;Dify 主链 NONE。见 `technical.md`。 |
|
||||
| **旧 XFA 合成预览/OCR 专用入口** | 已废弃 | 浏览器不得调用 `/xfa/automark`;内部 XFA 多源执行器由统一 `/pdf-automark` 调用,原生 PDF 页是统一画布。 |
|
||||
| **XFA 字段拆分映射(历史)** | 已被统一方案接管 | 早期 `stages[]` 流水线与独立映射页能力将在统一方案阶段 1/4 对齐并收口;对照文档:[xfa-field-split-mapping.md](features/shipping-notice/xfa-field-split-mapping.md)。 |
|
||||
| 订单模板录入 UX 重构(阶段 0-7) | 已完成 | 已完成 Draft Revision、Lease、向导、独立草稿编辑器自动保存、不可变验证运行与两步发布报告;样本上传仅负责资产保存和 PDF/EML Document 物化,版面解析作为后台预热且不阻断上传。自动标注另经统一 Draft 样本就绪门禁:当前 ready Layout、唯一视觉主表、内容/hash/checksum/parser 身份均可验证时才幂等冻结样本证据并入队;保存、轮询、入队和 Worker 复验使用同一契约,失败展示可操作原因且不影响其他 Profile。盲测复核区分准备中、兼容性诊断和正式复核:仅 ready Layout 的真实 table_id 可确认,确认时冻结 LayoutVersion/checksum/parser 身份,执行不回读最新布局;临时 PDF 恢复仅作诊断。同模板族历史 annotation/training/新旧 blind test 文档可重新复核复用,当前版本建模样本仍严格排除。编辑器在可见状态自动续租。Dify 无需配置变更。 |
|
||||
| 订单人工复核工作台(阶段 0-7) | 已实现 | 每个 PDF Unit 一个 Review Case,机器 Candidate/Extraction 不可变、人工 Draft 独立版本化;按 PDF 独立处置、证据复核与原子确认建单,不支持多订单 PDF 或跨 PDF 合并/拆分。字段和明细可按冻结 bbox 定位 PDF 原文(明细按 table/cell 反查),版本历史按需展开;确认后展示 `auto_progress` 真实结果/检查点并可直达任务进度工作台。单 PDF 重识别复用 WorkflowItem 真实状态展示已提交/版面解析/字段提取/草稿生成,完成后自动打开新版;“跳转当前版本”点击时强制刷新工作项,目标未就绪时明确提示。 |
|
||||
| **复核工作台布局重构(阶段 0–5)** | 已实现(待真机视觉签署) | 替换旧三栏:主编辑区 + 阻断摘要侧栏;PDF **默认右下角浮动证据面板**(八向 resize、记忆尺寸位置、展开/移侧;用户主动「固定为侧栏」才双栏),不挤占订单网格;Ctrl/Cmd+滚轮与适合宽度/页面;溢出拖拽平移;双击字段定位与证据联动高亮;异常字段 Alt+[/] 导航;真正按需加载;Chat/证据/pdfjs 异步分包;AI/版本历史/完整检查按需抽屉且审计失败阻断展示;确认与自动推进态解耦并可重试;同事务入队 `shipping_notice_run`;单一主滚动 + sticky 底栏。真机三档 viewport 清单见 layout-plan §11.1。权威方案:[review-workbench-layout-plan.md](features/shipping-notice/review-workbench-layout-plan.md)。 |
|
||||
| **复核工作台状态隔离(Case/证据/资格/自动化)** | 进行中(正式 OT 后分层已落地) | Case 切换请求代次 + 瞬态清理;正式 OT 后右侧主卡切自动处理、订单检查折叠、系统等待不冒充人工待办;`profile_match` 四态 + `field_completeness`;`completed_checks` 后端投影;`automation.phase` 区分建单前/后文案。契约:[review-workbench-state-isolation-contract.md](features/shipping-notice/review-workbench-state-isolation-contract.md)。 |
|
||||
| **OT 后行级自动履约(明细合并 + 匹配事实)** | 已实现 | 明细只读库存源;库存浮层仅 preparation/matching;短缺单条放行后异步创建独立 Notice 并生成其唯一 Excel;多条开放明细仍必须人工勾选后合并创建,暂不支持批次放行。冻结:[post-ot-line-auto-fulfillment-freeze.md](features/shipping-notice/post-ot-line-auto-fulfillment-freeze.md)。 |
|
||||
| **双工作台架构 + Candidate Qualification(阶段 0–6)** | 阶段 0–6 达标(评审整改后) | **已完成**:双工作台边界;Candidate Qualification(追加式快照 + 审计);模板审批不再硬阻断自动建单;对话「本次处理中」轻量侧栏;复核返回对话;货代上传 RPA 可按 `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 接入自动链;Process Gate 对话内恢复;审计事件字典含 chat_* / qualification / upload_rpa。权威:[review-workbench-layout-plan.md](features/shipping-notice/review-workbench-layout-plan.md) §0。 |
|
||||
| **对话侧 Task 进度与「本次处理中」** | 阶段 2–5 已实现 | 侧栏以用户可见任务(OT)分组为主路径;`ShippingConversationProcessingCard` + processing API;`WF-...` 下沉;发送走统一提交无确认框。 |
|
||||
| **会话多任务聚合与统一提交(阶段 0–5)** | 整改中 | 契约冻结(§1.6.1);统一提交 + 独立 submission 幂等;同 PDF 指纹继承 OT(跨 Schema);投影按「当前有效最新 Run」;未查看 completed 仍可见;任务级取消/重试均走 Run API;状态四语言 + 更新时间。权威:technical.md §1.6.1。 |
|
||||
| **多 EML / 直接 PDF / PDF 优先全链路重构(阶段 0–7)** | 蓝图 §六 表层基本对齐;workflow/batches DROP 推迟 | `co4`–`co7`:接入层、Notice/履约、`order_tasks`/evidences/notice_lines/document_versions、`processing_runs/units/plans/route_decisions`。待:DROP batches/workflows、FE 去旧 Workflow。 |
|
||||
| **Candidate 统一自动建单资格** | 阶段 1 已实现 | 新增 `candidate_qualification_contract/service`、表 `shipping_order_candidate_qualifications`;三种解析来源统一门禁;模板批准仅 parser_trace;移除 LLM 天然阻断;STP 自动建单前持久化资格快照。 |
|
||||
| **邮件补充冲突可解释性与历史重评估** | 已实现(2026-08-21) | 新 Finding 展示 PDF/邮件双方原值、规范化值与证据;金额语义比较、精确 `PO + MPN` 行关联;管理员可按 Candidate/Run 或受确认的全量操作重评估历史旧冲突,证据不足显示重新识别 PDF 恢复动作并保留阻断/审计。 |
|
||||
| **复核保存校验自动入队反馈** | 已实现(2026-08-21) | Draft validate 保留后端 `resume_outcome`;`auto_create_enqueued`、已排队或运行中统一显示已入队,实际后续节点仅消费后端处理投影。 |
|
||||
| **后台顺序自动推进 + Process Gate 对话恢复** | 已实现 | 自动链:库存准备→匹配→库存 RPA→Excel;货代上传 RPA 须 `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 显式 true 且通过就绪校验。RPA 中投影 `upload_rpa_pending` / `is_waiting_manual_upload=false`。对话侧 ProcessGateRecoveryCard;技术重试上限 3。 |
|
||||
| **建单前统一恢复协调器(Gate/资格/auto_gate)** | 进行中(P0 缺陷已修,待正式验收) | `order_review_resume_service` + 行级履约 fail-closed(库存重校验、task 行不可 reopen、审计 before/after);复核侧栏置顶业务阻断,履约表格在库存模式;业务审计含白名单快照。权威:[process-gate-recovery-contract.md](features/shipping-notice/process-gate-recovery-contract.md)。 |
|
||||
| **双工作台审计闭环** | 已实现(阶段 6) | 事件字典冻结 chat_* / review_* / process_gate_* / qualification / workflow_node;对话恢复写 `chat_process_gate_*`;审计中心分组与 Candidate/Gate 筛选;普通账本脱敏 + 敏感快照独立鉴权;覆盖率举证见 AUDIT_COVERAGE_MATRIX。 |
|
||||
| **复核字段精确高亮(阶段 0–5)** | 已完成(盲测样本集另立) | 冻结 `shipping-field-highlight-v1`;原生唯一 glyph / OCR candidate / Cell 来源分级;证据 API 全量 `highlight_quality`;工作台 verified 实线 / candidate 虚线;坐标诊断与 list/focus/restore/version 审计齐全;`review_coordinate_corrected` 事件已冻结(人工改框写路径待模板标注扩展)。权威契约:[field-highlight-contract.md](features/shipping-notice/field-highlight-contract.md)。 |
|
||||
| **STP 直通 + 例外工作台** | 已实现(首期) | 可信 PDF 自动建 OT 并推进至「待人工上传」;例外进入人工复核/任务处理;Chat 仅上传与通知。阶段 0–5 已落地:字段契约、起行锚点、建单资格与候选、自动建单/复核台、跨候选库存匹配→Notice/NoticeLine→Excel→待人工上传、统一 `ui_state.stp_facts` 与审计双写/时间线 i18n。订单项次由各单据写路径按顺序生成且不可编辑;库存准备失败停留在通知准备阶段。|
|
||||
| **全门禁级中断恢复(契约冻结)** | 已实现(P0–P4 代码与自动化;P5 外部条件待签署) | **RecoveryPlan → Attempt → Job → Worker/RPA → 幂等回调 → AutoProgress → Projection** 已收口;20 Gate 均有运行时实施状态,跨阶段恢复、精确失效、多源库存准备、组合指纹、未知上传状态和前端 `recovery_targets` 已覆盖。权威契约:[process-gate-recovery-contract.md](features/shipping-notice/process-gate-recovery-contract.md);验收:[process-gate-recovery-acceptance.md](features/shipping-notice/process-gate-recovery-acceptance.md);最终报告:[process-gate-recovery-final-compliance.md](features/shipping-notice/process-gate-recovery-final-compliance.md)。生产双 Worker、真实 RPA、Dify 手工核对、视觉/E2E 与人工签署仍为发布前条件;不引入 Temporal/Celery。 |
|
||||
| **错误可解释性(阶段 0–4)** | 完全达标 | 分层原因码冻结且主路径全量 EMITTED(仅预留 `inventory_uom_conversion_failed`);`AUDIT_COVERAGE_MATRIX` 统一覆盖率 100%;审计中心业务/技术分层且无强制横滚;库存源复核始终展示 `source_code`;四语言对齐。权威契约:[error-explainability-contract.md](features/shipping-notice/error-explainability-contract.md)。 |
|
||||
| **订单项次与字段血缘审计** | 已实现(硬切换) | `customer_po_line_no` 作为原始客户事实保留;订单解析行、冻结档行、发货通知行各自在所属单据内从 1 编号;不提供 Schema 派生、项次覆盖或恢复。|
|
||||
| 模板发布与自动冻结资格分离(阶段 4) | 已实现 | Profile 的发布仅允许确定性解析;每个发布版本独立冻结人工确认资格,首版强制 `manual_confirmation` 且自动冻结关闭,盲测批准、旧版本资格或 checksum 变化均不能越过该门禁 |
|
||||
| Run 自动冻结门禁与执行 | 已实现 | Run 创建时冻结 `manual_confirmation` 初始策略;结果落库后按模板资格、已确认 Bill-to 客户、业务场景、技术失败、预算停止和待处理订单刷新 `auto_freeze_policy_json`。仅资格与全部门禁显式放行时,自动消费当前 Run 的 accepted Candidate 并冻结新建 Task;不触发库存、Excel 或上传履约副作用。 |
|
||||
| 人工复核与字段证据闭环(阶段 5) | 已实现 | 单头、订单行、冲突解决均要求乐观锁、原因和结构化 `document_cell`/`manual_input` 证据;跨订单或伪造证据在写值前拒绝,复核审计保存结构化证据且详情页展示页码、表格、单元格与原文 |
|
||||
| 原 PDF 双层重解析 | 已实现 | “重新识别此 PDF”仅为当前原始文件创建后继 Run;“重新解析本批次”逐 PDF 创建独立子 Run、局部成功替换,按完整 Run 谱系选择每个原文件的当前 Case;已确认/履约文件排除;不支持上传替代 PDF。 |
|
||||
| 多订单 Candidate 判重与自动建批 | 已实现 | Candidate 身份/内容双指纹;高置信 SKU+Qty 订单自动建 Task,低置信/冲突/修订保留待处理;部分消费 Intake 不丢剩余订单;缺 Reservation/Source Type/Hub Code 的 Task 停在自然对话补字段门禁 |
|
||||
| 库存 RPA 源 YAML 配置 | 已实现 | `backend/config/shipping_inventory_sources.yaml`,新增 Warehouse 只改 YAML |
|
||||
| 订单解析阶段库存源判定 | 已实现 | `parse_notice` 内 adjudicate 写线索;低置信度先 `parse_review`,解析通过后再 `inventory_source_review`;稳定态 `resolved`/`user_confirmed` |
|
||||
| 文件解析阶段问题清单 | 已实现 | 步骤 2 工作台/`ui_state.summary.issues` 一次列出解析复核、RSV、库存源门禁与 parse warnings |
|
||||
| 发货通知关键字段真值校验 | 已实现 | LLM 出候选、后端裁决;支持多模板 Reservation 别名,拒绝 32 位 hex/UUID;仅按 TSV 列关系与唯一 SKU/APN/MPN 证据纠错;`parse_validation` 留痕,blocking issue 在解析确认和库存匹配前双重阻断 |
|
||||
| 内部料号库存匹配 | 已实现 | 主匹配键为 `(part_number, reservation_id)`;库存 `Supplier Sku` 对应内部料号,`AWS Sku` 仅作为可选 `aws_part_number`,AWS-only 库存表不能形成有效主匹配行 |
|
||||
| 库存快照身份校验 | 已实现 | link 时校验 `source_code`/`site_id`/`warehouse_id` 与任务一致 |
|
||||
| 库存快照 TTL 复用 | 已实现 | `inventory_snapshot_store`,按需任务优先复用未过期快照 |
|
||||
| 库存 RPA 批量导出(DSV/Crane 一次登录) | 已实现 | `inventory_export_batch` trigger + worker + `/rpa/inventory-batch-ready`;回调以 `ShippingOrderTask` 为唯一任务模型,收件与业务处理分离,事务失败必须收口为失败;库存等待使用单一 Gate Attempt 与 30→60→120→240→300 秒退避 Job,不为每次轮询新增 Attempt。 |
|
||||
| 库存每日定时导出排程 | 已实现 | `schedule_type=platform_job` + `platform_api_path=shipping-inventory-rpa`,cron 建议 `0 3 * * *` |
|
||||
| 库存源至外部系统仓库映射 | 已实现 | 维护精确与 Source 默认映射;当前仅后台维护和后端内部 Service,不开发 Tool API 或调拨逻辑 |
|
||||
| 建单防重复(第一阶段) | 已实现 | 批次 `create_idempotency_key`、任务 `source_content_hash`、同请求去重、幂等重放 |
|
||||
| 客户身份与业务编号规则 | 已文档化 | 内部 `SN-...` 与业务号分离;业务号固定为 `客户简码 + YYMMDD + 两位流水`,例如 `WYC26071501`,日期口径 `Asia/Shanghai` |
|
||||
| 客户受控合并 | 已实现 | 管理员预览历史保留与未来配置迁移后,输入源简码和原因归并至启用目标客户;历史业务/编号/审计不改写,识别证据和来源键迁移,源客户标记为 merged 并不可再用于新任务 |
|
||||
| 期初客户导入与对账 | 已实现 | 标准 Excel 模板、上传暂存、预检查重、冲突决策、单事务发布、来源键幂等重导和 CSV 对账 |
|
||||
| 客户影子识别 | 已实现 | Candidate 抽取后记录客户候选、证据和版本;Schema 普通升级造成字段 UUID 变化时,按冻结语义安全映射新版 Header 字段;支持人工真值标签与准确率报告,不绑定、不编号、不阻断现有货代流程 |
|
||||
| 客户人工确认与 Gate | 已实现 | `customer_review`;业务用户从标准客户主数据中确认,客户未稳定时阻断库存源、RPA、匹配、Excel 和上传 |
|
||||
| 受控自动客户识别 | 已实现 | 仅对 approved 且允许自动匹配的邮箱/非公共域名/模板指纹开放;唯一命中才自动确认,默认关闭;管理端可查询自动裁决、自动确认、历史回填和“原号作废 + 新号替代”纠错审计 |
|
||||
| 客户治理闭环 | 已实现 | 客户与识别证据关键变更记录快照时间线;简码、状态、自动匹配授权必须填写原因。自动确认在总开关外再受有效人工标注样本量(默认 20)与准确率(默认 98%)门禁约束,未达标保持 `customer_review`;客户主数据页展示时间线和降级原因 |
|
||||
| 字段资产治理与 Schema 契约解耦(阶段 0–5) | 已实现 | 全局标准 **58** + 扩展资产库(Header/Line 可共享 `reservation_id`);**唯一**发货订单 Schema(`STANDARD_SHIPPING_NOTICE`)多版本采用/发布门禁;**自动建单总开关随 Schema 版本 definition 冻结**(草稿保存 + 发布生效,含审计);管理端双入口(字段资产库 / 订单 Schema);Run 冻结含 schema_code;表结构保留 `schema_code` 但不开放多族治理。见 [field-governance-plan.md](features/shipping-notice/field-governance-plan.md)。生产切换须停写→迁移→手动勾选建议项发布 V1。 |
|
||||
| 履约治理 UI 重构 | 待续 | 本轮从 Schema 页移出策略卡;库存/Excel/RPA/策略工作台另案 |
|
||||
| 客户识别证据源与订单字段彻底分域(G2/G3) | 待续 | 本轮仅 G1 边界:禁止 mail context 进入订单字段资产;身份 UI 不重做 |
|
||||
| 滚动履约领域契约(阶段 0) | 实施中 | 冻结 `SHIP_AVAILABLE_ROLLING`、预置核心字段与可配置扩展字段、Snapshot 正式真相、预约单全局注册、独立 Shipment 通知号、Artifact/Attempt 拆分、LLM 人工复核门禁;全项满足自动生成一张通知,部分满足停人工多选,Excel 编号与通知号一致;扩展字段是否进入库存/Excel/RPA 由已发布业务配置决定。 |
|
||||
| 订单冻结就绪门禁(阶段 6) | 已完成 | 冻结前聚合校验已接受抽取、客户确认、字段冲突、最小履约字段、正数数量和版本;Task 行锁与 Snapshot 的 `task_id` 唯一约束保证重复确认只返回同一快照;来源清单冻结字段裁决、文档 hash、证据定位和人工复核历史。 |
|
||||
| 重发版本替代与货代撤销(阶段 7) | 已完成 | 身份固定为客户+PO、内容变化单独版本化;未上传旧版立即作废,已上传旧版须由受权人员登记外部撤销已确认后才能解除新版本履约阻断;新旧任务关系和撤销审计永久保留。 |
|
||||
| 库存、Excel 与上传入口门禁(阶段 8) | 已完成 | 履约入口及其底层服务均要求活动的冻结订单,替代/作废/撤销待处理版本无法匹配或导出;人工上传仅按业务单号确认,服务端从当前用户会话取得操作人并创建 Attempt 审计。 |
|
||||
| 安全 Chatflow(阶段 9) | 已完成 | 仅允许一个启用货代 Chatflow;Dify OpenAPI 只保留短效能力令牌保护的任务/批次状态查询,所有写操作改由 HXOPS 确认卡与服务端状态机执行。 |
|
||||
| 产品原型 | 已文档化 | 见 [docs/features/shipping-notice/shipping_notice_agent_prototype.md](features/shipping-notice/shipping_notice_agent_prototype.md) |
|
||||
| **多候选库存源自动批次探测(一期)** | 已实现 | `ensure_inventory` STP 多候选分支:缺文件不再隐式阻断为 `needs_human`,改为自动单批次 RPA 探测(仅缺失源,已有 ready 快照复用)并返回 `running`;逐源 Attempt/超时/重试保留。设计:[2026-08-29-shipping-inventory-source-selection-design.md](superpowers/specs/2026-08-29-shipping-inventory-source-selection-design.md) §2。 |
|
||||
| **库存匹配数据自证 + 行级歧义兜底(一期)** | 已实现 | 全部候选源快照按行打 `__source_code` 标签匹配,按行反写源/可用量/缺口;同一行命中多源 → 行 `multi_file_conflict` 阻断 + `candidate_hit_source_codes`(禁止静默选源)。设计 §2.3。 |
|
||||
| **行级人工选源动作 select_line_inventory_source(一期)** | 已实现 | Gate 业务动作(属 `inventory_matching`):校验行冲突、源 ∈ 候选、源启用、通知未生成 Excel(否则 `SHIPPING.LINE_SOURCE_LOCKED`);写候选行覆写 + 仅该行重匹配 + 审计 `review_line_source_selected`。 |
|
||||
| **通知准备行源下拉与锁定渲染(一期)** | 已实现 | `ui_state.preparation` 下发 `source_locked` / `lines[].source_ambiguous` / `source_candidates`;前端歧义行渲染库存源下拉 + 首选高亮 + 确认,`source_locked` 行只读徽标;阶段自动跳转一次性 toast + 清理 `reparse` 死守卫;四语言文案。 |
|
||||
| **波次库存源按自身行重路由(D8)** | 已实现 | `post_ot_fulfillment_wave_service` 创建波次通知不再继承首通知任务级源字段(`inventory_source_*`/`routing_fingerprint`/`snapshot_id`),仅继承订单级路由上下文(目的地/仓提示);新增 `inventory_candidate_freeze_service.freeze_wave_notice_routing` 按波次自身行评估路由并冻结候选集,随后走同一套自动探测/匹配/反写。测试:`test_shipping_wave_rerouting.py`。 |
|
||||
| **确认后订单编辑窗谓词(二期 T10)** | 已实现 | `order_edit_window_service.editable_scope`(header=订单任一通知无 Excel 且无活动 Attempt;行=所属通知无 Excel 且无活动 Attempt,未入波次行不受首单 Excel 限制)+ `order_has_active_attempt`;`ui_state` 下发 `edit_window`;测试通过。设计 §3.1。 |
|
||||
| **Excel 前保存守卫 + 失效分类重跑(二期 T11/T12)** | 已实现 | 正式字段编辑路径(`task_workflow.update_notice_*`)新增活动 Attempt 守卫(`SHIPPING.EDIT_WINDOW_SYSTEM_BUSY`);失效重跑沿用 Schema `change_effect`:路由字段→`rerun_inventory_source_resolution`、行字段→`rerun_inventory_matching`、导出→`regenerate_excel`、需重解析→`require_revision`;审计含 `applied_effects` 失效动作链。设计 §3.2/§3.3。 |
|
||||
| **编辑窗前端渲染(二期 T13)** | 已实现 | `ShippingTaskUiState.edit_window` 类型 + `formalHeaderEditable()`/`formalLineEditable(lineKey)`;头字段编辑块按 `edit_window.header` 门控、歧义行源下拉确认按行锁定;四语言 `errors.json` 补 `SHIPPING.EDIT_WINDOW_FIELD_LOCKED/SYSTEM_BUSY`;`npm run build` 通过。 |
|
||||
|
||||
### 排程平台任务契约中心(schedule)
|
||||
|
||||
@@ -204,7 +218,7 @@
|
||||
| 通用 Profile + Adapter 架构 | 实施中 | 销售 Profile 与 Adapter 协议已落地;周任务扫描文档库类型目录;ERP PO / OA 销货放行单打印仅占位 |
|
||||
| 单一共享盘旧检核 | 已停用主路径 | 旧共享盘扫描保留模块但周任务不再调用;不得按核价单/采购单口径扩展 |
|
||||
| 增量、归档与缺件通知 | 实施中 | 每周二上月;单文件结果;归档复制同名跳过;企微每批一条汇总 |
|
||||
| Tool / 工作台查询 | 实施中 | 工作台任务列表含「强制重检上月」;`/runs` 读新引擎批次;旧 states 查询保留兼容 |
|
||||
| Tool / 工作台查询 | 实施中 | 工作台含检核任务与企微发送记录两 Tab;「强制重检上月」;`/runs` 读新引擎批次,`/notifications` 读每批一条企微汇总;旧 states 查询保留兼容 |
|
||||
| Dify Chatflow 编排 | 待完成 | 须按新口径(上月、Profile、批次汇总)编排;现有草稿仅对应旧引擎 Tool |
|
||||
|
||||
### 采购合同审查
|
||||
@@ -724,3 +738,33 @@
|
||||
详细目标架构、接口契约、测试矩阵与验收标准见 [features/auth/hxops-peer-service-sso.md](features/auth/hxops-peer-service-sso.md)。
|
||||
|
||||
---
|
||||
|
||||
## 在途仓自动调拨 Agent
|
||||
|
||||
| 功能项 | 状态 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| 领域模型/状态机/DTO/审计/迁移 | 后端已实现 | ackend/app/models/in_transit_transfer.py(Run/SourceJob/Precheck/InvoiceItem/Attempt/AuditEvent/Archive)+ 迁移 it1a2b3c4d5e;13 状态服务端门禁(services/in_transit_transfer/status.py) |
|
||||
| 收料文件准备与只读预检 | 后端已实现 | ready 复用/缺文件按来源触发收料 RPA/来源隔离/字段校验/D+1/Invoice 多行汇总+原始行追溯/ERP 库存查询/严格数量匹配/预检快照 Hash/进度恢复 |
|
||||
| 确认与 ERP 原子调拨 | 后端已实现 | 直接生成执行 Run/写前复查/Invoice 幂等/duplicate_success/result_unknown 隔离/单项失败不阻断/按 ERP 单号聚合结果(ERP SOAP 实现在 WSDL 冻结前 fail-closed) |
|
||||
| 排程/恢复/异常/通知 | 后端已实现 | 08:00 收料文件与 09:00 自动调拨 platform job;待处理池 3/5/7 天老化;人工重试/关闭;七 Sheet 异常 Excel;每非空 Run 一条企微通知(失败不改 ERP 结果) |
|
||||
| 生产硬化 | 后端已实现 | MinIO 归档+Hash 复核;Worker 崩溃/陈旧执行恢复;运营指标;越权 403;下载访问审计;性能测试;运维手册 docs/features/in-transit-transfer/technical.md |
|
||||
| 前端 Chat 卡片/结果页与四语言 | 实施中 | `frontend/src/features/chat/` 卡片(文件进度/预检/结果/待处理)与 admin 模块按计划实施 |
|
||||
|
||||
---
|
||||
|
||||
## 外部系统连接器框架(Integration Connector)
|
||||
|
||||
> 平台级外部系统集成抽象(连接器/能力契约/绑定/AI 工具暴露)。首个消费者为在途仓自动调拨的 `query_inventory`。设计文档 [docs/platform/integration-connector-framework-design.md](platform/integration-connector-framework-design.md);完整愿景见 [enterprise-integration-center-prototype.md](platform/enterprise-integration-center-prototype.md)。
|
||||
|
||||
| 功能项 | 状态 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| 配置实体 + 迁移 | 后端已实现 | `models/integration_connector.py`(CredentialReference/ClientInstance/InterfaceDefinition/Binding/Call)+ 迁移 ic1a2b3c4d5f |
|
||||
| Capability 强类型契约 | 后端已实现 | 代码注册(输入/输出 Schema/幂等语义/是否写);在途调拨 3 能力 query_inventory/create_transfer/verify_duplicate |
|
||||
| REST/SOAP 传输 | 后端已实现 | `transports/`(fail-closed:缺 endpoint/wsdl 抛 INTEGRATION.TRANSPORT_NOT_FROZEN) |
|
||||
| 声明式映射引擎 | 后端已实现 | 点路径/数组下标 + 白名单转换函数 + 最小 Schema 校验(禁任意 Python/JS/SQL) |
|
||||
| 凭据引用 + 脱敏 | 后端已实现 | 只存 secret_ref 引用;sanitize 脱敏;credential_summary 不回显明文 |
|
||||
| Binding 版本化解析 | 后端已实现 | (capability, context, environment) → 客户端+接口+映射版本;默认+来源覆盖+优先级+生效区间;冻结快照 |
|
||||
| CapabilityGateway 引擎 | 后端已实现 | resolve→validate→build→call→map→classify→落 IntegrationCall;result_unknown 不自动重试 |
|
||||
| Admin API | 后端已实现 | `/api/integration-connector/*`(配置 CRUD + 能力清单/调用 + 连接测试;拒绝 interface_id;require_admin) |
|
||||
| 调拨 query_inventory 接线 | 后端已实现 | `services/in_transit_transfer/gateway_adapter.py` 把 ERP 访问收敛到 gateway(P1 用默认绑定,来源专属绑定待 P2/P3) |
|
||||
| 配置作业 UI / MCP / Dify 暴露 / RPA/SQL 传输 | 待实施 | 属 P2/P3(AI 只暴露 Capability;RPA 为独立异步 Transport) |
|
||||
@@ -14,8 +14,8 @@
|
||||
"/tools/get_task_status": {
|
||||
"post": {
|
||||
"operationId": "get_task_status",
|
||||
"summary": "查询任务当前状态与 human_options;响应含库存连接器独立字段与候选结构",
|
||||
"description": "返回 inventory_source_code、inventory_connector_type、inventory_warehouse_id、inventory_source_status(unresolved|ambiguous|resolved|user_confirmed|invalid|conflicted)、inventory_source_method、inventory_source_config_version、inventory_routing_fingerprint、inventory_source_confirmed_by、inventory_source_confirmed_at,以及 step_payload.inventory_source_resolution.candidates。",
|
||||
"summary": "查询任务当前状态与 human_options;响应含库存源状态与候选结构",
|
||||
"description": "返回 inventory_source_code、inventory_warehouse_id、inventory_source_status(unresolved|ambiguous|resolved|user_confirmed|invalid|conflicted)、inventory_source_method、inventory_source_config_version、inventory_routing_fingerprint,以及 step_payload.inventory_source_resolution.candidates。",
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
|
||||
@@ -10,3 +10,5 @@
|
||||
| [agent_progress_prototype.md](agent_progress_prototype.md) | Agent 进度管理通用底座(`async_batch` 等) |
|
||||
| [agent_runtime_context_prototype.md](agent_runtime_context_prototype.md) | Runtime Context 协议原型 |
|
||||
| [progress_contract_platform_prototype.html](progress_contract_platform_prototype.html) | 进度契约平台 HTML 原型 |
|
||||
| [enterprise-integration-center-prototype.md](enterprise-integration-center-prototype.md) | 企业集成中心蓝图(完整愿景,含 HTML 原型) |
|
||||
| [integration-connector-framework-design.md](integration-connector-framework-design.md) | Integration Connector Framework 设计(首期最小可行收敛版) |
|
||||
@@ -0,0 +1,502 @@
|
||||
# Integration Connector Framework:连接器、能力契约、绑定与 AI 工具暴露设计
|
||||
|
||||
| 项目 | 说明 |
|
||||
| --- | --- |
|
||||
| 文档版本 | v1.0(首期最小可行设计) |
|
||||
| 日期 | 2026-08-27 |
|
||||
| 状态 | 设计评审中(未实现) |
|
||||
| 读者 | 平台研发、后端、前端、Agent/集成负责人、ERP/RPA 管理员 |
|
||||
| 关联文档 | [企业集成中心蓝图(完整愿景)](enterprise-integration-center-prototype.md) |
|
||||
| 首个消费者 | 在途仓自动调拨(`in_transit_transfer`) |
|
||||
|
||||
> 本文是既有《HXOPS 企业集成中心与在途仓自动调拨原型设计》(`enterprise-integration-center-prototype.md`)的可落地设计。目标是直接建设通用连接器配置能力,同时控制边界:不引入低代码流程编排、任意脚本执行等与当前业务无关的 iPaaS 能力。蓝图中的高级能力(Saga 补偿、Schema Registry、灾备等)保留为后续演进项。
|
||||
|
||||
---
|
||||
|
||||
## 0. 三条设计原则
|
||||
|
||||
1. **配置替换外部系统,不替代领域业务规则。** 连接器/接口/字段映射可配置;但"数量必须相等""当天收料不调拨""`result_unknown` 不得重试"等规则永远属于领域层,不允许管理员通过配置改变。
|
||||
2. **AI 调用业务能力,不调用原始接口。** 对 AI Agent 与外部应用只暴露治理过的 Capability(如 `query_inventory`),不暴露 ERP 地址、SOAP Action、凭据、请求模板或接口编号。
|
||||
3. **所有配置与调用均版本化、可测试、可审计、fail-closed。** 配置缺项即拒绝,不猜测;一次 Run 冻结全部相关版本;每次调用留痕。
|
||||
|
||||
---
|
||||
|
||||
## 1. 背景与问题
|
||||
|
||||
### 1.1 现状
|
||||
|
||||
在途仓自动调拨当前把 ERP 访问**写死**在代码里:
|
||||
|
||||
- `app/services/in_transit_transfer/erp_adapter.py` 的 `SoapErpTransport` 是唯一传输层,`query_inventory` / `create_transfer` / `verify_duplicate` 三个操作硬编码;
|
||||
- `app/services/in_transit_transfer/deps.py::_build_erp_adapter()` 固定读取 `IN_TRANSIT_TRANSFER_ERP_*` 配置键并固定构造 SOAP 传输;
|
||||
- 没有"按来源/按操作选择哪个外部系统、哪个接口、哪种映射"的注册与路由机制。
|
||||
|
||||
### 1.2 目标
|
||||
|
||||
建设一个**系统无关**的连接器框架:同一业务能力(如"查库存")在不同外部系统(ERP / WMS / OA / PLM / HR / RPA 等)上,只通过配置切换客户端实例、接口定义与字段映射,业务代码零改动。同时把治理过的能力暴露给 AI Agent 与其他应用调用。
|
||||
|
||||
> 命名约定:框架不使用 `ErpAdapter` 之类 ERP 专属命名。ERP 只是框架接入的**一个外部系统示例**。通用抽象统一称为 **Connector / Transport / Capability / InterfaceDefinition / Binding**。
|
||||
|
||||
### 1.3 "零改代码"的边界
|
||||
|
||||
- **已注册的业务能力**更换外部系统、接口或字段映射时,业务代码零改动;
|
||||
- **新增全新业务能力**仍需注册能力契约(输入/输出 Schema、幂等语义、是否写)并实现领域处理逻辑。
|
||||
|
||||
配置不能替代领域业务规则(见原则 1)。
|
||||
|
||||
---
|
||||
|
||||
## 2. 三层最小架构
|
||||
|
||||
```text
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ 领域层(Domain) │
|
||||
│ 业务规则、状态机、幂等、写前复查、来源隔离、审计 │
|
||||
│ 只调用标准 Capability,不感知协议/地址/凭据/字段路径 │
|
||||
└────────────────────────┬────────────────────────────────┘
|
||||
│ CapabilityGateway.call(capability, ctx, params)
|
||||
┌────────────────────────▼────────────────────────────────┐
|
||||
│ 连接器层(Connector) │
|
||||
│ Transport 实现(首期 REST / SOAP)+ 声明式请求/响应映射 │
|
||||
│ resolve → build → call → map → classify → audit │
|
||||
└────────────────────────┬────────────────────────────────┘
|
||||
│ Transport.call(interface, client, request)
|
||||
┌────────────────────────▼────────────────────────────────┐
|
||||
│ 配置层(Configuration) │
|
||||
│ ClientInstance / InterfaceDefinition / Binding / 版本 │
|
||||
│ CredentialReference(Secret 引用,非明文) │
|
||||
└─────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 核心概念与实体
|
||||
|
||||
### 3.1 配置实体(5 个核心表 + 代码注册能力)
|
||||
|
||||
| 实体 | 存哪 | 职责 |
|
||||
| --- | --- | --- |
|
||||
| **ConnectorType 连接器类型** | 代码常量 | Transport 实现:首期 `REST`、`SOAP`;后置 `RPA`、`SQL`、`FILE`,不单独建表 |
|
||||
| **ClientInstance 客户端实例** | DB | 一份连接配置:连到哪、凭据引用、超时/TLS、默认 org/租户 |
|
||||
| **InterfaceDefinition 接口定义(按版本存储)** | DB | 一个可调操作;每个版本一行,包含请求/响应配置、消息配置、映射、Schema、测试配置和发布状态 |
|
||||
| **Binding 绑定** | DB | `(Capability, context_selector) → (ClientInstance + InterfaceDefinition 版本)`,含版本/生效区间/优先级/状态 |
|
||||
| **CredentialReference 凭据引用** | DB | 仅存 `secret_ref` + 元数据;真实凭据由 Secret 服务注入,不回显 |
|
||||
| **Capability 业务能力** | 代码注册 + DB 目录 | 强类型契约(见 §4),不依赖连接器配置表动态生成业务逻辑 |
|
||||
|
||||
> 当前不单独建立 `Connector`、`MessageProfile`、`MappingVersion`、`Fixture` 表,也不把每个 Header、XML 节点或映射字段拆成关系表。接口版本是配置冻结边界:稳定身份、版本、状态、路由、安全和审计字段使用关系列;协议细节、模板、映射和测试引用使用 JSONB。未来只有在出现跨接口复用、独立权限/查询或统计需求时再拆表。
|
||||
|
||||
### 3.2 运行时实体(2)
|
||||
|
||||
| 实体 | 职责 |
|
||||
| --- | --- |
|
||||
| **IntegrationCall** | 一次调用实例:能力、绑定版本、请求摘要、响应摘要、状态、耗时、trace_id |
|
||||
| **IntegrationAsyncTask** | RPA/Webhook/MQ 等异步任务的提交、等待、回调与恢复状态(后置) |
|
||||
|
||||
> 审计事件可关联以上两个实体,但**审计表不承担运行状态**;运行状态归 IntegrationCall / IntegrationAsyncTask。
|
||||
|
||||
### 3.3 关系字段与 JSONB 边界
|
||||
|
||||
**必须使用独立列**:主键、业务编码、外键、能力、连接器类型、端点、环境、版本、状态、启用标记、凭据引用、优先级、生效时间、超时、创建/更新时间,以及需要索引、唯一约束、权限、路由、统计或审计的字段。
|
||||
|
||||
**放入接口版本 JSONB**:REST 请求头/路径/Body 模板,SOAP 版本、命名空间、操作包装、`SOAPAction`、CDATA 和响应解码规则,请求/响应字段映射、白名单转换、成功/失败规则、输入输出 Schema、分页/分片/大小限制和协议扩展参数。
|
||||
|
||||
**大报文与 Golden Fixture**:真实请求/响应样例不直接塞入接口表;首期使用受控文件或对象存储,并在接口版本 JSON 中保存样例引用、校验和及场景标识。只有需要在线维护、权限管理或测试统计时才独立建 Fixture 表。
|
||||
|
||||
接口版本建议至少包含以下 JSONB 字段:
|
||||
|
||||
```text
|
||||
request_config_json
|
||||
response_config_json
|
||||
input_schema_json
|
||||
output_schema_json
|
||||
test_config_json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Capability 强类型契约
|
||||
|
||||
`Capability` **不能完全由数据库动态定义**,否则会退化为"管理员写业务逻辑"。
|
||||
|
||||
- **代码注册**:能力名称、输入 Schema、输出 Schema、幂等语义、是否允许写,由代码注册(如 `@register_capability`)。
|
||||
- **DB 只维护**:启用状态、版本、展示描述、绑定关系。
|
||||
- **领域只调标准能力**,例如:
|
||||
|
||||
```text
|
||||
query_inventory(input) -> InventoryResult
|
||||
create_transfer(input) -> TransferResult
|
||||
verify_duplicate(input) -> TransferResult
|
||||
```
|
||||
|
||||
外部系统差异全部在 Connector 层(Transport + 映射)解决,不进入领域层。
|
||||
|
||||
> 能力命名规范:`<domain>.<action>`,如 `in_transit_transfer.query_inventory`。本文其余处以短名 `query_inventory` 等指代,均属于 `in_transit_transfer` 域。
|
||||
|
||||
---
|
||||
|
||||
## 5. Binding 版本化与发布
|
||||
|
||||
Binding 至少包含:
|
||||
|
||||
```text
|
||||
capability
|
||||
context_selector # 来源/组织/租户/环境等路由条件(含默认绑定)
|
||||
client_instance # 版本引用
|
||||
interface_definition # 版本引用
|
||||
priority
|
||||
environment
|
||||
effective_from / effective_to
|
||||
status # draft / published / retired
|
||||
```
|
||||
|
||||
- 配置修改**不能影响运行中的任务**。
|
||||
- 一次 Run 创建时必须冻结:`ClientInstance 版本`、`InterfaceDefinition 版本(含消息与映射 JSON)`、`Binding 版本`、`Credential 引用版本`。
|
||||
|
||||
---
|
||||
|
||||
## 6. 表达式与映射限制
|
||||
|
||||
请求模板与返回映射**禁止**执行任意 Python / JavaScript / SQL。仅允许:
|
||||
|
||||
- JSONPath / JMESPath(JSON)
|
||||
- XPath(XML)
|
||||
- SQL 命名参数(仅限预注册模板,见 §12)
|
||||
- 白名单转换函数(`cast` / `decimal` / `date` / `default` / `fallback` / `enum-map` / `list-map` / `if-else`)
|
||||
- 有限条件表达式
|
||||
- 变量占位符
|
||||
|
||||
所有表达式执行须有**超时、深度、长度、函数白名单**限制;输出经 JSON Schema 校验,不合法即 fail-closed 报错。
|
||||
|
||||
---
|
||||
|
||||
## 7. 运行时调用引擎(同步管线)
|
||||
|
||||
```
|
||||
resolve(capability, context) → Binding → (client, interface, credential, mapping)
|
||||
build_request(interface, params) → 该接口的原始请求
|
||||
transport.call(connector_type, client, request) → 原始响应
|
||||
map_response(mapping, raw) → 统一结果 DTO(经输出 Schema 校验)
|
||||
classify(result) → success / business_failed / technical_failed / timeout / result_unknown
|
||||
audit(IntegrationCall)
|
||||
```
|
||||
|
||||
统一结果 DTO:
|
||||
|
||||
```text
|
||||
IntegrationCallResult(status, data, error_code, error_message, document_no?, trace_id)
|
||||
```
|
||||
|
||||
首期 Transport 契约(同步):
|
||||
|
||||
```text
|
||||
rest.call(interface, client, request) -> raw_response
|
||||
soap.call(interface, client, request) -> raw_response
|
||||
```
|
||||
|
||||
### 7A. 标准 DTO 到目标系统请求的映射模型
|
||||
|
||||
领域层只传入能力定义的标准 DTO。连接器运行时按以下顺序完成转换:
|
||||
|
||||
```text
|
||||
标准 Capability DTO
|
||||
→ 输入校验/规范化
|
||||
→ 声明式字段映射(标准字段 → 目标字段)
|
||||
→ Target Request Model(目标请求模型)
|
||||
→ Message Profile + Serializer(报文包装与序列化)
|
||||
→ Transport(SOAP/REST/...)
|
||||
```
|
||||
|
||||
- **简单字段**:例如 `lot` → `img04`、`warehouse` → `img02`,通过路径映射和类型转换完成。
|
||||
- **数组/重复节点**:例如多个批号映射为多个 `Record`,由映射引擎按集合展开,禁止领域层拼接 XML。
|
||||
- **受控业务转换**:批号集合拼接、分片、日期/数量格式化等只能调用代码注册的白名单函数(如 `controlled_lot_condition`),不能执行任意脚本、SQL 或模板代码。
|
||||
- **缺失与冲突**:必填字段缺失、类型不符、映射产生非法结构时立即失败(fail-closed),并返回可定位的字段错误。
|
||||
- **输出**:目标响应先按协议解码,再按声明式映射转成标准输出 DTO,并通过 Capability 输出 Schema 校验。
|
||||
|
||||
映射配置建议采用结构化 JSON,而非自由文本表达式。例如:
|
||||
|
||||
```json
|
||||
{
|
||||
"fields": [
|
||||
{"source": "warehouse", "target": "img02", "required": true},
|
||||
{"source": "lots", "target": "img04", "expand": "record", "required": true}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 7B. Message Profile 与 Transport 分离
|
||||
|
||||
SOAP Transport 只负责 HTTP/SOAP 通讯(URL、TLS、超时、认证、响应状态),不写死任何供应商的操作名或 XML 结构。接口版本 JSON 中的 `message` 配置(逻辑上的 Message Profile,不单独建表)负责协议消息细节:
|
||||
|
||||
- SOAP 版本、Envelope/Body 命名空间;
|
||||
- 操作元素名称及命名空间;
|
||||
- `SOAPAction`(包括必须为空字符串的场景);
|
||||
- 请求参数承载方式(元素、属性、CDATA、纯文本或 JSON);
|
||||
- body wrapper、内层根节点、重复节点规则;
|
||||
- 响应外层路径、转义字符串二次解析规则及错误定位。
|
||||
|
||||
因此 `GetItemStockListRequest`、`RequestContent`、`img01` 等均属于接口版本的消息配置,不属于通用代码。REST 也采用同样的“请求模板 + 序列化器”模型,以便未来接入非 TIPTOP SOAP 服务。配置引擎必须能够从标准 DTO 完整生成最终 HTTP 报文,而不是要求领域层预先拼接目标 XML/JSON。
|
||||
|
||||
### 7C. WSDL 自动发现、确认与版本冻结
|
||||
|
||||
WSDL 仅用于生成接口草稿,不能直接作为生产运行时的唯一真相:
|
||||
|
||||
1. 导入 WSDL,发现 service/port/binding/operation、命名空间、SOAP 版本和默认 action;
|
||||
2. 生成可编辑草稿,并标出 WSDL 无法确定的字段承载方式(如 CDATA 内嵌 XML);
|
||||
3. 使用真实测试报文进行连接测试和试运行,人工确认请求/响应路径及映射;
|
||||
4. 发布后生成不可变版本,后续修改必须创建新版本并重新测试;
|
||||
5. 运行中的 Run 固定引用的版本,禁止配置热变更影响执行。
|
||||
|
||||
### 7D. TIPTOP Gateway Profile 示例(非通用约束)
|
||||
|
||||
当前 TIPTOP Gateway 可建为 `tiptop_gateway_v1` Message Profile,仅作为一个外部系统适配示例:
|
||||
|
||||
- SOAP 1.1,`SOAPAction` 按对方要求配置(成功样例为空字符串);
|
||||
- Body 操作包装名由接口定义/WSDL 草稿确认,例如 `GetItemStockListRequest`;
|
||||
- `request` 参数承载 CDATA 内嵌业务 XML;
|
||||
- 业务 XML 包含 `Access`、`RequestContent/Parameter/Record/Field`;
|
||||
- 响应的 `response` 可能是 XML 转义字符串,需先 XML decode,再解析 `Response/Execution/Status` 和 `Document/RecordSet`;
|
||||
- `Field[@name,@value]` 转换为标准库存记录,具体 `img` 字段字典必须在接口映射中维护。
|
||||
|
||||
用户名、密码、应用 ID 等只引用 Secret,占位符或 Secret 引用不得在文档、日志和配置快照中保存明文。
|
||||
|
||||
### 7E. 批号库存批量查询与分片
|
||||
|
||||
自动调拨输入是收料文件中的批号集合,标准输入示例:
|
||||
|
||||
```json
|
||||
{"warehouse": "HTP-D43", "lots": ["HOW25071402", "HOW25071403"]}
|
||||
```
|
||||
|
||||
连接器必须支持一次请求携带多个批号,不能按批号逐条调用。由于外部系统存在报文大小、网关超时和 XML/JSON 解析限制,接口定义应配置:
|
||||
|
||||
- 最大批号数、最大请求字节数、最大响应字节数;
|
||||
- 超限时按稳定顺序自动分片;
|
||||
- 分片并发上限、单片超时、失败策略(是否整体失败);
|
||||
- 分片结果按批号/料号等业务键去重、合并并保持可追溯的 `trace_id`。
|
||||
|
||||
分片不是领域规则,属于连接器执行策略;数量核对、来源隔离和调拨决策仍由领域层负责。
|
||||
|
||||
### 7F. 配置测试与发布门禁
|
||||
|
||||
每个接口版本至少通过以下测试后才能发布:
|
||||
|
||||
- schema 校验:标准输入、必填项、数组边界、非法类型;
|
||||
- golden request:生成报文与已确认样例逐项比对(命名空间、wrapper、SOAPAction、CDATA);
|
||||
- golden response:覆盖成功、业务失败、技术失败、空结果和 XML 转义响应;
|
||||
- 大批量测试:验证分片、合并、超时和大小上限;
|
||||
- 安全测试:凭据脱敏、禁止任意表达式、禁止客户端覆盖 `interface_id`;
|
||||
- 回归测试:输出 DTO 与领域层契约保持兼容。
|
||||
|
||||
连接测试只证明网络和认证可用;接口试运行还必须证明请求结构、响应解析和业务映射均正确。任何一项失败都不得发布。
|
||||
|
||||
---
|
||||
|
||||
## 8. RPA 与异步执行(后置,但契约先定)
|
||||
|
||||
RPA **不是 FILE 的别名**,也不是普通同步调用。它必须拥有独立 Transport Contract:
|
||||
|
||||
```text
|
||||
submit_trigger # 写 trigger 文件/信号,原子提交
|
||||
callback_authentication # 回调签名/防重放
|
||||
heartbeat # Worker 心跳与能力声明
|
||||
timeout_recovery # 超时恢复与反查
|
||||
artifact_locator # 结果产物定位(文件/共享目录)
|
||||
result_file_mapping # 结果文件 → 标准数据(复用 FILE 映射)
|
||||
```
|
||||
|
||||
即:**RPA = 异步 Transport + 文件结果适配器**,不能只配置成"触发一个文件,然后按 FILE 读取"。
|
||||
|
||||
异步管线(预留):
|
||||
|
||||
```
|
||||
resolve → submit(trigger) → 注册 IntegrationAsyncTask → 等待(心跳/回调) → 结果落盘 → map → classify → audit
|
||||
```
|
||||
|
||||
首期**不实现** RPA 通用连接器内核;继续复用现有收料 RPA 能力(`shipping_notice/receipt_rpa.py` + `rpa_worker_heartbeat.py`)。待框架稳定后再将 RPA 接入为异步 Transport。
|
||||
|
||||
---
|
||||
|
||||
## 9. AI / 外部应用暴露面
|
||||
|
||||
### 9.1 只暴露 Capability,不暴露原始接口
|
||||
|
||||
AI 与其他应用只能看到:
|
||||
|
||||
```text
|
||||
query_inventory
|
||||
create_transfer
|
||||
verify_duplicate
|
||||
get_transfer_status
|
||||
download_receipt_file
|
||||
```
|
||||
|
||||
不应知道:ERP 地址、SOAP Action、凭据、原始请求模板、外部系统接口编号、`interface_id`。
|
||||
|
||||
### 9.2 治理门禁
|
||||
|
||||
- 能力级 RBAC(复用 `app/core/decorators.py` + `action_registry.py` 的 `ACTION_AGENT_CODES` 模式)
|
||||
- 租户 / 组织范围校验
|
||||
- 写操作确认门禁
|
||||
- 幂等键
|
||||
- 调用额度与超时
|
||||
- `result_unknown` 禁止自动重试
|
||||
- 高风险操作的人工确认或策略开关
|
||||
|
||||
### 9.3 通用 REST 网关(谨慎)
|
||||
|
||||
`POST /api/integration/call` 灵活但风险高,约束如下:
|
||||
|
||||
- 对外默认使用**能力白名单**;
|
||||
- **不允许**客户端直接传 `interface_id` 覆盖 Binding;
|
||||
- `interface_id` 仅作后台诊断参数,普通 Agent / 外部应用不可传;
|
||||
- 推荐生成**能力专用端点**或统一工具名,例如:
|
||||
|
||||
```text
|
||||
POST /api/integration/capabilities/query_inventory
|
||||
```
|
||||
|
||||
### 9.4 多面暴露(一次定义、多面复用)
|
||||
|
||||
每个 InterfaceDefinition 自动生成**工具描述**(name / 描述 / 入参 Schema / 出参 Schema / 鉴权):
|
||||
|
||||
1. **REST 网关**(其他应用)
|
||||
2. **MCP Server**(对标 MCP 的 Agent,后置)
|
||||
3. **Dify 自定义工具**(接入现有 `action_registry.py`)
|
||||
|
||||
---
|
||||
|
||||
## 10. 凭据模型(引用 + Secret 元数据)
|
||||
|
||||
DB **不保存真正凭据内容**,只保存:
|
||||
|
||||
```text
|
||||
secret_ref
|
||||
secret_provider
|
||||
credential_type
|
||||
version
|
||||
status
|
||||
last_verified_at
|
||||
```
|
||||
|
||||
- ClientInstance 引用 `secret_ref`;
|
||||
- 切换凭据通过版本更新,**不能覆盖运行中的调用**;
|
||||
- 凭据不回显、不写日志、不进配置快照(复用调拨 `sanitize_snapshot` 思路)。
|
||||
|
||||
---
|
||||
|
||||
## 11. 配置作业完整生命周期
|
||||
|
||||
客户端配置页不是简单 CRUD,而是:
|
||||
|
||||
```text
|
||||
草稿
|
||||
→ 参数校验
|
||||
→ 连接测试
|
||||
→ 接口试运行
|
||||
→ 返回映射预览
|
||||
→ 发布
|
||||
→ 生效
|
||||
→ 停用
|
||||
```
|
||||
|
||||
- 试运行必须使用**脱敏样本或测试环境**;
|
||||
- "测试连接成功"不代表业务映射正确——试运行须同时校验成功响应与业务错误响应的映射结果。
|
||||
|
||||
---
|
||||
|
||||
## 12. SQL 连接器限制(后置)
|
||||
|
||||
SQL 连接器除"默认只读"外,还须:
|
||||
|
||||
- 只允许**预注册查询模板**;
|
||||
- 禁止 AI 直接生成 SQL;
|
||||
- 禁止多语句、DDL、DML、存储过程调用;
|
||||
- 限制表、字段、行数、执行时长;
|
||||
- 返回结果必须经输出 Schema 校验与脱敏。
|
||||
|
||||
---
|
||||
|
||||
## 13. 与在途调拨的接入(首个消费者)
|
||||
|
||||
### 13.1 责任分层
|
||||
|
||||
| 层 | 负责 | 不负责 |
|
||||
| --- | --- | --- |
|
||||
| 领域层 | 数量严格匹配、D+1、幂等、写前复查、`result_unknown`、来源隔离、审计 | 协议、地址、凭据、字段路径 |
|
||||
| 连接器层 | `query_inventory` / `create_transfer` / `verify_duplicate` 的请求/响应映射与 SOAP/REST 传输 | 是否该调拨、数量判定 |
|
||||
|
||||
### 13.2 接入方式
|
||||
|
||||
- 领域代码改为通过 `CapabilityGateway` 调能力 `in_transit_transfer.query_inventory / create_transfer / verify_duplicate`;
|
||||
- 现有 `RouteResolver`(按来源解析 org/仓库)**不替换**,其输出的来源上下文作为 `context_selector` 喂给 Binding;
|
||||
- 预置绑定:`(query_inventory, DBS-AWSBI)` → 当前 ERP 客户端 + 查询接口;将来 `(query_inventory, CRANE-SZ)` → 新 WMS 客户端 + 接口,只加配置行;
|
||||
- 移除 ERP 专属 `ErpAdapter` 作为通用层;ERP 仅作为框架接入的外部系统实例。
|
||||
|
||||
---
|
||||
|
||||
## 14. MVP 范围与分期
|
||||
|
||||
### 14.1 首期最小可行(MVP)
|
||||
|
||||
实体:5 个核心配置/运行表(`ClientInstance`、按版本存储的 `InterfaceDefinition`、`Binding`、`CredentialReference`、`IntegrationCall`);`Capability` 由代码注册,`ConnectorType` 由代码实现。
|
||||
|
||||
Transport:仅 `REST`、`SOAP`。
|
||||
|
||||
能力:仅注册 3 个:
|
||||
|
||||
```text
|
||||
query_inventory # 查询外部系统库存
|
||||
create_transfer # 创建/审核/过账调拨单
|
||||
verify_duplicate # 确认重复 Invoice 对应原单
|
||||
```
|
||||
|
||||
### 14.2 分期
|
||||
|
||||
| 阶段 | 内容 | 明确不做 |
|
||||
| --- | --- | --- |
|
||||
| **P0** | 连接器内核与通用配置闭环:`CapabilityGateway` + REST/SOAP Transport + ClientInstance/InterfaceDefinition/Binding + 版本化配置 + Secret 引用 + 连接测试/接口试运行;`query_inventory` 首个配置绑定消费者 | 任意脚本转换、低代码流程编排 |
|
||||
| **P1** | 配置作业 UI(草稿→校验→测试→试运行→预览→发布→回滚/停用)+ AI 暴露(只暴露治理后的能力) | interface_id 直传、原始接口暴露 |
|
||||
| **P2** | 异步与更多协议:RPA / FILE / Webhook / MQ / MCP / SQL 只读查询 | 不受控的通用脚本执行 |
|
||||
|
||||
---
|
||||
|
||||
## 15. 落地文件与数据迁移(P1 起)
|
||||
|
||||
- 模型:`app/models/integration_connector.py`(ClientInstance / 按版本存储的 InterfaceDefinition / Binding / CredentialReference / IntegrationCall;异步能力启用后再增加 IntegrationAsyncTask)
|
||||
- 服务:`app/services/integration_connector/`(`capability.py` / `binding.py` / `engine.py` / `mapping.py` / `transports/rest.py` / `transports/soap.py` / `descriptors.py` / `security.py`)
|
||||
- API:`app/api/integration_connector.py`(Admin CRUD + 能力调用端点 + 工具清单)
|
||||
- Admin UI:`frontend/src/features/admin/modules/integration-connector/`(客户端配置作业)
|
||||
- 迁移:Alembic 新迁移,挂在当前 head 后
|
||||
|
||||
---
|
||||
|
||||
## 16. 安全 / 审计 / fail-closed 总则
|
||||
|
||||
- 能力级 RBAC;SQL 默认只读、写操作须显式标记 + 强制审计;
|
||||
- 凭据仅 Secret 引用,日志脱敏;
|
||||
- 缺端点 / 缺凭据 / 映射不合法 → fail-closed 拒绝,绝不猜测;
|
||||
- 每次调用落 `IntegrationCall`;配置创建/测试/发布/停用记前后快照审计;
|
||||
- 写操作必须携带幂等键,`result_unknown` 禁止自动重试。
|
||||
|
||||
---
|
||||
|
||||
## 17. 首期验收标准
|
||||
|
||||
- 新增外部系统实例(换系统)无需修改调拨领域代码;
|
||||
- 修改外部字段路径需发布新的 `InterfaceDefinition` 版本;
|
||||
- 一次 Run 能追溯到冻结的全部配置版本;
|
||||
- 原始 SOAP/REST 报文不进入调拨领域表;
|
||||
- 凭据不回显、不写日志、不进快照;
|
||||
- AI / 外部应用只能调用治理过的 Capability,无法传入 `interface_id` 或原始接口参数;
|
||||
- 数量严格匹配、D+1、写前复查、`result_unknown` 禁重试等规则仍在领域层生效。
|
||||
- SOAP 报文可由配置完整生成并解析:支持命名空间、wrapper、SOAPAction、CDATA/内嵌 XML、XML 属性字段及转义响应。
|
||||
- 多批号库存查询支持单次批量请求、大小限制下自动分片及结果合并,不产生逐批号调用风暴。
|
||||
- WSDL 导入可生成草稿;人工确认后发布冻结版本,golden request/response 和边界测试全部通过。
|
||||
|
||||
---
|
||||
|
||||
## 18. 相关文档
|
||||
|
||||
- [企业集成中心蓝图(完整愿景)](enterprise-integration-center-prototype.md)
|
||||
- 在途仓自动调拨实现(Phase 0/1):`backend/app/services/in_transit_transfer/`
|
||||
- Chat Action Registry(Agent 挂载点):`backend/app/services/chat/action_registry.py`
|
||||
@@ -0,0 +1,94 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>HXOPS 集成连接器配置中心</title>
|
||||
<style>
|
||||
:root{--page:#f7f9fc;--surface:#fff;--soft:#f1f5f9;--line:#e2e8f0;--ink:#0f172a;--text:#334155;--muted:#64748b;--brand:#0284c7;--brand-soft:#e0f2fe;--nav:#102a43;--nav-soft:#173c5b;--ok:#15803d;--ok-bg:#ecfdf3;--warn:#b45309;--warn-bg:#fff7ed;--bad:#b91c1c;--bad-bg:#fef2f2;--r:12px;--shadow:0 8px 24px rgba(15,23,42,.06);font-family:"PingFang SC","Microsoft YaHei","Segoe UI",system-ui,sans-serif}*{box-sizing:border-box}body{margin:0;background:var(--page);color:var(--ink);font-size:14px}button,input,select,textarea{font:inherit}button{cursor:pointer}.app{min-height:100vh;display:grid;grid-template-columns:228px minmax(0,1fr)}.side{background:var(--nav);color:#dbeafe;padding:18px 14px;display:flex;flex-direction:column}.brand{display:flex;gap:10px;align-items:center;padding:4px 8px 20px;border-bottom:1px solid #ffffff1f}.mark{width:34px;height:34px;border-radius:10px;background:#0ea5e9;display:grid;place-items:center;color:#fff;font-weight:800}.brand b{display:block;color:#fff}.brand small{color:#93c5fd;font-size:11px}.nav-title{margin:22px 9px 8px;color:#8aa4bb;font-size:11px;letter-spacing:.12em}.nav{width:100%;border:0;background:transparent;color:#cbd5e1;text-align:left;padding:10px 11px;border-radius:8px;margin:2px 0}.nav:hover,.nav.active{background:var(--nav-soft);color:#fff}.nav.active{box-shadow:inset 3px 0 var(--brand)}.side-foot{margin-top:auto;border:1px solid #ffffff1f;border-radius:9px;padding:11px;color:#9fb3c8;font-size:12px;line-height:1.6}.side-foot b{color:#e0f2fe}.main{min-width:0}.top{height:62px;background:#fffffff2;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:0 28px;position:sticky;top:0;z-index:4}.crumb{color:var(--muted)}.crumb b{color:var(--text)}.top-right{display:flex;gap:12px;align-items:center}.env{border:1px solid #bae6fd;background:var(--brand-soft);color:#075985;border-radius:999px;padding:6px 10px;font-size:12px}.avatar{width:30px;height:30px;border-radius:50%;display:grid;place-items:center;background:var(--nav);color:#fff}.wrap{max-width:1540px;margin:auto;padding:26px 30px 44px}.head{display:flex;justify-content:space-between;gap:20px;margin-bottom:22px}.eyebrow{color:var(--brand);font:700 11px Consolas,monospace;letter-spacing:.13em;text-transform:uppercase}.head h1{font-size:27px;margin:7px 0 5px}.head p{margin:0;color:var(--muted);line-height:1.65;max-width:760px}.actions{display:flex;gap:9px;align-items:center;flex-wrap:wrap}.btn{border:1px solid var(--line);background:var(--surface);color:var(--text);border-radius:8px;padding:8px 13px;font-size:13px}.btn:hover{background:var(--soft);border-color:#94a3b8}.btn.primary{background:var(--brand);border-color:var(--brand);color:#fff}.stats{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:18px}.stat,.panel{background:var(--surface);border:1px solid var(--line);border-radius:var(--r);box-shadow:var(--shadow)}.stat{padding:15px 17px}.stat label{display:block;color:var(--muted);font-size:12px}.stat strong{font-size:26px;display:block;margin:7px 0 3px}.stat small,.muted{color:var(--muted)}.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin-bottom:16px;overflow:auto}.tab{border:0;background:transparent;color:var(--muted);padding:11px 15px;border-bottom:2px solid transparent;white-space:nowrap}.tab.active{color:var(--brand);border-color:var(--brand);font-weight:600}.view{display:none}.view.active{display:block}.panel-head,.toolbar{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:16px 18px;border-bottom:1px solid var(--line)}.panel-head h2{font-size:16px;margin:0}.panel-head small{color:var(--muted)}.body{padding:18px}.table-wrap{overflow:auto}.table{width:100%;border-collapse:collapse}.table th{background:var(--soft);color:var(--muted);font-size:12px;text-align:left;padding:11px 16px;white-space:nowrap}.table td{padding:13px 16px;border-bottom:1px solid #eef2f7;color:var(--text);white-space:nowrap}.table tr:last-child td{border-bottom:0}.code{font:12px Consolas,monospace;color:#0f4c6e}.badge{display:inline-flex;border-radius:999px;padding:4px 8px;font-size:11px;font-weight:600}.badge.ok{background:var(--ok-bg);color:var(--ok)}.badge.info{background:var(--brand-soft);color:#0369a1}.badge.warn{background:var(--warn-bg);color:var(--warn)}.badge.bad{background:var(--bad-bg);color:var(--bad)}.link{border:0;background:transparent;color:var(--brand);padding:0}.grid2{display:grid;grid-template-columns:1.3fr .7fr;gap:16px}.stack{display:grid;gap:16px}.metric{display:flex;justify-content:space-between;padding:11px 0;border-bottom:1px solid #eef2f7}.metric:last-child{border:0}.editor{display:grid;grid-template-columns:220px minmax(0,1fr) 340px;gap:16px}.steps{padding:12px}.step{display:flex;gap:10px;padding:12px 9px;color:var(--muted);border-radius:9px}.step.active{background:var(--brand-soft);color:#075985}.step.done{color:var(--ok)}.num{width:23px;height:23px;border:1px solid currentColor;border-radius:50%;disLine truncated
|
||||
</style></head><body><div class="app"><aside class="side"><div class="brand"><div class="mark">H</div><div><b>HXOPS</b><small>Enterprise AI Gateway</small></div></div><div class="nav-title">平台管理</div><button class="nav">⌂ 工作台</button><button class="nav active">↔ 集成连接器</button><button class="nav">◈ Agent 应用</button><button class="nav">▤ 审计日志</button><div class="nav-title">业务域</div><button class="nav">▣ 在途仓调拨</button><button class="nav">□ 货代收料</button><div class="side-foot"><b>配置提示</b><br>领域层只提交标准 DTO。接口配置生成目标报文,发布后版本冻结。</div></aside><main class="main"><header class="top"><div class="crumb">平台管理 / <b>集成连接器</b></div><div class="top-right"><span class="env">测试环境</span><span class="muted">曹慧鹏</span><span class="avatar">曹</span></div></header><div class="content"><div class="head"><div><div class="eyebrow">Integration connector</div><h1>集成连接器配置中心</h1><p>管理外部系统连接、接口报文和能力绑定。接口编辑、测试和发布都在接口定义详情内完成。</p></div><div class="actions"><button class="btn" data-view-target="calls">调用记录</button><button class="btn primary" data-modal="client">+ 新建连接器</button></div></div><div class="stats"><div class="stat"><label>客户端实例</label><strong>4</strong><small>2 个生产 · 2 个测试</small></div><div class="stat"><label>接口定义</label><strong>12</strong><small>10 个已发布</small></div><div class="stat"><label>今日调用</label><strong>1,284</strong><small>成功率 99.7%</small></div><div class="stat"><label>待办配置</label><strong>2</strong><small>需要试运行或验证</small></div></div><div class="tabs"><button class="tab active" data-view="overview">配置总览</button><button class="tab" data-view="clients">客户端实例</button><button class="tab" data-view="interfaces">接口定义</button><button class="tab" data-view="bindings">能力绑定</button><button class="tab" data-view="credentials">凭据引用</button><button class="tab" data-view="capabilities">能力清单</button><button class="tab" data-view="calls">调用记录</button></div>
|
||||
<section class="view active" id="overview"><div class="grid2"><div class="panel"><div class="panel-head"><div><h2>配置总览</h2><small>当前环境的连接和发布状态</small></div><button class="btn" data-modal="check">配置检查</button></div><div class="body"><div class="metric"><span>连接实例健康</span><b style="color:var(--ok)">4 / 4 正常</b></div><div class="metric"><span>已发布接口</span><b>10 / 12</b></div><div class="metric"><span>能力绑定覆盖</span><b>8 个来源上下文</b></div><div class="metric"><span>最后一次发布</span><b>今天 09:42</b></div></div></div><div class="stack"><div class="panel"><div class="panel-head"><h2>待处理</h2><small>配置作业</small></div><div class="body"><div class="metric"><span>库存查询 v4 草稿</span><span class="badge warn">待试运行</span></div><div class="metric"><span>DBS 凭据轮换</span><span class="badge info">待确认</span></div></div></div><div class="panel"><div class="panel-head"><h2>配置原则</h2></div><div class="body"><div class="notice">关系字段保存身份、版本、状态和路由。JSON 配置保存协议细节、模板和映射。</div></div></div></div></div><div class="panel" style="margin-top:16px"><div class="panel-head"><h2>最近变更</h2><button class="btn" data-view-target="calls">查看审计</button></div><div class="table-wrap"><table class="table"><thead><tr><th>时间</th><th>对象</th><th>动作</th><th>结果</th></tr></thead><tbody><tr><td>09:42</td><td class="code">get_item_stock_list v3</td><td>发布接口版本</td><td><span class="badge ok">成功</span></td></tr><tr><td>09:18</td><td class="code">TIPTOP-TEST</td><td>连接测试</td><td><span class="badge ok">成功</span></td></tr></tbody></table></div></div></section>
|
||||
<section class="view" id="clients"><div class="panel"><div class="toolbar"><div><b>客户端实例</b><div class="muted">连接地址、协议、环境、超时和凭据引用</div></div><div class="actions"><input class="search" placeholder="搜索实例编码或名称"><button class="btn" data-modal="wsdl">导入 WSDL</button><button class="btn primary" data-modal="client">+ 新建客户端</button></div></div><div class="table-wrap"><table class="table"><thead><tr><th>实例</th><th>协议</th><th>环境</th><th>地址</th><th>超时</th><th>凭据</th><th>状态</th><th>操作</th></tr></thead><tbody><tr><td><b>TIPTOP-TEST</b><div class="muted">TIPTOP 测试客户端</div></td><td><span class="badge info">SOAP 1.1</span></td><td>测试</td><td class="code">topgp.../web/ws/r</td><td>60s</td><td class="code">tiptop-test</td><td><span class="badge ok">连接正常</span></td><td><button class="link" data-drawer="client">详情</button> <button class="link" data-modal="test">测试</button></td></tr><tr><td><b>WMS-PROD</b><div class="muted">仓储管理系统</div></td><td><span class="badge info">REST</span></td><td>生产</td><td class="code">wms-api.../v2</td><td>30s</td><td class="code">wms-prod</td><td><span class="badge ok">连接正常</span></td><td><button class="link" data-drawer="client">详情</button> <button class="link" data-modal="test">测试</button></td></tr><tr><td><b>DBS-RPA</b><div class="muted">DBS 收料文件</div></td><td><span class="badge warn">RPA</span></td><td>生产</td><td class="code">共享目录</td><td>120s</td><td class="code">dbs-rpa</td><td><span class="badge warn">待验证</span></td><td><button class="link" data-drawer="client">详情</button></td></tr></tbody></table></div></div></section>
|
||||
<section class="view" id="interfaces"><div class="panel"><div class="toolbar"><div><b>接口定义</b><div class="muted">接口编辑、测试、发布都在接口详情内完成</div></div><div class="actions"><select class="filter"><option>全部协议</option><option>REST</option><option>SOAP</option></select><button class="btn primary" data-modal="new-interface">+ 新建接口</button></div></div><div class="table-wrap"><table class="table"><thead><tr><th>接口编码</th><th>能力</th><th>客户端</th><th>协议</th><th>版本</th><th>状态</th><th>最近测试</th><th>操作</th></tr></thead><tbody><tr><td class="code"><b>get_item_stock_list</b><div class="muted">批号库存查询</div></td><td class="code">query_inventory</td><td>TIPTOP-TEST</td><td>SOAP</td><td>v3</td><td><span class="badge ok">已发布</span></td><td>今天 09:18</td><td><button class="link" data-view-target="editor">编辑详情</button></td></tr><tr><td class="code"><b>create_transfer</b><div class="muted">创建调拨单</div></td><td class="code">create_transfer</td><td>TIPTOP-TEST</td><td>SOAP</td><td>v2</td><td><span class="badge ok">已发布</span></td><td>昨天 16:02</td><td><button class="link" data-view-target="editor">编辑详情</button></td></tr><tr><td class="code"><b>wms_inventory_query</b><div class="muted">仓库库存查询</div></td><td class="code">query_inventory</td><td>WMS-PROD</td><td>REST</td><td>v1</td><td><span class="badge warn">草稿</span></td><td>未测试</td><td><button class="link" data-view-target="editor">编辑详情</button></td></tr></tbody></table></div></div></section>
|
||||
<section class="view" id="editor"><div class="editor"><div class="panel steps"><div class="step done" data-step="basic"><span class="num">1</span><div><b>基本信息</b><small>接口身份和客户端</small></div></div><div class="step active" data-step="request"><span class="num">2</span><div><b>请求映射</b><small>DTO 到目标报文</small></div></div><div class="step" data-step="response"><span class="num">3</span><div><b>响应映射</b><small>返回标准结果</small></div></div><div class="step" data-step="publish"><span class="num">4</span><div><b>测试与发布</b><small>验证后冻结版本</small></div></div></div><div class="panel"><div class="panel-head"><div><h2 id="editor-title">get_item_stock_list · 请求映射</h2><small>草稿 v4 · TIPTOP-TEST · SOAP</small></div><div class="actions"><button class="btn" data-toast="接口草稿已保存">保存草稿</button><button class="btn primary" data-step-target="publish">测试与发布</button></div></div><div id="pane-basic" class="section pane" style="display:none"><h3>基本信息</h3><p>接口编码是稳定身份。修改协议细节时创建新的不可变版本。</p><div class="formgrid"><div class="field"><label>接口编码</label><input class="input" value="get_item_stock_list"></div><div class="field"><label>接口名称</label><input class="input" value="批号库存查询"></div><div class="field"><label>业务能力</label><select><option>in_transit_transfer.query_inventory</option><option>in_transit_transfer.create_transfer</option></select></div><div class="field"><label>客户端实例</label><select><option>TIPTOP-TEST</option><option>WMS-PROD</option></select></div><div class="field"><label>新版本号</label><input class="input" value="4" type="number"></div><div class="field"><label>接口状态</label><select><option>草稿</option><option>停用</option></select></div></div></div><div id="pane-request" class="section pane"><h3>标准输入 DTO</h3><p>领域层只传标准结构,不了解 XML 节点、SOAPAction 或外部字段名。</p><textarea rows="7">{
|
||||
"warehouse": "HTP-D43",
|
||||
"lots": ["HOW25071402", "HOW25071403"]
|
||||
}</textarea><h3 style="margin-top:18px">消息配置与请求映射</h3><p>SOAP 特有的命名空间、包装节点和 CDATA 规则都属于接口版本。</p><div class="formgrid"><div class="field"><label>SOAP 版本</label><select><option>SOAP 1.1</option><option>SOAP 1.2</option></select></div><div class="field"><label>SOAPAction</label><input class="input" value=""""></div><div class="field"><label>操作包装节点</label><input class="input" value="GetItemStockListRequest"></div><div class="field"><label>参数承载方式</label><select><option>CDATA 内嵌 XML</option><option>纯文本</option></select></div><div class="field"><label>仓库 → 外部字段</label><input class="input" value="warehouse → img02" readonly></div><div class="field"><label>批号集合 → 外部字段</label><input class="input" value="lots[] → img04(展开 Record)" readonly></div><div class="field full"><label>命名空间</label><input class="input" value="http://www.dsc.com.tw/tiptop/TIPTOPServiceGateWay"></div></div></div><div id="pane-response" class="section pane" style="display:none"><h3>响应映射</h3><p>外部响应先解码,再映射为领域层可消费的标准库存结果。</p><div class="formgrid"><div class="field"><label>响应状态路径</label><input class="input" value="Response.Execution.Status[@code]" readonly></div><div class="field"><label>记录集合路径</label><input class="input" value="Response.ResponseContent.Document.RecordSet...Record" readonly></div><div class="field"><label>料号 → item_no</label><input class="input" value="img01 → item_no" readonly></div><div class="field"><label>批号 → lot</label><input class="input" value="img04 → lot" readonly></div><div class="field"><label>库存数量 → ledger_quantity</label><input class="input" value="img11 → ledger_quantity" readonly></div><div class="field"><label>转义响应</label><select><option>先 XML Decode,再解析内层 Response</option><option>直接解析</option></select></div></div></div><div id="pane-publish" class="section pane" style="display:none"><h3>测试与发布</h3><p>测试通过后才能发布。发布会冻结当前接口版本并更新对应绑定。</p><div class="check"><span class="checkicon">✓</span><div><b>输入 Schema 校验</b><small>warehouse、lots[] 符合标准 DTO 定义</small></div></div><div class="check"><span class="checkicon">✓</span><div><b>Golden Request / Response</b><small>请求结构和响应二次解码均通过</small></div></div><div class="check warn"><span class="checkicon">!</span><div><b>生产环境试运行</b><small>尚未执行</small></div></div><div class="actions" style="margin-top:16px"><button class="btn" data-modal="test-run">执行全部测试</button><button class="btn primary" data-toast="发布被阻断:请先完成生产试运行">发布接口版本</button></div></div></div><aside class="panel preview"><div class="panel-head"><div><h2>最终报文预览</h2><small>标准 DTO 即时生成</small></div><span class="badge ok">结构有效</span></div><div class="body"><div class="flow"><span>标准 DTO</span><span>›</span><span>字段映射</span><span>›</span><span>XML 序列化</span><span>›</span><span>SOAP</span></div><div class="previewblock"><div class="previewtitle">HTTP Header</div><pre>Content-Type: text/xml; charset=utf-8
|
||||
SOAPAction: ""</pre></div><div class="previewblock"><div class="previewtitle">SOAP Body</div><pre><soap:Body>
|
||||
<fjs:GetItemStockListRequest>
|
||||
<fjs:request><![CDATA[
|
||||
<Field name="img02" value="HTP-D43"/>
|
||||
<Field name="img04" value="HOW25071402"/>
|
||||
<Field name="img04" value="HOW25071403"/>
|
||||
]]></fjs:request>
|
||||
</fjs:GetItemStockListRequest>
|
||||
</soap:Body></pre></div><div class="notice">必填字段、命名空间和 SOAPAction 校验通过。</div></div></aside></div></section>
|
||||
<section class="view" id="bindings"><div class="panel"><div class="toolbar"><div><b>能力绑定</b><div class="muted">按来源、组织和环境选择客户端与接口版本</div></div><button class="btn primary" data-modal="binding">+ 新建绑定</button></div><div class="table-wrap"><table class="table"><thead><tr><th>能力</th><th>来源上下文</th><th>客户端</th><th>接口版本</th><th>优先级</th><th>状态</th><th>操作</th></tr></thead><tbody><tr><td class="code">in_transit_transfer.query_inventory</td><td>DBS-AWSBI / TGHX</td><td>TIPTOP-TEST</td><td class="code">get_item_stock_list v3</td><td>10</td><td><span class="badge ok">已发布</span></td><td><button class="link" data-drawer="binding">详情</button></td></tr><tr><td class="code">in_transit_transfer.create_transfer</td><td>DBS-AWSBI / TGHX</td><td>TIPTOP-TEST</td><td class="code">create_transfer v2</td><td>10</td><td><span class="badge ok">已发布</span></td><td><button class="link" data-drawer="binding">详情</button></td></tr></tbody></table></div></div></section>
|
||||
<section class="view" id="credentials"><div class="panel"><div class="toolbar"><div><b>凭据引用</b><div class="muted">只保存 Secret 引用,不保存密码和 Token</div></div><button class="btn primary" data-modal="credential">+ 新建凭据引用</button></div><div class="table-wrap"><table class="table"><thead><tr><th>编码</th><th>Secret 引用</th><th>提供方</th><th>类型</th><th>版本</th><th>状态</th><th>操作</th></tr></thead><tbody><tr><td class="code">tiptop-test</td><td class="code">secret://integration/tiptop-test</td><td>Vault</td><td>basic_auth</td><td>3</td><td><span class="badge ok">有效</span></td><td><button class="link" data-drawer="credential">详情</button> <button class="link" data-modal="rotate">轮换</button></td></tr><tr><td class="code">wms-prod</td><td class="code">secret://integration/wms-prod</td><td>Vault</td><td>bearer</td><td>2</td><td><span class="badge ok">有效</span></td><td><button class="link" data-drawer="credential">详情</button></td></tr></tbody></table></div></div></section>
|
||||
<section class="view" id="capabilities"><div class="panel"><div class="toolbar"><div><b>能力清单</b><div class="muted">AI 和外部应用只能调用治理后的业务能力</div></div><button class="btn" data-toast="能力清单来自代码注册表">刷新能力</button></div><div class="table-wrap"><table class="table"><thead><tr><th>能力</th><th>用途</th><th>写操作</th><th>幂等语义</th><th>绑定数</th><th>对外暴露</th><th>操作</th></tr></thead><tbody><tr><td class="code"><b>query_inventory</b></td><td>查询外部库存</td><td>否</td><td>可重复读取</td><td>3</td><td><span class="badge ok">允许</span></td><td><button class="link" data-drawer="capability">查看契约</button></td></tr><tr><td class="code"><b>create_transfer</b></td><td>创建并提交调拨</td><td>是</td><td>必须幂等键</td><td>2</td><td><span class="badge warn">需确认</span></td><td><button class="link" data-drawer="capability">查看契约</button></td></tr></tbody></table></div></div></section>
|
||||
<section class="view" id="calls"><div class="panel"><div class="toolbar"><div><b>调用记录</b><div class="muted">展示脱敏摘要,原始报文按权限和保留周期管理</div></div><div class="actions"><input class="search" placeholder="搜索 trace_id 或能力"><select class="filter"><option>全部结果</option><option>成功</option><option>结果未知</option></select></div></div><div class="table-wrap"><table class="table"><thead><tr><th>时间</th><th>Trace ID</th><th>能力</th><th>客户端</th><th>接口版本</th><th>耗时</th><th>结果</th><th>操作</th></tr></thead><tbody><tr><td>09:42:18</td><td class="code">tr_8f31c0</td><td class="code">query_inventory</td><td>TIPTOP-TEST</td><td>v3</td><td>684 ms</td><td><span class="badge ok">成功</span></td><td><button class="link" data-drawer="call">详情</button></td></tr><tr><td>09:16:52</td><td class="code">tr_8f201d</td><td class="code">create_transfer</td><td>TIPTOP-TEST</td><td>v2</td><td>20.0 s</td><td><span class="badge bad">结果未知</span></td><td><button class="link" data-drawer="call">详情</button></td></tr></tbody></table></div></div></section></div></main></div>
|
||||
<div class="back" id="drawer"><aside class="drawer" role="dialog" aria-modal="true"><div class="drawerhead"><div><div class="eyebrow">Configuration detail</div><h2 id="dtitle">配置详情</h2><div class="muted" id="dsub">只读演示</div></div><button class="close" data-close>×</button></div><div class="drawerbody" id="dbody"></div></aside></div><div class="back" id="modal"><div class="modal" role="dialog" aria-modal="true"><div class="drawerhead"><div><div class="eyebrow">Configuration task</div><h2 id="mtitle">配置作业</h2><div class="muted" id="msub">填写信息后保存为草稿</div></div><button class="close" data-close>×</button></div><div class="drawerbody" id="mbody"></div></div></div><div id="toast" style="position:fixed;right:24px;bottom:24px;background:#0f172a;color:#fff;padding:11px 15px;border-radius:8px;opacity:0;transform:translateY(10px);transition:.2s;pointer-events:none;font-size:13px"></div>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var tabs = document.querySelectorAll('.tab'), views = document.querySelectorAll('.view');
|
||||
function show(id) { tabs.forEach(function (t) { t.classList.toggle('active', t.dataset.view === id); }); views.forEach(function (v) { v.classList.toggle('active', v.id === id); }); window.scrollTo(0, 0); }
|
||||
tabs.forEach(function (t) { t.addEventListener('click', function () { show(t.dataset.view); }); });
|
||||
document.querySelectorAll('[data-view-target]').forEach(function (b) { b.addEventListener('click', function () { show(b.dataset.viewTarget); }); });
|
||||
|
||||
var toast = document.getElementById('toast'), timer;
|
||||
function notify(message) { toast.textContent = message; toast.style.opacity = '1'; toast.style.transform = 'translateY(0)'; clearTimeout(timer); timer = setTimeout(function () { toast.style.opacity = '0'; toast.style.transform = 'translateY(10px)'; }, 2200); }
|
||||
document.querySelectorAll('[data-toast]').forEach(function (b) { b.addEventListener('click', function () { notify(b.dataset.toast); }); });
|
||||
|
||||
var modal = document.getElementById('modal'), mtitle = document.getElementById('mtitle'), msub = document.getElementById('msub'), mbody = document.getElementById('mbody');
|
||||
function field(label, html) { return '<div class="field"><label>' + label + '</label>' + html + '</div>'; }
|
||||
function newInterfaceForm() {
|
||||
return '<div class="flow" id="new-flow"><span class="badge info">1 基本信息</span><span>›</span><span>2 请求配置</span><span>›</span><span>3 响应配置</span><span>›</span><span>4 测试发布</span></div>' +
|
||||
'<div class="new-pane" data-new-pane="1"><h3>接口基本信息</h3><p>先确定接口身份、能力和使用的客户端实例。</p><div class="formgrid">' + field('接口编码', '<input class="input" data-new="code" placeholder="例如 get_item_stock_list">') + field('接口名称', '<input class="input" data-new="name" placeholder="例如 批号库存查询">') + field('业务能力', '<select class="input" data-new="capability"><option>query_inventory</option><option>create_transfer</option></select>') + field('客户端实例', '<select class="input" data-new="client"><option>TIPTOP-TEST</option><option>WMS-PROD</option><option>DBS-RPA</option></select>') + field('协议类型', '<select class="input" data-new="protocol"><option>SOAP 1.1</option><option>REST JSON</option><option>SQL</option><option>RPA / FILE</option></select>') + field('版本号', '<input class="input" data-new="version" value="1" type="number">') + '</div></div>' +
|
||||
'<div class="new-pane" data-new-pane="2" style="display:none"><h3>请求配置</h3><p>定义标准 DTO 如何生成目标系统请求报文。</p><div class="formgrid">' + field('HTTP 方法', '<select class="input"><option>POST</option><option>GET</option></select>') + field('路径 / Endpoint', '<input class="input" placeholder="/web/ws/r/{operation}">') + field('操作名', '<input class="input" placeholder="由接口编码自动带入" value="get_item_stock_list">') + field('Wrapper 节点', '<input class="input" placeholder="留空则按模板生成">') + field('Content-Type', '<select class="input"><option>text/xml; charset=utf-8</option><option>application/json</option><option>text/plain; charset=utf-8</option></select>') + field('请求模板', '<textarea rows="5" placeholder="使用 {{std_data.parameter}} 或 Velocity 模板"></textarea>') + '</div><div class="notice" style="margin-top:14px">模板负责节点、命名空间、CDATA 和字段位置;领域层只传标准 DTO。</div></div>' +
|
||||
'<div class="new-pane" data-new-pane="3" style="display:none"><h3>响应配置</h3><p>把目标系统响应映射为统一的标准结果。</p><div class="formgrid">' + field('响应格式', '<select class="input"><option>XML(外层 SOAP + 内层 XML)</option><option>JSON</option><option>CSV / Excel 文件</option></select>') + field('状态路径', '<input class="input" placeholder="例如 Response.Execution.Status[@code]">') + field('记录集合路径', '<input class="input" placeholder="例如 Document.RecordSet.Master.Record">') + field('字段映射', '<textarea rows="6" placeholder="item_no <- img01\nlot <- img04\nledger_quantity <- img11"></textarea>') + '</div></div>' +
|
||||
'<div class="new-pane" data-new-pane="4" style="display:none"><h3>测试与发布</h3><p>保存前先运行结构检查和连接测试,发布后版本冻结。</p><div class="check"><span class="checkicon">✓</span><div><b>配置完整性</b><small>接口身份、客户端和请求模板已填写</small></div></div><div class="check"><span class="checkicon">✓</span><div><b>标准 DTO 试生成</b><small>可生成请求预览,未发现缺少字段</small></div></div><div class="check warn"><span class="checkicon">!</span><div><b>外部系统连接测试</b><small>点击“执行连接测试”后才可发布</small></div></div><div class="actions" style="margin-top:14px"><button class="btn" data-run-new-test>执行连接测试</button><span class="muted" data-new-test-result></span></div></div>' +
|
||||
'<div class="actions" style="margin-top:20px;justify-content:space-between"><button class="btn" data-close>取消</button><div class="actions"><button class="btn" data-new-prev>上一步</button><button class="btn" data-new-next>下一步</button><button class="btn primary" data-new-save style="display:none">创建接口草稿</button></div></div>';
|
||||
}
|
||||
function openModal(type) {
|
||||
mtitle.textContent = type === 'new-interface' ? '新增接口定义' : '配置作业';
|
||||
var titles = { client: '新建客户端实例', wsdl: '导入 WSDL', test: '连接测试', 'test-run': '接口试运行', binding: '新建能力绑定', credential: '新建凭据引用', rotate: '凭据轮换', check: '配置检查' };
|
||||
mtitle.textContent = type === 'new-interface' ? '新增接口定义' : (titles[type] || '配置作业');
|
||||
msub.textContent = type === 'new-interface' ? '按步骤完成配置,随时可保存草稿' : '填写信息后保存';
|
||||
if (type === 'new-interface') mbody.innerHTML = newInterfaceForm();
|
||||
else {
|
||||
var forms = {
|
||||
client: '<div class="formgrid">' + field('实例编码', '<input class="input" value="NEW-CLIENT" placeholder="例如 TIPTOP-TEST">') + field('实例名称', '<input class="input" placeholder="例如 WMS 测试客户端">') + field('协议', '<select class="input"><option>SOAP 1.1</option><option>SOAP 1.2</option><option>REST</option><option>RPA / FILE</option></select>') + field('环境', '<select class="input"><option>测试</option><option>生产</option></select>') + field('服务地址', '<input class="input" placeholder="https://...">') + field('超时(秒)', '<input class="input" value="60" type="number">') + field('凭据引用', '<select class="input"><option>tiptop-test</option><option>不使用凭据</option></select>') + field('默认命名空间', '<input class="input" placeholder="协议需要时填写">') + '</div><div class="notice" style="margin-top:14px">密码、Token 等敏感信息只通过凭据引用注入,不在此页面保存。</div>',
|
||||
wsdl: '<div class="field">' + field('WSDL 地址', '<input class="input" value="https://example.com/service?wsdl" placeholder="输入可访问的 WSDL URL">') + '</div><div class="field" style="margin-top:12px">' + field('导入到客户端', '<select class="input"><option>TIPTOP-TEST</option><option>新建客户端</option></select>') + '</div><div class="notice" style="margin-top:14px">导入后会读取服务、操作、命名空间和 SOAP 版本;SOAPAction 以 WSDL 定义为准,不自动改写。</div>',
|
||||
test: '<div class="formgrid">' + field('客户端实例', '<select class="input"><option>TIPTOP-TEST</option><option>WMS-PROD</option><option>DBS-RPA</option></select>') + field('测试方式', '<select class="input"><option>健康检查</option><option>发送样例请求</option></select>') + field('样例数据', '<textarea rows="6" placeholder="粘贴标准 DTO 或选择已保存 Fixture"></textarea>') + field('Fixture', '<select class="input"><option>库存查询-两批号</option><option>不使用 Fixture</option></select>') + '</div><div class="actions" style="margin-top:14px"><button class="btn" data-run-test>开始测试</button><span class="muted" data-test-result></span></div>',
|
||||
'test-run': '<div class="notice">将使用当前草稿版本和标准 DTO Fixture 执行一次真实调用。写操作接口仅允许在测试环境试运行。</div><div class="field" style="margin-top:14px">' + field('选择 Fixture', '<select class="input"><option>库存查询-两批号</option><option>调拨单-单明细</option></select>') + '</div><div class="previewblock" style="margin-top:14px"><div class="previewtitle">调用摘要</div><pre>query_inventory · TIPTOP-TEST · v4\n预期:HTTP 200,Execution.Status code=0</pre></div><div class="actions" style="margin-top:14px"><button class="btn" data-run-test>执行试运行</button><span class="muted" data-test-result></span></div>',
|
||||
binding: '<div class="formgrid">' + field('业务能力', '<select class="input"><option>in_transit_transfer.query_inventory</option><option>in_transit_transfer.create_transfer</option></select>') + field('来源实例', '<input class="input" placeholder="例如 DBS-AWSBI">') + field('组织 / 租户', '<input class="input" placeholder="例如 TGHX">') + field('客户端实例', '<select class="input"><option>TIPTOP-TEST</option><option>WMS-PROD</option></select>') + field('接口版本', '<select class="input"><option>get_item_stock_list v3</option><option>wms_inventory_query v1</option></select>') + field('优先级', '<input class="input" value="10" type="number">') + '</div>',
|
||||
credential: '<div class="formgrid">' + field('引用编码', '<input class="input" placeholder="例如 tiptop-test">') + field('Secret 提供方', '<select class="input"><option>Vault</option><option>环境变量</option><option>KMS</option></select>') + field('Secret 路径', '<input class="input" placeholder="secret://integration/...">') + field('凭据类型', '<select class="input"><option>basic_auth</option><option>bearer</option><option>api_key</option></select>') + '</div><div class="notice" style="margin-top:14px">此处只登记引用路径,实际密钥由 Secret 管理系统提供。</div>',
|
||||
rotate: '<div class="notice">轮换会创建新版本 Secret,并在验证通过后切换客户端引用;旧版本保留用于回滚。</div><div class="formgrid" style="margin-top:14px">' + field('凭据引用', '<input class="input" value="secret://integration/tiptop-test" readonly>') + field('新版本说明', '<input class="input" placeholder="例如 2026-09 例行轮换">') + field('验证方式', '<select class="input"><option>连接测试通过后切换</option><option>手动确认后切换</option></select>') + '</div>',
|
||||
check: '<div class="check"><span class="checkicon">✓</span><div><b>客户端实例配置</b><small>4 个实例均有协议、地址和凭据引用</small></div></div><div class="check"><span class="checkicon">✓</span><div><b>接口版本完整性</b><small>12 个接口中 10 个已发布,2 个待处理</small></div></div><div class="check warn"><span class="checkicon">!</span><div><b>生产试运行</b><small>库存查询 v4 尚未完成生产环境验证</small></div></div>'
|
||||
};
|
||||
mbody.innerHTML = (forms[type] || '<div class="formgrid">' + field('名称', '<input class="input" placeholder="请输入名称">') + field('环境', '<select class="input"><option>测试</option><option>生产</option></select>') + field('说明', '<textarea rows="4" placeholder="补充说明"></textarea>') + '</div>') + '<div class="actions" style="margin-top:18px"><button class="btn" data-close>取消</button><button class="btn primary" data-save>' + (type === 'check' ? '关闭' : '保存') + '</button></div>';
|
||||
mbody.querySelectorAll('[data-run-test]').forEach(function (b) { b.addEventListener('click', function () { var r = mbody.querySelector('[data-test-result]'); if (r) { r.textContent = '成功 · HTTP 200 · 684 ms'; r.style.color = 'var(--ok)'; } notify('测试通过'); }); });
|
||||
}
|
||||
if (type === 'new-interface') { mbody.querySelector('[data-new-prev]').style.visibility = 'hidden'; }
|
||||
modal.classList.add('show');
|
||||
}
|
||||
document.querySelectorAll('[data-modal]').forEach(function (b) { b.addEventListener('click', function () { openModal(b.dataset.modal); }); });
|
||||
document.querySelectorAll('.back').forEach(function (x) { x.addEventListener('click', function (e) { if (e.target === x || e.target.closest('[data-close]')) x.classList.remove('show'); }); });
|
||||
mbody.addEventListener('click', function (e) {
|
||||
if (e.target.closest('[data-save]')) { modal.classList.remove('show'); notify('配置已保存'); }
|
||||
if (e.target.closest('[data-new-next]') || e.target.closest('[data-new-prev]')) {
|
||||
var panes = mbody.querySelectorAll('[data-new-pane]'), current = Array.prototype.findIndex.call(panes, function (p) { return p.style.display !== 'none'; });
|
||||
var next = e.target.closest('[data-new-next]') ? Math.min(3, current + 1) : Math.max(0, current - 1);
|
||||
panes.forEach(function (p, i) { p.style.display = i === next ? 'block' : 'none'; });
|
||||
mbody.querySelector('[data-new-prev]').style.visibility = next === 0 ? 'hidden' : 'visible';
|
||||
mbody.querySelector('[data-new-next]').style.display = next === 3 ? 'none' : 'inline-block';
|
||||
mbody.querySelector('[data-new-save]').style.display = next === 3 ? 'inline-block' : 'none';
|
||||
mbody.querySelectorAll('#new-flow span').forEach(function (s, i) { if (i % 2 === 0) s.className = i / 2 <= next ? 'badge info' : ''; });
|
||||
}
|
||||
if (e.target.closest('[data-new-save]')) { modal.classList.remove('show'); notify('接口草稿已创建,可进入接口定义详情继续配置'); show('interfaces'); }
|
||||
if (e.target.closest('[data-run-new-test]')) { var r = mbody.querySelector('[data-new-test-result]'); r.textContent = '连接成功 · 684 ms'; r.style.color = 'var(--ok)'; notify('连接测试通过'); }
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-step-target]').forEach(function (b) { b.addEventListener('click', function () { var target = b.dataset.stepTarget; var s = document.querySelector('.step[data-step="' + target + '"]'); if (s) s.click(); }); });
|
||||
document.querySelectorAll('.step').forEach(function (s) { s.addEventListener('click', function () { document.querySelectorAll('.step').forEach(function (x) { x.classList.toggle('active', x === s); }); document.querySelectorAll('.pane').forEach(function (p) { p.style.display = 'none'; }); var p = document.getElementById('pane-' + s.dataset.step); if (p) p.style.display = 'block'; document.getElementById('editor-title').textContent = 'get_item_stock_list · ' + ({ basic: '基本信息', request: '请求映射', response: '响应映射', publish: '测试与发布' }[s.dataset.step] || '接口配置'); }); });
|
||||
document.querySelectorAll('[data-drawer]').forEach(function (b) { b.addEventListener('click', function () { document.getElementById('dtitle').textContent = '配置详情'; document.getElementById('dsub').textContent = '只读信息 · 已脱敏'; document.getElementById('dbody').innerHTML = '<div class="notice">已打开详情。敏感凭据和原始报文不会回显。</div><div class="kv" style="margin-top:14px"><div class="kvitem"><label>状态</label><b>已发布</b></div><div class="kvitem"><label>更新时间</label><b>今天 09:42</b></div><div class="kvitem"><label>负责人</label><b>平台集成组</b></div><div class="kvitem"><label>审计追踪</label><b>可在调用记录查看</b></div></div>'; document.getElementById('drawer').classList.add('show'); }); });
|
||||
});
|
||||
</script></body></html>
|
||||
@@ -1,176 +0,0 @@
|
||||
# Shipping Notice Five-Stage Lifecycle Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Make `接收解析 -> 订单复核 -> 通知准备 -> 货代上传 -> 通知完成` the only user-visible Shipping Notice lifecycle, where completion means verifiable freight-upload success.
|
||||
|
||||
**Architecture:** Keep Process Gate, Intake, Run/Unit, upload attempt and technical progress as execution facts. Extend the existing shared read-model projection with `freight_upload`; inject `upload_complete` only when the canonical success predicate confirms task status, every reservation and an audit-backed succeeded upload attempt. API consumers receive `lifecycle_nodes`; `four_stage_nodes` remains a one-release compatibility alias.
|
||||
|
||||
**Tech Stack:** Flask, SQLAlchemy, pytest, Vue 3, TypeScript, Vue I18n, Vitest.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Define the server-side lifecycle and success predicate
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/lifecycle_projection.py`
|
||||
- Modify: `backend/app/services/shipping_notice/ui_state.py`
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_contract.py`
|
||||
- Test: `backend/tests/test_shipping_notice_ui_state.py`
|
||||
|
||||
- [ ] **Step 1: Add failing assertions for the new stage and completion boundary**
|
||||
|
||||
```python
|
||||
assert state['lifecycle_stage'] == 'freight_upload'
|
||||
assert [entry['code'] for entry in state['lifecycle_entries']][-2:] == [
|
||||
'freight_upload', 'upload_complete',
|
||||
]
|
||||
assert completed_state['lifecycle_stage'] == 'upload_complete'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run the focused UI-state test**
|
||||
|
||||
Run: `cd backend; pytest -q tests/test_shipping_notice_ui_state.py`
|
||||
Expected: failing assertions because the current implementation has four lifecycle stages.
|
||||
|
||||
- [ ] **Step 3: Implement one canonical predicate and five-stage projection**
|
||||
|
||||
```python
|
||||
def has_verified_upload_success(task: ShippingNotice) -> bool:
|
||||
return (
|
||||
task.upload_status == 'uploaded'
|
||||
and reservations_are_uploaded(task)
|
||||
and has_succeeded_upload_attempt(task)
|
||||
)
|
||||
|
||||
if has_verified_upload_success(task):
|
||||
lifecycle_stage = 'upload_complete'
|
||||
elif gate_code in LIFECYCLE_STAGE_BY_GATE:
|
||||
lifecycle_stage = LIFECYCLE_STAGE_BY_GATE[gate_code]
|
||||
```
|
||||
|
||||
Map `freight_upload_rpa`, `manual_upload_handoff`, and all upload-pending/failure/unknown reasons to `freight_upload`. Map only a verified success to `upload_complete`; update Gate `ui_placement.target_surface` to `freight_upload`.
|
||||
|
||||
- [ ] **Step 4: Re-run the focused UI-state test**
|
||||
|
||||
Run: `cd backend; pytest -q tests/test_shipping_notice_ui_state.py`
|
||||
Expected: PASS.
|
||||
|
||||
### Task 2: Evolve batch projection without breaking callers
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/shipping_processing_projection.py`
|
||||
- Modify: `backend/tests/test_shipping_processing_projection.py`
|
||||
- Modify: `backend/tests/test_shipping_processing_projection_stage4.py`
|
||||
|
||||
- [ ] **Step 1: Add failing batch-node assertions**
|
||||
|
||||
```python
|
||||
assert [node['code'] for node in payload['lifecycle_nodes']] == [
|
||||
'intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete',
|
||||
]
|
||||
assert payload['four_stage_nodes'] == payload['lifecycle_nodes']
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Implement `lifecycle_nodes` and compatibility alias**
|
||||
|
||||
```python
|
||||
lifecycle_nodes = _batch_lifecycle_nodes(work_items)
|
||||
payload['lifecycle_nodes'] = lifecycle_nodes
|
||||
payload['four_stage_nodes'] = lifecycle_nodes # deprecated compatibility field
|
||||
```
|
||||
|
||||
Use the shared success predicate when deriving an item lifecycle so technical `completed`, a PDF candidate, a reference number, cancellation, or archive cannot make an item complete.
|
||||
|
||||
- [ ] **Step 3: Run the projection tests**
|
||||
|
||||
Run: `cd backend; pytest -q tests/test_shipping_processing_projection.py tests/test_shipping_processing_projection_stage4.py tests/test_shipping_projection_cross_surface.py`
|
||||
Expected: PASS.
|
||||
|
||||
### Task 3: Make all frontend surfaces consume five lifecycle stages
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/features/chat/types/shipping.api.types.ts`
|
||||
- Modify: `frontend/src/features/chat/shipping/shippingStepper.ts`
|
||||
- Modify: `frontend/src/features/chat/components/shipping/ShippingConversationProcessingCard.vue`
|
||||
- Modify: `frontend/src/features/chat/views/ShippingOrderReviewView.vue`
|
||||
- Modify: `frontend/src/features/workspace/shipping-task-center/ShippingTaskCenterPage.vue`
|
||||
- Modify: `frontend/src/features/shipping-progress/components/WorkbenchProgressGrouped.vue`
|
||||
- Test: `frontend/src/features/chat/shipping/shippingStepper.spec.ts`
|
||||
- Test: `frontend/src/features/chat/views/ShippingOrderReviewView.spec.ts`
|
||||
- Test: `frontend/src/features/chat/components/shipping/ShippingConversationProcessingCard.spec.ts`
|
||||
|
||||
- [ ] **Step 1: Add failing five-stage type and rendering tests**
|
||||
|
||||
```ts
|
||||
expect(resolveShippingWorkflowSteps({ ui_state: { steps } })).toHaveLength(5)
|
||||
expect(wrapper.text()).toContain('货代上传')
|
||||
expect(wrapper.text()).toContain('通知完成')
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Update shared types and Stepper**
|
||||
|
||||
Add `'freight_upload'` to `LifecycleWorkbenchStage`, stage-node DTOs and the five label-key array. Prefer `lifecycleNodes`; retain the old field only as an API fallback.
|
||||
|
||||
- [ ] **Step 3: Split the lifecycle workbench surfaces**
|
||||
|
||||
`freight_upload` hosts Excel download, RPA retry/poll, manual evidence registration and unknown-result reconciliation. `upload_complete` becomes read-only success evidence: uploaded time, freight receipt/reference, succeeded attempt and reservation summary. Do not move action authorization into the frontend.
|
||||
|
||||
- [ ] **Step 4: Ensure polling does not stop at freight-upload**
|
||||
|
||||
Keep polling while `lifecycleStage === 'freight_upload'`; stop only after verified `upload_complete`, cancellation, archive, or explicit terminal failure.
|
||||
|
||||
- [ ] **Step 5: Run focused frontend tests**
|
||||
|
||||
Run: `cd frontend; npm run test:unit -- shippingStepper.spec.ts ShippingOrderReviewView.spec.ts ShippingConversationProcessingCard.spec.ts`
|
||||
Expected: PASS.
|
||||
|
||||
### Task 4: Synchronize i18n and documentation
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/locales/zh-CN/chat.json`
|
||||
- Modify: `frontend/src/locales/zh-TW/chat.json`
|
||||
- Modify: `frontend/src/locales/en/chat.json`
|
||||
- Modify: `frontend/src/locales/th/chat.json`
|
||||
- Modify: `frontend/src/locales/zh-CN/workspace.json`
|
||||
- Modify: `frontend/src/locales/zh-TW/workspace.json`
|
||||
- Modify: `frontend/src/locales/en/workspace.json`
|
||||
- Modify: `frontend/src/locales/th/workspace.json`
|
||||
- Modify: `docs/demand.md`
|
||||
- Modify: `docs/tec.md`
|
||||
- Modify: `docs/funclist.md`
|
||||
- Modify: `docs/features/shipping-notice/technical.md`
|
||||
- Modify: `docs/features/shipping-notice/business.md`
|
||||
|
||||
- [ ] **Step 1: Add all four-language stage and work-surface labels**
|
||||
|
||||
Add `freightUpload` and descriptions for upload in progress, manual upload pending, failure, and unknown result. Retain `uploadComplete` text as `通知完成`; its description must require verified success.
|
||||
|
||||
- [ ] **Step 2: Update the authoritative business and technical contracts**
|
||||
|
||||
Replace four-stage wording with the five-stage order. Document the single success predicate, unknown-result handling, `lifecycle_nodes` compatibility period, and the rule that completed lists/statistics use verified success only.
|
||||
|
||||
- [ ] **Step 3: Validate locale JSON**
|
||||
|
||||
Run: `Get-ChildItem frontend/src/locales/*/{chat,workspace}.json | ForEach-Object { Get-Content -Raw $_ | ConvertFrom-Json | Out-Null }`
|
||||
Expected: no output and exit code 0.
|
||||
|
||||
### Task 5: Full verification
|
||||
|
||||
**Files:**
|
||||
- Verify all modified files.
|
||||
|
||||
- [ ] **Step 1: Run focused backend regression**
|
||||
|
||||
Run: `cd backend; pytest -q tests/test_shipping_notice_ui_state.py tests/test_shipping_upload_attempt.py tests/test_shipping_manual_upload_evidence.py tests/test_shipping_upload_unknown_state.py tests/test_shipping_processing_projection.py tests/test_shipping_processing_projection_stage4.py tests/test_shipping_projection_cross_surface.py`
|
||||
Expected: PASS.
|
||||
|
||||
- [ ] **Step 2: Build frontend**
|
||||
|
||||
Run: `cd frontend; npm run build`
|
||||
Expected: PASS.
|
||||
|
||||
- [ ] **Step 3: Check diff integrity**
|
||||
|
||||
Run: `git diff --check; git status --short`
|
||||
Expected: no whitespace errors; status lists only the planned files plus pre-existing user changes.
|
||||
@@ -1,264 +0,0 @@
|
||||
# Shipping Profile Anchor Frame Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** 让坐标 Profile 能在同一稳定版式因动态内容导致主表纵向平移时,使用冻结的锚点坐标框架完成确定性匹配和取值,而不影响未启用该能力的模板。
|
||||
|
||||
**Architecture:** 在现有 `OrderCoordinateProfile` 中增加可选的扁平 `coordinate_model` 声明(`type`、`anchors`、`max_translate_x`、`max_translate_y`)。matcher 从当前 Layout 的唯一锚点和主表结构计算受限的平移变换;同一变换贯穿表头观测、主表定位、订单头字段和值框、订单行坐标重建,禁止建立第二套偏移估算机制。
|
||||
|
||||
**Tech Stack:** Flask、Pydantic、SQLAlchemy JSON Profile、pytest、Vue 3、TypeScript、Vue I18n、Vitest。
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 原 PDF 是不可变事实;匹配和解析所需的页级坐标必须通过 `ensure_on_demand_coordinate_evidence()` 获取。
|
||||
- 未声明 `coordinate_model.type = anchor_frame` 的 Profile 必须逐位保持现有 matcher、取值、阈值和候选排序行为。
|
||||
- 不允许按订单号、客户名、文件名或固定偏移量写代码;不建立按 PDF 的坐标变体。
|
||||
- 仅允许平移;锚点不存在、不唯一、位移超过模板上限、关键结构冲突或多个 Profile 合格时必须 `review_required`。
|
||||
- Schema 是唯一业务字段契约;Dify 不参与模板选择、坐标变换或正式值取值。Dify 配置由用户维护,本项目仅在收尾文档说明其边界。
|
||||
- 不改数据库表结构、不新增依赖、不修改其他 Profile 数据;FOX MX Profile 现版数据在后端能力通过回归后再单独受控更新。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 冻结 Profile 契约与变换审计输出
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/document_layout/order_profile.py`
|
||||
- Modify: `backend/app/services/shipping_notice/document_layout/order_profile_matcher.py`
|
||||
- Test: `backend/tests/test_shipping_order_profile_matcher.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces `CoordinateModel` / `AnchorFrameCoordinateModel`,作为 `OrderCoordinateProfile.coordinate_model`。
|
||||
- Produces `CoordinateTransform`,包含 `status`、`translate_x`、`translate_y`、`anchor_ids`、`reason_codes`;仅含配置身份与数值,不含正文。
|
||||
- Extends `ProfileMatchCandidate` with optional `coordinate_transform`.
|
||||
|
||||
- [ ] **Step 1: 写入失败用例**
|
||||
|
||||
```python
|
||||
def test_anchor_frame_matches_same_structure_after_bounded_vertical_translation():
|
||||
profile = _with_signature(_profile('PO_A', coordinate_model={
|
||||
'type': 'anchor_frame',
|
||||
'anchors': [{'anchor_id': 'title', 'text': 'PURCHASE ORDER', 'region': {'x0': .1, 'y0': .05, 'x1': .9, 'y1': .15}}],
|
||||
'max_translate_x': .01, 'max_translate_y': .04,
|
||||
}), _layout())
|
||||
result = match_frozen_coordinate_profiles(profiles=[profile], layout=_translated_layout(.03))
|
||||
assert result.status == 'unique_match'
|
||||
assert result.candidates[0].coordinate_transform['translate_y'] == .03
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 验证 RED**
|
||||
|
||||
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py -k anchor_frame`
|
||||
|
||||
Expected: FAIL,因为 Profile 契约尚不接受 `coordinate_model`,且 matcher 未输出变换。
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
```python
|
||||
class AnchorFrameCoordinateModel(OrderProfileModel):
|
||||
type: Literal['anchor_frame']
|
||||
anchors: list[AnchorRule] = Field(min_length=1, max_length=4)
|
||||
max_translate_x: float = Field(default=.03, ge=0, le=.15)
|
||||
max_translate_y: float = Field(default=.06, ge=0, le=.20)
|
||||
|
||||
class CoordinateModel(OrderProfileModel):
|
||||
type: Literal['legacy', 'anchor_frame'] = 'legacy'
|
||||
anchor_frame: AnchorFrameCoordinateModel | None = None
|
||||
```
|
||||
|
||||
在 matcher 中仅当 `anchor_frame` 明确启用时从唯一静态锚点计算一致的 X/Y 平移;超界、缺失、歧义或多个锚点不一致必须为硬失败原因。对当前观察表头和主表 bbox 应用该平移后才评分;`legacy` 路径不改。
|
||||
|
||||
- [ ] **Step 4: 验证 GREEN 与旧逻辑回归**
|
||||
|
||||
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py`
|
||||
|
||||
Expected: PASS;新增用例覆盖受限平移、缺锚点、歧义锚点、超界平移和 legacy 不变。
|
||||
|
||||
### Task 2: 让已选变换贯穿 Profile 行重建
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/order_extraction_workflow.py`
|
||||
- Modify: `backend/app/services/shipping_notice/document_layout/coordinate_table_reconstruction.py`
|
||||
- Test: `backend/tests/test_shipping_coordinate_table_reconstruction.py`
|
||||
- Test: `backend/tests/test_shipping_generic_order_gate.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes `ProfileMatchResult` 中唯一选中 Profile 的 `coordinate_transform`。
|
||||
- Extends `reconstruct_coordinate_profile_rows(..., coordinate_transform: dict | None = None)`。
|
||||
- Produces仅以同一运行时平移投影后的表区/行区重建结果。
|
||||
|
||||
- [x] **Step 1: 写入失败用例**
|
||||
|
||||
```python
|
||||
def test_reconstruction_uses_selected_anchor_frame_translation_for_all_subrows():
|
||||
rows = reconstruct_coordinate_profile_rows(
|
||||
characters=_translated_rows(.03), table_bbox=_page_bbox(),
|
||||
table_region=_legacy_region(), line_layouts=_layouts(),
|
||||
coordinate_transform={'status': 'applied', 'translate_x': 0, 'translate_y': .03},
|
||||
)
|
||||
assert rows[0].fields['customer_po_line_no'] == '00010'
|
||||
```
|
||||
|
||||
- [x] **Step 2: 验证 RED**
|
||||
|
||||
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_coordinate_table_reconstruction.py -k anchor_frame`
|
||||
|
||||
Expected: FAIL,因为重建函数没有接收或应用运行时变换。
|
||||
|
||||
- [x] **Step 3: 最小实现**
|
||||
|
||||
为坐标重建增加仅限 `status=applied` 的平移投影;校验平移数字有限且投影框仍在页内,非法变换返回现有的不可重建结果。工作流必须从共同 matcher 的唯一结果传递同一 `coordinate_transform`,不能重新计算、不能按 raw table 猜测偏移。
|
||||
|
||||
- [x] **Step 4: 验证 GREEN 与路由门禁**
|
||||
|
||||
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_coordinate_table_reconstruction.py tests/test_shipping_generic_order_gate.py`
|
||||
|
||||
Expected: PASS;缺失/非法变换保持 `coordinate_evidence_unavailable → review_required`,其他 Profile 路由不变。
|
||||
|
||||
### Task 3: 管理端声明与复核端审计展示
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/features/admin/types/shipping-order-document-profile.types.ts`
|
||||
- Modify: `frontend/src/features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue`
|
||||
- Modify: `frontend/src/features/chat/types/shipping.api.types.ts`
|
||||
- Modify: `frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.vue`
|
||||
- Modify: `frontend/src/locales/zh-CN/chat.json`
|
||||
- Modify: `frontend/src/locales/zh-TW/chat.json`
|
||||
- Modify: `frontend/src/locales/en/chat.json`
|
||||
- Modify: `frontend/src/locales/th/chat.json`
|
||||
- Test: `frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.spec.ts`
|
||||
|
||||
**Interfaces:**
|
||||
- Admin payload accepts optional `coordinate_model`,默认 `legacy`,只有管理员显式确认时才提交 `anchor_frame`。
|
||||
- Review DTO exposes `coordinate_transform` only for the selected/current candidate and reason codes only.
|
||||
|
||||
- [x] **Step 1: 写入失败的前端展示用例**
|
||||
|
||||
```ts
|
||||
it('shows anchor-frame translation only in the technical template-match detail', () => {
|
||||
const wrapper = mount(ReviewProfileMatchPanel, { props: { profileMatch: anchorFrameMatch } })
|
||||
expect(wrapper.text()).toContain('锚点坐标框架')
|
||||
expect(wrapper.text()).toContain('纵向平移')
|
||||
})
|
||||
```
|
||||
|
||||
- [x] **Step 2: 验证 RED**
|
||||
|
||||
Run: `cd frontend; npm run test:unit -- ReviewProfileMatchPanel.spec.ts`
|
||||
|
||||
Expected: FAIL,因为 DTO 和面板尚未呈现坐标框架诊断。
|
||||
|
||||
- [x] **Step 3: 最小实现**
|
||||
|
||||
在现有 Profile 编辑器增加受控的“相对锚点坐标框架”选项:默认关闭,启用时要求至少一个唯一静态 AnchorRule 与 X/Y 上限。复核面板只展示模式、是否应用、X/Y 平移和稳定 reason code;不显示原始字符、不显示完整 PDF 坐标、不新增终端用户操作。
|
||||
|
||||
- [x] **Step 4: 验证 GREEN、四语一致和构建**
|
||||
|
||||
Run: `cd frontend; npm run test:unit -- ReviewProfileMatchPanel.spec.ts; npm run build`
|
||||
|
||||
Expected: PASS;所有新增 i18n key 存在于四种语言,构建无 TypeScript 错误。
|
||||
|
||||
### Task 4: 当前 FOX MX 现版数据、端到端回归与正式文档
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/demand.md`
|
||||
- Modify: `docs/tec.md`
|
||||
- Modify: `docs/funclist.md`
|
||||
- Modify: `docs/features/shipping-notice/technical.md`
|
||||
- Modify: `docs/features/shipping-notice/business.md`
|
||||
- Modify: current database Profile `61` only after Task 1-3 pass
|
||||
- Test: `backend/tests/test_shipping_order_profile_matcher.py`
|
||||
- Test: `backend/tests/test_shipping_coordinate_table_reconstruction.py`
|
||||
- Test: `frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.spec.ts`
|
||||
|
||||
**Interfaces:**
|
||||
- FOX MX current Profile uses `coordinate_model.type = anchor_frame`; it has no order-number-specific rule and no stored A/B variant.
|
||||
- Dify document only explains that Dify must not participate in this deterministic path; it contains no credentials or platform mutation.
|
||||
|
||||
- [ ] **Step 1: 增加真实 Layout 回归测试**
|
||||
|
||||
```python
|
||||
def test_fox_mx_anchor_frame_matches_baseline_and_dynamic_vertical_shift(app):
|
||||
assert _match_profile_layout(profile_id=61, layout_id=124).status == 'unique_match'
|
||||
assert _match_profile_layout(profile_id=61, layout_id=346).status == 'unique_match'
|
||||
assert _match_profile_layout(profile_id=61, layout_id=344).status == 'unique_match'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 验证 RED**
|
||||
|
||||
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py -k fox_mx_anchor_frame`
|
||||
|
||||
Expected: FAIL,直到当前 Profile 明确声明 `anchor_frame` 且现版签名/定义一致。
|
||||
|
||||
- [ ] **Step 3: 受控更新现版 Profile 数据**
|
||||
|
||||
只在 Task 1-3 的全量相关测试通过后,事务更新 Profile 61 的 `definition_json`、结构指纹、checksum、matching signature 及其 validation run;不新建版本。变换锚点仅取固定标题/表头等静态文本,基线为 `4210007483.pdf`,回归样本为 `4210012208.pdf` 和 `4210012210.pdf`。
|
||||
|
||||
- [ ] **Step 4: 完成端到端验证和正式文档**
|
||||
|
||||
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py tests/test_shipping_coordinate_table_reconstruction.py tests/test_shipping_order_field_extraction.py tests/test_shipping_generic_order_gate.py`
|
||||
|
||||
Run: `cd frontend; npm run test:unit -- ReviewProfileMatchPanel.spec.ts; npm run build`
|
||||
|
||||
Run: `git diff --check`
|
||||
|
||||
Expected: 全部 PASS;正式文档包含架构、失败闭环、其他模板隔离、FOX MX 校准规则及 Dify 手动配置边界。
|
||||
|
||||
## Phase Review Gates
|
||||
|
||||
| 阶段 | 关键节点 | 放行证据 |
|
||||
| --- | --- | --- |
|
||||
| 1 | 范围/数据基线/既有能力 | 本计划、Profile 61 回滚校验、2208/2210 差异证据、未影响其他 Profile 的 DB 查询 |
|
||||
| 2 | 契约/Matcher/行重建 | RED→GREEN 测试、legacy 回归、缺锚/歧义/超界 fail-closed 测试 |
|
||||
| 3 | 管理端/复核端/i18n | Vitest、四语言 JSON 解析、前端 build、无新增用户端越权动作 |
|
||||
| 4 | 数据/全链路/文档 | 三份 FOX PDF 真实 Layout 回归、相关后端测试、前端 build、`git diff --check`、文档一致性检查 |
|
||||
|
||||
## Phase 1 Review Record
|
||||
|
||||
- [x] 原因确认:2026-08-20 将 Profile 61 的表格/表头/行布局整体下移 `0.0124703088`,使 Layout 344 命中但 Layout 346 发生 `profile_header_signature_conflict`。
|
||||
- [x] 基线恢复:Profile 61 与 validation run #150 已恢复至 `4210007483.pdf` 对应的历史冻结定义;Layout 124 和 346 已复算为 `unique_match`。
|
||||
- [x] 范围确认:不采用按 PDF 的 A/B 变体,不改变全局 matcher 阈值,不改 Dify,不新增数据库表。
|
||||
- [x] 影响确认:本阶段仅修改计划文档;已有数据库恢复仅涉及 Profile 61,其他 6 个 Profile 未写入。
|
||||
- [x] 下一阶段准入:已具备最小契约、测试和隔离边界,可进入后端 TDD。
|
||||
|
||||
## Phase 2 Review Record
|
||||
|
||||
- [x] 契约/Matcher:`legacy` 默认路径保持 `coordinate_transform=None`;`anchor_frame` 仅由唯一静态锚点计算有限平移,缺失、歧义、不一致、超界均 fail-closed。
|
||||
- [x] 评分一致性:matcher 对当前观察和七维结构评分均使用不回写冻结签名的平移副本;签名校验仍使用冻结签名原文。
|
||||
- [x] 行重建:共同 matcher 选中的变换只经 Profile 身份校验后传入工作流;页级裁剪、表区、物理行、字段区、终止/排除区使用同一内存投影。
|
||||
- [x] Fail-closed:非法/缺失变换不回退旧绝对坐标,保持 `order_profile_coordinate_reconstruction_unavailable -> coordinate_evidence_unavailable`。
|
||||
- [x] 回归证据:matcher 24 passed;坐标重建 40 passed;通用路由门禁 22 passed。
|
||||
- [x] 范围 Review:未新增数据库表、依赖、Profile 版本或 Dify 配置;未改变订单头第二套取值机制;其他 legacy Profile 调用点默认行为不变。
|
||||
- [x] 下一阶段准入:后端变换闭环已完成并通过阶段验收,进入管理端/复核端/i18n 实现。
|
||||
|
||||
## Phase 3 Review Record
|
||||
|
||||
- [x] DTO 契约:前端与后端统一使用扁平 `coordinate_model`(`type`、`anchors`、`max_translate_x`、`max_translate_y`),不保留嵌套变体。
|
||||
- [x] 管理端:默认 `legacy`;仅显式选择 `anchor_frame` 才提交配置;锚点为空、无坐标或 X/Y 上限越界时保存门禁阻断;legacy 不写新字段。
|
||||
- [x] 复核端:仅管理员技术详情展示模式、应用状态、X/Y 平移和 reason code;普通用户不显示坐标框架诊断;不输出原始正文或完整坐标。
|
||||
- [x] 四语言:zh-CN、zh-TW、en、th 均补齐 `coordinateModel` 与管理端配置文案。
|
||||
- [x] Header 闭环:订单头字段读取消费 matcher 已选同一 `coordinate_transform`,订单号/日期/币种不再独立使用旧绝对框。
|
||||
- [x] 自动化证据:后端相关测试 123 passed;复核投影测试 3 passed;前端 ReviewPanel 5 passed;`npm run build` passed。
|
||||
- [x] 范围 Review:未新增数据库表、依赖、Dify 配置或用户端动作;legacy Profile 和其他模板默认路径保持不变。
|
||||
- [x] 下一阶段准入:阶段 3 合规 Review 通过,可进入现版 FOX MX Profile 61 受控数据校准。
|
||||
|
||||
## Phase 4 Review Record
|
||||
|
||||
- [x] 数据基线复核:Profile 61 当前 `definition_json` 与历史 revision 51 逐项一致;附件 `4210007483.pdf` 的表头、订单号标签、订单号值框与现版坐标一致,未发现需要恢复的坐标。
|
||||
- [x] 订单号根因:PDFium 原生字符将 `ORDER NO.:` 嵌在整行文本中;旧的锚点匹配将整行作为 `exact` 比较对象,导致锚点无法命中,根因不是 Profile 坐标偏移。
|
||||
- [x] 最小修复:matcher 在视觉行内定位锚点子串并使用锚点自身 bbox;未改变 Profile 61 的定义、字段/表格坐标、版本号或其他 Profile 数据。
|
||||
- [x] 真实回归:Layout 124 为 `unique_match`(0.985938),Layout 346 为同 Profile `unique_match`(0.889008),Layout 344 为 `evidence_insufficient` 并进入 Review;禁止证据不足时高分自动命中。
|
||||
- [x] 订单头取值:Layout 124 确定性读出 `customer_po_number=4210007483`,状态 `confirmed`,来源 `pdf_coordinate`;日期、币种、目的地等绑定字段均通过。
|
||||
- [x] 范围与数据隔离:未新建 Profile 版本、未更新 Profile 61 数据、未修改其他 Profile、未修改 Dify 配置;数据库写入范围为零。
|
||||
- [x] 下一阶段准入:后端 matcher、订单头/订单行相关回归及前端构建完成后,进入最终阶段验收报告。
|
||||
|
||||
## Final Phase Acceptance Report
|
||||
|
||||
| 阶段 | 验收结果 | 证据 |
|
||||
| --- | --- | --- |
|
||||
| 4A 基线核验 | 通过 | Profile 61 当前定义与 revision 51 一致;PDF 实测坐标未支持坐标回写 |
|
||||
| 4B matcher 修复 | 通过 | `tests/test_shipping_order_profile_matcher.py`:25 passed;行内 `ORDER NO.:` 锚点可定位自身字符框 |
|
||||
| 4C 影响 Review | 通过 | Layout 124/346 唯一匹配;Layout 344 `evidence_insufficient`;订单号 `4210007483` confirmed |
|
||||
| 4D 数据边界 | 通过 | version=1 保持不变;未新建版本、未修改其他 Profile、未写入 Profile 61 数据、未修改 Dify |
|
||||
| 5 全链路验收 | 通过 | 后端 124 passed;ReviewPanel 5 passed;前端 `npm run build` 通过;`git diff --check` 通过 |
|
||||
|
||||
结论:该阶段工作满足“原 PDF 不可变、Schema 唯一契约、证据不足进入 Review、无坐标变体、其他模板隔离”的要求。订单号识别问题由行内锚点匹配修复解决,不通过修改现版 Profile 坐标规避。
|
||||
@@ -1,182 +0,0 @@
|
||||
# 延后发货通知单号与库存结果重读 Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** 仅在首次发货 Excel 成功生成时为既有 `ShippingNotice` 分配业务单号,并提供不触发 RPA 的库存结果重读 Gate 动作。
|
||||
|
||||
**Architecture:** `ShippingNotice` 继续作为建单、库存和匹配阶段的内部流程载体;新 Notice 在 Excel 前保持 `business_no=None`。首次 Excel Artifact 生成时,同一事务内锁定明细归属、生成 Artifact 并为该 Notice 分配编号。库存重读复用既有快照查询、身份校验、挂接和库存加载函数,不写 RPA trigger。
|
||||
|
||||
**Tech Stack:** Flask、SQLAlchemy 2.0、Alembic、pytest、Vue 3、TypeScript、Vitest。
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 不新增发货通知单实体、平行表或第二套编号体系。
|
||||
- 一个 Notice 可通过既有 Reservation/Artifact 明细关联覆盖多条订单明细;有效 Reservation 不得重复归属其他 Notice。
|
||||
- 新 Notice 仅在首个 Excel 成功生成的事务中分配 `business_no`;历史数据兼容读取不变。
|
||||
- `reload_inventory_result` 不得调用 `retry_rpa`、写 trigger 或新建 RPA Attempt。
|
||||
- 新增前端文案同步 zh-CN、zh-TW、en、th 四语言;后端业务错误遵循 `AppError` envelope。
|
||||
- 保留并避开工作区与本需求无关的未提交改动。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 延后 Notice 编号至首个 Excel 生成
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/customer_identity_gate.py`
|
||||
- Modify: `backend/app/services/shipping_notice/export.py`
|
||||
- Modify: `backend/app/services/shipping_notice/business_numbering_service.py`
|
||||
- Modify: `backend/tests/test_shipping_customer_identity_gate.py`
|
||||
- Modify: `backend/tests/test_shipping_excel_template.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `confirm_task_customer(task, customer_id, actor_id)`、`generate_shipment_excel(task)`。
|
||||
- Produces: 客户确认后 `task.business_no is None`;首个成功 Artifact 创建后 `task.business_no` 非空且可由既有货代接口使用。
|
||||
|
||||
- [ ] **Step 1: 写入失败测试**
|
||||
|
||||
```python
|
||||
def test_confirm_customer_does_not_assign_business_number(app):
|
||||
with app.app_context():
|
||||
task, customer, user = _seed_task()
|
||||
confirmed = confirm_task_customer(task, customer_id=customer.id, actor_id=user.id)
|
||||
assert confirmed.customer_id == customer.id
|
||||
assert confirmed.business_no is None
|
||||
|
||||
|
||||
def test_first_export_assigns_notice_business_number(app, tmp_path):
|
||||
with app.app_context():
|
||||
task = _seed_exportable_task_without_business_number(tmp_path)
|
||||
artifact = generate_shipment_excel(task)
|
||||
assert task.business_no is not None
|
||||
assert artifact.task_id == task.id
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 验证失败原因正确**
|
||||
|
||||
Run: `cd backend; pytest tests/test_shipping_customer_identity_gate.py::test_confirm_customer_does_not_assign_business_number tests/test_shipping_excel_template.py::test_first_export_assigns_notice_business_number -q`
|
||||
|
||||
Expected: FAIL,因为客户确认路径仍分配编号,或导出路径未分配编号。
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
```python
|
||||
# customer_identity_gate.py
|
||||
# 仅写入客户确认事实;不得调用 assign_notice_business_number。
|
||||
|
||||
# export.py,在首个 Artifact 持久化的同一事务中:
|
||||
if not task.business_no:
|
||||
assign_notice_business_number(task)
|
||||
```
|
||||
|
||||
保留已有 `assert_notice_has_no_export_artifact` 约束,确保同一 Notice 的首个 Artifact 是唯一编号触发点;分批导出必须由既有波次服务创建新 Notice,禁止在同一 Notice 重生成第二个有效 Artifact。
|
||||
|
||||
- [ ] **Step 4: 验证通过**
|
||||
|
||||
Run: `cd backend; pytest tests/test_shipping_customer_identity_gate.py tests/test_shipping_business_numbering.py tests/test_shipping_excel_template.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
### Task 2: 增加无 RPA 的库存结果重读 Gate 动作
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_contract.py`
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_executor.py`
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_projection.py`
|
||||
- Modify: `backend/app/services/shipping_notice/error_explainability_contract.py`
|
||||
- Test: `backend/tests/test_shipping_process_gate_contract.py`
|
||||
- Test: `backend/tests/test_shipping_process_gate_retry_cap.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `reload_inventory_result`(`inventory_preparation` Gate 的用户动作)。
|
||||
- Produces: 命中有效快照时挂接并加载库存;无快照时返回 `blocked_retryable`,不写 RPA trigger/Attempt。
|
||||
|
||||
- [ ] **Step 1: 写入失败测试**
|
||||
|
||||
```python
|
||||
def test_inventory_preparation_allows_reload_without_rpa_trigger():
|
||||
assert action_belongs_to_gate(
|
||||
gate_code='inventory_preparation', action_code='reload_inventory_result',
|
||||
) is True
|
||||
|
||||
|
||||
def test_reload_inventory_result_reuses_snapshot_without_new_rpa_attempt(app, monkeypatch):
|
||||
task, execution, snapshot = _seed_timeout_task_with_matching_snapshot()
|
||||
result = _dispatch_gate_action(execution, 'reload_inventory_result')
|
||||
assert result['outcome'] == 'passed'
|
||||
assert task.inventory_snapshot_id == snapshot.id
|
||||
assert _rpa_attempt_count(task) == 0
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 验证失败原因正确**
|
||||
|
||||
Run: `cd backend; pytest tests/test_shipping_process_gate_contract.py -q`
|
||||
|
||||
Expected: FAIL,因为 `reload_inventory_result` 未注册为 Gate 动作。
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
```python
|
||||
def _handle_reload_inventory_result(*, execution, gate, payload):
|
||||
# 使用 _try_reuse_inventory_snapshot 的查询、身份校验与库存加载行为;
|
||||
# 不设置 mode='retry_rpa',不调用 ensure_inventory_via_rpa。
|
||||
response = ensure_inventory({**_task_payload(execution, payload), 'mode': 'auto'})
|
||||
return _tool_outcome(action_code='reload_inventory_result', response=response, ...)
|
||||
```
|
||||
|
||||
当 `inventory_preparation` 的原因是 RPA 超时/耗尽时,投影将 `reload_inventory_result` 作为主动作;`retry_inventory_preparation` 作为明确的“重新获取库存(重新运行 RPA)”替代动作。
|
||||
|
||||
- [ ] **Step 4: 验证通过**
|
||||
|
||||
Run: `cd backend; pytest tests/test_shipping_process_gate_contract.py tests/test_shipping_process_gate_retry_cap.py tests/test_shipping_notice_inventory_rpa_workflow.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
### Task 3: 工作台文案、投影与回归验证
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/locales/zh-CN/workspace.json`
|
||||
- Modify: `frontend/src/locales/zh-TW/workspace.json`
|
||||
- Modify: `frontend/src/locales/en/workspace.json`
|
||||
- Modify: `frontend/src/locales/th/workspace.json`
|
||||
- Modify: `frontend/src/features/shipping-progress/actionPresentation.ts`
|
||||
- Modify: `frontend/src/features/chat/components/shipping-review/ReviewCurrentProcessingCard.spec.ts`
|
||||
- Modify: `docs/features/shipping-notice/technical.md`
|
||||
- Modify: `docs/funclist.md`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 后端下发的 `reload_inventory_result` 和 Artifact 成功后才出现的 Notice `business_no`。
|
||||
- Produces: 主按钮显示“重新读取库存结果”;备用按钮明确为“重新获取库存(重新运行 RPA)”;Excel 前不展示单号。
|
||||
|
||||
- [ ] **Step 1: 写入失败测试**
|
||||
|
||||
```ts
|
||||
it('renders reload result as the timeout primary action', async () => {
|
||||
const wrapper = mount(ReviewCurrentProcessingCard, {
|
||||
props: { primaryAction: { code: 'reload_inventory_result' } },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
expect(wrapper.text()).toContain('重新读取库存结果');
|
||||
});
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 验证失败原因正确**
|
||||
|
||||
Run: `cd frontend; npm run test -- ReviewCurrentProcessingCard.spec.ts`
|
||||
|
||||
Expected: FAIL,因为该动作尚无前端展示映射或翻译。
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
新增四语言 label,复用动作展示注册表;仅更改此动作及现有 RPA 重试动作的用户可见标签。更新技术文档与功能清单的单号时机、明细归属和库存重读说明。
|
||||
|
||||
- [ ] **Step 4: 验证通过**
|
||||
|
||||
Run: `cd frontend; npm run test -- ReviewCurrentProcessingCard.spec.ts; npm run build`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
## Plan Self-Review
|
||||
|
||||
- 覆盖规格:Task 1 覆盖延后编号;Task 2 覆盖无 RPA 快照读取与超时主动作;Task 3 覆盖 UI、四语言与文档。
|
||||
- 未新增实体、编号表或新的 RPA 流程;复用现有 Notice、Artifact、Reservation、快照和 Gate 机制。
|
||||
- 计划未采用未定义的跨域服务;实际代码以现有 `ensure_inventory(mode='auto')` 作为库存快照复用入口。
|
||||
@@ -1,124 +0,0 @@
|
||||
# Reservation Vendor Comments Anchor Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** 已标注 Reservation ID 专区的订单模板,跨页在 `Vendor Comments` 与首次 `Terms and Condition(s)` 之间确定性读取 Reservation,而不依赖固定页码或坐标。
|
||||
|
||||
**Architecture:** `reservation_id_region` 继续作为该能力的显式启用开关,保留原几何数据以兼容历史草稿/画布,但运行时不再消费其 `page_no/region`。运行时为已启用模板补齐全部 PDF 页的坐标证据,以视觉阅读顺序定位起止锚点,截取边界内文本,再复用现有 Reservation 候选解析、行号归属和冲突 Review 契约。
|
||||
|
||||
**Tech Stack:** Flask、Python、PDF/OCR 坐标证据、pytest。
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 只对包含 `definition.reservation_id_region` 的已选中模板启用;未标注模板不得全文扫描或改变结果。
|
||||
- 起点为首次 `Vendor Comments`;终点为其后首次 `Terms and Condition` 或 `Terms and Conditions`,匹配忽略大小写、冒号和复数差异。
|
||||
- 区块允许跨页;不存在起点、终点或二者顺序异常时不猜值,稳定进入 Review。
|
||||
- Reservation 仍仅接受带 `Reservation` 标签的 5 位或 10 位纯数字;行号、冲突和越界处理复用 `reservation_region.py`。
|
||||
- 原 PDF 不可变;页坐标只通过 `ensure_on_demand_coordinate_evidence(..., page_nos=None)` 取得;不新增依赖、表结构或 Dify 改动。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Vendor Comments 区块提取契约
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/reservation_region.py`
|
||||
- Test: `backend/tests/test_shipping_notice_reservation_id.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces `extract_reservation_from_vendor_comments_pages(pages: list[tuple[int, list[dict[str, Any]]]]) -> tuple[list[dict[str, object]], str | None]`。
|
||||
- `str | None` 是 `None`、`vendor_comments_anchor_missing` 或 `terms_and_conditions_anchor_missing`;调用方据此决定 Review。
|
||||
|
||||
- [ ] **Step 1: Write failing tests**
|
||||
|
||||
```python
|
||||
def test_vendor_comments_window_crosses_pages_and_stops_at_first_terms_heading():
|
||||
candidates, reason = extract_reservation_from_vendor_comments_pages([
|
||||
(1, _glyph_lines('Vendor Comments:', 'Reservation#33008')),
|
||||
(2, _glyph_lines('Reservation#3000098851 for line#1', 'Terms and Conditions:', 'Reservation#99999')),
|
||||
])
|
||||
assert reason is None
|
||||
assert [item['value'] for item in candidates] == ['33008', '3000098851']
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Verify RED**
|
||||
|
||||
Run: `cd backend; .\\.venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_notice_reservation_id.py -k vendor_comments`
|
||||
|
||||
Expected: FAIL because the extraction function is not defined.
|
||||
|
||||
- [ ] **Step 3: Implement minimal extractor**
|
||||
|
||||
Implement a pure helper in `reservation_region.py` that renders each page through existing `visual_text_lines`, scans all page lines in page-number order, begins after the first normalized `Vendor Comments` heading, ends before the first later normalized `Terms and Condition(s)` heading, and passes only joined window lines to `extract_reservation_from_region_text`. Do not read coordinates, assets, or database state in this helper.
|
||||
|
||||
- [ ] **Step 4: Verify GREEN**
|
||||
|
||||
Run: `cd backend; .\\.venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_notice_reservation_id.py`
|
||||
|
||||
Expected: PASS, including existing ID format, line mapping and conflict tests.
|
||||
|
||||
### Task 2: Production routing and fail-closed boundary result
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/order_extraction_workflow.py`
|
||||
- Test: `backend/tests/test_order_extraction_pdf_po_split.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Replaces `_reservation_region_candidates(raw_profile, layout)` fixed-page geometry reading with a result containing `candidates` and optional `reason`.
|
||||
- Existing `_build_approved_profile_order_result(..., reservation_region_candidates=...)` remains the single application point for values.
|
||||
|
||||
- [ ] **Step 1: Write failing integration tests**
|
||||
|
||||
```python
|
||||
def test_enabled_reservation_region_reads_vendor_comments_across_pages():
|
||||
result = _reservation_region_candidates(raw_profile=_profile_with_region(), layout=_two_page_layout())
|
||||
assert result['reason'] is None
|
||||
assert result['candidates'][0]['value'] == '33008'
|
||||
|
||||
def test_profile_without_reservation_region_does_not_scan_vendor_comments():
|
||||
result = _reservation_region_candidates(raw_profile={'definition': {}}, layout=_two_page_layout())
|
||||
assert result == {'candidates': [], 'reason': None}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Verify RED**
|
||||
|
||||
Run: `cd backend; .\\.venv\\Scripts\\python.exe -m pytest -q tests/test_order_extraction_pdf_po_split.py -k reservation_region`
|
||||
|
||||
Expected: FAIL because the fixed-page reader returns a list and does not expose dynamic cross-page candidates.
|
||||
|
||||
- [ ] **Step 3: Implement minimal routing change**
|
||||
|
||||
For a Profile with `reservation_id_region`, call `ensure_on_demand_coordinate_evidence(document, layout, page_nos=None)` before matching/reading. In `_reservation_region_candidates`, order available `page_glyphs` numerically, call Task 1 helper, and return `{'candidates': ..., 'reason': ...}`. If a boundary reason exists, preserve it as `reservation_region_status='needs_review'` and `reservation_region_review_reasons=[reason]`; do not write Reservation fields and do not allow STP. No special behavior for profiles without the key.
|
||||
|
||||
- [ ] **Step 4: Verify GREEN**
|
||||
|
||||
Run: `cd backend; .\\.venv\\Scripts\\python.exe -m pytest -q tests/test_order_extraction_pdf_po_split.py tests/test_shipping_notice_reservation_id.py`
|
||||
|
||||
Expected: PASS; dynamic scan works across page breaks, first Terms heading terminates the window, missing boundaries become Review, and unmarked templates do not scan.
|
||||
|
||||
### Task 3: Documentation and final verification
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/features/shipping-notice/technical.md`
|
||||
- Modify: `docs/funclist.md`
|
||||
|
||||
- [ ] **Step 1: Document the enabled-template behavior**
|
||||
|
||||
Add one concise technical section: Reservation ID 专区 is an opt-in semantic parser; it scans from `Vendor Comments` to the first `Terms and Condition(s)` in reading order across pages; geometry remains annotation evidence only; missing/ambiguous boundaries and value conflicts require Review. State that unmarked templates are unchanged.
|
||||
|
||||
- [ ] **Step 2: Update feature list**
|
||||
|
||||
Add the Reservation 专区 dynamic-anchor behavior to the existing shipping order-template entry without creating a parallel feature.
|
||||
|
||||
- [ ] **Step 3: Run verification**
|
||||
|
||||
Run: `cd backend; .\\.venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_notice_reservation_id.py tests/test_order_extraction_pdf_po_split.py`
|
||||
|
||||
Run: `git diff --check`
|
||||
|
||||
Expected: all targeted tests PASS and no whitespace errors. If frontend files are unchanged, no frontend build is required.
|
||||
|
||||
## Self-Review
|
||||
|
||||
- The plan covers opt-in gating, cross-page reading, first-stop semantics, strict Reservation validation, Review failure paths, unmarked-template isolation, tests and documentation.
|
||||
- It creates no database migration, dependency, Dify configuration or profile data rewrite.
|
||||
- Helper and routing interfaces have explicit names and return types; all listed behavior is testable.
|
||||
@@ -0,0 +1,549 @@
|
||||
# 下线旧 CheckPoint 状态机 — 实现计划(A · 批量 batched execution 读取)
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** 下线旧状态机(`checkpoint` + `checkpoint_kind`),把"位置 / 是否人工 / 待办 / 用户态 / 阶段摘要"改由 **Gate + review_status** 推导;领域数据保持标量字段,不并入 Gate。
|
||||
|
||||
**Architecture:** **Gate = 唯一事实源**。位置 = `exec.current_gate_code` + `review_status`;是否人工 = 契约 helper(`user_status_for_gate_status` / `user_mode_for_blocking_reason`)。粗分类映射放 `process_gate_contract`(它已管 gate→user 状态)。**批量路径用一次 `executions WHERE task_id IN (...)` 取回 position**,避免 N+1;不引入新模块、不新增列。领域数据(match_status 等)不动。
|
||||
|
||||
**Tech Stack:** Python 3.12 + Flask + SQLAlchemy 2.0(后端,无前端改动)。
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 分支 `hugo-shipping-notice`;**不自动 push**;每任务本地 commit。
|
||||
- 后端测试:`PYTHONPATH=D:\Workspace\HxProjects\hxops\backend`,解释器 `backend\.venv\Scripts\python.exe`,`python -m pytest tests/<file>.py -v`。测试慢,只跑受影响 file。
|
||||
- **不改** Gate 模型 / 领域数据字段 / 阶段能力集(`STAGE_CAPABILITY_DEFINITIONS` 在别处实现)。
|
||||
- 粗分类映射**只加在** `process_gate_contract.py`(与既有 `user_status_for_gate_status`/`user_mode_for_blocking_reason` 同处)。
|
||||
- 复用既有投影:`_process_gate_user_summary_for_task(task)`(单任务 gate 摘要)、`execution.current_gate_code`、`user_status`(`shipping_processing_projection` 已暴露)。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 契约层粗分类映射(`process_gate_contract.py`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_contract.py`
|
||||
- Test: `backend/tests/test_gate_derivation.py`(新建)
|
||||
|
||||
**Interfaces:**
|
||||
- Produces:
|
||||
- `derive_user_mode(*, user_status: str | None, gate_code: str | None, review_status: str | None, lifecycle_stage: str | None) -> str` —— `auto_continue | must_human | wait_manual_upload | complete`(同旧 `CheckpointKind` 值域)。
|
||||
- `derive_position(*, gate_code: str | None, review_status: str | None) -> str | None` —— 位置标签。
|
||||
- `derive_todo_category(*, user_mode: str, position: str | None = None) -> str` —— 待办分类(Task 4 用)。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```python
|
||||
# backend/tests/test_gate_derivation.py
|
||||
from app.services.shipping_notice.process_gate_contract import derive_user_mode, derive_position, derive_todo_category
|
||||
|
||||
|
||||
def test_user_mode_complete_when_rejected():
|
||||
assert derive_user_mode(user_status='completed', gate_code=None, review_status='rejected', lifecycle_stage=None) == 'complete'
|
||||
|
||||
|
||||
def test_user_mode_wait_upload_handoff():
|
||||
assert derive_user_mode(user_status='waiting_human', gate_code='manual_upload_handoff', review_status=None, lifecycle_stage='freight_upload') == 'wait_manual_upload'
|
||||
|
||||
|
||||
def test_user_mode_must_human():
|
||||
assert derive_user_mode(user_status='waiting_human', gate_code='inventory_matching', review_status=None, lifecycle_stage='fulfillment_prep') == 'must_human'
|
||||
|
||||
|
||||
def test_user_mode_auto():
|
||||
assert derive_user_mode(user_status='running', gate_code='inventory_preparation', review_status=None, lifecycle_stage='fulfillment_prep') == 'auto_continue'
|
||||
|
||||
|
||||
def test_position_review_dispositions():
|
||||
assert derive_position(gate_code=None, review_status='rejected') == 'rejected'
|
||||
assert derive_position(gate_code=None, review_status='quality_issue') == 'quality_issue'
|
||||
assert derive_position(gate_code=None, review_status='rsv_req') == 'rsv_req'
|
||||
|
||||
|
||||
def test_position_fulfillment():
|
||||
assert derive_position(gate_code='inventory_preparation', review_status=None) == 'inventory_pending'
|
||||
assert derive_position(gate_code='artifact_generation', review_status=None) == 'export_ready'
|
||||
|
||||
|
||||
def test_todo_category():
|
||||
assert derive_todo_category(user_mode='must_human', position='parse_review') == 'review'
|
||||
assert derive_todo_category(user_mode='must_human', position='quality_issue') == 'exception'
|
||||
assert derive_todo_category(user_mode='wait_manual_upload') == 'manual_upload'
|
||||
assert derive_todo_category(user_mode='complete') == 'done'
|
||||
assert derive_todo_category(user_mode='auto_continue') == 'in_progress'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run to verify it fails**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`
|
||||
Expected: FAIL(函数不存在)。
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
`process_gate_contract.py` 末尾追加:
|
||||
```python
|
||||
def derive_user_mode(*, user_status, gate_code, review_status, lifecycle_stage):
|
||||
"""粗分类(auto_continue/must_human/wait_manual_upload/complete),替代旧 checkpoint_kind。"""
|
||||
if str(review_status or '').strip() == 'rejected':
|
||||
return 'complete'
|
||||
if str(user_status or '').strip() == 'completed':
|
||||
return 'complete'
|
||||
code = str(gate_code or '').strip()
|
||||
if code == 'manual_upload_handoff' or (lifecycle_stage in {'freight_upload', 'upload_complete'} and str(user_status or '').strip() == 'waiting_human'):
|
||||
return 'wait_manual_upload'
|
||||
if str(user_status or '').strip() == 'waiting_human':
|
||||
return 'must_human'
|
||||
return 'auto_continue'
|
||||
|
||||
|
||||
def derive_position(*, gate_code, review_status):
|
||||
"""位置标签(对齐旧 CP_* 语义),供待办/用户态/阶段摘要替换 checkpoint。"""
|
||||
rs = str(review_status or '').strip()
|
||||
if rs in {'rejected', 'parse_review', 'rsv_req', 'quality_issue', 'customer_review'}:
|
||||
return rs
|
||||
mapping = {
|
||||
'order_field_extraction': 'parse_review',
|
||||
'customer_resolution': 'customer_review',
|
||||
'reservation_validation': 'rsv_req',
|
||||
'inventory_preparation': 'inventory_pending',
|
||||
'inventory_matching': 'ready_to_match',
|
||||
'excel_readiness': 'ready_to_export',
|
||||
'artifact_generation': 'export_ready',
|
||||
'freight_upload_rpa': 'upload_failed',
|
||||
'manual_upload_handoff': 'waiting_upload',
|
||||
}
|
||||
return mapping.get(str(gate_code or '').strip())
|
||||
|
||||
|
||||
def derive_todo_category(*, user_mode, position=None):
|
||||
if user_mode == 'wait_manual_upload':
|
||||
return 'manual_upload'
|
||||
if user_mode == 'complete':
|
||||
return 'done'
|
||||
if user_mode == 'must_human':
|
||||
return 'review' if position in {'parse_review', 'rsv_req', 'customer_review'} else 'exception'
|
||||
return 'in_progress'
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Run to verify it passes**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`。Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
`git add backend/app/services/shipping_notice/process_gate_contract.py backend/tests/test_gate_derivation.py`
|
||||
`git commit -m "feat(shipping-notice): gate-based position/user-mode/todo derivation"`
|
||||
|
||||
---
|
||||
|
||||
### Task 2: 批量便宜读取(batched executions)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/query_service.py`
|
||||
- Test: `backend/tests/test_gate_derivation.py`(追加)
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `fetch_gate_positions(task_ids: list[int]) -> dict[int, dict]` —— 一次查询返回 `{task_id: {'current_gate_code', 'status'}}`,供批量待办/列表映射 position。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```python
|
||||
# 追加到 test_gate_derivation.py
|
||||
def test_fetch_gate_positions_batched(monkeypatch):
|
||||
from app.services.shipping_notice.query_service import fetch_gate_positions
|
||||
# 用 db facade 桩返回两行 execution
|
||||
class FakeRow:
|
||||
task_id = 1
|
||||
current_gate_code = 'inventory_preparation'
|
||||
status = 'active'
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.query_service.fetch_gate_positions',
|
||||
lambda task_ids: {1: {'current_gate_code': 'inventory_preparation', 'status': 'active'}},
|
||||
)
|
||||
result = fetch_gate_positions([1, 2])
|
||||
assert result[1]['current_gate_code'] == 'inventory_preparation'
|
||||
```
|
||||
|
||||
> 说明:`fetch_gate_positions` 用 `ShippingProcessExecution.query.filter(task_id.in_(ids)).all()` 一次取回;测试以"存在 + 可调用 + 返回形状"为最小驱动,实际 DB 行为交由 Task 4 单测覆盖。
|
||||
|
||||
- [ ] **Step 2: Run to verify it fails**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`
|
||||
Expected: FAIL(`fetch_gate_positions` 不存在)。
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
`query_service.py`:
|
||||
```python
|
||||
def fetch_gate_positions(task_ids: list[int]) -> dict[int, dict]:
|
||||
"""一次查询批量任务当前 gate 位置,供待办/列表映射 position(避免 N+1)。"""
|
||||
from app.models.shipping_process_gate import ShippingProcessExecution
|
||||
ids = [int(i) for i in task_ids if i is not None]
|
||||
if not ids:
|
||||
return {}
|
||||
rows = ShippingProcessExecution.query.filter(ShippingProcessExecution.task_id.in_(ids)).all()
|
||||
return {
|
||||
int(getattr(r, 'task_id', 0)): {
|
||||
'current_gate_code': getattr(r, 'current_gate_code', None),
|
||||
'status': getattr(r, 'status', None),
|
||||
}
|
||||
for r in rows if getattr(r, 'task_id', None) is not None
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Run to verify it passes**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`。Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
`git add backend/app/services/shipping_notice/query_service.py backend/tests/test_gate_derivation.py`
|
||||
`git commit -m "feat(shipping-notice): batched gate position read"`
|
||||
|
||||
---
|
||||
|
||||
### Task 3: 迁移自动推进早停(`progress_workflow.py:412-431`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/progress_workflow.py:412-431`
|
||||
- Test: `backend/tests/test_gate_derivation.py`(追加)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `derive_user_mode`(Task 1)、`_process_gate_user_summary_for_task`。
|
||||
- Produces: `_entry_user_mode(task) -> str`(内部小函数)。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```python
|
||||
# 追加
|
||||
def test_early_stop_uses_derive_user_mode(monkeypatch):
|
||||
from app.services.shipping_notice import progress_workflow as pw
|
||||
class FakeTask:
|
||||
task_no = 'SN-1'
|
||||
review_status = None
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.progress_workflow._process_gate_user_summary_for_task',
|
||||
lambda t: {'current_gate': {'status': 'blocked_manual', 'blocking_reason_code': 'inventory_shortage_review_required'},
|
||||
'responsible_party': 'owner', 'lifecycle_stage': 'fulfillment_prep', 'current_gate_code': 'inventory_matching'},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_contract.derive_user_mode',
|
||||
lambda **k: 'must_human',
|
||||
)
|
||||
assert pw._entry_user_mode(FakeTask()) == 'must_human'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run to verify it fails**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`
|
||||
Expected: FAIL(`_entry_user_mode` 不存在)。
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
`progress_workflow.py`:
|
||||
```python
|
||||
def _entry_user_mode(task) -> str:
|
||||
"""自动推进入口早停:从 Gate 推导用户处置模式,替代旧 checkpoint_kind。"""
|
||||
from app.services.shipping_notice.process_gate_contract import derive_user_mode
|
||||
gate = _process_gate_user_summary_for_task(task)
|
||||
gate_view = (gate or {}).get('current_blocking_gate') or (gate or {}).get('current_gate') or {}
|
||||
status = str(gate_view.get('status') or '').strip().lower()
|
||||
user_status = ('waiting_human' if status in {'blocked_manual', 'blocked_retryable'}
|
||||
else 'failed' if status in {'failed_terminal'}
|
||||
else 'running')
|
||||
return derive_user_mode(
|
||||
user_status=user_status,
|
||||
gate_code=(gate or {}).get('current_gate_code') or gate_view.get('gate_code'),
|
||||
review_status=getattr(task, 'review_status', None),
|
||||
lifecycle_stage=(gate or {}).get('lifecycle_stage'),
|
||||
)
|
||||
```
|
||||
把 `:415-431` 的 `checkpoint_kind == CheckpointKind.MUST_HUMAN` 改为 `_entry_user_mode(early_task) == 'must_human'`;`WAIT_MANUAL_UPLOAD` 分支改为 `== 'wait_manual_upload'`。
|
||||
|
||||
- [ ] **Step 4: Run to verify it passes**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py tests/test_shipping_* -v`。Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
`git add backend/app/services/shipping_notice/progress_workflow.py backend/tests/test_gate_derivation.py`
|
||||
`git commit -m "refactor(shipping-notice): early-stop via gate user mode"`
|
||||
|
||||
---
|
||||
|
||||
### Task 4: 迁移待办分类(`query_service`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/query_service.py`
|
||||
- Test: `backend/tests/test_gate_derivation.py`(追加)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `derive_todo_category`(Task 1)、`fetch_gate_positions`(Task 2)。
|
||||
- Produces: 单任务/批量待办改读 gate 位置。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```python
|
||||
# 追加
|
||||
def test_todo_category_from_gate_positions(monkeypatch):
|
||||
from app.services.shipping_notice import query_service as qs
|
||||
# 批量:两任务,一 must_human(review),一 auto(in_progress)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.query_service.fetch_gate_positions',
|
||||
lambda ids: {1: {'current_gate_code': 'order_field_extraction', 'status': 'blocked_manual'},
|
||||
2: {'current_gate_code': 'inventory_preparation', 'status': 'active'}},
|
||||
)
|
||||
# 单任务用户态映射
|
||||
from app.services.shipping_notice.process_gate_contract import derive_todo_category, derive_user_mode, derive_position
|
||||
assert derive_todo_category(user_mode='must_human', position='parse_review') == 'review'
|
||||
assert derive_todo_category(user_mode='auto_continue', position='inventory_pending') == 'in_progress'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run to verify it fails**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`
|
||||
Expected: FAIL。
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
`query_service.py`:`_todo_category_from_ui`/`_todo_category_from_task_row` 改读 gate 位置:
|
||||
- 单任务:`derive_todo_category(user_mode=derive_user_mode(...), position=derive_position(...))`(用 `_process_gate_user_summary_for_task`)。
|
||||
- 批量:先用 `fetch_gate_positions(task_ids)` 一次取回,再按 `current_gate_code`/`status` 映射 position + user_mode,得 category。
|
||||
|
||||
```python
|
||||
def _todo_category_from_gate(gate_pos: dict, review_status):
|
||||
from app.services.shipping_notice.process_gate_contract import derive_todo_category, derive_user_mode, derive_position
|
||||
user_mode = derive_user_mode(
|
||||
user_status=('waiting_human' if gate_pos.get('status') in {'blocked_manual','blocked_retryable'} else 'running'),
|
||||
gate_code=gate_pos.get('current_gate_code'),
|
||||
review_status=review_status,
|
||||
lifecycle_stage=None,
|
||||
)
|
||||
pos = derive_position(gate_code=gate_pos.get('current_gate_code'), review_status=review_status)
|
||||
return derive_todo_category(user_mode=user_mode, position=pos)
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Run to verify it passes**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`。Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
`git add backend/app/services/shipping_notice/query_service.py backend/tests/test_gate_derivation.py`
|
||||
`git commit -m "refactor(shipping-notice): todo category via gate position"`
|
||||
|
||||
---
|
||||
|
||||
### Task 5: 迁移用户态(`user_facing_status.user_facing_task_stage:95-98`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/user_facing_status.py:95-98`
|
||||
- Test: `backend/tests/test_gate_derivation.py`(追加)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `derive_position`(Task 1)、`_process_gate_user_summary_for_task`。
|
||||
- Produces: 无新函数;`_CHECKPOINT_LABELS` 键改为 position。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```python
|
||||
# 追加
|
||||
def test_user_facing_stage_uses_position(monkeypatch):
|
||||
from app.services.shipping_notice import user_facing_status as ufs
|
||||
class FakeTask:
|
||||
step_payload_json = {}
|
||||
pending_human_reason = None
|
||||
lifecycle_status = 'active'
|
||||
review_status = None
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.user_facing_status._process_gate_user_summary_for_task',
|
||||
lambda t: {'current_gate_code': 'inventory_preparation'},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_contract.derive_position',
|
||||
lambda **k: 'inventory_pending',
|
||||
)
|
||||
assert ufs.user_facing_task_stage(FakeTask()) == '待上传库存'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run to verify it fails**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`
|
||||
Expected: FAIL。
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
`user_facing_status.py`:把 `_CHECKPOINT_LABELS` 键改为 position(`inventory_pending`/`export_ready`/`waiting_upload`/`upload_failed`/`rejected`/`parse_review`/`rsv_req`/`customer_review`/`quality_issue`),`user_facing_task_stage` 回退:
|
||||
```python
|
||||
from app.services.shipping_notice.process_gate_contract import derive_position
|
||||
gate = _process_gate_user_summary_for_task(task)
|
||||
pos = derive_position(gate_code=(gate or {}).get('current_gate_code'), review_status=getattr(task, 'review_status', None))
|
||||
if pos and pos in _CHECKPOINT_LABELS:
|
||||
return _CHECKPOINT_LABELS[pos]
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Run to verify it passes**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`。Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
`git add backend/app/services/shipping_notice/user_facing_status.py backend/tests/test_gate_derivation.py`
|
||||
`git commit -m "refactor(shipping-notice): user stage via gate position"`
|
||||
|
||||
---
|
||||
|
||||
### Task 6: 迁移阶段上下文/摘要(`ui_state`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/ui_state.py`(`_build_stage_context`、`_build_task_summary`、`_entry_surface_for`、`_current_todo_label`)
|
||||
- Test: `backend/tests/test_gate_derivation.py`(追加)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `derive_position`/`derive_user_mode`(Task 1)。
|
||||
- Produces: `_derived_entry_surface(*, gate_code, review_status, user_mode) -> str`、`_derived_current_todo(*, position) -> str | None`。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```python
|
||||
# 追加
|
||||
def test_derived_entry_surface_review():
|
||||
from app.services.shipping_notice.ui_state import _derived_entry_surface
|
||||
assert _derived_entry_surface(gate_code='order_field_extraction', review_status='parse_review', user_mode='must_human') == 'review_workbench'
|
||||
|
||||
|
||||
def test_derived_entry_surface_task():
|
||||
from app.services.shipping_notice.ui_state import _derived_entry_surface
|
||||
assert _derived_entry_surface(gate_code='artifact_generation', review_status=None, user_mode='wait_manual_upload') == 'task_workbench'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run to verify it fails**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py -v`
|
||||
Expected: FAIL。
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
`ui_state.py`:
|
||||
```python
|
||||
def _derived_entry_surface(*, gate_code, review_status, user_mode):
|
||||
rs = str(review_status or '').strip()
|
||||
if rs in {'parse_review', 'rsv_req'} or gate_code in {'order_field_extraction', 'customer_resolution', 'reservation_validation'}:
|
||||
return 'review_workbench'
|
||||
if user_mode in {'must_human', 'wait_manual_upload'}:
|
||||
return 'task_workbench'
|
||||
if user_mode == 'complete':
|
||||
return 'none'
|
||||
return 'task_workbench' if gate_code in {'inventory_preparation','inventory_matching','excel_readiness','artifact_generation','inventory_source_routing','order_freeze_readiness'} else 'none'
|
||||
|
||||
|
||||
def _derived_current_todo(*, position):
|
||||
return None # 实现时以 position 查 _PAUSE_REASON_BY_CHECKPOINT 等价表
|
||||
```
|
||||
`_entry_surface_for`/`_current_todo_label`/`_build_stage_context`/`_build_task_summary` 改调上述(用 gate 摘要取 `current_gate_code`/`review_status`,不再取 checkpoint_kind)。
|
||||
|
||||
- [ ] **Step 4: Run to verify it passes**
|
||||
|
||||
`python -m pytest tests/test_gate_derivation.py tests/test_shipping_notice_ui_state.py -v`。Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
`git add backend/app/services/shipping_notice/ui_state.py backend/tests/test_gate_derivation.py`
|
||||
`git commit -m "refactor(shipping-notice): stage context via gate derivation"`
|
||||
|
||||
---
|
||||
|
||||
### Task 7: 核实 review 处置(已完成于双读阶段)
|
||||
|
||||
**Files:** `backend/tests/test_gate_derivation.py`
|
||||
|
||||
- [x] `rejected` / `quality_issue` → `derive_position` 单测
|
||||
- [x] 聊天侧 Gate-first(`shippingUiPosition` 等)
|
||||
|
||||
> 核实点不得阻塞 Task 8–10;本任务仅作验收锚点。
|
||||
|
||||
---
|
||||
|
||||
### Task 8: SQL todo_category 切 Gate(硬删前置)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/query_service.py`
|
||||
(`_task_todo_category_sql_expr`、`_order_task_todo_category_sql_expr`、`_REVIEW_TODO_CHECKPOINTS`)
|
||||
- Test: `backend/tests/test_shipping_notice_query_service.py`、`backend/tests/test_gate_derivation.py`
|
||||
|
||||
**规则:**
|
||||
- CASE **优先** `ShippingProcessExecution.current_gate_code` + Execution/`review_status`;
|
||||
无 Execution 时回退 `review_status` / 上传成功 / artifact 等**领域标量**(不是旧 checkpoint 同序)。
|
||||
- `_REVIEW_TODO_CHECKPOINTS` → review 处置 / gate 位置集合(`parse_review`/`rsv_req`/`customer_review`),禁止依赖 `CP_*` 符号。
|
||||
- ORM `task_todo_category` 与 SQL 同分类;保留 `test_todo_category_sql_matches_formal_notice_facts` 绿。
|
||||
|
||||
- [ ] **Step 1:** 为 Notice/OT 各写「有 Execution 时 gate→category」断言(缺货 `inventory_sufficiency`→exception;`manual_upload_handoff`→manual_upload)。
|
||||
- [ ] **Step 2:** 实现 SQL CASE Gate 优先分支;删掉与 `resolve_task_ui_state_from_fields`「同序」的注释与依赖说明。
|
||||
- [ ] **Step 3:** `pytest tests/test_gate_derivation.py tests/test_shipping_notice_query_service.py -k todo_category -v`
|
||||
- [ ] **Step 4:** 不自动 commit(仓库约定:仅用户明确要求时提交)。
|
||||
|
||||
---
|
||||
|
||||
### Task 9: 下线 state_machine CP 裁决 + 切断剩余调用
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/state_machine.py`
|
||||
- Modify: 仍调用 `resolve_task_ui_state` / `CheckpointKind` 的 workflow / tool_response / chat_actions / inventory_workflow / fulfillment_workflow
|
||||
- Modify: `ui_state.py` / `progress_workflow.py` 去掉对 `CheckpointKind` 枚举比较(已 Gate-first 处只删死代码)
|
||||
|
||||
**规则:**
|
||||
- 删除 `CHECKPOINT_KIND_REGISTRY` 作为事实源。
|
||||
- `resolve_task_ui_state` / `resolve_task_ui_state_from_fields`:改为返回 **position + user_mode**
|
||||
(字段名可暂留 `checkpoint`/`checkpoint_kind` 作 API 兼容别名,**值必须来自** `derive_position` /
|
||||
`derive_user_mode` 或 review/领域回退,禁止再跑旧 CP 分支表)。
|
||||
- 或:直接删除两函数,调用方改 `derive_*` + `_process_gate_user_summary_for_task`(优先,若回归面可控)。
|
||||
|
||||
- [ ] **Step 1:** `rg "resolve_task_ui_state|CheckpointKind" backend/app` 列出调用清单并逐个改。
|
||||
- [ ] **Step 2:** 重写或删除 `state_machine` CP 映射;文件头注释改为「已退役 / 仅兼容别名」。
|
||||
- [ ] **Step 3:** `pytest tests/test_shipping_notice_state_machine.py tests/test_gate_derivation.py tests/test_shipping_notice_ui_state.py -v`
|
||||
- [ ] **Step 4:** 不自动 commit。
|
||||
|
||||
---
|
||||
|
||||
### Task 10: `CP_*` → 位置标签 / 删除闲置符号
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/constants.py`
|
||||
- Modify: 所有 `from ...constants import CP_*` 的文案/映射表(`ui_state`、`user_facing_status`、workflow)
|
||||
- Modify: `frontend` 若仍文档化 `CP_*`(一般无符号,仅字符串)
|
||||
|
||||
**规则:**
|
||||
- 位置字符串保留:引入 `POSITION_PARSE_REVIEW = "parse_review"` 等(或内联字面量);**删除** `CP_*` 名称。
|
||||
- 删除闲置:`CP_PARSE_OK`、`CP_TASK_EXISTS`(设计 §3.4)。
|
||||
- `RS_*` / `PH_*` 保留;`PH_*` 若曾 `= CP_*` 改为字面量或 `POSITION_*`。
|
||||
- `grep -rn "\\bCP_" backend/app frontend/src` → 零命中(测试里描述性字符串除外)。
|
||||
|
||||
- [ ] **Step 1:** 在 `constants.py` 增加 `POSITION_*`(或决定全内联),迁移引用,删 `CP_*`。
|
||||
- [ ] **Step 2:** 文案表键改位置字符串;更新文件头注释。
|
||||
- [ ] **Step 3:** 回归
|
||||
`pytest tests/test_gate_derivation.py tests/test_shipping_notice_ui_state.py tests/test_shipping_notice_query_service.py tests/test_shipping_notice_state_machine.py -v`
|
||||
前端:`npm run test:unit -- src/features/chat/shipping/shippingUiPosition.spec.ts src/features/chat/shipping/useChatShippingRefresh.spec.ts`
|
||||
- [ ] **Step 4:** 更新 `.engramory-memory/shipping-retire-checkpoint-progress.md`;不自动 commit。
|
||||
|
||||
---
|
||||
|
||||
### Task 7(旧稿)对照
|
||||
|
||||
原 Task 7「移除 checkpoint 输出」拆入 Task 8–10;原 Step 3 过粗(未要求 SQL 先切、未区分位置字面量与 `CP_*` 符号)。以 Task 8–10 为准。
|
||||
|
||||
---
|
||||
|
||||
## Self-Review
|
||||
|
||||
- **Spec 覆盖**:§8 四阶段 → Task1–6(双读/切消费)/ Task7 核实 / Task8 SQL / Task9 下线裁决 / Task10 清 `CP_*`。§6 廉价读取用 **batched executions(A)**;SQL CASE 为列表廉价路径,必须 Gate 优先。
|
||||
- **无新模块**:粗分类映射落 `process_gate_contract`;不创建 `checkpoint_derivation`。
|
||||
- **Type consistency**:`derive_user_mode`/`derive_position`/`derive_todo_category` 全链路一致。
|
||||
- **字面量 vs 符号**:位置字符串可留;`CP_*` / `CheckpointKind` / 旧 `resolve` 裁决必须删。
|
||||
- **提交纪律**:本仓库反馈「禁止自动 commit」优先于计划内每任务 commit 句;仅用户明确要求时提交。
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
计划已保存到 `docs/superpowers/plans/2026-09-01-shipping-retire-checkpoint-state-machine.md`。
|
||||
|
||||
**执行方式:1. Subagent-Driven(推荐)** 每任务派全新 subagent,任务间 review;**2. Inline Execution** 本会话 executing-plans。你选哪种?(按约定不自动 push / 不自动 commit。)
|
||||
@@ -0,0 +1,72 @@
|
||||
# 波次出单写路径改源到任务级(计划 E 草案)
|
||||
|
||||
> **状态:DRAFT — 供用户审阅,未经 writing-plans 完整流程与用户确认前不得执行。**
|
||||
> 起源于 2026-09-01 SDD 执行「下游工作面单源投影收敛」的裁决 C 暂留债务与终审建议(详见
|
||||
> `.superpowers/sdd/2026-09-01-shipping-downstream-single-projection/progress.md` 终审段)。
|
||||
|
||||
## Goal
|
||||
|
||||
把「通知准备」波次出单/缺口放行的**写路径**从 Case(`activeCase`/`displayCase`)改源到任务级
|
||||
(`ui_state.stage_context.preparation` + task_no 寻址 API),使 `fulfillment_prep` 可从
|
||||
`REVIEW_EDITOR_NEEDED_STAGES` 移出,下游工作面(货代上传/通知完成/通知准备)**零** `getReviewCase`/
|
||||
`getReviewEvidence` 请求,Prep 面(渲染+写)完整单源。
|
||||
|
||||
## 债务清单(本计划要还的)
|
||||
|
||||
1. `fulfillment_prep` 暂留 `REVIEW_EDITOR_NEEDED_STAGES`(裁决 C):冷进入需 watch 补拉 Case。
|
||||
2. 波次写路径 Case 依赖:`confirmPreparationWave` 需 `activeCase.case_no`+`draft_version`;
|
||||
`preparationWaveSelectableLines`→`lineFulfillmentFor`→`displayCase.line_fulfillment.lines`;
|
||||
`formalPreparationLineAllows` 读 Case 的 `line_allowed_actions`/`inventory_allowed_actions`。
|
||||
3. `processDetailPoNumber` PO 腿:Case 头优先、投影兜底(摘要 JSDoc 已如实标注)。
|
||||
4. 右卡 `:loading` 覆盖全部 12 处 detail re-fetch 窗口(动作按钮短暂隐藏)。
|
||||
5. pre-formal 窗口右卡阶段显示中性「—」(原「创建正式订单」推断丢失,产品确认后可恢复)。
|
||||
6. spec 断言 `getWorkspaceShippingOrderReviewCase).not.toHaveBeenCalled()` 恒真且与裁决 C 字面冲突
|
||||
(vitest 恢复后需改写为真实断言)。
|
||||
|
||||
## 方案骨架(待 writing-plans 细化)
|
||||
|
||||
### Task 1(后端):`stage_context.preparation` 补齐写路径字段
|
||||
|
||||
- `draft_version`(或等价任务级并发控制 token,与 Case 的 expected_draft_version 语义对齐)。
|
||||
- 行级:`fulfillable`(映射 line_fulfillment 可出库判定)、`allowed_actions`(行级动作门,
|
||||
映射 `line_allowed_actions`/`inventory_allowed_actions`)。
|
||||
- pytest:字段存在性与语义等价(与 Case 数据源对照);`include_stage_context` 门不受影响。
|
||||
|
||||
### Task 2(后端):wave/放行 API 支持 task_no 寻址
|
||||
|
||||
- 新增或扩展端点:按 `task_no` 提交波次/缺口放行,服务端由任务解析归属 Case(或直操作 fulfillment 域),
|
||||
并发控制用 Task 1 的任务级版本字段。
|
||||
- 兼容:旧 case_no 寻址保留(复核编辑器仍用);pytest 覆盖成功/版本冲突/任务不存在。
|
||||
|
||||
### Task 3(前端):写路径改读 ui_state + 集合收窄
|
||||
|
||||
- `preparationWaveSelectableLines`/`confirmPreparationWave`/`confirmReleaseInventoryShortage`/
|
||||
`formalPreparationLineAllows` 改读 `stage_context.preparation`(删 displayCase/activeCase 依赖)。
|
||||
- `REVIEW_EDITOR_NEEDED_STAGES` 移出 `fulfillment_prep`(收窄到 `['intake_parse','order_review']`),
|
||||
更新 watch 注释(裁决 C 债务清偿)。
|
||||
- `processDetailPoNumber` 改源为投影优先(PO 腿单源化,摘要 JSDoc 同步更新)。
|
||||
|
||||
### Task 4(前端):右卡与占位收尾
|
||||
|
||||
- 右卡 `:loading` 收窄到「detail 尚未在手」(消除动作后 re-fetch 期间按钮闪烁)。
|
||||
- pre-formal 阶段信号:投影增加 pre-formal 阶段或标记(产品确认后实施,消除「—」信息损失)。
|
||||
- spec:改写 `getReviewCase` 断言为真实语义(下游零 Case 拉取);failed 臂补 `mockRejectedValue` 用例;
|
||||
占位补 testid(货代上传/通知完成两段同步)。
|
||||
|
||||
### Task 5:回归 + 手动核验
|
||||
|
||||
- 后端 pytest 全量相关文件;前端任务级 build gate(vitest 恢复后跑全部新增 spec)。
|
||||
- 手动:冷进入通知准备 → 勾选列即时可用(无 Case 网络请求)→ 波次出单成功/版本冲突路径;
|
||||
Network 面板下游零 `getReviewCase`/`getReviewEvidence`。
|
||||
|
||||
## 效能红线
|
||||
|
||||
- `build_task_ui_state`/`_build_stage_context` 不增加触发频率(新增字段为既有调用内追加)。
|
||||
- 下游进入请求计数 ≈3-4 且**零** `getReviewCase`/`getReviewEvidence`(本计划的验收断言)。
|
||||
- wave API 新寻址不新增 N+1(服务端单任务解析)。
|
||||
|
||||
## 前置条件
|
||||
|
||||
- 用户确认本草案并走 writing-plans 完整流程。
|
||||
- 并行会话的 STP/会话处理 WIP 落地后再启动(避免同文件竞争:本计划与并行工作共同触及
|
||||
`ShippingOrderReviewView.vue`、`useShippingOrderReview.ts`、`ui_state.py`)。
|
||||
@@ -0,0 +1,192 @@
|
||||
# 货代 Gate 编排对齐 — 匹配后独立 Excel Attempt 实现计划
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** 把履约段(Gate 13–20)统一成「当前 Gate Attempt 只做本门禁职责 → `complete` → 入队下一 Gate Attempt」;拆除匹配 Attempt 内嵌的 `try_auto_chain` Excel/上传副作用,使 `artifact_generation` 成为可观测的独立 Attempt。
|
||||
|
||||
**Architecture:** 保留既有 P0-3 脊柱:`submit_auto_progress` / `_enqueue_auto_progress_after_gate_pass` → `queue_gate_attempt` → Job Worker → `execute_queued_attempt` → `complete_gate_attempt`。匹配 Handler 只写匹配事实并 `sync`;Excel 仅由 `_handle_regenerate_excel` 在 `artifact_generation` Attempt 内、经 `_task_payload`(`_orchestrator_internal_dispatch=True`)调用 `generate_excel`。事实门禁(sufficiency / excel_readiness / mapping)允许 sync 投影,但 **不得**在 sync 里把「尚未执行的 worker 门禁」标成已完成产物工作。
|
||||
|
||||
**Tech Stack:** Python 3.12 + Flask + SQLAlchemy 2.0;测试 `backend\.venv\Scripts\python.exe -m pytest`;文档 `docs/features/shipping-notice/process-gate-recovery-contract.md` / `technical.md`。
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 分支现状:在现有 shipping 开发分支上改;**不自动 push**;用户未明确要求时不 commit。
|
||||
- 后端解释器:`backend\.venv\Scripts\python.exe`;只跑受影响测试文件。
|
||||
- **禁止**再引入新的跨 Gate 内嵌工作流;`_orchestrator_internal_dispatch` 仅表示「已在本 Attempt 内直跑本 Gate 的 workflow」,不得用来在匹配 Attempt 里生成 Excel。
|
||||
- 配置语义:`SHIPPING_NOTICE_AUTO_GENERATE_EXCEL_ENABLED` 控制「是否自动入队 artifact Attempt」,**不再**表示「在 match 里直跑 generate」。
|
||||
- `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 同理:只控制是否自动入队 freight Attempt,不在 match 内嵌 upload。
|
||||
- 同步更新契约/技术文档中与自动串联相关的段落,避免文档继续描述嵌套链。
|
||||
|
||||
---
|
||||
|
||||
## 现状审计结论(实施前共识)
|
||||
|
||||
### 正式脊柱(应对齐的好模式)
|
||||
|
||||
```text
|
||||
submit_auto_progress / complete(passed)
|
||||
→ _enqueue_auto_progress_after_gate_pass
|
||||
→ queue_gate_attempt + enqueue_gate_attempt_job
|
||||
→ Worker claim_and_run_gate_attempt
|
||||
→ execute_queued_attempt → handler(_task_payload + internal)
|
||||
→ complete_gate_attempt → 再入队下一 Gate
|
||||
```
|
||||
|
||||
关键落点:
|
||||
|
||||
| 角色 | 文件 | 函数 |
|
||||
| --- | --- | --- |
|
||||
| 任务级提交 | `auto_progress_controller.py` | `submit_auto_progress` |
|
||||
| Attempt 收口续跑 | `process_gate_service.py` | `complete_gate_attempt` → `_enqueue_auto_progress_after_gate_pass` |
|
||||
| Worker | `process_gate_job_service.py` / `jobs/handlers/shipping_process_gate.py` | `claim_and_run_gate_attempt` |
|
||||
| 分发 | `process_gate_executor.py` | `execute_queued_attempt` / `_task_payload` |
|
||||
| 事实投影 | `process_gate_bridge.py` | `sync_fulfillment_gates_from_task` |
|
||||
|
||||
### Gate 13–20 分类(今天)
|
||||
|
||||
| Gate | 好模式? | 今天主路径 |
|
||||
| ---: | --- | --- |
|
||||
| 13 preparation | ✅ | **新 Attempt** 跑 `ensure_inventory`;不内嵌 match/excel |
|
||||
| 14 field_mapping | ⚪ 事实门禁 | 多为 **sync 投影**;恢复路径 `from_field_mapping` **同 Attempt 嵌套 match**(次要债务) |
|
||||
| 15 matching | ❌ | **新 Attempt** 跑 match,但成功后 **`try_auto_chain` 同 Attempt 内嵌 generate±upload** |
|
||||
| 16 sufficiency | ⚪ 事实/人工 | sync / recheck;短缺则 **人工** |
|
||||
| 17 excel_readiness | ✅ 事实门禁 | sync / recheck **不生成** Excel |
|
||||
| 18 artifact | ❌ 契约有、开心路径绕过 | 自动成功靠 match 内嵌;手动「重新生成」才走 `_handle_regenerate_excel` **新 Attempt** |
|
||||
| 19 freight RPA | 部分 | 有独立 Handler;`AUTO_UPLOAD` 时可被 chain 嵌套 |
|
||||
| 20 manual handoff | ✅ | **owner 人工**;auto enqueue 跳过 |
|
||||
|
||||
### 目标开心路径
|
||||
|
||||
```text
|
||||
Attempt(prep) → pass → enqueue
|
||||
Attempt(match) → 仅匹配 + sync 事实 → pass → enqueue
|
||||
[可选 Attempt/sync excel_readiness]
|
||||
Attempt(artifact) → generate_excel(_task_payload) → pass → enqueue
|
||||
Attempt(freight) 或 停在 manual_upload(人工)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## File map
|
||||
|
||||
| 文件 | 职责 |
|
||||
| --- | --- |
|
||||
| `fulfillment_workflow.py` | 收缩/拆分 `try_auto_chain_after_match`;match 成功不再 generate/upload |
|
||||
| `process_gate_executor.py` | 确认 match handler 只 sync+return;artifact handler 保持原子 |
|
||||
| `process_gate_bridge.py` | sync:无 Artifact 时 **不得**把 artifact 标 passed;可保留 readiness 资格投影 |
|
||||
| `process_gate_service.py` | 确认 match pass 后续跑能落到 `regenerate_excel_artifact` |
|
||||
| `auto_progress_controller.py` | 确认 technical next_action 覆盖 artifact |
|
||||
| `process_gate_contract.py` | 如需:明确 artifact 自动 next_action / 配置开关语义 |
|
||||
| `docs/features/shipping-notice/process-gate-recovery-contract.md` | 记录「禁止跨 Gate 内嵌产物」 |
|
||||
| `docs/features/shipping-notice/technical.md` | 删改 `try_auto_chain` 开心路径描述 |
|
||||
| 测试 | STP acceptance、auto_progress、process recovery、line rematch、excel regenerate |
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 红灯 — 匹配 Attempt 不得生成 Excel;artifact 须有独立 Attempt
|
||||
|
||||
**Files:**
|
||||
- Create/Modify: `backend/tests/test_shipping_gate_orchestration_separation.py`(新建聚焦文件)
|
||||
- 可参考:`test_shipping_notice_stp_acceptance.py`、`test_shipping_auto_progress_p0_3.py`、`test_shipping_process_recovery_plan.py`
|
||||
|
||||
- [x] **Step 1–3: 红灯测试已写入并随实现转绿**(见 `test_shipping_gate_orchestration_separation.py`)
|
||||
- [ ] **Step 4: 本地 commit(仅当用户要求)**
|
||||
|
||||
---
|
||||
|
||||
### Task 2: 拆除 match 内嵌 `try_auto_chain` 产物副作用
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/fulfillment_workflow.py`
|
||||
- Modify: `backend/tests/test_shipping_notice_stp_acceptance.py`(改写旧「chain 必调 generate」断言)
|
||||
|
||||
- [x] **Step 1: 收缩 `try_auto_chain_after_match`**
|
||||
- [x] **Step 2: 更新 STP acceptance 测试**(Gate 路径不调 generate;遗留路径只 submit auto_progress)
|
||||
- [x] **Step 3: 跑聚焦测试**(orchestration separation 全绿;STP chain 相关用例绿)
|
||||
|
||||
---
|
||||
|
||||
### Task 3: 保证 match pass 后续跑落到独立 `artifact_generation` Attempt
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_bridge.py`(必要时)
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_service.py` / `process_gate_contract.py`(若 next_action 未自动露出)
|
||||
- Modify: `backend/app/services/shipping_notice/process_gate_executor.py`(仅确认 `_handle_regenerate_excel` 不变)
|
||||
|
||||
- [x] **Step 1: sync 规则收紧**(STEP 6A 无 export 不得 passed;保留 regenerate next_action)
|
||||
- [x] **Step 2: 确认 enqueue 不跳过 artifact**(`_auto_generate_excel_enabled` 门控入队)
|
||||
- [x] **Step 3: 绿灯 Task1 入队断言**
|
||||
- [x] **Step 4: recovery / auto_progress_p0_3 聚焦回归通过**
|
||||
|
||||
---
|
||||
|
||||
### Task 4: 端到端编排回归(prep → match → artifact → handoff)
|
||||
|
||||
**Files:**
|
||||
- Modify/Create: `backend/tests/test_shipping_gate_orchestration_separation.py` 增加集成用例
|
||||
- 可选:轻量 spy Job enqueue,避免真实 RPA
|
||||
|
||||
- [x] **Step 1: 集成断言**(`test_happy_path_generate_excel_only_in_artifact_attempt`)
|
||||
- [x] **Step 2: 跑测试至全绿**
|
||||
|
||||
---
|
||||
|
||||
### Task 5: 次要债务(可同 PR 或 follow-up)— 恢复路径嵌套
|
||||
|
||||
**Files:**
|
||||
- Modify: `process_gate_executor.py` → `_handle_retry_inventory_from_field_mapping`
|
||||
|
||||
- [x] **Step 1: 评估范围** — **Follow-up P1**(本迭代不拆):映射恢复 Attempt 仍嵌套 `_handle_retry_inventory_matching`;函数注释已标注目标形态。
|
||||
|
||||
- [ ] **Step 2: 若本迭代纳入** — 延期。
|
||||
|
||||
---
|
||||
|
||||
### Task 6: 文档与死代码标注
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/features/shipping-notice/process-gate-recovery-contract.md`
|
||||
- Modify: `docs/features/shipping-notice/technical.md`(`try_auto_chain` / auto excel 相关)
|
||||
- Modify: `progress_workflow.py` 文件头注释(标明 P0-3 后旧跨 Gate 体为 dead)
|
||||
|
||||
- [x] **Step 1: 契约增补一条硬规则**
|
||||
- [x] **Step 2: technical.md 开心路径改为「match pass → enqueue artifact Attempt」**
|
||||
- [x] **Step 3: 可选清理** — `_dispatch_legacy_orchestration` / STEP 3 注释标 DEPRECATED。
|
||||
|
||||
---
|
||||
|
||||
### Task 7: 验收清单(人工)
|
||||
|
||||
- [ ] 重匹配成功后:诊断/Attempt 列表出现 **独立的** `artifact_generation` Attempt(不仅是 matching)。
|
||||
- [ ] 右卡在生成中短暂停留「Excel 生成」而非匹配完成后瞬间跳过。
|
||||
- [ ] 生成失败:仅 artifact Attempt `blocked_retryable` +「重新生成 Excel」;matching 保持 passed。
|
||||
- [ ] `AUTO_GENERATE_EXCEL=false`:匹配通过后停在可点「重新生成」,不静默 noop。
|
||||
- [ ] `AUTO_UPLOAD=true`:artifact pass 后再出现 freight Attempt(不在 match 内嵌 upload)。
|
||||
- [ ] i18n / `can_fulfill_complete_line` 等已合入改动回归仍正常。
|
||||
|
||||
---
|
||||
|
||||
## 风险与回滚
|
||||
|
||||
| 风险 | 缓解 |
|
||||
| --- | --- |
|
||||
| 匹配通过后若 enqueue 失败会停在无 Excel | 测试锁 enqueue;失败时 UI 仍有 regenerate |
|
||||
| 延迟增加(多一个 Job) | 可接受;观测性优先 |
|
||||
| 旧 chat tool 仍调 `try_auto_chain` | Gate 路径切断;遗留路径改为只 submit auto_progress |
|
||||
| sync 与 enqueue 竞态 | 沿用现有 Job 去重 / idempotency_key;禁止 sync 提前 passed artifact |
|
||||
|
||||
回滚:恢复 `try_auto_chain` 内 generate(仅应急);正式修复应保留独立 Attempt。
|
||||
|
||||
---
|
||||
|
||||
## 建议实施顺序
|
||||
|
||||
1. Task 1 红灯
|
||||
2. Task 2 拆 chain
|
||||
3. Task 3 sync + enqueue
|
||||
4. Task 4 集成
|
||||
5. Task 6 文档
|
||||
6. Task 5 视排期
|
||||
7. Task 7 人工验收
|
||||
|
||||
**非目标(本计划不做):** 重写 20 Gate 模型、改前端按钮契约、合并 excel_readiness 与 artifact、删除全部 legacy auto_progress 函数体。
|
||||
@@ -0,0 +1,181 @@
|
||||
# 货代域状态契约统一(Phase A–E)
|
||||
|
||||
> **日期**:2026-09-06
|
||||
> **范围**:shipping-notice 对外状态词 / 投影边界
|
||||
> **权威手册**:落地后同步 [`docs/features/shipping-notice/technical.md`](../../features/shipping-notice/technical.md)「状态契约统一」节
|
||||
> **Phase A 状态**:已完成(`project_notice_upload_status` / `project_facts_upload_state`)
|
||||
> **Phase B/D/E 状态**:已完成(2026-09-06;C 仍待做)
|
||||
> **本轮未做**:Phase C match 拆名;D1c 全局停发 `pending_human_reason`
|
||||
|
||||
---
|
||||
|
||||
## 1. 方法论(以 Phase A 为模板,B–E 强制同款)
|
||||
|
||||
Phase A 已验证的最佳实践,**后续 Phase 一律照此执行**,不再用「过渡期同义词 / 双读 / LEGACY 兜底」:
|
||||
|
||||
| 原则 | 含义 | 反例(禁止) |
|
||||
|---|---|---|
|
||||
| **单一判词** | 每个对外字段、每个语义位只有一个规范词;调用方只写 `== 'canonical'` | `{'uploaded','succeeded','success'}`、`includes([...])` |
|
||||
| **单点投影** | 跨层翻译只发生在**一个** projector/mapper;业务/FE 禁止再造轮子 | 各文件自写 frozenset、入口散落 OR |
|
||||
| **层内一词 ≠ 层间一词** | Attempt / Artifact / Job / Gate / Tool 可保留各自库内词;**同名对外字段**必须经投影后只暴露本层契约词 | 把 Attempt.`succeeded` 直接塞进名为 `upload_status` 的 API |
|
||||
| **硬切、无历史兼容** | 不读旧别名、不双字段镜像、不 LEGACY-UNIFY;测试与 FE 同步删兜底 | 「先发双认、下个版本再删」 |
|
||||
| **故意双层保留** | Gate→`user_status`、五段 `lifecycle_stage` vs 15 段 stage、`lifecycle_status` vs runtime 是**分层设计**,不是同义词债 | 为了「统一」把 F2 与 stage 压成一词 |
|
||||
|
||||
成功判据(每个 Phase 自检):
|
||||
|
||||
1. 存在唯一投影/映射函数(或已有契约 helper,禁止新建平行集合)。
|
||||
2. 调用点全部改为单一等值判断或既有域谓词(如 `has_verified_upload_success`)。
|
||||
3. 前后端测试不再断言或接受别名。
|
||||
4. `technical.md` 写明该字段的规范词与禁止项。
|
||||
|
||||
---
|
||||
|
||||
## 2. Review 结论(仍成立)
|
||||
|
||||
同类债不止 `upload_status`:内部枚举泄到对外字段、或同字段混多域词,迫使 frozenset / `includes` 兜底。
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph keep [故意双层_保留]
|
||||
Gate["Gate/Execution"] --> UserStatus["user_status F2六值"]
|
||||
Machine15["15段 processing stage"] --> Lifecycle5["lifecycle_stage 五段"]
|
||||
end
|
||||
subgraph done [Phase A_已收口]
|
||||
Attempt["Attempt.succeeded"] --> UploadProj["project_notice_upload_status → uploaded"]
|
||||
Attempt2["Attempt/Artifact"] --> FactsProj["project_facts_upload_state → succeeded"]
|
||||
end
|
||||
subgraph todo [B-E_待硬切]
|
||||
HumanMix["跨层: waiting_human / waiting_review / needs_human / idle"]
|
||||
MatchMix["同名多域: match_status"]
|
||||
JobMix["Job→automation 散落 synonym"]
|
||||
Hygiene["canceled/done/error 入口与读侧"]
|
||||
end
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Phase A — 上传边界(已完成 · 模板)
|
||||
|
||||
| 层 | 字段 | 规范成功词 |
|
||||
|---|---|---|
|
||||
| Attempt(库内) | `ShippingUploadAttempt.status` | `succeeded` |
|
||||
| Artifact(库内) | `ShippingExportArtifact.status` | `uploaded` |
|
||||
| Notice 面 API | `upload_status` | **`uploaded`**(经 `project_notice_upload_status`) |
|
||||
| facts | `facts.upload_state` | **`succeeded`**(经 `project_facts_upload_state` ∈ `PROJECTION_UPLOAD_STATES`) |
|
||||
| 业务完成谓词 | — | `has_verified_upload_success`(三层验证,非同义词 OR) |
|
||||
|
||||
调用方只允许 `projected == 'uploaded'` 或 `has_verified_upload_success`;禁止再读 Attempt 原词做成败。
|
||||
|
||||
---
|
||||
|
||||
## 4. Phase B — human-wait:跨层硬切(重评)
|
||||
|
||||
### 问题本质(与 A 不同)
|
||||
|
||||
**不是**同一语义的多别名,而是 **把不同层的词当成同义词**:
|
||||
|
||||
| 层 | 规范词 | 用途 |
|
||||
|---|---|---|
|
||||
| Wire `user_status`(F2) | **`waiting_human`** 等六值 | 唯一用户主态;已有 `user_status_for_gate_status` |
|
||||
| Processing / lifecycle **stage** | 可含 `waiting_review`、`order_review` 等 | 阶段位置,**不是** user_status |
|
||||
| Tool 响应 `status` | `needs_human` | Agent/Tool 契约,**不得**泄入 `user_status` |
|
||||
| 废弃/脏词 | `idle`、`pending_review` 作 user_status | **停发**;读侧不认 |
|
||||
|
||||
当前债:FE [`normalizeLifecycleStatus`](../../../frontend/src/features/chat/shipping/conversationProcessingProjection.ts) 的 `[LEGACY-UNIFY]` 把 `waiting_human` 压成 `waiting_review`;卡片仍 `waiting_human \|\| idle`。
|
||||
|
||||
### 落地做法(同款原则)
|
||||
|
||||
1. **不新造** synonym projector;复用 `process_gate_contract.USER_FACING_TASK_STATUSES` + 既有 Gate→user mapper。
|
||||
2. 后端保证 wire `user_status` ∈ F2 六值;**禁止**把 stage 词或 Tool `needs_human` 写入 `user_status`。
|
||||
3. FE:**删除** LEGACY-UNIFY;`userStatus === 'waiting_human'` 单判;文案/stage 走独立 stage 字段。
|
||||
4. **无兼容期**:停发即删读侧别名;测试锁定混层必失败。
|
||||
|
||||
### 不做
|
||||
|
||||
- 不把 `waiting_review` 并进 `waiting_human`(那是 stage)。
|
||||
- 不把 Tool `needs_human` 改成 `waiting_human`(换一层契约,属于另案)。
|
||||
|
||||
---
|
||||
|
||||
## 5. Phase C — match_status:同名多域拆字段(重评)
|
||||
|
||||
### 问题本质
|
||||
|
||||
**同音异义(homonym)**,不是同义词:`match_status` 被 inventory / profile / STP / ledger 共用不同枚举。
|
||||
|
||||
### 落地做法
|
||||
|
||||
1. **拆名硬切**(无双读旧字段):
|
||||
- 任务履约:`inventory_match_status` ∈ {`fulfillable`,`partial`,`unfulfillable`,…}(以 `match.py` / 行聚合为准)
|
||||
- 模板路由:`profile_match_status` ∈ profile 路由枚举
|
||||
2. STP / ledger / audit **改写**到对应域词;禁止再用 `matched`/`shortage` 冒充 fulfillable 语义。
|
||||
3. 行级对外只发 `inventory_matched`;FE 删 `matched` 双认。
|
||||
4. 单点:聚合只走既有 `aggregate_match_status_for_task`(或改名后的唯一出口),调用方 `==` 域内一词。
|
||||
|
||||
### 不做
|
||||
|
||||
- 不写「旧 match_status OR 新字段」过渡读。
|
||||
- 不把三域枚举塞进一个 frozenset「统一成功」。
|
||||
|
||||
---
|
||||
|
||||
## 6. Phase D — blocking_reason / Job→automation(重评)
|
||||
|
||||
### D1 `blocking_reason`
|
||||
|
||||
- Wire **只暴露** Gate 形 `blocking_reason` / `blocking_reason_code`。
|
||||
- `pending_human_reason`:可留作写库镜像,**读 API 停发、FE 停读**(硬切,不做双字段兼容窗口)。
|
||||
- 判定复用既有 Gate 投影,不新造 reason synonym 表。
|
||||
|
||||
### D2 Job → Case `automation.status`
|
||||
|
||||
- 抽取**唯一** `project_job_to_automation_status(job, …)`(落点靠近现有 [`order_review_workbench_projection`](../../../backend/app/services/shipping_notice/order_review_workbench_projection.py) 内联逻辑)。
|
||||
- Job 库内可保留 `succeeded`/`dead` 等;**mapper 内**翻译一次;调用方只见 Case automation 枚举,禁止 `{succeeded,success,completed}` / `{failed,dead}` 散落。
|
||||
- FE 只消费投影后的 automation 枚举。
|
||||
|
||||
---
|
||||
|
||||
## 7. Phase E — 入口卫生 + 不变量门禁(重评)
|
||||
|
||||
与「兼容入口归一」旧表述不同:**读侧零别名,写侧单点规范化**。
|
||||
|
||||
1. 每个子系统一个 write-path normalizer(取消态只认 `cancelled`;禁止读侧再认 `canceled`/`done` 作同义)。
|
||||
2. `failed`/`error`/`fatal`:对外失败词按该层契约定一词;其余只在 mapper 入口吸收并**立刻写成规范词**,库外不泄漏。
|
||||
3. 不变量测试:关键 API 字段 ∈ 契约集合;**禁止**在 projector 模块外新增 synonym frozenset(CI/单测扫描或显式白名单)。
|
||||
4. Phase A 已示范:成功路径不留 `success` 对外出口。
|
||||
|
||||
---
|
||||
|
||||
## 8. 执行顺序与切片
|
||||
|
||||
| Phase | 状态 | 建议触发 | 依赖 |
|
||||
|---|---|---|---|
|
||||
| **A** 上传投影 | **完成** | — | — |
|
||||
| **B** human-wait 跨层硬切 | **完成** | — | 不动 Gate→user 设计 |
|
||||
| **C** match 拆名 | 待做 | STP/ledger 再踩坑或 API 演进窗口 | 独立变更,忌与 B 绑死 |
|
||||
| **D** reason / automation | **完成(D1b+D2)** | D1c 全局 PH 停发可另开 | 写路径 PH 列保留 |
|
||||
| **E** 卫生门禁 | **完成(最小门禁)** | 全量入口归一可跟 C | `test_shipping_status_contract_hygiene` |
|
||||
|
||||
**禁止**:发现债就一次清完;每个 Phase 单独可验证、单独可回滚。
|
||||
|
||||
---
|
||||
|
||||
## 9. 明确保留(不要合并)
|
||||
|
||||
- Gate/Execution → `user_status`(F2)
|
||||
- `lifecycle_stage`(五段)vs 15 段 processing stage(`freight_upload` vs `freight_uploading` 属分层)
|
||||
- `lifecycle_status`(active/voided/…)vs runtime status
|
||||
- STP `progress_nodes` 诊断 ≠ UI 真源
|
||||
- FileAsset.`upload_status`(另一产品面)
|
||||
|
||||
---
|
||||
|
||||
## 10. 与旧计划差异(本次重评)
|
||||
|
||||
| 旧表述 | 新表述 |
|
||||
|---|---|
|
||||
| B:冻结 wire,LEGACY 后端停发后再删 FE | B:**立即硬切**;删 LEGACY-UNIFY;跨层分词而非 synonym 合并 |
|
||||
| C:拆分/冻结,可过渡 | C:**拆名硬切、无双读** |
|
||||
| D:双字段可共存一段时间 | D:**读侧只留 blocking_reason**;PH 停发 |
|
||||
| E:入口归一 + 兼容拼写 | E:**写侧单点规范化 + 读侧零别名**;不变量禁 frozenset 扩散 |
|
||||
| 「过渡期同义词兜底」 | **全面取消**;与 Phase A 一致 |
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
# 发货 Excel 单据编号与库存结果重读设计
|
||||
|
||||
## 背景与目标
|
||||
|
||||
当前 `ShippingNotice.business_no` 在客户确认/正式建单时分配,并被工作台展示为“发货通知单号”。这与实际业务不一致:现有的 `ShippingNotice` 就是发货通知单实体,但应延后到其 Excel 首次成功生成的同一业务事务中创建;一个发货通知单可覆盖多条订单明细,而每条订单明细只能归属一个有效发货通知单。Excel 是发货通知单的外在文件表示,不是业务主实体。
|
||||
|
||||
同时,库存 RPA 超时后,业务人员需要先重新读取已经产生但未被系统消费的库存结果;该操作不得再次触发 RPA。
|
||||
|
||||
本设计的目标是:
|
||||
|
||||
1. 复用现有 `ShippingNotice` 承载单号和订单明细归属,而非以 Excel Artifact 承载业务身份。
|
||||
2. 保证发货通知单与首次生成的 Excel 在同一事务中产生;一个通知单覆盖一个固定的订单明细集合。
|
||||
3. 在库存 RPA 超时后,提供只读取并挂接有效库存快照的恢复动作。
|
||||
|
||||
## 数据模型与编号边界
|
||||
|
||||
复用现有 `ShippingNotice` 作为发货通知单实体,使用其 `business_no`、业务日期、日内流水、规则版本、所属正式订单及状态字段;其现有 Reservation/Artifact 明细关联以订单明细为外键,并对有效归属建立唯一约束。`ShippingExportArtifact` 只保存该通知单的 Excel 文件版本和生成输入快照。
|
||||
|
||||
首次生成 Excel 时,在同一数据库事务内完成以下操作:
|
||||
|
||||
1. 根据经库存匹配确认的订单明细/Reservation 创建现有 `ShippingNotice`,并冻结其归属集合。
|
||||
2. 按客户、上海业务日期为该发货通知单分配业务编号。
|
||||
3. 创建并校验该通知单的首个 Excel Artifact,并将 Artifact 关联到通知单。
|
||||
4. 提交事务后才将发货通知单、Excel 文件及单号作为正式结果对外展示。
|
||||
|
||||
编号写入失败、明细绑定失败或 Artifact 校验失败时,整个生成事务失败,不得暴露发货通知单、无编号 Excel 或订单明细占用。
|
||||
|
||||
新流程不再在客户确认/正式订单创建阶段分配 `ShippingNotice.business_no`,而是在创建该 Notice 与首个 Excel 的同一事务分配。历史记录仍可查询、下载和审计;新投影和新货代操作使用该 Notice 的 `business_no`。
|
||||
|
||||
一个 `ShippingNotice` 恒等于一张发货通知单、一个业务编号和一个 Excel。分批发货时,每个 Excel 都必须创建独立 `ShippingNotice` 并分配独立单号;不得在同一 Notice 下创建第二个 Excel Artifact。模板修订或技术故障需要重出文件时,沿用既有文件修复/替代机制,不得将第二个有效 Excel 挂到同一 Notice,也不得改变已冻结订单明细集合。
|
||||
|
||||
## API、投影与 UI
|
||||
|
||||
处理工作台的“发货通知单号”仅在发货通知单及其首个 Excel 均已在同一事务中成功生成后展示。生成 Excel 前不显示该字段。
|
||||
|
||||
下载 Excel、RPA 上传、人工确认上传、批量上传投影与审计查询均按发货通知单号精确定位通知单,再读取其当前有效 Excel 和已冻结明细集合。不得再把整单 `task_no` 或新流程中的 `ShippingNotice.business_no` 当作外部发货通知单号。
|
||||
|
||||
既有按 Notice 级 `business_no` 的路由和审计语义保持不变。过渡期须兼容历史“先建 Notice 后生成 Excel”的数据;新数据仅在首个 Excel 成功生成时创建 Notice 并分配其 `business_no`。
|
||||
|
||||
## 库存结果重读动作
|
||||
|
||||
新增正式 Gate action:`reload_inventory_result`,仅归属 `inventory_preparation`。
|
||||
|
||||
该动作执行步骤:
|
||||
|
||||
1. 根据当前任务已冻结的库存源和仓库身份查找最新、未过期、状态为 ready 的库存快照。
|
||||
2. 复用现有身份校验和 `link_snapshot_to_task` / `link_snapshot_to_task_for_preparation` 逻辑挂接快照。
|
||||
3. 从快照 JSON 或存储文件读取库存行,并调用既有库存加载/门禁同步流程。
|
||||
4. 写入独立审计事件,记录命中的快照、来源、仓库及读取结果。
|
||||
|
||||
该动作严禁调用 trigger 写入、`retry_rpa` 模式或创建新的 RPA Attempt。未找到有效快照、快照过期或身份不匹配时,以可恢复阻断返回,并下发“重新获取库存”(现有 `retry_inventory_preparation`,明确为重新运行 RPA)和上传库存文件的替代路径。
|
||||
|
||||
RPA 超时对应的 `inventory_preparation` Gate 应将 `reload_inventory_result` 作为首选主动作;用户主动选择“重新获取库存”时才重新创建 RPA 导出。
|
||||
|
||||
## 错误处理与审计
|
||||
|
||||
所有新增 API/服务错误保持 `{ success, data | error, request_id }` 契约,业务失败使用既有 `AppError` 子类。新增错误码必须同步四语言 `errors.json`。
|
||||
|
||||
审计必须能回答:哪个发货通知单在何时因首次 Excel 生成而创建、覆盖哪些 Reservation/订单明细、其当前及历史 Excel Artifact 分别是什么;以及库存重读是否命中快照、为何未命中、是否发生任何 RPA trigger(该操作必须为否)。
|
||||
|
||||
## 测试与验收
|
||||
|
||||
后端测试至少覆盖:
|
||||
|
||||
1. 客户确认和正式建单后不再分配新 Notice 级编号。
|
||||
2. 发货通知单与其首个 Excel Artifact 在同一事务中创建并分配通知单号。
|
||||
3. 同一发货通知单可绑定多个明细;同一明细不能归属两个有效发货通知单;分批导出必须创建不同 Notice、不同单号和不同 Excel。
|
||||
4. 通知单创建、编号、明细绑定或首个 Artifact 校验失败时不留下可用通知单、Excel、单号或 Reservation 占用。
|
||||
5. 同一 Notice 不能生成第二个有效 Excel;分批导出创建新 Notice,并保留 Reservation/明细不可重复归属约束。
|
||||
6. `reload_inventory_result` 命中有效快照时完成挂接和库存加载,且不写 RPA trigger、不创建 RPA Attempt。
|
||||
7. `reload_inventory_result` 无可用快照时返回可恢复阻断,允许用户明确选择重新运行 RPA。
|
||||
8. RPA 超时投影首选“重新读取库存结果”。
|
||||
|
||||
前端测试至少覆盖:Artifact 单号未生成时不显示、生成后显示;RPA 超时时主按钮为“重新读取库存结果”,并保留“重新获取库存(重新运行 RPA)”作为替代动作。四种语言(zh-CN、zh-TW、en、th)均提供新增文案。
|
||||
|
||||
## 非目标
|
||||
|
||||
- 不为每条订单明细生成单独单号;订单明细只能通过通知单明细关联归属一个有效发货通知单。
|
||||
- 不改变库存 RPA Worker、trigger 文件格式、callback 协议或已存在的重新 RPA 行为。
|
||||
- 不修改历史数据的已有 Notice 单号;仅提供兼容读取。
|
||||
@@ -0,0 +1,198 @@
|
||||
# 设计:订单生命周期工作台「下游工作面」单源投影收敛(彻底单源化)
|
||||
|
||||
日期:2026-09-01
|
||||
状态:已确认(方案 2 彻底版:不做历史兼容 / 旧行为保留)
|
||||
关键词:shipping-workbench / fulfillment-prep / freight-upload / upload-complete / single-source-projection / FOIU / skeleton-loading
|
||||
|
||||
> 本文档承接 `2026-08-31-shipping-workbench-stage-lazy-load-design.md`(阶段懒加载)与
|
||||
> `2026-09-01-shipping-stage-capability-window-design.md`(阶段能力集),聚焦订单生命周期工作台
|
||||
> **下游工作面**(通知准备 / 货代上传 / 通知完成)与右卡「当前任务/场景」的**两次投影 /
|
||||
> 先只读后可编**闪烁,并以**彻底单源化**根治。
|
||||
|
||||
## 背景与问题
|
||||
|
||||
进入「通知准备」(`fulfillment_prep`)时,页面先后进入两个状态(用户观察):
|
||||
|
||||
1. **图1(首投影)**:库存匹配表仅有列头、无行数据(或行退化)、右侧「当前任务」显示
|
||||
「步骤未指定」、**不可编辑**(无勾选列、无「选择出库单明细 / 生成发货通知单」工具条)。
|
||||
2. **图2(次投影)**:行矩阵完整、顶部出现 `PJO | ZN…` 订单摘要、右卡显示「场景: 库存匹配」、
|
||||
**可编辑**(工具条 + 勾选列 + 生成按钮出现)。
|
||||
|
||||
用户在 1→2 之间看到「先不可编辑、再变可编辑」的闪烁 —— 即「两次投影 / 不可编辑→可编辑」。
|
||||
|
||||
## 根因(why)
|
||||
|
||||
下游工作面是一个**由多个相互独立、异步到达、且到达时刻不一致的投影拼装**的复合 UI:
|
||||
|
||||
| 表面要素 | 当前来源投影 | 到达通道 |
|
||||
|---|---|---|
|
||||
| 行矩阵内容 / `capabilities` / `source_options` | `formalTaskDetail.ui_state.stage_context.preparation` | `loadFormalTaskDetail()`(挂载预取 + `hasFormalOt` watcher + `progressVersion` watcher) |
|
||||
| **可编辑**(勾选列 / 波次出单工具条) | `activeCase.available_actions` 含 `edit_formal_task` | `loadReviewCase()`(进入下游阶段才懒加载) |
|
||||
| 顶部订单摘要 | `activeCase.draft.header_values.po_number` + `documentNavItems` | `loadReviewCase()` |
|
||||
| 客户 PO 行号列 | `displayCase.schema.fields` + `displayDraftLines` | `loadReviewCase()` |
|
||||
| 右卡「场景/下一步」 | `shippingProcessingProjection`(主)+ `activeCase.current_stage`(兜底) | `useShippingProcessingWorkItem`(轮询) |
|
||||
|
||||
下游各段的渲染门仅为 `hasCreatedShippingTask && formalTaskDetail && <stage>`;而
|
||||
「可编辑性 + 摘要 + 客户 PO 列 + 右卡阶段兜底」都依赖 **`activeCase`(review Case)**。下游阶段
|
||||
`activeCase` 默认**不加载**、要等 `loadReviewCase` 二次触发 → 与 `formalTaskDetail` 错峰 → 先只读残缺
|
||||
(图1),后可编辑完整(图2)。
|
||||
|
||||
> 行业定性:这是 **Flash of Incomplete UI(FOIU)/ loading 状态泄漏**。React Query / SWR / Relay
|
||||
> 的核心约定是一个资源只有 `isLoading → data`(或 `isLoading → error`),**禁止把"已渲染但语义上是
|
||||
> 半成品"的中间态当作真实状态**。当前实现恰好把"内容已到、可编辑性未到"当作"就绪",于是泄漏了
|
||||
> 半成品只读态。
|
||||
|
||||
## 五阶段双投影审计(2026-09-01 全量核查)
|
||||
|
||||
对五个阶段逐面核查「是否由多个独立、异步、错峰到达的投影拼装」。结论如下:
|
||||
|
||||
| 阶段 / 面 | 主来源投影 | 是否双投影 | 说明 | 处置 |
|
||||
|---|---|---|---|---|
|
||||
| 接收解析 `intake_parse` | `activeCase` + `intakeParseContext` | 否(低风险) | 编辑器单源;context 有授权门 + `caseContentSkeleton` 骨架 | 边界外(编辑器单源) |
|
||||
| 订单复核 `order_review` | `activeCase` | 否 | 复核编辑器单源;`caseContentSkeleton` 骨架 | 边界外(编辑器单源) |
|
||||
| **通知准备 `fulfillment_prep`** | `formalTaskDetail.ui_state` + **`activeCase`(`formalEditable`)`** | **是(核心)** | 可编辑性/摘要/客户 PO 列依赖懒加载 `activeCase` → 先只读后可编 | **彻底单源化** |
|
||||
| 货代上传 `freight_upload` | `formalTaskDetail`(门)+ `freightNoticeGroups` | 否 | 内容/动作来自任务级 `group.available_actions`(非 `activeCase`);有 `freightNoticeGroupsLoading` 占位 + stale-while-revalidate | 一并单源化(门/内容仍任务级) |
|
||||
| 通知完成 `upload_complete` | `formalTaskDetail`(门)+ `freightNoticeGroups` | **是(轻)** | 段内**缺加载占位**:直接渲染 `uploadedFreightNoticeGroups.length`,直入时闪「0 已上传/空」再填充 | **补加载占位** |
|
||||
| **右卡「当前任务/场景」(跨全部阶段)** | `shippingProcessingProjection`(主)+ **`activeCase.current_stage`(兜底)** | **是(跨阶段)** | 下游阶段 `activeCase` 不加载 → 阶段兜底缺失 → 先「步骤未指定」占位后真值(`currentProcessingStageDisplay`,`ShippingOrderReviewView.vue:223`) | **彻底单源化** |
|
||||
|
||||
**结论**:根治对象为**全部下游工作面(通知准备 / 货代上传 / 通知完成)+ 右卡当前任务/场景**。
|
||||
两个编辑器阶段(接收解析 / 订单复核)本就是单源(`activeCase` 为其权威),保持不动。
|
||||
|
||||
## 方案(彻底单源化:后端驱动 + 前端原子渲染)
|
||||
|
||||
### §1 目标与边界
|
||||
|
||||
**目标**:让**所有下游工作面**(通知准备 / 货代上传 / 通知完成)与**右卡当前任务/场景**完全脱离
|
||||
`activeCase` / `displayCase` / `formalEditable`,只由**一个权威投影** `formalTaskDetail.ui_state`
|
||||
(+ 既有的 `shippingProcessingProjection` 承担实时自动化/进度)驱动,一次原子渲染,消除一切
|
||||
「先只读后可编 / 空→有 / 步骤未指定→场景」的两跳。
|
||||
|
||||
**边界(不做)**:
|
||||
- 不改顶部五阶段导航结构。
|
||||
- 不重构「订单复核 / 接收解析」编辑器(`activeCase` 是它们的权威单源;见审计表)。
|
||||
- 不引入 GraphQL / BFF / 新框架 / 新状态库。
|
||||
|
||||
### §2 后端:`ui_state` 作为下游工作面唯一权威(单源 DTO)
|
||||
|
||||
`build_task_ui_state`(经 `/shipping-tasks/<task_no>?view=workbench`,恒 `include_stage_context=True`,
|
||||
见 `api/workspace/shipping_notice.py:557`)是下游工作面的**唯一权威**。在其已有基础上补齐
|
||||
下游面当前被迫从 review Case 取的字段:
|
||||
|
||||
```jsonc
|
||||
// stage_context.preparation(在现有 status/lines/source_options/source_locked/capabilities 基础上)
|
||||
{
|
||||
"editable": true, // 【新增】任务级:本正式 OT 已确认且非仅查看 → 工作面可操作
|
||||
// preparation_lines[] 新增原生 customer_po_line_no(业务核对主键;区别于已下发的 line_no/line_no_source,
|
||||
// 后者可能退化为内部行序 sequence)。列头用标准字段名「客户 PO 行号」(standard_field_registry.py:134)i18n;
|
||||
// 列是否展示由前端按 prep 行是否含 customer_po_line_no 简单判定,无需单独后端标志。
|
||||
}
|
||||
// 【不在后端改】顶部「PJO | ZN…」摘要由前端用既有投影拼装:
|
||||
// file_name ← Run/Queue item;po_number ← shippingProcessingProjection.sourceSummary.poNumber;
|
||||
// version ← reviewProgressContext(reviewProgressVersionLabel);caseNo ← route 参数。
|
||||
// 不读 activeCase,也不新增后端 summary 字段。
|
||||
```
|
||||
|
||||
**关键决策**:
|
||||
- **`editable`(任务级)**:取值 == 现有 `edit_formal_task` 判据(`case.status=='confirmed'` 且存在
|
||||
`confirmed_task_no`,见 `order_review_projection.py:603-608`),即「live 已确认正式 OT,非历史/作废查看」。
|
||||
**后端判据(明确化)**:存在正式任务号(`task.order_task_no` / 关联 `confirmed_task_no`)**且**
|
||||
`task.lifecycle_status` 不属于 `{closed, cancelled}` 时置 `true`;被替换/历史/作废视图置 `false`。
|
||||
- **`edit_window` 不替代 `editable`**:`edit_window`(`editable_scope`,`order_edit_window_service.py:123`)
|
||||
是 D10 **字段级**`{header, lines}` 编辑窗,判据「无 Export Artifact 且无活动 Attempt」,Excel 生成后
|
||||
会变 `false`;而「波次出单」需要任务级「已确认 OT」。二者语义不同,不可互换。`edit_window` 仅用于
|
||||
正式任务编辑器字段级读写锁定。
|
||||
- **下游面零 `activeCase` 依赖**:`hasCreatedShippingTask` / `hasFormalOt` / `confirmedNoticeTaskNo`
|
||||
全部由 Run/Queue 摘要项(后端已带 `has_formal_ot`/`confirmed_task_no`,见
|
||||
`order_review_projection.py:1173-1174`)与 `ui_state` 供给,不再读 `activeCase`/`displayCase`。
|
||||
|
||||
### §3 前端:下游工作面只渲染该单源 + 原子门 + 骨架/占位
|
||||
|
||||
**通知准备**:
|
||||
- 新增 `preparationSurfaceReady`:`formalTaskDetail && ui_state.stage_context.preparation` 完整;
|
||||
未就绪渲染骨架(复用现有 `formalTaskDetailPending` 分支),就绪后**一次渲染完整可编辑面**。
|
||||
- 新增 `preparationEditable`:`computed(() => ui_state.stage_context.preparation?.editable ?? false)`;
|
||||
替换模板三处 `formalEditable`(勾选列 / 「选择出库单明细 + 生成发货通知单」工具条 / 行级选源)。
|
||||
- **删除 `formalPreparationContext` 的 `[B1]` 兜底**(回退 `displayCase.line_fulfillment` 正是"只读半成品"
|
||||
来源);Prep 面只认 `ui_state.stage_context.preparation`。
|
||||
- 顶部订单摘要改由**既有投影拼装**(Run/Queue item + `sourceSummary.poNumber` + `reviewProgressContext`),
|
||||
不再读 `activeCase`;客户 PO 行号列改由 §2 DTO(`lines[].customer_po_line_no`)供给,不再依赖
|
||||
`displayCase`/`displayDraftLines`/`lineSchemaFields`。
|
||||
|
||||
**货代上传 / 通知完成**:
|
||||
- 内容与动作继续由任务级 `freightNoticeGroups` + `group.available_actions` + `formalTaskDetail.ui_state`
|
||||
供给(本就是任务级,无 `activeCase`);**通知完成段补 `freightNoticeGroupsLoading` 加载占位**,
|
||||
消除直入时「0 已上传/空」先行。
|
||||
|
||||
**右卡当前任务/场景(真单源)**:
|
||||
- `currentProcessingStageDisplay` 的「当前阶段/场景」**只读 `shippingProcessingProjection`**(实时、轻量、已轮询),
|
||||
不读 `ui_state` / `activeCase.current_stage` —— 避免「同一语义多源先 A 后 B」的闪烁。
|
||||
- **投影未就绪** → 返回空阶段,由右卡在 `loading` 时渲染骨架占位(`stageLoading`);**不是**「步骤未指定」
|
||||
之类的误导值。`isLoading → data`,无两跳。
|
||||
- `ui_state` 不参与右卡阶段(它只用于下游工作面内容);终态「通知完成」由投影
|
||||
(`uiState.lifecycleStage==='upload_complete'` / `userStatus==='completed'`)判定。
|
||||
- 保留 `loading` fail-closed(投影读取中抑制可执行动作)语义。
|
||||
|
||||
**统一**:下游路径与 `activeCase` / `displayCase` / `formalEditable` 解除所有读关系;
|
||||
`loadReviewCase()` 只在进入「订单复核 / 接收解析」编辑器时触发(`REVIEW_EDITOR_NEEDED_STAGES`
|
||||
仅保留这两阶段)。
|
||||
|
||||
### §4 数据流(下游工作面原子首屏)
|
||||
|
||||
```
|
||||
Run + Queue(导航/阶段入口 + has_formal_ot/confirmed_task_no)──┐
|
||||
任务详情 view=workbench(ui_state 单源:行矩阵+capabilities+editable+摘要+客户PO列)──┼─ 并行
|
||||
work-item 投影(OT;右卡阶段/实时自动化/进度) ────────────────┘
|
||||
复核 Case + Evidence ── 默认不拉;进入「订单复核 / 接收解析」才拉
|
||||
```
|
||||
|
||||
各下游面模板门均为「该面单源就绪」原子门;loading→骨架/占位;ready→完整面;无中间只读/空态。
|
||||
|
||||
### §5 加载 / 错误 / 回归
|
||||
|
||||
**加载态**:骨架 / 加载占位;**错误态**:沿用 `formalTaskDetailLoadFailed` + 「重新加载」按钮;
|
||||
全程不出现「半成品只读 / 空→有」中间态。
|
||||
|
||||
**回归测试**(`frontend/src/features/chat/views/ShippingOrderReviewView.spec.ts`):
|
||||
- 进入 Prep:`formalTaskDetail.ui_state` 单源就绪即渲染**完整可编辑矩阵**(勾选列 + 工具条 +
|
||||
「生成发货通知单」);无需二次 `activeCase`;无「只读→可编辑」翻转。
|
||||
- `activeCase` 缺省(下游懒加载)**不影响** Prep 可编辑性与行矩阵(顺序断言:`getReviewCase` 在
|
||||
下游阶段**不被调用**)。
|
||||
- 删除 `[B1]` 兜底后,`displayCase.line_fulfillment` 为空不降级为「只读半成品」。
|
||||
- 右卡:阶段**只由 `shippingProcessingProjection`** 供给;投影未到 → 空阶段 + 骨架占位,
|
||||
不出现「步骤未指定→场景」两跳,也不读 `ui_state`/`activeCase`。
|
||||
- 通知完成:直入(`freightNoticeGroups` 未就绪)时段内显示加载占位,不闪「0 已上传/空」。
|
||||
- 货代上传:保持既有加载占位。
|
||||
|
||||
**后端测试**(`backend/tests/test_shipping_*`):
|
||||
- `stage_context.preparation.editable` 在下发(`include_stage_context=True`)时存在且取值符合
|
||||
「已确认 OT」判据;历史/作废任务为 `false`。
|
||||
- `preparation_lines[].customer_po_line_no` 存在(原始客户 PO 行号,非 `line_no`)。
|
||||
- Run/Queue 摘要项 `has_formal_ot` / `confirmed_task_no` 在下游阶段稳定下发。
|
||||
|
||||
### §6 分阶段落地(小而可验证)
|
||||
|
||||
1. 后端:`ui_state.stage_context.preparation` 增 `editable`;`preparation_lines[]` 增
|
||||
`customer_po_line_no`(原生值,非 `line_no`)。跑 `test_shipping_*` 回归。
|
||||
(摘要不改后端:前端用既有投影拼装。)
|
||||
2. 前端:新增 `preparationSurfaceReady` + `preparationEditable`;替换三处门控;删除 `[B1]` 兜底与
|
||||
下游路径对 `activeCase`/`displayCase`/`formalEditable` 的全部读取;
|
||||
`currentProcessingStageDisplay` 改为**只读 `shippingProcessingProjection`**(投影未到 → 空阶段 +
|
||||
骨架占位,不读 `ui_state`/`activeCase`);摘要去 `activeCase`(既有投影拼装);客户 PO 列读
|
||||
`lines[].customer_po_line_no` + 标准 i18n 列头;`REVIEW_EDITOR_NEEDED_STAGES` 收窄到
|
||||
仅编辑器两阶段;通知完成段补 `freightNoticeGroupsLoading` 占位。`npm run build` 通过。
|
||||
3. 全量回归 + 手动核对(深链带 `task_no` / 批次中心跳转 / 通知准备直接进入),确认无任何
|
||||
「只读→可编辑 / 空→有 / 步骤未指定→场景」两跳;且下游阶段 Network 无 `getReviewCase`/`getReviewEvidence`。
|
||||
|
||||
**效能约束(实现时必须守住)**:
|
||||
1. 右卡阶段只由 `shippingProcessingProjection`(实时轻量轮询)驱动,不耦合 `formalTaskDetail` 重刷新节奏;
|
||||
2. `build_task_ui_state` 不增加触发频率(沿用 `deepLinkTaskPrefetch` + `formalTaskDetailGeneration`
|
||||
代际守卫 + `progressVersion` 变化检测);`view=workbench` 继续裁剪重字段,`ui_state` 只追加小字段;
|
||||
3. `loadFreightNoticeGroups` 保持 `freightGroupsInFlight` 去重 + stale-while-revalidate;
|
||||
4. 下游阶段请求计数 ≈3-4(Run+Queue+taskDetail+work-item),无 `getReviewCase`/`getReviewEvidence`。
|
||||
|
||||
## 自测入口
|
||||
|
||||
- 后端:`PYTHONPATH=D:\Workspace\HxProjects\hxops\backend`,
|
||||
`backend\.venv\Scripts\python.exe -m pytest tests/test_shipping_* -v`(测试环境慢,逐文件跑)。
|
||||
- 前端:`cd frontend && npm run build`(内含 `vue-tsc -b` 类型拦截)。vitest 因 `node:crypto`/vite8
|
||||
暂不可用,以前端 build + 手动核对为主。
|
||||
@@ -0,0 +1,233 @@
|
||||
# 2026-09-01 货代发货通知 — 下线旧 CheckPoint 状态机(收敛到 Gate + 领域数据分离)设计
|
||||
|
||||
> 目标:下线旧粗粒度状态机(`checkpoint` + `checkpoint_kind`),把"进程位置 / 是否人工 / 待办 / 按钮"改由**单一事实来源(SSOT)**推导:**履约+复核位置 = Gate(Process Gate)**,**review case 处置(非订单 / 文件质量异常)= 接收解析节点**,**文档 intake 文本抽取失败 = 文件质量异常处置**。业务领域数据保持独立标量字段,不塞进 Gate。
|
||||
> 前提:模块未正式上线(无历史兼容负担);不影响现有功能需求。这是**减法**。
|
||||
|
||||
---
|
||||
|
||||
## 1. 背景与问题
|
||||
|
||||
### 1.1 现状:两套状态机表达同一个履约进程
|
||||
|
||||
确认后 OT 的"进程位置 + 是否需要人工"存在**两套**表达:
|
||||
|
||||
| 层 | 表达 | 来源 | 现状 |
|
||||
|---|---|---|---|
|
||||
| CheckPoint(旧,粗) | 一个 `checkpoint` id + `checkpoint_kind`(AUTO_CONTINUE / MUST_HUMAN / WAIT_MANUAL_UPLOAD / COMPLETE) | `resolve_task_ui_state`(`state_machine.py:246`)从任务标量字段投影 | 与 Gate 概念重复 |
|
||||
| Process Gate(新,细) | 20 门禁 + Execution/Gate/Attempt + 恢复动作 + 幂等 | `process_gate_contract.py` / `process_gate_service.py` | 真正的工作流状态机 |
|
||||
|
||||
`checkpoint_kind` 那 4 分类**恰好是** `gate_status + responsible_party + blocking_reason → user_mode` 的一张粗查表。**CheckPoint 是 Gate 的粗投影,概念重复 → 违反单一事实来源(SSOT)。**
|
||||
|
||||
### 1.2 关键区分:状态机 ≠ 领域数据 ≠ 派生视图
|
||||
|
||||
这里要分清**三层不同的东西**:
|
||||
|
||||
| 层 | 是什么 | 来源 |
|
||||
|---|---|---|
|
||||
| **Gate** | 工作流/检查状态机(20 gate 各自的 status + attempt + 恢复动作 + 责任方 + 作废链) | Execution/Gate/Attempt 表 |
|
||||
| **领域数据** | `inventory_lines_json`(库存数据)、`export_file_path`(Excel 产物指针)、`match_status`(匹配结果值)、`upload_status`(上传结果) | **领域服务产出**(inventory/fulfillment/upload),Gate 只**校验**其是否就绪 |
|
||||
| **派生视图** | "进程位置 / 是否人工 / 待办 / 用户态 / 阶段摘要" | 旧机由领域数据投影;新设计**由 Gate 推导** |
|
||||
|
||||
**三个约束**:
|
||||
|
||||
1. **Gate ≠ 领域数据**:`inventory_lines_json` 装库存数据、`export_file_path` 是产物指针,Gate 表里没有这些。把领域数据塞进 Gate 会让状态机"爆炸",是过度设计。
|
||||
2. **不能把 Gate 压回领域数据列**:Gate 是**更富**的状态机(每个 gate 的 status/attempt/恢复/作废/责任方),几列标量表达不了;CheckPoint 当初正是因为"标量列太粗"才被 Gate 取代。压回去是倒退。
|
||||
3. **领域数据 ≠ Gate 的缓存**:领域数据是真实数据、由领域服务产出,不是对 Gate 状态的缓存;它只是被 Gate 校验。
|
||||
|
||||
行业最佳实践 = **状态机(Gate)+ 领域数据(标量字段)正确分离**;派生视图(位置/待办/状态)从 Gate 推导。
|
||||
|
||||
---
|
||||
|
||||
## 2. 设计原则
|
||||
|
||||
- **撤**:旧粗状态机(`checkpoint` + `checkpoint_kind`,即 `state_machine.TaskUiState` 的状态机投影)。
|
||||
- **留**:Gate(状态机)+ 标量字段(领域数据/结果)。不把数据塞回 Gate。
|
||||
- **不新增**:不新造第三套状态;只把"位置/是否人工/待办/按钮"从旧机迁到正确轴。
|
||||
- **SSOT**:履约+复核位置 = Gate;review case 处置 = 接收解析节点;领域数据 = 标量字段。
|
||||
|
||||
---
|
||||
|
||||
## 3. 最终 CP 去处(全部 20 个)
|
||||
|
||||
### 3.1 复核 gate(seq1-9,在执行链内)→ 从 Gate 读
|
||||
|
||||
| CP | 位置 | Gate |
|
||||
|---|---|---|
|
||||
| `CP_PARSE_REVIEW` | 解析需人审 | `order_field_extraction` / `document_profile_routing`(needs_human) |
|
||||
| `CP_CUSTOMER_REVIEW` | 客户身份确认 | `customer_resolution`(blocked_manual) |
|
||||
| `CP_RSV_REQ` | Reservation 需人审 | `reservation_validation`(blocked_manual) |
|
||||
|
||||
> 复核 gate 确实在 OT 执行链里(如 exec 51 的 seq5-9 均为 passed),故复核 CP 读 Gate 即可。
|
||||
|
||||
### 3.2 履约/上传/完成 gate(seq10-20)→ 从 Gate 读
|
||||
|
||||
| CP | Gate |
|
||||
|---|---|
|
||||
| `CP_INVENTORY_PENDING` | `inventory_preparation`(pending/queued/running) |
|
||||
| `CP_UPLOAD_REQ` | `inventory_preparation`(RPA 耗尽→补传库存文件) |
|
||||
| `CP_READY_MATCH` | `inventory_matching`(pending,字段映射 passed 后) |
|
||||
| `CP_READY_EXPORT` | `excel_readiness`(pending,满足性 passed 后) |
|
||||
| `CP_EXPORT_READY` / `CP_EXPORT_GENERATED` | `artifact_generation`(passed)→ 货代上传 |
|
||||
| `CP_UPLOAD_FAILED` | `freight_upload_rpa`(failed_terminal / blocked_retryable) |
|
||||
| `CP_UPLOAD_RESULT_UNKNOWN` | `freight_upload_rpa`(waiting_external) |
|
||||
| `CP_WAITING_UPLOAD` | `manual_upload_handoff`(blocked_manual) |
|
||||
| `CP_UPLOADED` | `manual_upload_handoff`(passed)/ `upload_complete` |
|
||||
| `CP_COMPLETED` | `upload_complete` |
|
||||
| `CP_INVENTORY_SOURCE_REVIEW` | `inventory_source_routing`(规则自动) |
|
||||
| `CP_ORDER_FREEZE` | `order_freeze_readiness` |
|
||||
|
||||
### 3.3 review case 处置(接收解析节点)→ 从 review case / disposition 读
|
||||
|
||||
| CP | 处置 | review case |
|
||||
|---|---|---|
|
||||
| `CP_REJECTED` | **标记为非订单**(`mark_non_order`) | `status='non_order'` |
|
||||
| `CP_NOTICE_TEXT_EXTRACTION_FAILED` | **文件质量异常**(`mark_quality_issue`) | `status='quality_issue'` |
|
||||
|
||||
> 这两者本就是"接收解析"节点的处置结果,不是独立状态机节点。`mark_non_order` / `mark_quality_issue` 是建单前人工 gate 的既有动作,`order_review_projection._allowed_actions` 已覆盖(non_order → view;quality_issue → view/mark_quality_issue/reparse)。
|
||||
|
||||
### 3.4 转瞬/信息态 → 省略
|
||||
|
||||
| CP | 处理 |
|
||||
|---|---|
|
||||
| `CP_PARSE_OK` | 省略("解析通过"仅转瞬态,被 gate passed / 推进中吸收) |
|
||||
| `CP_TASK_EXISTS` | 省略("任务已存在"信息态,被 task_creation passed 吸收) |
|
||||
|
||||
## 4. 结论:旧 CheckPoint 状态机可整体下线
|
||||
|
||||
**所有 20 个 CP 节点去处已定**:
|
||||
|
||||
- **16 个 → Gate**(复核 seq1-9 + 履约/上传/完成 seq10-20)。
|
||||
- **2 个 → review case 处置**(非订单 / 文件质量异常)。
|
||||
- **2 个 → 省略**(转瞬/信息态)。
|
||||
|
||||
撤掉 `checkpoint` + `checkpoint_kind` 后:履约+复核位置读 Gate;拒绝/文件质量读 review case;领域数据读标量字段。**无需为任何 CP 硬造 Gate 等价。**
|
||||
|
||||
---
|
||||
|
||||
## 5. 为什么符合行业最佳实践(SSOT)
|
||||
|
||||
- **单一事实来源**:一个状态概念只有一个权威表达(履约+复核 = Gate;处置 = review case)。消除并存的旧粗状态机,即消除反模式的"双写状态"。
|
||||
- **移除被取代的旧代码层**:CheckPoint 是初版粗机,Gate 是为更细控制/恢复/幂等后加。冗余源于"新层到位旧层未撤"。正确修法是在新层验证后删旧层。
|
||||
- **增量迁移**(见 §6):先并行验证、再切换、最后清理,是"状态机替换"的标准流程。
|
||||
- **不过度设计**:下线是往"更少、更单一"走;Gate 复杂由职责需要,不构成保留旧粗层的理由。
|
||||
|
||||
## 6. 一个需要处理的问题:廉价读取(不是保留状态机的理由)
|
||||
|
||||
**先分辨"便宜"的对象**:旧机便宜,是因为它算的**派生视图**(位置/是否人工/待办/状态)由**单行标量列**直接投影(0 join)。而查 Gate 要跨 `executions + gates + attempts` 多表 join。**单任务详情**查 Gate 完全没问题;**批量/列表/待办索引**一次算 N 个任务的待办/状态时,逐任务 join 就是 N+1/重 join,明显变慢。
|
||||
|
||||
**但这不构成保留旧状态机的理由——正确做法是**:
|
||||
|
||||
- **派生视图从 Gate 推导**(进程位置/是否人工/待办/状态 = Gate 的 `user_status`/`user_mode`/`entry_surface`),保持 SSOT。
|
||||
- **为满足廉价读**,把**这个派生视图**做成**缓存**(写到 task 行/派生列),列表/索引读缓存,不 join Gate 表。
|
||||
- **领域数据字段(`inventory_lines_json`、`export_file_path`、`match_status`、`upload_status`)保持原样**——它们是**真实数据,不是缓存**,由领域服务产出、被 Gate 校验。**不要**把领域数据当缓存写回、也**不要**把 Gate 压回这几列。
|
||||
|
||||
> 一句话:**不是"把 Gate 改成读标量列"(倒退),而是"把旧机算的那个派生视图改成读 Gate,并缓存它以满足廉价读";领域数据照旧单独存放。**(此点属后续实现范畴,本期设计仅指出方向。)
|
||||
|
||||
### 6.1 与阶段能力集(`STAGE_CAPABILITY_DEFINITIONS`)的关系
|
||||
|
||||
`STAGE_CAPABILITY_DEFINITIONS`(阶段能力集,定义在别处实现)与**本下线方案正交、不冲突、且方向互相印证**:
|
||||
|
||||
| | 阶段能力集 | 本下线方案 |
|
||||
|---|---|---|
|
||||
| 概念轴 | **动作/权限**(该阶段能点哪些按钮) | **状态/进程**(走到哪、是否人工) |
|
||||
| 字段依赖 | `stage` / `scope` / `action_code` / `invalidate` / `reset_to`(全部 gate/阶段码) | `checkpoint` / `checkpoint_kind` → 改读 Gate + review case |
|
||||
| 是否引用 `checkpoint_kind` | **没有** | — |
|
||||
|
||||
要点:
|
||||
|
||||
1. `STAGE_CAPABILITY_DEFINITIONS` 只写 gate 码/阶段码,**不引用** `checkpoint`/`checkpoint_kind`,故不依赖旧状态机。
|
||||
2. 阶段能力集的核心(触发上游能力 → **作废下游 gate → 重置回 inventory_preparation → 重跑**)正是**把 Gate 当唯一事实源**(通过作废/重置 Gate 表达回退与推进)——**与本下线方案想让"位置从 Gate 推导"方向一致**,甚至是"Gate = 事实源"的先行实践。
|
||||
3. 阶段能力集作废下游时会经 `recovery_invalidation_service` 清 `match_status`/`export_file_path` 等标量:旧机(从标量投影)会自然跟随;下线后从 Gate 读位置,Gate 被重置位置也自然对。**两种口径自洽,不打架**。
|
||||
4. 能力渲染 `ui_state.stage_context.preparation.capabilities`(`_stage_capabilities_for_task`)只读 `lifecycle_stage`/`source_locked`/预条件,**不看 `checkpoint_kind`**。
|
||||
|
||||
**结论**:两者不同轴、可并行、无需因一方改动而改另一方。
|
||||
|
||||
---
|
||||
|
||||
## 7. 消费点迁移
|
||||
|
||||
| 消费点 | 现读 | 改读 |
|
||||
|---|---|---|
|
||||
| 自动推进早停 `progress_workflow.py:415-431` | `checkpoint_kind == MUST_HUMAN / WAIT_MANUAL_UPLOAD` | Gate 推导 `user_mode`(`blocking_reason → BLOCKING_REASON_TO_USER_MODE`)+ `responsible_party` |
|
||||
| 待办分类 `query_service._todo_category_from_ui:722` | `checkpoint + checkpoint_kind` | 履约:Gate `user_status`/`user_mode`;复核:review case 处置 |
|
||||
| 用户态 `user_facing_status.py` | `checkpoint → 用户态` | Gate `user_status_for_gate_status` + review case 处置 |
|
||||
| 阶段上下文/摘要 `ui_state._build_stage_context/_build_task_summary` | `checkpoint_kind` 驱动 `current_todo`/`entry_surface`/阻断文案 | 同轴推导 |
|
||||
|
||||
---
|
||||
|
||||
## 8. 迁移计划(分阶段,低风险)
|
||||
|
||||
### 阶段 1:加轴推导 + 双读(行为不变)
|
||||
- 新增"轴推导"纯函数(履约=Gate、复核=review case 处置)。
|
||||
- 4 个消费点**先读新轴推导**,并**对照旧 checkpoint_kind** 断言一致(双读,不改行为)。
|
||||
- 目的:验证新推导与旧机一致,暴露分歧。
|
||||
|
||||
### 阶段 2:消费点切到新轴
|
||||
- 4 个消费点正式改读新轴推导,移除对 `resolve_task_ui_state` 的 `checkpoint`/`checkpoint_kind` 依赖。
|
||||
- 每切一个,跑该消费点回归。
|
||||
|
||||
### 阶段 3:下线旧机(硬删顺序,禁止跳步)
|
||||
|
||||
> **保留字面量 ≠ 保留状态机**:`parse_review` / `inventory_pending` / `export_ready` 等字符串是
|
||||
> **位置标签**(与 `derive_position` 对齐),可继续作文案/映射表的 key。删的是 **CheckPoint 状态机**:
|
||||
> `CheckpointKind`、`resolve_task_ui_state` 的 CP 裁决、`CP_*` 常量命名,以及 SQL/API 对它们的依赖。
|
||||
|
||||
**强制顺序(后步依赖前步):**
|
||||
|
||||
1. **SQL `todo_category` CASE 切 Gate / `review_status`**
|
||||
`_task_todo_category_sql_expr` / `_order_task_todo_category_sql_expr` 优先读
|
||||
`ShippingProcessExecution.current_gate_code` + `review_status`;与 ORM `task_todo_category`
|
||||
口径对齐后再删旧 checkpoint 分支。列表过滤不得在删旧机后仍依赖 `resolve_task_ui_state` 同序 CASE。
|
||||
|
||||
2. **切断消费点对 `resolve_task_ui_state` 的依赖**
|
||||
确认 progress / query / ui_state / user_facing / chat 均 Gate-first;仅允许迁移期 API
|
||||
别名 `checkpoint_*`(值 = `derive_position` / `derive_user_mode`)。
|
||||
|
||||
3. **下线 `state_machine` CP 裁决**
|
||||
移除 `CHECKPOINT_KIND_REGISTRY` / `CheckpointKind` 作为事实源;`resolve_task_ui_state*`
|
||||
删除或改为薄委托(仅回退无 Execution 的 review_status / 领域标量),**禁止**再输出独立 CP 状态机结果。
|
||||
|
||||
4. **`CP_*` 常量清理 / 改名**
|
||||
`constants.py` 中仅服务旧机的 `CP_*`:能映射为位置标签的改为 `POSITION_*`(或内联字面量);
|
||||
转瞬态 `CP_PARSE_OK` / `CP_TASK_EXISTS` 直接删除。`RS_*` / `PH_*` **保留**。
|
||||
文案表(`_PAUSE_REASON_*`、`_CHECKPOINT_LABELS`)改键为位置字符串,禁止再 import `CP_*`。
|
||||
|
||||
5. **聊天 / Tool 别名收口(可选同 PR 或紧随)**
|
||||
前端已 Gate-first(`shippingUiPosition`);后端 Tool/confirm 响应优先 `position`/`user_mode`,
|
||||
`checkpoint` 字段可暂留别名,硬删 API 字段另开任务。
|
||||
|
||||
6. **回归 + grep 门禁**
|
||||
`grep CP_|CheckpointKind|resolve_task_ui_state` 仅允许测试过渡与明确 deprecated 包装;
|
||||
跑 `test_gate_derivation` + `test_shipping_notice_ui_state` + `test_shipping_notice_query_service` 待办分类。
|
||||
|
||||
### 阶段 4:回归
|
||||
- 全量受影响 `test_shipping_*`;重点:自动推进、待办 SQL/ORM 一致、用户态、五阶段/摘要、F5CDD796 类死局。
|
||||
- 前端:`shippingUiPosition` / `useChatShippingRefresh` / `parseOrderReviewConfirmResponse`。
|
||||
|
||||
---
|
||||
|
||||
## 9. 风险与注意
|
||||
|
||||
| 风险 | 对策 |
|
||||
|---|---|
|
||||
| 复核阶段 CP 停点归属(gate vs review case) | 已核对:复核 gate(seq1-9)在执行链内,CP_RSV_REQ 等读 Gate;非订单/文件质量走 review case 处置 |
|
||||
| 廉价读取(列表/索引)性能 | 用 Gate 派生缓存/字段,不并存状态机(§6) |
|
||||
| 4 消费点漂移 | 阶段 1 双读断言兜住 |
|
||||
| 全量回归耗时(~1-2 min/file) | 只跑受影响 file;分阶段回归 |
|
||||
|
||||
---
|
||||
|
||||
## 10. 验收标准
|
||||
|
||||
- [x] `checkpoint` + `checkpoint_kind` 不再被消费点直接依赖(4 消费点改读 Gate / review case 处置);API 字段已硬删为 `position` / `user_mode`。
|
||||
- [x] "位置 / 是否人工 / 待办分类 / 用户态 / 阶段摘要" 由 Gate + review 推导;领域标量 CP 裁决已删除。
|
||||
- [ ] 履约死局(F5CDD796 类)与正常流不回归(待人工冒烟)。
|
||||
- [x] Gate 与领域数据字段不互相塞入对方(数据仍在标量字段,状态机仍只是状态机)。
|
||||
|
||||
---
|
||||
|
||||
## 11. 不属于本设计的范围
|
||||
|
||||
- **不**把领域数据(库存/Excel/匹配结果)并入 Gate(过度设计)。
|
||||
- **不**重写 Gate 模型本身(保留状态机主轴)。
|
||||
- **不**触及阶段能力集(已在别处实现)。
|
||||
+21
-11
@@ -27,9 +27,9 @@
|
||||
### STP 阶段 0:字段契约与状态语义冻结(2026-07-30,项次派生 Phase 0 纠偏)
|
||||
|
||||
- 标准字段目录锁定 **58** 项;`reservation_id` 可同时存在于 Header 与 Line,资产唯一键为 `(field_code, scope)`。
|
||||
- 运行时投影:`line_key`(草稿稳定标识)、`effective_reservation_id = validated(line) ?? validated(header)`;`line_no` 为可识别内部项次,不再由 `position+1` 系统覆盖。
|
||||
- Schema `definition_json.derivation_rules`:同行明细派生契约(首期仅 `copy_if_empty`,目标仅 `line_no`);新草稿预置关闭的 `customer_po_line_no → line_no`。
|
||||
- `customer_po_line_no` / `line_no` 均进入确定性表格可解析字段集;Excel 导出行号为 `system_fact:export_sequence`。
|
||||
- 草稿行使用 `draft_line_id`;冻结档与库存准备使用 `snapshot_line_id` 和系统生成的 `line_no`;正式通知使用 `ShippingNoticeLine.line_no`。
|
||||
- Schema 不提供派生规则;`line_no` 不进入确定性表格解析字段集,由各单据写路径按顺序生成。
|
||||
- Excel 导出行序号使用已持久化的 `ShippingNoticeLine.line_no`。
|
||||
- 进度事实源仍以后端状态机为准;阶段 0 冻结字段与投影语义。
|
||||
|
||||
### STP 阶段 1:模板起行锚点(2026-07-30)
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
- `stp_line_inventory_match`:准备冻结候选快照行;按 `effective_reservation_id + part_number` 跨文件匹配。
|
||||
- 裁决:`ok` / `shortage` / `not_found` / `multi_file_conflict`;结果写入 `step_payload.line_inventory_resolutions`。
|
||||
- 唯一 ok 源 → `inventory_source_status=resolved` 并 `try_auto_chain_after_match` 生成 Excel(`export_sequence`);多源行级成功命中以主绑定源制单(`stp_line_match_multi`),同键多文件冲突仍停人工。
|
||||
- 库存门禁通过后才创建 `ShippingNotice`/`ShippingNoticeLine` 并生成 Excel;库存准备失败停留在通知准备阶段,多候选源只写一个批量 RPA trigger。
|
||||
- `match_completed` 仅 `fulfillable` 且全部明细 `ok` 时允许 Excel;partial 禁止制单。
|
||||
- OT 后短缺放行复用 `SHIPPING_LINE_AUTO_FULFILL` Job:已审计放行的短缺行可作为 wave 候选;仅唯一开放候选自动创建独立 `ShippingNotice` 并调度 Excel,多候选返回人工勾选,不自动合并或批次放行。
|
||||
- `ensure_inventory` 多候选路径不隐式 RPA;自动链硬停 `wait_manual_upload`。
|
||||
@@ -244,7 +244,7 @@ PDF 证据锚定优先使用现有 `pypdfium2` 逐字文本坐标定位,并由
|
||||
- Excel 命名规则由已发布模板的 `filename_pattern` 定义;未定义时读取环境变量 `SHIPPING_NOTICE_EXPORT_FILENAME_PATTERN`。两者均由后端编译、校验并在 Artifact 保存规则来源、版本、最终文件名和独立流水。客户端请求不得携带命名模式或文件名;流水即使 Artifact 作废亦不得复用。
|
||||
- LLM Observation 必须有真实 `evidence_ref`,并以 `evidence_verified=false` 落库;任意关键字段存在该类 Observation 时,冻结门禁返回 `SHIPPING.ORDER_LLM_REVIEW_REQUIRED`。Dify 故障只能转人工复核,不能使确定性模板路径降级为猜测。
|
||||
- JSON API 按统一 envelope 返回。关键错误码至少包括 `SHIPPING.ORDER_SNAPSHOT_FROZEN`、`SHIPPING.ORDER_LLM_REVIEW_REQUIRED`、`SHIPPING.RESERVATION_CONFLICT`、`SHIPPING.INVENTORY_STALE`、`SHIPPING.EXPORT_NOT_READY`、`SHIPPING.UPLOAD_EVIDENCE_REQUIRED`;权限矩阵禁止 Dify/普通用户调用冻结、制单、上传回调和作废接口。
|
||||
- **引用与快照**:规则保存发布时的 `context_field_id`,发布/运行快照同时冻结字段代码、显示名、Schema 字段配置、规则集版本、定义和命中证据。运行期优先按快照 ID 取值;普通 Schema 升级仅在 `field_code`、Header 作用域、值类型和身份授权均未变化时映射新 ID,实际命中字段 ID 仍写入证据链。字段退役、删除或 Schema 发布移除被启用规则引用字段时服务端阻断。
|
||||
- **引用与快照**:规则保存发布时的 `context_field_id`,发布/运行快照同时冻结字段代码、显示名、Schema 字段配置、规则集版本、定义和命中证据。运行期**以 `field_code`(语义键)优先绑定**当前 Schema 字段,快照 `context_field_id`(UUID) 仅作同字段快速命中兜底;Schema 升级造成字段 UUID 漂移时仍能按稳定 `field_code` 承接旧快照,实际命中字段 ID 仍写入证据链。字段退役、删除或 Schema 发布移除被启用规则引用字段时服务端阻断。
|
||||
- **裁决边界**:客户主体和送货站点独立候选;编码确定性匹配优先;多命中、冲突、未命中均进入人工复核。业务弱证据(地址、联系人、名称)默认不得单独自动确认;公共邮箱域名永久禁止。
|
||||
- **Dify**:不新增 Tool 或修改画布。Dify 继续按已发布动态 Schema 契约提交 Header Observation;HXOPS 完成证据校验、字段裁决、规则匹配、质量门禁和最终确认。
|
||||
- **技术编号与业务编号分离**:`ShippingNotice.task_no` 是内部不可变锚点;`ShippingNotice` 自持 `business_no`、标准客户和编号快照。一个 PO 可对应多个 Notice;每个 Notice 只有一个 `business_no` 和一个 Excel。货代下载、人工确认、RPA 上传和批量 API 只接受 `business_no`,内部 `task_no` 不得作为货代操作维度。
|
||||
@@ -324,8 +324,9 @@ PDF 证据锚定优先使用现有 `pypdfium2` 逐字文本坐标定位,并由
|
||||
- 裁决结果写入 `ShippingOrderFieldDecision/ShippingOrderFieldValue`,流程摘要写入 `ShippingTask.step_payload_json.parse_validation`;字段模型调整必须配套 Alembic 迁移。
|
||||
- 不保留旧字段 alias、双版本读取、固定订单行投影或历史值猜测回填;任务的 `current_order_extraction_id` 是履约读取入口。
|
||||
- 订单抽取提交、人工确认和 `match_inventory` 三层重复执行关键门禁,防止脏值通过任一旁路进入后续履约。
|
||||
- 客户角色采用“解析原文”和“主数据解析”分层:动态 Schema 保存 Bill-to/Ship-to 名称、外部编码、来源系统及地址证据;`ShippingOrderCustomerMatch` 保存角色候选和确认快照;`ShippingCustomerExternalRef`、`ShippingCustomerSite`、`ShippingCustomerSiteIdentifier` 提供外部客户编码与送货站点匹配。LLM 不生成主数据 ID 或客户简称。
|
||||
- 客户匹配遵循外部编码优先、标准名称/已审核别名回退;Ship-to 必须落到启用站点并校验所属客户。Candidate 只展示候选,正式客户绑定和业务编号仍通过既有质量门禁。
|
||||
- 客户识别采用“解析原文”和“规则证据”分层:动态 Schema 保存 Bill-to/Ship-to 名称、外部编码、来源系统及地址证据;已发布 Identity Rule Set 以全部适用证据生成 `ShippingCustomerShadowResolution`,其中 `confirmed_customer_id` 是唯一客户确认事实。`ShippingCustomerExternalRef`、`ShippingCustomerSite`、`ShippingCustomerSiteIdentifier` 只提供可被规则使用的主数据证据。LLM 不生成主数据 ID 或客户简称。
|
||||
- 客户识别可采用外部编码、标准名称、已审核别名或其他已发布证据;Bill-to/Ship-to 不是客户业务角色。Candidate 只展示 Resolution 候选,正式客户绑定和业务编号仍通过既有质量门禁。
|
||||
|
||||
- 单票与多票发货需求统一落入 `ShippingBatch`;单票使用 `file_count=1` 的批次容器。
|
||||
- 库存 Excel 上传后保存为 `shipping_inventory_files` 批次库存快照,并通过 `shipping_task_inventory_links` 关联到本批任务。
|
||||
- 字段映射与完整库存解析在库存快照层完成一次;每票仍使用自己的发货需求行独立执行库存匹配、Excel 生成与上传。
|
||||
@@ -1323,9 +1324,15 @@ Dify
|
||||
- `summary_points`:知识点复盘数组
|
||||
- `summary_checklist`:考前必知数组
|
||||
- `question_bank`:结构化题库(`id/type/prompt/answer/explanation/options`)
|
||||
- 培训配置管理页新增工作区文案字段,统一保存在 `TrainingConfig.settings`:
|
||||
- `progress_items`:学员侧进度项数组,通用培训按 `video/summary/exam/result` 解释,安全培训按 `company/department/team/exam` 解释
|
||||
- `progress_hint_text`:培训进度说明文案,最长 500 字
|
||||
- `step_intro_text`:步骤引导文案,最长 500 字
|
||||
- 员工培训工作区读取顺序:
|
||||
1. 优先读取 `extra_config.training_config`
|
||||
2. 若某项未配置,则仅该项回退到前端默认值,保证旧 Agent 不因缺字段而失效
|
||||
1. 优先读取已发布 `TrainingConfig.settings`
|
||||
2. 若未命中发布配置,再兼容读取 `extra_config.training_config`
|
||||
3. 对入职培训、安全培训的存量配置,后端序列化阶段自动补默认进度说明和步骤引导文案,避免旧数据出现空白
|
||||
- 学员侧通用培训进度模块只根据 `progress_items` 动态渲染;当该数组为空时,整个进度模块隐藏,避免显示静态默认流程。
|
||||
- 题库题量改为后台可配后,前端分数计算改为“按当前题量折算百分制”,不再硬编码每题 5 分。
|
||||
- 管理端支持从已上传并标记为 `training_exam_pdf` 的指南 PDF 解析题库:
|
||||
1. 后端按 `guide_id` 读取 PDF 文本
|
||||
@@ -1448,8 +1455,7 @@ Dify
|
||||
- **受控坐标预览**:页面授权写入 Redis,key 为随机令牌且 TTL 120 秒;每个 token 固定管理员、Profile、Document、page_no,并通过 `GETDEL` 原子消费。Redis 不可用时预览 fail-closed。PDF 只在后端渲染低清单页 PNG;文本候选和局部预览按 Profile 样本关联再次鉴权,响应设置 `Cache-Control: private, no-store`。OCR 只能经绑定样本的显式管理员请求生成,EML 复用 HTML 白名单清洗结果且不渲染可执行 DOM。
|
||||
- **模板版本中心数据边界**:版本列表接口只返回族摘要和版本摘要,不返回 PDF、正文、大体积 Layout payload 或盲测真值。版本详情接口返回 Profile 元数据、Schema 摘要、定义摘要、配置规模、冻结证据摘要、样本摘要、测试摘要、自动冻结资格摘要、来源版本和 checksum;样本画布预览接口必须以冻结样本绑定身份鉴权,短时、单用途、管理员绑定且 `no-store`,不得接受任意 `document_id` 直接取页。
|
||||
- **模板版本中心审计与使用数据边界**:`audit-events` 只返回事件类型、操作者摘要、`request_id`、过滤条件命中的安全 `detail_json` 和 ISO 8601 时间,不返回 PDF、正文、对象存储地址、盲测真值或可复原答案的坐标。`usages` 只返回脱敏文档名、Run 编号、匹配/执行状态、原因码、模板身份命中方式和只读诊断入口;不得回传文档正文、文件地址或运行时原始模型输出。
|
||||
- **订单客户指纹与冻结门禁**:`ShippingOrderCustomerMatch` 保留 Bill-to/Ship-to 原文、标准化组件、`order-customer-fingerprint.v1` 指纹、候选快照和确认理由。只有 `bill_to.status=confirmed` 且存在客户/简码/指纹/规则版本时 `order_freeze_service` 才冻结 Snapshot;冻结服务不接受外部 `customer_id` 或 `customer_short_code`。Snapshot 的 `rule_versions_json.ordering_customer` 保存匹配 ID、指纹、规则版本、确认方法和人员时间,避免主数据变化改写历史履约事实。
|
||||
|
||||
- **订单客户识别与冻结门禁**:`ShippingCustomerShadowResolution` 保存已发布 Rule Set 的证据、候选快照和确认审计。只有 Resolution 为 `confirmed`、存在 `confirmed_customer_id`、证据和 Rule Set checksum 时 `order_freeze_service` 才冻结 Snapshot;冻结服务不接受外部 `customer_id` 或 `customer_short_code`。Snapshot 的 `rule_versions_json.ordering_customer` 保存 Resolution ID、Rule Set checksum/version、确认方法和人员时间,避免主数据变化改写历史履约事实。
|
||||
<!-- XFA_SPLIT_SCOPE_UPDATE -->
|
||||
|
||||
### XFA 拆分规则作用域与源路径(2026-08-05)
|
||||
@@ -1506,3 +1512,7 @@ RecoveryPlan → Gate Attempt → Job → Worker/RPA → 幂等回调 → `run_t
|
||||
`freight-receipt-rpa` 写入 `shipping_receipt_rpa.v1` trigger,仅由 `freight_receipt_rpa_worker.py` 消费。它使用专属 `SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR` 和 `...RECEIPT_DROP_DIR`,不得与库存 Worker 共享目录或 callback。trigger 先写同目录临时文件、`fsync` 后以 `os.replace` 原子发布,避免 Worker 读取半截 JSON。Worker 在单次排程内按 `connector_type + rpa_profile_id + login_url` 分组并登录一次,串行导出;密文凭据仅在冻结 trigger 内传递并在 Worker 短暂解密。callback 仅允许读取 receipt drop 根内的 `.xlsx`,校验 SHA-256/大小后归档 MinIO。收料表与 `shipping_inventory_files` 无关联。
|
||||
|
||||
下载接口为 `GET /api/workspace/receipt-report-files/{file_id}/download`(管理员或排程接收人);`GET /api/workspace/receipt-report-files` 仅列出当前用户有权读取的脱敏归档元数据,并在授权过滤后施加 limit。管理员可通过 `GET /api/admin/receipt-rpa-units?status=failed` 定位失败单元,并以 `POST /api/admin/receipt-rpa-units/{unit_id}/retry`(必填原因)或 `POST /api/admin/receipt-report-files/{file_id}/resend` 补偿。运行等待 callback 超时会被 Worker 启动和周期扫描收口为失败,绝不自动重试;管理员补偿创建新单元,保留旧单元。管理员在既有库存站点抽屉通过独立 `GET/PUT /api/admin/shipping-notice/sources/{source_id}/receipt-report-config` 维护收料配置,不能改写库存 Source 字段:DBS 维护路径/条件/Warehouse,Crane 固定 `Inbound Details`,拒绝 Warehouse 和查询条件;Worker 无论 Profile 登录 URL 的原 hash 均强制进入 `#/inbound-details-query` 并直接使用页面默认条件。所有入口写含前后状态快照的 `ShippingAuditEvent`;三年期满仅删除对象、保留文件事实与审计。
|
||||
|
||||
# 在途仓自动调拨独立架构(2026-08)
|
||||
|
||||
调拨业务域独立于 shipping_notice 订单解析:ackend/app/services/in_transit_transfer/ 承载状态机/DTO/审计/文件准备/预检/执行/恢复/通知/归档/指标,erp_adapter.py 为 ERP 唯一访问出口(SOAP 在 WSDL 冻结前 fail-closed,凭据仅来自环境/Secret)。数据落 ransfer_* 七表(迁移 it1a2b3c4d5e);异步走 ransfer 队列(workers/worker_in_transit_transfer.py);08:00/09:00 platform job 注册于 schedule。前端卡片在 rontend/src/features/chat/(TransferMessageView 自驱动),四语言文案齐备。运维手册见 [features/in-transit-transfer/technical.md](features/in-transit-transfer/technical.md)。
|
||||
Reference in new issue
Block a user