chore: 整理项目结构,清理归档文件,更新部署配置

This commit is contained in:
Simon
2026-07-04 21:01:39 +08:00
parent 8bd4ab0366
commit 64ff1bf7d5
508 changed files with 43575 additions and 14129 deletions
+31 -10
View File
@@ -170,7 +170,24 @@ async def send_message(
if conversation.status == "resolved":
raise ERR_CONVERSATION_RESOLVED
# 2. 创建消息记录
# 2. 敏感词检测(#81 v0.6.0 内容审核)
# 只对文本消息进行敏感词检测
flagged_words = []
if body.msg_type == "text" and body.content:
from app.services.content_moderation_service import ContentModerationService
moderation = ContentModerationService()
result = moderation.moderate(body.content)
if result.matched_words:
flagged_words = result.matched_words
# 检测到敏感词,但只警告不阻止发送
logger.warning(
f"[ContentModeration] 坐席消息含敏感词: "
f"conversation={conv_id_str}, words={flagged_words}"
)
# 返回消息的同时带上警告信息(前端可选择显示提示)
# 3. 创建消息记录
# (原步骤编号顺延)
# 从会话的 assigned_agent_id 获取坐席信息
agent_id = conversation.assigned_agent_id or "unknown"
@@ -197,7 +214,7 @@ async def send_message(
)
db.add(message)
# 3. 更新会话最后消息信息
# 4. 更新会话最后消息信息
conversation.last_message_at = datetime.now()
conversation.last_message_summary = body.content[:256]
conversation.updated_at = datetime.now()
@@ -205,7 +222,7 @@ async def send_message(
await db.flush() # 刷新以获取消息 ID
# 4. 调用企微 API 发送消息给员工
# 5. 调用企微 API 发送消息给员工
# 注意:只有 text 类型消息才需要调用企微 API 推送给员工
# image/file 等非文本消息暂不通过企微推送(仅存储消息记录供坐席查看)
# 跳过 Redis 连可避免无谓的网络开销,减少截图发送超时
@@ -232,7 +249,7 @@ async def send_message(
# 企微 API 调用失败不阻塞消息存储
logger.warning(f"企微消息发送失败(消息已存储): {e}")
# 5. 更新消息状态为已发送
# 6. 更新消息状态为已发送
message.status = "sent"
await db.flush()
@@ -249,6 +266,7 @@ async def send_message(
async def poll_messages(
conversation_id: str,
after_message_id: Optional[str] = Query(None, description="返回此消息ID之后的新消息"),
current_agent: Agent = Depends(get_current_agent), # 添加此参数以支持权限验证
db: AsyncSession = Depends(get_db),
):
"""坐席轮询新消息。
@@ -311,7 +329,7 @@ async def poll_messages(
@require_permission("conversation", "update", "own")
async def recall_message(
message_id: str,
agent: Agent = Depends(get_current_agent),
current_agent: Agent = Depends(get_current_agent),
db: AsyncSession = Depends(get_db),
):
"""撤回消息(2分钟内)。
@@ -325,12 +343,13 @@ async def recall_message(
Args:
message_id: 消息ID
agent: 当前坐席(鉴权依赖注入)
current_agent: 当前坐席(鉴权依赖注入)
db: 数据库会话
Returns:
Dict: 统一响应格式
"""
agent = current_agent # 保持函数体内 agent 引用不变
# 查询消息
stmt = select(Message).where(Message.id == str(message_id))
result = await db.execute(stmt)
@@ -389,7 +408,7 @@ async def recall_message(
@require_permission("conversation", "update", "own")
async def delete_message(
message_id: str,
agent: Agent = Depends(get_current_agent),
current_agent: Agent = Depends(get_current_agent),
db: AsyncSession = Depends(get_db),
):
"""删除坐席自己发送的消息。
@@ -401,12 +420,13 @@ async def delete_message(
Args:
message_id: 消息ID
agent: 当前坐席(鉴权依赖注入)
current_agent: 当前坐席(鉴权依赖注入)
db: 数据库会话
Returns:
Dict: 统一响应格式
"""
agent = current_agent # 保持函数体内 agent 引用不变
# 查询消息
stmt = select(Message).where(Message.id == str(message_id))
result = await db.execute(stmt)
@@ -433,7 +453,7 @@ async def delete_message(
@require_permission("conversation", "update", "own")
async def mark_read(
conversation_id: str,
agent: Agent = Depends(get_current_agent),
current_agent: Agent = Depends(get_current_agent),
db: AsyncSession = Depends(get_db),
):
"""标记会话中所有员工未读消息为已读。
@@ -449,12 +469,13 @@ async def mark_read(
Args:
conversation_id: 会话ID
agent: 当前坐席(鉴权依赖注入)
current_agent: 当前坐席(鉴权依赖注入)
db: 数据库会话
Returns:
Dict: 统一响应格式
"""
agent = current_agent # 保持函数体内 agent 引用不变
conv_id_str = str(conversation_id)
# P0-4 修复:先校验当前坐席有权访问此会话