feat(shipping-notice): 新增发货批次和任务管理功能,支持批次创建与任务处理

This commit is contained in:
hugo committed 2026-06-17 20:45:19 +08:00
1 parent 457f0f4e5e
commit 634dee4b81
81 files changed
+9088 -3625

No files matched your search

@@ -0,0 +1,510 @@
{
"template_kind": "hxops_shipping_notice_chatflow_delivery_template",
"template_version": "2026-06-17",
"template_status": "manual-import-required",
"app": {
"name": "货代发货通知 Agent",
"mode": "advanced-chat",
"description": "Hxops 货代发货通知 Chatflow 交付模板。用于在 Dify 画布中手工还原节点、变量、HTTP 调用和 Agent 配置。",
"icon": "truck",
"icon_background": "#E0F2FE"
},
"delivery_notes": [
"本文件是仓库侧交付模板,不是从 Dify 控制台实际导出的原生 DSL。",
"实际发布前,仍应在 Dify 中完成节点配置后导出一份官方 DSL 作为最终交付包。",
"Tool API 契约以 docs/openapi/shipping_notice_tools.dify.json 和 backend/app/services/shipping_notice/openapi_spec.py 为准。",
"Agent Prompt、节点职责与 HTTP 示例以 docs/shipping_notice.md 为准。"
],
"tool_openapi": {
"runtime_import_url": "{{HXOPS_TOOLS_API_BASE}}/api/shipping-notice/tools/openapi.json",
"repo_import_file": "docs/openapi/shipping_notice_tools.dify.json",
"auth": {
"header_name": "X-Shipping-Tool-Key",
"value_from_env": "SHIPPING_NOTICE_TOOL_API_KEY"
}
},
"environment_variables": [
{
"name": "HXOPS_API_BASE",
"type": "string",
"required": true,
"example": "http://192.168.100.192:8890"
},
{
"name": "SHIPPING_NOTICE_TOOL_API_KEY",
"type": "secret",
"required": true,
"example": "your-tool-key"
},
{
"name": "HXOPS_TOOLS_API_BASE",
"type": "string",
"required": true,
"example": "http://192.168.100.192:8890"
}
],
"conversation_variables": [
{
"name": "current_batch_no",
"type": "string",
"description": "当前批次号"
},
{
"name": "current_task_no",
"type": "string",
"description": "当前聚焦任务号"
},
{
"name": "current_task_step",
"type": "string",
"description": "当前任务步骤"
},
{
"name": "current_checkpoint",
"type": "string",
"description": "当前人工节点 / checkpoint"
},
{
"name": "current_task_status",
"type": "string",
"description": "当前任务 process_status"
},
{
"name": "batch_queue_summary",
"type": "string",
"description": "批次摘要文案"
},
{
"name": "last_tool_status",
"type": "string",
"description": "最近一次 Tool 调用状态"
}
],
"graph": {
"entry_node_id": "start",
"answer_node_id": "answer_final",
"nodes": [
{
"id": "start",
"type": "start",
"title": "开始",
"outputs": [
"query",
"files",
"conversation_id"
],
"doc_anchor": "docs/shipping_notice.md#L471-L480"
},
{
"id": "ctx_preprocess",
"type": "code",
"title": "预处理上下文",
"script_ref": "docs/shipping_notice.md#L481-L523",
"outputs": [
"normalized_query",
"detected_batch_no",
"detected_task_no",
"intent_hint",
"has_files",
"error_message"
]
},
{
"id": "route_classifier",
"type": "code",
"title": "附件/意图分类",
"script_ref": "docs/shipping_notice.md#L525-L550",
"outputs": [
"route_key",
"reason"
]
},
{
"id": "tool_create_batch",
"type": "tool",
"title": "创建批次",
"operation_id": "create_batch",
"when": "route_key == notice_batch_upload",
"inputs": {
"conversation_id": "{{conversation_id}}",
"file_count": "{{files.length}}"
}
},
{
"id": "iter_notice_files",
"type": "iteration",
"title": "文件循环器",
"when": "route_key == notice_batch_upload",
"iterates": "files",
"doc_anchor": "docs/shipping_notice.md#L442-L449"
},
{
"id": "tool_create_task",
"type": "tool",
"title": "创建单个任务",
"operation_id": "create_task",
"inputs": {
"batch_no": "{{current_batch_no}}",
"conversation_id": "{{conversation_id}}",
"source_type": "pdf",
"source_file_name": "{{iter_notice_files.item.name}}",
"source_file_type": "{{iter_notice_files.item.mime_type}}",
"batch_index": "{{iter_notice_files.index}}",
"batch_total": "{{files.length}}"
}
},
{
"id": "http_extract_notice_text",
"type": "http",
"title": "文本抽取",
"method": "external_or_frontend",
"notes": [
"由前端或 HTTP 节点完成原文抽取。",
"抽取出的 raw_text 继续传给 LLM字段抽取 / parse_notice。"
]
},
{
"id": "llm_extract_notice",
"type": "llm",
"title": "LLM字段抽取",
"prompt_ref": "docs/shipping_notice.md#L733-L778",
"outputs": [
"llm_json_text"
]
},
{
"id": "code_validate_notice_json",
"type": "code",
"title": "抽取结果校验",
"script_ref": "docs/shipping_notice.md#L567-L594",
"outputs": [
"validated_json",
"is_valid",
"error_message"
]
},
{
"id": "tool_parse_notice",
"type": "tool",
"title": "保存解析结果",
"operation_id": "parse_notice",
"inputs": {
"task_id": "{{tool_create_task.text.task_id}}",
"raw_text": "{{http_extract_notice_text.text}}"
}
},
{
"id": "code_batch_summary",
"type": "code",
"title": "批次摘要组装",
"script_ref": "docs/shipping_notice.md#L596-L621",
"outputs": [
"batch_queue_summary",
"focus_task_no"
]
},
{
"id": "code_set_focus_task",
"type": "code",
"title": "设置当前聚焦任务",
"writes_variables": [
"current_batch_no",
"current_task_no"
]
},
{
"id": "tool_get_task_status_init",
"type": "tool",
"title": "读取当前任务状态",
"operation_id": "get_task_status",
"inputs": {
"task_id": "{{current_task_no}}",
"conversation_id": "{{conversation_id}}"
}
},
{
"id": "http_upload_inventory",
"type": "http",
"title": "上传库存文件",
"request_ref": "docs/shipping_notice.md#L271-L310",
"method": "POST",
"url": "{{HXOPS_API_BASE}}/api/shipping-notice/tools/upload_inventory_file",
"headers": {
"X-Shipping-Tool-Key": "{{SHIPPING_NOTICE_TOOL_API_KEY}}"
},
"body_type": "multipart/form-data",
"body": {
"task_id": "{{current_task_no}}",
"file": "{{files[0]}}"
}
},
{
"id": "tool_schema_preview",
"type": "tool",
"title": "读取 schema preview",
"operation_id": "get_inventory_schema_preview",
"inputs": {
"task_id": "{{current_task_no}}"
}
},
{
"id": "llm_map_inventory",
"type": "llm",
"title": "LLM字段映射建议",
"prompt_ref": "docs/shipping_notice.md#L780-L815",
"outputs": [
"mapping_json_text"
]
},
{
"id": "code_validate_mapping",
"type": "code",
"title": "映射 JSON 校验",
"script_ref": "docs/shipping_notice.md#L651-L678",
"outputs": [
"mapping_json",
"is_valid",
"error_message"
]
},
{
"id": "tool_apply_mapping",
"type": "tool",
"title": "应用字段映射",
"operation_id": "apply_inventory_mapping",
"inputs": {
"task_id": "{{current_task_no}}",
"map_json": "{{code_validate_mapping.mapping_json}}"
}
},
{
"id": "code_alignment_result",
"type": "code",
"title": "字段对齐结果收口",
"notes": [
"整理 align_msg / 下一步动作。",
"若 stop_agent_turn=true,则直接进入 Answer。"
]
},
{
"id": "code_switch_intent",
"type": "code",
"title": "任务切换意图解析",
"script_ref": "docs/shipping_notice.md#L623-L649",
"when": "route_key == task_switch"
},
{
"id": "tool_switch_focus_task",
"type": "tool",
"title": "切换聚焦任务",
"operation_id": "switch_focus_task",
"when": "route_key == task_switch",
"inputs": {
"batch_no": "{{current_batch_no}}",
"task_id": "{{code_switch_intent.target_task_no}}",
"switch_mode": "{{code_switch_intent.switch_mode}}"
}
},
{
"id": "tool_get_task_status_after_switch",
"type": "tool",
"title": "加载当前任务详情",
"operation_id": "get_task_status",
"when": "route_key == task_switch",
"inputs": {
"task_id": "{{current_task_no}}",
"conversation_id": "{{conversation_id}}"
}
},
{
"id": "agent_shipping",
"type": "agent",
"title": "货代 Agent",
"instruction_ref": "docs/shipping_notice.md#L881-L912",
"tool_bindings": [
"get_task_status",
"submit_decision",
"match_inventory",
"generate_shipment_excel",
"upload_to_freight",
"auto_progress",
"get_inventory_schema_preview",
"apply_inventory_mapping",
"ensure_inventory",
"parse_inventory",
"update_notice_fields",
"update_notice_line"
]
},
{
"id": "code_normalize_tool_result",
"type": "code",
"title": "工具结果标准化",
"script_ref": "docs/shipping_notice.md#L680-L704",
"outputs": [
"tool_status",
"tool_message",
"tool_checkpoint",
"tool_action_buttons",
"tool_human_options",
"tool_data_json"
]
},
{
"id": "code_build_reply",
"type": "code",
"title": "组装直接回复",
"script_ref": "docs/shipping_notice.md#L706-L731",
"outputs": [
"final_reply"
]
},
{
"id": "answer_final",
"type": "answer",
"title": "直接回复",
"text": "{{final_reply}}"
}
],
"edges": [
{
"from": "start",
"to": "ctx_preprocess"
},
{
"from": "ctx_preprocess",
"to": "route_classifier"
},
{
"from": "route_classifier",
"to": "tool_create_batch",
"condition": "route_key == notice_batch_upload"
},
{
"from": "tool_create_batch",
"to": "iter_notice_files"
},
{
"from": "iter_notice_files",
"to": "tool_create_task"
},
{
"from": "tool_create_task",
"to": "http_extract_notice_text"
},
{
"from": "http_extract_notice_text",
"to": "llm_extract_notice"
},
{
"from": "llm_extract_notice",
"to": "code_validate_notice_json"
},
{
"from": "code_validate_notice_json",
"to": "tool_parse_notice",
"condition": "is_valid == true"
},
{
"from": "tool_parse_notice",
"to": "code_batch_summary"
},
{
"from": "code_batch_summary",
"to": "code_set_focus_task"
},
{
"from": "code_set_focus_task",
"to": "tool_get_task_status_init"
},
{
"from": "tool_get_task_status_init",
"to": "agent_shipping"
},
{
"from": "route_classifier",
"to": "http_upload_inventory",
"condition": "route_key == inventory_upload"
},
{
"from": "http_upload_inventory",
"to": "tool_schema_preview"
},
{
"from": "tool_schema_preview",
"to": "llm_map_inventory"
},
{
"from": "llm_map_inventory",
"to": "code_validate_mapping"
},
{
"from": "code_validate_mapping",
"to": "tool_apply_mapping",
"condition": "is_valid == true"
},
{
"from": "tool_apply_mapping",
"to": "code_alignment_result"
},
{
"from": "code_alignment_result",
"to": "answer_final"
},
{
"from": "route_classifier",
"to": "code_switch_intent",
"condition": "route_key == task_switch"
},
{
"from": "code_switch_intent",
"to": "tool_switch_focus_task"
},
{
"from": "tool_switch_focus_task",
"to": "tool_get_task_status_after_switch"
},
{
"from": "tool_get_task_status_after_switch",
"to": "agent_shipping"
},
{
"from": "route_classifier",
"to": "agent_shipping",
"condition": "route_key == continue_task"
},
{
"from": "agent_shipping",
"to": "code_normalize_tool_result"
},
{
"from": "code_normalize_tool_result",
"to": "code_build_reply"
},
{
"from": "code_build_reply",
"to": "answer_final"
},
{
"from": "route_classifier",
"to": "answer_final",
"condition": "route_key == direct_reply"
}
]
},
"http_examples": {
"upload_inventory_file_ref": "docs/shipping_notice.md#L271-L310",
"create_batch_ref": "docs/shipping_notice.md#L312-L349",
"apply_inventory_mapping_ref": "docs/shipping_notice.md#L350-L369"
},
"acceptance_checklist": [
"OpenAPI 从 docs/openapi/shipping_notice_tools.dify.json 或运行时 /tools/openapi.json 成功导入",
"Agent 节点已绑定 get_task_status/submit_decision/match_inventory/auto_progress/update_notice_* 等工具",
"HTTP 节点已配置 X-Shipping-Tool-Key",
"多通知文件场景能够 create_batch -> create_task -> parse_notice",
"库存 Excel 场景走 upload_inventory_file -> get_inventory_schema_preview -> apply_inventory_mapping",
"align_review 时 Agent 不越过人工确认",
"match_inventory 返回 ok 后,同轮继续 auto_progress",
"parse_review 阶段可调用 update_notice_fields / update_notice_line"
]
}
+362 -4
View File
@@ -11,11 +11,11 @@
}
],
"paths": {
"/tools/create_task": {
"/tools/create_batch": {
"post": {
"operationId": "create_task",
"summary": "创建发货任务 task",
"description": "创建发货任务 task",
"operationId": "create_batch",
"summary": "创建发货批次 batch(一次多文件上传的聚合容器)",
"description": "创建发货批次 batch(一次多文件上传的聚合容器)",
"parameters": [],
"requestBody": {
"required": true,
@@ -24,6 +24,62 @@
"schema": {
"type": "object",
"properties": {
"batch_no": {
"type": "string",
"description": "已存在的批次编号(可选)。传入时将直接复用该批次。"
},
"user_id": {
"type": "integer",
"description": "Hxops 用户 ID(可选)"
},
"conversation_id": {
"type": "string",
"description": "Dify 会话 ID,便于工作台关联"
},
"file_count": {
"type": "integer",
"description": "本批通知文件数量"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/tools/create_task": {
"post": {
"operationId": "create_task",
"summary": "创建发货任务 task(可挂到某个 batch)",
"description": "创建发货任务 task(可挂到某个 batch)",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"batch_no": {
"type": "string",
"description": "发货批次编号(batch id),如 SB-20260617-ABCD1234"
},
"task_id": {
"type": "string",
"description": "已存在的发货任务编号(可选)。传入时将直接复用该任务,禁止重复创建。"
},
"user_id": {
"type": "integer",
"description": "Hxops 用户 ID(可选)"
@@ -42,6 +98,22 @@
"pdf"
]
},
"source_file_name": {
"type": "string",
"description": "原始通知文件名(多文件场景建议传)"
},
"source_file_type": {
"type": "string",
"description": "原始通知文件类型(多文件场景建议传)"
},
"batch_index": {
"type": "integer",
"description": "当前任务在批次中的顺序,从 1 开始"
},
"batch_total": {
"type": "integer",
"description": "当前批次总任务数"
},
"raw_content": {
"type": "string",
"description": "原始发货通知文本(可选,后续 parse 也可传入)"
@@ -108,6 +180,206 @@
}
}
},
"/tools/update_notice_fields": {
"post": {
"operationId": "update_notice_fields",
"summary": "更新解析后的发货通知单头字段,如客户、PO、交期、收货地",
"description": "更新解析后的发货通知单头字段,如客户、PO、交期、收货地",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"task_id": {
"type": "string",
"description": "发货任务编号(task id),如 SN-20260529-ABCD1234"
},
"fields": {
"type": "object",
"description": "可更新字段:customer_name/customer_code/ship_to/po_number/required_date",
"additionalProperties": true
},
"comment": {
"type": "string",
"description": "修改备注(可选)"
}
},
"required": [
"task_id",
"fields"
]
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/tools/update_notice_line": {
"post": {
"operationId": "update_notice_line",
"summary": "更新解析结果中的某一行,如 SKU、Reservation ID、数量、交期",
"description": "更新解析结果中的某一行,如 SKU、Reservation ID、数量、交期",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"task_id": {
"type": "string",
"description": "发货任务编号(task id),如 SN-20260529-ABCD1234"
},
"line_index": {
"type": "integer",
"description": "行下标,从 0 开始"
},
"patch": {
"type": "object",
"description": "可更新字段:sku/reservation_id/quantity/qty/required_date/uom",
"additionalProperties": true
},
"comment": {
"type": "string",
"description": "修改备注(可选)"
}
},
"required": [
"task_id",
"line_index",
"patch"
]
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/tools/add_notice_line": {
"post": {
"operationId": "add_notice_line",
"summary": "向解析结果新增一行发货需求",
"description": "向解析结果新增一行发货需求",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"task_id": {
"type": "string",
"description": "发货任务编号(task id),如 SN-20260529-ABCD1234"
},
"line": {
"type": "object",
"description": "新增行,至少包含 sku 和 qty/quantity",
"additionalProperties": true
},
"comment": {
"type": "string",
"description": "修改备注(可选)"
}
},
"required": [
"task_id",
"line"
]
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/tools/remove_notice_line": {
"post": {
"operationId": "remove_notice_line",
"summary": "删除解析结果中的某一行发货需求",
"description": "删除解析结果中的某一行发货需求",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"task_id": {
"type": "string",
"description": "发货任务编号(task id),如 SN-20260529-ABCD1234"
},
"line_index": {
"type": "integer",
"description": "行下标,从 0 开始"
},
"comment": {
"type": "string",
"description": "修改备注(可选)"
}
},
"required": [
"task_id",
"line_index"
]
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/tools/parse_inventory": {
"post": {
"operationId": "parse_inventory",
@@ -575,6 +847,92 @@
}
}
}
},
"/tools/get_batch_status": {
"post": {
"operationId": "get_batch_status",
"summary": "查询批次当前状态、任务列表与当前聚焦任务",
"description": "查询批次当前状态、任务列表与当前聚焦任务",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"batch_no": {
"type": "string",
"description": "发货批次编号(batch id),如 SB-20260617-ABCD1234"
}
},
"required": [
"batch_no"
]
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/tools/switch_focus_task": {
"post": {
"operationId": "switch_focus_task",
"summary": "切换当前批次的聚焦任务",
"description": "切换当前批次的聚焦任务",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"batch_no": {
"type": "string",
"description": "发货批次编号(batch id),如 SB-20260617-ABCD1234"
},
"task_no": {
"type": "string",
"description": "发货任务编号(task id),如 SN-20260529-ABCD1234"
},
"target_task_no": {
"type": "string",
"description": "发货任务编号(task id),如 SN-20260529-ABCD1234"
}
},
"required": [
"batch_no"
]
}
}
}
},
"responses": {
"200": {
"description": "Tool response (status: ok|running|needs_human|failed). May include checkpoint, human_options, action_buttons.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
}
}
}
+955 -1389
View File
File diff suppressed because it is too large. Load diff