feat(shipping_notice): 完成货代发货通知全流程功能迭代与重构

主要变更:
1.  移除废弃的发货通知字段抽取独立Workflow Agent相关代码
2.  重构Dify服务调用,新增inputs参数支持注入环境变量配置的工具API地址与密钥
3.  新增auto_progress工具API与checkpoint catalog接口,支持流程自动推进
4.  统一字段命名,将column_mapping_json改为map_json并兼容旧有调用
5.  重构库存匹配、解析结果的展示格式,改为标准化多语言Markdown表格
6.  新增ODM ID库存字段支持,优化库存解析与映射逻辑
7.  新增LibreOffice转换隔离Profile配置,避免多实例运行冲突
8.  新增完整环境变量配置、数据库迁移脚本与测试用例
9.  适配前端代码,更新字段命名与聊天跳转逻辑
10. 更新OpenAPI规范适配Dify工具调用,删除已归档的旧部署文档
This commit is contained in:
hugo committed 2026-06-08 16:07:20 +08:00
1 parent 2ce5256483
commit c18c0394d0
50 files changed
+6088 -2407

No files matched your search

@@ -1,137 +1,51 @@
from __future__ import annotations
"""Backward-compatible re-exports — canonical definitions live in state_machine.py."""
from typing import Any
from app.services.shipping_notice.state_machine import (
ACTION_SPECS,
ALL_ACTION_IDS,
ALL_CHECKPOINT_IDS,
CHECKPOINT_REGISTRY,
TaskTransition,
TaskUiState,
action_buttons_for_checkpoint,
apply_task_transition,
build_action_buttons,
build_chat_actions_payload,
build_checkpoint_catalog,
checkpoint_for_task,
format_actions_directive,
human_options_for_checkpoint,
human_options_for_task,
human_options_for_task_or_checkpoint,
resolve_task_ui_state,
ui_state_for_checkpoint,
upload_req_options_for_task,
validate_registry,
)
from app.models import ShippingTask
# Legacy alias
CHECKPOINT_OPTIONS = CHECKPOINT_REGISTRY
ACTION_SPECS: dict[str, dict[str, str]] = {
"confirm": {"label": "确认", "message": "确认", "variant": "primary"},
"reject": {"label": "驳回", "message": "驳回", "variant": "danger"},
"reparse": {"label": "重新解析", "message": "重新解析", "variant": "secondary"},
"confirm_inventory_mapping": {"label": "确认", "message": "确认", "variant": "primary"},
"correct_inventory_mapping": {"label": "更正映射", "message": "更正映射", "variant": "secondary"},
"reparse_inventory": {"label": "重新上传", "message": "重新上传库存", "variant": "secondary"},
"rematch": {"label": "重新匹配", "message": "重新匹配", "variant": "secondary"},
"retry_rpa": {"label": "重试 RPA", "message": "重试 RPA 导出库存", "variant": "secondary"},
"upload_inventory_file": {
"label": "选择库存文件",
"message": "我要上传库存 Excel",
"variant": "secondary",
},
"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": "已在货代系统手工上传完成",
"variant": "primary",
},
"paste_inventory_json": {
"label": "粘贴库存",
"message": "我粘贴库存小表",
"variant": "secondary",
},
"edit_inventory_mapping": {
"label": "修改映射",
"message": "修改库存列映射",
"variant": "primary",
},
"match_inventory": {
"label": "匹配库存",
"message": "匹配库存",
"variant": "primary",
},
}
def human_options_for_task(task: ShippingTask) -> list[str] | None:
if task.process_status == "rejected" or task.review_status == "rejected":
return []
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 ["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 task.review_status == "inventory_shortage_review":
return ["confirm", "reject", "rematch"]
if reason == "low_parse_confidence" or task.review_status == "parse_review":
return ["confirm", "reject", "reparse"]
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 (
task.process_status == "waiting_inventory" and reason == "inventory_rpa_pending"
):
return ["retry_rpa", "upload_inventory_file"]
if reason == "upload_rpa_pending" or task.process_status == "waiting_upload":
return ["retry_upload", "download_excel", "mark_manual_uploaded"]
return None
def checkpoint_for_task(task: ShippingTask) -> str | None:
if task.process_status == "rejected" or task.review_status == "rejected":
return "rejected"
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 task.review_status == "parse_review":
return "parse_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 == "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
def build_action_buttons(option_ids: list[str] | None) -> list[dict[str, str]]:
if not option_ids:
return []
buttons: list[dict[str, str]] = []
for option_id in option_ids:
spec = ACTION_SPECS.get(option_id)
if not spec:
continue
buttons.append({"id": option_id, **spec})
return buttons
def build_chat_actions_payload(task: ShippingTask) -> dict[str, Any]:
options = human_options_for_task(task)
buttons = build_action_buttons(options)
return {
"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,
}
__all__ = [
"ACTION_SPECS",
"ALL_ACTION_IDS",
"ALL_CHECKPOINT_IDS",
"CHECKPOINT_OPTIONS",
"CHECKPOINT_REGISTRY",
"TaskTransition",
"TaskUiState",
"action_buttons_for_checkpoint",
"apply_task_transition",
"build_action_buttons",
"build_chat_actions_payload",
"build_checkpoint_catalog",
"checkpoint_for_task",
"format_actions_directive",
"human_options_for_checkpoint",
"human_options_for_task",
"human_options_for_task_or_checkpoint",
"resolve_task_ui_state",
"ui_state_for_checkpoint",
"upload_req_options_for_task",
"validate_registry",
]