Files
syops/docs/features/shipping-notice/xfa-profile-migration-runbook.md
T
hugoandCursor 84a881b554 feat(shipping-notice): 落地 XFA 统一视觉拆分确认门禁与处理投影收敛
闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。
同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 10:21:25 +08:00

98 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# XFA / 坐标模板统一 Binding 迁移运维手册
> 适用:统一视觉标注方案阶段 7
> 权威方案:[xfa-unified-visual-split-implementation-plan.md](./xfa-unified-visual-split-implementation-plan.md)
> 日期:2026-08-06
## 1. 目标
将现有订单文档模板一次性迁移为统一 `bindings[]`(`value_binding` + `visual_binding`),**不要求人工从零重建**:
| 模板类型 | 行为 |
| --- | --- |
| 普通坐标 | `order_field_layouts` / 表区 `field_regions` → `pdf_coordinate`/`ocr_coordinate` binding;视觉框 `source=migrated_coordinate`,已有框 `status=confirmed` |
| XFA | 保留 `header_mappings` / `line_mapping` / `source_contract`;由 mappings 生成 `xfa_dataset` binding;有 AcroForm Widget 时填建议框,否则占位;**一律 `status=suggested`,须人工确认后才能发布** |
报告指标:
- `path_preserve_rate`:XFA 路径保留率(期望 100%)
- `field_diff_count`:正式 Schema 字段差异(期望 0)
- `pending_visual_count`:待补/待确认视觉框数(XFA 通常 >0)
## 2. 为何无 Alembic
迁移报告与 before/after 写入 `ShippingOrderDocumentProfileAudit.detail_json`(事件类型
`order_profile_unified_migration_dry_run` / `order_profile_unified_migration_executed`)。
definition 的 `bindings[]` 为 JSON 内字段,**不新增表列**,故本阶段不需要数据库迁移脚本。
## 3. Dry Run(必须先做)
### 3.1 CLI
```bash
cd backend
python scripts/migrate_order_profiles_to_unified_bindings.py --dry-run
python scripts/migrate_order_profiles_to_unified_bindings.py --profile-id <ID> --dry-run
```
### 3.2 Admin API
```http
GET /api/admin/shipping-notice/order-document-profiles/unified-migration/scan
POST /api/admin/shipping-notice/order-document-profiles/<profile_id>/unified-migration/dry-run
GET /api/admin/shipping-notice/order-document-profiles/<profile_id>/unified-migration/report
```
模板库列表页提供 **待迁移 / 待补框** 筛选、**批量 Dry Run**;版本详情页提供单模板 Dry Run 与状态徽章。
### 3.3 通过标准
- `path_preserve_rate == 100`
- `field_diff_count == 0`
- 报告已写入审计,可通过 GET report 回放
任一指标不满足:**禁止 Execute**,先排查 mapping / Schema 字段。
## 4. Execute
```bash
python scripts/migrate_order_profiles_to_unified_bindings.py --profile-id <ID> --execute
```
或:
```http
POST /api/admin/shipping-notice/order-document-profiles/<profile_id>/unified-migration/execute
```
行为:
1. 已发布模板 → clone 新 Draft(同族已有草稿则冲突,需先处理)
2. 草稿模板 → 原地写入 `bindings[]` 并新增 Draft Revision
3. 审计含 before/after 摘要与完整 report
**禁止**批量跳过视觉确认后直接发布。
## 5. 核验
1. 打开新 Draft → 确认 `bindings` 数量与 Dry Run 一致
2. XFA:在统一工作台逐字段确认视觉框(`suggested` → `confirmed`)
3. 跑当前样本验证 / 盲测 / 发布检查
4. `pending_visual_count > 0` 或视觉未确认 → **发布门禁必须阻断**
## 6. 回退
| 场景 | 做法 |
| --- | --- |
| Dry Run 仅审计 | 无需回退 definition;可忽略报告 |
| Execute 后未发布 | 删除同族 Draft,或从历史 Revision 恢复;已发布版本未变 |
| 已误发布 | 退役该版本;回退到迁移前已发布版本;按发布流程重新审核 |
回退时保留审计事件(不可改删),便于追溯。
## 7. 风险与注意
- XFA 无 Widget 时视觉框为占位 suggested,**必须人工画框确认**
- 同族已有 Draft 时 Execute clone 会冲突,先合并或删除草稿
- 迁移不改 Dify 画布;自动建单仍须发布门禁 + CQ/STP