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

+51 -25
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import Any
from app.services.shipping_notice.i18n import resolve_lang, t
from app.services.shipping_notice.reservation_id import extract_reservation_id
@@ -112,18 +112,46 @@ def _fmt_qty(value: float) -> str:
return f"{value:g}"
def _md_cell(value: Any) -> str:
text = str(value or "").strip() or "-"
return text.replace("|", "\\|")
def format_match_summary(
match_status: str,
line_results: list[dict[str, Any]],
*,
task_no: str | None = None,
lang: str | None = None,
) -> str:
"""Human-readable order qty vs inventory qty for match_inventory responses."""
"""Fixed Markdown table for match_inventory responses (Agent must display verbatim)."""
resolved = resolve_lang({"lang": lang} if lang else None)
if not line_results:
return "无订单明细,无法比对数量。"
return t("match.no_lines", lang=resolved)
lines = ["匹配明细(订单数量 vs 库存可用量):"]
for i, row in enumerate(line_results, 1):
sku = str(row.get("sku") or "-")
reservation_id = str(row.get("reservation_id") or "-")
lines: list[str] = []
if task_no:
lines.append(t("match.title", lang=resolved).format(task_no=task_no))
lines.append("")
lines.append(t("match.subtitle", lang=resolved))
lines.append("")
lines.append(
"| # | "
f"{t('field.reservation_id', lang=resolved)} | "
f"{t('field.sku', lang=resolved)} | "
f"{t('match.col.order_qty', lang=resolved)} | "
f"{t('match.col.inv_qty', lang=resolved)} | "
f"{t('match.col.gap', lang=resolved)} | "
f"{t('match.col.status', lang=resolved)} |"
)
lines.append("|---:|---|---|---:|---:|---:|---|")
status_keys = {
"ok": "match.status.ok",
"partial": "match.status.partial",
"shortage": "match.status.shortage",
}
for index, row in enumerate(line_results, 1):
try:
required = float(row.get("required_qty") or 0)
except (TypeError, ValueError):
@@ -137,25 +165,23 @@ def format_match_summary(
except (TypeError, ValueError):
shortage = 0.0
status = str(row.get("line_status") or "")
status_label = {"ok": "充足", "partial": "部分满足", "shortage": "不足"}.get(
status, status or "未知"
status_label = t(status_keys.get(status, "match.status.unknown"), lang=resolved)
gap_cell = "-" if shortage <= 0 else _fmt_qty(shortage)
lines.append(
"| "
f"{index} | "
f"{_md_cell(row.get('reservation_id'))} | "
f"{_md_cell(row.get('sku'))} | "
f"{_fmt_qty(required)} | "
f"{_fmt_qty(available)} | "
f"{gap_cell} | "
f"{status_label} |"
)
detail = (
f"{i}. SKU {sku} | Reservation ID {reservation_id} | "
f"订单 {_fmt_qty(required)} / 库存 {_fmt_qty(available)} | {status_label}"
)
if shortage > 0:
detail += f"(缺口 {_fmt_qty(shortage)})"
lines.append(detail)
lines.append("")
if match_status == "fulfillable":
lines.append("结论:库存充足,可生成发货 Excel 并上传货代系统。")
elif match_status == "partial":
lines.append("结论:部分行库存不足,请复核缺口后决定是否部分发货。")
elif match_status == "unfulfillable":
lines.append("结论:库存均不足,无法整单发货。")
else:
lines.append(f"结论:match_status={match_status}")
conclusion_key = f"match.conclusion.{match_status}"
conclusion = t(conclusion_key, lang=resolved)
if conclusion == conclusion_key:
conclusion = t("match.conclusion.other", lang=resolved).format(status=match_status)
lines.append(conclusion)
return "\n".join(lines)