feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ffc0d4a430
commit
39fe3c05f2
453 files changed
+17945
-8646
No files matched your search
@@ -5,7 +5,7 @@
|
||||
## 0. 结论速览
|
||||
|
||||
1. **解耦:可行,且方向正确。** Worker 与后端之间早已是「文件契约 + HTTP 回调 + 心跳」的进程边界(Worker 零 backend import),in_transit_transfer 已成为第二个消费方——RPA 事实上已是跨域平台能力,继续寄生在 `services/shipping_notice/` 里只会让第三个、第四个业务域重复绑定。推荐**两阶段**:阶段 A 机械收编编排层/API/调度壳到 `services/freight_rpa/`(低风险);表所有权与事务边界重构单独立项(阶段 B)。
|
||||
2. **改名:可行,但必须分批。** inventory→onhand 是绝对重灾区(源码约 19,700 次 / 约 708 文件、24 张表、636 个 i18n 键、约 40 个前后端契约枚举值);receipt→inbound 约 4,100 次 / 203 文件(in_transit_transfer 域已完成);shipment→outbound 约 260 次 / 72 文件(须排除 contract_payment 的「发货款」节点,占约 1/3)。
|
||||
2. **改名:可行,但必须分批。** inventory→onhand 是绝对重灾区(源码约 19,700 次 / 约 708 文件、24 张表、636 个 i18n 键、约 40 个前后端契约枚举值);receipt→inbound 约 4,100 次 / 203 文件(in_transit_transfer 域已完成)。**shipment→outbound 已否决(2026-10-17)**:货代履约「出货」与调拨 outbound 无关;contract_payment 的「发货款」shipment 仍须排除误伤。
|
||||
3. **解耦与改名互相纠缠,推荐合并批次:** 改名最危险的部分(Worker 回调 URL、trigger schema、env 变量、CIFS 物理目录)恰好集中在 RPA 域内——先解耦再改名等于把旧名字搬两次家。推荐「批次 R = 解耦 + RPA 域随迁新名」一次切换;shipping_notice 业务域改名(批次 S)随后独立进行。
|
||||
|
||||
## 1. 背景与本次范围
|
||||
@@ -84,7 +84,7 @@ RPA 能力分三层存在:
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| inventory→onhand | ~19,700 | ~708 | 194 文件/6,630 | 197 文件/5,535 | 73 文件/1,010 | 150 文件/4,241 | 61 文件/1,568 | 26 文件/570 | **24 张** `shipping_inventory_*` | 159 键/语言 ≈ 636 |
|
||||
| receipt→inbound | ~4,100 | ~203 | 52/832 | 46/1,190 | 18/124 | 33/358 | 28/1,184 | 21/413 | 4 张 `shipping_receipt_*` | 7 键/语言 |
|
||||
| shipment→outbound | ~260 | ~72 | 20/63 | 14/69 | 4/5 | 20/70 | 12/48 | 1/2 | 0 张(record_kind 值已随 tt14 迁移) | 3 键/语言 |
|
||||
| ~~shipment→outbound~~(履约) | — | — | **2026-10-17 否决**:履约 shipment 不改 outbound;调拨侧 outbound 已由 10-15/tt14 处理 | — |
|
||||
|
||||
**无关业务排除项(误伤清单)**:`contract_payment` 模块的付款节点类型 `shipment`(「发货款」,与 prepayment 并列)——约占 shipment 总量 1/3,**必须排除**(backend/app/services/contract_payment/、frontend/src/features/contract-payment/、docs/features/contract-payment-plan/)。`shipping` 一词不在改名范围(模块名 shipping_notice、`shipping_*` 前缀保留,仅词根 inventory/receipt/shipment 替换——即 `shipping_inventory_files`→`shipping_onhand_files`)。`movement` 一词按 10-15 spec 拍板保留。
|
||||
|
||||
@@ -129,17 +129,17 @@ RPA 能力分三层存在:
|
||||
S2 API 路由 + 权限键 + 前端契约枚举 + 前端目录/文件 git mv + i18n 636 键(前后端同批)
|
||||
S3 存量枚举值数据迁移 + 文档(technical.md 等)
|
||||
↓
|
||||
[批次 T] shipment→outbound(排除 contract_payment)
|
||||
约 40 文件:fulfillment_workflow、i18n.py、Excel 文件名模板、generate_shipment_excel 路由
|
||||
[批次 T] **已废除(2026-10-17)**:原「shipment→outbound」错误——货代履约出货 ≠ 调拨 outbound。
|
||||
履约侧 `shipment_*` 保留;若未来另案做命名卫生,目标词也不得是 outbound。
|
||||
↓
|
||||
[批次 D] 文档全域清扫收尾 + 终局 grep 门禁
|
||||
[批次 D] 文档全域清扫收尾 + 终局 grep 门禁(合法 outbound=调拨;禁止再把履约 shipment 扫成待改 outbound)
|
||||
```
|
||||
|
||||
理由:R 在 S 之前,避免「先给旧结构改名、再整体搬家」的双倍触碰;S 一次切换所有表与契约,避免两次表迁移;T 最小、风险最低放后面;D 收口。
|
||||
理由:R 在 S 之前,避免「先给旧结构改名、再整体搬家」的双倍触碰;S 一次切换所有表与契约,避免两次表迁移;D 收口。原 T 因术语混用取消。
|
||||
|
||||
**发布拍板(Q5/Q9,2026-10-16)**:四个批次**同一发布窗口上线**(后端+前端+迁移+Windows Worker 同窗口),不做双路由;实施顺序仍按 R→S→T→D,安全网纪律见 §6-Q11。
|
||||
**发布拍板(Q5/Q9,2026-10-16;T 范围 2026-10-17 修订)**:批次 **R+S+D** 同一发布窗口上线(后端+前端+迁移+Windows Worker 同窗口),不做双路由;实施顺序 **R→S→D**,安全网纪律见 §6-Q11。
|
||||
|
||||
量级估计:批次 R 约 1~2 周(含 Worker 联调窗口);批次 S 机器替换 2~3 天 + 全量回归与冒烟(后端 463 基线 + 前端 vitest/build),风险集中在存量数据迁移与前后端契约;批次 T 约 0.5 天;批次 D 约 1 天。
|
||||
量级估计:批次 R 约 1~2 周(含 Worker 联调窗口);批次 S 机器替换 2~3 天 + 全量回归与冒烟;批次 D 约 1 天。
|
||||
|
||||
## 6. 决策记录(2026-10-16 已拍板)
|
||||
|
||||
@@ -158,7 +158,7 @@ RPA 能力分三层存在:
|
||||
|
||||
## 7. 下一步(流程路由)
|
||||
|
||||
决策已闭环。正式 spec:`docs/superpowers/specs/2026-10-16-freight-rpa-decouple-and-rename-design.md`(以本文档 §2-§5 事实 + §6 决策 + §8 完整性清单为输入)。后续:`/to-tickets`(批次 R/S/T/D 四个 epic、S 内部按 S1-S3 拆分、声明阻塞边)→ 逐票 `/implement`;批次 R 的 CIFS/Worker 切换脚本用 `/wizard` 生成。
|
||||
决策已闭环(**2026-10-17 追加:废除 T**)。正式 spec:`docs/superpowers/specs/2026-10-16-freight-rpa-decouple-and-rename-design.md`。后续:`/to-tickets`(epic:**R/S/D**,S 内 S1-S3;勿再开 shipment→outbound 票)→ 逐票 `/implement`;R 的 CIFS/Worker 切换见 cutover-runbook。
|
||||
|
||||
## 8. 完整性清单(Q3「需要考虑完整」/ Q4「需要考虑完整」的展开,spec 阶段逐项核实)
|
||||
|
||||
@@ -172,7 +172,7 @@ RPA 能力分三层存在:
|
||||
- **脚本**:`backend/scripts/import_shipping_inventory_sources.py`。
|
||||
- **权限键(Q14 最终拍板:随批次 S 改;Q13b 层级修订)**:后端权限校验与前端 `modules.ts`/`admin.types.ts`/`admin.routes.ts` 的 `shipping_inventory`→`freight_rpa`(name `AdminFreightRpa`),并**迁移权限数据表中存量字符串值**(否则管理员丢页面,迁移动进批次 S 数据迁移波)。
|
||||
- **admin 路由与前端模块(Q13b:货代管理 = onhand/inbound/outbound 三子域)**:统一 `/api/admin/freight-rpa/` 命名空间——共享 `sources`/`rpa-profiles`,onhand 子域 `onhand/{fields,structure-analyses,validation-batches,snapshots,export-records}`,inbound 挂站点 `sources/<id>/inbound-report-config`,outbound 预留;`features/admin/modules/shipping-inventory/`→`freight-rpa/`(FreightRpaPage);admin.json `shippingInventory.*` 键名段四语言随改。
|
||||
- **文件产物模板**:出货 Excel 名 `shipment_{task_no}_{ts}.xlsx`→`outbound_*`(settings.py);zip 名、导出文件名模板清点。
|
||||
- **文件产物模板**:出货 Excel 名 `shipment_{task_no}_{ts}.xlsx` **保留 shipment 词根**(履约出货 ≠ outbound);zip/导出模板清点时不得改成 outbound_*。
|
||||
- **不改**:MinIO/storage_key、历史归档对象名、历史迁移文件、`docs/superpowers/` 归档。
|
||||
- **错误码族(2026-10-16 评审补充,最大漏项)**:`errors.json` 四语言含 **73+ 个含 INVENTORY 的键**(`SHIPPING_INVENTORY_*`、`SHIPPING.*INVENTORY*`、`TRANSFER_ERP_INVENTORY_NOT_FOUND`)——键名、值文案(含「库存」字样)、后端 `contracts.py` 定义与 AppError 抛点同批改;`TRANSFER_*` 已由 10-15 处理的部分除外。
|
||||
- **docker-compose 透传(评审补充)**:`docker-compose.yml` 仅 1 行显式透传 `FREIGHT_RPA_SHARED_RECEIPT_TRIGGER_DIR`(L324),批次 R 随 env 改名同步;其余 FREIGHT_RPA_* 经 env_file 自动流入,无需逐条改。
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Freight RPA 解耦批次 R 实施计划(模块归位 + RPA 域随迁新名)
|
||||
|
||||
> **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.
|
||||
>
|
||||
> **2026-10-17 勘误(就地纠偏,不另开文档):** outbound **仅**在途调拨出站;货代履约「出货」≠ outbound。本批交付的 `freight_rpa/outbound/` 骨架合法。upload trigger action 误用 `outbound_upload`,须改为与心跳一致的 **`freight_upload`**(后端+Worker 同窗口硬切)。后续批次见 evaluation/design:**T(shipment→outbound)已废除**;发布序 **R→S→D**。
|
||||
|
||||
**Goal:** 把 freight RPA 后端编排层从 shipping_notice 收编为独立 `freight_rpa` 包,并把 RPA 跨进程契约(env/trigger schema/回调 URL/Worker 目录/排程 job key)一次切换为 onhand/inbound 命名;数据库表零变更。
|
||||
|
||||
@@ -25,7 +27,7 @@
|
||||
|
||||
## 计划切分说明
|
||||
|
||||
本计划只覆盖批次 R。批次 S(28 表 rename+shipping_notice 域改名+存量数据迁移)、T(shipment→outbound)、D(文档收口)在批次 R 落地后基于实际新结构另出计划,四批同一发布窗口上线(ADR 0003)。
|
||||
本计划只覆盖批次 R。批次 S(表 rename+shipping_notice 域改名+存量数据迁移)、D(文档收口)在 R 落地后另出计划;**原批次 T「shipment→outbound」已废除(2026-10-17)**。发布窗口为 **R+S+D** 同窗口(ADR 0003,术语边界以 GLOSSARY 为准)。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Freight RPA 解耦批次 D 实施计划(权威文档收口)
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development.
|
||||
|
||||
**Goal:** 把权威文档中的 inventory/receipt 旧词收口为 onhand/inbound;确认 outbound 仅调拨;upload=freight_upload;不做 shipment→outbound。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-16-freight-rpa-decouple-and-rename-design.md`
|
||||
**D6:** `docs/superpowers/` 历史 plans/specs/ADR 归档**不改写**;权威文档必改。
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 不提交(本轮用户已下令整段不提交)
|
||||
- 不改 `docs/superpowers/plans|specs` 历史快照(本批新写的 batch-d 计划除外)
|
||||
- 不改 ADR 编号历史正文中的决策快照句,除非 ADR 0003 已在批次 R 勘误范围内需保持一致
|
||||
- shipment 履约 / contract_payment / freight_upload / 调拨 outbound 边界以 GLOSSARY 为准
|
||||
|
||||
## Task 1: 权威文档术语收口
|
||||
|
||||
**Files (must update if they still say inventory/receipt as code terms):**
|
||||
|
||||
- `docs/features/shipping-notice/technical.md`(inventory/receipt 代码词 → onhand/inbound;保留履约 shipment)
|
||||
- `docs/features/freight-rpa/GLOSSARY.md`(核对,已纠偏则只补漏)
|
||||
- `docs/features/freight-rpa/cutover-runbook.md`(核对 freight_upload)
|
||||
- `scripts/freight_rpa/README.md`
|
||||
- `docs/funclist.md` / `docs/demand.md` / `docs/tec.md` 中相关条目
|
||||
- `docs/convention/环境变量规则.md` 中 FREIGHT_RPA_* 命名段
|
||||
- `docs/adr/0003-freight-rpa-module-boundary.md`(若与现行 R→S→D 不一致则就地勘误)
|
||||
|
||||
Steps:
|
||||
|
||||
1. Grep 上述权威路径中的 `inventory`/`receipt`/`outbound_upload`/`shipment→outbound` 作为代码术语的命中。
|
||||
2. 按 GLOSSARY 替换;中文「库存」可保留为 onhand 文案。
|
||||
3. 自检:`docs/superpowers/` 除本批新计划外不改。
|
||||
4. Stage only the doc files you change. Do not commit.
|
||||
@@ -0,0 +1,201 @@
|
||||
# Freight RPA 解耦批次 S 实施计划(表 rename + shipping_notice 域 inventory→onhand)
|
||||
|
||||
> **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:** 在批次 R 已切换 RPA 契约(onhand/inbound/`freight_upload`)的前提下,把 shipping_notice 业务域代码/表/前端/i18n/权限/存量枚举从 `inventory`/`receipt` 词根迁到 `onhand`/`inbound`,数据库 **29 张表一次 rename**,无兼容层。
|
||||
|
||||
**Architecture:** 表命名与 env/包/蓝图同构——共享 `freight_rpa_sources`/`freight_rpa_profiles`;配置域 `freight_rpa_onhand_*` / `freight_rpa_inbound_*`;发货消费事实保留 `shipping_*` 前缀只改词根→`shipping_onhand_*`。admin 入口统一 `/api/admin/freight-rpa/`。
|
||||
|
||||
**Tech Stack:** Flask + SQLAlchemy 2.0 + Alembic(接批次 R 后 head)、Vue3+TS+i18n 四语言、pytest/vitest;自写 codemod(不引第三方)。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-16-freight-rpa-decouple-and-rename-design.md`
|
||||
**清单权威:** `docs/superpowers/plans/2026-10-16-freight-rpa-decouple-and-rename-evaluation.md` §5/§8
|
||||
**术语:** `docs/features/freight-rpa/GLOSSARY.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- **禁止自动 commit**:每任务止于 `git add`;提交须用户显式批准。
|
||||
- **批次 T 已废除**:禁止把履约 `shipment_*` / 出货 Excel 改成 `outbound_*`;outbound **仅**调拨出站。
|
||||
- **upload 独立**:action=`freight_upload`(已与心跳对齐);禁止 `outbound_upload` / `freight_rpa_upload`。
|
||||
- **白名单勿伤**:`contract_payment` 的 `shipment`(发货款);`movement` 一词;MinIO/storage_key;历史 `docs/superpowers/` 与旧迁移文件不改写。
|
||||
- **无双路由/无兼容层**:旧 admin 路径与旧枚举字符串发布后直接失效;权限键存量必须 UPDATE。
|
||||
- **迁移**:全部带可执行 downgrade;枚举 UPDATE 分批防长锁;发布前全库备份义务。
|
||||
- **中文文案**:onhand=库存、inbound=入站、outbound=出站(仅调拨)、履约称「出货」。
|
||||
- **注释纪律**:改签名/协作关系同步文件头与函数 docstring(AGENTS.md §5)。
|
||||
- **Windows**:`backend/.venv/Scripts/python.exe`;pytest 从 `backend/`;vitest/build 从 `frontend/`。
|
||||
- **不新增第三方依赖**。
|
||||
|
||||
## 29 表映射(S1 权威表)
|
||||
|
||||
### 共享 → `freight_rpa_*`
|
||||
| 旧 | 新 |
|
||||
| --- | --- |
|
||||
| `shipping_inventory_sources` | `freight_rpa_sources` |
|
||||
| `shipping_rpa_profiles` | `freight_rpa_profiles` |
|
||||
|
||||
### 配置域 → `freight_rpa_onhand_*`
|
||||
| 旧 | 新 |
|
||||
| --- | --- |
|
||||
| `shipping_inventory_fields` | `freight_rpa_onhand_fields` |
|
||||
| `shipping_inventory_source_parsing_binding_audits` | `freight_rpa_onhand_source_parsing_binding_audits` |
|
||||
| `shipping_inventory_parsing_profiles` | `freight_rpa_onhand_parsing_profiles` |
|
||||
| `shipping_inventory_structure_analyses` | `freight_rpa_onhand_structure_analyses` |
|
||||
| `shipping_inventory_configuration_test_runs` | `freight_rpa_onhand_configuration_test_runs` |
|
||||
| `shipping_inventory_validation_batches` | `freight_rpa_onhand_validation_batches` |
|
||||
| `shipping_inventory_routing_rules` | `freight_rpa_onhand_routing_rules` |
|
||||
| `shipping_inventory_routing_rule_conditions` | `freight_rpa_onhand_routing_rule_conditions` |
|
||||
| `shipping_inventory_routing_rule_versions` | `freight_rpa_onhand_routing_rule_versions` |
|
||||
| `shipping_inventory_external_mappings` | `freight_rpa_onhand_external_mappings` |
|
||||
| `shipping_inventory_mappings` | `freight_rpa_onhand_mappings` |
|
||||
| `shipping_task_inventory_rpa_attempts` | `freight_rpa_onhand_task_rpa_attempts` |
|
||||
|
||||
### inbound → `freight_rpa_inbound_*`
|
||||
| 旧 | 新 |
|
||||
| --- | --- |
|
||||
| `shipping_receipt_report_configs` | `freight_rpa_inbound_report_configs` |
|
||||
| `shipping_receipt_rpa_unit_runs` | `freight_rpa_inbound_rpa_unit_runs` |
|
||||
| `shipping_receipt_report_files` | `freight_rpa_inbound_report_files` |
|
||||
| `shipping_receipt_notification_deliveries` | `freight_rpa_inbound_notification_deliveries` |
|
||||
|
||||
### 发货消费事实 → `shipping_onhand_*`(保留 shipping 前缀)
|
||||
| 旧 | 新 |
|
||||
| --- | --- |
|
||||
| `shipping_inventory_files` | `shipping_onhand_files` |
|
||||
| `shipping_inventory_candidate_sets` | `shipping_onhand_candidate_sets` |
|
||||
| `shipping_inventory_candidate_sources` | `shipping_onhand_candidate_sources` |
|
||||
| `shipping_inventory_candidate_lines` | `shipping_onhand_candidate_lines` |
|
||||
| `shipping_inventory_preparation_attempts` | `shipping_onhand_preparation_attempts` |
|
||||
| `shipping_inventory_preparation_source_attempts` | `shipping_onhand_preparation_source_attempts` |
|
||||
| `shipping_task_inventory_links` | `shipping_task_onhand_links` |
|
||||
| `shipping_temporary_inventory_sessions` | `shipping_temporary_onhand_sessions` |
|
||||
| `shipping_notice_line_inventory_matches` | `shipping_notice_line_onhand_matches` |
|
||||
| `shipping_notice_inventory_verifications` | `shipping_notice_onhand_verifications` |
|
||||
| `shipping_notice_inventory_verification_lines` | `shipping_notice_onhand_verification_lines` |
|
||||
|
||||
列名族(随迁):`inventory_source_id`→`source_id` 等(以 evaluation §8.1 为准,迁移内列清单锁死)。`in_transit_transfer` 对 `shipping_receipt_report_files` 的 FK 必须跟随 inbound rename。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 迁移骨架 + 29 表 rename 往返测试(红)
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/migrations/versions/<rev>_freight_rpa_batch_s_rename_tables.py`(down_revision = 当前 head)
|
||||
- Create: `backend/tests/migrations/test_freight_rpa_batch_s_rename_contract.py`(或沿用既有 migration contract 目录惯例)
|
||||
|
||||
- [ ] **Step 1: 写失败测试** — SQLite upgrade 后断言 29 新表名存在、旧表名不存在;downgrade 后反向;再 upgrade。
|
||||
- [ ] **Step 2: 跑测确认失败**
|
||||
```bash
|
||||
cd backend && ./.venv/Scripts/python.exe -m pytest tests/migrations/test_freight_rpa_batch_s_rename_contract.py -q
|
||||
```
|
||||
- [ ] **Step 3: 实现 rename_table + 索引/约束/FK 名 sweep + downgrade**
|
||||
- [ ] **Step 4: 跑测通过**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 2: models 类名/文件名/__tablename__ 对齐
|
||||
|
||||
**Files:**
|
||||
- Modify/Rename: `backend/app/models/shipping_inventory_*.py`、`shipping_receipt_report.py`、`shipping_task_inventory_rpa_attempts.py`、`shipping_temporary_inventory.py`、`shipping_notice_line_inventory_match.py`、相关 `shipping.py`/`shipping_fulfillment.py` 段落、`models/__init__.py`
|
||||
- Modify: `backend/app/models/in_transit_transfer.py`(FK 字符串)
|
||||
|
||||
- [ ] **Step 1: 更新测试或编译探针**(import 旧类名应失败)
|
||||
- [ ] **Step 2: 跑测确认红**
|
||||
- [ ] **Step 3: git mv + 类名/表名/关系字符串替换;同步文件头注释**
|
||||
- [ ] **Step 4: 相关 model 测试绿**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 3: 后端 services/api 机械改名(inventory→onhand,receipt→inbound)
|
||||
|
||||
**Files:** `backend/app/services/shipping_notice/**`、`backend/app/services/admin/shipping_inventory_service.py`、`backend/app/api/**` 中引用旧模型/路径的模块;**不含**把 `shipment_*` 改 outbound。
|
||||
|
||||
- [ ] **Step 1: 写/更新聚焦测试**(至少一条 admin sources 列表、一条 candidate 流)
|
||||
- [ ] **Step 2: 红**
|
||||
- [ ] **Step 3: codemod + 手工修歧义**(白名单排除 contract_payment、shipment 履约、freight_upload)
|
||||
- [ ] **Step 4: `pytest -k "onhand or inbound or freight_rpa or shipping_notice"` 相关子集绿**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 4: admin 路由迁 `/api/admin/freight-rpa/` + 权限键
|
||||
|
||||
**Files:**
|
||||
- Modify/Rename: `backend/app/api/admin/shipping_inventory.py` → freight-rpa 树
|
||||
- Modify: `backend/app/api/admin/__init__.py`、`admin_freight_rpa.py` 合并边界
|
||||
- Modify: 权限常量与校验;迁移脚本(或本批 migration 第二段)UPDATE 权限表存量字符串 `shipping_inventory`→`freight_rpa`
|
||||
|
||||
- [ ] **Step 1: 契约测试** — 新路径 200;旧 `/api/admin/shipping-notice/...` inventory 管理路径 404
|
||||
- [ ] **Step 2: 红**
|
||||
- [ ] **Step 3: 实现路由树**(共享 sources/rpa-profiles;onhand/*;sources/<id>/inbound-report-config;temporary sessions 留 shipping-notice 只改词根)
|
||||
- [ ] **Step 4: 测绿**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 5: 前端模块 git mv + API/路由/权限 + i18n 四语言
|
||||
|
||||
**Files:**
|
||||
- `frontend/src/features/admin/modules/shipping-inventory/` → `freight-rpa/`
|
||||
- `admin.routes.ts`、`modules.ts`、`admin.types.ts`、`admin.api.ts`
|
||||
- `locales/{zh-CN,zh-TW,en,th}/admin.json`、`errors.json`(及 chat/workspace 中 inventory 键)
|
||||
|
||||
- [ ] **Step 1: 写/更新 vitest**(模块 id、路由名 `AdminFreightRpa`)
|
||||
- [ ] **Step 2: 红**
|
||||
- [ ] **Step 3: git mv + URL/键替换;四语言同步**
|
||||
- [ ] **Step 4: `npm run test -- --run` 相关 + `npm run build`**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 6: 存量枚举/审计/job_type 数据迁移
|
||||
|
||||
**Files:** 新 Alembic data migration(可与 Task 1 同文件分段或独立 revision)
|
||||
|
||||
对象(evaluation §8.2):`shipping_task_events` 事件名/step_key;`step_payload_json`/ui_state ~40 契约值;`jobs.job_type`(如 `SHIPPING_INVENTORY_CALLBACK_PROCESS`);attempt 行内枚举;权限存量(若未在 Task 4 完成)。
|
||||
|
||||
- [ ] **Step 1: 迁移契约测试**(种子旧值 → upgrade → 断言新值 → downgrade)
|
||||
- [ ] **Step 2: 红**
|
||||
- [ ] **Step 3: 分批 UPDATE + downgrade**
|
||||
- [ ] **Step 4: 测绿**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 7: 配置/脚本/job 注册键 + 错误码族
|
||||
|
||||
**Files:**
|
||||
- `backend/config/shipping_inventory_sources.yaml`(改名+键)
|
||||
- `backend/scripts/import_shipping_inventory_sources.py`
|
||||
- `job_registry.py` options_source;jobs handler 模块名
|
||||
- `errors.json`×4 + 后端错误码定义/抛点(`SHIPPING_INVENTORY_*` 族)
|
||||
|
||||
- [ ] **Step 1: 护栏测试**(四语言 errors 键 parity)
|
||||
- [ ] **Step 2–4: 红→改→绿**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
### Task 8: grep 门禁 + 子集回归收口
|
||||
|
||||
- [ ] **Step 1: 增加/更新门禁脚本或测试** — 白名单外 `inventory`/`receipt` 在约定路径清零;**禁止**把 `shipment` 履约扫成待改;合法 `outbound` 仅调拨语境
|
||||
- [ ] **Step 2: 跑门禁(预期先红再修漏网)**
|
||||
- [ ] **Step 3: 后端关键 pytest 基线 + 前端 build**
|
||||
- [ ] **Step 4: 自审 DO-NOT-TOUCH 列表无误伤**
|
||||
- [ ] **Step 5: 暂存不提交**
|
||||
|
||||
---
|
||||
|
||||
## 计划外(下一批)
|
||||
|
||||
- **批次 D**:权威文档全域清扫(`shipping-notice/technical.md`、funclist/demand/tec、环境变量规则、freight_rpa README);历史 superpowers 不改写。
|
||||
- **批次 T**:已废除,不实施。
|
||||
|
||||
## 验收
|
||||
|
||||
- 29 表 rename 往返绿;旧 admin inventory 路径 404;新 freight-rpa 管理路径可用
|
||||
- 权限键迁移后管理员不丢页
|
||||
- i18n 四语言键集一致;errors 族同步
|
||||
- grep 门禁白名单外清零;shipment 履约与 contract_payment 未误伤
|
||||
- upload action 仍为 `freight_upload`
|
||||
@@ -0,0 +1,78 @@
|
||||
# Freight RPA upload action 纠偏 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:** 把批次 R 误写的 upload trigger action `outbound_upload` 改回与心跳能力一致的 `freight_upload`,消除「出站 outbound」与「履约上传 upload」混名。
|
||||
|
||||
**Architecture:** upload 是与 onhand/inbound/outbound **同级独立域**。trigger schema 保持 `freight_rpa.upload.v1`;action 与心跳能力串 `FREIGHT_UPLOAD_CAPABILITY = "freight_upload"` 对齐。不做 `freight_rpa_upload`(见下方裁决)。
|
||||
|
||||
**Tech Stack:** Python / Flask;Worker 侧 `onhand_rpa_worker._handle_upload_trigger` 当前不校验 action 字面量,但仍须双侧契约文档一致。
|
||||
|
||||
**Ruling(2026-10-17):** 否决把 `freight_upload` 改成 `freight_rpa_upload`。理由:心跳能力、lifecycle stage、gate `freight_upload_rpa` 已广泛使用 `freight_upload`;`freight_rpa_*` 是包/表/env 命名空间,action 用短动词与 `onhand_export`/`inbound_export` 同形。改成 `freight_rpa_upload` 会制造第三套词根且波及 shipping_notice 生命周期契约,超出本纠偏。
|
||||
|
||||
**Spec 权威:** `docs/superpowers/specs/2026-10-16-freight-rpa-decouple-and-rename-design.md`(upload action 对齐 freight_upload)+ `docs/features/freight-rpa/GLOSSARY.md` Upload 条。
|
||||
|
||||
---
|
||||
|
||||
## File map
|
||||
|
||||
| File | Responsibility |
|
||||
| --- | --- |
|
||||
| `backend/app/services/freight_rpa/upload/trigger_io.py` | 常量 + 写入 action |
|
||||
| `backend/tests/services/freight_rpa/**`(若已有 upload 契约测)或新建最小单测 | 断言 action/schema |
|
||||
| `docs/features/freight-rpa/GLOSSARY.md` / cutover-runbook / batch-R 勘误 | 已就地写明;本计划只确认代码落地 |
|
||||
|
||||
---
|
||||
|
||||
### Task 1: upload action → `freight_upload`
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/freight_rpa/upload/trigger_io.py`
|
||||
- Modify or create: focused test under `backend/tests/services/freight_rpa/`(优先改既有;无则新建 `test_upload_trigger_contract.py`)
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
断言 `ACTION_*`(或写入 trigger 后读出的 `action`)等于 `"freight_upload"`,`schema_version` 等于 `"freight_rpa.upload.v1"`。禁止再出现 `outbound_upload` / `shipment_upload`。
|
||||
|
||||
- [ ] **Step 2: 跑测确认失败**
|
||||
|
||||
```bash
|
||||
cd backend && python -m pytest tests/services/freight_rpa/ -k upload -q
|
||||
```
|
||||
|
||||
Expected: 失败(当前常量仍是 outbound_upload)或新增测未发现常量。
|
||||
|
||||
- [ ] **Step 3: 改常量与注释**
|
||||
|
||||
- 将 `ACTION_OUTBOUND_UPLOAD = "outbound_upload"` 改为 `ACTION_FREIGHT_UPLOAD = "freight_upload"`
|
||||
- 更新所有引用
|
||||
- 文件头 docstring:说明 action 对齐心跳 `freight_upload`;upload 独立域,禁止 outbound_* / shipment_* 作为 upload action
|
||||
- 禁止引入 `freight_rpa_upload`
|
||||
|
||||
- [ ] **Step 4: 跑测通过**
|
||||
|
||||
```bash
|
||||
cd backend && python -m pytest tests/services/freight_rpa/ -k upload -q
|
||||
```
|
||||
|
||||
另跑:
|
||||
|
||||
```bash
|
||||
rg -n "outbound_upload|ACTION_OUTBOUND_UPLOAD" backend/app scripts/freight_rpa
|
||||
```
|
||||
|
||||
Expected: 代码命中清零(文档勘误「勿用 outbound_upload」可保留)。
|
||||
|
||||
- [ ] **Step 5: 暂存,不提交**
|
||||
|
||||
`git add` 相关文件;**不要 commit**(等用户批准)。
|
||||
|
||||
---
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 不改 lifecycle / gate / i18n 里的 `freight_upload` 业务词(它们本来就对)
|
||||
- 不改 `shipment_*` 履约出货命名
|
||||
- 不改 `freight_rpa/outbound/` 调拨出站骨架
|
||||
- 不做双路由/兼容层
|
||||
- 三层注释规范(文件头 + 函数)随改同步
|
||||
@@ -0,0 +1,716 @@
|
||||
# Freight RPA 阶段 B 实施计划(报表归属与回调事实)
|
||||
|
||||
> **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:** 在当前 Flask 进程内,让 `freight_rpa` 拥有登录连接、库存站点、在手/入站报表配置和两类报表文件;发货通知与在途调拨只按 `source_code` 读取,并只更新自己的任务。
|
||||
|
||||
**Architecture:** 批次 S 的未执行迁移已经把解析方案表落到 `freight_rpa_parsing_profiles`,本计划不再写第二条改名。新迁移 `s18` 挂在 `s17c` 之后:新建 `freight_rpa_onhand_report_configs` 并搬走站点上的三列,再把 `shipping_onhand_files` 改名为 `freight_rpa_onhand_report_files`(列不动)。回调在 RPA 事务提交文件之后,用 `ReportFact` 调用已注册处理函数;处理函数失败不回滚文件。不引入队列,不拆第二个服务。
|
||||
|
||||
**Tech Stack:** Flask、SQLAlchemy 2.0、Alembic、Vue 3 + TypeScript、pytest。Python 用 `backend/.venv/Scripts/python.exe`,命令在 `backend/` 下执行。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-18-freight-rpa-phase-b-design.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 不把 `freight_rpa` 拆成第二个可部署服务,不引入消息队列。
|
||||
- 不新做出站抓取。出站配置和出站文件表等出站立项再加,命名与在手、入站相同。
|
||||
- 不把履约出货改名为 outbound,不改 `freight_upload`。
|
||||
- 不改合同付款的 `shipment`(发货款),不改 `movement`,不改历史 MinIO 对象键(含 `shipping/receipt-reports/`)。
|
||||
- 不改写已有的阶段 A 计划与 spec。
|
||||
- 不改这些仍只服务在手的表:`freight_rpa_onhand_fields`、外部仓库映射、发货路由规则、配置测试。不改它们的表名和归属。
|
||||
- 不把在手文件表里的解析行、字段映射、快照状态拆到另一张表。入站文件表只存原文件,两张表的列保持不同。
|
||||
- `report_kind` 取值 `onhand`、`inbound`、`outbound`,与解析方案 `purpose` 相同。本阶段实际送达的是 `onhand` 和 `inbound`。
|
||||
- 批次 S、D 已在工作区且未提交。本计划的代码继续改在这份工作区上。禁止 `git add -A`。禁止 `git commit`(提交须用户显式批准)。每任务只 `git add` 该任务列出的路径。
|
||||
- 解析方案最终表名已经写在未执行的 `s17b` 里。禁止再添加 `freight_rpa_onhand_parsing_profiles` 这个名字。
|
||||
- 站点启用规则:已有在手报表配置且其中 `parsing_profile_id` 非空,并且站点 `excel_template_id` 非空。PostgreSQL 的 CHECK 不能跨表,所以模板仍留在站点行的 CHECK 上,解析方案改由保存站点的服务拒绝。
|
||||
- 注释:改签名或协作关系时同步文件头和函数 docstring(AGENTS.md §5)。
|
||||
- 新增 `error.code` 时补齐 `locales/*/errors.json` 四语言。本计划复用已有码,不新造码,除非某步写明。
|
||||
|
||||
## 文件地图
|
||||
|
||||
| 路径 | 职责 |
|
||||
| --- | --- |
|
||||
| `backend/migrations/versions/s18d1e2f3a4b5_freight_rpa_phase_b_report_ownership.py` | 新建在手配置表、搬三列、改在手文件表名、downgrade |
|
||||
| `backend/app/models/shipping_onhand_config.py` | 站点去掉三列;新增 `ShippingOnhandReportConfig` |
|
||||
| `backend/app/models/shipping.py` | `ShippingOnhandFile.__tablename__` 改为 `freight_rpa_onhand_report_files` |
|
||||
| `backend/app/services/freight_rpa/reports/facts.py` | `ReportFact` 与取值校验 |
|
||||
| `backend/app/services/freight_rpa/reports/queries.py` | 按 `source_code` / `file_id` 的只读查询,以及入站解析结果标记 |
|
||||
| `backend/app/services/freight_rpa/reports/dispatch.py` | 提交后调用处理函数;未注册则 `FREIGHT_RPA.SINK_NOT_REGISTERED` |
|
||||
| `backend/app/services/freight_rpa/common/report_audit.py` | 写既有 `ShippingAuditEvent`,替代对 `shipping_notice.audit_service` 的 import |
|
||||
| `backend/app/services/freight_rpa/onhand/report_store.py` | 在手报表行的插入与更新(含解析列) |
|
||||
| `backend/app/services/in_transit_transfer/inbound_report_handler.py` | inbound 事实只推进 `TransferSourceJob` |
|
||||
| `backend/app/services/shipping_notice/onhand_report_handler.py` | onhand 事实只更新发货门禁、候选和任务关联 |
|
||||
| `docs/adr/0004-freight-rpa-report-ownership.md` | 阶段 B 归属决策 |
|
||||
| `docs/features/freight-rpa/GLOSSARY.md` | 站点归属改为 RPA |
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 迁移在手配置表与在手文件表名
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/migrations/versions/s18d1e2f3a4b5_freight_rpa_phase_b_report_ownership.py`
|
||||
- Modify: `backend/app/models/shipping_onhand_config.py`
|
||||
- Modify: `backend/app/models/shipping.py`(`ShippingOnhandFile.__tablename__` 与指向 `shipping_onhand_files` 的 `ForeignKey`)
|
||||
- Modify: `backend/app/models/__init__.py`(导出 `ShippingOnhandReportConfig`)
|
||||
- Modify: 下列文件里的 `ForeignKey('shipping_onhand_files.id')` 改为 `ForeignKey('freight_rpa_onhand_report_files.id')`:`shipping_onhand_mapping.py`、`shipping_excel_template.py`、`shipping_onhand_preparation.py`、`shipping_notice_line_onhand_match.py`
|
||||
- Test: `backend/tests/test_migration_s18_phase_b_report_ownership.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 批次 S 之后库上已有 `freight_rpa_sources.report_path_json`、`query_parameters_json`、`parsing_profile_id`,以及表 `shipping_onhand_files`。`s17b` 的解析方案目标名已是 `freight_rpa_parsing_profiles`。
|
||||
- Produces: 表 `freight_rpa_onhand_report_configs`(列:`id`、`source_id` 唯一、`parsing_profile_id` 可空、`report_path_json` JSON 非空、`query_parameters_json` JSON 非空、`config_version` int 默认 1、`created_by`、`updated_by`、`created_at`、`updated_at`)。站点行不再有那三列。`ck_freight_rpa_sources_enabled_bindings` 换成 `ck_freight_rpa_sources_enabled_template`,表达式 `enabled = false OR excel_template_id IS NOT NULL`。模型类 `ShippingOnhandReportConfig`,关系 `ShippingOnhandSource.onhand_report_config`(`uselist=False`)。`ShippingOnhandFile.__tablename__ == 'freight_rpa_onhand_report_files'`,列与改名前相同。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
`backend/tests/test_migration_s18_phase_b_report_ownership.py` 沿用 `tests/test_migration_s17_batch_s_rename.py` 的 `_load` + SQLite `Operations` 手法。测试不从迁移模块读取期望表名。
|
||||
|
||||
```python
|
||||
def test_s18_revision_follows_s17c():
|
||||
migration = _load("s18d1e2f3a4b5_freight_rpa_phase_b_report_ownership.py")
|
||||
assert migration.revision == "s18d1e2f3a4b5"
|
||||
assert migration.down_revision == "s17c2d3e4f5a6"
|
||||
|
||||
|
||||
def test_s17b_parsing_profile_target_is_final_name():
|
||||
s17b = _load("s17b1c2d3e4f5a_freight_rpa_batch_s_rename_tables.py")
|
||||
assert ("shipping_inventory_parsing_profiles", "freight_rpa_parsing_profiles") in s17b._TABLE_RENAMES
|
||||
assert "freight_rpa_onhand_parsing_profiles" not in str(s17b._TABLE_RENAMES)
|
||||
|
||||
|
||||
def test_s18_upgrade_moves_onhand_config_and_renames_files_then_downgrade_restores(op):
|
||||
# op fixture:内存 SQLite,先跑 s17b.upgrade 再跑 s17c.upgrade(或桩出 s17c 之后的两张表)。
|
||||
# 桩站点一行:source_code='DSV',report_path_json={'menu':'onhand'},
|
||||
# query_parameters_json=[{'name':'wh'}],parsing_profile_id=1,excel_template_id=9。
|
||||
# 桩 shipping_onhand_files 一行:id=7,onhand_lines_json=[{'sku':'A'}],snapshot_status='ready'。
|
||||
migration = _load("s18d1e2f3a4b5_freight_rpa_phase_b_report_ownership.py")
|
||||
migration.upgrade()
|
||||
config_cols = _column_names(op, "freight_rpa_onhand_report_configs")
|
||||
assert {"source_id", "report_path_json", "query_parameters_json", "parsing_profile_id"} <= set(config_cols)
|
||||
source_cols = _column_names(op, "freight_rpa_sources")
|
||||
assert "report_path_json" not in source_cols
|
||||
assert "parsing_profile_id" not in source_cols
|
||||
assert "source_code" in source_cols
|
||||
file_cols = _column_names(op, "freight_rpa_onhand_report_files")
|
||||
assert "onhand_lines_json" in file_cols
|
||||
assert "snapshot_status" in file_cols
|
||||
row = op.get_bind().exec_driver_sql(
|
||||
"SELECT report_path_json, parsing_profile_id FROM freight_rpa_onhand_report_configs"
|
||||
).one()
|
||||
assert row.parsing_profile_id == 1
|
||||
migration.downgrade()
|
||||
assert "report_path_json" in _column_names(op, "freight_rpa_sources")
|
||||
assert "onhand_lines_json" in _column_names(op, "shipping_onhand_files")
|
||||
assert "freight_rpa_onhand_parsing_profiles" not in _table_names(op)
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/test_migration_s18_phase_b_report_ownership.py -q`
|
||||
|
||||
Expected: FAIL,迁移文件不存在。
|
||||
|
||||
- [ ] **Step 3: 写迁移与模型**
|
||||
|
||||
`revision = "s18d1e2f3a4b5"`,`down_revision = "s17c2d3e4f5a6"`。
|
||||
|
||||
upgrade 顺序:
|
||||
|
||||
1. `op.create_table('freight_rpa_onhand_report_configs', ...)`,`UniqueConstraint('source_id', name='uq_freight_rpa_onhand_report_configs_source')`,`source_id` 外键 `freight_rpa_sources.id` `ondelete='CASCADE'`,`parsing_profile_id` 外键 `freight_rpa_parsing_profiles.id`。
|
||||
2. `INSERT INTO freight_rpa_onhand_report_configs (source_id, report_path_json, query_parameters_json, parsing_profile_id, config_version, created_at, updated_at) SELECT id, report_path_json, query_parameters_json, parsing_profile_id, config_version, created_at, updated_at FROM freight_rpa_sources`。
|
||||
3. `op.drop_constraint('ck_freight_rpa_sources_enabled_bindings', 'freight_rpa_sources', type_='check')`。若库上的历史约束名仍是改名前的名字,用反射按「定义里同时含 `parsing_profile_id` 与 `excel_template_id`」找到那一条再删。
|
||||
4. 删掉站点上的 `report_path_json`、`query_parameters_json`、`parsing_profile_id`。
|
||||
5. `op.create_check_constraint('ck_freight_rpa_sources_enabled_template', 'freight_rpa_sources', 'enabled = false OR excel_template_id IS NOT NULL')`。
|
||||
6. `op.rename_table('shipping_onhand_files', 'freight_rpa_onhand_report_files')`。然后复用 `s17b` 里「对象名包含旧表名则替换」的扫描,旧串 `shipping_onhand_files`,新串 `freight_rpa_onhand_report_files`。新名超过 63 字符时沿用 `s17b` 的截断函数。列名不改。
|
||||
|
||||
downgrade 相反:文件表改回 `shipping_onhand_files`,把三列加回 `freight_rpa_sources`,从配置表 `UPDATE` 回去,丢掉配置表,恢复 `ck_freight_rpa_sources_enabled_bindings` 原文 `enabled = false OR (parsing_profile_id IS NOT NULL AND excel_template_id IS NOT NULL)`。
|
||||
|
||||
模型:`ShippingOnhandSource` 删除三列与 `parsing_profile` 关系;启用 CHECK 改为模板那条。新增 `ShippingOnhandReportConfig`,字段与上表一致,`inventory_source` 关系命名与入站配置的 `ShippingInboundReportConfig` 相同风格。`ShippingParsingProfile.sources` 改为指向配置行。`ShippingOnhandFile.__tablename__ = 'freight_rpa_onhand_report_files'`。文件头写明:在手文件表归 RPA,列仍含解析行与快照状态。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/test_migration_s18_phase_b_report_ownership.py tests/test_migration_s17_batch_s_rename.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/migrations/versions/s18d1e2f3a4b5_freight_rpa_phase_b_report_ownership.py backend/tests/test_migration_s18_phase_b_report_ownership.py backend/app/models/shipping_onhand_config.py backend/app/models/shipping.py backend/app/models/__init__.py backend/app/models/shipping_onhand_mapping.py backend/app/models/shipping_excel_template.py backend/app/models/shipping_onhand_preparation.py backend/app/models/shipping_notice_line_onhand_match.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: 站点启用与管理端改读写在手配置
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/admin/shipping_onhand_admin_service.py`
|
||||
- Modify: `frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue`(库存报表配置卡片的绑定字段)
|
||||
- Test: `backend/tests/test_admin_freight_rpa_onhand_config.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ShippingOnhandReportConfig`,站点行上的 `excel_template_id`、`enabled`。
|
||||
- Produces: `assert_onhand_source_can_enable(source: ShippingOnhandSource) -> None`。`enabled` 为真且缺少配置、或配置的 `parsing_profile_id` 为空、或 `excel_template_id` 为空时抛 `ValidationError(code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED')`。站点 DTO 不再带 `report_path_json` / `query_parameters_json` / `parsing_profile_id`;改为 `onhand_report_config: { id, report_path_json, query_parameters_json, parsing_profile_id } | null`。保存在手配置的函数 `save_onhand_report_config(source_id: int, data: dict, actor_id: int | None) -> dict`,没有配置行时插入,有则更新,并递增该行的 `config_version`。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```python
|
||||
def test_enabled_source_requires_onhand_profile_and_template(app, db_session):
|
||||
source = _source(enabled=True, excel_template_id=None)
|
||||
db_session.add(source)
|
||||
db_session.commit()
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
assert_onhand_source_can_enable(source)
|
||||
assert exc.value.code == "SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED"
|
||||
|
||||
|
||||
def test_save_onhand_report_config_does_not_write_source_columns(app, db_session):
|
||||
source = _source(enabled=False, excel_template_id=9)
|
||||
db_session.add(source)
|
||||
db_session.commit()
|
||||
save_onhand_report_config(source.id, {
|
||||
"report_path_json": {"menu": "stock"},
|
||||
"query_parameters_json": [],
|
||||
"parsing_profile_id": _published_onhand_profile_id(),
|
||||
}, actor_id=1)
|
||||
db_session.refresh(source)
|
||||
assert not hasattr(source, "report_path_json")
|
||||
config = ShippingOnhandReportConfig.query.filter_by(source_id=source.id).one()
|
||||
assert config.report_path_json == {"menu": "stock"}
|
||||
assert config.parsing_profile.purpose == "onhand"
|
||||
```
|
||||
|
||||
`parsing_profile.purpose` 不是 `onhand` 时,`save_onhand_report_config` 抛 `ValidationError(code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED')`。入站配置的保存函数保持只接受 `purpose='inbound'`。
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/test_admin_freight_rpa_onhand_config.py -q`
|
||||
|
||||
Expected: FAIL,`assert_onhand_source_can_enable` 未定义。
|
||||
|
||||
- [ ] **Step 3: 改服务与页面**
|
||||
|
||||
`shipping_onhand_admin_service.py` 里现在写 `source.report_path_json`、`source.query_parameters_json`、`source.parsing_profile_id` 的分支改写配置行。解析方案绑定审计仍写 `freight_rpa_onhand_source_parsing_binding_audits`,`parsing_profile_id` 取自配置行。`FreightRpaPage.vue` 的库存报表配置卡片改绑 `onhand_report_config` 的三个字段;收料卡片继续绑入站配置。站点头部仍编辑 `source_code`、`display_name`、`connector_type`、`rpa_profile_id`、`excel_template_id`、仓库模式。不新增文案。
|
||||
|
||||
触发抓取读路径的同一任务内改完,否则管理端能存、排程仍读已删除的列:
|
||||
|
||||
- `backend/app/services/shipping_notice/onhand_trigger_batch.py`:`report_path_json` / `query_parameters_json` / `parsing_profile_id` 从 `source.onhand_report_config` 取。配置缺失则沿用现有「站点未就绪」错误,不新造码。
|
||||
- `backend/app/services/freight_rpa/onhand/trigger_io.py` 若直接读这三列,同样改读配置。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/test_admin_freight_rpa_onhand_config.py tests/test_admin_freight_rpa_routes.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/app/services/admin/shipping_onhand_admin_service.py backend/app/services/shipping_notice/onhand_trigger_batch.py backend/app/services/freight_rpa/onhand/trigger_io.py frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue backend/tests/test_admin_freight_rpa_onhand_config.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: 报表只读查询
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/services/freight_rpa/reports/__init__.py`
|
||||
- Create: `backend/app/services/freight_rpa/reports/facts.py`
|
||||
- Create: `backend/app/services/freight_rpa/reports/queries.py`
|
||||
- Test: `backend/tests/services/freight_rpa/test_report_queries.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ShippingOnhandSource`、`ShippingOnhandReportConfig`、`ShippingInboundReportConfig`、`ShippingInboundReportFile`、`ShippingOnhandFile`、`usable_inbound_file_condition()`(现位于 `in_transit_transfer/inbound_file_gate.py`,本任务把可用条件的过滤表达式复制进 `queries.py`,门禁模块下一步改为调用这里,避免 `freight_rpa` import `in_transit_transfer`)。
|
||||
- Produces:
|
||||
|
||||
```python
|
||||
@dataclass(frozen=True)
|
||||
class ReportFact:
|
||||
report_kind: str
|
||||
source_code: str
|
||||
file_id: int | None
|
||||
sha256: str | None
|
||||
ok: bool
|
||||
error_code: str | None = None
|
||||
error_message: str | None = None
|
||||
|
||||
def require_report_kind(value: str) -> str:
|
||||
"""只接受 onhand、inbound、outbound。其他值抛 ValidationError(code='SHIPPING.RECEIPT_CALLBACK_INVALID')。"""
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SiteView:
|
||||
source_code: str
|
||||
display_name: str
|
||||
connector_type: str
|
||||
excel_template_id: int | None
|
||||
enabled: bool
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class OnhandConfigView:
|
||||
report_path_json: dict
|
||||
query_parameters_json: list
|
||||
parsing_profile_id: int | None
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class InboundConfigView:
|
||||
report_path_json: dict
|
||||
query_parameters_json: list
|
||||
parsing_profile_id: int | None
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class InboundFileView:
|
||||
file_id: int
|
||||
source_code: str
|
||||
sha256: str
|
||||
storage_key: str
|
||||
original_filename: str
|
||||
created_at: datetime
|
||||
|
||||
def get_site(source_code: str) -> SiteView | None: ...
|
||||
def get_onhand_config(source_code: str) -> OnhandConfigView | None: ...
|
||||
def get_inbound_config(source_code: str) -> InboundConfigView | None: ...
|
||||
def latest_usable_inbound_file(source_code: str) -> InboundFileView | None: ...
|
||||
def read_inbound_file_bytes(file_id: int) -> bytes: ...
|
||||
def mark_inbound_parse_failure(file_id: int, *, error_code: str, error_message: str) -> None: ...
|
||||
def clear_inbound_parse_failure(file_id: int) -> None: ...
|
||||
```
|
||||
|
||||
`latest_usable_inbound_file` 的过滤与今天 `matching_service._latest_usable_report_file` 相同:经 unit run 的 `source_code`,未删除、未过期、按 `created_at`/`id` 倒序第一条。`read_inbound_file_bytes` 用现有 `file_asset_storage` 按 `storage_key` 读取。找不到文件抛 `NotFoundError`。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```python
|
||||
def test_latest_usable_inbound_file_returns_newest(app, db_session):
|
||||
older = _inbound_file(source_code="DSV", sha256="a" * 64, created_at=datetime(2026, 10, 1))
|
||||
newer = _inbound_file(source_code="DSV", sha256="b" * 64, created_at=datetime(2026, 10, 2))
|
||||
db_session.add_all([older, newer])
|
||||
db_session.commit()
|
||||
view = latest_usable_inbound_file("DSV")
|
||||
assert view is not None
|
||||
assert view.file_id == newer.id
|
||||
assert view.sha256 == "b" * 64
|
||||
|
||||
|
||||
def test_report_kind_rejects_shipment():
|
||||
with pytest.raises(ValidationError):
|
||||
require_report_kind("shipment")
|
||||
assert require_report_kind("outbound") == "outbound"
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/freight_rpa/test_report_queries.py -q`
|
||||
|
||||
Expected: FAIL,模块不存在。
|
||||
|
||||
- [ ] **Step 3: 实现查询模块**
|
||||
|
||||
文件头写明:本模块是发货与调拨读报表的唯一入口;不 import `shipping_notice` 或 `in_transit_transfer`。`mark_inbound_parse_failure` 只更新 `parse_failed_at`、`parse_error_code`、`parse_error_message` 后 `flush`,不 `commit`(调用方处于自己的事务)。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/freight_rpa/test_report_queries.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/app/services/freight_rpa/reports backend/tests/services/freight_rpa/test_report_queries.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: 在途调拨改为只读函数
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/in_transit_transfer/matching_service.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/movement_file_repository.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/source_file_status.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/inbound_file_gate.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/inbound_trigger_service.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/backlog_reparse_service.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/deps.py`
|
||||
- Modify: `backend/app/services/in_transit_transfer/evidence_sync.py`(它经 `_latest_usable_report_file` 取文件)
|
||||
- Test: `backend/tests/services/in_transit_transfer/test_inbound_report_read_boundary.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 3 的 `latest_usable_inbound_file`、`read_inbound_file_bytes`、`get_inbound_config`、`get_site`、`mark_inbound_parse_failure`、`clear_inbound_parse_failure`。
|
||||
- Produces: 上述文件不再出现 `from app.models import ShippingInboundReportFile` 或 `ShippingInboundReportConfig` 或 `ShippingOnhandSource`。`matching_service._latest_usable_report_file` 删除,调用处改为 `latest_usable_inbound_file`。解析失败标记改为 `mark_inbound_parse_failure(file_id=...)`。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```python
|
||||
def test_in_transit_does_not_import_rpa_report_models():
|
||||
root = Path(__file__).resolve().parents[3] / "app" / "services" / "in_transit_transfer"
|
||||
banned = ("ShippingInboundReportFile", "ShippingInboundReportConfig", "ShippingOnhandSource", "ShippingOnhandReportConfig")
|
||||
hits = []
|
||||
for path in root.rglob("*.py"):
|
||||
text = path.read_text(encoding="utf-8")
|
||||
for name in banned:
|
||||
if name in text:
|
||||
hits.append(f"{path.name}: {name}")
|
||||
assert hits == []
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_inbound_report_read_boundary.py -q`
|
||||
|
||||
Expected: FAIL,列出 `matching_service.py` 等文件。
|
||||
|
||||
- [ ] **Step 3: 替换查询**
|
||||
|
||||
`matching_service` 里原 `_latest_usable_report_file` 的调用改为:
|
||||
|
||||
```python
|
||||
from app.services.freight_rpa.reports.queries import latest_usable_inbound_file, read_inbound_file_bytes
|
||||
|
||||
view = latest_usable_inbound_file(source_code)
|
||||
if view is None:
|
||||
return None
|
||||
payload = read_inbound_file_bytes(view.file_id)
|
||||
```
|
||||
|
||||
后续只用 `view.file_id`、`view.sha256`、`view.created_at`。`source_file_status.py` 的写标记改为 `mark_inbound_parse_failure` / `clear_inbound_parse_failure`。`inbound_trigger_service.py` 读站点与入站配置改为 `get_site` / `get_inbound_config`。`inbound_file_gate.py` 若只剩过滤表达式,改为从 `queries.py` 引用,自身不再 import 模型。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_inbound_report_read_boundary.py tests/services/in_transit_transfer -q`
|
||||
|
||||
Expected: PASS。既有匹配测试仍绿。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/app/services/in_transit_transfer backend/tests/services/in_transit_transfer/test_inbound_report_read_boundary.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: 发货通知改为只读函数,在手文件写入收进 RPA
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/services/freight_rpa/onhand/report_store.py`
|
||||
- Modify: `backend/app/services/shipping_notice/onhand_snapshot_store.py`(`create_inventory_snapshot_from_rpa`、`create_empty_rpa_inventory_snapshot`、`get_or_create_rpa_inventory_snapshot` 改为调用 report_store,不再自己 `ShippingOnhandFile(...)`)
|
||||
- Modify: `backend/app/services/shipping_notice/onhand_file_store.py`(`save_task_inventory_upload` 的插入改为调用 report_store)
|
||||
- Modify: 仍直接构造或查询 `ShippingOnhandFile` / `ShippingInboundReportConfig` 的发货模块:`onhand_rpa_workflow.py`、`onhand_source_repository.py`、`inbound_report_access.py`、`query_service.py`
|
||||
- Test: `backend/tests/services/shipping_notice/test_report_model_boundary.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 3 的查询函数。`ShippingOnhandFile` 列集合不变。
|
||||
- Produces:
|
||||
|
||||
```python
|
||||
def insert_onhand_report(**columns: Any) -> int:
|
||||
"""插入 freight_rpa_onhand_report_files 一行并 flush。返回 file_id。不创建任务关联,不 commit。"""
|
||||
|
||||
def update_onhand_report(file_id: int, **columns: Any) -> None:
|
||||
"""按 file_id 更新该行的给定列并 flush。不 commit。"""
|
||||
```
|
||||
|
||||
发货侧可以继续更新 `shipping_task_onhand_links`、候选集、行匹配、核验。禁止再 `db.session.add(ShippingOnhandFile(...))`。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```python
|
||||
def test_shipping_notice_does_not_construct_rpa_report_rows():
|
||||
root = Path(__file__).resolve().parents[3] / "app" / "services" / "shipping_notice"
|
||||
banned_snippets = ("ShippingOnhandFile(", "ShippingInboundReportFile(", "ShippingInboundReportConfig(")
|
||||
hits = []
|
||||
for path in root.rglob("*.py"):
|
||||
text = path.read_text(encoding="utf-8")
|
||||
for snippet in banned_snippets:
|
||||
if snippet in text:
|
||||
hits.append(f"{path.name}: {snippet}")
|
||||
assert hits == []
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/shipping_notice/test_report_model_boundary.py -q`
|
||||
|
||||
Expected: FAIL,命中 `onhand_file_store.py` 与 `onhand_snapshot_store.py`。
|
||||
|
||||
- [ ] **Step 3: 挪走插入**
|
||||
|
||||
`report_store.insert_onhand_report` 接收今天 `ShippingOnhandFile(...)` 已有的列关键字(`storage_path`、`file_sha256`、`onhand_lines_json`、`field_mapping_json`、`snapshot_status`、`warehouse_id`、`source_code`、`rpa_run_no` 等),不增列。`onhand_snapshot_store.create_inventory_snapshot_from_rpa` 在得到 `file_id` 之后仍调用现有的 `link_snapshot_to_task`,关联表留在发货域。查询改用 `get_onhand_config` / `get_site`。`inbound_report_access.py` 的下载改 `read_inbound_file_bytes`。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/shipping_notice/test_report_model_boundary.py tests/test_freight_rpa_batch_s_grep_gate.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/app/services/freight_rpa/onhand/report_store.py backend/app/services/shipping_notice/onhand_snapshot_store.py backend/app/services/shipping_notice/onhand_file_store.py backend/app/services/shipping_notice/onhand_rpa_workflow.py backend/app/services/shipping_notice/onhand_source_repository.py backend/app/services/shipping_notice/inbound_report_access.py backend/app/services/shipping_notice/query_service.py backend/tests/services/shipping_notice/test_report_model_boundary.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: 回调先提交文件,再投递事实
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/services/freight_rpa/reports/dispatch.py`
|
||||
- Create: `backend/app/services/freight_rpa/common/report_audit.py`
|
||||
- Modify: `backend/app/services/freight_rpa/inbound/report_archive.py`
|
||||
- Modify: `backend/app/services/freight_rpa/common/callback_sinks.py`(文件头说明文件就绪走 `dispatch_report_fact`,进度类 kind 仍走 `dispatch_sink`)
|
||||
- Modify: `backend/tests/services/freight_rpa/test_import_boundary.py`
|
||||
- Test: `backend/tests/services/freight_rpa/test_report_fact_dispatch.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ReportFact`、`register_sink` 的未注册错误码 `FREIGHT_RPA.SINK_NOT_REGISTERED`(http 404)。
|
||||
- Produces:
|
||||
|
||||
```python
|
||||
Handler = Callable[[ReportFact], None]
|
||||
|
||||
def register_report_handler(report_kind: str, handler: Handler) -> None: ...
|
||||
|
||||
def dispatch_report_fact(fact: ReportFact) -> None:
|
||||
"""kind 无处理函数时抛 AppError(code='FREIGHT_RPA.SINK_NOT_REGISTERED', http_status=404)。
|
||||
本函数不 commit、不 rollback。"""
|
||||
```
|
||||
|
||||
`ingest_inbound_callback` 去掉 `on_terminal` 参数。每个终态分支在 `db.session.commit()` 之后构造 `ReportFact(report_kind='inbound', source_code=unit.source_code, file_id=..., sha256=..., ok=..., error_code=..., error_message=...)` 并调用 `dispatch_report_fact`。同一 `unit_run_id + sha256` 已有文件时不插入第二行,仍投递 `ok=True` 的事实(供处理函数重试)。处理函数抛出的异常原样向外抛,不包一层日志后吞掉。
|
||||
|
||||
`append_shipping_audit_event(...)` 的调用改为 `report_audit.append_rpa_report_event(...)`,关键字与现函数相同,内部写入同一个 `ShippingAuditEvent` 模型(允许 import 模型,禁止 import `app.services.shipping_notice.audit_service`)。事件名字符串保持 `shipping_inbound_rpa_callback_received` 与 `shipping_inbound_report_archived`,避免审计查询断档。
|
||||
|
||||
`test_import_boundary.py` 的 `ALLOWED_SHIPPING_NOTICE` 改为空集。`file_assets` 那条白名单一并删除(包内已经不引用它)。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```python
|
||||
def test_handler_failure_keeps_committed_file(app, db_session, monkeypatch):
|
||||
unit = _awaiting_unit(source_code="DSV")
|
||||
db_session.add(unit)
|
||||
db_session.commit()
|
||||
|
||||
def boom(fact: ReportFact) -> None:
|
||||
raise RuntimeError("handler down")
|
||||
|
||||
register_report_handler("inbound", boom)
|
||||
with pytest.raises(RuntimeError, match="handler down"):
|
||||
ingest_inbound_callback(_success_payload(unit, sha256_file=b"abc"))
|
||||
assert ShippingInboundReportFile.query.filter_by(unit_run_id=unit.id).count() == 1
|
||||
|
||||
|
||||
def test_second_delivery_does_not_insert_another_file(app, db_session):
|
||||
seen: list[ReportFact] = []
|
||||
register_report_handler("inbound", seen.append)
|
||||
unit = _awaiting_unit(source_code="DSV")
|
||||
db_session.add(unit)
|
||||
db_session.commit()
|
||||
payload = _success_payload(unit, sha256_file=b"abc")
|
||||
ingest_inbound_callback(payload)
|
||||
ingest_inbound_callback(payload)
|
||||
assert ShippingInboundReportFile.query.filter_by(unit_run_id=unit.id).count() == 1
|
||||
assert [fact.file_id for fact in seen] == [seen[0].file_id, seen[0].file_id]
|
||||
|
||||
|
||||
def test_missing_handler_raises_sink_not_registered(app, db_session):
|
||||
unit = _awaiting_unit(source_code="DSV")
|
||||
db_session.add(unit)
|
||||
db_session.commit()
|
||||
with pytest.raises(AppError) as exc:
|
||||
ingest_inbound_callback(_success_payload(unit, sha256_file=b"abc"))
|
||||
assert exc.value.code == "FREIGHT_RPA.SINK_NOT_REGISTERED"
|
||||
assert ShippingInboundReportFile.query.filter_by(unit_run_id=unit.id).count() == 1
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/freight_rpa/test_report_fact_dispatch.py -q`
|
||||
|
||||
Expected: FAIL,`ingest_inbound_callback` 仍要求 `on_terminal`。
|
||||
|
||||
- [ ] **Step 3: 改归档与审计**
|
||||
|
||||
非法载荷、单元不存在、配置缺失维持现有 4xx(`SHIPPING.RECEIPT_CALLBACK_INVALID`、`SHIPPING.RECEIPT_UNIT_NOT_FOUND`),在 `commit` 之前抛出,不调用 `dispatch_report_fact`。落 MinIO 或插行失败时事务回滚,同样不投递。`freight_upload` 的 trigger 与回调文件不改。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/freight_rpa/test_report_fact_dispatch.py tests/services/freight_rpa/test_import_boundary.py tests/test_freight_receipt_rpa_callback.py -q`
|
||||
|
||||
Expected: PASS。旧回调测试里若仍向 `ingest_inbound_callback` 传 `on_terminal=`,改成注册 `register_report_handler`。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/app/services/freight_rpa/reports/dispatch.py backend/app/services/freight_rpa/common/report_audit.py backend/app/services/freight_rpa/inbound/report_archive.py backend/app/services/freight_rpa/common/callback_sinks.py backend/tests/services/freight_rpa/test_report_fact_dispatch.py backend/tests/services/freight_rpa/test_import_boundary.py backend/tests/test_freight_receipt_rpa_callback.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 7: 业务处理函数只改自己的任务
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/services/in_transit_transfer/inbound_report_handler.py`
|
||||
- Create: `backend/app/services/shipping_notice/onhand_report_handler.py`
|
||||
- Modify: `backend/app/services/shipping_notice/rpa_sinks.py`
|
||||
- Modify: `backend/app/services/shipping_notice/inbound_report_storage.py`(去掉吞掉异常的 `_advance_transfer_source_job`;终态推进改由调拨处理函数承担)
|
||||
- Modify: `backend/app/__init__.py`(`register_onhand_sinks` / `register_inbound_sinks` 里增加 `register_report_handler`)
|
||||
- Modify: `backend/app/services/in_transit_transfer/inbound_callback_bridge.py`(`advance_source_job_from_inbound_callback` 保持只更新 `status='waiting_rpa_callback'` 的行)
|
||||
- Test: `backend/tests/services/in_transit_transfer/test_inbound_report_handler.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ReportFact`、`advance_source_job_from_inbound_callback`、`register_report_handler`。
|
||||
- Produces:
|
||||
|
||||
```python
|
||||
def handle_inbound_report(fact: ReportFact) -> None:
|
||||
"""report_kind 必须是 inbound。ok 且 file_id 有值时把等待中的 TransferSourceJob 推进到 file_ready;
|
||||
ok 为假时推进到 failed。没有 waiting_rpa_callback 行则 return。第二次调用时该行已离开等待态,不再改。"""
|
||||
|
||||
def handle_onhand_report(fact: ReportFact) -> None:
|
||||
"""report_kind 必须是 onhand。用 fact.file_id 更新发货门禁与候选。不写 TransferSourceJob。
|
||||
不插入 freight_rpa_onhand_report_files。"""
|
||||
```
|
||||
|
||||
`register_inbound_sinks` 调用 `register_report_handler('inbound', handle_inbound_report)`。`register_onhand_sinks` 调用 `register_report_handler('onhand', handle_onhand_report)`。进度类 sink(`inbound-unit-progress`、`onhand-batch-claimed` 等)仍走 `register_sink`,不改 envelope。
|
||||
|
||||
在手回调 `rpa_report_inventory` / `rpa_report_inventory_batch`:先 `insert_onhand_report` 或 `update_onhand_report`,`db.session.commit()`,再 `dispatch_report_fact(ReportFact(report_kind='onhand', ...))`。处理函数抛错时文件行还在。
|
||||
|
||||
证据同步 `sync_and_commit_for_callback` 改由 `handle_inbound_report` 在推进 `file_ready` 之后调用。它抛错时文件已提交,异常继续向外抛,供 Worker 重试。排程终态 `finalize_receipt_schedule_run_if_complete` 仍由该处理函数在调拨推进之后调用;函数本身在 `schedule` 包,`freight_rpa` 不 import 它。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```python
|
||||
def test_unregistered_transfer_handler_leaves_job_waiting(app, db_session):
|
||||
job = _waiting_job(source_code="DSV")
|
||||
db_session.add(job)
|
||||
db_session.commit()
|
||||
# 不注册 handle_inbound_report
|
||||
with pytest.raises(AppError) as exc:
|
||||
ingest_inbound_callback(_success_payload_for("DSV"))
|
||||
assert exc.value.code == "FREIGHT_RPA.SINK_NOT_REGISTERED"
|
||||
db_session.refresh(job)
|
||||
assert job.status == "waiting_rpa_callback"
|
||||
|
||||
|
||||
def test_handler_fail_then_success_advances_once(app, db_session, monkeypatch):
|
||||
job = _waiting_job(source_code="DSV")
|
||||
db_session.add(job)
|
||||
db_session.commit()
|
||||
calls = {"n": 0}
|
||||
|
||||
def flaky(fact: ReportFact) -> None:
|
||||
calls["n"] += 1
|
||||
if calls["n"] == 1:
|
||||
raise RuntimeError("once")
|
||||
handle_inbound_report(fact)
|
||||
|
||||
register_report_handler("inbound", flaky)
|
||||
payload = _success_payload_for("DSV")
|
||||
with pytest.raises(RuntimeError):
|
||||
ingest_inbound_callback(payload)
|
||||
ingest_inbound_callback(payload)
|
||||
db_session.refresh(job)
|
||||
assert job.status == "file_ready"
|
||||
assert ShippingInboundReportFile.query.count() == 1
|
||||
|
||||
|
||||
def test_no_waiting_job_is_success(app, db_session):
|
||||
register_report_handler("inbound", handle_inbound_report)
|
||||
ingest_inbound_callback(_success_payload_for("DSV"))
|
||||
assert TransferSourceJob.query.filter_by(source_code="DSV").count() == 0
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_inbound_report_handler.py -q`
|
||||
|
||||
Expected: FAIL,`handle_inbound_report` 未定义。
|
||||
|
||||
- [ ] **Step 3: 接上两个处理函数**
|
||||
|
||||
`handle_inbound_report` 在 `fact.ok and fact.file_id` 时调用:
|
||||
|
||||
```python
|
||||
advance_source_job_from_inbound_callback(
|
||||
source_code=fact.source_code,
|
||||
file_no=str(fact.file_id),
|
||||
file_sha256=fact.sha256,
|
||||
callback_ok=True,
|
||||
)
|
||||
```
|
||||
|
||||
否则 `callback_ok=False`,带上 `fact.error_code` 与 `fact.error_message`。返回 `None` 时直接结束。不要在这里捕获异常。`inbound_report_storage._advance_transfer_source_job` 的 `except Exception: logger.warning` 删除,避免再次把失败吞掉。
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_inbound_report_handler.py tests/test_freight_receipt_rpa_callback.py tests/services/freight_rpa/test_import_boundary.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add backend/app/services/in_transit_transfer/inbound_report_handler.py backend/app/services/shipping_notice/onhand_report_handler.py backend/app/services/shipping_notice/rpa_sinks.py backend/app/services/shipping_notice/inbound_report_storage.py backend/app/__init__.py backend/app/services/in_transit_transfer/inbound_callback_bridge.py backend/tests/services/in_transit_transfer/test_inbound_report_handler.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 8: ADR、术语与切换说明
|
||||
|
||||
**Files:**
|
||||
- Create: `docs/adr/0004-freight-rpa-report-ownership.md`
|
||||
- Modify: `docs/features/freight-rpa/GLOSSARY.md`(站点一条)
|
||||
- Modify: `docs/features/freight-rpa/cutover-runbook.md` 第 5 节的升级目标 revision
|
||||
- Modify: `docs/superpowers/specs/2026-10-18-freight-rpa-phase-b-design.md` 状态行改为「已有实施计划」,并加上本计划路径。不改其他段落。
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 本计划 Task 1–7 的表名与 `ReportFact` 字段。
|
||||
- Produces: ADR 记录「同一进程、提交后调用处理函数、无队列」。GLOSSARY 站点句改为归属 `freight_rpa`。Runbook 的 `flask db current` 目标改为 `s18d1e2f3a4b5`,并写明它包含 `s17b`、`s17c`。
|
||||
|
||||
- [ ] **Step 1: 写 ADR**
|
||||
|
||||
标题:Freight RPA 报表归 RPA,业务方只消费报表事实。
|
||||
|
||||
正文按 `docs/adr/0002-transfer-type-configuration.md` 的篇幅,写清三句:
|
||||
|
||||
1. 登录连接、站点、在手配置、入站配置、解析方案、在手文件、入站文件由 `freight_rpa` 写入。
|
||||
2. 文件在 RPA 事务提交之后,同一次 HTTP 请求调用 `handle_onhand_report` / `handle_inbound_report`。失败返回 5xx,文件保留,Worker 重试。
|
||||
3. 不另建服务、不引入消息队列。出站抓取不在本决策内;`report_kind=outbound` 只占位。
|
||||
|
||||
- [ ] **Step 2: 改 GLOSSARY 与 runbook**
|
||||
|
||||
`GLOSSARY.md` 第 51–52 行改为:
|
||||
|
||||
```markdown
|
||||
**站点(Source)**:
|
||||
一个货代抓取目标(如 DSV AWS、Crane NA),持有登录连接与报表配置。表 `freight_rpa_sources` 归属 freight_rpa。发货通知与在途调拨只保存 source_code。
|
||||
```
|
||||
|
||||
`cutover-runbook.md` 第 5 节把 `flask db current` 的期望从 `tt16c7d8e9f0a1b2` 改为 `s18d1e2f3a4b5`。同节加一句:该 revision 依次包含批次 R 的任务键、批次 S 的表改名与枚举、阶段 B 的在手配置表和在手文件表名。冒烟三条链路的文字不改:在手导出、入站导出、履约上传。
|
||||
|
||||
- [ ] **Step 3: 核对用词**
|
||||
|
||||
在 `docs/adr/0004-freight-rpa-report-ownership.md` 与 `docs/features/freight-rpa/GLOSSARY.md` 中搜索 `归属 shipping_notice`,结果应为空。搜索 `freight_upload`,runbook 的履约上传冒烟仍在。
|
||||
|
||||
- [ ] **Step 4: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add docs/adr/0004-freight-rpa-report-ownership.md docs/features/freight-rpa/GLOSSARY.md docs/features/freight-rpa/cutover-runbook.md docs/superpowers/specs/2026-10-18-freight-rpa-phase-b-design.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 自检
|
||||
|
||||
| 设计条款 | 任务 |
|
||||
| --- | --- |
|
||||
| 在手配置表,三列搬离站点 | Task 1、Task 2 |
|
||||
| 解析方案表名在 s17b,库上不出现 `freight_rpa_onhand_parsing_profiles` | Task 1 测试 |
|
||||
| 在手文件只改表名 | Task 1 |
|
||||
| 启用规则换检查位置 | Task 2 |
|
||||
| 只读函数:站点、配置、最新入站文件、按 file_id 读内容 | Task 3、Task 4、Task 5 |
|
||||
| 调拨与发货不再为查询 import 报表模型 | Task 4、Task 5 的门禁测试 |
|
||||
| 回调事实含 outbound 取值;本阶段投递 onhand 与 inbound | Task 3、Task 6、Task 7 |
|
||||
| 未注册处理函数、重复回调、失败后再成功 | Task 6、Task 7 |
|
||||
| 文件提交不依赖处理函数 | Task 6 |
|
||||
| `freight_rpa` 不 import 发货工作流与 `audit_service` | Task 6 边界测试 |
|
||||
| 不改 `freight_upload`、不做出站抓取、不拆服务 | Global Constraints;Task 6 写明不改 upload 文件 |
|
||||
| ADR 0004 与 GLOSSARY | Task 8 |
|
||||
|
||||
不在本计划里的项:排程函数名 `run_freight_receipt_rpa_*`、表名 `freight_rpa_inbound_rpa_unit_runs` 与 `freight_rpa_onhand_task_rpa_attempts` 的中间 `rpa`、Worker 日志行 `[freight_inbound_rpa_worker]`。设计文档没有要求改它们。
|
||||
@@ -0,0 +1,448 @@
|
||||
# 货代 RPA 类名前缀与上传动作 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:** 把表名已是 `freight_rpa_*` 的 ORM 类改成 `FreightRpa` 前缀,并把 Worker 上传动作与心跳能力改成 `freight_rpa_upload`。
|
||||
|
||||
**Architecture:** 两块互不依赖。任务 1 只改三个动作/能力字面量、原因码和两份现行文档,schema 仍是 `freight_rpa.upload.v1`。任务 2 用显式类名表做整词替换并移动模型文件,再只改站点关系属性 `inventory_source` 与 `receipt_report_config`。不留旧名别名,不写迁移。
|
||||
|
||||
**Tech Stack:** Flask、SQLAlchemy 2.0、pytest。Python 用 `backend/.venv/Scripts/python.exe`。pytest 的工作目录是 `backend/`。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-19-freight-rpa-class-prefix-design.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 类名以 `FreightRpa` 开头。`ShippingInboundRpaUnitRun` 改为 `FreightRpaInboundUnitRun`,`ShippingTaskOnhandRpaAttempt` 改为 `FreightRpaOnhandTaskAttempt`,`ShippingOnhandSource` 改为 `FreightRpaSource`。
|
||||
- 心跳能力与 trigger `action` 改为 `freight_rpa_upload`。`trigger_io.SCHEMA` 保持 `freight_rpa.upload.v1`。
|
||||
- 不保留旧类名、旧模块路径、旧动作名的别名。后端与 Windows Worker 同一次发布。
|
||||
- 不改任何表名、索引名、约束名、外键名。不新增 Alembic 迁移。`backend/migrations/` 不参与替换。
|
||||
- 不改发货阶段 `freight_upload`、`freight_uploading`,不改门禁码 `freight_upload_rpa`,不改动作码 `retry_freight_upload_rpa`、`poll_freight_upload_rpa`、`trigger_freight_upload_rpa`,不改四语言文案。
|
||||
- 函数名 `check_freight_upload_rpa_ready` 与 `assert_freight_upload_rpa_ready` 保留。
|
||||
- 不改 `ShippingUploadAttempt` 与表 `shipping_notice_upload_attempts`。
|
||||
- 不改这些发货类:`ShippingNotice`、`ShippingTaskOnhandLink`、`ShippingOnhandCandidateSet`、`ShippingOnhandCandidateSource`、`ShippingOnhandCandidateLine`、`ShippingOnhandPreparationAttempt`、`ShippingOnhandPreparationSourceAttempt`、`ShippingNoticeLineOnhandMatch`、`ShippingOnhandVerification`、`ShippingOnhandVerificationLine`、`ShippingFreightCancellation`、`ShippingExcelTemplate`。关系属性 `inventory_file` 保留。
|
||||
- 不把履约出货改名为 outbound,不改 `shipment_*`。
|
||||
- 不改环境变量 `FREIGHT_RPA_UPLOAD_*`,不改上传回调路径,不改 MinIO 键。
|
||||
- 不改写 `docs/superpowers/plans/` 与 `docs/superpowers/specs/` 里已有计划正文。本规格的状态行除外,见任务 2 最后一步。
|
||||
- 本计划覆盖 2026-10-17 对 `freight_rpa_upload` 的否决,也覆盖阶段 B「不改 `freight_upload`」里对动作名和心跳能力的那一句。阶段名和门禁码仍不改。
|
||||
- 工作区里已有未提交的批次 S/D 与阶段 B。禁止 `git add -A`,禁止 `git commit`。每任务只暂存该任务列出的路径。
|
||||
- 改签名或文件协作关系时同步文件头 docstring(AGENTS.md §5)。
|
||||
|
||||
## 文件地图
|
||||
|
||||
| 文件 | 职责 |
|
||||
| --- | --- |
|
||||
| `backend/app/services/freight_rpa/upload/trigger_io.py` | trigger 的 `action` 常量 |
|
||||
| `backend/app/services/freight_rpa/common/worker_heartbeat.py` | 心跳能力常量、缺失原因码、管理端状态键 |
|
||||
| `scripts/freight_rpa/common/rpa_heartbeat.py` | Windows Worker 上报的能力字符串 |
|
||||
| `docs/features/freight-rpa/GLOSSARY.md` | Upload 条的现行动作名 |
|
||||
| `docs/features/freight-rpa/cutover-runbook.md` | 发布窗口里的动作名,以及发布前清空 upload 目录 |
|
||||
| `backend/app/models/freight_rpa_config.py` | 站点、登录连接、解析方案及在手配置类。由 `shipping_onhand_config.py` 改名 |
|
||||
| `backend/app/models/freight_rpa_inbound_report.py` | 入站配置、执行单元、文件、通知。由 `shipping_inbound_report.py` 改名 |
|
||||
| `backend/app/models/freight_rpa_onhand_mapping.py` | 在手字段映射。由 `shipping_onhand_mapping.py` 改名 |
|
||||
| `backend/app/models/freight_rpa_onhand_task_attempts.py` | 在手任务抓取尝试。由 `shipping_onhand_task_rpa_attempts.py` 改名 |
|
||||
| `backend/app/models/freight_rpa_onhand_report_file.py` | 在手报表文件。从 `shipping.py` 拆出 |
|
||||
| `backend/app/models/__init__.py` | 导出新类名,不留旧类名 |
|
||||
| `backend/tests/test_freight_rpa_class_names.py` | 锁表名、新类名、关系属性名 |
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 上传动作与心跳能力
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/freight_rpa/upload/trigger_io.py`
|
||||
- Modify: `backend/app/services/freight_rpa/common/worker_heartbeat.py`
|
||||
- Modify: `scripts/freight_rpa/common/rpa_heartbeat.py`
|
||||
- Modify: `backend/tests/services/freight_rpa/test_upload_trigger_contract.py`
|
||||
- Modify: `backend/tests/services/freight_rpa/test_worker_heartbeat.py`
|
||||
- Modify: `backend/tests/test_freight_rpa_heartbeat.py`
|
||||
- Modify: `docs/features/freight-rpa/GLOSSARY.md`
|
||||
- Modify: `docs/features/freight-rpa/cutover-runbook.md`
|
||||
- Test: `backend/tests/services/freight_rpa/test_upload_trigger_contract.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 现有 `write_upload_trigger(...)`、`check_freight_upload_rpa_ready()`、`build_heartbeat_payload(...)`。函数名不改。
|
||||
- Produces: `ACTION_FREIGHT_RPA_UPLOAD = "freight_rpa_upload"`;`FREIGHT_RPA_UPLOAD_CAPABILITY = "freight_rpa_upload"`;两者相等。缺失原因码 `missing_freight_rpa_upload_capability`。`SCHEMA` 仍为 `freight_rpa.upload.v1`。
|
||||
|
||||
- [ ] **Step 1: 把契约测试改成新动作名**
|
||||
|
||||
在 `backend/tests/services/freight_rpa/test_upload_trigger_contract.py` 把导入和断言换成:
|
||||
|
||||
```python
|
||||
from app.services.freight_rpa.common.worker_heartbeat import FREIGHT_RPA_UPLOAD_CAPABILITY
|
||||
from app.services.freight_rpa.upload import trigger_io
|
||||
|
||||
|
||||
def test_upload_trigger_constants_align_with_heartbeat_capability():
|
||||
"""upload action 必须与 Worker 心跳能力串 freight_rpa_upload 一致。"""
|
||||
assert trigger_io.SCHEMA == "freight_rpa.upload.v1"
|
||||
assert trigger_io.ACTION_FREIGHT_RPA_UPLOAD == "freight_rpa_upload"
|
||||
assert trigger_io.ACTION_FREIGHT_RPA_UPLOAD == FREIGHT_RPA_UPLOAD_CAPABILITY
|
||||
assert "outbound_upload" not in trigger_io.ACTION_FREIGHT_RPA_UPLOAD
|
||||
assert "shipment_upload" not in trigger_io.ACTION_FREIGHT_RPA_UPLOAD
|
||||
```
|
||||
|
||||
同一文件里 `test_write_upload_trigger_persists_freight_upload_action` 的两处动作断言改为:
|
||||
|
||||
```python
|
||||
assert payload["action"] == trigger_io.ACTION_FREIGHT_RPA_UPLOAD
|
||||
assert payload["schema_version"] == trigger_io.SCHEMA
|
||||
assert payload["action"] == "freight_rpa_upload"
|
||||
assert payload["schema_version"] == "freight_rpa.upload.v1"
|
||||
```
|
||||
|
||||
在 `backend/tests/services/freight_rpa/test_worker_heartbeat.py` 把 `FREIGHT_UPLOAD_CAPABILITY` 的导入改成 `FREIGHT_RPA_UPLOAD_CAPABILITY`。`test_check_freight_upload_rpa_ready_requires_freight_upload_capability` 的断言改为:
|
||||
|
||||
```python
|
||||
assert result.ready is False
|
||||
assert any("missing_freight_rpa_upload_capability" in reason for reason in result.reasons)
|
||||
```
|
||||
|
||||
`test_check_freight_upload_rpa_ready_when_worker_and_dirs_ok` 里心跳能力列表改为:
|
||||
|
||||
```python
|
||||
capabilities=[ONHAND_EXPORT_CAPABILITY, FREIGHT_RPA_UPLOAD_CAPABILITY],
|
||||
```
|
||||
|
||||
在 `backend/tests/test_freight_rpa_heartbeat.py` 的 `test_build_heartbeat_payload_inbound_worker_declares_inbound_export` 后面增加:
|
||||
|
||||
```python
|
||||
def test_build_heartbeat_payload_adds_freight_rpa_upload_when_upload_enabled(monkeypatch):
|
||||
"""开启上传时心跳能力是 freight_rpa_upload,不再上报 freight_upload。"""
|
||||
module = _load_freight_rpa_heartbeat_module()
|
||||
monkeypatch.setenv("FREIGHT_RPA_WORKER_UPLOAD_ENABLED", "true")
|
||||
payload = module.build_heartbeat_payload(
|
||||
trigger_dir=r"C:\HxopsRpaTest\data\onhand_triggers",
|
||||
drop_dir=r"C:\HxopsRpaTest\data\onhand_drop",
|
||||
)
|
||||
assert payload["capabilities"] == ["onhand_export", "freight_rpa_upload"]
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试,确认失败**
|
||||
|
||||
工作目录 `backend/`:
|
||||
|
||||
```powershell
|
||||
..\.venv\Scripts\python.exe -m pytest tests/services/freight_rpa/test_upload_trigger_contract.py tests/services/freight_rpa/test_worker_heartbeat.py::test_check_freight_upload_rpa_ready_requires_freight_upload_capability tests/test_freight_rpa_heartbeat.py::test_build_heartbeat_payload_adds_freight_rpa_upload_when_upload_enabled -q --tb=line
|
||||
```
|
||||
|
||||
Expected: FAIL。导入失败或断言仍是 `freight_upload`。
|
||||
|
||||
- [ ] **Step 3: 改三个字面量**
|
||||
|
||||
`trigger_io.py`:
|
||||
|
||||
```python
|
||||
SCHEMA = "freight_rpa.upload.v1"
|
||||
ACTION_FREIGHT_RPA_UPLOAD = "freight_rpa_upload"
|
||||
```
|
||||
|
||||
`write_upload_trigger` 写入的 `"action"` 改为 `ACTION_FREIGHT_RPA_UPLOAD`。文件头里描述动作的那一句改为:action 对齐心跳能力 `freight_rpa_upload`(`FREIGHT_RPA_UPLOAD_CAPABILITY`)。删除对常量名 `ACTION_FREIGHT_UPLOAD`、`FREIGHT_UPLOAD_CAPABILITY` 的引用。
|
||||
|
||||
`worker_heartbeat.py`:
|
||||
|
||||
```python
|
||||
FREIGHT_RPA_UPLOAD_CAPABILITY = "freight_rpa_upload"
|
||||
```
|
||||
|
||||
删除 `FREIGHT_UPLOAD_CAPABILITY`。所有引用改到新常量,包括 `check_freight_upload_rpa_ready` 与 `assert_freight_upload_rpa_ready` 内部。这两个函数名保留。
|
||||
|
||||
`_REASON_USER_HINTS` 的键改为 `missing_freight_rpa_upload_capability`,提示文案改为 `Worker 未声明 freight_rpa_upload 能力`。`_missing_capability_reason` 继续用 `f"missing_{required_capability}_capability"`,不要再手写旧码。
|
||||
|
||||
`serialize_rpa_worker_status` 返回字典里的键 `"freight_upload"` 改为 `"freight_rpa_upload"`。这是该文件里剩下的动作字面量;仓库里没有前端读取这个键。
|
||||
|
||||
文件头注释里「freight_upload 不变」改为「上传能力为 freight_rpa_upload」。
|
||||
|
||||
`scripts/freight_rpa/common/rpa_heartbeat.py` 的 `build_heartbeat_payload`:开启上传时 `capabilities.append("freight_rpa_upload")`。函数 docstring 同步写成 `freight_rpa_upload`。
|
||||
|
||||
- [ ] **Step 4: 改现行文档**
|
||||
|
||||
`docs/features/freight-rpa/GLOSSARY.md` Upload 条:心跳能力与上传 action 写成 `freight_rpa_upload`。schema 仍写 `freight_rpa.upload.v1`。保留「禁止 outbound_*」这句话。
|
||||
|
||||
`docs/features/freight-rpa/cutover-runbook.md` 里动作和心跳现在写成 `freight_upload` 或「`freight_upload` 不变」的地方,改成 `freight_rpa_upload`。在「一次上传」那一步之前加一句:发布前清空 upload 的 triggers 与 queue;已落盘且 `action` 为 `freight_upload` 的 trigger 不改写、不双读。
|
||||
|
||||
不要改 `docs/superpowers/plans/2026-10-17-freight-rpa-upload-action-fix.md`。
|
||||
|
||||
- [ ] **Step 5: 跑测试并检索旧字面量**
|
||||
|
||||
工作目录 `backend/`:
|
||||
|
||||
```powershell
|
||||
..\.venv\Scripts\python.exe -m pytest tests/services/freight_rpa/test_upload_trigger_contract.py tests/services/freight_rpa/test_worker_heartbeat.py tests/test_freight_rpa_heartbeat.py -q --tb=short
|
||||
```
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
在仓库根目录检索。下面三条的结果必须为空:
|
||||
|
||||
```powershell
|
||||
rg -n "ACTION_FREIGHT_UPLOAD|FREIGHT_UPLOAD_CAPABILITY" backend/app/services/freight_rpa/upload/trigger_io.py backend/app/services/freight_rpa/common/worker_heartbeat.py scripts/freight_rpa/common/rpa_heartbeat.py
|
||||
rg -n "\"freight_upload\"" backend/app/services/freight_rpa/upload/trigger_io.py backend/app/services/freight_rpa/common/worker_heartbeat.py scripts/freight_rpa/common/rpa_heartbeat.py
|
||||
rg -n "missing_freight_upload_capability" backend/app/services/freight_rpa/common/worker_heartbeat.py backend/tests/services/freight_rpa/test_worker_heartbeat.py
|
||||
```
|
||||
|
||||
`check_freight_upload_rpa_ready` 仍在 `worker_heartbeat.py`。发货阶段文件里的 `freight_upload` 不动。
|
||||
|
||||
- [ ] **Step 6: 只暂存本任务路径**
|
||||
|
||||
```powershell
|
||||
git add -- backend/app/services/freight_rpa/upload/trigger_io.py backend/app/services/freight_rpa/common/worker_heartbeat.py scripts/freight_rpa/common/rpa_heartbeat.py backend/tests/services/freight_rpa/test_upload_trigger_contract.py backend/tests/services/freight_rpa/test_worker_heartbeat.py backend/tests/test_freight_rpa_heartbeat.py docs/features/freight-rpa/GLOSSARY.md docs/features/freight-rpa/cutover-runbook.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: ORM 类名与模型文件
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/models/freight_rpa_config.py`
|
||||
- Create: `backend/app/models/freight_rpa_inbound_report.py`
|
||||
- Create: `backend/app/models/freight_rpa_onhand_mapping.py`
|
||||
- Create: `backend/app/models/freight_rpa_onhand_task_attempts.py`
|
||||
- Create: `backend/app/models/freight_rpa_onhand_report_file.py`
|
||||
- Create: `backend/tests/test_freight_rpa_class_names.py`
|
||||
- Modify: `backend/app/models/shipping.py`
|
||||
- Modify: `backend/app/models/__init__.py`
|
||||
- Delete: `backend/app/models/shipping_onhand_config.py`
|
||||
- Delete: `backend/app/models/shipping_inbound_report.py`
|
||||
- Delete: `backend/app/models/shipping_onhand_mapping.py`
|
||||
- Delete: `backend/app/models/shipping_onhand_task_rpa_attempts.py`
|
||||
- Test: `backend/tests/test_freight_rpa_class_names.py`
|
||||
|
||||
引用这些类的 `backend/app`、`backend/tests`、`backend/scripts` 由下面的脚本改名。`backend/migrations/` 与 `docs/superpowers/` 不跑脚本。
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 任务 1 不需要。表名保持规格第 3 节那一列。
|
||||
- Produces: `from app.models import FreightRpaSource, FreightRpaOnhandReportFile, FreightRpaInboundReportFile, FreightRpaInboundUnitRun, FreightRpaParsingProfile, FreightRpaProfile`。`FreightRpaSource.inbound_report_config`。`FreightRpaOnhandReportConfig.source`、`FreightRpaOnhandExternalMapping.source`、`FreightRpaInboundReportConfig.source`、`FreightRpaInboundUnitRun.source`。`app.models` 上不再有 `ShippingOnhandSource`、`ShippingOnhandFile`、`ShippingInboundReportFile`、`ShippingParsingProfile`。
|
||||
|
||||
- [ ] **Step 1: 写会失败的类名测试**
|
||||
|
||||
创建 `backend/tests/test_freight_rpa_class_names.py`:
|
||||
|
||||
```python
|
||||
"""
|
||||
backend/tests/test_freight_rpa_class_names.py
|
||||
|
||||
用途:锁住货代 RPA 模型的类名、表名和站点关系属性名。
|
||||
依赖:app.models 里拆出的 freight_rpa_* 模型模块。
|
||||
逻辑:被 pytest 直接导入;不连数据库。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import app.models as models
|
||||
from app.models.freight_rpa_config import (
|
||||
FreightRpaOnhandExternalMapping,
|
||||
FreightRpaOnhandReportConfig,
|
||||
FreightRpaSource,
|
||||
)
|
||||
from app.models.freight_rpa_inbound_report import (
|
||||
FreightRpaInboundReportConfig,
|
||||
FreightRpaInboundReportFile,
|
||||
FreightRpaInboundUnitRun,
|
||||
)
|
||||
from app.models.freight_rpa_onhand_report_file import FreightRpaOnhandReportFile
|
||||
from app.models.freight_rpa_onhand_task_attempts import FreightRpaOnhandTaskAttempt
|
||||
|
||||
|
||||
def test_freight_rpa_classes_keep_existing_table_names():
|
||||
"""类名换成 FreightRpa 后,表名仍是规格里的 freight_rpa_*。"""
|
||||
assert FreightRpaSource.__tablename__ == "freight_rpa_sources"
|
||||
assert FreightRpaOnhandReportFile.__tablename__ == "freight_rpa_onhand_report_files"
|
||||
assert FreightRpaInboundReportFile.__tablename__ == "freight_rpa_inbound_report_files"
|
||||
assert FreightRpaInboundUnitRun.__tablename__ == "freight_rpa_inbound_rpa_unit_runs"
|
||||
|
||||
|
||||
def test_site_relationships_drop_inventory_and_receipt_names():
|
||||
"""站点关系改叫 source / inbound_report_config,索引名不在这个测试里改。"""
|
||||
assert "source" in FreightRpaOnhandReportConfig.__mapper__.relationships
|
||||
assert "inventory_source" not in FreightRpaOnhandReportConfig.__mapper__.relationships
|
||||
assert "source" in FreightRpaInboundReportConfig.__mapper__.relationships
|
||||
assert "source" in FreightRpaInboundUnitRun.__mapper__.relationships
|
||||
assert "inbound_report_config" in FreightRpaSource.__mapper__.relationships
|
||||
assert "receipt_report_config" not in FreightRpaSource.__mapper__.relationships
|
||||
assert "source" in FreightRpaOnhandExternalMapping.__mapper__.relationships
|
||||
assert FreightRpaOnhandTaskAttempt.__tablename__ == "freight_rpa_onhand_task_rpa_attempts"
|
||||
|
||||
|
||||
def test_old_shipping_class_names_are_not_exported():
|
||||
"""旧类名不留别名。发货任务关联类仍叫 ShippingTaskOnhandLink。"""
|
||||
assert not hasattr(models, "ShippingOnhandSource")
|
||||
assert not hasattr(models, "ShippingOnhandFile")
|
||||
assert not hasattr(models, "ShippingInboundReportFile")
|
||||
assert not hasattr(models, "ShippingParsingProfile")
|
||||
assert hasattr(models, "FreightRpaSource")
|
||||
assert hasattr(models, "FreightRpaOnhandReportFile")
|
||||
assert hasattr(models, "ShippingTaskOnhandLink")
|
||||
assert hasattr(models, "ShippingUploadAttempt")
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试,确认失败**
|
||||
|
||||
工作目录 `backend/`:
|
||||
|
||||
```powershell
|
||||
..\.venv\Scripts\python.exe -m pytest tests/test_freight_rpa_class_names.py -q --tb=line
|
||||
```
|
||||
|
||||
Expected: FAIL,模块 `app.models.freight_rpa_config` 不存在。
|
||||
|
||||
- [ ] **Step 3: 移动文件并按显式表替换类名**
|
||||
|
||||
在仓库根目录把下面整段存成临时文件 `rename_freight_rpa_classes.py` 并执行。跑完删除它,不要 `git add` 它。脚本先 `git mv`,再替换模块路径,再只替换类名整词,长名字在前。不要把 `ShippingOnhand` 当成前缀去替换。
|
||||
|
||||
```python
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path.cwd()
|
||||
MOVES = [
|
||||
("backend/app/models/shipping_onhand_config.py", "backend/app/models/freight_rpa_config.py"),
|
||||
("backend/app/models/shipping_inbound_report.py", "backend/app/models/freight_rpa_inbound_report.py"),
|
||||
("backend/app/models/shipping_onhand_mapping.py", "backend/app/models/freight_rpa_onhand_mapping.py"),
|
||||
("backend/app/models/shipping_onhand_task_rpa_attempts.py", "backend/app/models/freight_rpa_onhand_task_attempts.py"),
|
||||
]
|
||||
MODULE_PATHS = [
|
||||
("app.models.shipping_onhand_task_rpa_attempts", "app.models.freight_rpa_onhand_task_attempts"),
|
||||
("app.models.shipping_onhand_config", "app.models.freight_rpa_config"),
|
||||
("app.models.shipping_inbound_report", "app.models.freight_rpa_inbound_report"),
|
||||
("app.models.shipping_onhand_mapping", "app.models.freight_rpa_onhand_mapping"),
|
||||
("models.shipping_onhand_task_rpa_attempts", "models.freight_rpa_onhand_task_attempts"),
|
||||
("models.shipping_onhand_config", "models.freight_rpa_config"),
|
||||
("models.shipping_inbound_report", "models.freight_rpa_inbound_report"),
|
||||
("models.shipping_onhand_mapping", "models.freight_rpa_onhand_mapping"),
|
||||
]
|
||||
RENAMES = [
|
||||
("ShippingOnhandSourceParsingBindingAudit", "FreightRpaSourceParsingBindingAudit"),
|
||||
("ShippingOnhandRoutingRuleCondition", "FreightRpaOnhandRoutingRuleCondition"),
|
||||
("ShippingOnhandRoutingRuleVersion", "FreightRpaOnhandRoutingRuleVersion"),
|
||||
("ShippingOnhandConfigurationTestRun", "FreightRpaOnhandConfigurationTestRun"),
|
||||
("ShippingInboundNotificationDelivery", "FreightRpaInboundNotificationDelivery"),
|
||||
("ShippingOnhandStructureAnalysis", "FreightRpaOnhandStructureAnalysis"),
|
||||
("ShippingOnhandExternalMapping", "FreightRpaOnhandExternalMapping"),
|
||||
("ShippingOnhandValidationBatch", "FreightRpaOnhandValidationBatch"),
|
||||
("ShippingInboundReportConfig", "FreightRpaInboundReportConfig"),
|
||||
("ShippingOnhandReportConfig", "FreightRpaOnhandReportConfig"),
|
||||
("ShippingInboundReportFile", "FreightRpaInboundReportFile"),
|
||||
("ShippingTaskOnhandRpaAttempt", "FreightRpaOnhandTaskAttempt"),
|
||||
("ShippingOnhandRoutingRule", "FreightRpaOnhandRoutingRule"),
|
||||
("ShippingInboundRpaUnitRun", "FreightRpaInboundUnitRun"),
|
||||
("ShippingParsingProfile", "FreightRpaParsingProfile"),
|
||||
("ShippingOnhandMapping", "FreightRpaOnhandMapping"),
|
||||
("ShippingOnhandSource", "FreightRpaSource"),
|
||||
("ShippingOnhandField", "FreightRpaOnhandField"),
|
||||
("ShippingOnhandFile", "FreightRpaOnhandReportFile"),
|
||||
("ShippingRpaProfile", "FreightRpaProfile"),
|
||||
]
|
||||
SKIP_PARTS = {"migrations", "superpowers", ".superpowers"}
|
||||
ROOTS = [
|
||||
ROOT / "backend" / "app",
|
||||
ROOT / "backend" / "tests",
|
||||
ROOT / "backend" / "scripts",
|
||||
ROOT / "scripts" / "freight_rpa",
|
||||
]
|
||||
|
||||
for src, dst in MOVES:
|
||||
subprocess.run(["git", "mv", src, dst], check=True, cwd=ROOT)
|
||||
|
||||
for base in ROOTS:
|
||||
for path in base.rglob("*"):
|
||||
if not path.is_file() or path.suffix not in {".py", ".md"}:
|
||||
continue
|
||||
if any(part in SKIP_PARTS for part in path.parts):
|
||||
continue
|
||||
text = path.read_text(encoding="utf-8")
|
||||
updated = text
|
||||
for old, new in MODULE_PATHS:
|
||||
updated = updated.replace(old, new)
|
||||
for old, new in RENAMES:
|
||||
updated = re.sub(rf"\b{old}\b", new, updated)
|
||||
if updated != text:
|
||||
path.write_text(updated, encoding="utf-8")
|
||||
```
|
||||
|
||||
然后把 `FreightRpaOnhandReportFile` 的整个类(含它上方的类 docstring,不含 `ShippingTaskOnhandLink`)从 `backend/app/models/shipping.py` 剪到新文件 `backend/app/models/freight_rpa_onhand_report_file.py`。新文件自己 import `Base` 以及这个类用到的 SQLAlchemy 符号。`shipping.py` 若还引用该类,改为从新模块导入,或只在类型注解里用字符串 `"FreightRpaOnhandReportFile"`。`ShippingTaskOnhandLink.inventory_file` 的目标类字符串改为 `"FreightRpaOnhandReportFile"`,属性名 `inventory_file` 不变。
|
||||
|
||||
把新文件头写成:
|
||||
|
||||
```python
|
||||
"""
|
||||
backend/app/models/freight_rpa_onhand_report_file.py
|
||||
|
||||
用途:货代 RPA 抓回的在手报表文件。
|
||||
依赖:models.base.Base、shipping.py 里的 ShippingTaskOnhandLink。
|
||||
逻辑:表名 freight_rpa_onhand_report_files 不变;发货任务通过 ShippingTaskOnhandLink 引用本行。
|
||||
"""
|
||||
```
|
||||
|
||||
另外四个模型文件的文件头第一行改成新路径,类名改成新类名。`__tablename__`、`Index(...)`、`UniqueConstraint(...)`、`CheckConstraint(...)` 的字符串一个字都不改。
|
||||
|
||||
`backend/app/models/__init__.py` 的 import 路径改到新模块,`__all__` 只导出新类名。文件头「在手/入站模型只导出 ShippingOnhand* 与 ShippingInbound*」改为「在手/入站模型导出 FreightRpa*」。
|
||||
|
||||
- [ ] **Step 4: 只改两个关系属性**
|
||||
|
||||
不要全局把 `inventory_source` 换成 `source`。投影字典的键 `'inventory_source'`、门禁码、`inventory_source_code` 都要留下。
|
||||
|
||||
只做这三类替换,范围是 `backend/app`、`backend/tests`、`backend/scripts`:
|
||||
|
||||
1. 模型字段行 `inventory_source:` 改为 `source:`。出现位置是 `FreightRpaOnhandReportConfig`、`FreightRpaOnhandExternalMapping`、`FreightRpaInboundReportConfig`、`FreightRpaInboundUnitRun`。
|
||||
2. 模型文件里的 `back_populates='inventory_source'` 改为 `back_populates='source'`。
|
||||
3. 关键字实参 `inventory_source=` 改为 `source=`。点号访问 `.inventory_source` 改为 `.source`。已知位置包括 `shipping_onhand_admin_service.py` 构造 `FreightRpaOnhandReportConfig`、`onhand_configuration_test.py`、`import_freight_rpa_sources.py`、`freight_rpa_inbound_job.py` 的 `unit.inventory_source`、`api/schedule/runs.py` 的 `retry.inventory_source`。
|
||||
|
||||
`receipt_report_config` 用整词替换成 `inbound_report_config`,同一范围。这个整词不会打中 `get_receipt_report_config`,因为中间有下划线。不要改 `backend/migrations` 里的旧表名 `shipping_receipt_report_configs`。
|
||||
|
||||
改完后这两条结果必须为空:
|
||||
|
||||
```powershell
|
||||
rg -n "\.inventory_source\b|inventory_source=" backend/app backend/tests backend/scripts
|
||||
rg -n "\breceipt_report_config\b" backend/app backend/tests backend/scripts
|
||||
```
|
||||
|
||||
`rg -n "inventory_source" backend/app/services/shipping_notice/line_onhand_match_projection.py` 仍应能看到字典键 `'inventory_source'`。那是发货投影,本任务不改。
|
||||
|
||||
- [ ] **Step 5: 跑类名测试并检索旧类名**
|
||||
|
||||
工作目录 `backend/`:
|
||||
|
||||
```powershell
|
||||
..\.venv\Scripts\python.exe -m pytest tests/test_freight_rpa_class_names.py -q --tb=short
|
||||
```
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
仓库根目录,下面每一条结果必须为空。把规格第 3 节的旧类名逐个放进同一条正则:
|
||||
|
||||
```powershell
|
||||
rg -n "\bShippingOnhandSource\b|\bShippingOnhandFile\b|\bShippingInboundReportFile\b|\bShippingInboundRpaUnitRun\b|\bShippingTaskOnhandRpaAttempt\b|\bShippingParsingProfile\b|\bShippingRpaProfile\b|\bShippingOnhandReportConfig\b|\bShippingOnhandMapping\b|\bShippingInboundReportConfig\b|\bShippingInboundNotificationDelivery\b|\bShippingOnhandField\b|\bShippingOnhandExternalMapping\b|\bShippingOnhandStructureAnalysis\b|\bShippingOnhandConfigurationTestRun\b|\bShippingOnhandValidationBatch\b|\bShippingOnhandRoutingRule\b|\bShippingOnhandRoutingRuleCondition\b|\bShippingOnhandRoutingRuleVersion\b|\bShippingOnhandSourceParsingBindingAudit\b" backend/app scripts/freight_rpa
|
||||
```
|
||||
|
||||
`backend/migrations` 里的旧类名允许留下。
|
||||
|
||||
旧模块路径也必须为空:
|
||||
|
||||
```powershell
|
||||
rg -n "models\.shipping_onhand_config|models\.shipping_inbound_report|models\.shipping_onhand_mapping|models\.shipping_onhand_task_rpa_attempts|shipping import FreightRpaOnhandReportFile" backend/app backend/tests backend/scripts
|
||||
```
|
||||
|
||||
若 `from app.models.shipping import FreightRpaOnhandReportFile` 仍在,改成 `from app.models.freight_rpa_onhand_report_file import FreightRpaOnhandReportFile`,或改成 `from app.models import FreightRpaOnhandReportFile`。
|
||||
|
||||
再跑一条导入检查,确认模型包能加载:
|
||||
|
||||
```powershell
|
||||
..\.venv\Scripts\python.exe -c "import app.models as m; assert m.FreightRpaInboundReportFile.__tablename__=='freight_rpa_inbound_report_files'"
|
||||
```
|
||||
|
||||
工作目录仍是 `backend/`。
|
||||
|
||||
- [ ] **Step 6: 改规格状态行**
|
||||
|
||||
`docs/superpowers/specs/2026-10-19-freight-rpa-class-prefix-design.md` 第一段状态从 `待评审` 改为 `已有实施计划`,并写上本计划路径 `docs/superpowers/plans/2026-10-19-freight-rpa-class-prefix.md`。规格正文的类名对照表不要改。
|
||||
|
||||
- [ ] **Step 7: 只暂存本任务碰到的路径**
|
||||
|
||||
先删掉临时脚本 `rename_freight_rpa_classes.py`。然后暂存新模型文件、测试、`shipping.py`、`models/__init__.py`,以及 `git status --short` 里确因本任务改了类名或关系属性的 `backend/app`、`backend/tests`、`backend/scripts` 文件。不要暂存 `backend/migrations`。不要 `git add -A`。规格状态行一并暂存:
|
||||
|
||||
```powershell
|
||||
git add -- docs/superpowers/specs/2026-10-19-freight-rpa-class-prefix-design.md backend/tests/test_freight_rpa_class_names.py backend/app/models/freight_rpa_config.py backend/app/models/freight_rpa_inbound_report.py backend/app/models/freight_rpa_onhand_mapping.py backend/app/models/freight_rpa_onhand_task_attempts.py backend/app/models/freight_rpa_onhand_report_file.py backend/app/models/shipping.py backend/app/models/__init__.py
|
||||
```
|
||||
|
||||
其余被类名替换碰到的文件,按 `git diff --name-only` 逐个 `git add -- <path>`。
|
||||
@@ -1,6 +1,6 @@
|
||||
# Freight RPA 独立模块化与 onhand/inbound/outbound 全域改名 — 设计文档
|
||||
|
||||
日期:2026-10-16 | 状态:**草案(待用户评审)** | 决策依据:`docs/superpowers/plans/2026-10-16-freight-rpa-decouple-and-rename-evaluation.md`(§6 决策记录 + §8 完整性清单)+ `docs/adr/0003-freight-rpa-module-boundary.md` | 术语:`docs/features/freight-rpa/GLOSSARY.md` | 前置:`2026-10-15-inbound-outbound-idempotency-rename`(已实施,**须先提交**)
|
||||
日期:2026-10-16 | 状态:**已修订(2026-10-17 术语纠偏)** | 决策依据:`docs/superpowers/plans/2026-10-16-freight-rpa-decouple-and-rename-evaluation.md`(§6 决策记录 + §8 完整性清单)+ `docs/adr/0003-freight-rpa-module-boundary.md` | 术语:`docs/features/freight-rpa/GLOSSARY.md` | 前置:`2026-10-15-inbound-outbound-idempotency-rename`(已实施)| **2026-10-17 纠偏**:outbound **仅**在途调拨出站;货代履约「出货」(shipment) **禁止**改名为 outbound;废除批次 T「shipment→outbound」;upload action 应对齐 `freight_upload`(批次 R 误落的 `outbound_upload` 须改回)
|
||||
|
||||
## 0. 问题陈述(Problem Statement)
|
||||
|
||||
@@ -8,13 +8,13 @@ Freight RPA(货代 RPA)的后端编排层寄生在 shipping_notice 业务包
|
||||
|
||||
## 1. 解决方案(Solution)
|
||||
|
||||
把 RPA 编排层/调度壳/回调路由收编为独立模块 `freight_rpa`(回调 blueprint `/api/freight-rpa/*`),数据库表全部留在原地;术语改名按四个批次(R=RPA 域随解耦一次切换、S=shipping_notice 域含 28 表 rename 与存量数据迁移、T=shipment→outbound 排除合同付款、D=文档收口)实施,四个批次**同一发布窗口上线**:后端+前端+迁移+Windows Worker 同窗口切换,不做双路由、不留兼容层。出站(outbound)仅解析规则与目录结构就位,抓取链路留待未来。
|
||||
把 RPA 编排层/调度壳/回调路由收编为独立模块 `freight_rpa`(回调 blueprint `/api/freight-rpa/*`),数据库表全部留在原地;术语改名按批次 **R→S→D** 实施(**原批次 T「shipment→outbound」已废除**):R=RPA 域随解耦一次切换、S=shipping_notice 域含表 rename 与存量数据迁移、D=文档收口。同一发布窗口上线:后端+前端+迁移+Windows Worker 同窗口切换,不做双路由、不留兼容层。**outbound** 仅服务在途调拨出站(目录/解析预留,抓取链路留待未来);**货代履约出货**留在 shipping_notice(`shipment_*`),与 outbound 无关。
|
||||
|
||||
## 2. 用户故事(User Stories)
|
||||
|
||||
1. 作为平台开发者,我希望 RPA 编排层独立于 shipping_notice 业务包,以便新增 RPA 消费方时不必理解发货通知业务。
|
||||
2. 作为平台开发者,我希望 freight_rpa 包的 import 边界被自动化测试守卫(禁止 import 业务 workflow/状态机),以便未来改动不会重新引入反向依赖。
|
||||
3. 作为货代运营,我希望库存/收料/出货在代码、契约、目录中统一为 onhand/inbound/outbound,以便与调拨域及 WMS 术语一致。
|
||||
3. 作为货代运营,我希望库存/入站在代码、契约、目录中统一为 onhand/inbound,出站(outbound)仅用于在途调拨语境,以便与调拨域一致;发货履约「出货」不并入 outbound。
|
||||
4. 作为货代运营,我希望收料工作台、文件下载等既有功能仅更名不变行为,以便操作习惯零变化。
|
||||
5. 作为 RPA 管理员,我希望 RPA Profile/站点配置的管理入口迁移到 `/api/admin/freight-rpa/*`,以便配置归属清晰。
|
||||
6. 作为 RPA 管理员,我希望 Worker 心跳与离线企微告警行为不变,以便监控不中断。
|
||||
@@ -31,7 +31,7 @@ Freight RPA(货代 RPA)的后端编排层寄生在 shipping_notice 业务包
|
||||
17. 作为前端用户,我希望管理页(库存/入站数据域配置页)与用户端的路由、模块名、权限键全部使用新术语且存量权限数据随迁移,以便权限分配与新结构一致(Q14 最终拍板:随批次 S 改)。
|
||||
18. 作为未来开发者(含 AI 助手),我希望权威文档(shipping-notice technical、freight_rpa README、GLOSSARY、funclist/demand/tec、环境变量规则)全部使用新术语,以便按文档写出的代码就是对的。
|
||||
19. 作为未来开发者,我希望历史 spec/plan/ADR 不被改写,以便保留当时的决策快照。
|
||||
20. 作为货代运营,我希望 outbound 仅作结构预留(解析 purpose 枚举、目录分层),以便未来出站抓取链路接入时零术语迁移。
|
||||
20. 作为货代运营,我希望 outbound 仅作**在途调拨出站**结构预留(解析 purpose 枚举、目录分层),以便未来调拨出站抓取接入时零术语迁移;不与发货履约出货混名。
|
||||
21. 作为系统,我希望 trigger schema 升级为 `freight_rpa.onhand.v1`/`freight_rpa.inbound.v1` 且切换时在途文件排空,以便新旧契约不混挂。
|
||||
22. 作为合同付款用户,我希望「发货款」付款节点(shipment)完全不受影响,以便无关业务零风险。
|
||||
23. 作为平台开发者,我希望错误码族(errors.json 四语言 73+ 个含 INVENTORY 键 + 后端定义与抛点)同批更名,以便错误契约与术语一致。
|
||||
@@ -62,16 +62,17 @@ Freight RPA(货代 RPA)的后端编排层寄生在 shipping_notice 业务包
|
||||
- 存量枚举值数据迁移(无兼容层):审计事件名、step_key、step_payload_json/ui_state 动作值(约 40 个前后端契约值)、attempt 行;UPDATE 分批防长锁;迁移前全库备份;全部带可执行 downgrade。
|
||||
- 完整清单(含配置 yaml、options_source 注册键、导入脚本、权限键与存量权限数据、文件名模板、已核实无风险项)以评估文档 §8 为权威,spec 不重复罗列。
|
||||
|
||||
**术语面(批次 S/T/D)**
|
||||
**术语面(批次 S/D;原 T 已废除)**
|
||||
|
||||
- shipping_notice 域代码、前端目录/文件/组件/路由名、i18n(636 个 inventory 键 + receipt/shipment 键,四语言)、错误码族、权威文档:inventory→onhand、receipt→inbound;shipment→outbound(批次 T,排除 contract_payment);`movement` 一词保留(10-15 已拍板);中文文案基线:onhand=库存、inbound=入站、outbound=出站,指货代原始单据可保留「收料报表」称谓。
|
||||
- 历史 `docs/superpowers/`、ADR、归档文档不改写。
|
||||
- **admin 配置域随批次 S 改(Q14 最终拍板 + Q13b 层级修订:货代管理 = onhand/inbound/outbound 三子域)**:数据域管理路由统一命名空间 `/api/admin/freight-rpa/`,其下按子域区分——共享资源 `/freight-rpa/sources`(站点,三子域共用)与 `/freight-rpa/rpa-profiles`(凭据,批次 R 已定);onhand 子域 `/freight-rpa/onhand/{fields,structure-analyses,validation-batches,snapshots,export-records}`;inbound 子域挂站点 `/freight-rpa/sources/<id>/inbound-report-config`(词根区分子域);outbound 同级预留(本期无路由)。temporary-inventory-sessions 归发货业务侧,留 `/shipping-notice/` 前缀只改词根。前端 `features/admin/modules/shipping-inventory/`→`freight-rpa/`(FreightRpaPage)、路由 name `AdminFreightRpa`、权限模块键 `shipping_inventory`→`freight_rpa`(存量角色权限记录随迁移 UPDATE,防管理员丢页面)、导航文案「货代管理」、admin.json `shippingInventory.*` 键名段随改(四语言)。
|
||||
- shipping_notice 域代码、前端目录/文件/组件/路由名、i18n(inventory/receipt 键,四语言)、错误码族、权威文档:inventory→onhand、receipt→inbound;**不做** shipment→outbound。履约侧 `shipment_*`(出货 Excel 等)保留在 shipping_notice;合同付款 `shipment`(发货款)永远排除。`movement` 一词保留(10-15 已拍板)。中文文案基线:onhand=库存、inbound=入站、outbound=出站(**仅调拨**);货代履约称「出货」。
|
||||
- upload action:应对齐心跳能力 `freight_upload`(批次 R 误用 `outbound_upload` 须在后续提交改回)。
|
||||
- 历史归档快照不整篇改写;**本文件与 evaluation / GLOSSARY / 批次 R 计划**作为现行权威已就地纠偏。
|
||||
- **admin 配置域随批次 S 改(Q14 + Q13b:货代管理 = onhand/inbound/outbound 三子域)**:outbound 子域预留指**调拨出站配置/抓取**,不是发货履约。路由统一 `/api/admin/freight-rpa/`——共享 `sources`/`rpa-profiles`,onhand `onhand/{...}`,inbound 挂站点 `sources/<id>/inbound-report-config`,outbound 同级预留(本期无路由)。temporary-inventory-sessions 归发货业务侧,留 `/shipping-notice/` 只改词根。前端模块→`freight-rpa/`、权限键→`freight_rpa`,存量权限数据随迁移 UPDATE。
|
||||
|
||||
**发布协议(单窗口)**
|
||||
|
||||
- 四批同一发布窗口;窗口纪律:暂停三个 RPA 排程 + 禁止手动 RPA 触发 + 确认 Worker 空闲 + trigger/drop 排空 + 备好回滚单元;全部迁移带 downgrade 且 test 环境预演 upgrade→冒烟→downgrade→upgrade。
|
||||
- 分支:先提交 10-15 在途交付,从 `dev` 切单一 feature 分支承载四批。
|
||||
- 批次 **R+S+D** 同一发布窗口(T 已取消独立改名批);窗口纪律:暂停三个 RPA 排程 + 禁止手动 RPA 触发 + 确认 Worker 空闲 + trigger/drop 排空 + 备好回滚单元;全部迁移带 downgrade 且 test 环境预演 upgrade→冒烟→downgrade→upgrade。
|
||||
- 分支:从含在途交付的基线切 feature 分支承载 R→S→D。
|
||||
|
||||
## 4. 测试决策(Testing Decisions)
|
||||
|
||||
@@ -92,14 +93,15 @@ Freight RPA(货代 RPA)的后端编排层寄生在 shipping_notice 业务包
|
||||
## 5. 范围外(Out of Scope)
|
||||
|
||||
- 阶段 B:表所有权裁决、「文件就绪」事件化、回调事务边界重构、`ShippingInventorySource` 拆分(另立项另立 ADR)。
|
||||
- 出站抓取/归档/落档/匹配链路(仅结构就位);出站单位常量映射。
|
||||
- contract_payment 的 shipment(发货款)节点;`movement` 一词;`shipping` 模块名与前缀(admin 数据域路由前缀改 freight-onhand 除外,见 §3)。
|
||||
- 调拨出站抓取/归档/落档/匹配链路(outbound 仅结构就位);出站单位常量映射。
|
||||
- 发货履约 `generate_shipment_excel` / `shipment_qty` / `shipment_*.xlsx` **禁止**改名为 outbound_*(原批次 T 已废除)。
|
||||
- contract_payment 的 shipment(发货款)节点;`movement` 一词;`shipping` 模块名与前缀。
|
||||
- MinIO 历史 storage_key、历史迁移文件、`docs/superpowers/` 与 ADR 归档、运行日志。
|
||||
- 10-15 spec §9 遗留未做项(一键新版本/改绑引导等)继续搁置。
|
||||
|
||||
## 6. 补充说明(Further Notes)
|
||||
|
||||
- 实施顺序 R→S→T→D,同一发布窗口上线(ADR 0003);批次间的内部阻塞边在 to-tickets 阶段声明。
|
||||
- 实施顺序 **R→S→D**(原 T 已废除),同一发布窗口上线(ADR 0003);批次间的内部阻塞边在 to-tickets 阶段声明。
|
||||
- 影响面量化(~700 文件/2 万次、41 条路由、636 i18n 键、73+ 错误码键)见评估文档 §4/§8,本 spec 不重复。
|
||||
- 术语冲突裁决权:本 spec + GLOSSARY 为准;与旧文档冲突处按 D6「历史不改写、权威必改」处理。
|
||||
- 验收总门禁:grep 白名单外清零(白名单 = contract_payment、历史文档)+ 后端 463 基线 + 前端 vitest/build + 四语言键集护栏 + test 预演通过 + 生产窗口冒烟清单全绿。
|
||||
@@ -0,0 +1,143 @@
|
||||
# Freight RPA 阶段 B — 报表归属与业务解耦设计
|
||||
|
||||
日期:2026-10-18 | 状态:**已有实施计划**(`docs/superpowers/plans/2026-10-18-freight-rpa-phase-b.md`)| 前置:`docs/superpowers/specs/2026-10-16-freight-rpa-decouple-and-rename-design.md`(阶段 A,批次 R/S/D)| 术语:`docs/features/freight-rpa/GLOSSARY.md` | 决策记录将另立 `docs/adr/0004-freight-rpa-report-ownership.md`
|
||||
|
||||
## 0. 问题
|
||||
|
||||
阶段 A 把编排、回调路由和 Worker 契约收进 `freight_rpa`。Windows Worker 是独立进程。后端仍是同一个 Flask 进程、同一套数据库。
|
||||
|
||||
还没解开的是写入权。回调转给发货通知之后,发货通知既落报表文件,又推进自己的门禁,并调用 `advance_source_job_from_inbound_callback` 修改在途调拨的 `TransferSourceJob`。在途调拨直接查询入站报表表。站点、报表配置、报表文件都是 RPA 的数据,发货代码仍在读写它们。
|
||||
|
||||
表名也还不对齐。管理端上,一个库存站点下面并列着「库存报表配置」和「收料报表配置」。收料配置已是独立表;在手报表的路径、查询条件和解析方案仍在站点行上。解析方案目录用 `purpose` 区分 onhand、inbound、outbound。未提交的批次 S 迁移目标名已改为 `freight_rpa_parsing_profiles`。入站原文件在 `freight_rpa_inbound_report_files`,在手文件仍叫 `shipping_onhand_files`。
|
||||
|
||||
## 1. 目标与非目标
|
||||
|
||||
**目标:** 在当前后端进程内,RPA 拥有登录连接、库存站点、报表配置和报表文件。发货通知和在途调拨只选用 `source_code`,只更新自己的任务。
|
||||
|
||||
报表记录是货代系统导出、由 Worker 抓回的文件:
|
||||
|
||||
| 词 | 含义 |
|
||||
| --- | --- |
|
||||
| onhand | 在手库存报表 |
|
||||
| inbound | 入站报表(界面称收料报表) |
|
||||
| outbound | 出站报表 |
|
||||
|
||||
履约出货是发货通知自己的出货 Excel 和上传,代码继续用 `shipment_*` 与 `freight_upload`。它不是 outbound。本阶段不改这条链路。
|
||||
|
||||
**非目标:**
|
||||
|
||||
- 不把 `freight_rpa` 拆成第二个可部署服务,不引入消息队列。
|
||||
- 不新做出站抓取。出站配置和出站文件表等出站立项再加,命名与在手、入站相同。
|
||||
- 不把履约出货改名为 outbound,不改 `freight_upload`。
|
||||
- 不改合同付款的 `shipment`(发货款),不改 `movement`,不改历史 MinIO 对象键。
|
||||
- 不改写已有的阶段 A 计划与 spec。
|
||||
- 不改这些仍只服务在手的表:`freight_rpa_onhand_fields`(在手字段目录;入站解析用固定领域字段)、外部仓库映射、发货路由规则、配置测试。不改它们的表名和归属。
|
||||
- 不把在手文件表里的解析行、字段映射、快照状态拆到另一张表。入站文件表只存原文件,两张表的列保持不同。
|
||||
|
||||
## 2. 目标结构
|
||||
|
||||
一个库存站点先存在。在手报表配置和入站报表配置都挂在这个站点上,各最多一行。登录连接是站点引用的另一张表。
|
||||
|
||||
| 目标表 | 现在的表 | 内容 |
|
||||
| --- | --- | --- |
|
||||
| `freight_rpa_profiles` | 同名(旧 `shipping_rpa_profiles`) | 登录连接:地址、账号、密码。界面「连接配置」 |
|
||||
| `freight_rpa_sources` | 同名(旧 `shipping_inventory_sources`) | 库存站点。留下 `source_code`、`display_name`、`connector_type`、`rpa_profile_id`、`excel_template_id`、`warehouse_resolution_mode`、`fixed_warehouse_id`、`enabled`、`snapshot_ttl_seconds`、`config_version`。不再放报表路径、查询条件和解析方案 |
|
||||
| `freight_rpa_onhand_report_configs` | 无。三列现在在站点行上 | 在手报表配置:路径、查询条件、解析方案。一个站点一行 |
|
||||
| `freight_rpa_inbound_report_configs` | 同名(旧 `shipping_receipt_report_configs`) | 入站报表配置。一个站点一行。本阶段不改结构 |
|
||||
| `freight_rpa_parsing_profiles` | `shipping_inventory_parsing_profiles` | 解析方案目录。`purpose` 区分 onhand / inbound / outbound。批次 S 未执行的迁移直接改到这个表名。模型类为 `ShippingParsingProfile` |
|
||||
| `freight_rpa_onhand_report_files` | `shipping_onhand_files` | 在手报表文件。只改表名,列保留 |
|
||||
| `freight_rpa_inbound_report_files` | 同名 | 入站报表原文件。本阶段不改结构 |
|
||||
|
||||
发货通知的候选集、行匹配、核验,以及在途调拨的 `TransferSourceJob`,仍由各自的领域写入。
|
||||
|
||||
站点要启用,必须已有在手报表配置且其中有解析方案,并且站点上已选发货模板。这是现有约束换了检查位置,不是新规则。
|
||||
|
||||
## 3. 谁写入
|
||||
|
||||
RPA 写入并更新:登录连接、站点、在手配置、入站配置、解析方案、在手报表文件、入站报表文件及其单元和投递记录。
|
||||
|
||||
发货通知和在途调拨不插入、不更新这些表。它们需要数据时调用 RPA 的只读函数:
|
||||
|
||||
- 按 `source_code` 读取站点,以及在手或入站配置里抓取要用的字段
|
||||
- 按 `source_code` 取最新一份可用入站报表(文件号、哈希、创建时间、下载标识)
|
||||
- 按 `file_id` 读取报表内容或受控下载信息
|
||||
|
||||
触发抓取仍由业务方调用 `freight_rpa` 的 trigger 写入函数。RPA 不调用业务包来决定要不要抓。
|
||||
|
||||
## 4. 回调
|
||||
|
||||
Worker 回调仍进入 `/api/freight-rpa/*`。RPA 在自己的事务里校验载荷、按对应报表配置落文件、写抓取尝试,然后提交。提交成功后,在同一次请求里调用使用方注册的处理函数。事实为:
|
||||
|
||||
- `report_kind`:`onhand`、`inbound`、`outbound`。与解析方案的 `purpose` 同一套取值。本阶段实际送达的是 `onhand` 和 `inbound`;`outbound` 留给出站抓取,事实形状不再另改
|
||||
- `source_code`、`file_id`、`sha256`
|
||||
- `ok`,失败时还有 `error_code`、`error_message`
|
||||
|
||||
RPA 不 import 发货工作流,不写 `TransferSourceJob`、发货门禁或排程终态。
|
||||
|
||||
- 发货通知用 onhand 事实更新自己的快照、候选和门禁。
|
||||
- 在途调拨用 inbound 事实把仍处于 `waiting_rpa_callback` 的 `TransferSourceJob` 推进到 `file_ready` 或 `failed`。没有等待中的任务时不改行。
|
||||
|
||||
处理函数必须能重复执行。同一 `file_id` 再次送达时不重复插入报表,也不重复推进已经离开等待态的任务。处理函数抛错时,回调对 Worker 返回错误,已提交的文件不回滚,Worker 按现有机制重试。
|
||||
|
||||
`register_sink` 仍是注册点。注册的函数只更新使用方自己的状态。报表归档审计记在 RPA 自己的审计事件上,`freight_rpa` 不再 import `shipping_notice.audit_service`。
|
||||
|
||||
```text
|
||||
Worker 回调
|
||||
→ freight_rpa 校验、落报表、提交
|
||||
→ 同请求调用处理函数(报表事实)
|
||||
→ 发货通知更新自己的快照/门禁
|
||||
→ 在途调拨更新自己的 TransferSourceJob
|
||||
→ 处理函数失败:HTTP 错误,文件保留,Worker 重试
|
||||
```
|
||||
|
||||
在途调拨匹配:
|
||||
|
||||
```text
|
||||
matching_service
|
||||
→ freight_rpa 只读查询(source_code) → 最新可用 inbound 报表
|
||||
→ 按 file_id 读取内容
|
||||
```
|
||||
|
||||
## 5. 错误处理
|
||||
|
||||
| 情况 | 行为 |
|
||||
| --- | --- |
|
||||
| 载荷非法、站点不存在、对应报表配置不存在 | 不落文件,回调 4xx,不调用处理函数 |
|
||||
| 落文件失败 | 事务回滚,回调 5xx,Worker 重试 |
|
||||
| 文件已提交,处理函数失败 | 文件保留,回调 5xx,Worker 重试 |
|
||||
| 没有等待中的调拨任务 | 调拨处理函数成功返回,不改行 |
|
||||
| 未注册处理函数 | `FREIGHT_RPA.SINK_NOT_REGISTERED`,不静默丢弃 |
|
||||
|
||||
## 6. 迁移
|
||||
|
||||
一次迁移完成三件事,并带可执行 downgrade:
|
||||
|
||||
1. 新建 `freight_rpa_onhand_report_configs`,把站点行上的 `report_path_json`、`query_parameters_json`、`parsing_profile_id` 拷入后从站点行删除。`source_code` 不变。
|
||||
2. 解析方案目录的最终表名是 `freight_rpa_parsing_profiles`。批次 S 尚未提交、也尚未在任何环境执行 upgrade,因此改的是批次 S 那次迁移的目标名,而不是在它之后再写一条改名迁移。行和 `purpose` 不改。
|
||||
3. `shipping_onhand_files` 改名为 `freight_rpa_onhand_report_files`。列不改。
|
||||
|
||||
downgrade 按相反顺序把表名和三列搬回。
|
||||
|
||||
## 7. 测试
|
||||
|
||||
1. 未注册调拨处理函数时,报表行已存在,`TransferSourceJob` 仍停在 `waiting_rpa_callback`。
|
||||
2. 同一回调投递两次,报表不重复,调拨任务不重复推进。
|
||||
3. 处理函数第一次失败、第二次成功:报表仍是一行,任务最终为 `file_ready`。
|
||||
4. 在途调拨通过只读函数取到文件。`in_transit_transfer` 与 `shipping_notice` 不再 import 这些报表和配置模型做查询。
|
||||
5. upgrade 后三列在 `freight_rpa_onhand_report_configs`,解析方案表名为 `freight_rpa_parsing_profiles`,在手文件表名为 `freight_rpa_onhand_report_files` 且列还在。downgrade 后在手配置三列回到站点行,在手文件表名回到 `shipping_onhand_files`,解析方案表名回到 `shipping_inventory_parsing_profiles`。库上不会出现 `freight_rpa_onhand_parsing_profiles`。
|
||||
6. 缺少在手解析方案或发货模板时,站点不能启用。
|
||||
7. `freight_rpa` 不 import `shipping_notice` 或 `in_transit_transfer` 的工作流、状态机和任务推进函数。
|
||||
|
||||
## 8. 验收
|
||||
|
||||
- 在手配置与入站配置都是站点下的一对一表,登录连接、站点、解析方案目录、两类报表文件的表名与第 2 节一致,归属 RPA。
|
||||
- 发货通知和在途调拨只通过 `source_code` 和只读函数使用它们,并只写自己的任务。
|
||||
- 回调落文件不依赖处理函数成功。
|
||||
- 履约出货与 `freight_upload` 的行为不变。
|
||||
- 迁移可 downgrade。ADR 0004 记录上述归属。GLOSSARY 中的站点不再写「归属 shipping_notice」。
|
||||
|
||||
## 9. 实施顺序
|
||||
|
||||
批次 S、D 的现有改动先不提交。解析方案目录的最终表名改在这批未执行的迁移里,随批次 S 第一次 upgrade 生效。批次 T 已废除,不涉及这张表。
|
||||
|
||||
在手配置新表、在手文件改名、回调拆开仍属阶段 B,设计评审通过后再写实施计划,顺序为:这两项迁移 → 只读查询与 import 边界 → 回调事实与幂等处理函数 → ADR 0004 与 GLOSSARY。阶段 B 的代码改在当前未提交的批次 S/D 工作区上继续,不另起一份已包含错误表名的提交。
|
||||
@@ -0,0 +1,107 @@
|
||||
# 货代 RPA 类名前缀与上传动作改名
|
||||
|
||||
日期:2026-10-19 | 状态:**已有实施计划** | 实施计划:docs/superpowers/plans/2026-10-19-freight-rpa-class-prefix.md | 做法:A(类名与 Worker 动作分开改,发货流程用词不动)
|
||||
|
||||
本规格覆盖两处旧约束,只覆盖写明的那一层:
|
||||
|
||||
- 2026-10-17《upload action 纠偏》否决 `freight_rpa_upload`。本规格改回这个动作名,只用于 Worker 心跳能力和 trigger 的 `action`。
|
||||
- 阶段 B 规格「不改 `freight_upload`」对上述动作名与心跳能力不再有效。发货阶段名、门禁码、界面文案仍遵守那一句。
|
||||
|
||||
## 1. 问题
|
||||
|
||||
表名已经是 `freight_rpa_*`,Python 类仍以 `Shipping` 开头。入站报表、在手报表和站点不属于发货通知。`ShippingInboundReportFile` 这类名字会让调用方以为行归发货通知。
|
||||
|
||||
上传已经由 `app.services.freight_rpa.upload` 执行。trigger 的 `action` 和心跳能力仍是 `freight_upload`。这个短名和发货单阶段 `freight_upload` 撞车。
|
||||
|
||||
## 2. 目标与非目标
|
||||
|
||||
**目标:**
|
||||
|
||||
- `__tablename__` 以 `freight_rpa_` 开头的模型类,类名以 `FreightRpa` 开头。
|
||||
- 类名里不再出现连续的 `RpaRpa`。`ShippingInboundRpaUnitRun` 改为 `FreightRpaInboundUnitRun`,`ShippingTaskOnhandRpaAttempt` 改为 `FreightRpaOnhandTaskAttempt`。
|
||||
- 站点类改为 `FreightRpaSource`。表 `freight_rpa_sources` 同时服务在手和入站。
|
||||
- Worker 心跳能力与 trigger `action` 改为 `freight_rpa_upload`。schema 保持 `freight_rpa.upload.v1`。
|
||||
- 不保留旧类名、旧模块路径、旧动作名的别名。后端与 Windows Worker 同一次发布。
|
||||
|
||||
**非目标:**
|
||||
|
||||
- 不改任何表名、索引名、约束名、外键名。包括仍带重复 `rpa` 的 `freight_rpa_inbound_rpa_unit_runs` 与 `freight_rpa_onhand_task_rpa_attempts`。因此本规格不新增 Alembic 迁移。
|
||||
- 不改发货阶段 `freight_upload`、`freight_uploading`,不改门禁码 `freight_upload_rpa`,不改动作码 `retry_freight_upload_rpa`、`poll_freight_upload_rpa`、`trigger_freight_upload_rpa`,不改四语言文案。
|
||||
- 不改 `ShippingUploadAttempt` 与表 `shipping_notice_upload_attempts`。
|
||||
- 不改发货自己的类:`ShippingNotice`、`ShippingTaskOnhandLink`、候选集、准备轮次、行匹配、在手核销、`ShippingFreightCancellation`、`ShippingExcelTemplate`。
|
||||
- 不把履约出货改名为 outbound,不改 `shipment_*`。
|
||||
- 不改环境变量 `FREIGHT_RPA_UPLOAD_*`,不改上传回调路径,不改 MinIO 键。
|
||||
- 不改写已有的阶段 A、阶段 B、2026-10-17 计划正文。
|
||||
|
||||
## 3. 类与文件
|
||||
|
||||
下表每一行都改类名,并改全部 import、类型注解、`relationship` 字符串和 `models/__init__.py` 导出。不留 `Shipping*` 别名。
|
||||
|
||||
| 现类名 | 新类名 | 表名(不变) | 现文件 → 新文件 |
|
||||
| --- | --- | --- | --- |
|
||||
| `ShippingOnhandField` | `FreightRpaOnhandField` | `freight_rpa_onhand_fields` | `shipping_onhand_config.py` → `freight_rpa_config.py` |
|
||||
| `ShippingRpaProfile` | `FreightRpaProfile` | `freight_rpa_profiles` | 同上 |
|
||||
| `ShippingOnhandSource` | `FreightRpaSource` | `freight_rpa_sources` | 同上 |
|
||||
| `ShippingOnhandReportConfig` | `FreightRpaOnhandReportConfig` | `freight_rpa_onhand_report_configs` | 同上 |
|
||||
| `ShippingOnhandSourceParsingBindingAudit` | `FreightRpaSourceParsingBindingAudit` | `freight_rpa_onhand_source_parsing_binding_audits` | 同上 |
|
||||
| `ShippingParsingProfile` | `FreightRpaParsingProfile` | `freight_rpa_parsing_profiles` | 同上 |
|
||||
| `ShippingOnhandStructureAnalysis` | `FreightRpaOnhandStructureAnalysis` | `freight_rpa_onhand_structure_analyses` | 同上 |
|
||||
| `ShippingOnhandConfigurationTestRun` | `FreightRpaOnhandConfigurationTestRun` | `freight_rpa_onhand_configuration_test_runs` | 同上 |
|
||||
| `ShippingOnhandValidationBatch` | `FreightRpaOnhandValidationBatch` | `freight_rpa_onhand_validation_batches` | 同上 |
|
||||
| `ShippingOnhandRoutingRule` | `FreightRpaOnhandRoutingRule` | `freight_rpa_onhand_routing_rules` | 同上 |
|
||||
| `ShippingOnhandRoutingRuleCondition` | `FreightRpaOnhandRoutingRuleCondition` | `freight_rpa_onhand_routing_rule_conditions` | 同上 |
|
||||
| `ShippingOnhandRoutingRuleVersion` | `FreightRpaOnhandRoutingRuleVersion` | `freight_rpa_onhand_routing_rule_versions` | 同上 |
|
||||
| `ShippingOnhandExternalMapping` | `FreightRpaOnhandExternalMapping` | `freight_rpa_onhand_external_mappings` | 同上 |
|
||||
| `ShippingInboundReportConfig` | `FreightRpaInboundReportConfig` | `freight_rpa_inbound_report_configs` | `shipping_inbound_report.py` → `freight_rpa_inbound_report.py` |
|
||||
| `ShippingInboundRpaUnitRun` | `FreightRpaInboundUnitRun` | `freight_rpa_inbound_rpa_unit_runs` | 同上 |
|
||||
| `ShippingInboundReportFile` | `FreightRpaInboundReportFile` | `freight_rpa_inbound_report_files` | 同上 |
|
||||
| `ShippingInboundNotificationDelivery` | `FreightRpaInboundNotificationDelivery` | `freight_rpa_inbound_notification_deliveries` | 同上 |
|
||||
| `ShippingOnhandMapping` | `FreightRpaOnhandMapping` | `freight_rpa_onhand_mappings` | `shipping_onhand_mapping.py` → `freight_rpa_onhand_mapping.py` |
|
||||
| `ShippingTaskOnhandRpaAttempt` | `FreightRpaOnhandTaskAttempt` | `freight_rpa_onhand_task_rpa_attempts` | `shipping_onhand_task_rpa_attempts.py` → `freight_rpa_onhand_task_attempts.py` |
|
||||
| `ShippingOnhandFile` | `FreightRpaOnhandReportFile` | `freight_rpa_onhand_report_files` | 从 `shipping.py` 拆到 `freight_rpa_onhand_report_file.py` |
|
||||
|
||||
`shipping.py` 改完后只保留发货通知、任务事件、清除审计、任务与在手文件关联,以及订单接入相关类。
|
||||
|
||||
这些类上仍指向站点、且名字还是 inventory / receipt 的关系属性一并改名。索引名不动。
|
||||
|
||||
| 现属性 | 新属性 | 所在类(用新类名) |
|
||||
| --- | --- | --- |
|
||||
| `inventory_source` | `source` | `FreightRpaOnhandReportConfig`、`FreightRpaOnhandExternalMapping`、`FreightRpaInboundReportConfig`、`FreightRpaInboundUnitRun` |
|
||||
| `receipt_report_config` | `inbound_report_config` | `FreightRpaSource` |
|
||||
|
||||
`onhand_report_config`、`external_mappings`、`rpa_profile`、`parsing_profile` 保持原属性名。
|
||||
|
||||
## 4. 上传动作
|
||||
|
||||
只改下面三个字面量,从 `freight_upload` 改为 `freight_rpa_upload`:
|
||||
|
||||
- `app.services.freight_rpa.common.worker_heartbeat.FREIGHT_UPLOAD_CAPABILITY`。常量改名为 `FREIGHT_RPA_UPLOAD_CAPABILITY`。
|
||||
- `app.services.freight_rpa.upload.trigger_io.ACTION_FREIGHT_UPLOAD`。常量改名为 `ACTION_FREIGHT_RPA_UPLOAD`。写入 trigger 的 `action` 使用该常量。
|
||||
- `scripts/freight_rpa/common/rpa_heartbeat.py` 在开启上传时追加的能力字符串。
|
||||
|
||||
`trigger_io.SCHEMA` 保持 `freight_rpa.upload.v1`。
|
||||
|
||||
就绪检查函数名保持 `check_freight_upload_rpa_ready` 与 `assert_freight_upload_rpa_ready`。它们检查的是发货门禁能否放行,函数名继续带门禁码;函数内部改读 `FREIGHT_RPA_UPLOAD_CAPABILITY`。
|
||||
|
||||
已落在共享目录、`action` 仍为 `freight_upload` 的 trigger 不改写、不双读。发布前清空 upload 的 triggers 与 queue。发布后 Worker 只声明并处理 `freight_rpa_upload`。
|
||||
|
||||
## 5. 错误处理
|
||||
|
||||
旧类名 import 直接失败,不提供兼容导出。
|
||||
|
||||
旧动作名不映射到新动作名。心跳里没有 `freight_rpa_upload` 时,现有就绪检查仍按缺少上传能力阻断自动上传,原因码改为 `missing_freight_rpa_upload_capability`。不保留 `missing_freight_upload_capability`。
|
||||
|
||||
## 6. 文档
|
||||
|
||||
实现时改这些现行文档,不改历史计划正文:
|
||||
|
||||
- `docs/features/freight-rpa/GLOSSARY.md` 的 Upload 条:action 与心跳能力写 `freight_rpa_upload`。
|
||||
- `docs/features/freight-rpa/cutover-runbook.md` 里把「`freight_upload` 不变」改成新动作名,并写上发布前清空 upload triggers/queue。
|
||||
|
||||
## 7. 测试
|
||||
|
||||
- `tests/services/freight_rpa/test_upload_trigger_contract.py`:`action`、心跳能力等于 `freight_rpa_upload`,schema 仍为 `freight_rpa.upload.v1`,且两者相等。
|
||||
- 心跳就绪测试:缺少 `freight_rpa_upload` 时原因含 `missing_freight_rpa_upload_capability`。
|
||||
- 在 `backend/app` 与 `scripts/freight_rpa` 中检索旧类名,结果为空。
|
||||
- 在 `trigger_io.py`、`app/services/freight_rpa/common/worker_heartbeat.py`、`scripts/freight_rpa/common/rpa_heartbeat.py` 中,动作与能力字面量 `"freight_upload"`、旧常量名 `FREIGHT_UPLOAD_CAPABILITY` 与 `ACTION_FREIGHT_UPLOAD` 结果为空。函数名 `check_freight_upload_rpa_ready`、`assert_freight_upload_rpa_ready` 保留。发货阶段与门禁文件里的 `freight_upload` 允许留下。
|
||||
- 不新增迁移测试。
|
||||
Reference in new issue
Block a user