From 320baf71054d8fc9a114e823954976b7708fbaa1 Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Fri, 13 Jun 2025 14:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20/event/getRobotList?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3,=20=E6=B7=BB=E5=8A=A0=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20tag,=20=20tag=3D0=20=E6=97=A0=E5=91=8A?= =?UTF-8?q?=E8=AD=A6,=20tag=3D1=20=E6=9C=89=E4=B8=80=E7=BA=A7=E5=91=8A?= =?UTF-8?q?=E8=AD=A6(=E9=AB=98=E6=B8=A9=E6=84=9F=E7=9F=A5=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6),=20tag=3D2=20=E6=9C=89=E4=BA=8C=E7=BA=A7=E5=91=8A?= =?UTF-8?q?=E8=AD=A6(=E5=85=B6=E4=BD=99=E5=91=8A=E8=AD=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/endpoints/events.py | 37 +++++++++++++++++++++++++++++++--- change_log.md | 1 + 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/api/v1/endpoints/events.py b/app/api/v1/endpoints/events.py index 9870f5f..aa970a9 100644 --- a/app/api/v1/endpoints/events.py +++ b/app/api/v1/endpoints/events.py @@ -1,4 +1,4 @@ -from operator import ge +from operator import and_, ge from typing import List, Optional from fastapi import APIRouter, Depends, HTTPException, Query, Body from paddle import normal @@ -9,7 +9,7 @@ from app.models.models import Robot, Message, RobotInfo,Group, GroupRobot, Event from app.schemas.event import EventList, EventDetail, EventUpdate, EventQuery, BackStageEvent, BackStageEventDto, BackStageEventDetail, EditTemperatureDto, OcrAlertMessage, OcrAlertMessageDto, GetRobotDto, CommonAlertMessage, GetAllMessageDto from app.util.httpResponse import BaseResponse from app.util.status import EventType, etypeNameDict -from sqlalchemy import select +from sqlalchemy import func, select from app.services.robot_sync_service import robot_sync_service # import datetime @@ -168,6 +168,36 @@ async def get_robot_list( # 格式化返回数据 robot_list = [] for robot, robot_info, group in robots: + + # 查询告警数量, 高温感知报警为一级报警, 其余为二级报警. + count_1 = 0 + query_1 = ( + select(func.count()) + .select_from(Message) + .where(and_(Message.handle=="0", Message.eventType=="1")) + ) + + count_1 = await db.execute(query_1) + count_1 = count_1.scalar_one_or_none() + + count_o = 0 + if count_1 == 0: + query_o = ( + select(func.count()) + .select_from(Message) + .where(and_(Message.handle=="0", Message.eventType!="1")) + ) + + count_o = await db.execute(query_o) + count_o = count_o.scalar_one_or_none() + + if count_1 > 0: + tag = 1 + elif count_o > 0: + tag = 2 + else: + tag = 0 + robot_dict = { "robotId": robot.robotId, "number": robot.number, @@ -186,7 +216,8 @@ async def get_robot_list( "positon": robot_info.positon if robot_info else None, "status": robot_info.status if robot_info else None, "ststusName": robot_info.ststusName if robot_info else None, - "updateTime": robot_info.updateTime if robot_info else None + "updateTime": robot_info.updateTime if robot_info else None, + "tag": tag } } robot_list.append(robot_dict) diff --git a/change_log.md b/change_log.md index 5e10a60..7b20b83 100644 --- a/change_log.md +++ b/change_log.md @@ -43,3 +43,4 @@ # 20250613 - 修改 /events/getMonitor 接口返回参数 +- 修改 /event/getRobotList接口, 添加返回参数 tag, tag=0 无告警, tag=1 有一级告警(高温感知报警), tag=2 有二级告警(其余告警).