362 lines
12 KiB
Python
362 lines
12 KiB
Python
from fastapi import APIRouter, Request, Query, Path, Body
|
|
from typing import Any, List, Dict, Union
|
|
from app.services.tjnetwork import (
|
|
Any,
|
|
ChangeSet,
|
|
add_junction,
|
|
delete_junction,
|
|
get_all_junctions,
|
|
get_junction,
|
|
get_junction_schema,
|
|
set_junction,
|
|
)
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/getjunctionschema", summary="获取节点架构", description="获取指定项目的节点属性架构和数据类型定义。")
|
|
async def fast_get_junction_schema(
|
|
network: str = Query(..., description="管网名称(或数据库名称)")
|
|
) -> dict[str, dict[str, Any]]:
|
|
"""
|
|
获取节点架构信息。
|
|
|
|
返回指定项目的节点属性架构,包括所有属性的类型和约束信息。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
"""
|
|
return get_junction_schema(network)
|
|
|
|
@router.post("/addjunction/", response_model=None, summary="添加节点", description="在供水网络中添加新的节点,指定节点ID和空间坐标。")
|
|
async def fastapi_add_junction(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
x: float = Query(..., description="X 坐标"),
|
|
y: float = Query(..., description="Y 坐标"),
|
|
z: float = Query(..., description="标高(海拔高度)")
|
|
) -> ChangeSet:
|
|
"""
|
|
添加新节点到供水网络。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
x: X 坐标值
|
|
y: Y 坐标值
|
|
z: 标高(海拔高度)
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "x": x, "y": y, "elevation": z}
|
|
return add_junction(network, ChangeSet(ps))
|
|
|
|
@router.post("/deletejunction/", response_model=None, summary="删除节点", description="从供水网络中删除指定的节点。")
|
|
async def fastapi_delete_junction(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> ChangeSet:
|
|
"""
|
|
删除指定的节点。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction}
|
|
return delete_junction(network, ChangeSet(ps))
|
|
|
|
@router.get("/getjunctionelevation/", summary="获取节点标高", description="获取指定节点的标高(海拔高度)。")
|
|
async def fastapi_get_junction_elevation(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> float:
|
|
"""
|
|
获取节点的标高值。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
float: 节点标高值
|
|
"""
|
|
ps = get_junction(network, junction)
|
|
return ps["elevation"]
|
|
|
|
@router.get("/getjunctionx/", summary="获取节点 X 坐标", description="获取指定节点的 X 坐标值。")
|
|
async def fastapi_get_junction_x(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> float:
|
|
"""
|
|
获取节点的 X 坐标。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
float: 节点 X 坐标值
|
|
"""
|
|
ps = get_junction(network, junction)
|
|
return ps["x"]
|
|
|
|
@router.get("/getjunctiony/", summary="获取节点 Y 坐标", description="获取指定节点的 Y 坐标值。")
|
|
async def fastapi_get_junction_y(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> float:
|
|
"""
|
|
获取节点的 Y 坐标。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
float: 节点 Y 坐标值
|
|
"""
|
|
ps = get_junction(network, junction)
|
|
return ps["y"]
|
|
|
|
@router.get("/getjunctioncoord/", summary="获取节点坐标", description="获取指定节点的 X 和 Y 坐标。")
|
|
async def fastapi_get_junction_coord(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> dict[str, float]:
|
|
"""
|
|
获取节点的坐标信息。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
dict: 包含 x 和 y 坐标的字典
|
|
"""
|
|
ps = get_junction(network, junction)
|
|
coord = {"x": ps["x"], "y": ps["y"]}
|
|
return coord
|
|
|
|
@router.get("/getjunctiondemand/", summary="获取节点需水量", description="获取指定节点的需水量。")
|
|
async def fastapi_get_junction_demand(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> float:
|
|
"""
|
|
获取节点的需水量。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
float: 节点的需水量值
|
|
"""
|
|
ps = get_junction(network, junction)
|
|
return ps["demand"]
|
|
|
|
@router.get("/getjunctionpattern/", summary="获取节点需水模式", description="获取指定节点的需水模式标识。")
|
|
async def fastapi_get_junction_pattern(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> str:
|
|
"""
|
|
获取节点的需水模式。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
str: 节点的需水模式标识
|
|
"""
|
|
ps = get_junction(network, junction)
|
|
return ps["pattern"]
|
|
|
|
@router.post("/setjunctionelevation/", response_model=None, summary="设置节点标高", description="设置指定节点的标高值。")
|
|
async def fastapi_set_junction_elevation(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
elevation: float = Query(..., description="标高(海拔高度)")
|
|
) -> ChangeSet:
|
|
"""
|
|
设置节点的标高。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
elevation: 标高值
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "elevation": elevation}
|
|
return set_junction(network, ChangeSet(ps))
|
|
|
|
@router.post("/setjunctionx/", response_model=None, summary="设置节点 X 坐标", description="设置指定节点的 X 坐标值。")
|
|
async def fastapi_set_junction_x(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
x: float = Query(..., description="X 坐标值")
|
|
) -> ChangeSet:
|
|
"""
|
|
设置节点的 X 坐标。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
x: X 坐标值
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "x": x}
|
|
return set_junction(network, ChangeSet(ps))
|
|
|
|
@router.post("/setjunctiony/", response_model=None, summary="设置节点 Y 坐标", description="设置指定节点的 Y 坐标值。")
|
|
async def fastapi_set_junction_y(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
y: float = Query(..., description="Y 坐标值")
|
|
) -> ChangeSet:
|
|
"""
|
|
设置节点的 Y 坐标。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
y: Y 坐标值
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "y": y}
|
|
return set_junction(network, ChangeSet(ps))
|
|
|
|
@router.post("/setjunctioncoord/", response_model=None, summary="设置节点坐标", description="设置指定节点的 X 和 Y 坐标。")
|
|
async def fastapi_set_junction_coord(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
x: float = Query(..., description="X 坐标值"),
|
|
y: float = Query(..., description="Y 坐标值")
|
|
) -> ChangeSet:
|
|
"""
|
|
设置节点的坐标。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
x: X 坐标值
|
|
y: Y 坐标值
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "x": x, "y": y}
|
|
return set_junction(network, ChangeSet(ps))
|
|
|
|
@router.post("/setjunctiondemand/", response_model=None, summary="设置节点需水量", description="设置指定节点的需水量。")
|
|
async def fastapi_set_junction_demand(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
demand: float = Query(..., description="需水量值")
|
|
) -> ChangeSet:
|
|
"""
|
|
设置节点的需水量。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
demand: 需水量值
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "demand": demand}
|
|
return set_junction(network, ChangeSet(ps))
|
|
|
|
@router.post("/setjunctionpattern/", response_model=None, summary="设置节点需水模式", description="设置指定节点的需水模式标识。")
|
|
async def fastapi_set_junction_pattern(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
pattern: str = Query(..., description="需水模式标识")
|
|
) -> ChangeSet:
|
|
"""
|
|
设置节点的需水模式。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
pattern: 需水模式标识
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
ps = {"id": junction, "pattern": pattern}
|
|
return set_junction(network, ChangeSet(ps))
|
|
|
|
@router.get("/getjunctionproperties/", summary="获取节点属性", description="获取指定节点的所有属性信息。")
|
|
async def fastapi_get_junction_properties(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID")
|
|
) -> dict[str, Any]:
|
|
"""
|
|
获取节点的完整属性信息。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
|
|
Returns:
|
|
dict: 包含节点所有属性的字典
|
|
"""
|
|
return get_junction(network, junction)
|
|
|
|
@router.get("/getalljunctionproperties/", summary="获取所有节点属性", description="获取指定项目中所有节点的属性信息。")
|
|
async def fastapi_get_all_junction_properties(
|
|
network: str = Query(..., description="管网名称(或数据库名称)")
|
|
) -> list[dict[str, Any]]:
|
|
"""
|
|
获取所有节点的属性信息列表。
|
|
|
|
此端点返回指定项目中所有节点的详细属性。缓存查询结果以提高性能。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
|
|
Returns:
|
|
list: 包含所有节点属性的列表
|
|
"""
|
|
# 缓存查询结果提高性能
|
|
# global redis_client # Redis logic removed for clean split, can be re-added if needed or imported
|
|
results = get_all_junctions(network)
|
|
return results
|
|
|
|
@router.post("/setjunctionproperties/", response_model=None, summary="批量设置节点属性", description="批量设置指定节点的多个属性。")
|
|
async def fastapi_set_junction_properties(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
junction: str = Query(..., description="节点 ID"),
|
|
req: Request = None
|
|
) -> ChangeSet:
|
|
"""
|
|
批量设置节点属性。
|
|
|
|
允许一次性设置节点的多个属性,如坐标、标高、需水量等。
|
|
|
|
Args:
|
|
network: 管网名称(或数据库名称)
|
|
junction: 节点 ID
|
|
req: 包含属性和值的 JSON 请求体
|
|
|
|
Returns:
|
|
ChangeSet: 包含变更信息的结果
|
|
"""
|
|
props = await req.json()
|
|
ps = {"id": junction} | props
|
|
return set_junction(network, ChangeSet(ps))
|