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
@@ -1,4 +1,6 @@
|
||||
"""Seed agents for freight shipping notice Chatflow orchestration."""
|
||||
import sqlalchemy as sa
|
||||
|
||||
from app import create_app, db
|
||||
from app.models import Agent
|
||||
from app.services.shipping_notice.agent_resolver import CHAT_AGENT_NAME, EXTRACT_AGENT_NAME
|
||||
@@ -9,6 +11,30 @@ CHAT_DESCRIPTION = "货代发货通知智能体:自然语言驱动解析、库
|
||||
EXTRACT_DESCRIPTION = "后台专用:从邮件/PDF 文本抽取结构化发货通知字段(Workflow,供 Tool 内部调用)"
|
||||
|
||||
|
||||
def _normalize_url(raw: str | None) -> str | None:
|
||||
if raw is None:
|
||||
return None
|
||||
text = str(raw).strip()
|
||||
if not text:
|
||||
return None
|
||||
if (text.startswith("`") and text.endswith("`")) or (text.startswith('"') and text.endswith('"')):
|
||||
text = text[1:-1].strip()
|
||||
return text or None
|
||||
|
||||
|
||||
def _ensure_pg_sequence(table: str, pk: str) -> None:
|
||||
engine_name = db.engine.dialect.name
|
||||
if engine_name != "postgresql":
|
||||
return
|
||||
if not table.replace("_", "").isalnum() or not pk.replace("_", "").isalnum():
|
||||
raise ValueError("invalid identifier")
|
||||
sql = sa.text(
|
||||
f"SELECT setval(pg_get_serial_sequence(:tbl, :pk), COALESCE((SELECT MAX({pk}) FROM {table}), 0), true)"
|
||||
)
|
||||
db.session.execute(sql, {"tbl": table, "pk": pk})
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def _upsert_agent(
|
||||
*,
|
||||
name: str,
|
||||
@@ -52,10 +78,11 @@ if __name__ == "__main__":
|
||||
import os
|
||||
|
||||
with app.app_context():
|
||||
_ensure_pg_sequence("agents", "id")
|
||||
chat_key = os.getenv("SHIPPING_NOTICE_CHAT_DIFY_API_KEY") or os.getenv("DIFY_API_KEY")
|
||||
chat_base = os.getenv("SHIPPING_NOTICE_CHAT_DIFY_BASE") or os.getenv("DIFY_API_BASE")
|
||||
chat_base = _normalize_url(os.getenv("SHIPPING_NOTICE_CHAT_DIFY_BASE") or os.getenv("DIFY_API_BASE"))
|
||||
extract_key = os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_API_KEY")
|
||||
extract_base = os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_BASE") or chat_base
|
||||
extract_base = _normalize_url(os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_BASE") or chat_base)
|
||||
|
||||
_upsert_agent(
|
||||
name=CHAT_AGENT_NAME,
|
||||
|
||||
Reference in new issue
Block a user