修复路由多id的格式问题
This commit is contained in:
@@ -363,27 +363,35 @@ async def insert_scada_data(
|
||||
|
||||
@router.get("/scada/by-ids-time-range")
|
||||
async def get_scada_by_ids_time_range(
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
device_ids: str,
|
||||
conn: AsyncConnection = Depends(get_database_connection),
|
||||
):
|
||||
device_ids_list = (
|
||||
[id.strip() for id in device_ids.split(",") if id.strip()] if device_ids else []
|
||||
)
|
||||
return await ScadaRepository.get_scada_by_ids_time_range(
|
||||
conn, device_ids, start_time, end_time
|
||||
conn, device_ids_list, start_time, end_time
|
||||
)
|
||||
|
||||
|
||||
@router.get("/scada/by-ids-field-time-range")
|
||||
async def get_scada_field_by_ids_time_range(
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
field: str,
|
||||
device_ids: str,
|
||||
conn: AsyncConnection = Depends(get_database_connection),
|
||||
):
|
||||
try:
|
||||
device_ids_list = (
|
||||
[id.strip() for id in device_ids.split(",") if id.strip()]
|
||||
if device_ids
|
||||
else []
|
||||
)
|
||||
return await ScadaRepository.get_scada_field_by_id_time_range(
|
||||
conn, device_ids, start_time, end_time, field
|
||||
conn, device_ids_list, start_time, end_time, field
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
@@ -422,9 +430,9 @@ async def delete_scada_data(
|
||||
|
||||
@router.get("/composite/scada-simulation")
|
||||
async def get_scada_associated_simulation_data(
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
device_ids: str,
|
||||
scheme_type: str = Query(None, description="指定方案名称,若为空则查询实时数据"),
|
||||
scheme_name: str = Query(None, description="指定方案名称,若为空则查询实时数据"),
|
||||
timescale_conn: AsyncConnection = Depends(get_database_connection),
|
||||
@@ -437,11 +445,18 @@ async def get_scada_associated_simulation_data(
|
||||
并根据对应的 type,查询对应的模拟数据
|
||||
"""
|
||||
try:
|
||||
# 手动解析 device_ids 为 List[str],去除空格
|
||||
device_ids_list = (
|
||||
[id.strip() for id in device_ids.split(",") if id.strip()]
|
||||
if device_ids
|
||||
else []
|
||||
)
|
||||
|
||||
if scheme_type and scheme_name:
|
||||
result = await CompositeQueries.get_scada_associated_scheme_simulation_data(
|
||||
timescale_conn,
|
||||
postgres_conn,
|
||||
device_ids,
|
||||
device_ids_list, # 使用解析后的列表
|
||||
start_time,
|
||||
end_time,
|
||||
scheme_type,
|
||||
@@ -452,7 +467,7 @@ async def get_scada_associated_simulation_data(
|
||||
await CompositeQueries.get_scada_associated_realtime_simulation_data(
|
||||
timescale_conn,
|
||||
postgres_conn,
|
||||
device_ids,
|
||||
device_ids_list, # 使用解析后的列表
|
||||
start_time,
|
||||
end_time,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user