docs: 移动蓝绿部署指南到 troubleshooting 目录
This commit is contained in:
@@ -20,6 +20,7 @@ from fastapi import APIRouter, Depends, Query
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
import redis.asyncio as aioredis
|
||||
from app.database import get_db
|
||||
from app.models.agent import Agent
|
||||
from app.models.conversation import Conversation
|
||||
@@ -41,7 +42,7 @@ from app.utils.response import AppException, success_response
|
||||
from app.api.agents import get_current_agent
|
||||
|
||||
# RBAC 权限装饰器
|
||||
from app.dependencies import require_role, require_permission
|
||||
from app.dependencies import get_redis, require_role, require_permission
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -61,6 +62,7 @@ async def list_conversations(
|
||||
page_size: int = Query(50, ge=1, le=100, description="每页数量"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_agent: Agent = Depends(get_current_agent),
|
||||
redis: aioredis.Redis = Depends(get_redis),
|
||||
):
|
||||
"""坐席获取会话列表(全局可见)。
|
||||
|
||||
@@ -82,7 +84,7 @@ async def list_conversations(
|
||||
Returns:
|
||||
Dict: 统一响应格式,包含会话列表和总数
|
||||
"""
|
||||
session_service = SessionService(db)
|
||||
session_service = SessionService(db, redis_client=redis)
|
||||
conversations, total = await session_service.get_conversations(
|
||||
status=status,
|
||||
agent_id=agent_id,
|
||||
@@ -107,10 +109,18 @@ async def list_conversations(
|
||||
for agent in result.scalars().all():
|
||||
agent_name_map[agent.user_id] = agent.name
|
||||
|
||||
# 转换为响应 Schema,附加 is_mine / assigned_agent_name / can_grab 字段
|
||||
# 批量获取员工头像(带缓存)
|
||||
employee_ids = list(set([conv.employee_id for conv in conversations]))
|
||||
employee_avatar_map = {}
|
||||
for emp_id in employee_ids:
|
||||
employee_avatar_map[emp_id] = await session_service._get_employee_avatar(emp_id)
|
||||
|
||||
# 转换为响应 Schema,附加 is_mine / assigned_agent_name / can_grab / avatar 字段
|
||||
items = []
|
||||
for conv in conversations:
|
||||
conv_data = ConversationResponse.model_validate(conv).model_dump()
|
||||
# 员工头像(从缓存获取)
|
||||
conv_data["avatar"] = employee_avatar_map.get(conv.employee_id, "")
|
||||
# 是否为当前坐席的会话
|
||||
conv_data["is_mine"] = conv.assigned_agent_id == current_agent.user_id
|
||||
# 坐席姓名(从批量查询结果中获取)
|
||||
@@ -152,6 +162,7 @@ async def list_conversations(
|
||||
async def get_conversation(
|
||||
conversation_id: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
redis: aioredis.Redis = Depends(get_redis),
|
||||
):
|
||||
"""获取会话详情。
|
||||
|
||||
@@ -162,10 +173,14 @@ async def get_conversation(
|
||||
Returns:
|
||||
Dict: 统一响应格式,包含会话详情
|
||||
"""
|
||||
session_service = SessionService(db)
|
||||
session_service = SessionService(db, redis_client=redis)
|
||||
conversation = await session_service.get_conversation(conversation_id)
|
||||
|
||||
# 获取员工头像(带缓存)
|
||||
avatar = await session_service._get_employee_avatar(conversation.employee_id)
|
||||
|
||||
response_data = ConversationResponse.model_validate(conversation).model_dump()
|
||||
response_data["avatar"] = avatar
|
||||
return success_response(data=response_data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user