- 调度整合:退役 in_transit_receipt_file_job,收料归档收敛 shipping_receipt_rpa_archive,排程注册表统一 - 自动调拨 Job:调拨前确保各来源当日收料文件就绪(缺失自动触发收料 RPA),严格等量匹配后生成 ERP 调拨单 - worker 手动唤醒:排程工作台支持手动唤醒与 runs 透视,heartbeat 协议同步 - 收料缺失幸存 T2:parse_failed 状态落库(迁移 q4c5) - 来源错误分层与 stale 时钟换源:改挂 inventory_checked_at 库存查得时刻,展示阈值与执行门禁解耦(迁移 t5a6) - 新增 wecom_sender 企微通知:每非空 Run 汇总一条,通知失败不影响 ERP 结果 - 同步排程工作台/调拨卡片前端、chat/admin 文案四语言、RPA 脚本与测试全家
594 lines
27 KiB
Markdown
594 lines
27 KiB
Markdown
# 在途调拨来源错误分层(勾选门禁 + 解析失败态 + 路由行内化)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/解析失败在勾选页处理;路由失败只行内阻断;匹配卡顶栏不再承担路由/解析主叙事。
|
||
|
||
**Architecture:** 在现有「调拨不维护独立抓取状态表」前提下,把解析失败挂在当日可用 `ShippingReceiptReportFile` 上(可空列 `parse_failed_at` / `parse_error_code` / `parse_error_message`)。`resolve_source_file_status` 在可用文件存在且已标记解析失败时投影 `file_status=parse_failed` 且 `has_ready_file=false`。证据同步/匹配 STEP0 对齐失败时写标记;同步成功清标记。勾选确认只提交 `has_ready_file` 来源;`retry-rpa` 对 `parse_failed` 优先重跑本地 sync(修 Profile 后不必整轮 RPA)。匹配侧删除「路由失败→整源 failed」抬升。
|
||
|
||
**Tech Stack:** Flask + SQLAlchemy 2 + Alembic;Vue 3 + Vitest;四语言 i18n(`chat.json`)。
|
||
|
||
**Spec:** 2026-09-29 会话批准的设计(bounded:C + 最小分层;无独立 spec 文件)。冻结决策:
|
||
- D1:`file_status` 扩展值 `parse_failed`(非独立字段)。
|
||
- D2:解析失败落在**当前可用收料归档文件**上,不新建调拨抓取状态表。
|
||
- D3:路由 `blocked_route_not_resolved` 只行内;禁止整源 `TRANSFER.ROUTE_NOT_RESOLVED` 顶栏。
|
||
- D4:勾选确认只 emit `has_ready_file===true`(静默过滤未就绪,含 `parse_failed`)。
|
||
- D5:不做匹配卡 B 排除条、不做勾选页路由预检、不改 stale/file_current 文案(另案)。
|
||
- D6:`parse_failed` 可重试:优先对现有文件 `sync_and_commit_for_callback`;仍失败则保持标记;无可用文件才走原 RPA 触发。
|
||
|
||
## Global Constraints
|
||
|
||
- 🔒 不提交密钥;本计划无新环境变量。
|
||
- 🧬 表结构变更必须配套 Alembic 迁移并提交。
|
||
- 🌍 前端新增文案必须同时补齐 `zh-CN / zh-TW / en / th` 的 `chat.json`(`chat.transfer.*`)。
|
||
- 📝 新建/调整代码满足 AGENTS.md §5 文件头 + 函数层注释。
|
||
- 🚫 禁止自动 commit;每任务止步于 `git add <具体文件>`。
|
||
- ➕ 不新增第三方依赖。
|
||
- 🧪 后端 `cd backend && python -m pytest ...`;前端相关 `cd frontend && npx vitest run <spec>`;改 frontend 后 `npm run build`。
|
||
- 🎯 YAGNI:匹配卡顶栏仍可作「匹配当轮才发现的解析失败」兜底;主路径是勾选投影。
|
||
|
||
## File map
|
||
|
||
| 文件 | 职责 |
|
||
| --- | --- |
|
||
| `backend/migrations/versions/<rev>_receipt_report_parse_failed.py` | 归档文件增加解析失败三列 |
|
||
| `backend/app/models/shipping_receipt_report.py` | 模型列 |
|
||
| `backend/app/services/in_transit_transfer/source_file_status.py` | 投影 `parse_failed`;record/clear 辅助 |
|
||
| `backend/app/services/in_transit_transfer/evidence_sync.py` | sync 成败写/清标记 |
|
||
| `backend/app/services/in_transit_transfer/matching_service.py` | 去路由整源抬升;align 失败 record |
|
||
| `backend/app/api/in_transit_transfer.py` | `retry-rpa`:parse_failed 先 re-sync |
|
||
| `frontend/src/features/chat/types/transfer.types.ts` | `file_status` 联合类型 |
|
||
| `frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue` | 徽标 + confirm **只 emit ready** + isRetryable |
|
||
| `frontend/src/features/chat/components/messages/TransferMatchCard.vue` | 顶栏 `failedSources` 过滤 `TRANSFER.ROUTE_NOT_RESOLVED`(含历史卡) |
|
||
| `frontend/src/locales/*/chat.json` | `fileParseFailed` 等 |
|
||
| 对应 tests | 见各 Task |
|
||
|
||
---
|
||
|
||
### Task 1: 归档文件 DDL + 模型列(parse 失败标记)
|
||
|
||
**Files:**
|
||
- Create: `backend/migrations/versions/<autogen>_add_receipt_report_parse_failed.py`
|
||
- Modify: `backend/app/models/shipping_receipt_report.py`(`ShippingReceiptReportFile`)
|
||
- Test: `backend/tests/services/in_transit_transfer/test_source_file_status.py`(本任务只加列可读;投影逻辑在 Task 2)
|
||
|
||
**Interfaces:**
|
||
- Produces: `ShippingReceiptReportFile.parse_failed_at: datetime | None`、`parse_error_code: str | None`(≤64)、`parse_error_message: str | None`(Text)。三者全空=未失败/已清除。
|
||
|
||
- [ ] **Step 1: 写迁移与模型**
|
||
|
||
在 `ShippingReceiptReportFile` 增加:
|
||
|
||
```python
|
||
parse_failed_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||
parse_error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||
parse_error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||
```
|
||
|
||
迁移 `upgrade`:`op.add_column` 三列,均可空;`downgrade` drop。down_revision 接当前 head(执行时用 `flask db heads` / `flask db migrate` 生成后核对单 head)。
|
||
|
||
- [ ] **Step 2: 本地 upgrade**
|
||
|
||
Run: `cd backend && flask db upgrade`
|
||
Expected: 成功;表含三列。
|
||
|
||
- [ ] **Step 3: Stage**
|
||
|
||
```bash
|
||
git add backend/migrations/versions/*parse_failed*.py backend/app/models/shipping_receipt_report.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 2: `resolve_source_file_status` 投影 `parse_failed` + record/clear
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/in_transit_transfer/source_file_status.py`
|
||
- Test: `backend/tests/services/in_transit_transfer/test_source_file_status.py`
|
||
|
||
**Interfaces:**
|
||
- Produces:
|
||
- `resolve_source_file_status` 返回的 `file_status` 增加 `'parse_failed'`;此时 `has_ready_file=False`,仍可带 `file_no`/`file_sha256`(便于诊断)。
|
||
- `record_receipt_parse_failure(*, report: ShippingReceiptReportFile, error_code: str, error_message: str, now: datetime | None = None) -> None`(只 flush 不 commit)
|
||
- `clear_receipt_parse_failure(*, report: ShippingReceiptReportFile) -> None`(清空三列,flush)
|
||
|
||
- [ ] **Step 1: 写失败测试**
|
||
|
||
在 `test_source_file_status.py` 追加(复用既有 `receipt_unit_run` fixture + `test_report_file_is_ready` 造文件模式):
|
||
|
||
```python
|
||
def test_usable_file_with_parse_failed_at_projects_parse_failed(app, receipt_unit_run):
|
||
"""可用归档文件若已标记 parse_failed_at → file_status=parse_failed 且不可当 ready。"""
|
||
from app import db
|
||
from app.models import ShippingReceiptReportFile
|
||
|
||
receipt_unit_run.status = 'success'
|
||
digest = hashlib.sha256(b'bad workbook').hexdigest()
|
||
db.session.add(ShippingReceiptReportFile(
|
||
unit_run_id=receipt_unit_run.id, storage_provider='minio', storage_bucket='test',
|
||
storage_key='shipping/receipt/bad.xlsx', original_filename='bad.xlsx',
|
||
file_size=16, sha256=digest,
|
||
parse_failed_at=datetime.utcnow(),
|
||
parse_error_code='TRANSFER_FILE_SCHEMA_INVALID',
|
||
parse_error_message='schema',
|
||
))
|
||
db.session.commit()
|
||
status = resolve_source_file_status(source_code=SOURCE_CODE)
|
||
assert status["file_status"] == "parse_failed"
|
||
assert status["has_ready_file"] is False
|
||
assert status["file_sha256"] == digest
|
||
|
||
|
||
def test_record_and_clear_parse_failure_roundtrip(app, receipt_unit_run):
|
||
"""record 写入三列;clear 清空后投影回 ready。"""
|
||
from app import db
|
||
from app.models import ShippingReceiptReportFile
|
||
from app.services.in_transit_transfer.source_file_status import (
|
||
clear_receipt_parse_failure,
|
||
record_receipt_parse_failure,
|
||
resolve_source_file_status,
|
||
)
|
||
|
||
receipt_unit_run.status = 'success'
|
||
digest = hashlib.sha256(b'roundtrip').hexdigest()
|
||
report = ShippingReceiptReportFile(
|
||
unit_run_id=receipt_unit_run.id, storage_provider='minio', storage_bucket='test',
|
||
storage_key='shipping/receipt/ok.xlsx', original_filename='ok.xlsx',
|
||
file_size=16, sha256=digest,
|
||
)
|
||
db.session.add(report)
|
||
db.session.commit()
|
||
record_receipt_parse_failure(
|
||
report=report, error_code="TRANSFER_FILE_SCHEMA_INVALID", error_message="bad",
|
||
)
|
||
db.session.commit()
|
||
assert resolve_source_file_status(source_code=SOURCE_CODE)["file_status"] == "parse_failed"
|
||
clear_receipt_parse_failure(report=report)
|
||
db.session.commit()
|
||
assert resolve_source_file_status(source_code=SOURCE_CODE)["file_status"] == "ready"
|
||
```
|
||
|
||
(造数口径对齐同文件 `test_report_file_is_ready`:不手写 `created_at`,依赖默认 utcnow 落在当日可用门禁。)
|
||
|
||
- [ ] **Step 2: Run 确认失败**
|
||
|
||
Run: `cd backend && python -m pytest tests/services/in_transit_transfer/test_source_file_status.py::test_usable_file_with_parse_failed_at_projects_parse_failed -q`
|
||
Expected: FAIL(尚无 `parse_failed` 分支)
|
||
|
||
- [ ] **Step 3: 实现投影与辅助函数**
|
||
|
||
在 `resolve_source_file_status` 命中 `usable_receipt_file_condition` 的 `report` 后:
|
||
|
||
```python
|
||
if report.parse_failed_at is not None:
|
||
return {
|
||
'file_status': 'parse_failed',
|
||
'has_ready_file': False,
|
||
'file_no': report.original_filename or str(report.id),
|
||
'file_sha256': report.sha256,
|
||
}
|
||
```
|
||
|
||
`record_receipt_parse_failure`:写 `parse_failed_at=now or utcnow`、`parse_error_code[:64]`、`parse_error_message[:2000]`,`db.session.flush()`。
|
||
`clear_receipt_parse_failure`:三列置 `None`,flush。
|
||
更新模块 docstring:状态集含 `parse_failed`。
|
||
|
||
- [ ] **Step 4: Run 全文件测试**
|
||
|
||
Run: `cd backend && python -m pytest tests/services/in_transit_transfer/test_source_file_status.py -q`
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage**
|
||
|
||
```bash
|
||
git add backend/app/services/in_transit_transfer/source_file_status.py backend/tests/services/in_transit_transfer/test_source_file_status.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 3: evidence_sync / 匹配 align 写清标记;路由不再整源 failed
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/in_transit_transfer/evidence_sync.py`(`sync_and_commit_for_callback` / `sync_source_rows` 成功清、失败记)
|
||
- Modify: `backend/app/services/in_transit_transfer/matching_service.py`(删路由抬升循环;align 的 `ReceiptFileSchemaError` 调 `record_receipt_parse_failure`)
|
||
- Test: `backend/tests/services/in_transit_transfer/test_evidence_sync.py`
|
||
- Test: `backend/tests/services/in_transit_transfer/test_matching_service.py`(改 `test_route_not_resolved_marks_source_failed`)
|
||
|
||
**Interfaces:**
|
||
- Consumes: Task 2 的 `record_receipt_parse_failure` / `clear_receipt_parse_failure`
|
||
- Produces: 同步成功清理当前 ready 文件标记;`ReceiptFileSchemaError`(及桥内等价解析失败)写入标记;`run_matching` 路由失败时来源 `stage` 保持 `file_ready`(有文件时),行 `result=blocked_route_not_resolved`
|
||
|
||
- [ ] **Step 1: 改写路由测试(先失败)**
|
||
|
||
替换 `test_route_not_resolved_marks_source_failed`:
|
||
|
||
```python
|
||
def test_route_not_resolved_stays_row_level_not_source_failed(dbs_ready_file):
|
||
"""路由缺失 → 行 blocked_route_not_resolved;来源保持 file_ready(不抬升顶栏)。"""
|
||
erp = FakeCapabilityClient()
|
||
rpa = FakeRPA()
|
||
deps = TransferDeps(
|
||
file_repository=make_ready_repo(dbs_ready_file),
|
||
rpa_trigger=rpa,
|
||
route_resolver=FakeRouteResolver(routes={}),
|
||
capabilities=erp,
|
||
)
|
||
seed_rows_from_file("DBS-AWSBI", deps, "2026-08-06")
|
||
result = run_matching(
|
||
source_codes=["DBS-AWSBI", "CRANE-SZ"], business_date="2026-08-06", deps=deps,
|
||
)
|
||
by_source = {stage.source_code: stage for stage in result.sources}
|
||
assert by_source["DBS-AWSBI"].stage == "file_ready"
|
||
assert by_source["DBS-AWSBI"].error_code is None
|
||
assert by_source["CRANE-SZ"].stage == "waiting_rpa_callback"
|
||
assert all(
|
||
item.result == "blocked_route_not_resolved"
|
||
for item in result.items if item.source_code == "DBS-AWSBI"
|
||
)
|
||
```
|
||
|
||
- [ ] **Step 2: Run 确认失败**
|
||
|
||
Run: `cd backend && python -m pytest tests/services/in_transit_transfer/test_matching_service.py::test_route_not_resolved_stays_row_level_not_source_failed -q`
|
||
Expected: FAIL(仍 `stage==failed`)
|
||
|
||
- [ ] **Step 3: 删路由整源抬升**
|
||
|
||
在 `run_matching` 中删除对 `route_failed_sources` 的 for 循环抬升;`_matching_rows` 可停止收集/返回 `route_failed_sources`(改为返回 `(items, pending_count)`,更新所有解包点与 docstring)。
|
||
|
||
- [ ] **Step 4: evidence_sync 成败挂钩**
|
||
|
||
在 `sync_source_rows` 成功路径(即将 return outcome 前):若当前 usable 文件存在,`clear_receipt_parse_failure`。
|
||
|
||
在 `sync_and_commit_for_callback` 的 `except`:**先** `db.session.rollback()`(保持桥隔离),**再**判断是否解析失败并独立 commit 标记:
|
||
|
||
```python
|
||
except Exception as exc: # noqa: BLE001
|
||
current_app.logger.warning(...)
|
||
db.session.rollback()
|
||
# [parse 投影] rollback 之后再写标记,避免脏会话;仅 schema 类失败落库
|
||
code = getattr(exc, "code", None) or ""
|
||
if code == TRANSFER_FILE_SCHEMA_INVALID or isinstance(exc, ReceiptFileSchemaError):
|
||
report = (
|
||
ShippingReceiptReportFile.query
|
||
.join(ShippingReceiptReportFile.unit_run)
|
||
.filter(
|
||
ShippingReceiptReportFile.unit_run.has(source_code=source_code),
|
||
usable_receipt_file_condition(),
|
||
)
|
||
.order_by(ShippingReceiptReportFile.created_at.desc(), ShippingReceiptReportFile.id.desc())
|
||
.first()
|
||
)
|
||
if report is not None:
|
||
record_receipt_parse_failure(
|
||
report=report,
|
||
error_code=str(code or TRANSFER_FILE_SCHEMA_INVALID),
|
||
error_message=str(exc)[:2000],
|
||
)
|
||
db.session.commit()
|
||
return False
|
||
```
|
||
|
||
`TRANSFER_FILE_SCHEMA_INVALID` 从 `contracts` 导入;`usable_receipt_file_condition` 从 `receipt_file_gate` 导入。
|
||
|
||
- [ ] **Step 5: matching align 失败挂钩**
|
||
|
||
`run_matching` 中 `align_errors` 分支:在 append `SourceProgressDTO(stage="failed", ...)` 之前,若 `error_code` 表明 schema/解析失败,对 `resolve` 到的可用文件 `record_receipt_parse_failure`(flush;随 create_matching 事务提交)。
|
||
|
||
- [ ] **Step 6: 补 evidence 测试 + 跑套件**
|
||
|
||
在 `test_evidence_sync.py` 增加:模拟 sync 抛 `ReceiptFileSchemaError` → 文件带 `parse_failed_at`;成功 sync → 标记被清。
|
||
Run:
|
||
|
||
```bash
|
||
cd backend && python -m pytest \
|
||
tests/services/in_transit_transfer/test_matching_service.py::test_route_not_resolved_stays_row_level_not_source_failed \
|
||
tests/services/in_transit_transfer/test_matching_service.py::test_source_isolation_dbs_failure_does_not_block_crane \
|
||
tests/services/in_transit_transfer/test_evidence_sync.py -q
|
||
```
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 7: Stage**
|
||
|
||
```bash
|
||
git add backend/app/services/in_transit_transfer/evidence_sync.py \
|
||
backend/app/services/in_transit_transfer/matching_service.py \
|
||
backend/tests/services/in_transit_transfer/test_matching_service.py \
|
||
backend/tests/services/in_transit_transfer/test_evidence_sync.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 4: `retry-rpa` 对 parse_failed 先本地重解析
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/api/in_transit_transfer.py`(`retry_source_rpa_api`,约 L723–753)
|
||
- Test: `backend/tests/api/test_in_transit_transfer_api.py`(当前无 retry-rpa 用例,本任务新增)
|
||
|
||
**Interfaces:**
|
||
- Consumes: `resolve_source_file_status`、`sync_and_commit_for_callback`、既有 `trigger_receipt_rpa`
|
||
- Produces: 当 `file_status==parse_failed` 且有 `file_sha256`:先 `sync_and_commit_for_callback`;成功且投影 `ready` → HTTP 200、`{"ok": true, "file_status": "ready", "reparsed": true}`(**不**返回 202/fetching);仍失败 → `ok=false`、`file_status=parse_failed`、`reparsed=true`;否则走原 `trigger_receipt_rpa`(202 + fetching)。
|
||
|
||
- [ ] **Step 1: 写 API 测试(失败)**
|
||
|
||
复用该文件 `API_PREFIX = "/api/in-transit-transfer"` 与 `admin_headers`;来源码用已有种子(如 `DSV360_AWSDU` 或测试里已 create 的实例)。核心断言:
|
||
|
||
```python
|
||
def test_retry_rpa_parse_failed_reparses_existing_file(
|
||
app, client, admin_headers, monkeypatch,
|
||
):
|
||
"""parse_failed 且有可用文件 → retry 先 sync,不触发 RPA。"""
|
||
called = {"rpa": 0, "sync": 0}
|
||
|
||
def fake_sync(*, source_code, business_date, now):
|
||
called["sync"] += 1
|
||
# 测试内把该来源文件 parse_* 清空,使后续 resolve → ready
|
||
return True
|
||
|
||
monkeypatch.setattr(
|
||
"app.services.in_transit_transfer.evidence_sync.sync_and_commit_for_callback",
|
||
fake_sync,
|
||
)
|
||
monkeypatch.setattr(
|
||
"app.services.in_transit_transfer.receipt_trigger_service.trigger_receipt_rpa",
|
||
lambda **kw: called.__setitem__("rpa", called["rpa"] + 1) or {"ok": True, "callback_id": "x"},
|
||
)
|
||
# arrange:当日 usable ReportFile + parse_failed_at(可参考 test_source_file_status 造数)
|
||
# monkeypatch resolve 第一次返回 parse_failed+sha,或真实落库后调用
|
||
code = "DSV360_AWSDU"
|
||
resp = client.post(f"{API_PREFIX}/sources/{code}/retry-rpa", headers=admin_headers)
|
||
assert resp.status_code == 200
|
||
body = resp.get_json()["data"]
|
||
assert body["ok"] is True
|
||
assert body["file_status"] == "ready"
|
||
assert body.get("reparsed") is True
|
||
assert called["sync"] == 1
|
||
assert called["rpa"] == 0
|
||
```
|
||
|
||
另加:`sync` 返回 True 但投影仍 `parse_failed` → `ok is False` 且 `rpa==0`。
|
||
|
||
- [ ] **Step 2: 实现分支**
|
||
|
||
在 `retry_source_rpa_api` 开头(`trigger_receipt_rpa` 之前):
|
||
|
||
```python
|
||
from datetime import datetime
|
||
from app.services.in_transit_transfer.date_policy import business_date_now
|
||
from app.services.in_transit_transfer.evidence_sync import sync_and_commit_for_callback
|
||
from app.services.in_transit_transfer.source_file_status import resolve_source_file_status
|
||
|
||
source_code = str(source_code).strip()
|
||
status = resolve_source_file_status(source_code=source_code)
|
||
if status.get("file_status") == "parse_failed" and status.get("file_sha256"):
|
||
ok = sync_and_commit_for_callback(
|
||
source_code=source_code,
|
||
business_date=str(business_date_now()),
|
||
now=datetime.utcnow(),
|
||
)
|
||
status = resolve_source_file_status(source_code=source_code)
|
||
ready = bool(ok) and status.get("file_status") == "ready"
|
||
return _ok({
|
||
"source_code": source_code,
|
||
"ok": ready,
|
||
"file_status": status["file_status"],
|
||
"reparsed": True,
|
||
})
|
||
# else: 既有 trigger_receipt_rpa 路径(保持 202 + fetching)
|
||
```
|
||
|
||
更新该函数 docstring:parse_failed 优先本地重解析。
|
||
|
||
- [ ] **Step 3: Run 测试**
|
||
|
||
Run: `cd backend && python -m pytest tests/api/test_in_transit_transfer_api.py -k retry_rpa -q`
|
||
Expected: 新用例 PASS
|
||
|
||
- [ ] **Step 4: Stage**
|
||
|
||
```bash
|
||
git add backend/app/api/in_transit_transfer.py backend/tests/api/test_in_transit_transfer_api.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 5: 前端类型 / 勾选卡 / 匹配卡顶栏 / 四语言
|
||
|
||
**Files:**
|
||
- Modify: `frontend/src/features/chat/types/transfer.types.ts`
|
||
- Modify: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue`
|
||
- Modify: `frontend/src/features/chat/components/messages/TransferMatchCard.vue`(`failedSources`)
|
||
- Modify: `frontend/src/locales/zh-CN/chat.json`、`zh-TW/chat.json`、`en/chat.json`、`th/chat.json`(`chat.transfer.fileParseFailed`)
|
||
- Test: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||
- Create: `frontend/src/features/chat/components/messages/TransferMatchCard.spec.ts`(仅测 failedSources 过滤;无既有 spec)
|
||
|
||
**Interfaces:**
|
||
- Consumes: API `file_status: 'parse_failed'`;匹配卡 `sources[].error_code`
|
||
- Produces: 徽标文案;`isRetryable` 含 `parse_failed`;`confirm()` **只 emit** `has_ready_file` 来源(现状是「至少一 ready 则 emit 全部勾选」——必须改);匹配卡顶栏排除 `TRANSFER.ROUTE_NOT_RESOLVED`
|
||
|
||
- [ ] **Step 1: 写前端失败测试**
|
||
|
||
```typescript
|
||
it('勾选 ready+parse_failed 确认时只提交 ready 来源', async () => {
|
||
const sources = [
|
||
{ source_code: 'DSV-OK', display_name: 'ok', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' as const },
|
||
{ source_code: 'DSV-BAD', display_name: 'bad', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'parse_failed' as const },
|
||
];
|
||
const wrapper = mountCard({}, sources);
|
||
await wrapper.find('[data-testid="transfer-source-option-DSV-OK"] input').setValue(true);
|
||
await wrapper.find('[data-testid="transfer-source-option-DSV-BAD"] input').setValue(true);
|
||
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
|
||
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DSV-OK']);
|
||
});
|
||
|
||
it('parse_failed 显示解析失败徽标且可重试', async () => {
|
||
const wrapper = mountCard({}, [
|
||
{ source_code: 'DSV-BAD', display_name: 'bad', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'parse_failed' as const },
|
||
]);
|
||
expect(wrapper.find('[data-testid="transfer-source-status-DSV-BAD"]').text()).toBe('解析失败');
|
||
expect((wrapper.find('[data-testid="transfer-source-retry-DSV-BAD"]').element as HTMLButtonElement).disabled).toBe(false);
|
||
});
|
||
```
|
||
|
||
修改既有「全选可见再确认」用例期望:由
|
||
`['DBS-AWSBI', 'DBS-AWSSG', 'CRANE-SZ']` → `['DBS-AWSBI', 'CRANE-SZ']`(静默丢掉无 ready)。
|
||
|
||
`TransferMatchCard.spec.ts`(mount 最小 props:`sources` + 空 `items`):
|
||
|
||
```typescript
|
||
it('顶栏不展示 ROUTE_NOT_RESOLVED 来源失败(路由只行内)', () => {
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: {
|
||
summary: {
|
||
matching_id: 'MTG-T', business_date: '2026-08-06',
|
||
executable_count: 0, blocked_count: 0, not_matured_count: 0,
|
||
pending_stock_check_count: 0, invalid_count: 0,
|
||
},
|
||
items: [],
|
||
selected: new Set<number>(),
|
||
sources: [
|
||
{ source_code: 'A', stage: 'failed', error_code: 'TRANSFER.ROUTE_NOT_RESOLVED', error_message: 'route not resolved' },
|
||
{ source_code: 'B', stage: 'failed', error_code: 'TRANSFER_FILE_SCHEMA_INVALID', error_message: 'schema' },
|
||
],
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
const banner = wrapper.find('[data-testid="transfer-match-failed-sources"]');
|
||
expect(banner.exists()).toBe(true);
|
||
expect(banner.text()).not.toContain('route not resolved');
|
||
expect(banner.text()).toContain('schema');
|
||
});
|
||
```
|
||
|
||
(`summary` 字段以 `TransferMatchingSummary` 实际必填为准;缺字段按类型补齐默认值。)
|
||
|
||
- [ ] **Step 2: Run 确认失败**
|
||
|
||
```bash
|
||
cd frontend && npx vitest run \
|
||
src/features/chat/components/messages/TransferSourceSelectCard.spec.ts \
|
||
src/features/chat/components/messages/TransferMatchCard.spec.ts
|
||
```
|
||
|
||
Expected: 新用例 FAIL / 全选用例 FAIL
|
||
|
||
- [ ] **Step 3: 实现**
|
||
|
||
1. `transfer.types.ts`:两处 `file_status` 联合类型加入 `'parse_failed'`。
|
||
2. `confirm()` —— **相对现状的关键 diff**:现状在 `selectedHasReadyFile` 为真时 `emit('confirm', [...selected.value], ...)`(会带上无文件勾选项);改为:
|
||
|
||
```typescript
|
||
function confirm() {
|
||
if (selectedCount.value === 0) {
|
||
notifyWarning(t('chat.transfer.needSelectSource'), t('chat.transfer.sourceSelectTitle'));
|
||
return;
|
||
}
|
||
const readyCodes = [...selected.value].filter(
|
||
(code) => props.sources.find((s) => s.source_code === code)?.has_ready_file,
|
||
);
|
||
if (readyCodes.length === 0) {
|
||
notifyWarning(t('chat.transfer.needReadyFile'), t('chat.transfer.sourceSelectTitle'));
|
||
return;
|
||
}
|
||
emit('confirm', readyCodes, { from: dateFrom.value || undefined, to: dateTo.value || undefined }, transferType.value);
|
||
}
|
||
```
|
||
|
||
3. `isRetryable`:增加 `source.file_status === 'parse_failed'`;更新函数注释。
|
||
4. 模板:`v-else-if="source.file_status === 'parse_failed'"` 徽标 + `t('chat.transfer.fileParseFailed')`(`data-testid="transfer-source-status-..."` 复用现有)。
|
||
5. `TransferMatchCard.vue`:
|
||
|
||
```typescript
|
||
const HIDDEN_SOURCE_BANNER_CODES = new Set(['TRANSFER.ROUTE_NOT_RESOLVED']);
|
||
|
||
const failedSources = computed(() =>
|
||
(props.sources ?? []).filter(
|
||
(source) =>
|
||
(source.error_code || source.error_message) &&
|
||
!HIDDEN_SOURCE_BANNER_CODES.has(String(source.error_code || '')),
|
||
),
|
||
);
|
||
```
|
||
|
||
给顶栏容器加 `data-testid="transfer-match-failed-sources"`。更新文件头注释:路由失败不进顶栏。
|
||
|
||
6. 四语言键(放在既有 `fileFailed` / `fileExpired` 旁):
|
||
|
||
| 语言 | `chat.transfer.fileParseFailed` |
|
||
| --- | --- |
|
||
| zh-CN | 解析失败 |
|
||
| zh-TW | 解析失敗 |
|
||
| en | Parse failed |
|
||
| th | แยกวิเคราะห์ไม่สำเร็จ |
|
||
|
||
- [ ] **Step 4: Run vitest + build**
|
||
|
||
```bash
|
||
cd frontend && npx vitest run \
|
||
src/features/chat/components/messages/TransferSourceSelectCard.spec.ts \
|
||
src/features/chat/components/messages/TransferMatchCard.spec.ts
|
||
cd frontend && npm run build
|
||
```
|
||
|
||
Expected: PASS / build OK
|
||
|
||
- [ ] **Step 5: Stage**
|
||
|
||
```bash
|
||
git add frontend/src/features/chat/types/transfer.types.ts \
|
||
frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue \
|
||
frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts \
|
||
frontend/src/features/chat/components/messages/TransferMatchCard.vue \
|
||
frontend/src/features/chat/components/messages/TransferMatchCard.spec.ts \
|
||
frontend/src/locales/zh-CN/chat.json frontend/src/locales/zh-TW/chat.json \
|
||
frontend/src/locales/en/chat.json frontend/src/locales/th/chat.json
|
||
```
|
||
|
||
---
|
||
|
||
### Task 6: 文档一句 + 回归烟雾
|
||
|
||
**Files:**
|
||
- Modify: `docs/features/in-transit-transfer/technical.md`(来源文件状态枚举补 `parse_failed`;错误分层一句)
|
||
|
||
- [ ] **Step 1: 更新 technical.md**
|
||
|
||
在描述 `/sources` 或 `file_status` 处追加:`parse_failed`=当日文件在但 movement 解析失败(`has_ready_file=false`);路由失败仅行内 `blocked_route_not_resolved`,不抬升来源顶栏。
|
||
|
||
- [ ] **Step 2: 定向回归**
|
||
|
||
```bash
|
||
cd backend && python -m pytest \
|
||
tests/services/in_transit_transfer/test_source_file_status.py \
|
||
tests/services/in_transit_transfer/test_matching_service.py \
|
||
tests/services/in_transit_transfer/test_evidence_sync.py \
|
||
tests/api/test_in_transit_transfer_api.py -k "retry or source" -q
|
||
cd frontend && npx vitest run src/features/chat/components/messages/TransferSourceSelectCard.spec.ts
|
||
```
|
||
|
||
Expected: 全绿
|
||
|
||
- [ ] **Step 3: Stage**
|
||
|
||
```bash
|
||
git add docs/features/in-transit-transfer/technical.md
|
||
```
|
||
|
||
---
|
||
|
||
## Self-review
|
||
|
||
| 设计要求 | 任务 |
|
||
| --- | --- |
|
||
| parse_failed 扩 file_status + 落库 | T1–T2 |
|
||
| sync/align 写清标记(桥 rollback 后再 commit 标记) | T3 |
|
||
| 路由只行内(去抬升) | T3 |
|
||
| 历史匹配卡顶栏过滤 ROUTE | T5 |
|
||
| retry 先 re-sync(`str(business_date_now())`) | T4 |
|
||
| 勾选徽标 + confirm **静默过滤**非 ready + i18n | T5 |
|
||
| 文档 | T6 |
|
||
| 不做 B 排除条 / 路由预检 / stale·file_current 文案 | 全局约束 D5 |
|
||
|
||
无 TBD 占位;接口名与仓库现状对齐(`retry_source_rpa_api`、`API_PREFIX`、`TRANSFER.ROUTE_NOT_RESOLVED`)。
|