docs: 移动蓝绿部署指南到 troubleshooting 目录

This commit is contained in:
Simon
2026-07-05 17:03:36 +08:00
parent ab90db3d3d
commit ca7c6d937a
91 changed files with 4841 additions and 406 deletions
+32 -28
View File
@@ -33,9 +33,8 @@ from app.schemas.message import MessageCreate, MessageResponse
from app.api.agents import get_current_agent
# RBAC 权限装饰器
from app.dependencies import require_permission
from app.dependencies import require_permission, get_current_user, UserInfo
from app.services.wecom_service import WecomService
from app.services.ws_manager import manager
from app.utils.response import AppException, ERR_CONVERSATION_NOT_FOUND, ERR_CONVERSATION_RESOLVED, success_response
@@ -60,6 +59,7 @@ async def list_messages(
conversation_id: str,
limit: int = Query(50, ge=1, le=100, description="每页消息数量"),
before: Optional[str] = Query(None, description="加载此消息ID之前的消息(向上翻页)"),
current_agent: Agent = Depends(get_current_agent),
db: AsyncSession = Depends(get_db),
):
"""获取会话消息列表(分页)。
@@ -142,6 +142,7 @@ async def send_message(
conversation_id: str,
body: MessageCreate,
db: AsyncSession = Depends(get_db),
current_user: UserInfo = Depends(get_current_user),
):
"""坐席发送消息。
@@ -222,37 +223,40 @@ async def send_message(
await db.flush() # 刷新以获取消息 ID
# 5. 调用企微 API 发送消息给员工
# 注意:只有 text 类型消息才需要调用企微 API 推送给员工
# image/file 等非文本消息暂不通过企微推送(仅存储消息记录供坐席查看)
# 跳过 Redis 连可避免无谓的网络开销,减少截图发送超时
if body.msg_type == "text":
# dev 模式短路:直接跳过企微推送,避免 invalid corpid 噪音
from app.config import settings
if getattr(settings, 'dev_mode', False):
logger.debug(f"[DEV] 跳过企微推送: msg_id={message.id}")
else:
try:
import redis.asyncio as aioredis
# 5. 移除企微 API 调用,仅通过 WebSocket 推送到 H5
# 企微提醒由定时任务处理(超时未回复场景)
# 只保留 WebSocket 推送逻辑
redis_client = settings.create_redis_client()
wecom_service = WecomService(redis_client)
# 6. 更新会话的最后坐席回复时间(用于超时提醒判断)
conversation.last_agent_reply_at = datetime.now()
conversation.reminder_sent = False # 重置提醒标记,允许再次发送提醒
conversation.pending_close_at = datetime.now() + timedelta(minutes=10) # 10分钟后待关闭
db.add(conversation)
await wecom_service.send_text_message(
conversation.employee_id, body.content
)
await wecom_service.close()
await redis_client.close()
except Exception as e:
# 企微 API 调用失败不阻塞消息存储
logger.warning(f"企微消息发送失败(消息已存储): {e}")
# 6. 更新消息状态为已发送
# 7. 更新消息状态为已发送
message.status = "sent"
await db.flush()
# 7. 通过 WebSocket 推送消息给 H5 用户
# 做什么:构建 new_message 事件,推送给会话的员工
# 为什么:实现双通道推送(企微消息 + WebSocket),H5 用户可以实时收到消息
try:
# 构建消息载荷
msg_payload = MessageResponse.model_validate(message).model_dump()
# 构建 WebSocket 事件
ws_event = {
"type": "new_message",
"data": msg_payload,
}
# 推送给会话的员工(H5用户)
await manager.send_to_employee(conversation.employee_id, ws_event)
logger.debug(f"WebSocket消息推送成功: employee_id={conversation.employee_id}, msg_id={message.id}")
except Exception as e:
# WebSocket 推送失败不阻塞响应(员工可能未打开H5页面)
logger.warning(f"WebSocket消息推送失败(H5用户可能不在线): {e}")
# 转换为响应格式
response_data = MessageResponse.model_validate(message).model_dump()
return success_response(data=response_data)