Commit 09ba42e2 by imwangxiaozhou

feat(二维码渠道, 员工群组助手): 添加二维码渠道状态支持并修复员工挂载列表逻辑

为二维码创建请求添加状态字段,支持启用/禁用状态并设置默认值为enable
在二维码创建服务中保存请求携带的状态参数
优化员工挂载列表逻辑:加载员工二维码映射数据,过滤无有效二维码的机器人,修正员工ID和微信用户ID的取值
1 parent 5ebd584d
......@@ -9,6 +9,7 @@ class QrcodeCreateRequest(BaseModel):
position_code: str = Field(..., max_length=100)
employee_id: str = Field(..., max_length=128, description="承接员工ID,对应企微员工标识(映射到 wecom_bots.bot_id)")
wechat_user_id: str = Field(..., max_length=128, description="承接员工微信ID,与 employee_id 指向同一个员工")
status: str = Field("enable", pattern=r"^(enable|disable)$")
remark: Optional[str] = Field(None, max_length=200)
welcome_message: Optional[str] = Field(None, max_length=500)
......
......@@ -194,6 +194,12 @@ class AgentGroupHelperService:
def list_employee_mounts(self) -> EmployeeMountsResponse:
bots = self.db.query(WeComBot).order_by(WeComBot.id.asc()).all()
employee_qrcode_rows = self.db.query(WeComEmployeeQrcode).all()
employee_qrcode_map = {
row.employee_id: row
for row in employee_qrcode_rows
if row.employee_id and str(row.qrcode_url or "").strip()
}
active_agents = self.db.query(Agent).filter(Agent.is_deleted == False).all()
agent_map: dict[int, list[Agent]] = {}
for agent in active_agents:
......@@ -213,13 +219,16 @@ class AgentGroupHelperService:
summaries: list[EmployeeMountSummary] = []
for bot in bots:
employee_id = str(bot.bot_id or "")
if not employee_id or employee_id not in employee_qrcode_map:
continue
mounted_agents = agent_map.get(bot.id, [])
mounted_qrcodes = qrcode_map.get(bot.id, [])
summaries.append(
EmployeeMountSummary(
employee_id=str(bot.bot_id or ""),
employee_id=employee_id,
employee_name=bot.bot_name or "",
wechat_user_id=str(bot.bot_id or ""),
wechat_user_id=employee_id,
agent_count=len(mounted_agents),
qrcode_count=len(mounted_qrcodes),
agents=[
......
......@@ -108,6 +108,7 @@ class QrcodeChannelService:
employee_name=employee_name,
qrcode_url=qrcode_url,
agent_ids=agent_ids,
status=req.status,
remark=req.remark,
welcome_message=req.welcome_message,
created_by="admin",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!