Files
syops/docs/superpowers/plans/2026-10-17-freight-rpa-decouple-batch-s.md
T
hugoandCursor 39fe3c05f2 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>
2026-10-19 10:46:06 +08:00

202 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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`