diff --git a/app/api/v1/endpoints/events.py b/app/api/v1/endpoints/events.py index a3f9abd..67f3a69 100644 --- a/app/api/v1/endpoints/events.py +++ b/app/api/v1/endpoints/events.py @@ -1,6 +1,7 @@ from operator import ge from typing import List, Optional from fastapi import APIRouter, Depends, HTTPException, Query, Body +from paddle import normal from sqlalchemy.ext.asyncio import AsyncSession from app.core.database import get_db from app.crud.event import event @@ -319,10 +320,38 @@ async def get_alert_detail( 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) - + alert_count = await event.get_alert_count(db, handle="0") + processed_count = await event.get_alert_count(db, handle="1") + return BaseResponse(code=200, msg="success", data={ + "alert_count": alert_count, + "processed_count": processed_count + }) +# 获取厂区及机器人实时监控 +@router.get("/events/getMonitor") +async def get_monitor(): + return BaseResponse(code=200, msg="success" + ,data={ + + "A区厂区监控":{ + "视角1": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", + "视角2": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8" + }, + "B区厂区监控":{ + "视角1": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", + "视角2": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8" + }, + "追随机器人监控":{ + "视角1": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", + "视角2": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8" + }, + "室外机器人监控":{ + "视角1": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", + "视角2": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8" + } + } + ) +# 获取机器人统计信息 @router.get("/events/robotST", response_model=BaseResponse[dict]) async def get_robot_st( db: AsyncSession = Depends(get_db) @@ -359,7 +388,7 @@ async def get_message_by_event_type( skip=skip, limit=limit, condition=[Message.handle==handle, Message.eventType==EventType.SMOKE.value]) - long_staty_message = await event.get_messages(db, + long_stay_message = await event.get_messages(db, skip=skip, limit=limit, condition=[Message.handle==handle, Message.eventType==EventType.LONGSTAY.value]) @@ -384,7 +413,7 @@ async def get_message_by_event_type( return { "high_temperature_message": high_temperature_message, "smoke_message": smoke_message, - "long_staty_message": long_staty_message, + "long_stay_message": long_stay_message, "air_quality_message": air_quality_message, "stop_emergency_message": stop_emergency_message, "voice_connect_message": voice_connect_message, diff --git a/app/crud/event.py b/app/crud/event.py index 39788e1..40ec92e 100644 --- a/app/crud/event.py +++ b/app/crud/event.py @@ -313,6 +313,7 @@ class CRUDEvent(CRUDBase[Event, EventUpdate, EventUpdate]): update(Message) .where(Message.messageId == ocrAlertMessageDto.messageId) .values( + handle = "1", remark = ocrAlertMessageDto.remark, updateTime=datetime.now() ) @@ -370,12 +371,13 @@ class CRUDEvent(CRUDBase[Event, EventUpdate, EventUpdate]): async def get_alert_count( self, - db: AsyncSession + db: AsyncSession, + handle: str ): try: query_stmt = ( select(func.count(Message.messageId)) - .where(Message.handle == "0") + .where(Message.handle == handle) ) result = await db.execute(query_stmt) @@ -406,14 +408,9 @@ class CRUDEvent(CRUDBase[Event, EventUpdate, EventUpdate]): day: int ): try: - - - now = datetime.now(timezone.utc) - + now = datetime.now(timezone.utc) start_time = now - timedelta(days=day) - - print(now) - print(start_time) + query_stmt = ( select( Message.eventType,