外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。 Co-authored-by: Cursor <cursoragent@cursor.com>
464 lines
26 KiB
Markdown
464 lines
26 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:** 来源选择卡按调拨类型声明的记录类型,分行内括号显示入站/出站状态,并用一个批量按钮和一个下载按钮按流重试、按目录打包。
|
||
|
||
**Architecture:** 一条调拨类型要哪些证据流,从它已有的范围规则里推导:字段为 `record_kind` 的规则值。没有这种规则时结果是 `("inbound", "outbound")`。状态投影、批量重试、下载打包和匹配圈档都读这个推导结果。不新增表字段,不改调拨类型表单。`resolve_source_file_status` 增加 `record_kind`,默认 `inbound`,这只是单流查询的参数缺省,不是类型没写规则时的业务默认。来源 API 在保留入站扁平字段的同时增加 `streams`。前端只按 `streams` 画括号。
|
||
|
||
**Tech Stack:** Flask、SQLAlchemy 2.0、Alembic、Vue 3、Vitest、pytest。后端测试在 `backend/`,Python 用 `backend/.venv/Scripts/python.exe`。
|
||
|
||
**Spec:** `docs/superpowers/specs/2026-10-19-transfer-evidence-stream-ui-design.md`
|
||
|
||
## Global Constraints
|
||
|
||
- 状态粒度是来源实例 × 记录类型。不拆来源行,不做「部分就绪」。
|
||
- 不新增调拨类型字段,不改调拨类型表单。入站还是出站,读该类型已有的范围规则:字段为 `record_kind`(表单下拉里的「记录类型」)的那几条,值里的 `inbound` / `outbound`。
|
||
- 一条类型没有「记录类型」规则时,入站和出站都要。规则里只写了其中一种,就只要那一种。来源卡、批量重试、下载、圈档都读这一结果,不看类型编码。
|
||
- 来源行只显示当前调拨类型声明的证据流。缺报表配置时状态为「未配置」。
|
||
- 行形态:`DSV360_AWSBI_BYAWSCMH01 [入站 √就绪 ↻] [出站 ⟳抓取中]`。重试是括号内的 `↻`,可读名称「重试入站」或「重试出站」。抓取中不显示 `↻`。行上不出现「重试」「文件」。
|
||
- 点状态字展开该流当天清单:文件名、抓取时间、sha256、文件大小、预览、下载。不解析 Excel,不新增行数字段。
|
||
- 选择条仍是三个按钮。下载文案为「下载证据文件」。压缩包名 `evidence-files-<n>.zip`,路径 `inbound/<source_code>/<filename>` 与 `outbound/<source_code>/<filename>`,只打包当前类型所需且已就绪的文件。
|
||
- 批量重试仍是一个按钮。按当前调拨类型的 `record_kinds`,只重试尚未就绪、且不是抓取中、且已配置的流。行上的 `↻` 可对已就绪的流强制重试。
|
||
- 确认匹配:该来源每一条所需流为 `ready` 或 `no_data` 才可提交。混合选择沿用披露条,并写明记录类型。
|
||
- 圈档固定条件里的 `record_kind='inbound'` 改为 `record_kinds_of(该类型的范围规则)`。没有类型对象的调用方显式只圈入站。
|
||
- 不拆两个下载按钮,不拆两个批量按钮,不为出站复制来源实例行,不改 Worker、排程和回调契约。
|
||
- 新增用户可见文案同时写入 `zh-CN` / `zh-TW` / `en` / `th`。
|
||
- 每个任务结束于 `git add`。不要在计划步骤里 `git commit`。
|
||
|
||
## File Structure
|
||
|
||
- `backend/app/services/in_transit_transfer/scope_rules.py`:从已有范围规则推导 `record_kinds_of`。不改表,不写迁移。
|
||
- `backend/app/services/in_transit_transfer/source_file_status.py`:按 `record_kind` 投影,缺配置为 `unconfigured`。
|
||
- `backend/app/api/in_transit_transfer/__init__.py`:`/sources` 增加 `streams`;重试与批量重试接受记录类型;下载改目录;新增证据清单。
|
||
- `backend/app/services/in_transit_transfer/matching_service.py`:`create_matching` 把 `record_kinds_of(类型.scope_rules)` 传入圈档底座。底座默认仍是入站。
|
||
- `frontend/src/features/chat/types/transfer.types.ts`、`api/transfer.api.ts`、`components/messages/TransferSourceSelectCard.vue`:括号行、清单、一个下载按钮、一个批量按钮。
|
||
- `frontend/src/locales/{zh-CN,zh-TW,en,th}/chat.json`:来源卡新文案。调拨类型页不改。
|
||
|
||
## 界面框线
|
||
|
||
调拨类型页不改。要出站时,仍用现有范围规则,字段选「记录类型」,值写 `outbound` 或同时写 `inbound` 与 `outbound`。
|
||
|
||
```text
|
||
+--------------------------------------------------+
|
||
| 范围规则 |
|
||
| 字段 [记录类型 v] 匹配 [等于 v] 值 [outbound] |
|
||
+--------------------------------------------------+
|
||
```
|
||
|
||
Task 7 只改来源选择卡。当前类型的范围规则里,「记录类型」只写了 inbound:
|
||
|
||
```text
|
||
+----------------------------------------------------------+
|
||
| 选择出入站来源实例 |
|
||
| 调拨类型 (在途仓至HUB仓) HUB仓维修出 HUB仓维修入 |
|
||
| 异动日期 [2026-10-14] ~ [2026-10-14] |
|
||
| 已选 10 个来源实例,其中 10 个可重试 |
|
||
| [批量重试 RPA] [下载证据文件] [清空选择] |
|
||
| CRANE |
|
||
| [x] DSV360_AWSBI_BYAWSCMH01 [入站 √就绪 ↻] |
|
||
| [确认范围并匹配] |
|
||
+----------------------------------------------------------+
|
||
```
|
||
|
||
同一张卡。当前类型没有「记录类型」规则,或规则值里 inbound 和 outbound 都有。点「入站 √就绪」后,清单开在该行下面。抓取中的括号里没有 ↻。
|
||
|
||
```text
|
||
+----------------------------------------------------------+
|
||
| 调拨类型 (没有记录类型规则,或两种值都有) |
|
||
| [x] DSV360_AWSBI_BYAWSCMH01 |
|
||
| [入站 √就绪 ↻] [出站 ⟳抓取中] |
|
||
| +----------------------------------------------+ |
|
||
| | Inbound_20261014.xlsx | |
|
||
| | 2026-10-14 09:12 · 128 KB · a1b2c3d4… | |
|
||
| | [预览] [下载] | |
|
||
| +----------------------------------------------+ |
|
||
| [x] DSV360_AWSBI_BYAWSPRD01 |
|
||
| [入站 —无数据 ↻] [出站 —未配置] |
|
||
+----------------------------------------------------------+
|
||
```
|
||
|
||
「未配置」的括号里没有 ↻。文件大小来自归档的 `file_size`,框线里的 `128 KB` 只是示意。
|
||
|
||
---
|
||
|
||
### Task 1: 从已有范围规则推导证据流
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/in_transit_transfer/scope_rules.py`
|
||
- Test: `backend/tests/services/in_transit_transfer/test_scope_rules.py`(没有则新建)
|
||
|
||
**Interfaces:**
|
||
- Consumes: `parse_scope_rules` 得到的 `ScopeRule`。字段名已在 `SCOPE_FIELDS` 里,就是 `record_kind`。
|
||
- Produces: `record_kinds_of(rules: tuple[ScopeRule, ...]) -> tuple[str, ...]`。只认值 `inbound` 与 `outbound`,按这个顺序去重。没有任何 `field == "record_kind"` 的规则时返回 `("inbound", "outbound")`。多条这种规则取值的交集;交集为空时返回 `()`。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
```python
|
||
def test_record_kinds_of_reads_existing_scope_rule():
|
||
"""没有记录类型规则时入站和出站都要;只写 outbound 时只要出站。"""
|
||
assert record_kinds_of(parse_scope_rules([
|
||
{"field": "doc_no", "match": "prefix", "values": ["HOM"]},
|
||
])) == ("inbound", "outbound")
|
||
assert record_kinds_of(parse_scope_rules([
|
||
{"field": "record_kind", "match": "equals", "values": ["outbound"]},
|
||
])) == ("outbound",)
|
||
assert record_kinds_of(parse_scope_rules([
|
||
{"field": "record_kind", "match": "in", "values": ["outbound", "inbound"]},
|
||
])) == ("inbound", "outbound")
|
||
```
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_scope_rules.py::test_record_kinds_of_reads_existing_scope_rule -v`
|
||
|
||
Expected: FAIL,`record_kinds_of` 未定义。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
在 `scope_rules.py` 实现 `record_kinds_of`。不要加模型列,不要写迁移,不要改调拨类型表单。启用类型 API 若把推导结果放进响应,字段名用 `record_kinds`,值只能来自这个函数。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_scope_rules.py -v`
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```bash
|
||
git add backend/app/services/in_transit_transfer/scope_rules.py backend/tests/services/in_transit_transfer/test_scope_rules.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 2: 按记录类型投影文件状态
|
||
|
||
**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:**
|
||
- Consumes: `queries.get_inbound_config` / `get_outbound_config`,`latest_usable_inbound_file`,出站文件与 `FreightRpaOutboundUnitRun` 的同口径查询。
|
||
- Produces: `resolve_source_file_status(*, source_code: str, record_kind: str = "inbound") -> dict`。`record_kind="inbound"` 时返回值与今天相同。`record_kind="outbound"` 且 `get_outbound_config` 为 `None` 时返回 `{"file_status": "unconfigured", "has_ready_file": False, "file_no": None, "file_sha256": None}`。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
```python
|
||
def test_outbound_without_config_is_unconfigured(monkeypatch):
|
||
"""没有出站报表配置时,出站流是未配置,入站投影函数签名仍可只传来源。"""
|
||
monkeypatch.setattr(
|
||
"app.services.in_transit_transfer.source_file_status.get_outbound_config",
|
||
lambda source_code: None,
|
||
)
|
||
status = resolve_source_file_status(source_code="DSV360_AWSBI", record_kind="outbound")
|
||
assert status["file_status"] == "unconfigured"
|
||
assert status["has_ready_file"] is False
|
||
```
|
||
|
||
再写一条:出站存在可用文件时 `file_status == "ready"`。查询函数按入站 `latest_usable_inbound_file` 的返回形状做 monkeypatch,不连真实 MinIO。
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_source_file_status.py::test_outbound_without_config_is_unconfigured -v`
|
||
|
||
Expected: FAIL,`record_kind` 意外参数或没有 `unconfigured`。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
`record_kind` 不是 `inbound`/`outbound` 时抛 `ValidationError`。入站分支保持现有顺序:可用文件 → 解析失败 → 进行中单元 → 失败 → `no_data` → 过期 → `none`。出站先查配置,没有则 `unconfigured`;有配置则用出站文件表和 `FreightRpaOutboundUnitRun` 走同一顺序。默认参数 `record_kind="inbound"`,不改 `execution_service` 等现有调用。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_source_file_status.py tests/services/in_transit_transfer/test_evidence_sync.py -v`
|
||
|
||
Expected: PASS。既有入站用例仍绿。
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```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: 来源列表返回 streams
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/api/in_transit_transfer/__init__.py`(`transfer_sources_api`)
|
||
- Test: `backend/tests/api/test_in_transit_transfer_api.py`
|
||
|
||
**Interfaces:**
|
||
- Consumes: `resolve_source_file_status(*, source_code, record_kind)`。
|
||
- Produces: 每个来源除现有 `file_status` / `has_ready_file`(等于入站流,供尚未改完的前端)外,增加
|
||
|
||
```python
|
||
"streams": [
|
||
{"record_kind": "inbound", "file_status": "ready", "has_ready_file": True, "file_no": "...", "file_sha256": "..."},
|
||
{"record_kind": "outbound", "file_status": "unconfigured", "has_ready_file": False, "file_no": None, "file_sha256": None},
|
||
]
|
||
```
|
||
|
||
两条都返回,前端按类型过滤。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
在来源列表用例中断言响应里 `DSV` 来源的 `streams` 长度为 2,且 `streams[0]["record_kind"] == "inbound"`,`file_status` 仍等于入站那条的 `file_status`。用现有测试夹具里的来源码,不要新造平台。
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py -k sources -v`
|
||
|
||
Expected: FAIL,响应没有 `streams`。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
`transfer_sources_api` 对每个来源调用两次投影,组装 `streams`。扁平字段继续取 `record_kind="inbound"` 的结果。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py -k sources -v`
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```bash
|
||
git add backend/app/api/in_transit_transfer/__init__.py backend/tests/api/test_in_transit_transfer_api.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 4: 重试按证据流,批量按调拨类型
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/api/in_transit_transfer/__init__.py`(`retry_source_rpa_api`、`retry_sources_rpa_batch_api`)
|
||
- Modify: `backend/app/services/in_transit_transfer/inbound_trigger_service.py` 与 `outbound_trigger_service.py`(只在 API 层选择调用哪个,不合并两个 trigger 实现)
|
||
- Test: `backend/tests/api/test_in_transit_transfer_api.py`
|
||
|
||
**Interfaces:**
|
||
- Consumes: `trigger_inbound_rpa`、`trigger_outbound_rpa`、`trigger_*_rpa_batch`、`get_by_code(transfer_type).record_kinds`。
|
||
- Produces: `POST /sources/<code>/retry-rpa` 请求体 `{"record_kind": "outbound"}`,缺省 `inbound`。`POST /sources/retry-rpa-batch` 请求体 `{"source_codes": [...], "transfer_type": "hub_to_hub"}`。批量结果每项增加 `record_kind`。已 `ready`、`fetching`、`unconfigured` 的流不写入 trigger。`no_data` / `failed` / `expired` / `none` / `parse_failed` 会进入对应流的重试。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
```python
|
||
def test_batch_retry_skips_ready_inbound_and_triggers_outbound(client, monkeypatch):
|
||
"""HUB 仓间调拨:入站已就绪不重抓,出站未就绪才触发。"""
|
||
def fail_inbound(**kwargs):
|
||
raise AssertionError("inbound batch")
|
||
|
||
called = {}
|
||
|
||
def record_outbound(**kwargs):
|
||
called["codes"] = kwargs["source_codes"]
|
||
return {"ok": True, "triggered": True}
|
||
|
||
def status(*, source_code, record_kind="inbound"):
|
||
if record_kind == "outbound":
|
||
return {"file_status": "none", "has_ready_file": False, "file_no": None, "file_sha256": None}
|
||
return {"file_status": "ready", "has_ready_file": True, "file_no": "a.xlsx", "file_sha256": "abc"}
|
||
|
||
monkeypatch.setattr(api_module, "trigger_inbound_rpa_batch", fail_inbound)
|
||
monkeypatch.setattr(api_module, "trigger_outbound_rpa_batch", record_outbound)
|
||
monkeypatch.setattr(api_module, "resolve_source_file_status", status)
|
||
response = client.post("/api/in-transit-transfer/sources/retry-rpa-batch", json={
|
||
"source_codes": ["DSV360_AWSBI"],
|
||
"transfer_type": "hub_to_hub",
|
||
})
|
||
assert response.status_code == 202
|
||
assert called["codes"] == ["DSV360_AWSBI"]
|
||
```
|
||
|
||
`api_module` 指 `app.api.in_transit_transfer`。蓝图前缀是 `/api/in-transit-transfer`。夹具若没有启用的 `hub_to_hub`,本测试用 `create_config` 建一个,`record_kinds` 为 `["inbound", "outbound"]`。
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py::test_batch_retry_skips_ready_inbound_and_triggers_outbound -v`
|
||
|
||
Expected: FAIL,请求体没有 `transfer_type` 或仍只调用入站 batch。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
单源端点读取 `record_kind`,出站走 `trigger_outbound_rpa`,`parse_failed` 仍只对入站做本地重解析;出站 `parse_failed` 重新触发出站 RPA。批量端点读取类型的 `record_kinds`,按流分组后最多写一个入站 batch 和一个出站 batch。`unconfigured` 记入结果 `ok: false`,`error_code` 用现有配置缺失码,不新增错误码。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py -k retry -v`
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```bash
|
||
git add backend/app/api/in_transit_transfer/__init__.py backend/tests/api/test_in_transit_transfer_api.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 5: 证据压缩包与当天清单
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/api/in_transit_transfer/__init__.py`(`download_source_inbound_files_api`,并新增清单路由)
|
||
- Test: `backend/tests/api/test_in_transit_transfer_api.py`
|
||
|
||
**Interfaces:**
|
||
- Consumes: 可用入站/出站归档文件、`file_asset_storage.get_bytes`、`file_asset_storage.presigned_get_url`。
|
||
- Produces:
|
||
- `POST /sources/inbound-files` 请求体增加 `transfer_type`。压缩包内路径为 `inbound/<source_code>/<filename>` 或 `outbound/<source_code>/<filename>`。下载名 `evidence-files-<n>.zip`。审计事件类型仍是 `TRANSFER_INBOUND_FILES_DOWNLOADED`。
|
||
- `GET /sources/<source_code>/evidence-files?record_kind=inbound` 返回 `[{file_id, original_filename, created_at, sha256, file_size, presigned_url}]`,只含当天可用文件。签发 URL 时写同一审计事件,`aggregate_id` 为 `source_code`。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
用 `zipfile.ZipFile` 读响应体。类型的范围规则把记录类型收成只要 inbound 时,名单包含 `inbound/DSV360_AWSBI/Inbound.xlsx`,且不包含 `outbound/`。没有记录类型规则时,两种就绪文件都打进包。清单用例断言 JSON 含 `file_size` 与 `presigned_url`,不含解析出的行数。
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py -k "evidence or inbound_files" -v`
|
||
|
||
Expected: FAIL,路径仍是 `<code>-<filename>` 或清单路由 404。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
下载循环按类型的 `record_kinds` 各取该来源最新可用文件,`archive.writestr(f"{kind}/{code}/{safe_name}", data)`。两种都没有文件时仍 `NotFoundError(..., code="SHIPPING.INBOUND_FILE_NOT_FOUND")`。清单查询复用下载用的可用文件条件,但返回当天全部可用文件而不只最新一份。`presigned_get_url(..., expires_seconds=300)`。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py -k "evidence or inbound_files" -v`
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```bash
|
||
git add backend/app/api/in_transit_transfer/__init__.py backend/tests/api/test_in_transit_transfer_api.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 6: 圈档跟随调拨类型的记录类型
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/in_transit_transfer/matching_service.py`(`_circle_ledger_base_query` 与 `create_matching` 附近的调用)
|
||
- Test: `backend/tests/services/in_transit_transfer/test_matching_service.py`
|
||
|
||
**Interfaces:**
|
||
- Consumes: `record_kinds_of(config.scope_rules)`。
|
||
- Produces: `_circle_ledger_base_query(*, record_kinds: tuple[str, ...], exclude_occupied_by_matching_id: int | None = None)`。`record_kinds` 必传,避免再用入站当隐式默认。`_circle_ledger_records` 增加同名参数并传给底座。`create_matching` 与 `circle_ledger_records_scope_union` 传入 `record_kinds_of(...)`。没有类型对象的调用点显式传入 `("inbound",)`。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
```python
|
||
def test_hub_to_hub_circles_outbound_ledger_rows(deps):
|
||
"""没有记录类型规则的类型圈入出站档;范围规则写明只要 inbound 的类型不圈。"""
|
||
_insert_ledger(source_code="DSV360_AWSBI", record_kind="outbound", doc_no="HOX1", movement_date="2026-10-14")
|
||
circled = create_matching(
|
||
source_codes=["DSV360_AWSBI"],
|
||
business_date="2026-10-14",
|
||
movement_date_from="2026-10-14",
|
||
movement_date_to="2026-10-14",
|
||
transfer_type="hub_to_hub",
|
||
deps=deps,
|
||
)
|
||
assert "HOX1" in {item.doc_no for item in items_of(circled)}
|
||
inbound_only = create_matching(
|
||
source_codes=["DSV360_AWSBI"],
|
||
business_date="2026-10-14",
|
||
movement_date_from="2026-10-14",
|
||
movement_date_to="2026-10-14",
|
||
transfer_type="in_transit_to_hub",
|
||
deps=deps,
|
||
)
|
||
assert "HOX1" not in {item.doc_no for item in items_of(inbound_only)}
|
||
```
|
||
|
||
`_insert_ledger` 与 `items_of` 按本文件已有的落档、读明细写法就地写,断言只看 `doc_no`。`hub_to_hub` 的范围规则不写记录类型。`in_transit_to_hub` 的范围规则必须有一条 `record_kind` 等于 `inbound`,否则会把 `HOX1` 也圈进来。
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_matching_service.py::test_hub_to_hub_circles_outbound_ledger_rows -v`
|
||
|
||
Expected: FAIL,出站行被 `record_kind='inbound'` 滤掉。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
底座过滤改为 `TransferMovementLedger.record_kind.in_(record_kinds)`。`_circle_ledger_records` 把 `record_kinds` 传给底座。`create_matching` 传入 `record_kinds_of(当前类型.scope_rules)`。`circle_ledger_records_scope_union` 对每个 `config` 传入 `record_kinds_of(config.scope_rules)`。没有类型对象的调用点不改参数。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_matching_service.py -v`
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```bash
|
||
git add backend/app/services/in_transit_transfer/matching_service.py backend/tests/services/in_transit_transfer/test_matching_service.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 7: 来源选择卡与调拨类型表单
|
||
|
||
**Files:**
|
||
- Modify: `frontend/src/features/chat/types/transfer.types.ts`
|
||
- Modify: `frontend/src/features/chat/api/transfer.api.ts`
|
||
- Modify: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue`
|
||
- Modify: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||
- Modify: `frontend/src/locales/zh-CN/chat.json`、`zh-TW/chat.json`、`en/chat.json`、`th/chat.json`
|
||
|
||
**Interfaces:**
|
||
- Consumes: `streams[]`、`record_kinds`、`POST retry-rpa` 的 `record_kind`、`POST retry-rpa-batch` 的 `transfer_type`、`GET evidence-files`、`POST inbound-files` 的 `transfer_type`。
|
||
- Produces: 卡片只渲染当前类型 `record_kinds` 里的括号。状态字按钮的 `aria-expanded` 控制行下清单。`↻` 的 `aria-label` 为 i18n「重试入站」或「重试出站」。`file_status === 'fetching'` 时不渲染 `↻`。
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
在 `TransferSourceSelectCard.spec.ts` 增加来源:
|
||
|
||
```typescript
|
||
const hubSource = {
|
||
source_code: 'DSV360_AWSBI_BYAWSCMH01',
|
||
display_name: 'CMH01',
|
||
platform: 'crane',
|
||
enabled: true,
|
||
has_ready_file: true,
|
||
file_status: 'ready' as const,
|
||
streams: [
|
||
{ record_kind: 'inbound' as const, file_status: 'ready' as const, has_ready_file: true },
|
||
{ record_kind: 'outbound' as const, file_status: 'fetching' as const, has_ready_file: false },
|
||
],
|
||
};
|
||
```
|
||
|
||
断言类型为 `hub_to_hub`(两种记录类型)时,文本含 `[入站 √就绪]` 与 `[出站 ⟳抓取中]`,出站括号内没有重试按钮,入站括号内的按钮 `aria-label` 为「重试入站」。类型为 `in_transit_to_hub` 时不出现「出站」。组件内不出现按钮文案「文件」。下载按钮文案为「下载证据文件」。
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
Run: `npm run test -- src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||
|
||
工作目录:`frontend/`。
|
||
|
||
Expected: FAIL,仍渲染单个「文件已就绪」和「下载入站文件」。
|
||
|
||
- [ ] **Step 3: Write minimal implementation**
|
||
|
||
`TransferSourceOption.streams` 为 `{ record_kind: 'inbound' | 'outbound'; file_status: ...; has_ready_file: boolean }[]`。状态字映射:`ready` → `√就绪`,`fetching` → `⟳抓取中`,`failed` → `×失败`,`no_data` → `—无数据`,`expired` → `!已过期`,`parse_failed` → `!解析失败`,`none` → `—无文件`,`unconfigured` → `—未配置`。前缀用 i18n「入站」「出站」。括号用文本,不用额外色块区分记录类型;就绪/失败仍可用现有绿/红字色,文字始终在。
|
||
|
||
点状态字调用 `listEvidenceFiles(sourceCode, recordKind)`,清单插在该行下方,按钮只有「预览」「下载」,都打开 `presigned_url`。批量重试提交 `{ source_codes, transfer_type }`。单行 `↻` 提交 `{ record_kind }`。确认门禁改为:所选类型的每条流都是 `ready` 或 `no_data`。披露条把未就绪流写成「来源编码 入站 抓取中」。
|
||
|
||
`downloadFiles` 的 zh-CN 改为「下载证据文件」,zh-TW「下載證據文件」,en「Download evidence files」,th「ดาวน์โหลดไฟล์หลักฐาน」。新增键走 `chat.transfer.streamInbound`、`streamOutbound`、`retryInbound`、`retryOutbound`、`previewEvidence`、`downloadEvidence`,四语言一起补。不改 `TransferTypesPage.vue`。来源卡用启用类型接口带回的 `record_kinds`(由 `record_kinds_of` 算出)决定画几条括号。
|
||
|
||
卡片上的来源编码、状态括号保持现在的 `text-xs` 密度,不把重试按钮放大到 44px。
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
Run: `npm run test -- src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||
|
||
Expected: PASS
|
||
|
||
- [ ] **Step 5: Stage changes**
|
||
|
||
```bash
|
||
git add frontend/src/features/chat/types/transfer.types.ts frontend/src/features/chat/api/transfer.api.ts frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue frontend/src/features/chat/components/messages/TransferSourceSelectCard.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
|
||
```
|