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"),