fix(training): 出国规章企微卡片改跳通用入口聊天页
This commit is contained in:
1 parent
80d78130f8
commit
89a033f0f9
3 files changed
+72
-2
No files matched your search
@@ -90,6 +90,30 @@ def _is_overseas_regulations_training(training_type: str) -> bool:
|
||||
return "出国规章培训" in str((published or {}).get("name") or "")
|
||||
|
||||
|
||||
def _resolve_overseas_jump_agent_id() -> Optional[int]:
|
||||
"""
|
||||
解析出国规章企微卡片落地聊天页的「通用入口」Agent ID。
|
||||
|
||||
用途:企微 textcard 点击后应进入 /chat/<通用入口> 聊天页(学习之窗入口所在页),
|
||||
而 /workspace 是应用管理工作台页,不符合培训通知落地预期。
|
||||
核心逻辑:各环境 Agent ID 不同,禁止硬编码;在启用 Agent 中优先按
|
||||
handler_config.content_profile='generic_entrance' 匹配,兜底按名称精确匹配「通用入口」。
|
||||
Returns:
|
||||
通用入口 Agent ID;解析失败返回 None,调用方回退 /workspace。
|
||||
"""
|
||||
agents = db.session.execute(
|
||||
select(Agent).where(Agent.is_active.is_(True)).order_by(Agent.sort_order, Agent.id)
|
||||
).scalars().all()
|
||||
for agent in agents:
|
||||
handler_config = agent.handler_config if isinstance(agent.handler_config, dict) else {}
|
||||
if str(handler_config.get("content_profile") or "").strip() == "generic_entrance":
|
||||
return int(agent.id)
|
||||
for agent in agents:
|
||||
if str(agent.name or "").strip() == "通用入口":
|
||||
return int(agent.id)
|
||||
return None
|
||||
|
||||
|
||||
def _normalize_training_version(value: Any, training_type: str) -> str:
|
||||
"""
|
||||
规范培训版本号,未传时按培训类型补默认值。
|
||||
@@ -612,12 +636,14 @@ def upsert_user_training_record(user: User, payload: dict[str, Any]) -> Training
|
||||
db.session.commit()
|
||||
if stage == "result" and _is_overseas_regulations_training(training_type):
|
||||
try:
|
||||
# [STEP] 企微卡片落地页:优先跳「通用入口」聊天页(/chat/<id>);解析失败回退 /workspace 保持历史行为
|
||||
jump_agent_id = _resolve_overseas_jump_agent_id()
|
||||
send_wecom_event_message(
|
||||
event_type="training_overseas_thailand_guidelines",
|
||||
user=user,
|
||||
title="中国员工出差泰国的行为准则",
|
||||
content="中国员工出差泰国的行为准则",
|
||||
jump_path="/workspace",
|
||||
jump_path=f"/chat/{jump_agent_id}" if jump_agent_id else "/workspace",
|
||||
)
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
|
||||
Reference in new issue
Block a user