feat(shipping-notice): 完成货代发货通知全流程开发与代码重构
- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑 - 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示 - 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败 - 新增路径工具类统一管理相对路径,优化配置文件处理逻辑 - 归档旧文档,将部署、Dify配置合并到`shipping_notice.md` - 新增完整单元测试与集成测试覆盖核心流程 - 更新前端国际化与会话管理逻辑,优化界面交互
This commit is contained in:
1 parent
b62082758b
commit
8deae3146b
65 files changed
+6477
-1937
No files matched your search
@@ -58,7 +58,7 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
if not server.endswith("/api/shipping-notice"):
|
||||
server = f"{server}/api/shipping-notice" if server else "/api/shipping-notice"
|
||||
|
||||
case_id = _str_prop("发货任务编号,如 SN-20260529-ABCD1234")
|
||||
task_id = _str_prop("发货任务编号(task id),如 SN-20260529-ABCD1234")
|
||||
|
||||
return {
|
||||
"openapi": "3.0.0",
|
||||
@@ -69,9 +69,9 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
},
|
||||
"servers": [{"url": server}],
|
||||
"paths": {
|
||||
"/tools/create_case": _post_op(
|
||||
"create_case",
|
||||
"创建发货任务 case",
|
||||
"/tools/create_task": _post_op(
|
||||
"create_task",
|
||||
"创建发货任务 task",
|
||||
{
|
||||
"user_id": _int_prop("Hxops 用户 ID(可选)"),
|
||||
"conversation_id": _str_prop("Dify 会话 ID,便于工作台关联"),
|
||||
@@ -83,10 +83,10 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
"parse_notice",
|
||||
"解析发货通知文本",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"raw_text": _str_prop("待解析的发货通知全文"),
|
||||
},
|
||||
required=["case_id"],
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/parse_inventory": _post_op(
|
||||
"parse_inventory",
|
||||
@@ -95,9 +95,9 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
"apply_inventory_mapping;或 use_uploaded_file=true(规则映射兜底)。小表可粘贴文本。"
|
||||
"成功后 stop_agent_turn,等 confirm_inventory_mapping 后再 match。",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"use_uploaded_file": _str_prop(
|
||||
"true=解析该 case 已上传的 Excel(服务端直传,不经过 LLM)",
|
||||
"true=解析该任务已上传的 Excel(服务端直传,不经过 LLM)",
|
||||
enum=["true", "false"],
|
||||
),
|
||||
"column_mapping_json": _str_prop(
|
||||
@@ -110,53 +110,53 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
'可选,已整理好的 JSON 数组字符串,如 [{"sku":"A001","available_qty":10}]'
|
||||
),
|
||||
},
|
||||
required=["case_id"],
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/get_inventory_schema_preview": _post_op(
|
||||
"get_inventory_schema_preview",
|
||||
"读取已上传库存 Excel 的表头与样例行(小 payload,供 LLM 推断列映射)",
|
||||
{"case_id": case_id},
|
||||
required=["case_id"],
|
||||
{"task_id": task_id},
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/apply_inventory_mapping": _post_op(
|
||||
"apply_inventory_mapping",
|
||||
"应用 LLM/人工列映射并解析完整库存文件;返回 field_alignment 等待用户确认",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"column_mapping_json": _str_prop(
|
||||
'列映射 JSON,如 {"sku":"料号","reservation_id":"COM ID","available_qty":"Qty Available"}'
|
||||
'列映射 JSON,含 sku/reservation_id/available_qty;可选 match_rule(LLM 自然语言匹配说明,缺省则后端动态兜底)'
|
||||
),
|
||||
},
|
||||
required=["case_id", "column_mapping_json"],
|
||||
required=["task_id", "column_mapping_json"],
|
||||
),
|
||||
"/tools/ensure_inventory": _post_op(
|
||||
"ensure_inventory",
|
||||
"确保库存快照可用(RPA 自动导出;对话库存请优先用 parse_inventory)",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"mode": _str_prop("auto=自动/RPA;retry_rpa=重试 RPA", enum=["auto", "retry_rpa"]),
|
||||
"inventory_lines_json": _str_prop(
|
||||
'手工库存 JSON 数组字符串,如 [{"sku":"A001","available_qty":10}]'
|
||||
),
|
||||
},
|
||||
required=["case_id"],
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/match_inventory": _post_op(
|
||||
"match_inventory",
|
||||
"匹配发货需求与库存。前置条件:submit_decision(confirm_inventory_mapping) 已成功;"
|
||||
"未确认时调用会被拒绝并返回 forbidden_next_tools",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"inventory_lines_json": _str_prop("可选,覆盖库存 JSON 数组后再匹配"),
|
||||
},
|
||||
required=["case_id"],
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/submit_decision": _post_op(
|
||||
"submit_decision",
|
||||
"人工复核决策。case_id 与 conversation_id 至少传一个;用户确认时禁止 create_case",
|
||||
"人工复核决策。task_id 与 conversation_id 至少传一个;用户确认时禁止 create_task",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"conversation_id": _str_prop("Dify 会话 ID;用户仅回复「确认」时用于定位 case"),
|
||||
"task_id": task_id,
|
||||
"conversation_id": _str_prop("Dify 会话 ID;用户仅回复「确认」时用于定位任务"),
|
||||
"decision": _str_prop(
|
||||
"confirm=确认继续;reject=驳回;rematch=重新匹配;reparse=重新解析;"
|
||||
"confirm_inventory_mapping=确认库存字段对齐;correct_inventory_mapping=更正列映射;reparse_inventory=重新上传库存",
|
||||
@@ -178,27 +178,27 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
"/tools/generate_shipment_excel": _post_op(
|
||||
"generate_shipment_excel",
|
||||
"生成固定模板发货 Excel(须 match_inventory 成功且 process_status=matched)",
|
||||
{"case_id": case_id},
|
||||
required=["case_id"],
|
||||
{"task_id": task_id},
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/upload_to_freight": _post_op(
|
||||
"upload_to_freight",
|
||||
"上传 Excel 到货代系统(RPA 或手工确认)",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"mode": _str_prop(
|
||||
"auto=触发 RPA;retry_upload=重试;manual_confirm=手工上传完成",
|
||||
enum=["auto", "retry_upload", "manual_confirm"],
|
||||
),
|
||||
"freight_ref_no": _str_prop("货代系统单号(manual_confirm 时填写)"),
|
||||
},
|
||||
required=["case_id"],
|
||||
required=["task_id"],
|
||||
),
|
||||
"/tools/get_case_status": _post_op(
|
||||
"get_case_status",
|
||||
"查询 case 当前状态与 human_options。case_id 与 conversation_id 至少传一个",
|
||||
"/tools/get_task_status": _post_op(
|
||||
"get_task_status",
|
||||
"查询任务当前状态与 human_options。task_id 与 conversation_id 至少传一个",
|
||||
{
|
||||
"case_id": case_id,
|
||||
"task_id": task_id,
|
||||
"conversation_id": _str_prop("Dify 会话 ID"),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user