feat(shipping): 新增货代发货批量自动处理与任务重试功能

本次提交完整实现货代发货通知的自动化批量处理能力:
1.  新增发货单票后台任务类型与专用worker队列,实现任务持久化调度
2.  实现发货批次后台编排器,支持上传后自动逐票推进解析、匹配、导出全流程
3.  新增单票重试、批次待处理重试的API与前端操作界面
4.  补充全量多语言翻译,新增重试、任务列表、状态展示相关文案
5.  优化上传交互逻辑,改为后台自动处理任务,无需手动触发解析指令
6.  修复文件检核工具无数据预检逻辑,避免创建空检核批次
7.  调整发货工作流细节,优化Excel生成幂等性与任务状态同步
8.  更新环境配置与API文档,修正货代工具接口地址端口
This commit is contained in:
hugo committed 2026-06-23 11:22:09 +08:00
1 parent 70e8f700ff
commit 08360a4142
40 files changed
+2515 -371

No files matched your search

+136 -16
View File
@@ -1457,18 +1457,53 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输
| 输出名 | Dify 类型 | 说明 |
| --- | --- | --- |
| `ok` | Boolean | API `ok` 字段 |
| `error_code` | String | 如 `check_running` / `task_not_found` |
| `error_code` | String | 如 `check_running` / `no_data_to_check` / `task_not_found` |
| `message` | String | 提示或错误文案 |
| `run_id` | String | 检核批次 ID |
| `run_no` | String | 检核批次编号 |
| `run_status` | String | `running` / `success` / `failed` 等 |
| `run_status_label` | String | 批次状态中文文案 |
| `task_name` | String | 检核任务名称 |
| `started_at` | String | ISO 时间字符串 |
| `started_at_display` | String | 按北京时间格式化的启动时间 |
| `scene` | String | `started` / `already_running` / `no_data` / `failed` |
| `has_run_id` | Boolean | 是否拿到了有效批次 ID |
**完整 Python 代码**
```python
import json
from datetime import datetime, timezone, timedelta
_CN_TZ = timezone(timedelta(hours=8))
_STATUS_LABEL = {
"queued": "排队中",
"running": "进行中",
"success": "已完成",
"partial_failed": "部分失败",
"failed": "失败",
"cancelled": "已取消",
}
_DEFAULT_TASK_NAME = "RoHS 文件检核"
def _empty_result(message: str = "") -> dict:
return {
"ok": False,
"error_code": "invalid_response",
"message": message,
"run_id": "",
"run_no": "",
"run_status": "",
"run_status_label": "",
"task_name": "",
"started_at": "",
"started_at_display": "",
"scene": "failed",
"has_run_id": False,
}
def _load_tool_json(tool_json, tool_text):
if isinstance(tool_json, list) and tool_json:
@@ -1487,25 +1522,91 @@ def _load_tool_json(tool_json, tool_text):
return {}
return {}
def main(tool_json, tool_text) -> dict:
empty = {
"ok": False, "error_code": "invalid_response", "message": "",
"run_id": "", "run_no": "", "run_status": "", "task_name": "", "started_at": "",
}
def _format_started_at(iso_str) -> str:
if not iso_str:
return ""
s = str(iso_str).strip()
if not s:
return ""
if s.endswith("Z"):
s = s[:-1] + "+00:00"
try:
dt = datetime.fromisoformat(s)
except ValueError:
return str(iso_str)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)
local = dt.astimezone(_CN_TZ)
return f"{local.year}年{local.month}月{local.day}日 {local.hour:02d}:{local.minute:02d}"
def _status_label(status: str) -> str:
key = str(status or "").strip().lower()
if not key:
return ""
return _STATUS_LABEL.get(key, status)
def _resolve_scene(ok: bool, error_code: str) -> str:
code = str(error_code or "").strip()
if ok:
return "started"
if code == "check_running":
return "already_running"
if code == "no_data_to_check":
return "no_data"
return "failed"
def _safe_str(value) -> str:
if value is None:
return ""
return str(value).strip()
def main(tool_json, tool_text: str = "") -> dict:
data = _load_tool_json(tool_json, tool_text)
if not data:
empty["message"] = "无 Tool 响应"
empty = _empty_result("目前没有资料需要检核。")
empty["error_code"] = "no_data_to_check"
empty["scene"] = "no_data"
return empty
run = data.get("run") or {}
if not isinstance(run, dict):
run = {}
ok = bool(data.get("ok"))
error_code = _safe_str(data.get("error_code"))
message = _safe_str(data.get("message"))
run_id = _safe_str(run.get("run_id"))
run_no = _safe_str(run.get("run_no"))
run_status = _safe_str(run.get("status"))
task_name = _safe_str(
run.get("task_name") or run.get("schedule_name") or _DEFAULT_TASK_NAME
)
started_at = _safe_str(run.get("started_at"))
return {
"ok": bool(data.get("ok")),
"error_code": str(data.get("error_code") or ""),
"message": str(data.get("message") or ""),
"run_id": str(run.get("run_id") or ""),
"run_no": str(run.get("run_no") or ""),
"run_status": str(run.get("status") or ""),
"task_name": str(run.get("task_name") or run.get("schedule_name") or ""),
"started_at": str(run.get("started_at") or ""),
"ok": ok,
"error_code": error_code,
"message": message,
"run_id": run_id,
"run_no": run_no,
"run_status": run_status,
"run_status_label": _status_label(run_status),
"task_name": task_name,
"started_at": started_at,
"started_at_display": _format_started_at(started_at),
"scene": _resolve_scene(ok, error_code),
"has_run_id": bool(run_id),
}
```
@@ -1525,6 +1626,7 @@ def main(tool_json, tool_text) -> dict:
| --- | --- |
| `解析启动检核响应.ok == true` | [§3.11 Answer:检核已启动](#311-answer检核已启动) |
| `解析启动检核响应.error_code == "check_running"` | [§3.12 Answer:检核进行中](#312-answer检核进行中) |
| `解析启动检核响应.error_code == "no_data_to_check"` | [§3.13 Answer:没有资料需要检核](#313-answer没有资料需要检核) |
| 默认 | [§3.24 Answer:错误兜底(启动检核 body)](#324-answer错误兜底启动检核) |
---
@@ -1572,6 +1674,24 @@ def main(tool_json, tool_text) -> dict:
---
### 3.13 Answer:没有资料需要检核
**上游**:IF 启动业务分支(`error_code == "no_data_to_check"`)
**引用变量**:`解析启动检核响应.message` · **String**
**回复模板**
```text
目前没有资料需要检核,暂时不用启动本次检核。
{{#解析启动检核响应.message#}}
如果后续有新的资料进入检核范围,再发起一次即可。
```
---
### 3.14 Code:提取查询参数
**上游**:IF 意图分类(`check_status` 分支)
@@ -2031,7 +2151,7 @@ def main(tool_json, tool_text) -> dict:
### 3.24 Answer:错误兜底(启动检核 body)
**上游**:IF 启动业务分支(Tool **成功出口** 后,body 中 `ok=false` 且非 `check_running`;如 `invalid_response`)
**上游**:IF 启动业务分支(Tool **成功出口** 后,body 中 `ok=false` 且非 `check_running`、`no_data_to_check`;如 `invalid_response`)
**引用变量**:`解析启动检核响应.message` · **String**;`解析启动检核响应.error_code` · **String**
+10 -1
View File
@@ -157,6 +157,15 @@
"raw_text": {
"type": "string",
"description": "待解析的发货通知全文"
},
"structured": {
"type": "object",
"description": "Dify LLM 解析后的结构化结果对象。若提供,后端优先使用该对象中的 lines/confidence/reservation_id 等字段落库。",
"additionalProperties": true
},
"lang": {
"type": "string",
"description": "可选语言代码:zh|en|th"
}
},
"required": [
@@ -935,4 +944,4 @@
}
}
}
}
}