feat(shipping-notice): 完成货代发货通知全流程开发与代码重构

- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑
- 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示
- 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败
- 新增路径工具类统一管理相对路径,优化配置文件处理逻辑
- 归档旧文档,将部署、Dify配置合并到`shipping_notice.md`
- 新增完整单元测试与集成测试覆盖核心流程
- 更新前端国际化与会话管理逻辑,优化界面交互
This commit is contained in:
hugo committed 2026-06-04 15:26:34 +08:00
1 parent b62082758b
commit 8deae3146b
65 files changed
+6477 -1937

No files matched your search

+33 -10
View File
@@ -16,7 +16,7 @@ from datetime import datetime
from urllib.parse import urlparse
import requests
from flask import Blueprint, request, Response, stream_with_context, jsonify, g, current_app, has_request_context
from sqlalchemy import func, desc, or_
from sqlalchemy import func, desc, or_, exists, and_
from openpyxl import load_workbook
from app.services.dify import DifyService
from app.services.integration_api import IntegrationApiService
@@ -56,6 +56,21 @@ def _get_chat_session(user_id: int, agent_id: int, session_id: str | None):
).first()
def _chat_logs_for_session(user_id: int, agent_id: int, session: ChatSession):
match_ids = {session.session_id}
external_id = str(session.external_conversation_id or '').strip()
if external_id:
match_ids.add(external_id)
return db.session.query(ChatLog).filter(
ChatLog.user_id == user_id,
ChatLog.agent_id == agent_id,
or_(
ChatLog.session_id.in_(match_ids),
ChatLog.conversation_id.in_(match_ids),
),
).order_by(ChatLog.created_at.asc()).all()
def _ensure_chat_session(
user_id: int,
agent_id: int,
@@ -742,9 +757,19 @@ def get_chat_sessions():
if user is None or agent is None:
raise AppError(code='SYSTEM.INTERNAL_ERROR', message='Missing context', http_status=500)
session_rows = db.session.query(ChatSession).filter_by(
user_id=user.id,
agent_id=agent.id,
session_rows = db.session.query(ChatSession).filter(
ChatSession.user_id == user.id,
ChatSession.agent_id == agent.id,
or_(
ChatSession.status == 'running',
exists().where(
and_(
ChatLog.session_id == ChatSession.session_id,
ChatLog.user_id == user.id,
ChatLog.agent_id == agent.id,
)
),
),
).order_by(desc(ChatSession.last_active_at), desc(ChatSession.id)).limit(20).all()
sessions = [_serialize_session(item) for item in session_rows]
@@ -857,14 +882,12 @@ def get_chat_messages():
session = _get_chat_session(getattr(g.current_user, 'id', 0), getattr(g.current_agent, 'id', 0), conversation_id)
if session:
logs = _chat_logs_for_session(g.current_user.id, g.current_agent.id, session)
else:
logs = db.session.query(ChatLog).filter(
ChatLog.user_id == g.current_user.id,
ChatLog.agent_id == g.current_agent.id,
ChatLog.session_id == session.session_id,
).order_by(ChatLog.created_at.asc()).all()
else:
logs = db.session.query(ChatLog).filter_by(
conversation_id=conversation_id
ChatLog.conversation_id == conversation_id,
).order_by(ChatLog.created_at.asc()).all()
messages = []
@@ -1325,7 +1348,7 @@ def upload_chat_file():
headers=headers,
files={'file': (filename or 'upload', upload.stream, mimetype or 'application/octet-stream')},
data={'user': str(getattr(user, 'id', 'system'))},
timeout=(5, 60),
timeout=(5, 300),
)
except requests.RequestException as exc:
raise ServiceUnavailableError(f'Upload failed: {exc}')