修改 /event/getRobotList接口, 添加返回参数 tag, tag=0 无告警, tag=1 有一级告警(高温感知报警), tag=2 有二级告警(其余告警).

This commit is contained in:
haotian 2025-06-13 14:32:05 +08:00
parent e3905a521d
commit 320baf7105
2 changed files with 35 additions and 3 deletions

View File

@ -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)

View File

@ -43,3 +43,4 @@
# 20250613
- 修改 /events/getMonitor 接口返回参数
- 修改 /event/getRobotList接口, 添加返回参数 tag, tag=0 无告警, tag=1 有一级告警(高温感知报警), tag=2 有二级告警(其余告警).