添加--添加获取未处理告警消息数量接口
This commit is contained in:
parent
15e088ffad
commit
4f4a484b6d
@ -6,7 +6,7 @@ from app.crud.event import event
|
|||||||
from app.schemas.event import EventList, EventDetail, EventUpdate, EventQuery, BackStageEvent, BackStageEventDto, BackStageEventDetail, EditTemperatureDto, OcrAlertMessage, OcrAlertMessageDto
|
from app.schemas.event import EventList, EventDetail, EventUpdate, EventQuery, BackStageEvent, BackStageEventDto, BackStageEventDetail, EditTemperatureDto, OcrAlertMessage, OcrAlertMessageDto
|
||||||
from app.util.httpResponse import BaseResponse
|
from app.util.httpResponse import BaseResponse
|
||||||
|
|
||||||
import datetime
|
# import datetime
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -175,6 +175,14 @@ async def get_alert_detail(
|
|||||||
alert_message = await event.get_alert_detail(db, messageId=messageId)
|
alert_message = await event.get_alert_detail(db, messageId=messageId)
|
||||||
|
|
||||||
return BaseResponse(code=200, msg="success", data=alert_message)
|
return BaseResponse(code=200, msg="success", data=alert_message)
|
||||||
|
|
||||||
|
# 获取未处理告警消息数量
|
||||||
|
@router.get("/events/alertCount", response_model=BaseResponse)
|
||||||
|
async def get_alert_count(
|
||||||
|
db: AsyncSession = Depends(get_db)
|
||||||
|
):
|
||||||
|
alert_count = await event.get_alert_count(db)
|
||||||
|
return BaseResponse(code=200, msg="success", data=alert_count)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from typing import List, Optional, Dict, Any
|
from typing import List, Optional, Dict, Any
|
||||||
from sqlalchemy import select, and_, or_, update, bindparam
|
from sqlalchemy import select, and_, or_, update, bindparam, func
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from sqlalchemy.orm import selectinload
|
from sqlalchemy.orm import selectinload
|
||||||
from app.crud.base import CRUDBase
|
from app.crud.base import CRUDBase
|
||||||
@ -324,6 +324,22 @@ class CRUDEvent(CRUDBase[Event, EventUpdate, EventUpdate]):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"获取告警详情失败: {e}")
|
print(f"获取告警详情失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
async def get_alert_count(
|
||||||
|
self,
|
||||||
|
db: AsyncSession
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
query_stmt = (
|
||||||
|
select(func.count(Message.messageId))
|
||||||
|
.where(Message.handle == "0")
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await db.execute(query_stmt)
|
||||||
|
return result.scalar()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user