From 5a64e2fe1109c8d610b9dae1326993f2baf84396 Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Wed, 25 Mar 2026 15:19:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86/=E8=AF=AF=E6=8A=A5=E5=90=8E=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=9B=B4=E6=96=B0=E4=BC=81=E5=BE=AE=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E5=88=B0=E7=BB=88=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handle_alarm 执行后,若为终态操作(CLOSED/FALSE), 异步调用 update_alarm_card_terminal 同步企微卡片按钮状态, 避免前端已处理但企微卡片按钮仍可点击的不一致问题。 --- app/routers/yudao_aiot_alarm.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/routers/yudao_aiot_alarm.py b/app/routers/yudao_aiot_alarm.py index 9483551..5371419 100644 --- a/app/routers/yudao_aiot_alarm.py +++ b/app/routers/yudao_aiot_alarm.py @@ -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"),