feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认

This commit is contained in:
hugo committed 2026-07-16 08:16:19 +08:00
1 parent b595e157e9
commit 4fbaed2b4c
176 files changed
+14011 -994

No files matched your search

+22 -22
View File
@@ -862,7 +862,7 @@ class DifyService:
base_url = agent.api_base_url if agent.api_base_url else Config.DIFY_API_BASE
url = DifyService._build_chat_messages_url(base_url)
normalized_conversation_id = DifyService._normalize_dify_conversation_id(conversation_id)
visible_query = str(display_query or query or '').strip()
visible_query = str(query if display_query is None else display_query).strip()
headers = {
'Authorization': f'Bearer {agent.dify_api_key}',
@@ -1128,19 +1128,20 @@ class DifyService:
if isinstance(e, requests.exceptions.ReadTimeout) and has_sent_answer:
if current_app:
current_app.logger.warning(
"[chat-stream] read timeout after answer request_id=%s attempt=%s; finish stream silently",
"[chat-stream] read timeout after answer request_id=%s attempt=%s; emit synthetic terminal",
request_id,
attempt,
)
persist_stream_chat(
{
'event': 'message_end',
'conversation_id': normalized_conversation_id,
'answer': ''.join(full_answer).strip(),
'metadata': {},
},
'message_end',
)
# [STEP 3] 已有正文时用合成 message_end 正常收口;persist 会把 chat_log_id 回写到同一事件,
# 领域 Handler 仍能在网络超时后完成状态持久化,而前端不会把本轮误判为永久处理中。
timeout_end_event = {
'event': 'message_end',
'conversation_id': normalized_conversation_id,
'answer': ''.join(full_answer).strip(),
'metadata': {},
}
persist_stream_chat(timeout_end_event, 'message_end')
yield f"data: {json.dumps(timeout_end_event, ensure_ascii=False)}\n\n"
break
if not is_timeout and attempt < max_retries:
time.sleep(attempt * 2)
@@ -1154,17 +1155,16 @@ class DifyService:
message = "连接 Dify 超时,请检查 Dify API Base URL 和网络连通性。"
else:
message = str(e)
persist_stream_chat(
{
'event': 'error',
'conversation_id': normalized_conversation_id,
'answer': f"[Error: {message}]",
'metadata': {},
},
'error',
)
error_msg = json.dumps({'event': 'error', 'message': message})
yield f"data: {error_msg}\n\n"
# [STEP 4] 错误事件与持久化对象必须是同一个 dict,确保 chat_log_id 能继续传给 relay/领域 Handler。
error_event = {
'event': 'error',
'conversation_id': normalized_conversation_id,
'answer': f"[Error: {message}]",
'message': message,
'metadata': {},
}
persist_stream_chat(error_event, 'error')
yield f"data: {json.dumps(error_event, ensure_ascii=False)}\n\n"
@staticmethod
def _log_chat(