Files
wecom_it_smart_desk/backend/tmp_create_test_conversation.py
Simon bea288e414 feat: 2026-07-11 全量更新 - 代办集成+会议室预定+知识迭代修复+UI统一+Bug修复
== 已部署上线 (9项) ==
- 代办事项真实数据源集成 (企微审批API 8bug修复链)
- H5/坐席端 Logo样式统一+绿色背景
- 视频引导页修复 (localStorage key v2)
- 坐席端 v9 Vue版本修复 (ElMessage._context)
- 截图按钮 v10 修复 (getDisplayMedia user gesture)
- 扫码样式恢复+H5扫码登录跳转修复
- H5截图快捷键提示

== 代码完成待部署 (3项) ==
- 知识迭代3Bug修复 (#8 POST端点/#7 MERGE幂等/#6 过期检查)
- 会议室预定-小鱼易联终端 (40文件, 40/40测试通过)
- IT资产升级审批推送 (asset_service.py)

== 需求文档 (2项) ==
- 坐席端AI辅助消息框-PRD (4项新功能确认)
- 坐席端布局优化建议 v2.0 (7天计划)

== 新增文档 ==
- 日报-2026-07-11.md
- 知识迭代Bug修复报告-20260711.md
- 会议室预定-部署指南.md
- CHANGELOG.md 更新

== 测试 ==
- test_todo_integration.py: 40/40
- test_meetingroom.py: 40/40
- test_bugfix_ki_suggestions.py: 21/21
2026-07-11 23:13:10 +08:00

130 lines
4.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# 临时脚本:创建测试会话,包含主责坐席、协作坐席和被邀请员工,用于测试参与者双模式 UI
import sys
import asyncio
from datetime import datetime
from uuid import uuid4
sys.path.insert(0, r'D:\资料\03-项目开发\wecom_it_smart_desk\backend')
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from sqlalchemy import select
from app.database import Base
from app.models.agent import Agent
from app.models.conversation import Conversation
from app.models.employee import Employee
DB_URL = 'sqlite+aiosqlite:///D:/资料/03-项目开发/wecom_it_smart_desk/backend/it_smart_desk.db'
async def get_or_create_agent(session, user_id, name, department='信息技术部'):
stmt = select(Agent).where(Agent.user_id == user_id)
result = await session.execute(stmt)
agent = result.scalars().first()
if agent:
return agent
agent = Agent(
id=str(uuid4()),
user_id=user_id,
name=name,
status='online',
current_load=0,
max_load=5,
created_at=datetime.now(),
updated_at=datetime.now(),
role='agent',
skill_tags=[],
)
session.add(agent)
return agent
async def get_or_create_employee(session, employee_id, name, department='财务部'):
stmt = select(Employee).where(Employee.employee_id == employee_id)
result = await session.execute(stmt)
emp = result.scalars().first()
if emp:
return emp
emp = Employee(
id=str(uuid4()),
corp_id='wecom_corp_test',
employee_id=employee_id,
name=name,
department=department,
position='',
avatar='',
avatar_updated_at=datetime.utcnow(),
)
session.add(emp)
return emp
async def main():
engine = create_async_engine(DB_URL, echo=False, future=True)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async with async_session() as session:
# 确保测试员工和坐席存在
await get_or_create_employee(session, 'dev-user-001', '张三', '财务部')
await get_or_create_employee(session, 'dev-user-002', '王五', '人事部')
primary_agent = await get_or_create_agent(session, 'dev-agent-001', '李四', '信息技术部')
collab_agent = await get_or_create_agent(session, 'dev-agent-002', '陈静', '信息技术部')
# 修复现有所有会话的 tags 格式(应为 dict 而非 list
stmt_all = select(Conversation)
result_all = await session.execute(stmt_all)
all_convs = result_all.scalars().all()
for c in all_convs:
if not isinstance(c.tags, dict):
c.tags = {}
print(f'修复会话 {c.id} 的 tags 格式为 dict')
# 创建或更新测试会话(给 conv-002 添加参与者,当前会话就是它)
stmt = select(Conversation).where(Conversation.id == 'conv-002')
result = await session.execute(stmt)
conv = result.scalars().first()
if conv:
print(f'给 conv-002 添加参与者信息')
conv.assigned_agent_id = primary_agent.user_id
conv.collaborating_agent_ids = [collab_agent.user_id]
conv.participants = [
{'id': 'dev-user-002', 'name': '王五', 'department': '人事部', 'type': 'employee', 'joined': True},
]
conv.status = 'serving'
conv.tags = {}
conv.updated_at = datetime.now()
else:
conv = Conversation(
id=str(uuid4()),
corp_id='wecom_corp_test',
employee_id='dev-user-001',
employee_name='张三',
department='财务部',
position='',
level='',
status='serving',
is_vip=False,
is_pinned=False,
is_todo=False,
urgency_score=3,
tags={},
assigned_agent_id=primary_agent.user_id,
collaborating_agent_ids=[collab_agent.user_id],
participants=[
{'id': 'dev-user-002', 'name': '王五', 'department': '人事部', 'type': 'employee', 'joined': True},
],
ai_substantive_reply_count=0,
impact_scope=0,
is_blocking=False,
emotion_state='normal',
created_at=datetime.now(),
updated_at=datetime.now(),
last_message_at=datetime.now(),
)
session.add(conv)
print(f'测试会话创建成功: id={conv.id}')
await session.commit()
if __name__ == '__main__':
asyncio.run(main())