feat(shipping-notice): 完成货代发货通知全流程开发与代码重构

- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑
- 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示
- 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败
- 新增路径工具类统一管理相对路径,优化配置文件处理逻辑
- 归档旧文档,将部署、Dify配置合并到`shipping_notice.md`
- 新增完整单元测试与集成测试覆盖核心流程
- 更新前端国际化与会话管理逻辑,优化界面交互
This commit is contained in:
hugo committed 2026-06-04 15:26:34 +08:00
1 parent b62082758b
commit 8deae3146b
65 files changed
+6477 -1937

No files matched your search

@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import Any
from app.models import ShippingCase
from app.models import ShippingTask
ACTION_SPECS: dict[str, dict[str, str]] = {
"confirm": {"label": "确认", "message": "确认", "variant": "primary"},
@@ -20,6 +20,7 @@ ACTION_SPECS: dict[str, dict[str, str]] = {
},
"retry_upload": {"label": "重试上传", "message": "重试上传货代", "variant": "secondary"},
"download_excel": {"label": "下载 Excel", "message": "下载发货 Excel", "variant": "secondary"},
"generate_excel": {"label": "生成发货 Excel", "message": "生成发货 Excel", "variant": "primary"},
"mark_manual_uploaded": {
"label": "已手工上传",
"message": "已在货代系统手工上传完成",
@@ -30,49 +31,83 @@ ACTION_SPECS: dict[str, dict[str, str]] = {
"message": "我粘贴库存小表",
"variant": "secondary",
},
"edit_inventory_mapping": {
"label": "修改映射",
"message": "修改库存列映射",
"variant": "primary",
},
"match_inventory": {
"label": "匹配库存",
"message": "匹配库存",
"variant": "primary",
},
}
def human_options_for_case(case: ShippingCase) -> list[str] | None:
if case.process_status == "rejected" or case.review_status == "rejected":
def human_options_for_task(task: ShippingTask) -> list[str] | None:
if task.process_status == "rejected" or task.review_status == "rejected":
return []
reason = case.pending_human_reason
if reason == "inventory_field_mapping_review" or case.review_status == "inventory_mapping_review":
if (
task.process_status == "parsed"
and not task.review_status
and not task.pending_human_reason
and not task.inventory_lines_json
):
return ["upload_inventory_file", "retry_rpa", "paste_inventory_json"]
if (
task.process_status == "inventory_ready"
and not task.review_status
and not task.pending_human_reason
and not task.match_status
and isinstance(task.lines_json, list)
and len(task.lines_json) > 0
):
return ["match_inventory"]
if task.process_status == "matched":
if task.export_file_path:
return ["download_excel", "mark_manual_uploaded"]
return ["generate_excel"]
reason = task.pending_human_reason
if reason == "inventory_field_mapping_review" or task.review_status == "inventory_mapping_review":
return ["confirm_inventory_mapping", "correct_inventory_mapping", "reparse_inventory", "reject"]
if reason == "inventory_mapping_inference":
return ["upload_inventory_file", "paste_inventory_json"]
return ["edit_inventory_mapping", "upload_inventory_file", "paste_inventory_json", "retry_rpa"]
if reason == "reservation_id_required" or task.review_status == "reservation_id_required":
return ["reparse", "edit_inventory_mapping", "upload_inventory_file", "reject"]
if reason == "inventory_unavailable":
return ["retry_rpa", "upload_inventory_file"]
if reason == "inventory_shortage" or case.review_status == "inventory_shortage_review":
if reason == "inventory_shortage" or task.review_status == "inventory_shortage_review":
return ["confirm", "reject", "rematch"]
if reason == "low_parse_confidence" or case.review_status == "parse_review":
if reason == "low_parse_confidence" or task.review_status == "parse_review":
return ["confirm", "reject", "reparse"]
if reason == "upload_rpa_failed" or case.process_status == "upload_failed":
if reason == "upload_rpa_failed" or task.process_status == "upload_failed":
return ["retry_upload", "download_excel", "mark_manual_uploaded"]
if reason == "inventory_rpa_pending" or (
case.process_status == "waiting_inventory" and reason == "inventory_rpa_pending"
task.process_status == "waiting_inventory" and reason == "inventory_rpa_pending"
):
return ["retry_rpa", "upload_inventory_file"]
if reason == "upload_rpa_pending" or case.process_status == "waiting_upload":
if reason == "upload_rpa_pending" or task.process_status == "waiting_upload":
return ["retry_upload", "download_excel", "mark_manual_uploaded"]
return None
def checkpoint_for_case(case: ShippingCase) -> str | None:
if case.process_status == "rejected" or case.review_status == "rejected":
def checkpoint_for_task(task: ShippingTask) -> str | None:
if task.process_status == "rejected" or task.review_status == "rejected":
return "rejected"
reason = case.pending_human_reason
if reason == "inventory_field_mapping_review" or case.review_status == "inventory_mapping_review":
reason = task.pending_human_reason
if reason == "inventory_field_mapping_review" or task.review_status == "inventory_mapping_review":
return "inventory_field_mapping_review"
if reason == "low_parse_confidence" or case.review_status == "parse_review":
if reason == "low_parse_confidence" or task.review_status == "parse_review":
return "parse_review"
if reason == "inventory_shortage" or case.review_status == "inventory_shortage_review":
if reason == "inventory_shortage" or task.review_status == "inventory_shortage_review":
return "inventory_shortage_review"
if reason == "inventory_unavailable":
return "inventory_upload_required"
if reason == "inventory_mapping_inference":
return "inventory_mapping_inference"
if reason == "upload_rpa_failed" or case.process_status == "upload_failed":
if reason == "reservation_id_required" or task.review_status == "reservation_id_required":
return "reservation_id_required"
if reason == "upload_rpa_failed" or task.process_status == "upload_failed":
return "upload_failed"
return None
@@ -89,14 +124,14 @@ def build_action_buttons(option_ids: list[str] | None) -> list[dict[str, str]]:
return buttons
def build_chat_actions_payload(case: ShippingCase) -> dict[str, Any]:
options = human_options_for_case(case)
def build_chat_actions_payload(task: ShippingTask) -> dict[str, Any]:
options = human_options_for_task(task)
buttons = build_action_buttons(options)
return {
"case_no": case.case_no,
"checkpoint": checkpoint_for_case(case),
"process_status": case.process_status,
"review_status": case.review_status,
"pending_human_reason": case.pending_human_reason,
"task_no": task.task_no,
"checkpoint": checkpoint_for_task(task),
"process_status": task.process_status,
"review_status": task.review_status,
"pending_human_reason": task.pending_human_reason,
"action_buttons": buttons,
}