feat(freight-rpa): 增加出站报表配置与回调支持,重构相关服务

- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。
- 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。
- 更新 ORM 模型,增加出站报表相关的持久化模型。
- 统一命名规范,确保在手、入站与出站的概念一致性。
This commit is contained in:
hugo committed 2026-10-19 18:45:16 +08:00
1 parent 39fe3c05f2
commit 911afa0f73
152 files changed
+9861 -2984

No files matched your search

@@ -0,0 +1,737 @@
# 货代 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:** 管理端改名为「报表规则 / 来源站点 / 入站报表」,交付与入站同构的出站 RPA 全栈,并拆除入站 deliveries 与工作台收料文件页。
**Architecture:** 做法 A——按入站包逐文件克隆出站(models / trigger_io / report_archive / schedule job / Worker / 调拨 trigger / sink),不先做泛化层。改名与入站瘦身穿插在前序任务,降低出站联调噪声。`purpose=outbound` 校验改走 `MOVEMENT_FIELDS`。通知只走排程 `notify_user_ids`。
**Tech Stack:** Flask、SQLAlchemy 2.0、Alembic、Vue 3、pytest、Playwright Worker(Python)。后端测试工作目录 `backend/`;Windows 上 Python 用 `backend/.venv/Scripts/python.exe`(若无则用已激活的 venv)。
**Spec:** `docs/superpowers/specs/2026-10-19-freight-rpa-outbound-and-rename-design.md`
## Global Constraints
- 入口文案:`库存解析` → **报表规则**;`库存站点` → **来源站点**;`收料报表配置` → **入站报表配置**。父级「库存管理」、库存字段目录不改。
- 出站类名一律 `FreightRpaOutbound*`;假定 class-prefix 已合入(`FreightRpaSource` 等)。禁止引入 `Shipping*Outbound*`。
- 出站新建三表:`freight_rpa_outbound_report_configs` / `freight_rpa_outbound_rpa_unit_runs` / `freight_rpa_outbound_report_files`。**禁止**建 `*_notification_deliveries`。
- 删除 `freight_rpa_inbound_notification_deliveries` 及 resend / 工作台收料页 / `inbound_report_access`。
- `receipt-raw-zip` → `inbound-raw-zip`(路径与深链参数),无兼容别名。
- 出站配置非启用硬门槛;触发时站点停用/缺配置 fail-closed。
- `purpose=outbound` 与 inbound 同异动契约;旧 onhand 形态 outbound 草稿不自动迁移。
- RPA 层不强制 `in_out_flag`;方向过滤留在调拨域。
- 不改履约出货 / upload;不新建工作台出站文件页。
- 四语言 i18n 同步;错误码新增须写 `locales/*/errors.json`。
- 改函数签名或模块协作时同步文件头与函数注释(AGENTS.md §5)。
- 禁止 `git add -A` / `git commit`;每任务只 stage 该任务列出的路径。工作区可能已有未提交的其它批次,勿混入。
- **跨机路径(硬约束)**:出站回调 `file_path` 只按「outbound drop 根内文件名」解析。后端必须 `replace('\\','/')` 后取 `.name`,再拼 `FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR`,`relative_to(root)` 防穿越。禁止把 Windows 绝对路径当 Linux 路径打开。对照入站 `_read_inbound_callback_file` 与在手 `resolve_shared_inventory_drop_file`。Worker 侧优先只上报文件名。必须有带 `C:\\...\\foo.xlsx` 的回归测。
## 文件地图
| 文件 / 目录 | 职责 |
| --- | --- |
| `frontend/src/locales/{zh-CN,zh-TW,en,th}/admin.json` 等 | 报表规则 / 来源站点 / 入站·出站报表文案 |
| `frontend/src/features/admin/modules/freight-rpa/*` | 来源站点三块配置、报表规则 purpose=outbound UI |
| `frontend/src/features/workspace/**`(收料页相关) | 删除 |
| `backend/app/models/freight_rpa_outbound_report.py` | 出站三模型(新建) |
| `backend/app/models/freight_rpa_inbound_report.py` | 去掉 NotificationDelivery |
| `backend/migrations/versions/*_freight_rpa_outbound_and_inbound_slim.py` | 出站建表 + drop deliveries |
| `backend/app/services/shipping_notice/onhand_parsing_profile.py` | outbound → 异动校验 |
| `backend/app/services/admin/shipping_onhand_admin_service.py` | `get_/save_inbound_*` + `get_/save_outbound_*` |
| `backend/app/services/freight_rpa/outbound/*` | trigger_io、report_archive |
| `backend/app/services/schedule/freight_rpa_outbound_*.py` | job / finalize / archive / retention |
| `backend/app/api/freight_rpa.py` | outbound 回调路由 |
| `backend/app/api/schedule/runs.py` | inbound-raw-zip、outbound-raw-zip、outbound units |
| `backend/app/services/in_transit_transfer/outbound_trigger_service.py` | 按需触发 |
| `backend/app/services/in_transit_transfer/outbound_report_handler.py` | sink handler |
| `backend/app/services/shipping_notice/rpa_sinks.py` | `register_outbound_sinks` |
| `scripts/freight_rpa/outbound/*` | Worker / ps1 / 驱动 |
| `docs/features/freight-rpa/GLOSSARY.md` 等 | 术语与运维文档 |
---
### Task 1: 管理端改名(报表规则 / 来源站点 / 入站报表)
**Files:**
- Modify: `frontend/src/locales/zh-CN/admin.json`
- Modify: `frontend/src/locales/zh-TW/admin.json`
- Modify: `frontend/src/locales/en/admin.json`
- Modify: `frontend/src/locales/th/admin.json`
- Modify: `frontend/src/features/admin/shippingConfigNavigation.spec.ts`(若断言旧文案)
- Modify: `frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue`(仅当硬编码「收料」时)
- Modify: `frontend/src/features/admin/modules/freight-rpa/receiptReportConfigForm.ts` → 重命名文件为 `inboundReportConfigForm.ts`,并改导出函数名
- Modify: 所有 import 上述 form 的文件(`FreightRpaPage.vue`、`*.spec.ts`)
- Test: `frontend/src/features/admin/modules/freight-rpa/receiptReportConfigForm.spec.ts` → `inboundReportConfigForm.spec.ts`
**Interfaces:**
- Consumes: 现有 i18n 键 `admin.freightRpa.parsingProfiles`、`sources`、`receiptReportConfig*`
- Produces: 用户可见字符串变更;键名可将 `receiptReportConfig` 改为 `inboundReportConfig`(四语言同步改键,调用处同步);`buildInboundReportConfigPayload` 替代 `buildReceiptReportConfigPayload`
- [ ] **Step 1: 写失败的导航/文案断言(若已有 spec 则改期望)**
在 `shippingConfigNavigation.spec.ts` 或新建窄测中断言 labelKey 对应文案解析后为「报表规则」「来源站点」(用 i18n 或直接断言 key 不变、另测 locale 文件内容)。
最小 locale 断言脚本(Node,在 `frontend/`):
```js
const zh = require('./src/locales/zh-CN/admin.json');
if (zh.freightRpa.parsingProfiles !== '报表规则') throw new Error('parsingProfiles');
if (zh.freightRpa.sources !== '来源站点') throw new Error('sources');
if ((zh.freightRpa.inboundReportConfig || zh.freightRpa.receiptReportConfig) !== '入站报表配置') {
throw new Error('inboundReportConfig');
}
```
先跑应失败(当前为库存解析/库存站点/收料报表配置)。
- [ ] **Step 2: 改四语言文案与键**
zh-CN 最低改动示例:
```json
"parsingProfiles": "报表规则",
"parsingProfilesHelp": "维护可辨识的文件解析规则:库存面向字段目录与订单匹配,入站/出站面向标准异动字段(只读契约)。",
"sources": "来源站点",
"inventorySites": "来源站点",
"inboundReportConfig": "入站报表配置",
"inboundReportConfigHint": "与库存配置同构:报表路径 + 查询条件。查询条件可选,空则使用页面默认;排程按站点一对一导出。入站无独立开关,随站点统一启停。",
"outboundReportConfig": "出站报表配置",
"outboundReportConfigHint": "与入站配置同构:报表路径 + 查询条件;出站无独立开关,随站点统一启停。"
```
删除或停止使用 `receiptReportConfig*` 键。zh-TW / en / th 同步语义(en: Report Rules / Source Sites / Inbound Report Config / Outbound Report Config)。
同步 `parsingPurposeHint` 等仍写「仅入站」的句子,改为「入站/出站」。
- [ ] **Step 3: 重命名前端 form 模块**
`buildReceiptReportConfigPayload` → `buildInboundReportConfigPayload`;文件改名;`FreightRpaPage.vue` 中 `receiptConfig` 展示文案键改为 `inboundReportConfig*`(状态变量可暂留,Task 6/11 再统一)。
- [ ] **Step 4: 跑前端相关测试**
Run: `cd frontend && npx vitest run src/features/admin/modules/freight-rpa/inboundReportConfigForm.spec.ts src/features/admin/shippingConfigNavigation.spec.ts`
Expected: PASS
- [ ] **Step 5: Stage**
```bash
git add frontend/src/locales/zh-CN/admin.json frontend/src/locales/zh-TW/admin.json frontend/src/locales/en/admin.json frontend/src/locales/th/admin.json frontend/src/features/admin/modules/freight-rpa/inboundReportConfigForm.ts frontend/src/features/admin/modules/freight-rpa/inboundReportConfigForm.spec.ts frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue frontend/src/features/admin/shippingConfigNavigation.spec.ts
```
(含删除旧 `receiptReportConfigForm*` 的 staged deletion。)
---
### Task 2: 拆除入站 deliveries + 工作台收料页
**Files:**
- Modify: `backend/app/models/freight_rpa_inbound_report.py`(删 `FreightRpaInboundNotificationDelivery` 与 relationship)
- Modify: `backend/app/models/__init__.py`
- Modify: `backend/app/services/freight_rpa/inbound/report_archive.py`(删 `deliver_inbound_file`、`_recipient_ids` 及 WeCom 投递 import)
- Modify: `backend/app/api/schedule/runs.py`(删 resend 路由)
- Delete: `backend/app/services/shipping_notice/inbound_report_access.py`
- Modify: `backend/app/api/workspace/shipping_notice.py`(删 list/download inbound-report-files 两路由)
- Delete: `frontend/src/features/workspace/pages/InboundReportFilesPage.vue` 及其 `.spec.ts`
- Delete: `frontend/src/features/workspace/api/inbound-report.api.ts` 及其 `.spec.ts`(若仅服务该页)
- Modify: `frontend/src/app/router/routes/workspace.routes.ts`
- Modify: `frontend/src/features/workspace/components/WorkspaceSidebar.vue`
- Modify: `frontend/src/features/workspace/constants/routes.ts`
- Modify: `frontend/src/features/workspace/composables/useWorkspaceNavigation.ts`
- Modify: 四语言 `workspace` locale(去掉 `inboundReports` / nav 项)
- Delete or rewrite: `backend/tests/test_freight_receipt_rpa_notifications.py`、`test_freight_receipt_rpa_access.py`(去掉 deliveries/resend/workspace 断言)
- Create: `backend/migrations/versions/<rev>_drop_inbound_notification_deliveries.py`(可与 Task 4 合并为一迁移;若拆分则本任务只 drop)
- Test: 新建 `backend/tests/test_freight_rpa_inbound_slim_gate.py`
**Interfaces:**
- Consumes: 无
- Produces: 无 `FreightRpaInboundNotificationDelivery`;无 resend API;无 workspace 收料路由
- [ ] **Step 1: 写 grep gate 失败用例**
```python
# backend/tests/test_freight_rpa_inbound_slim_gate.py
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def test_no_inbound_notification_delivery_symbol():
hits = []
for path in (ROOT / "app").rglob("*.py"):
text = path.read_text(encoding="utf-8")
if "InboundNotificationDelivery" in text or "deliver_inbound_file" in text:
hits.append(str(path))
assert hits == []
def test_no_workspace_inbound_report_routes():
text = (ROOT / "app/api/workspace/shipping_notice.py").read_text(encoding="utf-8")
assert "inbound-report-files" not in text
```
Run: `pytest tests/test_freight_rpa_inbound_slim_gate.py -v`
Expected: FAIL
- [ ] **Step 2: 删模型、服务、API、前端页与测试中的引用**
按 Files 列表删除/改写。`report_archive.py` 文件头 docstring 去掉投递职责。迁移 `op.drop_table('freight_rpa_inbound_notification_deliveries')`(downgrade 可重建最小表结构或 `pass` 并在注释标明不可逆——推荐完整 rebuild 以便本地 downgrade)。
- [ ] **Step 3: 再跑 gate + 受影响测试**
Run: `pytest tests/test_freight_rpa_inbound_slim_gate.py tests/test_freight_receipt_rpa_notifications.py tests/test_freight_receipt_rpa_access.py -v`
Expected: gate PASS;旧测文件已删或改写后 PASS
- [ ] **Step 4: Stage 本任务路径**
```bash
git add backend/app/models/freight_rpa_inbound_report.py backend/app/models/__init__.py backend/app/services/freight_rpa/inbound/report_archive.py backend/app/api/schedule/runs.py backend/app/api/workspace/shipping_notice.py backend/migrations/versions/ backend/tests/test_freight_rpa_inbound_slim_gate.py frontend/src/app/router/routes/workspace.routes.ts frontend/src/features/workspace/
```
---
### Task 3: `receipt-raw-zip` → `inbound-raw-zip`
**Files:**
- Modify: `backend/app/api/schedule/runs.py`(路由与函数名)
- Modify: `backend/app/services/schedule/freight_rpa_inbound_archive.py`(`receipt_raw_zip_*` → `inbound_raw_zip_*` 函数名)
- Modify: `backend/app/services/schedule/scheduler_service.py`(深链 `download=inbound_raw_zip`)
- Modify: `backend/app/services/schedule/query_service.py`(summary 字段 `inbound_raw_zip_available`)
- Modify: `frontend/src/features/admin/api/schedule.api.ts`
- Modify: `frontend/src/features/admin/modules/schedules/**`(文案与 query 参数)
- Modify: 四语言 `admin.json` 中 downloadReceipt* → downloadInbound*
- Test: 既有 receipt zip 相关测改断言
**Interfaces:**
- Consumes: `resolve_receipt_raw_zip_download`(旧)
- Produces: `resolve_inbound_raw_zip_download(run) -> tuple[Path, str]`;路由 `GET /api/admin/schedule-runs/<id>/inbound-raw-zip`;深链 `download=inbound_raw_zip`
- [ ] **Step 1: 改后端路由与函数名,更新调用方**
路由:
```python
@schedule_admin_bp.route('/schedule-runs/<int:run_id>/inbound-raw-zip', methods=['GET'])
@require_admin
def get_schedule_run_inbound_raw_zip(run_id: int):
"""下载入站 RPA 排程 run 的原始入站 Excel 打包(ZIP + manifest)。"""
...
```
禁止保留 `receipt-raw-zip` 路由。
- [ ] **Step 2: 改前端 API 与深链**
```ts
export const scheduleRunInboundRawZipUrl = (runId: number) =>
`/api/admin/schedule-runs/${runId}/inbound-raw-zip`;
```
`useScheduleAdminDeepLink`:`downloadKind === 'inbound_raw_zip'`。
- [ ] **Step 3: 跑相关测试**
Run: `pytest tests/ -k "inbound_raw_zip or receipt_raw_zip" -v`
Expected: 无 receipt_raw_zip 残留失败;新名 PASS
- [ ] **Step 4: Stage**
```bash
git add backend/app/api/schedule/runs.py backend/app/services/schedule/freight_rpa_inbound_archive.py backend/app/services/schedule/scheduler_service.py backend/app/services/schedule/query_service.py frontend/src/features/admin/api/schedule.api.ts frontend/src/features/admin/modules/schedules frontend/src/locales
```
---
### Task 4: 出站模型 + Alembic 迁移
**Files:**
- Create: `backend/app/models/freight_rpa_outbound_report.py`
- Modify: `backend/app/models/freight_rpa_config.py`(`FreightRpaSource.outbound_report_config` relationship)
- Modify: `backend/app/models/__init__.py`
- Create/Modify: Alembic revision(建三表;若 Task 2 未 drop deliveries 则本迁移一并 drop)
- Test: `backend/tests/test_freight_rpa_outbound_models.py`
**Interfaces:**
- Consumes: `FreightRpaSource`、`FreightRpaParsingProfile`
- Produces: `FreightRpaOutboundReportConfig` / `UnitRun` / `ReportFile`;表名见 Global Constraints
- [ ] **Step 1: 写模型存在性测试**
```python
from app.models import FreightRpaOutboundReportConfig, FreightRpaOutboundUnitRun, FreightRpaOutboundReportFile
def test_outbound_model_tablenames():
assert FreightRpaOutboundReportConfig.__tablename__ == "freight_rpa_outbound_report_configs"
assert FreightRpaOutboundUnitRun.__tablename__ == "freight_rpa_outbound_rpa_unit_runs"
assert FreightRpaOutboundReportFile.__tablename__ == "freight_rpa_outbound_report_files"
```
Expected FAIL(未建类)
- [ ] **Step 2: 复制入站模型文件并改名**
以 `freight_rpa_inbound_report.py` 为模板新建 outbound 文件:
- 类/表/约束名全面 `Inbound`→`Outbound`、`inbound`→`outbound`
- **不要**复制 NotificationDelivery
- 文件头 docstring 写清出站职责;注释去掉「收料」
- `FreightRpaSource`:`outbound_report_config = relationship(..., uselist=False, back_populates='source')`
- [ ] **Step 3: 生成并手审迁移**
Run: `flask db migrate -m "freight_rpa outbound tables and drop inbound notification deliveries"`
手审:仅目标三表 create + deliveries drop;无无关 drop。
Run: `flask db upgrade`
Expected: OK
- [ ] **Step 4: 跑模型测**
Run: `pytest tests/test_freight_rpa_outbound_models.py -v`
Expected: PASS
- [ ] **Step 5: Stage**
```bash
git add backend/app/models/freight_rpa_outbound_report.py backend/app/models/freight_rpa_config.py backend/app/models/__init__.py backend/migrations/versions/ backend/tests/test_freight_rpa_outbound_models.py
```
---
### Task 5: `purpose=outbound` 改走异动校验
**Files:**
- Modify: `backend/app/services/shipping_notice/onhand_parsing_profile.py`
- Modify: `backend/tests/test_parsing_profile_purpose.py`
- Modify: `frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue`(`parsing.purpose === 'inbound'` 判断扩展为 inbound|outbound 共用异动 UI)
- Modify: `frontend/src/features/admin/modules/freight-rpa/movementParsingProfileForm.ts`(若有 purpose 分支)
**Interfaces:**
- Consumes: `_validate_definition(..., purpose=)`
- Produces: `purpose in {'inbound','outbound'}` 均走 `_required_movement_field_ids`,`match_keys=[]`
- [ ] **Step 1: 改测试期望**
```python
def test_outbound_definition_uses_movement_fields():
definition = _validate_definition(_inbound_definition(), purpose='outbound')
assert definition['match_keys'] == []
assert definition['field_mapping']['doc_no'] == '单据编号'
def test_outbound_onhand_shaped_definition_rejected():
"""库存目录形态(含 match_keys)在 outbound 下应失败。"""
# 使用现有 onhand 合法定义夹具;expect ValidationError
...
```
文件头注释:删除「onhand/outbound 维持库存字段目录」。
Run: `pytest tests/test_parsing_profile_purpose.py::test_outbound_definition_uses_movement_fields -v`
Expected: FAIL
- [ ] **Step 2: 改校验分支**
```python
if purpose in {'inbound', 'outbound'}:
_required_movement_field_ids(raw)
return {
'sheet_name': str(raw.get('sheet_name') or '').strip() or None,
'header_row_index': header_row_index,
'field_mapping': {str(key).strip(): str(value).strip() for key, value in field_mapping.items()},
'match_keys': [],
}
```
同步所有 `purpose == 'inbound'` 的文档字符串与 `purpose != 'inbound'` 的前端条件 → `purpose === 'onhand'` 才走库存目录 UI。
站点绑定过滤:
- 库存报表:`purpose === 'onhand'`(不要再用 `!== 'inbound'`,以免 outbound 混入)
- 入站:`purpose === 'inbound'`
- 出站:`purpose === 'outbound'`
- [ ] **Step 3: 跑测试**
Run: `pytest tests/test_parsing_profile_purpose.py -v`
Expected: PASS
- [ ] **Step 4: Stage**
```bash
git add backend/app/services/shipping_notice/onhand_parsing_profile.py backend/tests/test_parsing_profile_purpose.py frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue frontend/src/features/admin/modules/freight-rpa/movementParsingProfileForm.ts
```
---
### Task 6: 出站报表配置 Admin API + receipt→inbound 服务符号
**Files:**
- Modify: `backend/app/services/admin/shipping_onhand_admin_service.py`
- Modify: `backend/app/api/admin_freight_rpa.py`
- Modify: `frontend/src/features/admin/api/admin.api.ts`
- Create: `frontend/src/features/admin/modules/freight-rpa/outboundReportConfigForm.ts`(镜像 inbound form)
- Test: `backend/tests/test_freight_rpa_outbound_report_config_api.py`
**Interfaces:**
- Consumes: `FreightRpaOutboundReportConfig`
- Produces:
- `get_inbound_report_config(source_id) -> dict | None`(由 `get_receipt_report_config` 改名)
- `save_inbound_report_config(source_id, data, *, actor_id) -> dict`
- `get_outbound_report_config(source_id) -> dict | None`
- `save_outbound_report_config(source_id, data, *, actor_id) -> dict`
- 路由 `GET/PUT /api/admin/freight-rpa/sources/<id>/outbound-report-config`
- 载荷键:`parsing_profile_id`、`report_path_json`、`query_parameters_json`(与入站相同)
- [ ] **Step 1: API 契约测试(失败)**
```python
def test_put_outbound_report_config_requires_outbound_profile(client, admin_headers, source_id, onhand_profile_id):
resp = client.put(
f"/api/admin/freight-rpa/sources/{source_id}/outbound-report-config",
json={"parsing_profile_id": onhand_profile_id, "report_path_json": {}, "query_parameters_json": []},
headers=admin_headers,
)
assert resp.status_code in (400, 422)
```
- [ ] **Step 2: 实现服务与路由**
校验:`parsing_profile.purpose == 'outbound' and status == 'published'`(或允许草稿绑定策略与入站现行一致——**逐行对照** `_validate_receipt_report_config` 后改名为 `_validate_inbound_report_config`,再复制为 `_validate_outbound_report_config` 只改 purpose)。
重命名所有 `receipt_report_config` 服务函数与事件名中的 receipt→inbound(审计 `event_type` 若已有历史,新事件用 `shipping_outbound_report_config_saved` / `freight_rpa_inbound_report_config_saved`,不强制改历史事件字符串除非测试锁死)。
- [ ] **Step 3: 前端 API**
```ts
export const getOutboundReportConfig = (sourceId: number) =>
requestJson(`/api/admin/freight-rpa/sources/${sourceId}/outbound-report-config`);
export const saveOutboundReportConfig = (sourceId: number, body: unknown) =>
requestJson(`/api/admin/freight-rpa/sources/${sourceId}/outbound-report-config`, { method: 'PUT', body });
```
- [ ] **Step 4: 跑测**
Run: `pytest tests/test_freight_rpa_outbound_report_config_api.py -v`
Expected: PASS
- [ ] **Step 5: Stage 列出文件**
---
### Task 7: 出站 trigger_io + Worker 心跳能力
**Files:**
- Create: `backend/app/services/freight_rpa/outbound/__init__.py`
- Create: `backend/app/services/freight_rpa/outbound/trigger_io.py`
- Modify: `backend/app/services/freight_rpa/common/worker_heartbeat.py`(`OUTBOUND_EXPORT_CAPABILITY`、`assert_outbound_rpa_worker_ready`)
- Modify: `scripts/freight_rpa/common/rpa_callbacks.py`(outbound 回调路径常量)
- Test: `backend/tests/services/freight_rpa/test_outbound_trigger_contract.py`
**Interfaces:**
- Produces:
- `SCHEMA = "freight_rpa.outbound.v1"`
- `ACTION_OUTBOUND_EXPORT_BATCH = "outbound_export_batch"`
- `write_outbound_export_batch_trigger(run_no, units, meta) -> str | None`
- `outbound_trigger_dir()` / `outbound_drop_dir()` 读 `FREIGHT_RPA_SHARED_OUTBOUND_*`
- `OUTBOUND_EXPORT_CAPABILITY = "outbound_export"`
- [ ] **Step 1: 契约测试**
```python
from app.services.freight_rpa.outbound import trigger_io
from app.services.freight_rpa.common.worker_heartbeat import OUTBOUND_EXPORT_CAPABILITY
def test_outbound_trigger_constants():
assert trigger_io.SCHEMA == "freight_rpa.outbound.v1"
assert trigger_io.ACTION_OUTBOUND_EXPORT_BATCH == "outbound_export_batch"
assert OUTBOUND_EXPORT_CAPABILITY == "outbound_export"
```
- [ ] **Step 2: 实现**(逐函数对照 `inbound/trigger_io.py` 与 `assert_receipt_rpa_worker_ready`,符号全部 outbound 化;**禁止**复用 inbound 目录配置键)
- [ ] **Step 3: 跑测并 stage**
---
### Task 8: 出站排程 job / finalize / archive / retention + 注册
**Files:**
- Create: `backend/app/services/schedule/freight_rpa_outbound_job.py`
- Create: `backend/app/services/schedule/freight_rpa_outbound_finalize.py`
- Create: `backend/app/services/schedule/freight_rpa_outbound_archive.py`
- Create: `backend/app/services/schedule/freight_rpa_outbound_retention.py`
- Modify: `backend/app/services/schedule/job_registry.py`
- Modify: `backend/app/services/schedule/__init__.py`(若需注册 excel headers)
- Test: `backend/tests/test_freight_rpa_outbound_job.py`
**Interfaces:**
- Consumes: `write_outbound_export_batch_trigger`、`assert_outbound_rpa_worker_ready`
- Produces:
- `OUTBOUND_RPA_JOB_KEY = "freight-rpa-outbound"`
- `OUTBOUND_RETENTION_JOB_KEY = "freight-rpa-outbound-retention"`
- `AWAITING_OUTBOUND_RPA_CALLBACK_STATUS = "awaiting_outbound_rpa_callback"`
- 错误码使用 `RPA.OUTBOUND_*`(如 `RPA.OUTBOUND_TRIGGER_UNAVAILABLE`、`RPA.OUTBOUND_CALLBACK_TIMEOUT`),四语言 errors 本任务或 Task 13 补齐
- 单元表写入 `FreightRpaOutboundUnitRun`
- [ ] **Step 1: 对照入站 job 写「空 source 列表 fail-closed / worker 离线 failed」测试**
- [ ] **Step 2: 复制入站四文件并全文替换符号**(`receipt`→`outbound` 语义处改为 outbound;状态串不要沿用 `awaiting_receipt_*`)
- [ ] **Step 3: `job_registry` 注册两个 platform job**
- [ ] **Step 4: 跑测并 stage**
---
### Task 9: 出站回调 API + report_archive ingest
**Files:**
- Create: `backend/app/services/freight_rpa/outbound/report_archive.py`
- Modify: `backend/app/api/freight_rpa.py`
- Modify: `scripts/freight_rpa/common/rpa_callbacks.py`(若 Task 7 未完)
- Test: `backend/tests/test_freight_rpa_outbound_callback.py`
- Optional Create: `backend/app/services/freight_rpa/common/drop_path.py`(若抽取共用「drop 根 + 文件名」解析,供 outbound 使用;抽取时入站可后续再迁,本任务不强制改 inbound)
**Interfaces:**
- Produces: `ingest_outbound_callback(payload) -> None`;`_read_outbound_callback_file(file_path: str) -> bytes`;路由:
- `POST /api/freight-rpa/outbound-batch-ready`
- `POST /api/freight-rpa/outbound-unit-progress`
- `POST /api/freight-rpa/outbound-batch-progress`
- 归档成功后 `dispatch_report_fact(report_kind='outbound', ...)`(handler 可在 Task 10 注册前用测内临时 register)
- 路径解析语义与入站 `_read_inbound_callback_file` 一致(见 Global Constraints)
- [ ] **Step 1: 先写跨机路径回归测(必须红)**
```python
def test_read_outbound_callback_file_accepts_windows_absolute_path(tmp_path, app):
"""Worker 上报 C:\\...\\drop\\foo.xlsx 时,Linux 侧只按文件名拼本机 drop 根。"""
drop = tmp_path / "outbound_drop"
drop.mkdir()
target = drop / "foo.xlsx"
target.write_bytes(b"PK\x03\x04fake")
with app.app_context():
app.config["FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR"] = str(drop)
from app.services.freight_rpa.outbound.report_archive import _read_outbound_callback_file
data = _read_outbound_callback_file(r"C:\HxopsRpaTest\data\freight_rpa\outbound\drop\foo.xlsx")
assert data.startswith(b"PK")
def test_read_outbound_callback_file_rejects_traversal(tmp_path, app):
drop = tmp_path / "outbound_drop"
drop.mkdir()
with app.app_context():
app.config["FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR"] = str(drop)
from app.services.freight_rpa.outbound.report_archive import _read_outbound_callback_file
from app.core.errors import ValidationError
with pytest.raises(ValidationError):
_read_outbound_callback_file(r"..\..\etc\passwd")
```
另测:`file_path="foo.xlsx"`(仅文件名)同样成功。
Run: `pytest tests/test_freight_rpa_outbound_callback.py -k windows_absolute -v`
Expected: FAIL(函数未实现)
- [ ] **Step 2: 回调 schema 校验失败测试**(错误 schema → 4xx)
- [ ] **Step 3: 实现 `_read_outbound_callback_file` + archive**
最小实现(对照入站,**禁止** `Path(file_path).read_bytes()` 直接读回调串):
```python
def _read_outbound_callback_file(file_path: str) -> bytes:
configured_root = str(outbound_drop_dir() or "").strip()
if not configured_root:
raise ValidationError("outbound callback file root is unavailable", code="SHIPPING.OUTBOUND_CALLBACK_FILE_INVALID")
root = Path(configured_root).resolve()
name = Path(str(file_path).replace("\\", "/")).name
path = (root / name).resolve()
try:
path.relative_to(root)
except ValueError as exc:
raise ValidationError(
"outbound callback file is outside outbound drop root",
code="SHIPPING.OUTBOUND_CALLBACK_FILE_INVALID",
) from exc
if path.suffix.lower() != ".xlsx" or not path.is_file():
raise ValidationError(
"outbound callback file must be an existing xlsx",
code="SHIPPING.OUTBOUND_CALLBACK_FILE_INVALID",
)
...
return path.read_bytes()
```
**不要**移植已删除的 `deliver_inbound_file`。
- [ ] **Step 4: 接线路由与鉴权(与入站回调同 ToolApiKey 机制)**
- [ ] **Step 5: 跑测并 stage**(含 Step 1 路径测必须绿)
---
### Task 10: 调拨 outbound_trigger_service + handler/sink
**Files:**
- Create: `backend/app/services/in_transit_transfer/outbound_trigger_service.py`
- Create: `backend/app/services/in_transit_transfer/outbound_report_handler.py`
- Modify: `backend/app/services/shipping_notice/rpa_sinks.py`(`register_outbound_sinks`)
- Modify: `backend/app/__init__.py` 或组合根调用处(与 `register_inbound_sinks` 并列)
- Modify: `backend/app/services/freight_rpa/reports/queries.py`(`get_outbound_config` / `list_outbound_configured_source_codes`,对照 inbound)
- Test: `backend/tests/services/in_transit_transfer/test_outbound_trigger_service.py`
**Interfaces:**
- Produces:
- `trigger_outbound_rpa(...)` / `trigger_outbound_rpa_batch(...)`
- `handle_outbound_report(fact) -> None`(对称 `handle_inbound_report`:推进等待中的出站相关 SourceJob;无等待任务则 no-op;可重入)
- `register_outbound_sinks()` → `register_report_handler('outbound', handle_outbound_report)`
- [ ] **Step 1: 缺配置 fail-closed 测试**
- [ ] **Step 2: 实现 trigger + handler**(对照 inbound 文件;调拨状态机字段名以现有 outbound `record_kind` / SourceJob 为准,禁止猜新状态——若入站 handler 推 `waiting_rpa_callback`→`file_ready`,出站同一套等待态字段)
- [ ] **Step 3: 组合根注册**
- [ ] **Step 4: 跑测并 stage**
---
### Task 11: 管理端来源站点出站配置卡 + 排程运维 UI
**Files:**
- Modify: `frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue`
- Create: `frontend/src/features/admin/modules/freight-rpa/outboundReportConfigForm.ts`(若 Task 6 未建)
- Modify: `frontend/src/features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminRuns.ts`
- Modify: `backend/app/api/schedule/runs.py`(`outbound-rpa-units` list/retry、`outbound-raw-zip`)
- Modify: 四语言 admin schedule 文案
- Test: vitest 组件/ composable 窄测;后端 units API 测
**Interfaces:**
- Produces: 来源站点第三折叠「出站报表配置」;排程 scope `outbound`;`rpaWorkerStatusScope: 'onhand'|'inbound'|'outbound'`
- [ ] **Step 1: Vue —— 在入站配置块后复制一块出站**,绑定 `outboundConfig`,保存调 `saveOutboundReportConfig`;解析下拉 `purpose === 'outbound'`
- [ ] **Step 2: 排程 —— 对齐 inbound 的 worker 徽标与 raw-zip 下载按钮**
- [ ] **Step 3: 后端 units/retry/raw-zip 对照 inbound 路由实现**
- [ ] **Step 4: `cd frontend && npm run build`** Expected: PASS
- [ ] **Step 5: Stage**
---
### Task 12: Windows Outbound Worker 脚本
**Files:**
- Create: `scripts/freight_rpa/outbound/outbound_rpa_worker.py`
- Create: `scripts/freight_rpa/outbound/start_outbound_worker.ps1`
- Create: `scripts/freight_rpa/outbound/register_outbound_worker_tasks.ps1`
- Create: `scripts/freight_rpa/outbound/outbound_dbs_export.py`
- Create: `scripts/freight_rpa/outbound/outbound_crane_export.py`
- Modify: `scripts/freight_rpa/README.md`
- Modify: `scripts/freight_rpa/common/rpa_callbacks.py`(确认 outbound 端点)
- Test: 后端侧可用「trigger 文件名/schema」合同测;Worker 无 pytest 时用脚本静态断言(读常量)
**Interfaces:**
- Consumes: `freight_rpa.outbound.v1` / `outbound_export_batch`
- Produces: 轮询 `FREIGHT_RPA_SHARED_OUTBOUND_TRIGGER_DIR`;回调 outbound-*-progress/ready;心跳 `outbound_export`;Worker ID `*-outbound`
- [ ] **Step 1: 复制 inbound Worker 目录结构并替换常量/路径/回调**
- [ ] **Step 2: 回调 `file_path` 只报文件名**
在 outbound Worker 组装 batch-ready / unit 成功载荷时,`file_path`(及若有的等价字段)必须是 `Path(local_drop_file).name`,**禁止**把 `C:\\...\\drop\\xxx.xlsx` 整串作为契约主值(与入站现行「后端可容忍绝对路径、Worker 应只报文件名」一致)。在 worker 内加注释指向规格 §4.2 跨机路径契约。
- [ ] **Step 3: DBS 使用配置 `report_path`;Crane 固定出站页**(页面选择器字符串实现时按货代实名填写,注释标明来源截图/环境;禁止误用 Inbound Details)
- [ ] **Step 4: ps1 注入 `FREIGHT_RPA_WORKER_ID=<host>-outbound`、outbound logs 目录**
- [ ] **Step 5: Stage `scripts/freight_rpa/outbound/` 与 README**
---
### Task 13: 错误码四语言 + 文档 + ADR + 规格状态
**Files:**
- Modify: `frontend/src/locales/{zh-CN,zh-TW,en,th}/errors.json`
- Modify: `docs/features/freight-rpa/GLOSSARY.md`
- Modify: `docs/features/shipping-notice/technical.md`(改名 + 出站部署节,对称 §1.9)
- Modify: `docs/funclist.md`
- Modify: `docs/adr/0004-freight-rpa-report-ownership.md`
- Modify: `docs/superpowers/specs/2026-10-19-freight-rpa-outbound-and-rename-design.md`(状态 → 已有实施计划)
- Modify: 环境变量权威文档(若缺 OUTBOUND 项则补齐说明,不改真实密钥)
**Interfaces:** 无代码接口
- [ ] **Step 1: 为 Task 8/9 引入的每个新 `code=` 补四语言**
- [ ] **Step 2: Glossary —— Outbound 改为已交付抓取;注明无 deliveries、无工作台收料页;Inbound 用户文案「入站」**
- [ ] **Step 3: ADR 0004 Consequences 增加「本阶段注册 outbound handler」**
- [ ] **Step 4: 规格头状态改为「已有实施计划」并链到本 plan 路径**
- [ ] **Step 5: Stage 文档与 errors.json**
---
### Task 14: 总闸门(grep + 构建)
**Files:**
- Create/Modify: `backend/tests/test_freight_rpa_outbound_rename_gate.py`
**Interfaces:** 无
- [ ] **Step 1: 写入总闸门测试**
```python
def test_no_receipt_raw_zip_route():
text = Path("app/api/schedule/runs.py").read_text(encoding="utf-8")
assert "receipt-raw-zip" not in text
assert "inbound-raw-zip" in text
def test_outbound_purpose_not_catalog_in_validate_docstring():
text = Path("app/services/shipping_notice/onhand_parsing_profile.py").read_text(encoding="utf-8")
assert "purpose in {'inbound', 'outbound'}" in text or 'purpose in {"inbound", "outbound"}' in text
def test_no_outbound_notification_deliveries_table_reference():
...
```
- [ ] **Step 2: 跑闸门 + 出站相关测 + frontend build**
Run:
```bash
cd backend && pytest tests/test_freight_rpa_outbound_rename_gate.py tests/test_freight_rpa_inbound_slim_gate.py tests/test_parsing_profile_purpose.py tests/test_freight_rpa_outbound_models.py -v
cd ../frontend && npm run build
```
Expected: 全部 PASS
- [ ] **Step 3: Stage 闸门测试**
---
## Spec coverage(自检)
| 规格项 | 任务 |
| --- | --- |
| 报表规则 / 来源站点 / 入站报表文案 | T1 |
| 出站报表配置 UI | T11(API T6) |
| outbound 异动解析 | T5 |
| 出站三表 + 迁移 | T4 |
| 无 outbound deliveries;删入站 deliveries | T2、T4 |
| 下线工作台收料页 | T2 |
| inbound-raw-zip | T3 |
| trigger/心跳/回调/排程/retention | T7–T9、T8 |
| 按需 trigger + sink | T10 |
| Worker 脚本 | T12 |
| 错误码 / 文档 / ADR | T13 |
| 单发布总闸门 | T14 |
| 启用非硬门槛 | T6 校验不接入 activation checks(显式不改 `_source_activation_checks`) |
| Crane 固定出站页 | T12 |
| class-prefix 前置 | Global Constraints |
| 跨机路径:Windows `file_path` → Linux drop 文件名映射 | T9(测+读)、T12(Worker 只报文件名)、Global Constraints |
无 TBD。入站历史错误码 `RPA.RECEIPT_*` **本计划不强制改名**(避免无收益大爆炸);用户可见「收料」文案必须清掉。
@@ -0,0 +1,183 @@
# 货代 RPA:报表规则 / 来源站点改名 + 出站全栈 + 入站运维瘦身
日期:2026-10-19 | 状态:**已有实施计划**(`docs/superpowers/plans/2026-10-19-freight-rpa-outbound-and-rename.md`)| 前置:`docs/superpowers/specs/2026-10-18-freight-rpa-phase-b-design.md`、`docs/superpowers/specs/2026-10-19-freight-rpa-class-prefix-design.md`(假定 `FreightRpa*` 已落地或同发布先合入)| 术语:`docs/features/freight-rpa/GLOSSARY.md` | ADR:延续 `docs/adr/0004-freight-rpa-report-ownership.md`(本规格注册 outbound handler)
## 0. 问题
管理端货代域仍用「库存解析」「库存站点」「收料报表」等旧称,与已落地的 onhand / inbound 代码语义不一致。解析用途里虽有 `purpose=outbound`,但 UI/校验仍按库存字段目录占位;出站抓取(配置表、Worker、排程、回调、事实分发)未实施,仅有共享目录与 env 占位。
入站侧另有两处过度设计:`freight_rpa_inbound_notification_deliveries` 仅服务工作台「重发企微」幂等账,日常通知已由排程任务的通知人清单 + `_notify_schedule_run_wecom` 覆盖;工作台「收料文件」页与排程管理的 run 查询 / raw-zip 下载重叠。
## 1. 目标与非目标
**目标**
1. 用户可见改名(四语言):`库存解析` → **报表规则**;`库存站点` → **来源站点**;`收料报表配置` → **入站报表配置**。父级菜单「库存管理」、页内「库存字段目录」不改。
2. 来源站点详情新增 **出站报表配置**,与入站配置同构(路径 / 查询条件 / 解析绑定)。
3. `purpose=outbound` 解析改为与 inbound 相同的 **标准异动字段**(`MOVEMENT_FIELDS`)契约;纠正现有 onhand 形态占位。
4. 出站全栈镜像入站(做法 A:逐文件克隆,不先做泛化重构):配置 / unit / file 三表、trigger schema、独立 Worker、排程 + retention、回调、排程运维(unit 列表/重试/raw-zip)、在途调拨按需触发、`report_kind=outbound` handler + sinks。
5. 管理端代码命名:`receipt*` → `inbound*`(对外已是 `inbound-report-config` 的路径保持;`receipt-raw-zip` → `inbound-raw-zip`,无兼容别名)。
6. 入站瘦身:删除 deliveries 表与「重发企微」;下线工作台收料文件页;运维统一到排程管理。通知人须为可进入排程管理的管理员。
**非目标**
- 不改父级「库存管理」、不改「库存字段目录」信息架构。
- 不把履约「出货」/`shipment_*`/`freight_upload`/upload 域改名为 outbound。
- 不把入站/出站配置纳入来源站点启用硬门槛(与入站现状一致:可选配置,触发时 fail-closed)。
- 不做 outbound 旧解析草稿的自动字段迁移。
- 不重做 class-prefix;出站类一律 `FreightRpaOutbound*`。
- 不在本规格改在途调拨匹配算法,只接线 outbound 报表事实。
- 不新建工作台「出站文件」页。
- 出站不建 `notification_deliveries`;入站该表删除后亦不重建。
## 2. 已拍板决策
| 编号 | 决策 |
| --- | --- |
| D1 | 出站解析对齐入站异动契约(`MOVEMENT_FIELDS`) |
| D2 | 注册 `report_kind=outbound` handler + 调拨 sink(对称入站) |
| D3 | 改名含用户可见文案 + 管理端 `receipt*` 符号清理;回调路径无兼容层 |
| D4 | 单发布:改名 + 出站全栈 + 入站瘦身同交付 |
| D5 | 出站配置非启用硬门槛 |
| D6 | 出站触发 = 排程 `freight-rpa-outbound`(+ retention)+ 调拨 `outbound_trigger_service` |
| D7 | DBS 路径/查询可配;Crane 固定出站报表页(实名实现时对接,规格约束:固定页、不按 Warehouse 拆分) |
| D8 | 旧 onhand 形态 outbound 草稿:发布失败,人工重建 |
| D9 | 通知只走排程通知人清单;无逐文件企微投递账 |
| D10 | 父级「库存管理」不改 |
| D11 | 假定 `FreightRpa*` class-prefix 已落地或同发先合入 |
| D12 | RPA 层不强制 `in_out_flag`;方向过滤留在调拨域 |
| D13 | 库存字段目录保留,仅服务 onhand |
| D14 | 入口文案最终为 **报表规则**(非「文档规则」) |
| D15 | 删除入站 deliveries + resend API + 工作台收料页;运维归排程 |
**实现路径:做法 A**(入站模板逐文件克隆)。否决:先抽象 MovementReport 泛化层(B);复用入站 Worker 目录承载出站(C)。
## 3. 数据模型与解析契约
### 3.1 解析 Profile
| purpose | 字段契约 | 管理端 |
| --- | --- | --- |
| `onhand` | 库存字段目录 + `match_keys` | 不变 |
| `inbound` | `MOVEMENT_FIELDS` | 不变 |
| `outbound` | 与 inbound 相同 | 纠正:异动映射 UI/校验 |
创建后 purpose 不可改。保存/发布 outbound 必须通过与 inbound 同源的异动必填映射校验。
### 3.2 出站新建表(三张)
| 类 | 表 |
| --- | --- |
| `FreightRpaOutboundReportConfig` | `freight_rpa_outbound_report_configs` |
| `FreightRpaOutboundUnitRun` | `freight_rpa_outbound_rpa_unit_runs` |
| `FreightRpaOutboundReportFile` | `freight_rpa_outbound_report_files` |
配置字段与入站同构:`source_id`(1:1)、`parsing_profile_id`(仅 published 且 `purpose=outbound`)、`report_path_json`、`query_parameters_json`、`config_version`。无独立启停:是否运行 = 来源站点 `enabled` ∧ 配置存在且可解析。
`FreightRpaSource` 增加 `outbound_report_config` 关系(并列 `onhand_report_config` / `inbound_report_config`)。
### 3.3 报表事实分发
在阶段 B 白名单上注册 `handle_outbound_report` 与 `register_outbound_sinks`。在途调拨消费出站事实;方向过滤不在 RPA 层新增规则。
### 3.4 入站拆除
Alembic:`DROP` `freight_rpa_inbound_notification_deliveries`。删除模型 `FreightRpaInboundNotificationDelivery`、`deliver_inbound_file`、`POST /api/admin/inbound-report-files/<id>/resend`,以及仅服务于该账本的测试。
工作台下线:`/workspace/inbound-reports` 路由、侧栏入口、`InboundReportFilesPage`、workspace `inbound-report-files` list/download API,以及仅被该页使用的 `shipping_notice.inbound_report_access` 模块(当前无其它调用方)。失败 unit 重试保留在**排程管理 / admin inbound-rpa-units**;原始包下载保留在排程 `inbound-raw-zip`。
## 4. API / 管理端 / 触发 / Worker
### 4.1 管理端 API
| 能力 | 说明 |
| --- | --- |
| `GET/PUT .../sources/<id>/inbound-report-config` | 已有;服务层/前端符号 `receipt*` → `inbound*` |
| `GET/PUT .../sources/<id>/outbound-report-config` | 新增,镜像入站 |
| parsing-profiles | `purpose=outbound` 走异动校验 |
| `receipt-raw-zip` → `inbound-raw-zip` | 无别名;企微深链参数同发 |
### 4.2 Worker 回调与契约
新增(镜像入站):
- `/api/freight-rpa/outbound-batch-ready`
- `/api/freight-rpa/outbound-unit-progress`
- `/api/freight-rpa/outbound-batch-progress`
Trigger:schema `freight_rpa.outbound.v1`,action `outbound_export_batch`,文件名 `outbound_export_batch_{run_no}.json`。
心跳能力:`outbound_export`;Worker ID:`*-outbound`。
目录(env 多已占位):`FREIGHT_RPA_SHARED_OUTBOUND_{TRIGGER,DROP}_DIR`、`FREIGHT_RPA_OUTBOUND_ARCHIVE_DIR`、`FREIGHT_RPA_OUTBOUND_TIMEOUT_SECONDS`。
**跨机路径契约(硬约束,复现 onhand/inbound 历史事故禁止项)**
Windows Worker 与 Linux 后端通过同一 SMB 共享看到不同绝对路径根(如 `C:\HxopsRpaTest\data\freight_rpa\outbound\drop\...` vs `/mnt/hxops-rpa-*-data/freight_rpa/outbound/drop/...`)。历史上曾因回调 `file_path` 携带 Windows 分隔符/`\` 绝对路径,在 Linux 侧按原样打开导致成功抓取后全程 400(入站于 2026-10-08 按「只认文件名」修复)。
出站必须遵守:
1. Worker 回调 `file_path` **优先只报 drop 根内的文件名**(单一路径段,无目录)。
2. 后端读取时:**禁止**把 Worker 绝对路径当 Linux 路径直接 `open`;一律 `Path(str(file_path).replace('\\', '/')).name` 取末段,再拼到本机 `FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR` 根下,并用 `resolve().relative_to(root)` 防穿越。
3. 实现时对照入站 `_read_inbound_callback_file`(`freight_rpa/inbound/report_archive.py`)与在手 `resolve_shared_inventory_drop_file`(`onhand/workflow_protocol.py`);出站可抽共用 helper,但**不得**弱化「只认文件名」语义。
4. 必须有回归测试:载荷带 `C:\\...\\outbound\\drop\\foo.xlsx` 与仅 `foo.xlsx` 均能读到 Linux drop 内同名文件;带 `..\\` 的路径被拒绝。
### 4.3 排程与运维
- 平台任务:`freight-rpa-outbound`、`freight-rpa-outbound-retention`
- Admin:`outbound-rpa-units`(list/retry)、`GET .../schedule-runs/<id>/outbound-raw-zip`
- 入站排程文案「收料」→「入站」;finalize 仍用排程通知人清单发企微(可附 raw-zip,与现网库存/入站一致)
### 4.4 按需触发
新增 `outbound_trigger_service`(镜像 `inbound_trigger_service`):一源一单元;站点停用 / 出站配置缺失 / 登录连接缺失 → fail-closed。
### 4.5 脚本
`scripts/freight_rpa/outbound/`:`outbound_rpa_worker.py`、`start_outbound_worker.ps1`、`register_outbound_worker_tasks.ps1`、DBS/Crane export 驱动。Windows 任务名与入站同构独立(如 `HXOPS Freight Outbound RPA Worker TEST/PROD`)。后端与 Worker **同发**。
### 4.6 管理端 UI
- `FreightRpaPage`:侧栏/标题改为报表规则、来源站点;来源站点详情三块折叠——库存报表|入站报表|出站报表。
- 报表规则:outbound 与 inbound 共用异动映射交互。
- 排程工作台:outbound job key、Worker 轮询 scope=`outbound`。
## 5. 错误处理 / 测试 / 文档 / 发布
### 5.1 错误
新增出站错误码(镜像入站超时/Worker 离线等),四语言 `locales/*/errors.json` 同步。统一 envelope / `AppError` / `requestJson` / `useMessage`。
### 5.2 测试最低集
- outbound 异动校验;旧 onhand 形态 outbound 发布失败
- 出站配置 GET/PUT、1:1、绑定约束
- 排程/按需 trigger 契约;回调 → 归档 → dispatch(fake sink)
- grep gate:无 deliveries / resend / 工作台收料页引用
- i18n/导航:报表规则、来源站点、入站报表
- Worker env 目录契约
### 5.3 文档(同 PR)
- `GLOSSARY.md`:出站改为已交付抓取;注明无 deliveries、无工作台收料页
- `docs/features/shipping-notice/technical.md`:改名 + 出站部署对称入站 §1.9
- `docs/funclist.md`:补出站 RPA 与改名
- 环境变量权威文档确认 `FREIGHT_RPA_*OUTBOUND*`
- ADR 0004 Consequences:本阶段注册 outbound handler
### 5.4 发布
- class-prefix 先合入或同发
- 迁移:新建出站三表 + drop inbound deliveries
- 共享目录创建 `freight_rpa/outbound/{triggers,drop,logs,archives}`
- 先 Worker 心跳就绪再挂排程;不提交密钥
## 6. 成功标准
- 管理端可见文案符合 §1;来源站点可独立维护入站/出站报表配置。
- 出站排程与按需触发可跑通:trigger → Worker → 回调 → 文件归档 → outbound 事实分发。
- 排程管理可查 outbound run、下载 outbound-raw-zip、重试失败 unit;企微走排程通知人。
- 工作台无收料文件入口;无 deliveries 表与 resend 企微 API。
- `frontend` 相关改动 `npm run build` 通过;关键后端测试与 grep gate 通过。
## 7. 后续实施
实施计划:`docs/superpowers/plans/2026-10-19-freight-rpa-outbound-and-rename.md`。按任务执行;提交须用户显式授权。