功能:前端处理/误报后同步更新企微卡片到终态

handle_alarm 执行后,若为终态操作(CLOSED/FALSE),
异步调用 update_alarm_card_terminal 同步企微卡片按钮状态,
避免前端已处理但企微卡片按钮仍可点击的不一致问题。
This commit is contained in:
2026-03-25 15:19:43 +08:00
parent adf8d63da6
commit 5a64e2fe11

View File

@@ -246,9 +246,37 @@ async def handle_alert(
if not alarm:
raise HTTPException(status_code=404, detail="告警不存在")
# 终态操作CLOSED/FALSE同步更新企微卡片
if alarmStatus in ("CLOSED", "FALSE"):
action = "complete" if alarmStatus == "CLOSED" else "false"
asyncio.create_task(_sync_wechat_card_terminal(alarm_id, action, handler))
return YudaoResponse.success(True)
async def _sync_wechat_card_terminal(alarm_id: str, action: str, operator: str):
"""前端处理/误报后,异步同步企微卡片到终态"""
try:
from app.services.wechat_service import get_wechat_service
wechat = get_wechat_service()
if not wechat.enabled:
return
response_code = wechat.get_response_code(alarm_id)
if not response_code:
logger.debug(f"告警 {alarm_id} 无企微卡片 response_code跳过卡片更新")
return
await wechat.update_alarm_card_terminal(
response_code=response_code,
user_ids=[],
alarm_id=alarm_id,
action=action,
operator_name=operator,
)
logger.info(f"前端操作同步企微卡片: alarm={alarm_id}, action={action}")
except Exception as e:
logger.error(f"同步企微卡片失败: alarm={alarm_id}, error={e}", exc_info=True)
@router.delete("/alert/delete")
async def delete_alert(
alarmId: Optional[str] = Query(None, description="告警ID"),