feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动
外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
911afa0f73
commit
4c2a7e2a23
145 files changed
+11695
-4214
No files matched your search
@@ -0,0 +1,463 @@
|
||||
# 调拨证据流状态、重试与下载 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
|
||||
```
|
||||
@@ -0,0 +1,571 @@
|
||||
# 当前归档重新解析 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:** 新服务 `reparse_current_file` 自己找出站或入站的最新可用归档,然后调用已经存在的 `sync_outbound_source_rows` / `sync_source_rows`(它们只 flush)。结构错误沿用现有 `mark_*_parse_failure`。HTTP 层只做鉴权、参数和 envelope。前端按钮只画在清单第一行,请求体不带 `file_id`。
|
||||
|
||||
**Tech Stack:** Flask、SQLAlchemy 2.0、Vue 3、Vitest、pytest。后端测试在 `backend/`,Python 用 `backend/.venv/Scripts/python.exe`。前端测试在 `frontend/`,用 `npx vitest run`。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-21-transfer-current-file-reparse-design.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 入站和出站各自有「重新解析」。当天该流已有可用归档时可以点,状态是就绪或解析失败都可以。
|
||||
- 只解析该流当前最新一份可用归档(`created_at`、`id` 倒序第一条,与 `latest_usable_*_file` 相同),并幂等写入异动档。不写 RPA trigger。
|
||||
- 请求不接受 `file_id`。服务端自己取最新一份,避免清单过期时重放历史文件。
|
||||
- 同一份文件再解析一次:摘要未变则跳过已有档行,不另插一行。
|
||||
- 没有可用归档:422 `TRANSFER.CURRENT_REPARSE_NO_FILE`。
|
||||
- 有归档但没有已发布的对应 purpose 规则:422 `TRANSFER.CURRENT_REPARSE_NO_PROFILE`。不把文件标成解析失败。规则缺失不是文件错误。
|
||||
- 结构校验失败(`MovementFileSchemaError`):回滚档行,把 `parse_failed` 写到当前文件,HTTP 200,`ok: false`,`file_status: parse_failed`,带 `error_message`。
|
||||
- 其他异常(数据库截断、连接失败):回滚,不标解析失败,HTTP 200,`ok: false`,`error_message` 为异常文本。文件状态保持原投影。
|
||||
- 成功:HTTP 200,`ok: true`,返回 `inserted` / `updated` / `skipped` / `sealed_skipped` 和解析后的 `file_status`。审计沿用落档函数已有的 `TRANSFER_EVIDENCE_SYNCED`,不另造事件。
|
||||
- `file_version` 只经 `movement_file_version`。本入口不自己拼版本戳。
|
||||
- 展开清单后只有第一行显示「重新解析」。↻ 与 `POST /sources/{source_code}/retry-rpa` 不变。
|
||||
- 不调用 `POST /backlog/pending-match/reparse`,不删除已有档行。
|
||||
- 新增用户可见文案同时写入 `zh-CN` / `zh-TW` / `en` / `th`。新增 `error.code` 同步写入四份 `locales/*/errors.json`。
|
||||
- 每个任务结束于 `git add`。不要在计划步骤里 `git commit`。
|
||||
|
||||
## File Structure
|
||||
|
||||
- `backend/app/services/in_transit_transfer/current_file_reparse.py`:取当前归档、调用既有落档函数、提交或回滚、返回计数。不触发 RPA,不拼 `file_version`。
|
||||
- `backend/app/api/in_transit_transfer/__init__.py`:新增 `POST /sources/<source_code>/reparse`。不改 `retry-rpa`。
|
||||
- `backend/tests/services/in_transit_transfer/test_current_file_reparse.py`:服务行为。
|
||||
- `backend/tests/api/test_in_transit_transfer_api.py`:无文件 422、无权限 403。
|
||||
- `frontend/src/features/chat/api/transfer.api.ts` 与 `types/transfer.types.ts`:请求与响应类型。
|
||||
- `frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue`:第一行按钮。
|
||||
- `frontend/src/features/chat/components/messages/TransferMessageView.vue`:成功后 `loadSources`。
|
||||
- `frontend/src/locales/{zh-CN,zh-TW,en,th}/chat.json` 与 `errors.json`:按钮文案和两个错误码。
|
||||
- `docs/features/in-transit-transfer/technical.md`、`docs/funclist.md`:登记入口。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 当前文件重解析服务
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/services/in_transit_transfer/current_file_reparse.py`
|
||||
- Create: `backend/tests/services/in_transit_transfer/test_current_file_reparse.py`
|
||||
- Test: `backend/tests/services/in_transit_transfer/test_current_file_reparse.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `sync_outbound_source_rows(*, source_code: str, now: datetime) -> SyncOutcome | None`;`sync_source_rows(*, source_code: str, deps, business_date: str, now: datetime) -> SyncOutcome | None`;`latest_usable_outbound_file` / `latest_usable_inbound_file`;`mark_outbound_parse_failure` / `mark_inbound_parse_failure`;`resolve_source_file_status(*, source_code: str, record_kind: str) -> dict`;`MovementFileSchemaError`。
|
||||
- Produces: `reparse_current_file(*, source_code: str, record_kind: str, now: datetime) -> CurrentReparseResult`。`CurrentReparseResult` 字段:`source_code: str`、`record_kind: str`、`ok: bool`、`file_status: str`、`file_id: int | None`、`inserted: int`、`updated: int`、`skipped: int`、`sealed_skipped: int`、`error_code: str | None`、`error_message: str | None`。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
新建 `backend/tests/services/in_transit_transfer/test_current_file_reparse.py`。文件头写明用途是锁定「当前归档重解析、不触发 RPA」。导入 `pytest`、`datetime`、`AppError`、`TransferAuditEvent`、`TransferMovementLedger`、`FreightRpaOutboundReportFile`、`FreightRpaOutboundUnitRun`、`reparse_current_file`、`movement_file_version`、`factories`。把 `test_outbound_evidence_sync.py` 里的 `outbound_storage` fixture 和 `_seed_outbound_world` 抄进来,来源仍用全局种子 `DSV360_AWSDU`,`created_at` 用 `datetime.utcnow()`,否则当天可用门禁会把文件看成过期。`pytestmark = [pytest.mark.usefixtures("app")]`。
|
||||
|
||||
```python
|
||||
def test_reparse_outbound_inserts_ledger_without_new_rpa_run(outbound_storage):
|
||||
# [断言意图] 已落地出站文件重解析后出现 outbound 档行,且不新增出站执行单元。
|
||||
report = _seed_outbound_world()
|
||||
runs_before = FreightRpaOutboundUnitRun.query.filter_by(source_code=SOURCE).count()
|
||||
outbound_storage.objects[STORAGE_KEY] = factories.build_movement_xlsx([
|
||||
["ASN-O1", "1", "O", "MAT-O1", "成品", "LOT-O1", 120, "2026-10-16"],
|
||||
])
|
||||
|
||||
result = reparse_current_file(source_code=SOURCE, record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
assert result.ok is True
|
||||
assert result.file_id == report.id
|
||||
assert result.inserted == 1
|
||||
assert result.file_status == "ready"
|
||||
assert TransferMovementLedger.query.filter_by(
|
||||
source_code=SOURCE, record_kind="outbound", doc_no="ASN-O1").count() == 1
|
||||
assert FreightRpaOutboundUnitRun.query.filter_by(source_code=SOURCE).count() == runs_before
|
||||
assert TransferAuditEvent.query.filter_by(event_type="TRANSFER_EVIDENCE_SYNCED").count() == 1
|
||||
|
||||
|
||||
def test_reparse_same_outbound_file_skips_existing_row(outbound_storage):
|
||||
# [断言意图] 同一份摘要再解析一次不插入第二行。
|
||||
_seed_outbound_world()
|
||||
outbound_storage.objects[STORAGE_KEY] = factories.build_movement_xlsx([
|
||||
["ASN-O1", "1", "O", "MAT-O1", "成品", "LOT-O1", 120, "2026-10-16"],
|
||||
])
|
||||
reparse_current_file(source_code=SOURCE, record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
again = reparse_current_file(source_code=SOURCE, record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
assert again.ok is True
|
||||
assert again.inserted == 0
|
||||
assert again.skipped == 1
|
||||
assert TransferMovementLedger.query.filter_by(
|
||||
source_code=SOURCE, record_kind="outbound").count() == 1
|
||||
|
||||
|
||||
def test_reparse_schema_failure_marks_file_and_lands_nothing(outbound_storage):
|
||||
# [断言意图] 单号缺失是结构失败:零档行,文件变为 parse_failed,响应带原因。
|
||||
report = _seed_outbound_world()
|
||||
outbound_storage.objects[STORAGE_KEY] = factories.build_movement_xlsx(
|
||||
[["", 100, "O", "MAT-X", "成品", "LOT-X", 30, "2026-10-16"]])
|
||||
|
||||
result = reparse_current_file(source_code=SOURCE, record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
assert result.ok is False
|
||||
assert result.file_status == "parse_failed"
|
||||
assert result.inserted == 0
|
||||
assert "missing_invoice_no" in (result.error_message or "")
|
||||
marked = FreightRpaOutboundReportFile.query.filter_by(id=report.id).one()
|
||||
assert marked.parse_failed_at is not None
|
||||
assert TransferMovementLedger.query.filter_by(
|
||||
source_code=SOURCE, record_kind="outbound").count() == 0
|
||||
|
||||
|
||||
def test_reparse_without_published_profile_does_not_mark_parse_failed(outbound_storage):
|
||||
# [断言意图] 规则未发布不是文件错误,不写 parse_failed。
|
||||
report = _seed_outbound_world(profile_status="draft")
|
||||
outbound_storage.objects[STORAGE_KEY] = factories.build_movement_xlsx([
|
||||
["ASN-O1", "1", "O", "MAT-O1", "成品", "LOT-O1", 120, "2026-10-16"],
|
||||
])
|
||||
|
||||
with pytest.raises(AppError) as exc_info:
|
||||
reparse_current_file(source_code=SOURCE, record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
assert exc_info.value.code == "TRANSFER.CURRENT_REPARSE_NO_PROFILE"
|
||||
marked = FreightRpaOutboundReportFile.query.filter_by(id=report.id).one()
|
||||
assert marked.parse_failed_at is None
|
||||
|
||||
|
||||
def test_reparse_without_file_raises():
|
||||
# [断言意图] 没有可用归档时拒绝,而不是去触发 RPA。
|
||||
with pytest.raises(AppError) as exc_info:
|
||||
reparse_current_file(
|
||||
source_code="DSV360_AWSDU", record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
assert exc_info.value.code == "TRANSFER.CURRENT_REPARSE_NO_FILE"
|
||||
assert exc_info.value.http_status == 422
|
||||
|
||||
|
||||
def test_reparse_non_schema_error_does_not_mark_parse_failed(outbound_storage, monkeypatch):
|
||||
# [断言意图] 数据库一类异常回滚后不把文件标成解析失败,并把异常文本带回。
|
||||
report = _seed_outbound_world()
|
||||
outbound_storage.objects[STORAGE_KEY] = factories.build_movement_xlsx([
|
||||
["ASN-O1", "1", "O", "MAT-O1", "成品", "LOT-O1", 120, "2026-10-16"],
|
||||
])
|
||||
|
||||
def _boom(**_kwargs):
|
||||
raise RuntimeError("value too long for varchar(64)")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.services.in_transit_transfer.current_file_reparse.sync_outbound_source_rows",
|
||||
_boom,
|
||||
)
|
||||
result = reparse_current_file(source_code=SOURCE, record_kind="outbound", now=datetime.utcnow())
|
||||
|
||||
assert result.ok is False
|
||||
assert result.error_code == "TRANSFER.CURRENT_REPARSE_FAILED"
|
||||
assert "varchar(64)" in (result.error_message or "")
|
||||
marked = FreightRpaOutboundReportFile.query.filter_by(id=report.id).one()
|
||||
assert marked.parse_failed_at is None
|
||||
assert TransferMovementLedger.query.filter_by(
|
||||
source_code=SOURCE, record_kind="outbound").count() == 0
|
||||
```
|
||||
|
||||
`_seed_outbound_world` 增加可选参数 `profile_status: str = "published"`,传给 `FreightRpaParsingProfile.status`。入站成功路径用下面这个测试,归档时间同样取 `datetime.utcnow()`:
|
||||
|
||||
```python
|
||||
def test_reparse_inbound_inserts_ledger(archive_storage):
|
||||
# [断言意图] 入站当前文件走 sync_source_rows,record_kind 为 inbound。
|
||||
source, _profile = factories.seed_inbound_reparse_source("CRANE_REPARSE_NOW")
|
||||
storage_key = "archive/CRANE_REPARSE_NOW/current.xlsx"
|
||||
report = factories.seed_reparse_archive_file(
|
||||
source, sha="c" * 64, storage_key=storage_key, created_at=datetime.utcnow())
|
||||
archive_storage.objects[storage_key] = factories.build_movement_xlsx([
|
||||
["ASN-I1", "1", "I", "MAT-I1", "连接器", "LOT-I1", 10, "2026-08-05"],
|
||||
])
|
||||
|
||||
result = reparse_current_file(
|
||||
source_code="CRANE_REPARSE_NOW", record_kind="inbound", now=datetime.utcnow())
|
||||
|
||||
assert result.ok is True
|
||||
assert result.file_id == report.id
|
||||
assert result.inserted == 1
|
||||
row = TransferMovementLedger.query.filter_by(
|
||||
source_code="CRANE_REPARSE_NOW", record_kind="inbound").one()
|
||||
assert row.doc_no == "ASN-I1"
|
||||
assert row.file_version == movement_file_version("c" * 64)
|
||||
```
|
||||
|
||||
`archive_storage` fixture 与 `test_backlog_reparse_service.py` 相同:替换 `file_asset_storage.get_bytes`。
|
||||
|
||||
- [ ] **Step 2: Run test to verify it fails**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_current_file_reparse.py -q`
|
||||
|
||||
Expected: FAIL,`reparse_current_file` 无法导入。
|
||||
|
||||
- [ ] **Step 3: Write minimal implementation**
|
||||
|
||||
新建 `backend/app/services/in_transit_transfer/current_file_reparse.py`。文件头写明:用途是对当前可用归档做一次本地重解析;依赖 `evidence_sync.sync_source_rows`、`outbound_evidence_sync.sync_outbound_source_rows`、`source_file_status`、`freight_rpa.reports.queries` 的 mark/latest 函数;逻辑是先确认文件和已发布规则,再落档并提交,失败按规格回滚。
|
||||
|
||||
```python
|
||||
@dataclass(frozen=True)
|
||||
class CurrentReparseResult:
|
||||
"""一次当前归档重解析的返回。"""
|
||||
|
||||
source_code: str
|
||||
record_kind: str
|
||||
ok: bool
|
||||
file_status: str
|
||||
file_id: int | None
|
||||
inserted: int = 0
|
||||
updated: int = 0
|
||||
skipped: int = 0
|
||||
sealed_skipped: int = 0
|
||||
error_code: str | None = None
|
||||
error_message: str | None = None
|
||||
|
||||
|
||||
def reparse_current_file(*, source_code: str, record_kind: str, now: datetime) -> CurrentReparseResult:
|
||||
"""重解析该来源当前最新可用归档并提交。
|
||||
|
||||
核心逻辑:先取 latest usable 文件。没有文件抛 CURRENT_REPARSE_NO_FILE。
|
||||
有文件则调用既有 sync_*_source_rows。返回 None 表示没有已发布规则,抛
|
||||
CURRENT_REPARSE_NO_PROFILE,不写 parse_failed。结构错误回滚后 mark_*_parse_failure
|
||||
并单独提交。其他异常只回滚,不标解析失败。成功路径由 sync 函数里的
|
||||
movement_file_version 写版本戳,本函数不拼 sha256: 前缀。
|
||||
|
||||
Args:
|
||||
source_code: 来源实例编码。
|
||||
record_kind: inbound 或 outbound。
|
||||
now: 落档与新鲜度判定时刻。
|
||||
Returns:
|
||||
CurrentReparseResult。结构错误和其他落档异常时 ok 为 False。
|
||||
Raises:
|
||||
ValidationError: record_kind 不是 inbound 或 outbound。
|
||||
AppError: TRANSFER.CURRENT_REPARSE_NO_FILE 或 TRANSFER.CURRENT_REPARSE_NO_PROFILE,HTTP 422。
|
||||
"""
|
||||
```
|
||||
|
||||
函数体按这个顺序写:
|
||||
|
||||
1. `kind = record_kind.strip()`。不在 `{"inbound", "outbound"}` 时 `raise ValidationError("record_kind must be inbound or outbound")`。
|
||||
2. 出站用 `latest_usable_outbound_file(source_code, now=now)`,入站用 `latest_usable_inbound_file(source_code, now=now)`。结果是 `None` 时抛 `AppError(code="TRANSFER.CURRENT_REPARSE_NO_FILE", message="no usable archive file", http_status=422, details={"source_code": source_code, "record_kind": kind})`。
|
||||
3. `try` 里调用落档。出站:`sync_outbound_source_rows(source_code=source_code, now=now)`。入站:`sync_source_rows(source_code=source_code, deps=get_transfer_dependencies(), business_date=business_date_now(), now=now)`。
|
||||
4. 返回值是 `None`:抛 `AppError(code="TRANSFER.CURRENT_REPARSE_NO_PROFILE", message="no published parsing profile", http_status=422, details={"source_code": source_code, "record_kind": kind})`。此时还没有 commit。
|
||||
5. `db.session.commit()`。再用 `resolve_source_file_status(source_code=source_code, record_kind=kind)` 填 `file_status`。返回 `ok=True` 和 outcome 的四个计数、`file_id=file_view.file_id`。
|
||||
6. `except MovementFileSchemaError as exc`:`db.session.rollback()`,然后 `mark_outbound_parse_failure` 或 `mark_inbound_parse_failure`。`error_message` 取 `getattr(exc, "message", "") or str(exc)` 后截到 2000 字符(`AppError` 的 `str()` 可能是空串,行级原因在 `message` 里,例如 `missing_invoice_no`)。`error_code=exc.code`。`db.session.commit()` 只提交失败标记。再投影状态,返回 `ok=False`、同样的 `error_code` / `error_message`、计数全 0。
|
||||
7. `except AppError`:原样抛出(第 4 步的无规则错误不能被下面的通用分支吃掉)。
|
||||
8. `except Exception as exc`:`db.session.rollback()`,不调用 mark。投影状态后返回 `ok=False`、`error_code="TRANSFER.CURRENT_REPARSE_FAILED"`、`error_message=str(exc)[:500]`、计数全 0。
|
||||
|
||||
`sync_outbound_source_rows` 和 `sync_source_rows` 必须是本模块的顶层 import。非结构异常测试打桩的是 `app.services.in_transit_transfer.current_file_reparse.sync_outbound_source_rows`。不要 import `trigger_inbound_rpa` 或 `trigger_outbound_rpa`。
|
||||
|
||||
- [ ] **Step 4: Run test to verify it passes**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/services/in_transit_transfer/test_current_file_reparse.py -q`
|
||||
|
||||
Expected: PASS。
|
||||
|
||||
- [ ] **Step 5: Stage changes**
|
||||
|
||||
```bash
|
||||
git add backend/app/services/in_transit_transfer/current_file_reparse.py backend/tests/services/in_transit_transfer/test_current_file_reparse.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: HTTP 入口
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/api/in_transit_transfer/__init__.py`(放在 `retry_source_rpa_api` 前面)
|
||||
- Modify: `backend/tests/api/test_in_transit_transfer_api.py`
|
||||
- Test: `backend/tests/api/test_in_transit_transfer_api.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `reparse_current_file(*, source_code: str, record_kind: str, now: datetime) -> CurrentReparseResult`
|
||||
- Produces: `POST /api/in-transit-transfer/sources/<source_code>/reparse`。body `{"record_kind": "inbound"|"outbound"}`,缺省 `inbound`。成功 envelope 的 `data` 是 `CurrentReparseResult` 的字段。无文件、无规则由服务抛出的 `AppError` 变成 422。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
在 `test_in_transit_transfer_api.py` 增加:
|
||||
|
||||
```python
|
||||
def test_reparse_current_without_file_returns_422(client, admin_headers):
|
||||
# [断言意图] 没有出站归档时重解析是 422,不是 202 抓取中。
|
||||
response = client.post(
|
||||
f"{API_PREFIX}/sources/DSV360_AWSDU/reparse",
|
||||
headers=admin_headers,
|
||||
json={"record_kind": "outbound"},
|
||||
)
|
||||
assert response.status_code == 422
|
||||
assert response.get_json()["error"]["code"] == "TRANSFER.CURRENT_REPARSE_NO_FILE"
|
||||
|
||||
|
||||
def test_reparse_current_forbidden(client, unauthorized_headers):
|
||||
# [断言意图] 无调拨权限不能重解析。
|
||||
response = client.post(
|
||||
f"{API_PREFIX}/sources/DSV360_AWSDU/reparse",
|
||||
headers=unauthorized_headers,
|
||||
json={"record_kind": "inbound"},
|
||||
)
|
||||
assert response.status_code == 403
|
||||
```
|
||||
|
||||
使用该文件已有的 `admin_headers` 和 `unauthorized_headers`。
|
||||
|
||||
- [ ] **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_reparse_current_without_file_returns_422 tests/api/test_in_transit_transfer_api.py::test_reparse_current_forbidden -q`
|
||||
|
||||
Expected: FAIL,路由 404。
|
||||
|
||||
- [ ] **Step 3: Write minimal implementation**
|
||||
|
||||
在 `retry_source_rpa_api` 之前增加路由。不要修改 `retry_source_rpa_api` 的函数体。
|
||||
|
||||
```python
|
||||
@in_transit_transfer_bp.route("/sources/<source_code>/reparse", methods=["POST"])
|
||||
@require_transfer_permission
|
||||
def reparse_current_file_api(source_code: str):
|
||||
"""重解析该来源当前最新可用归档,不触发 RPA。
|
||||
|
||||
body 只读 record_kind,缺省 inbound。不接受 file_id。
|
||||
"""
|
||||
from app.services.in_transit_transfer.current_file_reparse import reparse_current_file
|
||||
|
||||
payload = request.get_json(silent=True) or {}
|
||||
if not isinstance(payload, dict):
|
||||
raise ValidationError("request body must be a JSON object")
|
||||
record_kind = str(payload.get("record_kind") or "inbound").strip() or "inbound"
|
||||
result = reparse_current_file(
|
||||
source_code=str(source_code).strip(),
|
||||
record_kind=record_kind,
|
||||
now=datetime.utcnow(),
|
||||
)
|
||||
return _ok({
|
||||
"source_code": result.source_code,
|
||||
"record_kind": result.record_kind,
|
||||
"ok": result.ok,
|
||||
"file_status": result.file_status,
|
||||
"file_id": result.file_id,
|
||||
"inserted": result.inserted,
|
||||
"updated": result.updated,
|
||||
"skipped": result.skipped,
|
||||
"sealed_skipped": result.sealed_skipped,
|
||||
"error_code": result.error_code,
|
||||
"error_message": result.error_message,
|
||||
})
|
||||
```
|
||||
|
||||
更新该 API 模块文件头的路由说明,加上这条 POST。`datetime` 若文件顶部未导入,沿用文件里已有的导入方式(`retry_source_rpa_api` 已使用 `datetime.utcnow()`,不要重复导入)。
|
||||
|
||||
- [ ] **Step 4: Run test to verify it passes**
|
||||
|
||||
Run: `backend/.venv/Scripts/python.exe -m pytest tests/api/test_in_transit_transfer_api.py::test_reparse_current_without_file_returns_422 tests/api/test_in_transit_transfer_api.py::test_reparse_current_forbidden tests/services/in_transit_transfer/test_current_file_reparse.py -q`
|
||||
|
||||
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 3: 来源卡按钮与四语文案
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/features/chat/types/transfer.types.ts`
|
||||
- Modify: `frontend/src/features/chat/api/transfer.api.ts`
|
||||
- Modify: `frontend/src/features/chat/api/transfer.api.spec.ts`
|
||||
- Modify: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue`
|
||||
- Modify: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||||
- Modify: `frontend/src/features/chat/components/messages/TransferMessageView.vue`
|
||||
- Modify: `frontend/src/locales/zh-CN/chat.json`
|
||||
- Modify: `frontend/src/locales/zh-TW/chat.json`
|
||||
- Modify: `frontend/src/locales/en/chat.json`
|
||||
- Modify: `frontend/src/locales/th/chat.json`
|
||||
- Modify: `frontend/src/locales/zh-CN/errors.json`
|
||||
- Modify: `frontend/src/locales/zh-TW/errors.json`
|
||||
- Modify: `frontend/src/locales/en/errors.json`
|
||||
- Modify: `frontend/src/locales/th/errors.json`
|
||||
- Test: `frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`、`frontend/src/features/chat/api/transfer.api.spec.ts`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `POST /api/in-transit-transfer/sources/{sourceCode}/reparse`
|
||||
- Produces: `reparseCurrentFile(sourceCode: string, recordKind: TransferRecordKind): Promise<TransferCurrentReparseResult>`。`TransferCurrentReparseResult` 字段与 Task 2 的 `data` 相同。
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
在 `transfer.api.spec.ts` 旁路现有 `retryTransferSourceRpa` 用例增加:
|
||||
|
||||
```typescript
|
||||
it('当前文件重解析 POST reparse,body 只有 record_kind', () => {
|
||||
reparseCurrentFile('DSV360_AWSDU', 'outbound');
|
||||
const calls = vi.mocked(requestJson).mock.calls;
|
||||
expect(calls[0][0]).toBe('/api/in-transit-transfer/sources/DSV360_AWSDU/reparse');
|
||||
expect(JSON.parse(String((calls[0][1] as RequestInit).body))).toEqual({ record_kind: 'outbound' });
|
||||
});
|
||||
```
|
||||
|
||||
按该文件已有的 `requestJson` mock 写法调整 `calls` 的取法。断言 body 里没有 `file_id`。
|
||||
|
||||
在 `TransferSourceSelectCard.spec.ts` 顶部、组件 import 之前增加 mock:
|
||||
|
||||
```typescript
|
||||
const transferApiMocks = vi.hoisted(() => ({
|
||||
listEvidenceFiles: vi.fn(),
|
||||
reparseCurrentFile: vi.fn(),
|
||||
}));
|
||||
vi.mock('../../api/transfer.api', () => transferApiMocks);
|
||||
```
|
||||
|
||||
新增用例:
|
||||
|
||||
```typescript
|
||||
it('只在清单第一行显示重新解析,点击不发出 retry', async () => {
|
||||
transferApiMocks.listEvidenceFiles.mockResolvedValue([
|
||||
{ file_id: 25, original_filename: 'current.xlsx', created_at: '2026-10-21T10:00:00', sha256: 'abc', file_size: 10, presigned_url: 'https://files.example/current' },
|
||||
{ file_id: 9, original_filename: 'older.xlsx', created_at: '2026-10-20T10:00:00', sha256: 'def', file_size: 10, presigned_url: 'https://files.example/older' },
|
||||
]);
|
||||
transferApiMocks.reparseCurrentFile.mockResolvedValue({
|
||||
source_code: 'DBS-AWSBI', record_kind: 'inbound', ok: true, file_status: 'ready',
|
||||
file_id: 25, inserted: 2, updated: 0, skipped: 0, sealed_skipped: 0,
|
||||
error_code: null, error_message: null,
|
||||
});
|
||||
const wrapper = mount(TransferSourceSelectCard, {
|
||||
props: { sources: readySources, transferTypes: defaultTransferTypes },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await wrapper.find('[data-testid="transfer-source-status-DBS-AWSBI"]').trigger('click');
|
||||
await flushPromises();
|
||||
const buttons = wrapper.findAll('[data-testid="transfer-evidence-reparse-DBS-AWSBI-inbound"]');
|
||||
expect(buttons).toHaveLength(1);
|
||||
await buttons[0].trigger('click');
|
||||
expect(transferApiMocks.reparseCurrentFile).toHaveBeenCalledWith('DBS-AWSBI', 'inbound');
|
||||
expect(wrapper.emitted('retry')).toBeUndefined();
|
||||
expect(wrapper.emitted('reparsed')).toBeTruthy();
|
||||
});
|
||||
```
|
||||
|
||||
`flushPromises` 用 `import { flushPromises } from '@vue/test-utils'`。若现有 mount 助手已经包了 props,沿用那个助手,不要另写一套来源数据。
|
||||
|
||||
- [ ] **Step 2: Run test to verify it fails**
|
||||
|
||||
Run: `npx vitest run src/features/chat/api/transfer.api.spec.ts src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||||
|
||||
工作目录:`frontend/`。
|
||||
|
||||
Expected: FAIL,`reparseCurrentFile` 不存在,按钮找不到。
|
||||
|
||||
- [ ] **Step 3: Write minimal implementation**
|
||||
|
||||
`transfer.types.ts` 在 `TransferEvidenceFile` 后增加:
|
||||
|
||||
```typescript
|
||||
export interface TransferCurrentReparseResult {
|
||||
source_code: string;
|
||||
record_kind: TransferRecordKind;
|
||||
ok: boolean;
|
||||
file_status: TransferSourceFileStatus['file_status'];
|
||||
file_id: number | null;
|
||||
inserted: number;
|
||||
updated: number;
|
||||
skipped: number;
|
||||
sealed_skipped: number;
|
||||
error_code: string | null;
|
||||
error_message: string | null;
|
||||
}
|
||||
```
|
||||
|
||||
`transfer.api.ts` 在 `listEvidenceFiles` 后增加 `reparseCurrentFile`。JSDoc 写明:只重放当前最新归档;body 只有 `record_kind`;不触发 RPA。
|
||||
|
||||
```typescript
|
||||
export const reparseCurrentFile = (
|
||||
sourceCode: string,
|
||||
recordKind: TransferRecordKind,
|
||||
) =>
|
||||
requestJson<TransferCurrentReparseResult>(
|
||||
`${BASE}/sources/${encodeURIComponent(sourceCode)}/reparse`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify({ record_kind: recordKind }),
|
||||
},
|
||||
);
|
||||
```
|
||||
|
||||
`TransferSourceSelectCard.vue`:
|
||||
|
||||
- import 改为 `listEvidenceFiles, reparseCurrentFile`。
|
||||
- `defineEmits` 增加 `reparsed: []`。
|
||||
- 增加 `reparsingKey = ref<string | null>(null)`。
|
||||
- 清单 `v-for` 改成 `(file, index) in evidenceFilesOf(...)`。
|
||||
- 仅当 `index === 0` 时,在预览链接前放按钮:
|
||||
|
||||
```vue
|
||||
<button
|
||||
v-if="index === 0"
|
||||
type="button"
|
||||
class="font-bold text-brand-700 disabled:opacity-50"
|
||||
:disabled="reparsingKey === evidenceKey(source.source_code, stream.record_kind)"
|
||||
:data-testid="`transfer-evidence-reparse-${source.source_code}-${stream.record_kind}`"
|
||||
@click="reparseEvidence(source.source_code, stream.record_kind)"
|
||||
>{{ t('chat.transfer.reparseCurrentFile') }}</button>
|
||||
```
|
||||
|
||||
`reparseEvidence` 的 JSDoc 写明:调用 `reparseCurrentFile`,不 emit `retry`。成功且 `ok` 时 `success` 提示新增/更新数,并重新 `listEvidenceFiles` 写回 `evidenceByKey`,然后 `emit('reparsed')`。`ok === false` 时 `notifyError` 显示 `error_message`,同样刷新清单和 `emit('reparsed')`,让解析失败状态回到芯片上。抛错时只 `notifyError`。
|
||||
|
||||
`TransferMessageView.vue` 的来源卡增加 `@reparsed="transfer.loadSources()"`。不要改 `onSourceRetry`。
|
||||
|
||||
四份 `chat.json` 的 `chat.transfer` 里,紧挨 `previewEvidence` 增加:
|
||||
|
||||
| key | zh-CN | zh-TW | en | th |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `reparseCurrentFile` | 重新解析 | 重新解析 | Reparse | แยกวิเคราะห์ซ้ำ |
|
||||
| `reparseCurrentFileDone` | 已重新解析:新增 {inserted},更新 {updated} | 已重新解析:新增 {inserted},更新 {updated} | Reparsed: {inserted} inserted, {updated} updated | แยกวิเคราะห์ซ้ำแล้ว: เพิ่ม {inserted} อัปเดต {updated} |
|
||||
|
||||
四份 `errors.json` 的 `TRANSFER.*` 段增加:
|
||||
|
||||
| key | zh-CN | zh-TW | en | th |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `TRANSFER.CURRENT_REPARSE_NO_FILE` | 当前没有可重新解析的归档文件。 | 目前沒有可重新解析的歸檔檔案。 | No archived file is available to reparse. | ไม่มีไฟล์ที่เก็บถาวรให้แยกวิเคราะห์ซ้ำ |
|
||||
| `TRANSFER.CURRENT_REPARSE_NO_PROFILE` | 当前证据流没有已发布的解析规则。 | 目前證據流沒有已發布的解析規則。 | This evidence stream has no published parsing profile. | สตรีมหลักฐานนี้ไม่มีโปรไฟล์การแยกวิเคราะห์ที่เผยแพร่แล้ว |
|
||||
|
||||
更新 `TransferSourceSelectCard.vue` 文件头依赖,写上 `reparseCurrentFile`。函数 `reparseEvidence` 上方按项目 JSDoc 写用途、参数、返回值。
|
||||
|
||||
- [ ] **Step 4: Run test to verify it passes**
|
||||
|
||||
Run: `npx vitest run src/features/chat/api/transfer.api.spec.ts src/features/chat/components/messages/TransferSourceSelectCard.spec.ts`
|
||||
|
||||
工作目录:`frontend/`。
|
||||
|
||||
Expected: PASS。既有来源卡用例仍然通过。若 mock 替换了整个 `transfer.api` 导致其他用例缺导出,只补那些用例实际会调用的导出,不要改断言去迁就 mock。
|
||||
|
||||
- [ ] **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/api/transfer.api.spec.ts frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts frontend/src/features/chat/components/messages/TransferMessageView.vue 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 frontend/src/locales/zh-CN/errors.json frontend/src/locales/zh-TW/errors.json frontend/src/locales/en/errors.json frontend/src/locales/th/errors.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: 文档
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/features/in-transit-transfer/technical.md`(来源 API 表,约第 70 行 `retry-rpa` 那一行之后)
|
||||
- Modify: `docs/funclist.md`(「来源重试合并触发与知情范围确认」那一行之后)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 2 的路由和两个错误码。
|
||||
- Produces: 文档与代码一致。无新代码。
|
||||
|
||||
- [ ] **Step 1: Update the API table**
|
||||
|
||||
在 `technical.md` 的来源路由表,`POST /sources/{source_code}/retry-rpa` 下一行增加:
|
||||
|
||||
`POST /sources/{source_code}/reparse`:重解析当前最新可用归档(body `record_kind`,缺省 inbound;不接受 file_id;不触发 RPA)。成功 200,`ok/file_status/file_id/inserted/updated/skipped/sealed_skipped`。无文件 422 `TRANSFER.CURRENT_REPARSE_NO_FILE`。无已发布规则 422 `TRANSFER.CURRENT_REPARSE_NO_PROFILE`,不标 parse_failed。结构失败 200 `ok: false` 且文件为 `parse_failed`。其他异常 200 `ok: false`,不标 parse_failed。与待匹配 `POST /backlog/pending-match/reparse` 不是同一条链路。
|
||||
|
||||
- [ ] **Step 2: Update the feature list**
|
||||
|
||||
在 `funclist.md` 来源重试行后增加一行:
|
||||
|
||||
「当前归档重新解析(2026-10-21)」已实现。来源卡证据清单第一行「重新解析」调用 `POST /sources/{source_code}/reparse`,只重放该流入站或出站的最新可用归档并幂等落档,不触发 RPA,不删除档行。↻ 仍是重新抓取。待匹配「清空并重新解析」仍是整桶重建。
|
||||
|
||||
- [ ] **Step 3: Stage changes**
|
||||
|
||||
```bash
|
||||
git add docs/features/in-transit-transfer/technical.md docs/funclist.md docs/superpowers/specs/2026-10-21-transfer-current-file-reparse-design.md docs/superpowers/plans/2026-10-21-transfer-current-file-reparse.md
|
||||
```
|
||||
@@ -0,0 +1,29 @@
|
||||
# 调拨来源选择:按证据流显示状态、重试与下载
|
||||
|
||||
日期:2026-10-19
|
||||
|
||||
对话已确认的界面与范围。实施计划:`docs/superpowers/plans/2026-10-19-transfer-evidence-stream-ui.md`。
|
||||
|
||||
## 目的
|
||||
|
||||
操作员在来源选择卡上能看出每个来源实例的入站、出站是否各自就绪,并只重试当前调拨类型还缺的那条证据流。下载仍是一个按钮,压缩包内按记录类型分目录。
|
||||
|
||||
## 已定决策
|
||||
|
||||
- 状态粒度是来源实例 × 记录类型。不拆来源行,不做「部分就绪」。
|
||||
- 不新增调拨类型字段,不改调拨类型表单。入站还是出站,读该类型已有的范围规则:字段为 `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(该类型的范围规则)`。没有类型对象的调用方显式只圈入站。
|
||||
|
||||
## 不做
|
||||
|
||||
- 不拆两个下载按钮,不拆两个批量按钮。
|
||||
- 不为出站复制来源实例行。
|
||||
- 不把整张卡改成大触控尺寸。
|
||||
- 不改货代 RPA Worker、排程和回调契约。
|
||||
@@ -0,0 +1,32 @@
|
||||
# 当前归档重新解析
|
||||
|
||||
日期:2026-10-21
|
||||
|
||||
来源选择卡在文件已经落地之后,需要一条不触发 RPA 的重新解析入口。出站回调落档失败(例如 `file_version` 超长)会被桥接吞掉,文件状态仍是就绪,异动档没有行。只在 `parse_failed` 上重试,覆盖不到这种情况。↻ 继续表示重新抓取。
|
||||
|
||||
## 行为
|
||||
|
||||
- 入站和出站各自有「重新解析」。当天该流已有可用归档时可以点,状态是就绪或解析失败都可以。
|
||||
- 只解析该流当前最新一份可用归档(`created_at`、`id` 倒序第一条,与 `latest_usable_*_file` 相同),并幂等写入异动档。不写 RPA trigger。
|
||||
- 请求不接受 `file_id`。服务端自己取最新一份,避免清单过期时重放历史文件。
|
||||
- 同一份文件再解析一次:摘要未变则跳过已有档行,不另插一行。
|
||||
- 没有可用归档:422 `TRANSFER.CURRENT_REPARSE_NO_FILE`。
|
||||
- 有归档但没有已发布的对应 purpose 规则:422 `TRANSFER.CURRENT_REPARSE_NO_PROFILE`。不把文件标成解析失败。规则缺失不是文件错误。
|
||||
- 结构校验失败(`MovementFileSchemaError`):回滚档行,把 `parse_failed` 写到当前文件,HTTP 200,`ok: false`,`file_status: parse_failed`,带 `error_message`。
|
||||
- 其他异常(数据库截断、连接失败):回滚,不标解析失败,HTTP 200,`ok: false`,`error_message` 为异常文本。文件状态保持原投影。
|
||||
- 成功:HTTP 200,`ok: true`,返回 `inserted` / `updated` / `skipped` / `sealed_skipped` 和解析后的 `file_status`。审计沿用落档函数已有的 `TRANSFER_EVIDENCE_SYNCED`,不另造事件。
|
||||
- `file_version` 只经 `movement_file_version`。本入口不自己拼版本戳。
|
||||
|
||||
## 界面
|
||||
|
||||
展开来源卡某条证据流的当天清单后,只有第一行(当前文件)在预览、下载旁边显示「重新解析」。更旧的归档只有预览和下载。
|
||||
|
||||
点下去调用 `POST /api/in-transit-transfer/sources/{source_code}/reparse`,body 只有 `{ "record_kind": "inbound" | "outbound" }`。成功或 `ok: false` 后刷新来源状态和这一条清单。↻ 与 `POST /sources/{source_code}/retry-rpa` 的行为不变。
|
||||
|
||||
待匹配「清空并重新解析」(`POST /backlog/pending-match/reparse`)仍是改规则后的整桶重建,本入口不调用它,也不删除已有档行。
|
||||
|
||||
## 不做
|
||||
|
||||
- 不改 ↻、批量重试、Worker、回调契约。
|
||||
- 不给历史归档逐份重放。
|
||||
- 不在部署或进程启动时自动补解析已经落地的文件。
|
||||
Reference in new issue
Block a user