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:
1 parent
2ce5256483
commit
c18c0394d0
50 files changed
+6088
-2407
No files matched your search
@@ -1,14 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from app.services.dify import DifyService
|
||||
from app.services.shipping_notice.po_number import enrich_notice_with_po_number
|
||||
from app.services.shipping_notice.reservation_id import find_reservation_id_in_document
|
||||
from app.services.shipping_notice.agent_resolver import resolve_extract_agent
|
||||
from app.services.shipping_notice.notice_lines import (
|
||||
enrich_notice_with_document_currency,
|
||||
enrich_notice_with_document_required_date,
|
||||
@@ -19,28 +15,6 @@ from app.services.shipping_notice.notice_lines import (
|
||||
)
|
||||
|
||||
|
||||
def _parse_workflow_outputs(result: dict[str, Any]) -> dict[str, Any] | None:
|
||||
outputs = result.get("outputs") if isinstance(result, dict) else None
|
||||
if not isinstance(outputs, dict):
|
||||
data = result.get("data") if isinstance(result, dict) else None
|
||||
outputs = data.get("outputs") if isinstance(data, dict) else None
|
||||
if not isinstance(outputs, dict):
|
||||
return None
|
||||
|
||||
for key in ("result", "text", "json", "structured", "output"):
|
||||
val = outputs.get(key)
|
||||
if isinstance(val, dict):
|
||||
return val
|
||||
if isinstance(val, str) and val.strip():
|
||||
try:
|
||||
parsed = json.loads(val)
|
||||
if isinstance(parsed, dict):
|
||||
return parsed
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
return outputs if outputs else None
|
||||
|
||||
|
||||
def _finalize_notice_parse(
|
||||
parsed: dict[str, Any],
|
||||
*,
|
||||
@@ -61,34 +35,6 @@ def _finalize_notice_parse(
|
||||
return parsed, round(confidence, 4), warnings
|
||||
|
||||
|
||||
def _resolve_workflow_file_input_key(agent) -> str | None:
|
||||
forced = str(os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_FILE_INPUT_KEY") or "").strip()
|
||||
if forced:
|
||||
return forced
|
||||
|
||||
params = DifyService.get_app_parameters(agent) or {}
|
||||
|
||||
def _walk(v: Any) -> str | None:
|
||||
if isinstance(v, dict):
|
||||
var = str(v.get("variable") or v.get("name") or "").strip()
|
||||
t = str(v.get("type") or v.get("value_type") or v.get("valueType") or "").strip().lower()
|
||||
has_file_cfg = isinstance(v.get("file"), dict) or isinstance(v.get("file_upload"), dict) or isinstance(v.get("fileUpload"), dict)
|
||||
if var and (has_file_cfg or t in {"file", "files", "file_array", "filearray", "file-list", "file_list"}):
|
||||
return var
|
||||
for vv in v.values():
|
||||
hit = _walk(vv)
|
||||
if hit:
|
||||
return hit
|
||||
elif isinstance(v, list):
|
||||
for item in v:
|
||||
hit = _walk(item)
|
||||
if hit:
|
||||
return hit
|
||||
return None
|
||||
|
||||
return _walk(params)
|
||||
|
||||
|
||||
def extract_notice_fields(
|
||||
*,
|
||||
raw_text: str,
|
||||
@@ -105,34 +51,6 @@ def extract_notice_fields(
|
||||
raw_text=str(structured.get("raw_text") or ""),
|
||||
)
|
||||
|
||||
agent = resolve_extract_agent()
|
||||
if agent and (raw_text.strip() or notice_files):
|
||||
try:
|
||||
inputs: dict[str, Any] = {"raw_text": raw_text, "source_type": source_type}
|
||||
if notice_files:
|
||||
key = _resolve_workflow_file_input_key(agent)
|
||||
if key:
|
||||
inputs[key] = notice_files
|
||||
else:
|
||||
warnings.append("workflow_file_input_key_missing")
|
||||
result = DifyService.run_workflow_streaming(
|
||||
agent=agent,
|
||||
inputs=inputs,
|
||||
user="shipping_notice_tool",
|
||||
)
|
||||
parsed = _parse_workflow_outputs(result)
|
||||
if parsed:
|
||||
finalized, confidence, line_warnings = _finalize_notice_parse(
|
||||
parsed,
|
||||
base_confidence=float(parsed.get("confidence") or 0.85),
|
||||
raw_text=raw_text,
|
||||
)
|
||||
warnings.extend(line_warnings)
|
||||
return finalized, confidence, warnings
|
||||
warnings.append("workflow_returned_no_structured_output")
|
||||
except Exception as exc:
|
||||
warnings.append(f"workflow_error:{exc}")
|
||||
|
||||
heuristic, confidence, heuristic_warnings = _heuristic_extract(raw_text)
|
||||
warnings.extend(heuristic_warnings)
|
||||
return _finalize_notice_parse(heuristic, base_confidence=confidence, raw_text=raw_text)
|
||||
|
||||
Reference in new issue
Block a user