更新方法以支持多id查询

This commit is contained in:
JIANG
2025-12-10 15:28:38 +08:00
parent 8a9345dfcc
commit 6582bf8879
2 changed files with 103 additions and 78 deletions

View File

@@ -361,7 +361,7 @@ async def insert_scada_data(
return {"message": f"Inserted {len(data)} records"}
@router.get("/scada")
@router.get("/scada/by-ids-time-range")
async def get_scada_by_ids_time_range(
device_ids: List[str],
start_time: datetime,
@@ -373,7 +373,7 @@ async def get_scada_by_ids_time_range(
)
@router.get("/scada/field")
@router.get("/scada/by-ids-field-time-range")
async def get_scada_field_by_ids_time_range(
device_ids: List[str],
start_time: datetime,
@@ -404,7 +404,7 @@ async def update_scada_field(
raise HTTPException(status_code=400, detail=str(e))
@router.delete("/scada")
@router.delete("/scada/by-id-time-range")
async def delete_scada_data(
device_id: str,
start_time: datetime,
@@ -422,23 +422,41 @@ async def delete_scada_data(
@router.get("/composite/scada-simulation")
async def get_scada_associated_simulation_data(
device_id: str,
device_ids: List[str],
start_time: datetime,
end_time: datetime,
field: str,
scheme_type: str = Query(None, description="指定方案名称,若为空则查询实时数据"),
scheme_name: str = Query(None, description="指定方案名称,若为空则查询实时数据"),
timescale_conn: AsyncConnection = Depends(get_database_connection),
postgres_conn: AsyncConnection = Depends(get_postgres_connection),
):
"""
获取 SCADA 关联的 link/node 模拟值
根据传入的 SCADA device_id找到关联的 link/node
根据传入的 SCADA device_ids,找到关联的 link/node
并根据对应的 type查询对应的模拟数据
"""
try:
result = await CompositeQueries.get_scada_associated_simulation_data(
timescale_conn, postgres_conn, device_id, start_time, end_time, field
)
if scheme_type and scheme_name:
result = await CompositeQueries.get_scada_associated_scheme_simulation_data(
timescale_conn,
postgres_conn,
device_ids,
start_time,
end_time,
scheme_type,
scheme_name,
)
else:
result = (
await CompositeQueries.get_scada_associated_realtime_simulation_data(
timescale_conn,
postgres_conn,
device_ids,
start_time,
end_time,
)
)
if result is None:
raise HTTPException(status_code=404, detail="No simulation data found")
return result