feat(shipping-notice): 新增库存确认来源接口及相关逻辑

This commit is contained in:
hugo committed 2026-07-13 21:53:45 +08:00
1 parent a31735b689
commit 0a9bd6415d
69 files changed
+8442 -775

No files matched your search

+17 -5
View File
@@ -1440,7 +1440,7 @@ def main(normalized_query: str = "", intent_hint: str = "", sys_files=None):
text = str(normalized_query or "").strip()
if files:
lower_names = " ".join(_file_name(f) for f in files)
if any(ext in lower_names for ext in [".xlsx", ".xls", ".csv"]):
if any(ext in lower_names for ext in [".xlsx", ".csv"]):
return {"route_key": "inventory_path", "reason": "inventory_file"}
return {"route_key": "direct_answer", "reason": "notice_files_managed_by_hxops"}
if intent_hint in {
@@ -2935,7 +2935,7 @@ Agent 状态输入标准化 -> 货代续办 Agent
| 确认 / 驳回 / 重匹配直连 | `确认` / `驳回` / `重新匹配` / `rematch` | `submit_decision` | 是,直连决策 Tool | 当前任务或显式 `SN-...` | 按状态机推进;`rematch` 清理 shortage 并重新入队当前任务 | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_contract_submit_decision_rematch_is_direct_recovery_entry` |
| shortage 阻断 | shortage review 后输入 `继续` 或自动续跑 | `match_inventory` / `submit_decision` 返回门禁 | 是,命中状态机门禁后停止 | 当前任务 | `status=needs_human`;禁止 `generate_shipment_excel` / `upload_to_freight`;不生成 Excel | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_shipping_notice_match_shortage_needs_human` |
| 多任务只推进 focus task | 多票批次中输入 `继续处理` | `get_batch_status` + 当前 focus 的 `get_task_status` | 是,先读状态再决定 | `batch.current_focus_task_no` | 每轮只围绕一个 focus task;读批次状态不循环推进整批 | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_contract_batch_status_keeps_single_focus_without_advancing_other_tasks` |
| 库存上传链路 | 上传 `.xlsx/.xls/.csv` | `get_inventory_schema_preview` → 映射 LLM → `apply_inventory_mapping` | 否,进入库存专用分支,不走自由 Agent | 当前任务 / 所属批次库存快照 | 生成 schema preview;应用映射后进入 `align_review` 或后端续跑 | 待实测 |
| 库存上传链路 | 上传 `.xlsx/.csv` | `get_inventory_schema_preview` → 映射 LLM → `apply_inventory_mapping` | 否,进入库存专用分支,不走自由 Agent | 当前任务 / 所属批次库存快照 | 生成 schema preview;应用映射后进入 `align_review` 或后端续跑 | 待实测 |
| 字段对齐人工门 | `apply_inventory_mapping` 返回 `align_review` 后输入 `确认` | `submit_decision(decision=confirm_inventory_mapping)` | 是,直连决策 Tool | 当前任务 | 停住等待确认;确认后交由 hxops worker 续跑匹配 / 导出 / 上传 | 待实测 |
| Tool 人工门收口 | 任一 Tool 返回 `needs_human` 或 `stop_agent_turn=true` | 工具结果标准化 | 是,硬停止本轮 | 当前任务 | 本轮不再继续调用后续 Tool | 待实测 |
| forbidden_next_tools 门禁 | Tool 返回 `forbidden_next_tools` | 工具结果标准化 | 是,硬门禁 | 当前任务 | 画布不调用被禁止 Tool | 待实测 |
@@ -3291,7 +3291,7 @@ API 层
### 5.2 快照复用规则
1. `ensure_inventory(mode=auto)` 在解析库存源后,优先 `find_latest_ready_snapshot(source_code, warehouse_id)`
1. `ensure_inventory(mode=auto)` 在库存源**已稳定**后,优先 `find_latest_ready_snapshot(source_code, site_id, warehouse_id)`
2. 未过期快照 → `link_snapshot_to_task(reason=reuse_latest)` → 映射/匹配
3. 过期或缺失 → 触发 RPA(单 task trigger 或定时 batch trigger)
4. `retry_rpa` **强制跳过**快照缓存
@@ -3312,6 +3312,18 @@ API 层
### 5.4 审计字段
- `shipping_inventory_files`:`warehouse_id`、`source_code`、`exported_at`、`expires_at`、`rpa_run_no`、`schedule_run_id`
- `shipping_task_inventory_links`:`link_reason`、`matched_warehouse_id`、`snapshot_age_seconds`、`audit_payload_json`
- `shipping_inventory_files`:`warehouse_id`、`site_id`、`source_code`、`exported_at`、`expires_at`、`rpa_run_no`、`schedule_run_id`、`identity_status`
- `shipping_task_inventory_links`:`link_reason`、`matched_source_code`、`matched_site_id`、`matched_warehouse_id`、`snapshot_age_seconds`、`audit_payload_json`、身份校验字段
### 5.5 订单解析阶段库存源判定(2026-07)
> 详细方案见 [`inventory_source_plan.md`](./inventory_source_plan.md)。
1. **`parse_notice` 内 adjudicate**:读取任务 `destination_*` 与 YAML `match`/`match_aliases`,产出 `InventorySourceAdjudication`。
2. **稳定才放行**:`inventory_source_status ∈ {resolved, user_confirmed}` 时任务才可 `parsed` 并触发 RPA;否则 `checkpoint=inventory_source_review`,`process_status=pending_review`。
3. **独立字段为真相源**:`inventory_source_code`、`inventory_site_id`、`inventory_warehouse_id` 等存于 `shipping_tasks` 列,gate 不读 `step_payload_json`。
4. **用户只确认 source_code**:`confirm_inventory_source` 根据编码回填 site/warehouse;路由指纹变更时要求重确认(`SHIPPING.INVENTORY_SOURCE_CHANGED`)。
5. **硬 Gate**:`inventory_rpa_workflow`、`inventory_workflow`、`fulfillment_workflow`、`progress_workflow` 入口均调用 `assert_inventory_source_gate`。
6. **快照复用键**:`find_latest_ready_snapshot(source_code, site_id, warehouse_id)`;link 时做 identity check。
7. **迁移**:`b4c5d6e7f8a9_add_shipping_inventory_source_gate_fields`。