449c6d4875
## H5 员工端 v4 (2026-07-13 00:48 已部署)
- 人工按钮三态文案统一为"人工坐席"
- 按钮位置移至发送键和语音按钮上方(垂直堆叠)
- 点按钮直接调 store.shakeAgent(),删除 CallAgentModal 弹窗动画
- 截图快捷键提示改为"截图->粘贴:Alt+Shift+A-Ctrl+V ---> Ctrl+V"
- 移动端隐藏截图提示(CSS 媒体查询)
- AI转人工提示改为"已为您呼叫人工坐席,请稍等!"
- 坐席接入提示改为"坐席正在查看您的信息,请等待处理回复!"
- 删除"摇铃呼叫坐席"入口和文案
- 删除孤儿组件 MessageList.vue + shake 动画 CSS
## H5 员工端 v5 (2026-07-13 02:08 已部署)
- RightPanel v2.1:删除"软件安装"和"资源权限"标签页
- 移除标签栏,智能推荐(DynamicRecommend)直接展示
- 删除 SoftwareDownloads/ApprovalLinks 引用和相关 CSS
## AI 对话链路全栈改造 Phase 1-6 (已部署)
- Phase 1: Dify JSON输出 + 后端blocking解析 + 双WS推送 + 错误降级
- Phase 2: 关键词收窄(~25强意图词) + 两级分类Prompt + 删除前端checkApprovalIntent
- Phase 3: WS扩展(ai_thinking+dynamic_recommend) + ai_structured气泡 + RightPanel v2 + 选项回传
- Phase 4: VisionService接入 + 图片消息融合(5秒窗口) + 降级策略
- Phase 5: 坐席端ai_thinking指示器 + ai_structured/byod_card渲染 + handleNewMessage修复
- Phase 6: diagnosis_stage(6值) + response_time_ms计时 + 慢响应告警(>10s)
## 坐席端 v5 (2026-07-13 01:38 已部署)
- ai_structured/byod_card 只读渲染
- AI思考指示器 UI
- handleNewMessage 透传 msg_type/extra_data 修复
- 布局优化v2.0: QuickReplyBar L1+L2悬浮 + ReplyBox左右分区 + 右栏260/560px切换
- 键盘快捷键v2.3: 纯数字路由 + ESC分层撤销 + Shift+Space用event.code
## 上下文感知智能诊断闭环 (2026-07-12 已部署)
- 三层诊断(API→Script→AI) + 三段排队(VIP→info_locked→not locked)
- 答题插队 + 五场景关闭
- 迁移052(6表+6列) + queue_service + quiz_service + closing_service
- H5前端: QueueWaiting + RightPanel双Tab + InputBar三态 + ResolveConfirmCard
- 坐席前端: pending_close结单流程 + 信息锁定(Dify步骤完成+有效回答率≥70%)
## 知识库迭代3 (2026-07-12 已部署)
- 分诊交互(H5+坐席+Dify独立应用)
- 拓扑预览(ECharts只读)
- 代答排除(4种匹配器: keyword/regex/intent/category)
- 迁移051 + 44文件43测试通过
## 后端变更
- 6个Python文件改造(h5_ai_task.py/h5.py/ai_service.py/closing_service.py等)
- funny_phrase_service.py: shake/connected/keyword 默认文案更新
- session_service.py: 企微消息文案同步
- 新增: queue.py/quiz.py/triage.py/exclusion_rules.py 等API端点
- 新增: diagnostic.py/quiz.py/triage_session.py 等模型
- 新增: closing_service/queue_service/quiz_service/triage_service 等服务
## 文档更新
- CHANGELOG.md: 新增 [未发布] 区全部变更记录
- 项目管理主文档 v2.5: 新增v0.7.3版本 + 已完成看板 + 最近搞定
- 版本记录: 新增v0.7.3条目
- AI对话链路实施计划: Phase 1-6 全部标记✅已实施
- 新增架构图/时序图/类图(mermaid)
## 部署路径修正
- 服务器项目根路径: /opt/wecom-it-desk/
- 所有前端dist均为ro bind mount,只能在宿主机源路径操作
- 服务器nginx /h5/ 是静态文件服务(非proxy_pass)
- elFinder上传二进制不可靠(MD5不匹配),改用base64分块上传
221 lines
7.3 KiB
Python
221 lines
7.3 KiB
Python
# =============================================================================
|
||
# 企微IT智能服务台 — 会议室报修业务服务
|
||
# =============================================================================
|
||
# 说明:处理终端报修的完整流程:
|
||
# 1. 创建报修记录到 meetingroom_repair 表
|
||
# 2. 创建IT工单会话(Conversation),状态为 queued(排队等待坐席)
|
||
# 3. 创建初始消息(故障描述),sender_type=system
|
||
# 4. 通过企微消息通知IT管理员
|
||
# 5. 通过WS推送报修通知到坐席端
|
||
#
|
||
# 设计决策:
|
||
# - 报修自动创建工单会话,复用现有IT服务台流程
|
||
# - 报修人未登录时使用"匿名"身份,但仍创建工单
|
||
# - 通知管理员和坐席同步进行,不影响主流程
|
||
# =============================================================================
|
||
|
||
import logging
|
||
import uuid
|
||
from datetime import datetime
|
||
from typing import Optional
|
||
|
||
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
||
from app.config import settings
|
||
from app.models.conversation import Conversation
|
||
from app.models.message import Message
|
||
from app.models.meetingroom_repair import MeetingroomRepair
|
||
from app.services.wecom_service import WecomService
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
# 设备类型中文映射
|
||
DEVICE_TYPE_LABELS = {
|
||
"projector": "投影仪",
|
||
"video_conf": "视频会议设备",
|
||
"aircon": "空调",
|
||
"desk_chair": "桌椅",
|
||
"network": "网络",
|
||
"other": "其他设备",
|
||
}
|
||
|
||
|
||
class RepairService:
|
||
"""会议室报修业务服务。
|
||
|
||
处理终端报修的完整流程:记录 + 创建工单 + 通知。
|
||
"""
|
||
|
||
def __init__(
|
||
self,
|
||
db: AsyncSession,
|
||
wecom_service: Optional[WecomService] = None,
|
||
) -> None:
|
||
"""初始化报修服务。
|
||
|
||
Args:
|
||
db: 数据库会话
|
||
wecom_service: 企微服务实例(用于发送通知消息)
|
||
"""
|
||
self.db = db
|
||
self.wecom = wecom_service
|
||
|
||
async def submit_repair(
|
||
self,
|
||
terminal_sn: str,
|
||
meetingroom_id: int,
|
||
meetingroom_name: str,
|
||
device_type: str,
|
||
fault_description: str,
|
||
reporter_name: Optional[str] = None,
|
||
reporter_userid: Optional[str] = None,
|
||
) -> dict:
|
||
"""提交报修,创建工单会话并通知。
|
||
|
||
Args:
|
||
terminal_sn: 终端序列号
|
||
meetingroom_id: 企微会议室ID
|
||
meetingroom_name: 会议室名称
|
||
device_type: 故障设备类型
|
||
fault_description: 故障描述
|
||
reporter_name: 报修人姓名(为空则"匿名")
|
||
reporter_userid: 报修人企微userid(为空则空字符串)
|
||
|
||
Returns:
|
||
dict: {"repair_id": int, "conversation_id": str}
|
||
"""
|
||
# 报修人信息处理
|
||
name = reporter_name or "匿名(终端报修)"
|
||
userid = reporter_userid or ""
|
||
|
||
# 设备类型中文名
|
||
device_label = DEVICE_TYPE_LABELS.get(device_type, device_type)
|
||
|
||
# 构造工单主题
|
||
subject = f"会议室报修:{meetingroom_name} - {device_label}"
|
||
|
||
# 1. 创建IT工单会话
|
||
conversation_id = str(uuid.uuid4())
|
||
conversation = Conversation(
|
||
id=conversation_id,
|
||
corp_id=settings.wecom_corp_id,
|
||
employee_id=userid or f"terminal:{terminal_sn}",
|
||
employee_name=name,
|
||
department="",
|
||
position="",
|
||
level="",
|
||
status="queued",
|
||
urgency_score=3, # 报修默认中等紧急
|
||
tags={"source": "terminal_repair", "terminal_sn": terminal_sn, "meetingroom_id": meetingroom_id},
|
||
last_message_at=datetime.now(),
|
||
last_message_summary=fault_description[:256],
|
||
)
|
||
self.db.add(conversation)
|
||
|
||
# 2. 创建初始系统消息(故障描述)
|
||
message = Message(
|
||
conversation_id=conversation_id,
|
||
sender_type="system",
|
||
sender_id="system",
|
||
sender_name="系统",
|
||
content=f"【终端报修】\n会议室: {meetingroom_name}\n设备类型: {device_label}\n故障描述: {fault_description}\n报修人: {name}\n终端SN: {terminal_sn}",
|
||
msg_type="text",
|
||
status="sent",
|
||
)
|
||
self.db.add(message)
|
||
|
||
# 3. 创建报修记录
|
||
repair = MeetingroomRepair(
|
||
terminal_sn=terminal_sn,
|
||
meetingroom_id=meetingroom_id,
|
||
meetingroom_name=meetingroom_name,
|
||
device_type=device_type,
|
||
fault_description=fault_description,
|
||
reporter_name=name,
|
||
reporter_userid=userid,
|
||
conversation_id=conversation_id,
|
||
status=0,
|
||
)
|
||
self.db.add(repair)
|
||
|
||
# 提交事务
|
||
await self.db.commit()
|
||
await self.db.refresh(repair)
|
||
|
||
# 4. 异步通知IT管理员(不阻塞主流程)
|
||
try:
|
||
await self._notify_admins(subject, fault_description, meetingroom_name, name)
|
||
except Exception as e:
|
||
logger.warning(f"报修通知管理员失败(不影响主流程): {e}")
|
||
|
||
# 5. 通过WS推送报修通知到坐席端
|
||
try:
|
||
await self._notify_agents(subject, conversation_id, meetingroom_name)
|
||
except Exception as e:
|
||
logger.warning(f"报修WS通知坐席失败(不影响主流程): {e}")
|
||
|
||
logger.info(
|
||
f"报修创建成功: repair_id={repair.id}, conversation_id={conversation_id}, "
|
||
f"room={meetingroom_name}, device={device_type}"
|
||
)
|
||
|
||
return {
|
||
"repair_id": repair.id,
|
||
"conversation_id": conversation_id,
|
||
}
|
||
|
||
async def _notify_admins(
|
||
self,
|
||
subject: str,
|
||
description: str,
|
||
room_name: str,
|
||
reporter: str,
|
||
) -> None:
|
||
"""通过企微消息通知IT管理员。"""
|
||
if not self.wecom:
|
||
return
|
||
|
||
# 通知内容
|
||
content = (
|
||
f"【会议室报修通知】\n"
|
||
f"会议室: {room_name}\n"
|
||
f"报修人: {reporter}\n"
|
||
f"问题: {description}\n"
|
||
f"时间: {datetime.now().strftime('%Y-%m-%d %H:%M')}\n"
|
||
f"请及时处理。"
|
||
)
|
||
|
||
# 从配置获取管理员userid列表
|
||
admin_userids = []
|
||
if settings.wecom_agent_userids:
|
||
admin_userids = [uid.strip() for uid in settings.wecom_agent_userids.split(",") if uid.strip()]
|
||
|
||
if admin_userids:
|
||
for uid in admin_userids:
|
||
try:
|
||
await self.wecom.send_text_message(uid, content)
|
||
except Exception as e:
|
||
logger.warning(f"发送报修通知给 {uid} 失败: {e}")
|
||
|
||
async def _notify_agents(
|
||
self,
|
||
subject: str,
|
||
conversation_id: str,
|
||
room_name: str,
|
||
) -> None:
|
||
"""通过WS推送报修通知到坐席端。"""
|
||
from app.services.ws_manager import manager
|
||
|
||
# 构造推送消息
|
||
message_data = {
|
||
"type": "new_conversation",
|
||
"conversation_id": conversation_id,
|
||
"source": "terminal_repair",
|
||
"subject": subject,
|
||
"room_name": room_name,
|
||
"timestamp": datetime.now().isoformat(),
|
||
}
|
||
|
||
# 广播到所有在线坐席
|
||
await manager.broadcast(message_data)
|