refactor(db)!: finalize pooled WNDB v2 migration
This commit is contained in:
@@ -8,6 +8,8 @@ from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.native.wndb.core.database import MaterializedViewRefreshAfterCommitError
|
||||
|
||||
|
||||
class ProblemDetails(BaseModel):
|
||||
"""RFC 9457 compatible error response used by the REST contract."""
|
||||
@@ -53,6 +55,24 @@ def _problem_response(
|
||||
|
||||
|
||||
def install_problem_details_handlers(app: FastAPI) -> None:
|
||||
@app.exception_handler(MaterializedViewRefreshAfterCommitError)
|
||||
async def materialized_view_refresh_error_handler(
|
||||
request: Request,
|
||||
exc: MaterializedViewRefreshAfterCommitError,
|
||||
) -> JSONResponse:
|
||||
response = _problem_response(
|
||||
request,
|
||||
status_code=503,
|
||||
title="Materialized view refresh failed",
|
||||
detail=(
|
||||
f"Project {exc.project!r} changes were committed, but GIS query "
|
||||
"views could not be refreshed. Do not repeat the write blindly."
|
||||
),
|
||||
code="materialized_view_refresh_failed_after_commit",
|
||||
)
|
||||
response.headers["X-TJWater-Changes-Committed"] = "true"
|
||||
return response
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def validation_error_handler(
|
||||
request: Request,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
get_control,
|
||||
@@ -13,7 +14,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/control", summary="获取控制架构", description="获取网络中控制对象的架构定义")
|
||||
async def fastapi_get_control_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_control_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取控制架构。
|
||||
|
||||
返回指定网络中控制对象的属性架构定义。
|
||||
@@ -21,7 +22,7 @@ async def fastapi_get_control_schema(network: str = Query(..., description="管
|
||||
return get_control_schema(network)
|
||||
|
||||
@router.get("/controls/properties", summary="获取控制属性", description="获取指定网络中的控制属性信息")
|
||||
async def fastapi_get_control_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_control_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取控制属性。
|
||||
|
||||
返回指定网络中的控制对象属性信息。
|
||||
@@ -29,19 +30,19 @@ async def fastapi_get_control_properties(network: str = Query(..., description="
|
||||
return get_control(network)
|
||||
|
||||
@router.patch("/controls/properties", response_model=None, summary="设置控制属性", description="更新指定网络中的控制属性")
|
||||
async def fastapi_set_control_properties(
|
||||
def fastapi_set_control_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置控制属性。
|
||||
|
||||
更新指定网络中的控制属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_control(network, ChangeSet(props))
|
||||
|
||||
@router.get("/rule-schemas", summary="获取规则架构", description="获取网络中规则对象的架构定义")
|
||||
async def fastapi_get_rule_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_rule_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取规则架构。
|
||||
|
||||
返回指定网络中规则对象的属性架构定义。
|
||||
@@ -49,7 +50,7 @@ async def fastapi_get_rule_schema(network: str = Query(..., description="管网
|
||||
return get_rule_schema(network)
|
||||
|
||||
@router.get("/rule-properties", summary="获取规则属性", description="获取指定网络中的规则属性信息")
|
||||
async def fastapi_get_rule_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_rule_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取规则属性。
|
||||
|
||||
返回指定网络中的规则对象属性信息。
|
||||
@@ -57,13 +58,13 @@ async def fastapi_get_rule_properties(network: str = Query(..., description="管
|
||||
return get_rule(network)
|
||||
|
||||
@router.patch("/rule-properties", response_model=None, summary="设置规则属性", description="更新指定网络中的规则属性")
|
||||
async def fastapi_set_rule_properties(
|
||||
def fastapi_set_rule_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置规则属性。
|
||||
|
||||
更新指定网络中的规则属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_rule(network, ChangeSet(props))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_curve,
|
||||
@@ -14,7 +15,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/curve", summary="获取曲线架构", description="获取网络中曲线对象的架构定义")
|
||||
async def fastapi_get_curve_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_curve_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取曲线架构。
|
||||
|
||||
返回指定网络中曲线对象的属性架构定义。
|
||||
@@ -22,23 +23,23 @@ async def fastapi_get_curve_schema(network: str = Query(..., description="管网
|
||||
return get_curve_schema(network)
|
||||
|
||||
@router.post("/curves", response_model=None, summary="添加曲线", description="在网络中添加一条新的曲线")
|
||||
async def fastapi_add_curve(
|
||||
def fastapi_add_curve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
curve: str = Query(..., description="曲线ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""添加曲线。
|
||||
|
||||
在指定网络中创建一条新的曲线,并设置其初始属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {
|
||||
"id": curve,
|
||||
} | props
|
||||
return add_curve(network, ChangeSet(ps))
|
||||
|
||||
@router.delete("/curves", response_model=None, summary="删除曲线", description="从网络中删除指定的曲线")
|
||||
async def fastapi_delete_curve(
|
||||
def fastapi_delete_curve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
curve: str = Query(..., description="曲线ID")
|
||||
) -> ChangeSet:
|
||||
@@ -50,7 +51,7 @@ async def fastapi_delete_curve(
|
||||
return delete_curve(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/curves/properties", summary="获取曲线属性", description="获取指定曲线的属性信息")
|
||||
async def fastapi_get_curve_properties(
|
||||
def fastapi_get_curve_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
curve: str = Query(..., description="曲线ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -61,21 +62,21 @@ async def fastapi_get_curve_properties(
|
||||
return get_curve(network, curve)
|
||||
|
||||
@router.patch("/curves/properties", response_model=None, summary="设置曲线属性", description="更新指定曲线的属性")
|
||||
async def fastapi_set_curve_properties(
|
||||
def fastapi_set_curve_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
curve: str = Query(..., description="曲线ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置曲线属性。
|
||||
|
||||
更新指定曲线的属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": curve} | props
|
||||
return set_curve(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/curves", summary="获取所有曲线", description="获取网络中的所有曲线列表")
|
||||
async def fastapi_get_curves(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
def fastapi_get_curves(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
"""获取所有曲线。
|
||||
|
||||
返回指定网络中的所有曲线ID列表。
|
||||
@@ -83,7 +84,7 @@ async def fastapi_get_curves(network: str = Query(..., description="管网名称
|
||||
return get_curves(network)
|
||||
|
||||
@router.get("/curves/existence", summary="检查曲线存在性", description="检查指定的曲线是否存在")
|
||||
async def fastapi_is_curve(
|
||||
def fastapi_is_curve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
curve: str = Query(..., description="曲线ID")
|
||||
) -> bool:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
get_energy,
|
||||
@@ -19,7 +20,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/time", summary="获取时间选项架构", description="获取网络中时间选项的架构定义")
|
||||
async def fastapi_get_time_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_time_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取时间选项架构。
|
||||
|
||||
返回指定网络中时间相关选项的属性架构定义。
|
||||
@@ -27,7 +28,7 @@ async def fastapi_get_time_schema(network: str = Query(..., description="管网
|
||||
return get_time_schema(network)
|
||||
|
||||
@router.get("/network-options/time", summary="获取时间选项属性", description="获取指定网络中的时间选项属性信息")
|
||||
async def fastapi_get_time_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_time_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取时间选项属性。
|
||||
|
||||
返回指定网络中的时间相关选项属性。
|
||||
@@ -35,19 +36,19 @@ async def fastapi_get_time_properties(network: str = Query(..., description="管
|
||||
return get_time(network)
|
||||
|
||||
@router.patch("/time-properties", response_model=None, summary="设置时间选项属性", description="更新指定网络中的时间选项属性")
|
||||
async def fastapi_set_time_properties(
|
||||
def fastapi_set_time_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置时间选项属性。
|
||||
|
||||
更新指定网络中的时间相关选项属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_time(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/energy", summary="获取能耗选项架构", description="获取网络中能耗选项的架构定义")
|
||||
async def fastapi_get_energy_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_energy_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取能耗选项架构。
|
||||
|
||||
返回指定网络中能耗相关选项的属性架构定义。
|
||||
@@ -55,7 +56,7 @@ async def fastapi_get_energy_schema(network: str = Query(..., description="管
|
||||
return get_energy_schema(network)
|
||||
|
||||
@router.get("/network-options/energy", summary="获取能耗选项属性", description="获取指定网络中的能耗选项属性信息")
|
||||
async def fastapi_get_energy_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_energy_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取能耗选项属性。
|
||||
|
||||
返回指定网络中的能耗相关选项属性。
|
||||
@@ -63,19 +64,19 @@ async def fastapi_get_energy_properties(network: str = Query(..., description="
|
||||
return get_energy(network)
|
||||
|
||||
@router.patch("/energy-properties", response_model=None, summary="设置能耗选项属性", description="更新指定网络中的能耗选项属性")
|
||||
async def fastapi_set_energy_properties(
|
||||
def fastapi_set_energy_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置能耗选项属性。
|
||||
|
||||
更新指定网络中的能耗相关选项属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_energy(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/pump-energy", summary="获取泵能耗选项架构", description="获取网络中泵能耗选项的架构定义")
|
||||
async def fastapi_get_pump_energy_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_pump_energy_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取泵能耗选项架构。
|
||||
|
||||
返回指定网络中泵能耗相关选项的属性架构定义。
|
||||
@@ -83,7 +84,7 @@ async def fastapi_get_pump_energy_schema(network: str = Query(..., description="
|
||||
return get_pump_energy_schema(network)
|
||||
|
||||
@router.get("/network-options/pump-energy", summary="获取泵能耗属性", description="获取指定泵的能耗属性信息")
|
||||
async def fastapi_get_pump_energy_proeprties(
|
||||
def fastapi_get_pump_energy_proeprties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="泵ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -94,21 +95,21 @@ async def fastapi_get_pump_energy_proeprties(
|
||||
return get_pump_energy(network, pump)
|
||||
|
||||
@router.patch("/network-options/pump-energy", response_model=None, summary="设置泵能耗属性", description="更新指定泵的能耗属性")
|
||||
async def fastapi_set_pump_energy_properties(
|
||||
def fastapi_set_pump_energy_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="泵ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置泵能耗属性。
|
||||
|
||||
更新指定泵的能耗相关属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": pump} | props
|
||||
return set_pump_energy(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/network-schemas/option", summary="获取选项架构", description="获取网络中选项对象的架构定义")
|
||||
async def fastapi_get_option_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_option_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取选项架构。
|
||||
|
||||
返回指定网络中选项对象的属性架构定义。
|
||||
@@ -116,7 +117,7 @@ async def fastapi_get_option_schema(network: str = Query(..., description="管
|
||||
return get_option_v3_schema(network)
|
||||
|
||||
@router.get("/network-options", summary="获取选项属性", description="获取指定网络中的选项属性信息")
|
||||
async def fastapi_get_option_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_option_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取选项属性。
|
||||
|
||||
返回指定网络中的选项对象属性信息。
|
||||
@@ -124,13 +125,13 @@ async def fastapi_get_option_properties(network: str = Query(..., description="
|
||||
return get_option_v3(network)
|
||||
|
||||
@router.patch("/network-options", response_model=None, summary="设置选项属性", description="更新指定网络中的选项属性")
|
||||
async def fastapi_set_option_properties(
|
||||
def fastapi_set_option_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置选项属性。
|
||||
|
||||
更新指定网络中的选项属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_option_v3(network, ChangeSet(props))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_pattern,
|
||||
@@ -14,7 +15,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/pattern", summary="获取模式架构", description="获取网络中模式对象的架构定义")
|
||||
async def fastapi_get_pattern_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_pattern_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取模式架构。
|
||||
|
||||
返回指定网络中模式对象的属性架构定义。
|
||||
@@ -22,23 +23,23 @@ async def fastapi_get_pattern_schema(network: str = Query(..., description="管
|
||||
return get_pattern_schema(network)
|
||||
|
||||
@router.post("/patterns", response_model=None, summary="添加模式", description="在网络中添加一个新的模式")
|
||||
async def fastapi_add_pattern(
|
||||
def fastapi_add_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pattern: str = Query(..., description="模式ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""添加模式。
|
||||
|
||||
在指定网络中创建一个新的模式,并设置其初始属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {
|
||||
"id": pattern,
|
||||
} | props
|
||||
return add_pattern(network, ChangeSet(ps))
|
||||
|
||||
@router.delete("/patterns", response_model=None, summary="删除模式", description="从网络中删除指定的模式")
|
||||
async def fastapi_delete_pattern(
|
||||
def fastapi_delete_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pattern: str = Query(..., description="模式ID")
|
||||
) -> ChangeSet:
|
||||
@@ -50,7 +51,7 @@ async def fastapi_delete_pattern(
|
||||
return delete_pattern(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/patterns/properties", summary="获取模式属性", description="获取指定模式的属性信息")
|
||||
async def fastapi_get_pattern_properties(
|
||||
def fastapi_get_pattern_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pattern: str = Query(..., description="模式ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -61,21 +62,21 @@ async def fastapi_get_pattern_properties(
|
||||
return get_pattern(network, pattern)
|
||||
|
||||
@router.patch("/patterns/properties", response_model=None, summary="设置模式属性", description="更新指定模式的属性")
|
||||
async def fastapi_set_pattern_properties(
|
||||
def fastapi_set_pattern_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pattern: str = Query(..., description="模式ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置模式属性。
|
||||
|
||||
更新指定模式的属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": pattern} | props
|
||||
return set_pattern(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/patterns/existence", summary="检查模式存在性", description="检查指定的模式是否存在")
|
||||
async def fastapi_is_pattern(
|
||||
def fastapi_is_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pattern: str = Query(..., description="模式ID")
|
||||
) -> bool:
|
||||
@@ -86,7 +87,7 @@ async def fastapi_is_pattern(
|
||||
return is_pattern(network, pattern)
|
||||
|
||||
@router.get("/patterns", summary="获取所有模式", description="获取网络中的所有模式列表")
|
||||
async def fastapi_get_patterns(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
def fastapi_get_patterns(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
"""获取所有模式。
|
||||
|
||||
返回指定网络中的所有模式ID列表。
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_mixing,
|
||||
@@ -32,7 +33,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/quality", summary="获取水质架构", description="获取网络中水质对象的架构定义")
|
||||
async def fastapi_get_quality_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_quality_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取水质架构。
|
||||
|
||||
返回指定网络中水质对象的属性架构定义。
|
||||
@@ -40,7 +41,7 @@ async def fastapi_get_quality_schema(network: str = Query(..., description="管
|
||||
return get_quality_schema(network)
|
||||
|
||||
@router.get("/quality-configurations/properties", summary="获取水质属性", description="获取指定节点的水质属性信息")
|
||||
async def fastapi_get_quality_properties(
|
||||
def fastapi_get_quality_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -51,19 +52,19 @@ async def fastapi_get_quality_properties(
|
||||
return get_quality(network, node)
|
||||
|
||||
@router.patch("/quality-configurations/properties", response_model=None, summary="设置水质属性", description="更新指定节点的水质属性")
|
||||
async def fastapi_set_quality_properties(
|
||||
def fastapi_set_quality_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置水质属性。
|
||||
|
||||
更新指定节点的水质属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_quality(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/emitter", summary="获取发射器架构", description="获取网络中发射器对象的架构定义")
|
||||
async def fastapi_get_emitter_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_emitter_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取发射器架构。
|
||||
|
||||
返回指定网络中发射器对象的属性架构定义。
|
||||
@@ -71,7 +72,7 @@ async def fastapi_get_emitter_schema(network: str = Query(..., description="管
|
||||
return get_emitter_schema(network)
|
||||
|
||||
@router.get("/emitters/properties", summary="获取发射器属性", description="获取指定连接点的发射器属性信息")
|
||||
async def fastapi_get_emitter_properties(
|
||||
def fastapi_get_emitter_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="连接点ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -82,21 +83,21 @@ async def fastapi_get_emitter_properties(
|
||||
return get_emitter(network, junction)
|
||||
|
||||
@router.patch("/emitters/properties", response_model=None, summary="设置发射器属性", description="更新指定连接点的发射器属性")
|
||||
async def fastapi_set_emitter_properties(
|
||||
def fastapi_set_emitter_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="连接点ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置发射器属性。
|
||||
|
||||
更新指定连接点的发射器属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"junction": junction} | props
|
||||
return set_emitter(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/network-schemas/source", summary="获取水源架构", description="获取网络中水源对象的架构定义")
|
||||
async def fastapi_get_source_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_source_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取水源架构。
|
||||
|
||||
返回指定网络中水源对象的属性架构定义。
|
||||
@@ -104,7 +105,7 @@ async def fastapi_get_source_schema(network: str = Query(..., description="管
|
||||
return get_source_schema(network)
|
||||
|
||||
@router.get("/sources/detail", summary="获取水源属性", description="获取指定节点的水源属性信息")
|
||||
async def fastapi_get_source(
|
||||
def fastapi_get_source(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -115,31 +116,31 @@ async def fastapi_get_source(
|
||||
return get_source(network, node)
|
||||
|
||||
@router.patch("/sources", response_model=None, summary="设置水源属性", description="更新指定节点的水源属性")
|
||||
async def fastapi_set_source(
|
||||
def fastapi_set_source(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置水源属性。
|
||||
|
||||
更新指定节点的水源属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_source(network, ChangeSet(props))
|
||||
|
||||
@router.post("/sources", response_model=None, summary="添加水源", description="在网络中添加一个新的水源")
|
||||
async def fastapi_add_source(
|
||||
def fastapi_add_source(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""添加水源。
|
||||
|
||||
在指定网络中创建一个新的水源,并设置其初始属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return add_source(network, ChangeSet(props))
|
||||
|
||||
@router.delete("/sources", response_model=None, summary="删除水源", description="从网络中删除指定节点的水源")
|
||||
async def fastapi_delete_source(
|
||||
def fastapi_delete_source(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> ChangeSet:
|
||||
@@ -151,7 +152,7 @@ async def fastapi_delete_source(
|
||||
return delete_source(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/reaction", summary="获取反应架构", description="获取网络中反应对象的架构定义")
|
||||
async def fastapi_get_reaction_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_reaction_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取反应架构。
|
||||
|
||||
返回指定网络中反应对象的属性架构定义。
|
||||
@@ -159,7 +160,7 @@ async def fastapi_get_reaction_schema(network: str = Query(..., description="管
|
||||
return get_reaction_schema(network)
|
||||
|
||||
@router.get("/reactions/detail", summary="获取反应属性", description="获取指定网络中的反应属性信息")
|
||||
async def fastapi_get_reaction(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_reaction(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取反应属性。
|
||||
|
||||
返回指定网络中的反应属性信息。
|
||||
@@ -167,19 +168,19 @@ async def fastapi_get_reaction(network: str = Query(..., description="管网名
|
||||
return get_reaction(network)
|
||||
|
||||
@router.patch("/reactions", response_model=None, summary="设置反应属性", description="更新指定网络中的反应属性")
|
||||
async def fastapi_set_reaction(
|
||||
def fastapi_set_reaction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置反应属性。
|
||||
|
||||
更新指定网络中的反应属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_reaction(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/pipe-reaction", summary="获取管道反应架构", description="获取网络中管道反应对象的架构定义")
|
||||
async def fastapi_get_pipe_reaction_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_pipe_reaction_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取管道反应架构。
|
||||
|
||||
返回指定网络中管道反应对象的属性架构定义。
|
||||
@@ -187,7 +188,7 @@ async def fastapi_get_pipe_reaction_schema(network: str = Query(..., description
|
||||
return get_pipe_reaction_schema(network)
|
||||
|
||||
@router.get("/pipe-reactions/detail", summary="获取管道反应属性", description="获取指定管道的反应属性信息")
|
||||
async def fastapi_get_pipe_reaction(
|
||||
def fastapi_get_pipe_reaction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -198,19 +199,19 @@ async def fastapi_get_pipe_reaction(
|
||||
return get_pipe_reaction(network, pipe)
|
||||
|
||||
@router.patch("/pipe-reactions", response_model=None, summary="设置管道反应属性", description="更新指定管道的反应属性")
|
||||
async def fastapi_set_pipe_reaction(
|
||||
def fastapi_set_pipe_reaction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置管道反应属性。
|
||||
|
||||
更新指定管道的反应属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_pipe_reaction(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/tank-reaction", summary="获取水池反应架构", description="获取网络中水池反应对象的架构定义")
|
||||
async def fastapi_get_tank_reaction_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_tank_reaction_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取水池反应架构。
|
||||
|
||||
返回指定网络中水池反应对象的属性架构定义。
|
||||
@@ -218,7 +219,7 @@ async def fastapi_get_tank_reaction_schema(network: str = Query(..., description
|
||||
return get_tank_reaction_schema(network)
|
||||
|
||||
@router.get("/tank-reactions/detail", summary="获取水池反应属性", description="获取指定水池的反应属性信息")
|
||||
async def fastapi_get_tank_reaction(
|
||||
def fastapi_get_tank_reaction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水池ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -229,19 +230,19 @@ async def fastapi_get_tank_reaction(
|
||||
return get_tank_reaction(network, tank)
|
||||
|
||||
@router.patch("/tank-reactions", response_model=None, summary="设置水池反应属性", description="更新指定水池的反应属性")
|
||||
async def fastapi_set_tank_reaction(
|
||||
def fastapi_set_tank_reaction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置水池反应属性。
|
||||
|
||||
更新指定水池的反应属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_tank_reaction(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/mixing", summary="获取混合架构", description="获取网络中混合对象的架构定义")
|
||||
async def fastapi_get_mixing_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_mixing_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取混合架构。
|
||||
|
||||
返回指定网络中混合对象的属性架构定义。
|
||||
@@ -249,7 +250,7 @@ async def fastapi_get_mixing_schema(network: str = Query(..., description="管
|
||||
return get_mixing_schema(network)
|
||||
|
||||
@router.get("/mixing-configurations/detail", summary="获取混合属性", description="获取指定水池的混合属性信息")
|
||||
async def fastapi_get_mixing(
|
||||
def fastapi_get_mixing(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水池ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -260,37 +261,37 @@ async def fastapi_get_mixing(
|
||||
return get_mixing(network, tank)
|
||||
|
||||
@router.patch("/mixing-configurations", response_model=None, summary="设置混合属性", description="更新指定水池的混合属性")
|
||||
async def fastapi_set_mixing(
|
||||
def fastapi_set_mixing(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置混合属性。
|
||||
|
||||
更新指定水池的混合属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_mixing(network, ChangeSet(props))
|
||||
|
||||
@router.post("/mixing-configurations", response_model=None, summary="添加混合", description="在网络中添加一个新的混合")
|
||||
async def fastapi_add_mixing(
|
||||
def fastapi_add_mixing(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""添加混合。
|
||||
|
||||
在指定网络中创建一个新的混合,并设置其初始属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return add_mixing(network, ChangeSet(props))
|
||||
|
||||
@router.delete("/mixing-configurations", response_model=None, summary="删除混合", description="从网络中删除指定的混合")
|
||||
async def fastapi_delete_mixing(
|
||||
def fastapi_delete_mixing(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""删除混合。
|
||||
|
||||
从指定网络中删除指定的混合及其相关数据。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return delete_mixing(network, ChangeSet(props))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body, Response
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_label,
|
||||
@@ -24,7 +25,7 @@ import json
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/vertex", summary="获取图形元素架构", description="获取网络中图形元素对象的架构定义")
|
||||
async def fastapi_get_vertex_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_vertex_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取图形元素架构。
|
||||
|
||||
返回指定网络中图形元素对象的属性架构定义。
|
||||
@@ -32,7 +33,7 @@ async def fastapi_get_vertex_schema(network: str = Query(..., description="管
|
||||
return get_vertex_schema(network)
|
||||
|
||||
@router.get("/visual-elements/properties", summary="获取图形元素属性", description="获取指定图形元素的属性信息")
|
||||
async def fastapi_get_vertex_properties(
|
||||
def fastapi_get_vertex_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="图形元素链接")
|
||||
) -> dict[str, Any]:
|
||||
@@ -43,43 +44,43 @@ async def fastapi_get_vertex_properties(
|
||||
return get_vertex(network, link)
|
||||
|
||||
@router.patch("/visual-elements/properties", response_model=None, summary="设置图形元素属性", description="更新指定图形元素的属性")
|
||||
async def fastapi_set_vertex_properties(
|
||||
def fastapi_set_vertex_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置图形元素属性。
|
||||
|
||||
更新指定图形元素的属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_vertex(network, ChangeSet(props))
|
||||
|
||||
@router.post("/visual-elements", response_model=None, summary="添加图形元素", description="在网络中添加一个新的图形元素")
|
||||
async def fastapi_add_vertex(
|
||||
def fastapi_add_vertex(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""添加图形元素。
|
||||
|
||||
在指定网络中创建一个新的图形元素,并设置其初始属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return add_vertex(network, ChangeSet(props))
|
||||
|
||||
@router.delete("/visual-elements", response_model=None, summary="删除图形元素", description="从网络中删除指定的图形元素")
|
||||
async def fastapi_delete_vertex(
|
||||
def fastapi_delete_vertex(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""删除图形元素。
|
||||
|
||||
从指定网络中删除指定的图形元素及其相关数据。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return delete_vertex(network, ChangeSet(props))
|
||||
|
||||
@router.get("/visual-elements/links", response_class=PlainTextResponse, summary="获取所有图形元素链接", description="获取网络中的所有图形元素链接列表")
|
||||
async def fastapi_get_all_vertex_links(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
def fastapi_get_all_vertex_links(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
"""获取所有图形元素链接。
|
||||
|
||||
返回指定网络中的所有图形元素链接列表。
|
||||
@@ -87,7 +88,7 @@ async def fastapi_get_all_vertex_links(network: str = Query(..., description="
|
||||
return json.dumps(get_all_vertex_links(network))
|
||||
|
||||
@router.get("/all-vertices", response_class=PlainTextResponse, summary="获取所有图形元素", description="获取网络中的所有图形元素详细信息")
|
||||
async def fastapi_get_all_vertices(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[dict[str, Any]]:
|
||||
def fastapi_get_all_vertices(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[dict[str, Any]]:
|
||||
"""获取所有图形元素。
|
||||
|
||||
返回指定网络中的所有图形元素详细信息。
|
||||
@@ -95,7 +96,7 @@ async def fastapi_get_all_vertices(network: str = Query(..., description="管网
|
||||
return json.dumps(get_all_vertices(network))
|
||||
|
||||
@router.get("/network-schemas/label", summary="获取标签架构", description="获取网络中标签对象的架构定义")
|
||||
async def fastapi_get_label_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_label_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取标签架构。
|
||||
|
||||
返回指定网络中标签对象的属性架构定义。
|
||||
@@ -103,7 +104,7 @@ async def fastapi_get_label_schema(network: str = Query(..., description="管网
|
||||
return get_label_schema(network)
|
||||
|
||||
@router.get("/labels/properties", summary="获取标签属性", description="获取指定坐标处的标签属性信息")
|
||||
async def fastapi_get_label_properties(
|
||||
def fastapi_get_label_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
x: float = Query(..., description="X坐标"),
|
||||
y: float = Query(..., description="Y坐标")
|
||||
@@ -115,43 +116,43 @@ async def fastapi_get_label_properties(
|
||||
return get_label(network, x, y)
|
||||
|
||||
@router.patch("/labels/properties", response_model=None, summary="设置标签属性", description="更新指定标签的属性")
|
||||
async def fastapi_set_label_properties(
|
||||
def fastapi_set_label_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置标签属性。
|
||||
|
||||
更新指定标签的属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_label(network, ChangeSet(props))
|
||||
|
||||
@router.post("/labels", response_model=None, summary="添加标签", description="在网络中添加一个新的标签")
|
||||
async def fastapi_add_label(
|
||||
def fastapi_add_label(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""添加标签。
|
||||
|
||||
在指定网络中创建一个新的标签,并设置其初始属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return add_label(network, ChangeSet(props))
|
||||
|
||||
@router.delete("/labels", response_model=None, summary="删除标签", description="从网络中删除指定的标签")
|
||||
async def fastapi_delete_label(
|
||||
def fastapi_delete_label(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""删除标签。
|
||||
|
||||
从指定网络中删除指定的标签及其相关数据。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return delete_label(network, ChangeSet(props))
|
||||
|
||||
@router.get("/network-schemas/backdrop", summary="获取背景架构", description="获取网络中背景对象的架构定义")
|
||||
async def fastapi_get_backdrop_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_backdrop_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""获取背景架构。
|
||||
|
||||
返回指定网络中背景对象的属性架构定义。
|
||||
@@ -159,7 +160,7 @@ async def fastapi_get_backdrop_schema(network: str = Query(..., description="管
|
||||
return get_backdrop_schema(network)
|
||||
|
||||
@router.get("/backdrops/properties", summary="获取背景属性", description="获取指定网络的背景属性信息")
|
||||
async def fastapi_get_backdrop_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fastapi_get_backdrop_properties(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取背景属性。
|
||||
|
||||
返回指定网络的背景属性信息。
|
||||
@@ -167,13 +168,13 @@ async def fastapi_get_backdrop_properties(network: str = Query(..., description=
|
||||
return get_backdrop(network)
|
||||
|
||||
@router.patch("/backdrops/properties", response_model=None, summary="设置背景属性", description="更新指定网络的背景属性")
|
||||
async def fastapi_set_backdrop_properties(
|
||||
def fastapi_set_backdrop_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置背景属性。
|
||||
|
||||
更新指定网络的背景属性值。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_backdrop(network, ChangeSet(props))
|
||||
|
||||
@@ -2,14 +2,11 @@ import logging
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query, Path
|
||||
import psycopg
|
||||
from psycopg import AsyncConnection
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.auth.project_dependencies import (
|
||||
ProjectContext,
|
||||
get_project_context,
|
||||
get_project_pg_session,
|
||||
get_project_pg_connection,
|
||||
get_project_timescale_connection,
|
||||
get_metadata_repository,
|
||||
)
|
||||
@@ -90,7 +87,7 @@ async def list_user_projects(
|
||||
|
||||
@router.get("/projects/current/database-health", summary="检查数据库健康状态", description="检查项目数据库连接的健康状况")
|
||||
async def project_db_health(
|
||||
pg_session: AsyncSession = Depends(get_project_pg_session),
|
||||
pg_conn: AsyncConnection = Depends(get_project_pg_connection),
|
||||
ts_conn: AsyncConnection = Depends(get_project_timescale_connection),
|
||||
):
|
||||
"""
|
||||
@@ -99,8 +96,10 @@ async def project_db_health(
|
||||
检查PostgreSQL和TimescaleDB数据库的连接状态
|
||||
"""
|
||||
try:
|
||||
await pg_session.execute(text("SELECT 1"))
|
||||
except SQLAlchemyError as exc:
|
||||
async with pg_conn.cursor() as cur:
|
||||
await cur.execute("SELECT 1")
|
||||
await cur.fetchone()
|
||||
except psycopg.Error as exc:
|
||||
logger.error("Project PostgreSQL health check failed", exc_info=True)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
|
||||
@@ -12,6 +12,7 @@ from fastapi import (
|
||||
UploadFile,
|
||||
status,
|
||||
)
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from app.auth.metadata_dependencies import (
|
||||
get_current_metadata_admin,
|
||||
@@ -24,6 +25,7 @@ from app.auth.project_dependencies import (
|
||||
from app.core.audit import AuditAction, log_audit_event
|
||||
from app.infra.db.metadb.repositories.metadata_repository import MetadataRepository
|
||||
from app.infra.db.project_routing import activate_project_routing
|
||||
from app.native.wndb.core.database import MaterializedViewRefreshAfterCommitError
|
||||
from app.services.network_import import network_update
|
||||
from app.services.tjnetwork import run_inp
|
||||
|
||||
@@ -87,8 +89,8 @@ def _validate_inp_bytes(content: bytes, filename: str) -> str:
|
||||
async def _read_upload(file: UploadFile) -> tuple[bytes, str]:
|
||||
filename = Path(file.filename or "").name
|
||||
content = await file.read(MAX_INP_FILE_BYTES + 1)
|
||||
_validate_inp_bytes(content, filename)
|
||||
return content, filename
|
||||
normalized = _validate_inp_bytes(content, filename).encode("utf-8")
|
||||
return normalized, filename
|
||||
|
||||
|
||||
async def _audit_model_change(
|
||||
@@ -114,7 +116,7 @@ async def _audit_model_change(
|
||||
)
|
||||
|
||||
|
||||
async def _run_uploaded_inp(content: bytes) -> str:
|
||||
def _run_uploaded_inp_sync(content: bytes) -> str:
|
||||
target_dir = Path("inp")
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
model_name = f"admin_model_{uuid4().hex}"
|
||||
@@ -123,7 +125,11 @@ async def _run_uploaded_inp(content: bytes) -> str:
|
||||
return run_inp(model_name)
|
||||
|
||||
|
||||
async def _update_from_inp(content: bytes, project_code: str) -> None:
|
||||
async def _run_uploaded_inp(content: bytes) -> str:
|
||||
return await run_in_threadpool(_run_uploaded_inp_sync, content)
|
||||
|
||||
|
||||
def _update_from_inp_sync(content: bytes, project_code: str) -> None:
|
||||
temp_path: Path | None = None
|
||||
try:
|
||||
with NamedTemporaryFile(suffix=".inp", delete=False) as temp_file:
|
||||
@@ -135,9 +141,15 @@ async def _update_from_inp(content: bytes, project_code: str) -> None:
|
||||
temp_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
async def _update_from_inp(content: bytes, project_code: str) -> None:
|
||||
await run_in_threadpool(_update_from_inp_sync, content, project_code)
|
||||
|
||||
|
||||
async def _apply_model_update(content: bytes, project_code: str) -> None:
|
||||
try:
|
||||
await _update_from_inp(content, project_code)
|
||||
except MaterializedViewRefreshAfterCommitError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
calculate_demand_to_network,
|
||||
@@ -21,7 +22,7 @@ router = APIRouter()
|
||||
summary="获取需水量属性架构",
|
||||
description="获取指定水网中需水量(Demand)的属性架构定义"
|
||||
)
|
||||
async def fastapi_get_demand_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fastapi_get_demand_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
获取需水量属性架构。
|
||||
|
||||
@@ -35,7 +36,7 @@ async def fastapi_get_demand_schema(network: str = Query(..., description="管
|
||||
summary="获取需水量属性",
|
||||
description="获取指定水网中节点的需水量属性信息"
|
||||
)
|
||||
async def fastapi_get_demand_properties(
|
||||
def fastapi_get_demand_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -54,17 +55,17 @@ async def fastapi_get_demand_properties(
|
||||
summary="设置需水量属性",
|
||||
description="设置指定水网中节点的需水量属性信息"
|
||||
)
|
||||
async def fastapi_set_demand_properties(
|
||||
def fastapi_set_demand_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
设置节点的需水量属性。
|
||||
|
||||
修改指定节点的需水量信息。请求体应包含需水量值、水压等级等属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"junction": junction} | props
|
||||
return set_demand(network, ChangeSet(ps))
|
||||
|
||||
@@ -76,9 +77,9 @@ async def fastapi_set_demand_properties(
|
||||
summary="计算需水量到节点分配",
|
||||
description="将总需水量按指定方式分配到多个节点"
|
||||
)
|
||||
async def fastapi_calculate_demand_to_nodes(
|
||||
def fastapi_calculate_demand_to_nodes(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> dict[str, float]:
|
||||
"""
|
||||
计算需水量到节点分配。
|
||||
@@ -91,7 +92,7 @@ async def fastapi_calculate_demand_to_nodes(
|
||||
"nodes": 节点ID列表(list[str])
|
||||
}
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
demand = props["demand"]
|
||||
nodes = props["nodes"]
|
||||
return calculate_demand_to_nodes(network, demand, nodes)
|
||||
@@ -101,9 +102,9 @@ async def fastapi_calculate_demand_to_nodes(
|
||||
summary="计算需水量到区域分配",
|
||||
description="将总需水量按区域特征分配到该区域内的节点"
|
||||
)
|
||||
async def fastapi_calculate_demand_to_region(
|
||||
def fastapi_calculate_demand_to_region(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> dict[str, float]:
|
||||
"""
|
||||
计算需水量到区域分配。
|
||||
@@ -116,7 +117,7 @@ async def fastapi_calculate_demand_to_region(
|
||||
"region": 区域ID(str)
|
||||
}
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
demand = props["demand"]
|
||||
region = props["region"]
|
||||
return calculate_demand_to_region(network, demand, region)
|
||||
@@ -126,7 +127,7 @@ async def fastapi_calculate_demand_to_region(
|
||||
summary="计算需水量到整网分配",
|
||||
description="将需水量均匀分配到整个水网的所有需水节点"
|
||||
)
|
||||
async def fastapi_calculate_demand_to_network(
|
||||
def fastapi_calculate_demand_to_network(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
demand: float = Query(..., description="总需水量(m³/h)", gt=0)
|
||||
) -> dict[str, float]:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
delete_junction,
|
||||
@@ -48,7 +49,7 @@ router = APIRouter()
|
||||
summary="检查节点有效性",
|
||||
description="检查指定ID是否为水网中的有效节点"
|
||||
)
|
||||
async def fastapi_is_node(
|
||||
def fastapi_is_node(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> bool:
|
||||
@@ -60,7 +61,7 @@ async def fastapi_is_node(
|
||||
summary="检查是否为接点",
|
||||
description="检查指定ID是否为水网中的接点(需求点)"
|
||||
)
|
||||
async def fastapi_is_junction(
|
||||
def fastapi_is_junction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> bool:
|
||||
@@ -72,7 +73,7 @@ async def fastapi_is_junction(
|
||||
summary="检查是否为水源",
|
||||
description="检查指定ID是否为水网中的水源(水库/河流)"
|
||||
)
|
||||
async def fastapi_is_reservoir(
|
||||
def fastapi_is_reservoir(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> bool:
|
||||
@@ -84,7 +85,7 @@ async def fastapi_is_reservoir(
|
||||
summary="检查是否为蓄水池",
|
||||
description="检查指定ID是否为水网中的蓄水池"
|
||||
)
|
||||
async def fastapi_is_tank(
|
||||
def fastapi_is_tank(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> bool:
|
||||
@@ -96,7 +97,7 @@ async def fastapi_is_tank(
|
||||
summary="检查管线有效性",
|
||||
description="检查指定ID是否为水网中的有效管线"
|
||||
)
|
||||
async def fastapi_is_link(
|
||||
def fastapi_is_link(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> bool:
|
||||
@@ -108,7 +109,7 @@ async def fastapi_is_link(
|
||||
summary="检查是否为管道",
|
||||
description="检查指定ID是否为水网中的管道"
|
||||
)
|
||||
async def fastapi_is_pipe(
|
||||
def fastapi_is_pipe(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> bool:
|
||||
@@ -120,7 +121,7 @@ async def fastapi_is_pipe(
|
||||
summary="检查是否为泵",
|
||||
description="检查指定ID是否为水网中的泵"
|
||||
)
|
||||
async def fastapi_is_pump(
|
||||
def fastapi_is_pump(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> bool:
|
||||
@@ -132,7 +133,7 @@ async def fastapi_is_pump(
|
||||
summary="检查是否为阀门",
|
||||
description="检查指定ID是否为水网中的阀门"
|
||||
)
|
||||
async def fastapi_is_valve(
|
||||
def fastapi_is_valve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> bool:
|
||||
@@ -144,7 +145,7 @@ async def fastapi_is_valve(
|
||||
summary="获取节点类型",
|
||||
description="获取指定节点的类型(接点/水源/蓄水池)"
|
||||
)
|
||||
async def fastapi_get_node_type(
|
||||
def fastapi_get_node_type(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> str:
|
||||
@@ -156,7 +157,7 @@ async def fastapi_get_node_type(
|
||||
summary="获取管线类型",
|
||||
description="获取指定管线的类型(管道/泵/阀门)"
|
||||
)
|
||||
async def fastapi_get_link_type(
|
||||
def fastapi_get_link_type(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> str:
|
||||
@@ -168,7 +169,7 @@ async def fastapi_get_link_type(
|
||||
summary="获取元素类型",
|
||||
description="获取指定元素的类型(节点或管线)"
|
||||
)
|
||||
async def fastapi_get_element_type(
|
||||
def fastapi_get_element_type(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
element: str = Query(..., description="元素ID")
|
||||
) -> str:
|
||||
@@ -180,7 +181,7 @@ async def fastapi_get_element_type(
|
||||
summary="获取元素类型值",
|
||||
description="获取指定元素的类型数值标识"
|
||||
)
|
||||
async def fastapi_get_element_type_value(
|
||||
def fastapi_get_element_type_value(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
element: str = Query(..., description="元素ID")
|
||||
) -> int:
|
||||
@@ -192,7 +193,7 @@ async def fastapi_get_element_type_value(
|
||||
summary="获取所有节点",
|
||||
description="获取指定水网中的所有节点ID列表"
|
||||
)
|
||||
async def fastapi_get_nodes(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
def fastapi_get_nodes(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
"""获取水网中所有节点的ID列表。"""
|
||||
return get_nodes(network)
|
||||
|
||||
@@ -201,7 +202,7 @@ async def fastapi_get_nodes(network: str = Query(..., description="管网名称
|
||||
summary="获取所有管线",
|
||||
description="获取指定水网中的所有管线ID列表"
|
||||
)
|
||||
async def fastapi_get_links(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
def fastapi_get_links(network: str = Query(..., description="管网名称(或数据库名称)")) -> list[str]:
|
||||
"""获取水网中所有管线的ID列表。"""
|
||||
return get_links(network)
|
||||
|
||||
@@ -226,7 +227,7 @@ def get_node_links_endpoint(
|
||||
summary="获取节点属性",
|
||||
description="获取指定节点的所有属性信息"
|
||||
)
|
||||
async def fast_get_node_properties(
|
||||
def fast_get_node_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -238,7 +239,7 @@ async def fast_get_node_properties(
|
||||
summary="获取管线属性",
|
||||
description="获取指定管线的所有属性信息"
|
||||
)
|
||||
async def fast_get_link_properties(
|
||||
def fast_get_link_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -250,7 +251,7 @@ async def fast_get_link_properties(
|
||||
summary="获取SCADA点属性",
|
||||
description="获取指定SCADA点的属性信息"
|
||||
)
|
||||
async def fast_get_scada_properties(
|
||||
def fast_get_scada_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
scada: str = Query(..., description="SCADA点ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -262,7 +263,7 @@ async def fast_get_scada_properties(
|
||||
summary="获取所有SCADA点属性",
|
||||
description="获取指定水网中所有SCADA点的属性信息"
|
||||
)
|
||||
async def fast_get_all_scada_properties(
|
||||
def fast_get_all_scada_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""获取水网中所有SCADA点的属性列表。"""
|
||||
@@ -273,7 +274,7 @@ async def fast_get_all_scada_properties(
|
||||
summary="获取指定类型元素属性",
|
||||
description="获取指定类型的元素属性信息"
|
||||
)
|
||||
async def fast_get_element_properties_with_type(
|
||||
def fast_get_element_properties_with_type(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
elementtype: str = Query(..., description="元素类型"),
|
||||
element: str = Query(..., description="元素ID")
|
||||
@@ -286,7 +287,7 @@ async def fast_get_element_properties_with_type(
|
||||
summary="获取元素属性",
|
||||
description="获取指定元素的属性信息"
|
||||
)
|
||||
async def fast_get_element_properties(
|
||||
def fast_get_element_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
element: str = Query(..., description="元素ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -302,7 +303,7 @@ async def fast_get_element_properties(
|
||||
summary="获取标题属性架构",
|
||||
description="获取指定水网的标题(标题)属性架构定义"
|
||||
)
|
||||
async def fast_get_title_schema(
|
||||
def fast_get_title_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""获取水网标题的属性架构。"""
|
||||
@@ -313,7 +314,7 @@ async def fast_get_title_schema(
|
||||
summary="获取水网标题属性",
|
||||
description="获取指定水网的标题(Title)信息"
|
||||
)
|
||||
async def fast_get_title(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def fast_get_title(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""获取水网的标题属性。"""
|
||||
return get_title(network)
|
||||
|
||||
@@ -323,12 +324,12 @@ async def fast_get_title(network: str = Query(..., description="管网名称(
|
||||
summary="设置水网标题属性",
|
||||
description="设置指定水网的标题(Title)信息"
|
||||
)
|
||||
async def fastapi_set_title(
|
||||
def fastapi_set_title(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置水网的标题属性。"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_title(network, ChangeSet(props))
|
||||
|
||||
############################################################
|
||||
@@ -340,7 +341,7 @@ async def fastapi_set_title(
|
||||
summary="获取状态属性架构",
|
||||
description="获取指定水网的状态(Status)属性架构定义"
|
||||
)
|
||||
async def fastapi_get_status_schema(
|
||||
def fastapi_get_status_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""获取水网状态的属性架构。"""
|
||||
@@ -351,7 +352,7 @@ async def fastapi_get_status_schema(
|
||||
summary="获取管线状态",
|
||||
description="获取指定管线的状态信息"
|
||||
)
|
||||
async def fastapi_get_status(
|
||||
def fastapi_get_status(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -364,13 +365,13 @@ async def fastapi_get_status(
|
||||
summary="设置管线状态",
|
||||
description="设置指定管线的状态信息"
|
||||
)
|
||||
async def fastapi_set_status_properties(
|
||||
def fastapi_set_status_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置管线的状态属性。"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"link": link} | props
|
||||
return set_status(network, ChangeSet(ps))
|
||||
|
||||
@@ -384,7 +385,7 @@ async def fastapi_set_status_properties(
|
||||
summary="删除节点",
|
||||
description="删除指定的节点(接点/水源/蓄水池)"
|
||||
)
|
||||
async def fastapi_delete_node(
|
||||
def fastapi_delete_node(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> ChangeSet:
|
||||
@@ -404,7 +405,7 @@ async def fastapi_delete_node(
|
||||
summary="删除管线",
|
||||
description="删除指定的管线(管道/泵/阀门)"
|
||||
)
|
||||
async def fastapi_delete_link(
|
||||
def fastapi_delete_link(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
link: str = Query(..., description="管线ID")
|
||||
) -> ChangeSet:
|
||||
|
||||
@@ -27,7 +27,7 @@ router = APIRouter()
|
||||
# # example: set_coord(p, ChangeSet({'node': 'j1', 'x': 1.0, 'y': 2.0}))
|
||||
# @router.post("/setcoord/", response_model=None)
|
||||
# async def fastapi_set_coord(network: str, req: Request) -> ChangeSet:
|
||||
# props = await req.json()
|
||||
# props = payload
|
||||
# return set_coord(network, ChangeSet(props))
|
||||
|
||||
@router.get(
|
||||
@@ -35,7 +35,7 @@ router = APIRouter()
|
||||
summary="获取节点坐标",
|
||||
description="获取指定节点的地理坐标(X, Y)"
|
||||
)
|
||||
async def fastapi_get_node_coord(
|
||||
def fastapi_get_node_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
node: str = Query(..., description="节点ID")
|
||||
) -> dict[str, float] | None:
|
||||
@@ -48,7 +48,7 @@ async def fastapi_get_node_coord(
|
||||
summary="获取范围内的网络元素",
|
||||
description="获取指定地理范围内的网络节点和管线"
|
||||
)
|
||||
async def fastapi_get_network_in_extent(
|
||||
def fastapi_get_network_in_extent(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
x1: float = Query(..., description="范围左下角X坐标", alias="x1"),
|
||||
y1: float = Query(..., description="范围左下角Y坐标", alias="y1"),
|
||||
@@ -63,7 +63,7 @@ async def fastapi_get_network_in_extent(
|
||||
summary="获取主要节点坐标",
|
||||
description="获取直径大于等于指定值的节点坐标"
|
||||
)
|
||||
async def fastapi_get_majornode_coords(
|
||||
def fastapi_get_majornode_coords(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
diameter: int = Query(..., description="最小直径(mm)", gt=0)
|
||||
) -> dict[str, dict[str, float]]:
|
||||
@@ -75,7 +75,7 @@ async def fastapi_get_majornode_coords(
|
||||
summary="获取主要管道节点",
|
||||
description="获取直径大于等于指定值的管道的节点ID"
|
||||
)
|
||||
async def fastapi_get_major_pipe_nodes(
|
||||
def fastapi_get_major_pipe_nodes(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
diameter: int = Query(..., description="最小直径(mm)", gt=0)
|
||||
) -> list[str] | None:
|
||||
@@ -87,7 +87,7 @@ async def fastapi_get_major_pipe_nodes(
|
||||
summary="获取网络管线节点",
|
||||
description="获取指定水网所有管线的起点和终点节点"
|
||||
)
|
||||
async def fastapi_get_network_link_nodes(
|
||||
def fastapi_get_network_link_nodes(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[str] | None:
|
||||
"""获取网络中所有管线的连接节点。"""
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_junction,
|
||||
@@ -13,7 +14,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/junction", summary="获取节点架构", description="获取指定项目的节点属性架构和数据类型定义。")
|
||||
async def fast_get_junction_schema(
|
||||
def fast_get_junction_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
@@ -27,7 +28,7 @@ async def fast_get_junction_schema(
|
||||
return get_junction_schema(network)
|
||||
|
||||
@router.post("/junctions", response_model=None, summary="添加节点", description="在供水网络中添加新的节点,指定节点ID和空间坐标。")
|
||||
async def fastapi_add_junction(
|
||||
def fastapi_add_junction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
x: float = Query(..., description="X 坐标"),
|
||||
@@ -51,7 +52,7 @@ async def fastapi_add_junction(
|
||||
return add_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.delete("/junctions", response_model=None, summary="删除节点", description="从供水网络中删除指定的节点。")
|
||||
async def fastapi_delete_junction(
|
||||
def fastapi_delete_junction(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> ChangeSet:
|
||||
@@ -69,7 +70,7 @@ async def fastapi_delete_junction(
|
||||
return delete_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/junctions/elevation", summary="获取节点标高", description="获取指定节点的标高(海拔高度)。")
|
||||
async def fastapi_get_junction_elevation(
|
||||
def fastapi_get_junction_elevation(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> float:
|
||||
@@ -87,7 +88,7 @@ async def fastapi_get_junction_elevation(
|
||||
return ps["elevation"]
|
||||
|
||||
@router.get("/junctions/x", summary="获取节点 X 坐标", description="获取指定节点的 X 坐标值。")
|
||||
async def fastapi_get_junction_x(
|
||||
def fastapi_get_junction_x(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> float:
|
||||
@@ -105,7 +106,7 @@ async def fastapi_get_junction_x(
|
||||
return ps["x"]
|
||||
|
||||
@router.get("/junctions/y", summary="获取节点 Y 坐标", description="获取指定节点的 Y 坐标值。")
|
||||
async def fastapi_get_junction_y(
|
||||
def fastapi_get_junction_y(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> float:
|
||||
@@ -123,7 +124,7 @@ async def fastapi_get_junction_y(
|
||||
return ps["y"]
|
||||
|
||||
@router.get("/junctions/coord", summary="获取节点坐标", description="获取指定节点的 X 和 Y 坐标。")
|
||||
async def fastapi_get_junction_coord(
|
||||
def fastapi_get_junction_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> dict[str, float]:
|
||||
@@ -142,7 +143,7 @@ async def fastapi_get_junction_coord(
|
||||
return coord
|
||||
|
||||
@router.get("/junctions/demand", summary="获取节点需水量", description="获取指定节点的需水量。")
|
||||
async def fastapi_get_junction_demand(
|
||||
def fastapi_get_junction_demand(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> float:
|
||||
@@ -160,7 +161,7 @@ async def fastapi_get_junction_demand(
|
||||
return ps["demand"]
|
||||
|
||||
@router.get("/junctions/pattern", summary="获取节点需水模式", description="获取指定节点的需水模式标识。")
|
||||
async def fastapi_get_junction_pattern(
|
||||
def fastapi_get_junction_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> str:
|
||||
@@ -178,7 +179,7 @@ async def fastapi_get_junction_pattern(
|
||||
return ps["pattern"]
|
||||
|
||||
@router.patch("/junctions/elevation", response_model=None, summary="设置节点标高", description="设置指定节点的标高值。")
|
||||
async def fastapi_set_junction_elevation(
|
||||
def fastapi_set_junction_elevation(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
elevation: float = Query(..., description="标高(海拔高度)")
|
||||
@@ -198,7 +199,7 @@ async def fastapi_set_junction_elevation(
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/junctions/x", response_model=None, summary="设置节点 X 坐标", description="设置指定节点的 X 坐标值。")
|
||||
async def fastapi_set_junction_x(
|
||||
def fastapi_set_junction_x(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
x: float = Query(..., description="X 坐标值")
|
||||
@@ -218,7 +219,7 @@ async def fastapi_set_junction_x(
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/junctions/y", response_model=None, summary="设置节点 Y 坐标", description="设置指定节点的 Y 坐标值。")
|
||||
async def fastapi_set_junction_y(
|
||||
def fastapi_set_junction_y(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
y: float = Query(..., description="Y 坐标值")
|
||||
@@ -238,7 +239,7 @@ async def fastapi_set_junction_y(
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/junctions/coord", response_model=None, summary="设置节点坐标", description="设置指定节点的 X 和 Y 坐标。")
|
||||
async def fastapi_set_junction_coord(
|
||||
def fastapi_set_junction_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
x: float = Query(..., description="X 坐标值"),
|
||||
@@ -260,7 +261,7 @@ async def fastapi_set_junction_coord(
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/junctions/demand", response_model=None, summary="设置节点需水量", description="设置指定节点的需水量。")
|
||||
async def fastapi_set_junction_demand(
|
||||
def fastapi_set_junction_demand(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
demand: float = Query(..., description="需水量值")
|
||||
@@ -280,7 +281,7 @@ async def fastapi_set_junction_demand(
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/junctions/pattern", response_model=None, summary="设置节点需水模式", description="设置指定节点的需水模式标识。")
|
||||
async def fastapi_set_junction_pattern(
|
||||
def fastapi_set_junction_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
pattern: str = Query(..., description="需水模式标识")
|
||||
@@ -300,7 +301,7 @@ async def fastapi_set_junction_pattern(
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/junctions/properties", summary="获取节点属性", description="获取指定节点的所有属性信息。")
|
||||
async def fastapi_get_junction_properties(
|
||||
def fastapi_get_junction_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -317,7 +318,7 @@ async def fastapi_get_junction_properties(
|
||||
return get_junction(network, junction)
|
||||
|
||||
@router.get("/junctions", summary="获取所有节点属性", description="获取指定项目中所有节点的属性信息。")
|
||||
async def fastapi_get_all_junction_properties(
|
||||
def fastapi_get_all_junction_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
@@ -336,10 +337,10 @@ async def fastapi_get_all_junction_properties(
|
||||
return results
|
||||
|
||||
@router.patch("/junctions/properties", response_model=None, summary="批量设置节点属性", description="批量设置指定节点的多个属性。")
|
||||
async def fastapi_set_junction_properties(
|
||||
def fastapi_set_junction_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
junction: str = Query(..., description="节点 ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
批量设置节点属性。
|
||||
@@ -354,6 +355,6 @@ async def fastapi_set_junction_properties(
|
||||
Returns:
|
||||
ChangeSet: 包含变更信息的结果
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": junction} | props
|
||||
return set_junction(network, ChangeSet(ps))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
PIPE_STATUS_OPEN,
|
||||
@@ -14,7 +15,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/pipe", summary="获取管道模式", description="获取管道对象的模式定义,包含所有可用字段及其类型")
|
||||
async def fastapi_get_pipe_schema(
|
||||
def fastapi_get_pipe_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
@@ -29,7 +30,7 @@ async def fastapi_get_pipe_schema(
|
||||
return get_pipe_schema(network)
|
||||
|
||||
@router.post("/pipes", response_model=None, summary="添加管道", description="向网络中添加新的管道,需要提供管道的基本参数如长度、管径、粗糙度等")
|
||||
async def fastapi_add_pipe(
|
||||
def fastapi_add_pipe(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道标识符"),
|
||||
node1: str = Query(..., description="管道起始节点ID"),
|
||||
@@ -70,7 +71,7 @@ async def fastapi_add_pipe(
|
||||
return add_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.delete("/pipes", response_model=None, summary="删除管道", description="从网络中删除指定的管道")
|
||||
async def fastapi_delete_pipe(
|
||||
def fastapi_delete_pipe(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="要删除的管道ID")
|
||||
) -> ChangeSet:
|
||||
@@ -88,7 +89,7 @@ async def fastapi_delete_pipe(
|
||||
return delete_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/pipes/node1", summary="获取管道起始节点", description="获取指定管道的起始节点ID")
|
||||
async def fastapi_get_pipe_node1(
|
||||
def fastapi_get_pipe_node1(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> str | None:
|
||||
@@ -106,7 +107,7 @@ async def fastapi_get_pipe_node1(
|
||||
return ps["node1"]
|
||||
|
||||
@router.get("/pipes/node2", summary="获取管道终止节点", description="获取指定管道的终止节点ID")
|
||||
async def fastapi_get_pipe_node2(
|
||||
def fastapi_get_pipe_node2(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> str | None:
|
||||
@@ -124,7 +125,7 @@ async def fastapi_get_pipe_node2(
|
||||
return ps["node2"]
|
||||
|
||||
@router.get("/pipes/length", summary="获取管道长度", description="获取指定管道的长度")
|
||||
async def fastapi_get_pipe_length(
|
||||
def fastapi_get_pipe_length(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> float | None:
|
||||
@@ -142,7 +143,7 @@ async def fastapi_get_pipe_length(
|
||||
return ps["length"]
|
||||
|
||||
@router.get("/pipes/diameter", summary="获取管道管径", description="获取指定管道的管径")
|
||||
async def fastapi_get_pipe_diameter(
|
||||
def fastapi_get_pipe_diameter(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> float | None:
|
||||
@@ -160,7 +161,7 @@ async def fastapi_get_pipe_diameter(
|
||||
return ps["diameter"]
|
||||
|
||||
@router.get("/pipes/roughness", summary="获取管道粗糙度", description="获取指定管道的粗糙度")
|
||||
async def fastapi_get_pipe_roughness(
|
||||
def fastapi_get_pipe_roughness(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> float | None:
|
||||
@@ -178,7 +179,7 @@ async def fastapi_get_pipe_roughness(
|
||||
return ps["roughness"]
|
||||
|
||||
@router.get("/pipes/minor-loss", summary="获取管道局部阻力系数", description="获取指定管道的局部阻力系数")
|
||||
async def fastapi_get_pipe_minor_loss(
|
||||
def fastapi_get_pipe_minor_loss(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> float | None:
|
||||
@@ -196,7 +197,7 @@ async def fastapi_get_pipe_minor_loss(
|
||||
return ps["minor_loss"]
|
||||
|
||||
@router.get("/pipes/status", summary="获取管道状态", description="获取指定管道的状态(开启或关闭)")
|
||||
async def fastapi_get_pipe_status(
|
||||
def fastapi_get_pipe_status(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> str | None:
|
||||
@@ -214,7 +215,7 @@ async def fastapi_get_pipe_status(
|
||||
return ps["status"]
|
||||
|
||||
@router.patch("/pipes/node1", response_model=None, summary="设置管道起始节点", description="设置指定管道的起始节点")
|
||||
async def fastapi_set_pipe_node1(
|
||||
def fastapi_set_pipe_node1(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
node1: str = Query(..., description="新的起始节点ID")
|
||||
@@ -234,7 +235,7 @@ async def fastapi_set_pipe_node1(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pipes/node2", response_model=None, summary="设置管道终止节点", description="设置指定管道的终止节点")
|
||||
async def fastapi_set_pipe_node2(
|
||||
def fastapi_set_pipe_node2(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
node2: str = Query(..., description="新的终止节点ID")
|
||||
@@ -254,7 +255,7 @@ async def fastapi_set_pipe_node2(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pipes/length", response_model=None, summary="设置管道长度", description="设置指定管道的长度")
|
||||
async def fastapi_set_pipe_length(
|
||||
def fastapi_set_pipe_length(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
length: float = Query(..., description="新的管道长度(单位:米)")
|
||||
@@ -274,7 +275,7 @@ async def fastapi_set_pipe_length(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pipes/diameter", response_model=None, summary="设置管道管径", description="设置指定管道的管径")
|
||||
async def fastapi_set_pipe_diameter(
|
||||
def fastapi_set_pipe_diameter(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
diameter: float = Query(..., description="新的管道管径(单位:毫米)")
|
||||
@@ -294,7 +295,7 @@ async def fastapi_set_pipe_diameter(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pipes/roughness", response_model=None, summary="设置管道粗糙度", description="设置指定管道的粗糙度")
|
||||
async def fastapi_set_pipe_roughness(
|
||||
def fastapi_set_pipe_roughness(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
roughness: float = Query(..., description="新的管道粗糙度值")
|
||||
@@ -314,7 +315,7 @@ async def fastapi_set_pipe_roughness(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pipes/minor-loss", response_model=None, summary="设置管道局部阻力系数", description="设置指定管道的局部阻力系数")
|
||||
async def fastapi_set_pipe_minor_loss(
|
||||
def fastapi_set_pipe_minor_loss(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
minor_loss: float = Query(..., description="新的局部阻力系数值")
|
||||
@@ -334,7 +335,7 @@ async def fastapi_set_pipe_minor_loss(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pipes/status", response_model=None, summary="设置管道状态", description="设置指定管道的状态(开启或关闭)")
|
||||
async def fastapi_set_pipe_status(
|
||||
def fastapi_set_pipe_status(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
status: str = Query(..., description="新的管道状态(开启/关闭)")
|
||||
@@ -354,7 +355,7 @@ async def fastapi_set_pipe_status(
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/pipes/properties", summary="获取管道属性", description="获取指定管道的所有属性信息")
|
||||
async def fastapi_get_pipe_properties(
|
||||
def fastapi_get_pipe_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -371,7 +372,7 @@ async def fastapi_get_pipe_properties(
|
||||
return get_pipe(network, pipe)
|
||||
|
||||
@router.get("/pipes", summary="获取所有管道属性", description="获取网络中所有管道的属性信息列表")
|
||||
async def fastapi_get_all_pipe_properties(
|
||||
def fastapi_get_all_pipe_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
@@ -388,10 +389,10 @@ async def fastapi_get_all_pipe_properties(
|
||||
return results
|
||||
|
||||
@router.patch("/pipes/properties", response_model=None, summary="设置管道属性", description="批量设置指定管道的多个属性")
|
||||
async def fastapi_set_pipe_properties(
|
||||
def fastapi_set_pipe_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pipe: str = Query(..., description="管道ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
批量设置管道属性。
|
||||
@@ -404,6 +405,6 @@ async def fastapi_set_pipe_properties(
|
||||
Returns:
|
||||
ChangeSet对象,包含本次修改的变更信息
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": pipe} | props
|
||||
return set_pipe(network, ChangeSet(ps))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_pump,
|
||||
@@ -13,7 +14,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/pump", summary="获取水泵模式", description="获取水泵对象的模式定义,包含所有可用字段及其类型")
|
||||
async def fastapi_get_pump_schema(
|
||||
def fastapi_get_pump_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
@@ -28,7 +29,7 @@ async def fastapi_get_pump_schema(
|
||||
return get_pump_schema(network)
|
||||
|
||||
@router.post("/pumps", response_model=None, summary="添加水泵", description="向网络中添加新的水泵,需要提供水泵的基本参数如功率等")
|
||||
async def fastapi_add_pump(
|
||||
def fastapi_add_pump(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵标识符"),
|
||||
node1: str = Query(..., description="水泵起始节点ID"),
|
||||
@@ -52,7 +53,7 @@ async def fastapi_add_pump(
|
||||
return add_pump(network, ChangeSet(ps))
|
||||
|
||||
@router.delete("/pumps", response_model=None, summary="删除水泵", description="从网络中删除指定的水泵")
|
||||
async def fastapi_delete_pump(
|
||||
def fastapi_delete_pump(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="要删除的水泵ID")
|
||||
) -> ChangeSet:
|
||||
@@ -70,7 +71,7 @@ async def fastapi_delete_pump(
|
||||
return delete_pump(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/pumps/node1", summary="获取水泵起始节点", description="获取指定水泵的起始节点ID")
|
||||
async def fastapi_get_pump_node1(
|
||||
def fastapi_get_pump_node1(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵ID")
|
||||
) -> str | None:
|
||||
@@ -88,7 +89,7 @@ async def fastapi_get_pump_node1(
|
||||
return ps["node1"]
|
||||
|
||||
@router.get("/pumps/node2", summary="获取水泵终止节点", description="获取指定水泵的终止节点ID")
|
||||
async def fastapi_get_pump_node2(
|
||||
def fastapi_get_pump_node2(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵ID")
|
||||
) -> str | None:
|
||||
@@ -106,7 +107,7 @@ async def fastapi_get_pump_node2(
|
||||
return ps["node2"]
|
||||
|
||||
@router.patch("/pumps/node1", response_model=None, summary="设置水泵起始节点", description="设置指定水泵的起始节点")
|
||||
async def fastapi_set_pump_node1(
|
||||
def fastapi_set_pump_node1(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵ID"),
|
||||
node1: str = Query(..., description="新的起始节点ID")
|
||||
@@ -126,7 +127,7 @@ async def fastapi_set_pump_node1(
|
||||
return set_pump(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/pumps/node2", response_model=None, summary="设置水泵终止节点", description="设置指定水泵的终止节点")
|
||||
async def fastapi_set_pump_node2(
|
||||
def fastapi_set_pump_node2(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵ID"),
|
||||
node2: str = Query(..., description="新的终止节点ID")
|
||||
@@ -146,7 +147,7 @@ async def fastapi_set_pump_node2(
|
||||
return set_pump(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/pumps/properties", summary="获取水泵属性", description="获取指定水泵的所有属性信息")
|
||||
async def fastapi_get_pump_properties(
|
||||
def fastapi_get_pump_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -163,7 +164,7 @@ async def fastapi_get_pump_properties(
|
||||
return get_pump(network, pump)
|
||||
|
||||
@router.get("/pumps", summary="获取所有水泵属性", description="获取网络中所有水泵的属性信息列表")
|
||||
async def fastapi_get_all_pump_properties(
|
||||
def fastapi_get_all_pump_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
@@ -180,10 +181,10 @@ async def fastapi_get_all_pump_properties(
|
||||
return results
|
||||
|
||||
@router.patch("/pumps/properties", response_model=None, summary="设置水泵属性", description="批量设置指定水泵的多个属性")
|
||||
async def fastapi_set_pump_properties(
|
||||
def fastapi_set_pump_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
pump: str = Query(..., description="水泵ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
批量设置水泵属性。
|
||||
@@ -196,6 +197,6 @@ async def fastapi_set_pump_properties(
|
||||
Returns:
|
||||
ChangeSet对象,包含本次修改的变更信息
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": pump} | props
|
||||
return set_pump(network, ChangeSet(ps))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Query, Request
|
||||
from fastapi import APIRouter, Body, Query
|
||||
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
@@ -18,21 +18,21 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/network-schemas/region", summary="获取区域属性架构")
|
||||
async def get_region_schema_endpoint(
|
||||
def get_region_schema_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
return get_region_schema(network)
|
||||
|
||||
|
||||
@router.get("/regions", summary="获取区域列表")
|
||||
async def get_regions_endpoint(
|
||||
def get_regions_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
) -> list[dict[str, Any]]:
|
||||
return [get_region(network, region_id) for region_id in get_regions(network)]
|
||||
|
||||
|
||||
@router.get("/regions/detail", summary="获取区域信息")
|
||||
async def get_region_endpoint(
|
||||
def get_region_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
id: str = Query(..., description="区域 ID"),
|
||||
) -> dict[str, Any]:
|
||||
@@ -40,7 +40,7 @@ async def get_region_endpoint(
|
||||
|
||||
|
||||
@router.get("/regions/nodes", summary="获取区域节点")
|
||||
async def get_region_nodes_endpoint(
|
||||
def get_region_nodes_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
id: str = Query(..., description="区域 ID"),
|
||||
) -> list[str]:
|
||||
@@ -48,26 +48,25 @@ async def get_region_nodes_endpoint(
|
||||
|
||||
|
||||
@router.patch("/regions", summary="修改区域", response_model=None)
|
||||
async def set_region_endpoint(
|
||||
def set_region_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
request: Request = None,
|
||||
payload: dict[str, Any] = Body(...),
|
||||
) -> ChangeSet:
|
||||
return set_region(network, ChangeSet(await request.json()))
|
||||
return set_region(network, ChangeSet(payload))
|
||||
|
||||
|
||||
@router.post("/regions", summary="添加区域", response_model=None)
|
||||
async def add_region_endpoint(
|
||||
def add_region_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
request: Request = None,
|
||||
payload: dict[str, Any] = Body(...),
|
||||
) -> ChangeSet:
|
||||
payload = await request.json()
|
||||
payload["boundary"] = [tuple(point[:2]) for point in payload.get("boundary", [])]
|
||||
return add_region(network, ChangeSet(payload))
|
||||
|
||||
|
||||
@router.delete("/regions", summary="删除区域", response_model=None)
|
||||
async def delete_region_endpoint(
|
||||
def delete_region_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
request: Request = None,
|
||||
payload: dict[str, Any] = Body(...),
|
||||
) -> ChangeSet:
|
||||
return delete_region(network, ChangeSet(await request.json()))
|
||||
return delete_region(network, ChangeSet(payload))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_reservoir,
|
||||
@@ -17,7 +18,7 @@ router = APIRouter()
|
||||
summary="获取水库模式",
|
||||
description="获取指定供水网络中所有水库的模式/属性字段定义"
|
||||
)
|
||||
async def fast_get_reservoir_schema(
|
||||
def fast_get_reservoir_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
@@ -39,7 +40,7 @@ async def fast_get_reservoir_schema(
|
||||
summary="添加水库",
|
||||
description="在指定供水网络中添加新的水库/水源节点"
|
||||
)
|
||||
async def fastapi_add_reservoir(
|
||||
def fastapi_add_reservoir(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
x: float = Query(..., description="水库的X坐标"),
|
||||
@@ -70,7 +71,7 @@ async def fastapi_add_reservoir(
|
||||
summary="删除水库",
|
||||
description="从指定供水网络中删除指定的水库/水源节点"
|
||||
)
|
||||
async def fastapi_delete_reservoir(
|
||||
def fastapi_delete_reservoir(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="要删除的水库的唯一标识符")
|
||||
) -> ChangeSet:
|
||||
@@ -94,7 +95,7 @@ async def fastapi_delete_reservoir(
|
||||
summary="获取水库水头",
|
||||
description="获取指定水库的供水水头/总水头值"
|
||||
)
|
||||
async def fastapi_get_reservoir_head(
|
||||
def fastapi_get_reservoir_head(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符")
|
||||
) -> float | None:
|
||||
@@ -118,7 +119,7 @@ async def fastapi_get_reservoir_head(
|
||||
summary="获取水库模式",
|
||||
description="获取指定水库的运行模式/供水模式"
|
||||
)
|
||||
async def fastapi_get_reservoir_pattern(
|
||||
def fastapi_get_reservoir_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符")
|
||||
) -> str | None:
|
||||
@@ -142,7 +143,7 @@ async def fastapi_get_reservoir_pattern(
|
||||
summary="获取水库X坐标",
|
||||
description="获取指定水库的X坐标位置"
|
||||
)
|
||||
async def fastapi_get_reservoir_x(
|
||||
def fastapi_get_reservoir_x(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符")
|
||||
) -> dict[str, float] | None:
|
||||
@@ -166,7 +167,7 @@ async def fastapi_get_reservoir_x(
|
||||
summary="获取水库Y坐标",
|
||||
description="获取指定水库的Y坐标位置"
|
||||
)
|
||||
async def fastapi_get_reservoir_y(
|
||||
def fastapi_get_reservoir_y(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符")
|
||||
) -> dict[str, float] | None:
|
||||
@@ -190,7 +191,7 @@ async def fastapi_get_reservoir_y(
|
||||
summary="获取水库坐标",
|
||||
description="获取指定水库的平面坐标(X和Y坐标)"
|
||||
)
|
||||
async def fastapi_get_reservoir_coord(
|
||||
def fastapi_get_reservoir_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符")
|
||||
) -> dict[str, float] | None:
|
||||
@@ -216,7 +217,7 @@ async def fastapi_get_reservoir_coord(
|
||||
summary="设置水库水头",
|
||||
description="更新指定水库的供水水头/总水头值"
|
||||
)
|
||||
async def fastapi_set_reservoir_head(
|
||||
def fastapi_set_reservoir_head(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
head: float = Query(..., description="新的水头值(米)")
|
||||
@@ -243,7 +244,7 @@ async def fastapi_set_reservoir_head(
|
||||
summary="设置水库模式",
|
||||
description="更新指定水库的运行模式/供水模式"
|
||||
)
|
||||
async def fastapi_set_reservoir_pattern(
|
||||
def fastapi_set_reservoir_pattern(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
pattern: str = Query(..., description="新的运行模式")
|
||||
@@ -270,7 +271,7 @@ async def fastapi_set_reservoir_pattern(
|
||||
summary="设置水库X坐标",
|
||||
description="更新指定水库的X坐标位置"
|
||||
)
|
||||
async def fastapi_set_reservoir_x(
|
||||
def fastapi_set_reservoir_x(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
x: float = Query(..., description="新的X坐标值")
|
||||
@@ -297,7 +298,7 @@ async def fastapi_set_reservoir_x(
|
||||
summary="设置水库Y坐标",
|
||||
description="更新指定水库的Y坐标位置"
|
||||
)
|
||||
async def fastapi_set_reservoir_y(
|
||||
def fastapi_set_reservoir_y(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
y: float = Query(..., description="新的Y坐标值")
|
||||
@@ -324,7 +325,7 @@ async def fastapi_set_reservoir_y(
|
||||
summary="设置水库坐标",
|
||||
description="更新指定水库的平面坐标(X和Y坐标)"
|
||||
)
|
||||
async def fastapi_set_reservoir_coord(
|
||||
def fastapi_set_reservoir_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
x: float = Query(..., description="新的X坐标值"),
|
||||
@@ -352,7 +353,7 @@ async def fastapi_set_reservoir_coord(
|
||||
summary="获取水库属性",
|
||||
description="获取指定水库的所有属性"
|
||||
)
|
||||
async def fastapi_get_reservoir_properties(
|
||||
def fastapi_get_reservoir_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符")
|
||||
) -> dict[str, Any]:
|
||||
@@ -375,7 +376,7 @@ async def fastapi_get_reservoir_properties(
|
||||
summary="获取所有水库属性",
|
||||
description="获取指定供水网络中所有水库的属性"
|
||||
)
|
||||
async def fastapi_get_all_reservoir_properties(
|
||||
def fastapi_get_all_reservoir_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
@@ -398,10 +399,10 @@ async def fastapi_get_all_reservoir_properties(
|
||||
summary="设置水库属性",
|
||||
description="批量更新指定水库的多个属性"
|
||||
)
|
||||
async def fastapi_set_reservoir_properties(
|
||||
def fastapi_set_reservoir_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
reservoir: str = Query(..., description="水库的唯一标识符"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
设置水库的多个属性。
|
||||
@@ -416,6 +417,6 @@ async def fastapi_set_reservoir_properties(
|
||||
Returns:
|
||||
包含操作变更集的ChangeSet对象
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": reservoir} | props
|
||||
return set_reservoir(network, ChangeSet(ps))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
get_tag,
|
||||
@@ -19,7 +20,7 @@ router = APIRouter()
|
||||
summary="获取标签属性架构",
|
||||
description="获取指定水网的标签(Tag)属性架构定义"
|
||||
)
|
||||
async def fastapi_get_tag_schema(
|
||||
def fastapi_get_tag_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""获取标签的属性架构。"""
|
||||
@@ -30,7 +31,7 @@ async def fastapi_get_tag_schema(
|
||||
summary="获取标签信息",
|
||||
description="获取指定类型和ID的标签信息"
|
||||
)
|
||||
async def fastapi_get_tag(
|
||||
def fastapi_get_tag(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
t_type: str = Query(..., description="标签类型"),
|
||||
id: str = Query(..., description="元素ID")
|
||||
@@ -43,7 +44,7 @@ async def fastapi_get_tag(
|
||||
summary="获取所有标签",
|
||||
description="获取指定水网中的所有标签信息"
|
||||
)
|
||||
async def fastapi_get_tags(
|
||||
def fastapi_get_tags(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""获取水网中所有标签的列表。"""
|
||||
@@ -56,10 +57,10 @@ async def fastapi_get_tags(
|
||||
summary="设置标签",
|
||||
description="为指定元素设置或修改标签信息"
|
||||
)
|
||||
async def fastapi_set_tag(
|
||||
def fastapi_set_tag(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""设置标签信息。"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
return set_tag(network, ChangeSet(props))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
add_tank,
|
||||
@@ -13,7 +14,7 @@ from app.services.tjnetwork import (
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/network-schemas/tank", summary="获取水箱模式", description="获取指定网络的水箱数据结构模式定义")
|
||||
async def fast_get_tank_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
def fast_get_tank_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
获取水箱的数据结构模式。
|
||||
|
||||
@@ -26,7 +27,7 @@ async def fast_get_tank_schema(network: str = Query(..., description="管网名
|
||||
return get_tank_schema(network)
|
||||
|
||||
@router.post("/tanks", summary="新增水箱", description="向指定网络中新增一个水箱", response_model=None)
|
||||
async def fastapi_add_tank(
|
||||
def fastapi_add_tank(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
x: float = Query(..., description="X坐标"),
|
||||
@@ -70,7 +71,7 @@ async def fastapi_add_tank(
|
||||
return add_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.delete("/tanks", summary="删除水箱", description="删除指定网络中的水箱", response_model=None)
|
||||
async def fastapi_delete_tank(
|
||||
def fastapi_delete_tank(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> ChangeSet:
|
||||
@@ -88,7 +89,7 @@ async def fastapi_delete_tank(
|
||||
return delete_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/tanks/elevation", summary="获取水箱标高", description="获取指定水箱的标高值")
|
||||
async def fastapi_get_tank_elevation(
|
||||
def fastapi_get_tank_elevation(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float | None:
|
||||
@@ -106,7 +107,7 @@ async def fastapi_get_tank_elevation(
|
||||
return ps["elevation"]
|
||||
|
||||
@router.get("/tanks/init-level", summary="获取水箱初始水位", description="获取指定水箱的初始水位值")
|
||||
async def fastapi_get_tank_init_level(
|
||||
def fastapi_get_tank_init_level(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float | None:
|
||||
@@ -124,7 +125,7 @@ async def fastapi_get_tank_init_level(
|
||||
return ps["init_level"]
|
||||
|
||||
@router.get("/tanks/min-level", summary="获取水箱最小水位", description="获取指定水箱的最小水位值")
|
||||
async def fastapi_get_tank_min_level(
|
||||
def fastapi_get_tank_min_level(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float | None:
|
||||
@@ -142,7 +143,7 @@ async def fastapi_get_tank_min_level(
|
||||
return ps["min_level"]
|
||||
|
||||
@router.get("/tanks/max-level", summary="获取水箱最大水位", description="获取指定水箱的最大水位值")
|
||||
async def fastapi_get_tank_max_level(
|
||||
def fastapi_get_tank_max_level(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float | None:
|
||||
@@ -160,7 +161,7 @@ async def fastapi_get_tank_max_level(
|
||||
return ps["max_level"]
|
||||
|
||||
@router.get("/tanks/diameter", summary="获取水箱直径", description="获取指定水箱的直径值")
|
||||
async def fastapi_get_tank_diameter(
|
||||
def fastapi_get_tank_diameter(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float | None:
|
||||
@@ -178,7 +179,7 @@ async def fastapi_get_tank_diameter(
|
||||
return ps["diameter"]
|
||||
|
||||
@router.get("/tanks/min-vol", summary="获取水箱最小体积", description="获取指定水箱的最小体积值")
|
||||
async def fastapi_get_tank_min_vol(
|
||||
def fastapi_get_tank_min_vol(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float | None:
|
||||
@@ -196,7 +197,7 @@ async def fastapi_get_tank_min_vol(
|
||||
return ps["min_vol"]
|
||||
|
||||
@router.get("/tanks/vol-curve", summary="获取水箱容积曲线", description="获取指定水箱的容积曲线标识")
|
||||
async def fastapi_get_tank_vol_curve(
|
||||
def fastapi_get_tank_vol_curve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> str | None:
|
||||
@@ -214,7 +215,7 @@ async def fastapi_get_tank_vol_curve(
|
||||
return ps["vol_curve"]
|
||||
|
||||
@router.get("/tanks/overflow", summary="获取水箱溢流口", description="获取指定水箱的溢流口配置")
|
||||
async def fastapi_get_tank_overflow(
|
||||
def fastapi_get_tank_overflow(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> str | None:
|
||||
@@ -232,7 +233,7 @@ async def fastapi_get_tank_overflow(
|
||||
return ps["overflow"]
|
||||
|
||||
@router.get("/tanks/x", summary="获取水箱X坐标", description="获取指定水箱的X坐标值")
|
||||
async def fastapi_get_tank_x(
|
||||
def fastapi_get_tank_x(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float:
|
||||
@@ -250,7 +251,7 @@ async def fastapi_get_tank_x(
|
||||
return ps["x"]
|
||||
|
||||
@router.get("/tanks/y", summary="获取水箱Y坐标", description="获取指定水箱的Y坐标值")
|
||||
async def fastapi_get_tank_y(
|
||||
def fastapi_get_tank_y(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> float:
|
||||
@@ -268,7 +269,7 @@ async def fastapi_get_tank_y(
|
||||
return ps["y"]
|
||||
|
||||
@router.get("/tanks/coord", summary="获取水箱坐标", description="获取指定水箱的X和Y坐标")
|
||||
async def fastapi_get_tank_coord(
|
||||
def fastapi_get_tank_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> dict[str, float]:
|
||||
@@ -287,7 +288,7 @@ async def fastapi_get_tank_coord(
|
||||
return coord
|
||||
|
||||
@router.patch("/tanks/elevation", summary="设置水箱标高", description="设置指定水箱的标高值", response_model=None)
|
||||
async def fastapi_set_tank_elevation(
|
||||
def fastapi_set_tank_elevation(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
elevation: float = Query(..., description="新的标高值")
|
||||
@@ -307,7 +308,7 @@ async def fastapi_set_tank_elevation(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/init-level", summary="设置水箱初始水位", description="设置指定水箱的初始水位值", response_model=None)
|
||||
async def fastapi_set_tank_init_level(
|
||||
def fastapi_set_tank_init_level(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
init_level: float = Query(..., description="新的初始水位值")
|
||||
@@ -327,7 +328,7 @@ async def fastapi_set_tank_init_level(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/min-level", summary="设置水箱最小水位", description="设置指定水箱的最小水位值", response_model=None)
|
||||
async def fastapi_set_tank_min_level(
|
||||
def fastapi_set_tank_min_level(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
min_level: float = Query(..., description="新的最小水位值")
|
||||
@@ -347,7 +348,7 @@ async def fastapi_set_tank_min_level(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/max-level", summary="设置水箱最大水位", description="设置指定水箱的最大水位值", response_model=None)
|
||||
async def fastapi_set_tank_max_level(
|
||||
def fastapi_set_tank_max_level(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
max_level: float = Query(..., description="新的最大水位值")
|
||||
@@ -367,7 +368,7 @@ async def fastapi_set_tank_max_level(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/diameter", summary="设置水箱直径", description="设置指定水箱的直径值", response_model=None)
|
||||
async def fastapi_set_tank_diameter(
|
||||
def fastapi_set_tank_diameter(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
diameter: float = Query(..., description="新的直径值")
|
||||
@@ -387,7 +388,7 @@ async def fastapi_set_tank_diameter(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/min-vol", summary="设置水箱最小体积", description="设置指定水箱的最小体积值", response_model=None)
|
||||
async def fastapi_set_tank_min_vol(
|
||||
def fastapi_set_tank_min_vol(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
min_vol: float = Query(..., description="新的最小体积值")
|
||||
@@ -407,7 +408,7 @@ async def fastapi_set_tank_min_vol(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/vol-curve", summary="设置水箱容积曲线", description="设置指定水箱的容积曲线标识", response_model=None)
|
||||
async def fastapi_set_tank_vol_curve(
|
||||
def fastapi_set_tank_vol_curve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
vol_curve: str = Query(..., description="新的容积曲线标识")
|
||||
@@ -427,7 +428,7 @@ async def fastapi_set_tank_vol_curve(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/overflow", summary="设置水箱溢流口", description="设置指定水箱的溢流口配置", response_model=None)
|
||||
async def fastapi_set_tank_overflow(
|
||||
def fastapi_set_tank_overflow(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
overflow: str = Query(..., description="新的溢流口配置")
|
||||
@@ -447,7 +448,7 @@ async def fastapi_set_tank_overflow(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/x", summary="设置水箱X坐标", description="设置指定水箱的X坐标值", response_model=None)
|
||||
async def fastapi_set_tank_x(
|
||||
def fastapi_set_tank_x(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
x: float = Query(..., description="新的X坐标值")
|
||||
@@ -467,7 +468,7 @@ async def fastapi_set_tank_x(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/y", summary="设置水箱Y坐标", description="设置指定水箱的Y坐标值", response_model=None)
|
||||
async def fastapi_set_tank_y(
|
||||
def fastapi_set_tank_y(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
y: float = Query(..., description="新的Y坐标值")
|
||||
@@ -487,7 +488,7 @@ async def fastapi_set_tank_y(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.patch("/tanks/coord", summary="设置水箱坐标", description="设置指定水箱的X和Y坐标", response_model=None)
|
||||
async def fastapi_set_tank_coord(
|
||||
def fastapi_set_tank_coord(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
x: float = Query(..., description="新的X坐标值"),
|
||||
@@ -509,7 +510,7 @@ async def fastapi_set_tank_coord(
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@router.get("/tanks/properties", summary="获取水箱属性", description="获取指定水箱的所有属性")
|
||||
async def fastapi_get_tank_properties(
|
||||
def fastapi_get_tank_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID")
|
||||
) -> dict[str, Any]:
|
||||
@@ -526,7 +527,7 @@ async def fastapi_get_tank_properties(
|
||||
return get_tank(network, tank)
|
||||
|
||||
@router.get("/tanks", summary="获取所有水箱属性", description="获取指定网络中所有水箱的属性")
|
||||
async def fastapi_get_all_tank_properties(
|
||||
def fastapi_get_all_tank_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
@@ -543,10 +544,10 @@ async def fastapi_get_all_tank_properties(
|
||||
return results
|
||||
|
||||
@router.patch("/tanks/properties", summary="设置水箱属性", description="批量设置指定水箱的多个属性", response_model=None)
|
||||
async def fastapi_set_tank_properties(
|
||||
def fastapi_set_tank_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
tank: str = Query(..., description="水箱ID"),
|
||||
req: Request = None
|
||||
payload: dict[str, Any] = Body(...)
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
批量设置水箱的属性。
|
||||
@@ -559,6 +560,6 @@ async def fastapi_set_tank_properties(
|
||||
Returns:
|
||||
包含变更信息的ChangeSet对象
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": tank} | props
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Request, Query, Path, Body
|
||||
from typing import Any, List, Dict, Union
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Body, Query
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
VALVES_TYPE_PRV,
|
||||
@@ -18,7 +19,7 @@ router = APIRouter()
|
||||
summary="获取阀门架构",
|
||||
description="获取指定水网中所有阀门的架构和字段定义",
|
||||
)
|
||||
async def fastapi_get_valve_schema(
|
||||
def fastapi_get_valve_schema(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
@@ -34,7 +35,7 @@ async def fastapi_get_valve_schema(
|
||||
summary="添加阀门",
|
||||
description="在指定的水网中添加新的阀门",
|
||||
)
|
||||
async def fastapi_add_valve(
|
||||
def fastapi_add_valve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
node1: str = Query(..., description="起点节点ID"),
|
||||
@@ -67,7 +68,7 @@ async def fastapi_add_valve(
|
||||
summary="删除阀门",
|
||||
description="从指定的水网中删除指定的阀门",
|
||||
)
|
||||
async def fastapi_delete_valve(
|
||||
def fastapi_delete_valve(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> ChangeSet:
|
||||
@@ -84,7 +85,7 @@ async def fastapi_delete_valve(
|
||||
summary="获取阀门起点节点",
|
||||
description="获取指定阀门连接的起点节点ID",
|
||||
)
|
||||
async def fastapi_get_valve_node1(
|
||||
def fastapi_get_valve_node1(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> str | None:
|
||||
@@ -101,7 +102,7 @@ async def fastapi_get_valve_node1(
|
||||
summary="获取阀门终点节点",
|
||||
description="获取指定阀门连接的终点节点ID",
|
||||
)
|
||||
async def fastapi_get_valve_node2(
|
||||
def fastapi_get_valve_node2(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> str | None:
|
||||
@@ -118,7 +119,7 @@ async def fastapi_get_valve_node2(
|
||||
summary="获取阀门直径",
|
||||
description="获取指定阀门的直径",
|
||||
)
|
||||
async def fastapi_get_valve_diameter(
|
||||
def fastapi_get_valve_diameter(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> float | None:
|
||||
@@ -135,7 +136,7 @@ async def fastapi_get_valve_diameter(
|
||||
summary="获取阀门类型",
|
||||
description="获取指定阀门的类型",
|
||||
)
|
||||
async def fastapi_get_valve_type(
|
||||
def fastapi_get_valve_type(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> str | None:
|
||||
@@ -152,7 +153,7 @@ async def fastapi_get_valve_type(
|
||||
summary="获取阀门开度",
|
||||
description="获取指定阀门的开度/设置值",
|
||||
)
|
||||
async def fastapi_get_valve_setting(
|
||||
def fastapi_get_valve_setting(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> float | None:
|
||||
@@ -169,7 +170,7 @@ async def fastapi_get_valve_setting(
|
||||
summary="获取阀门损失系数",
|
||||
description="获取指定阀门的损失系数",
|
||||
)
|
||||
async def fastapi_get_valve_minor_loss(
|
||||
def fastapi_get_valve_minor_loss(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> float | None:
|
||||
@@ -187,7 +188,7 @@ async def fastapi_get_valve_minor_loss(
|
||||
summary="设置阀门起点节点",
|
||||
description="设置指定阀门的起点节点",
|
||||
)
|
||||
async def fastapi_set_valve_node1(
|
||||
def fastapi_set_valve_node1(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
node1: str = Query(..., description="新的起点节点ID"),
|
||||
@@ -206,7 +207,7 @@ async def fastapi_set_valve_node1(
|
||||
summary="设置阀门终点节点",
|
||||
description="设置指定阀门的终点节点",
|
||||
)
|
||||
async def fastapi_set_valve_node2(
|
||||
def fastapi_set_valve_node2(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
node2: str = Query(..., description="新的终点节点ID"),
|
||||
@@ -225,7 +226,7 @@ async def fastapi_set_valve_node2(
|
||||
summary="设置阀门直径",
|
||||
description="设置指定阀门的直径",
|
||||
)
|
||||
async def fastapi_set_valve_diameter(
|
||||
def fastapi_set_valve_diameter(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
diameter: float = Query(..., description="新的直径值(mm)"),
|
||||
@@ -244,7 +245,7 @@ async def fastapi_set_valve_diameter(
|
||||
summary="设置阀门类型",
|
||||
description="设置指定阀门的类型",
|
||||
)
|
||||
async def fastapi_set_valve_type(
|
||||
def fastapi_set_valve_type(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
type: str = Query(..., description="新的阀门类型"),
|
||||
@@ -263,7 +264,7 @@ async def fastapi_set_valve_type(
|
||||
summary="设置阀门开度",
|
||||
description="设置指定阀门的开度/设置值",
|
||||
)
|
||||
async def fastapi_set_valve_setting(
|
||||
def fastapi_set_valve_setting(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
setting: float = Query(..., description="新的开度值"),
|
||||
@@ -281,7 +282,7 @@ async def fastapi_set_valve_setting(
|
||||
summary="获取阀门所有属性",
|
||||
description="获取指定阀门的所有属性",
|
||||
)
|
||||
async def fastapi_get_valve_properties(
|
||||
def fastapi_get_valve_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
) -> dict[str, Any]:
|
||||
@@ -297,7 +298,7 @@ async def fastapi_get_valve_properties(
|
||||
summary="获取所有阀门属性",
|
||||
description="获取指定水网中所有阀门的属性",
|
||||
)
|
||||
async def fastapi_get_all_valve_properties(
|
||||
def fastapi_get_all_valve_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
@@ -315,16 +316,16 @@ async def fastapi_get_all_valve_properties(
|
||||
summary="批量设置阀门属性",
|
||||
description="批量设置指定阀门的多个属性",
|
||||
)
|
||||
async def fastapi_set_valve_properties(
|
||||
def fastapi_set_valve_properties(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
valve: str = Query(..., description="阀门ID"),
|
||||
req: Request = None,
|
||||
payload: dict[str, Any] = Body(...),
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
批量设置阀门的属性。
|
||||
|
||||
更新指定阀门的一个或多个属性,通过JSON请求体传递要更新的属性。
|
||||
"""
|
||||
props = await req.json()
|
||||
props = payload
|
||||
ps = {"id": valve} | props
|
||||
return set_valve(network, ChangeSet(ps))
|
||||
|
||||
@@ -1,43 +1,18 @@
|
||||
import json
|
||||
from fastapi import APIRouter, Request, HTTPException, Query, Path, Depends
|
||||
from fastapi.responses import PlainTextResponse
|
||||
from typing import Any, Dict, List
|
||||
from fastapi import APIRouter, HTTPException, Query, Depends
|
||||
from app.infra.db.metadb.repositories.metadata_repository import MetadataRepository
|
||||
from app.auth.project_dependencies import get_metadata_repository
|
||||
from app.auth.permissions import (
|
||||
ENVIRONMENT_MANAGE,
|
||||
require_permission,
|
||||
from app.auth.project_dependencies import (
|
||||
get_metadata_repository,
|
||||
)
|
||||
from app.domain.schemas.metadata import ProjectMetaResponse
|
||||
import app.services.project_info as project_info
|
||||
from app.services.tjnetwork import (
|
||||
ChangeSet,
|
||||
list_project,
|
||||
have_project,
|
||||
create_project,
|
||||
delete_project,
|
||||
is_project_open,
|
||||
open_project,
|
||||
close_project,
|
||||
copy_project,
|
||||
export_inp,
|
||||
read_inp,
|
||||
dump_inp,
|
||||
get_all_vertices,
|
||||
get_all_scada_info,
|
||||
convert_inp_v3_to_v2,
|
||||
)
|
||||
|
||||
# For inp file upload/download
|
||||
import os
|
||||
from fastapi import Response, status
|
||||
from fastapi.responses import FileResponse
|
||||
inpDir = "data/" # Assuming data directory exists or is defined somewhere.
|
||||
# In main.py it was likely global. For safety, let's use a relative path or get from config.
|
||||
# But let's stick to what main.py probably used or a default.
|
||||
|
||||
router = APIRouter()
|
||||
lockedPrjs: Dict[str, str] = {}
|
||||
|
||||
@router.get("/projects/current", summary="获取项目信息", description="从数据库获取项目的详细信息,包括地图范围等。", response_model=ProjectMetaResponse)
|
||||
async def get_project_info_endpoint(
|
||||
@@ -63,105 +38,8 @@ async def get_project_info_endpoint(
|
||||
project_role="viewer", # Default role for public access
|
||||
)
|
||||
|
||||
@router.get("/project-codes", summary="获取项目列表", description="获取服务器上所有可用的供水管网项目名称列表。")
|
||||
async def list_projects_endpoint() -> list[str]:
|
||||
"""
|
||||
获取项目列表
|
||||
|
||||
返回所有已创建项目的名称列表。
|
||||
"""
|
||||
return list_project()
|
||||
|
||||
@router.get("/projects/existence", summary="检查项目是否存在", description="检查指定名称的项目是否存在。")
|
||||
async def have_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
):
|
||||
"""
|
||||
检查项目是否存在
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
return have_project(network)
|
||||
|
||||
@router.post("/projects", summary="创建新项目", description="创建一个新的供水管网项目。如果项目已存在,可能会覆盖或报错(取决于底层实现)。")
|
||||
async def create_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
_=Depends(require_permission(ENVIRONMENT_MANAGE)),
|
||||
):
|
||||
"""
|
||||
创建新项目
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
create_project(network)
|
||||
return network
|
||||
|
||||
@router.delete("/projects", summary="删除项目", description="永久删除指定的供水管网项目。此操作不可恢复。")
|
||||
async def delete_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
_=Depends(require_permission(ENVIRONMENT_MANAGE)),
|
||||
):
|
||||
"""
|
||||
删除项目
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
delete_project(network)
|
||||
return True
|
||||
|
||||
@router.get("/projects/current/status", summary="检查项目是否已打开", description="检查指定项目是否已被加载到内存中。")
|
||||
async def is_project_open_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
):
|
||||
"""
|
||||
检查项目是否已打开
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
return is_project_open(network)
|
||||
|
||||
@router.post("/projects/current", summary="打开项目", description="将指定项目加载到内存中,并初始化数据库连接池。")
|
||||
async def open_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
):
|
||||
"""
|
||||
打开项目
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
open_project(network)
|
||||
|
||||
return network
|
||||
|
||||
@router.delete("/projects/current", summary="关闭项目", description="将指定项目从内存中卸载,释放资源。")
|
||||
async def close_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)")
|
||||
):
|
||||
"""
|
||||
关闭项目
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
close_project(network)
|
||||
return True
|
||||
|
||||
@router.post("/project-copies", summary="复制项目", description="将现有项目复制为新项目。")
|
||||
async def copy_project_endpoint(
|
||||
source: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
target: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
_=Depends(require_permission(ENVIRONMENT_MANAGE)),
|
||||
):
|
||||
"""
|
||||
复制项目
|
||||
|
||||
- **source**: 管网名称(或数据库名称)
|
||||
- **target**: 管网名称(或数据库名称)
|
||||
"""
|
||||
copy_project(source, target)
|
||||
return True
|
||||
|
||||
@router.get("/projects/current/exports/change-set", response_model=None, summary="导出项目为 ChangeSet", description="导出项目的变更集 (ChangeSet),包含顶点、SCADA 元素、DMA、SA、VD 等信息。")
|
||||
async def export_inp_endpoint(
|
||||
def export_inp_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
version: str = Query(..., description="版本号 (通常用于增量更新)")
|
||||
) -> ChangeSet:
|
||||
@@ -173,279 +51,7 @@ async def export_inp_endpoint(
|
||||
"""
|
||||
cs = export_inp(network, version)
|
||||
op = cs.operations[0]
|
||||
open_project(network)
|
||||
op["vertex"] = json.dumps(get_all_vertices(network))
|
||||
op["scada"] = json.dumps(get_all_scada_info(network))
|
||||
|
||||
close_project(network)
|
||||
|
||||
return cs
|
||||
@router.post("/projects/current/imports", summary="读取 INP 文件到项目", description="从服务器文件系统中读取指定的 INP 文件并加载到项目中。")
|
||||
async def read_inp_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
inp: str = Query(..., description="INP 文件名 (不包含路径)")
|
||||
) -> bool:
|
||||
"""
|
||||
读取 INP 文件到项目
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
- **inp**: INP 文件名
|
||||
"""
|
||||
read_inp(network, inp)
|
||||
return True
|
||||
|
||||
@router.post("/projects/current/exports/inp", summary="导出项目到 INP 文件", description="将项目当前状态保存为 INP 文件到服务器文件系统。")
|
||||
async def dump_inp_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
inp: str = Query(..., description="目标文件名")
|
||||
) -> bool:
|
||||
"""
|
||||
导出项目到 INP 文件
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
- **inp**: 目标文件名
|
||||
"""
|
||||
dump_inp(network, inp)
|
||||
return True
|
||||
|
||||
@router.get("/projects/current/lock", summary="检查项目是否被锁定", description="检查指定项目是否处于锁定状态。")
|
||||
async def is_project_locked_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
检查项目是否被锁定
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
return network in lockedPrjs.keys()
|
||||
|
||||
@router.get("/projects/current/lock/ownership", summary="检查项目是否被当前用户锁定", description="检查指定项目是否被当前访问地址 (IP) 锁定。")
|
||||
async def is_project_locked_by_me_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
检查项目是否被当前用户锁定
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
client_host = req.client.host
|
||||
return lockedPrjs.get(network) == client_host
|
||||
|
||||
# 0 successfully locked
|
||||
# 1 already locked by you
|
||||
# 2 locked by others
|
||||
@router.post("/projects/current/lock", summary="锁定项目", description="锁定指定项目以防止并发修改。")
|
||||
async def lock_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
锁定项目
|
||||
|
||||
返回值:
|
||||
- **0**: 锁定成功
|
||||
- **1**: 已被当前用户锁定
|
||||
- **2**: 已被其他用户锁定
|
||||
"""
|
||||
client_host = req.client.host
|
||||
if not network in lockedPrjs.keys():
|
||||
lockedPrjs[network] = client_host
|
||||
return 0
|
||||
else:
|
||||
if lockedPrjs.get(network) == client_host:
|
||||
return 1
|
||||
else:
|
||||
return 2
|
||||
|
||||
@router.delete("/projects/current/lock", summary="解锁项目", description="释放对项目的锁定。")
|
||||
def unlock_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
解锁项目
|
||||
|
||||
只有锁定者才能解锁。
|
||||
"""
|
||||
client_host = req.client.host
|
||||
if lockedPrjs.get(network) == client_host:
|
||||
print("delete key")
|
||||
del lockedPrjs[network]
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@router.get("/projects/current/files/inp", status_code=status.HTTP_200_OK, summary="下载 INP 文件", description="从服务器数据目录下载指定的 INP 文件。")
|
||||
async def fastapi_download_inp(
|
||||
name: str = Query(..., description="文件名"),
|
||||
response: Response = None
|
||||
):
|
||||
"""
|
||||
下载 INP 文件
|
||||
|
||||
- **name**: 文件名
|
||||
"""
|
||||
filePath = inpDir + name
|
||||
if os.path.exists(filePath):
|
||||
return FileResponse(
|
||||
filePath, media_type="application/octet-stream", filename="inp.inp"
|
||||
)
|
||||
else:
|
||||
response.status_code = status.HTTP_400_BAD_REQUEST
|
||||
return True
|
||||
|
||||
# DingZQ, 2024-12-28, convert v3 to v2
|
||||
@router.post("/project-conversions", response_model=None, summary="转换 INP V3 为 V2", description="将 EPANET 3.0 格式的 INP 内容转换为 2.x 格式。")
|
||||
async def fastapi_convert_v3_to_v2(
|
||||
req: Request
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
转换 INP V3 为 V2
|
||||
|
||||
- **req**: 请求体,需包含 `{"inp": "..."}` 结构
|
||||
"""
|
||||
network = "v3Tov2"
|
||||
jo_root = await req.json()
|
||||
inp = jo_root["inp"]
|
||||
cs = convert_inp_v3_to_v2(inp)
|
||||
op = cs.operations[0]
|
||||
open_project(network)
|
||||
op["vertex"] = json.dumps(get_all_vertices(network))
|
||||
op["scada"] = json.dumps(get_all_scada_info(network))
|
||||
|
||||
close_project(network)
|
||||
|
||||
return cs
|
||||
|
||||
async def read_inp_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
inp: str = Query(..., description="INP 文件名 (不包含路径)")
|
||||
) -> bool:
|
||||
"""
|
||||
读取 INP 文件到项目
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
- **inp**: INP 文件名
|
||||
"""
|
||||
read_inp(network, inp)
|
||||
return True
|
||||
|
||||
async def dump_inp_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
inp: str = Query(..., description="目标文件名")
|
||||
) -> bool:
|
||||
"""
|
||||
导出项目到 INP 文件
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
- **inp**: 目标文件名
|
||||
"""
|
||||
dump_inp(network, inp)
|
||||
return True
|
||||
|
||||
async def is_project_locked_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
检查项目是否被锁定
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
return network in lockedPrjs.keys()
|
||||
|
||||
async def is_project_locked_by_me_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
检查项目是否被当前用户锁定
|
||||
|
||||
- **network**: 管网名称(或数据库名称)
|
||||
"""
|
||||
client_host = req.client.host
|
||||
return lockedPrjs.get(network) == client_host
|
||||
|
||||
# 0 successfully locked
|
||||
# 1 already locked by you
|
||||
# 2 locked by others
|
||||
async def lock_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
锁定项目
|
||||
|
||||
返回值:
|
||||
- **0**: 锁定成功
|
||||
- **1**: 已被当前用户锁定
|
||||
- **2**: 已被其他用户锁定
|
||||
"""
|
||||
client_host = req.client.host
|
||||
if not network in lockedPrjs.keys():
|
||||
lockedPrjs[network] = client_host
|
||||
return 0
|
||||
else:
|
||||
if lockedPrjs.get(network) == client_host:
|
||||
return 1
|
||||
else:
|
||||
return 2
|
||||
|
||||
def unlock_project_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
req: Request = None
|
||||
):
|
||||
"""
|
||||
解锁项目
|
||||
|
||||
只有锁定者才能解锁。
|
||||
"""
|
||||
client_host = req.client.host
|
||||
if lockedPrjs.get(network) == client_host:
|
||||
print("delete key")
|
||||
del lockedPrjs[network]
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
async def fastapi_download_inp(
|
||||
name: str = Query(..., description="文件名"),
|
||||
response: Response = None
|
||||
):
|
||||
"""
|
||||
下载 INP 文件
|
||||
|
||||
- **name**: 文件名
|
||||
"""
|
||||
filePath = inpDir + name
|
||||
if os.path.exists(filePath):
|
||||
return FileResponse(
|
||||
filePath, media_type="application/octet-stream", filename="inp.inp"
|
||||
)
|
||||
else:
|
||||
response.status_code = status.HTTP_400_BAD_REQUEST
|
||||
return True
|
||||
|
||||
# DingZQ, 2024-12-28, convert v3 to v2
|
||||
async def fastapi_convert_v3_to_v2(
|
||||
req: Request
|
||||
) -> ChangeSet:
|
||||
"""
|
||||
转换 INP V3 为 V2
|
||||
|
||||
- **req**: 请求体,需包含 `{"inp": "..."}` 结构
|
||||
"""
|
||||
network = "v3Tov2"
|
||||
jo_root = await req.json()
|
||||
inp = jo_root["inp"]
|
||||
cs = convert_inp_v3_to_v2(inp)
|
||||
op = cs.operations[0]
|
||||
open_project(network)
|
||||
op["vertex"] = json.dumps(get_all_vertices(network))
|
||||
op["scada"] = json.dumps(get_all_scada_info(network))
|
||||
|
||||
close_project(network)
|
||||
|
||||
return cs
|
||||
|
||||
@@ -12,7 +12,12 @@ from app.algorithms.sensor import (
|
||||
pressure_sensor_placement_sensitivity,
|
||||
)
|
||||
from app.auth.metadata_dependencies import get_current_metadata_user
|
||||
from app.auth.project_dependencies import ProjectContext, get_project_context
|
||||
from app.auth.project_dependencies import (
|
||||
ProjectContext,
|
||||
get_project_context,
|
||||
use_project_business_routing,
|
||||
)
|
||||
from app.infra.db.project_routing import ActiveProjectRouting
|
||||
from app.domain.schemas.sensor_placement import (
|
||||
SensorPointResponse,
|
||||
SensorPlacementExportRequest,
|
||||
@@ -106,6 +111,7 @@ def _get_run_response(
|
||||
async def get_sensor_placement_candidate_detail(
|
||||
node_id: str = Path(..., min_length=1, max_length=32),
|
||||
project_context: ProjectContext = Depends(get_project_context),
|
||||
_routing: ActiveProjectRouting = Depends(use_project_business_routing),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return await run_in_threadpool(
|
||||
@@ -166,6 +172,7 @@ async def optimize_sensor_placement_scheme(
|
||||
)
|
||||
async def get_sensor_placement_runs(
|
||||
project_context: ProjectContext = Depends(get_project_context),
|
||||
_routing: ActiveProjectRouting = Depends(use_project_business_routing),
|
||||
) -> list[dict[str, Any]]:
|
||||
return await run_in_threadpool(
|
||||
list_sensor_placement_runs,
|
||||
|
||||
@@ -127,7 +127,7 @@ def run_simulation_manually_by_date(
|
||||
|
||||
# 必须用这个PlainTextResponse,不然每个key都有引号
|
||||
@router.post("/project-runs", response_class=PlainTextResponse, summary="运行项目模拟", description="基于指定的管网项目运行标准水力模拟,返回纯文本格式的模拟报告。")
|
||||
async def run_project_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> str:
|
||||
def run_project_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> str:
|
||||
"""
|
||||
运行项目模拟
|
||||
|
||||
@@ -143,7 +143,7 @@ async def run_project_endpoint(network: str = Query(..., description="管网名
|
||||
# output 是 json
|
||||
# report 是 text
|
||||
@router.post("/project-return-dict-runs", summary="运行项目模拟(返回字典)", description="基于指定的管网项目运行标准水力模拟,返回JSON格式的字典,包含输出数据和报告文本。")
|
||||
async def run_project_return_dict_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
def run_project_return_dict_endpoint(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, Any]:
|
||||
"""
|
||||
运行项目模拟(返回字典)
|
||||
|
||||
@@ -160,7 +160,7 @@ async def run_project_return_dict_endpoint(network: str = Query(..., description
|
||||
|
||||
# put in inp folder, name without extension
|
||||
@router.post("/inp-runs", summary="运行INP文件", description="运行指定INP文件格式的管网模型进行水力模拟。INP文件应该放在inp文件夹中,参数为文件名不含扩展名。")
|
||||
async def run_inp_endpoint(network: str = Query(..., description="inp文件名(不含扩展名)")) -> str:
|
||||
def run_inp_endpoint(network: str = Query(..., description="inp文件名(不含扩展名)")) -> str:
|
||||
"""
|
||||
运行INP文件
|
||||
|
||||
@@ -173,7 +173,7 @@ async def run_inp_endpoint(network: str = Query(..., description="inp文件名
|
||||
|
||||
# path is absolute path
|
||||
@router.get("/outputs", summary="导出模拟输出", description="导出指定路径的模拟输出文件内容。参数应为绝对路径。")
|
||||
async def dump_output_endpoint(output: str = Query(..., description="模拟输出文件的绝对路径")) -> str:
|
||||
def dump_output_endpoint(output: str = Query(..., description="模拟输出文件的绝对路径")) -> str:
|
||||
"""
|
||||
导出模拟输出
|
||||
|
||||
@@ -186,7 +186,7 @@ async def dump_output_endpoint(output: str = Query(..., description="模拟输
|
||||
|
||||
# Analysis Endpoints
|
||||
@router.post("/burst-analyses", summary="爆管分析(高级)", description="高级版本的爆管分析,支持在指定时间点修改泵控制模式和阀门开度,以分析这些改变对爆管影响的作用。支持固定泵和变速泵的独立控制。")
|
||||
async def fastapi_burst_analysis(
|
||||
def fastapi_burst_analysis(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
modify_pattern_start_time: str = Query(..., description="模式修改开始时间(ISO 8601格式)"),
|
||||
burst_ID: list[str] = Query(..., description="爆管节点/管段ID列表"),
|
||||
@@ -220,7 +220,7 @@ async def fastapi_burst_analysis(
|
||||
|
||||
|
||||
@router.post("/valve-closure-analyses", response_class=PlainTextResponse, summary="阀门关闭分析(高级)", description="高级版本的阀门关闭分析,支持同时关闭多个阀门,并在指定持续时间内进行模拟。返回纯文本格式的分析结果。")
|
||||
async def fastapi_valve_close_analysis(
|
||||
def fastapi_valve_close_analysis(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
start_time: str = Query(..., description="阀门关闭开始时间(ISO 8601格式)"),
|
||||
valves: List[str] = Query(..., description="要关闭的阀门ID列表"),
|
||||
@@ -249,7 +249,7 @@ async def fastapi_valve_close_analysis(
|
||||
|
||||
|
||||
@router.post("/valve-isolation-analyses", summary="阀门隔离分析", description="分析当发生突发事件时,通过关闭指定阀门进行隔离,确定哪些阀门必须关闭、哪些可选关闭,以及隔离的可行性。")
|
||||
async def valve_isolation_endpoint(
|
||||
def valve_isolation_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
accident_element: List[str] = Query(..., description="发生事故的管段/节点ID列表"),
|
||||
disabled_valves: List[str] = Query(None, description="已故障的阀门ID列表(可选)"),
|
||||
@@ -290,7 +290,7 @@ async def valve_isolation_endpoint(
|
||||
|
||||
|
||||
@router.post("/flushing-analyses", response_class=PlainTextResponse, summary="冲洗分析(高级)", description="高级版本的冲洗分析,支持按状态和设置值控制多个可选阀门,指定排污节点,并设置固定的冲洗流量。返回纯文本格式的分析结果。")
|
||||
async def fastapi_flushing_analysis(
|
||||
def fastapi_flushing_analysis(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
start_time: str = Query(..., description="冲洗开始时间(ISO 8601格式)"),
|
||||
valves: List[str] | None = Query(None, description="参与控制的阀门ID列表(可选)"),
|
||||
@@ -403,7 +403,7 @@ async def fastapi_flushing_analysis(
|
||||
|
||||
|
||||
@router.post("/contaminant-simulations", response_class=PlainTextResponse, summary="污染物模拟", description="对管网中的污染物扩散进行模拟,评估污染源对管网的影响范围和浓度分布。支持指定污染源位置、污染浓度和扩散模式。")
|
||||
async def fastapi_contaminant_simulation(
|
||||
def fastapi_contaminant_simulation(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
start_time: str = Query(..., description="污染开始时间(ISO 8601格式)"),
|
||||
source: str = Query(..., description="污染源节点ID"),
|
||||
@@ -440,7 +440,7 @@ async def fastapi_contaminant_simulation(
|
||||
|
||||
|
||||
@router.post("/water-age-analyses", response_class=PlainTextResponse, summary="水龄分析(高级)", description="高级版本的水龄分析,在指定时间点进行分析,支持自定义模拟持续时间。返回纯文本格式的分析结果。")
|
||||
async def fastapi_age_analysis(
|
||||
def fastapi_age_analysis(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
start_time: str = Query(..., description="分析开始时间(ISO 8601格式)"),
|
||||
duration: int = Query(..., description="模拟持续时间(秒)"),
|
||||
@@ -464,7 +464,7 @@ async def fastapi_age_analysis(
|
||||
|
||||
|
||||
@router.post("/pressure-regulation-calculations", summary="压力调节(基础)", description="对管网的压力进行调节分析,通过控制泵的运行来维持目标节点的目标压力。此为基础版本。")
|
||||
async def pressure_regulation_endpoint(
|
||||
def pressure_regulation_endpoint(
|
||||
network: str = Query(..., description="管网名称(或数据库名称)"),
|
||||
target_node: str = Query(..., description="目标节点ID"),
|
||||
target_pressure: float = Query(..., description="目标压力值(kPa)"),
|
||||
@@ -482,7 +482,7 @@ async def pressure_regulation_endpoint(
|
||||
|
||||
|
||||
@router.post("/pressure-regulation-analyses", summary="压力调节(高级)", description="高级版本的压力调节分析,通过JSON请求体提供详细的控制参数,包括固定泵和变速泵的独立控制、水箱初始水位等。")
|
||||
async def fastapi_pressure_regulation(data: PressureRegulation = Body(..., description="压力调节控制参数")) -> str:
|
||||
def fastapi_pressure_regulation(data: PressureRegulation = Body(..., description="压力调节控制参数")) -> str:
|
||||
"""
|
||||
压力调节(高级版本)
|
||||
|
||||
@@ -496,7 +496,7 @@ async def fastapi_pressure_regulation(data: PressureRegulation = Body(..., descr
|
||||
|
||||
支持固定泵和变速泵的独立控制。
|
||||
"""
|
||||
item = data.dict()
|
||||
item = data.model_dump()
|
||||
simulation.query_corresponding_element_id_and_query_id(item["network"])
|
||||
fixed_pumps = set(globals.fixed_pumps_id.keys())
|
||||
variable_pumps = set(globals.variable_pumps_id.keys())
|
||||
@@ -520,7 +520,7 @@ async def fastapi_pressure_regulation(data: PressureRegulation = Body(..., descr
|
||||
|
||||
|
||||
@router.post("/project-managements", summary="项目管理(高级)", description="高级版本的项目管理,通过JSON请求体提供详细的控制参数,包括泵控制策略、水箱初始水位和区域需水量控制。")
|
||||
async def fastapi_project_management(data: ProjectManagement = Body(..., description="项目管理控制参数")) -> str:
|
||||
def fastapi_project_management(data: ProjectManagement = Body(..., description="项目管理控制参数")) -> str:
|
||||
"""
|
||||
项目管理(高级版本)
|
||||
|
||||
@@ -533,7 +533,7 @@ async def fastapi_project_management(data: ProjectManagement = Body(..., descrip
|
||||
|
||||
支持多维度的项目管理。
|
||||
"""
|
||||
item = data.dict()
|
||||
item = data.model_dump()
|
||||
return project_management(
|
||||
prj_name=item["network"],
|
||||
start_datetime=item["start_time"],
|
||||
@@ -549,7 +549,7 @@ async def fastapi_project_management(data: ProjectManagement = Body(..., descrip
|
||||
|
||||
|
||||
@router.post("/scheduling-analyses", summary="排程分析", description="对管网的供水排程进行分析,优化泵的运行时间和出水流量,平衡水厂出水、水箱进出水,满足用户需求。")
|
||||
async def fastapi_scheduling_analysis(data: SchedulingAnalysis = Body(..., description="排程分析参数")) -> str:
|
||||
def fastapi_scheduling_analysis(data: SchedulingAnalysis = Body(..., description="排程分析参数")) -> str:
|
||||
"""
|
||||
排程分析
|
||||
|
||||
@@ -563,7 +563,7 @@ async def fastapi_scheduling_analysis(data: SchedulingAnalysis = Body(..., descr
|
||||
|
||||
用于优化供水排程。
|
||||
"""
|
||||
item = data.dict()
|
||||
item = data.model_dump()
|
||||
return scheduling_simulation(
|
||||
item["network"],
|
||||
item["start_time"],
|
||||
@@ -575,7 +575,7 @@ async def fastapi_scheduling_analysis(data: SchedulingAnalysis = Body(..., descr
|
||||
|
||||
|
||||
@router.post("/daily-scheduling-analyses", summary="日排程分析", description="对管网的每日供水排程进行分析,优化水库、水厂、水箱和用户需求的协调,制定合理的每日排程方案。")
|
||||
async def fastapi_daily_scheduling_analysis(data: DailySchedulingAnalysis = Body(..., description="日排程分析参数")) -> str:
|
||||
def fastapi_daily_scheduling_analysis(data: DailySchedulingAnalysis = Body(..., description="日排程分析参数")) -> str:
|
||||
"""
|
||||
日排程分析
|
||||
|
||||
@@ -590,7 +590,7 @@ async def fastapi_daily_scheduling_analysis(data: DailySchedulingAnalysis = Body
|
||||
|
||||
用于制定每日供水排程方案。
|
||||
"""
|
||||
item = data.dict()
|
||||
item = data.model_dump()
|
||||
return daily_scheduling_simulation(
|
||||
item["network"],
|
||||
item["start_time"],
|
||||
@@ -607,7 +607,7 @@ async def fastapi_daily_scheduling_analysis(data: DailySchedulingAnalysis = Body
|
||||
|
||||
|
||||
@router.post("/pump-failure-events", summary="泵故障管理", description="记录和管理泵的故障状态,包括故障发生时间和受影响的泵列表。系统将记录故障日志并更新泵状态。")
|
||||
async def fastapi_pump_failure(data: PumpFailureState = Body(..., description="泵故障状态信息")) -> str:
|
||||
def fastapi_pump_failure(data: PumpFailureState = Body(..., description="泵故障状态信息")) -> str:
|
||||
"""
|
||||
泵故障管理
|
||||
|
||||
@@ -617,7 +617,7 @@ async def fastapi_pump_failure(data: PumpFailureState = Body(..., description="
|
||||
|
||||
系统将验证泵信息的有效性并更新故障状态文件。
|
||||
"""
|
||||
item = data.dict()
|
||||
item = data.model_dump()
|
||||
with open("./pump_failure_message.txt", "a", encoding="utf-8-sig") as f1:
|
||||
f1.write("[{}] {}\n".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), item))
|
||||
with open("./pump_failure_status.txt", "r", encoding="utf-8-sig") as f2:
|
||||
@@ -651,7 +651,7 @@ async def fastapi_pump_failure(data: PumpFailureState = Body(..., description="
|
||||
|
||||
|
||||
@router.post("/simulation-runs", summary="手动运行日期指定模拟", description="根据指定的开始时间和持续时间,手动运行水力模拟。开始时间必须是显式带时区的 ISO 8601 / RFC3339 时间。")
|
||||
async def fastapi_run_simulation_manually_by_date(
|
||||
def fastapi_run_simulation_manually_by_date(
|
||||
data: RunSimulationManuallyByDate = Body(..., description="模拟运行参数"),
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
|
||||
@@ -2,6 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Path, Body
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from psycopg import AsyncConnection
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.infra.db.timescaledb.repositories.realtime import RealtimeRepository
|
||||
from .dependencies import get_timescale_connection
|
||||
@@ -13,9 +14,31 @@ TIME_RANGE_START_DESC = f"时间范围开始时间。{TIME_WITH_TZ_DESC}"
|
||||
TIME_RANGE_END_DESC = f"时间范围结束时间。{TIME_WITH_TZ_DESC}"
|
||||
|
||||
|
||||
class RealtimeLinkBatchItem(BaseModel):
|
||||
time: datetime
|
||||
id: str
|
||||
flow: float | None = None
|
||||
friction: float | None = None
|
||||
headloss: float | None = None
|
||||
quality: float | None = None
|
||||
reaction: float | None = None
|
||||
setting: float | None = None
|
||||
status: float | None = None
|
||||
velocity: float | None = None
|
||||
|
||||
|
||||
class RealtimeNodeBatchItem(BaseModel):
|
||||
time: datetime
|
||||
id: str
|
||||
actual_demand: float | None = None
|
||||
total_head: float | None = None
|
||||
pressure: float | None = None
|
||||
quality: float | None = None
|
||||
|
||||
|
||||
@router.post("/timeseries/realtime/links/batches", status_code=201, summary="批量插入实时管道数据")
|
||||
async def insert_realtime_links(
|
||||
data: List[dict] = Body(..., description="管道数据列表,每项包含管道ID、时间戳等信息"),
|
||||
data: List[RealtimeLinkBatchItem] = Body(..., description="同一时间点的管道快照数据"),
|
||||
conn: AsyncConnection = Depends(get_timescale_connection)
|
||||
):
|
||||
"""
|
||||
@@ -29,7 +52,9 @@ async def insert_realtime_links(
|
||||
Returns:
|
||||
插入成功的记录数
|
||||
"""
|
||||
await RealtimeRepository.insert_links_batch(conn, data)
|
||||
await RealtimeRepository.insert_links_batch(
|
||||
conn, [item.model_dump() for item in data]
|
||||
)
|
||||
return {"message": f"Inserted {len(data)} records"}
|
||||
|
||||
|
||||
@@ -119,7 +144,7 @@ async def update_realtime_link_field(
|
||||
|
||||
@router.post("/timeseries/realtime/nodes/batches", status_code=201, summary="批量插入实时节点数据")
|
||||
async def insert_realtime_nodes(
|
||||
data: List[dict] = Body(..., description="节点数据列表,每项包含节点ID、时间戳等信息"),
|
||||
data: List[RealtimeNodeBatchItem] = Body(..., description="同一时间点的节点快照数据"),
|
||||
conn: AsyncConnection = Depends(get_timescale_connection)
|
||||
):
|
||||
"""
|
||||
@@ -133,7 +158,9 @@ async def insert_realtime_nodes(
|
||||
Returns:
|
||||
插入成功的记录数
|
||||
"""
|
||||
await RealtimeRepository.insert_nodes_batch(conn, data)
|
||||
await RealtimeRepository.insert_nodes_batch(
|
||||
conn, [item.model_dump() for item in data]
|
||||
)
|
||||
return {"message": f"Inserted {len(data)} records"}
|
||||
|
||||
|
||||
|
||||
+12
-12
@@ -11,6 +11,7 @@ from fastapi import APIRouter, Depends, Query
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.routing import APIRoute
|
||||
from pydantic import BaseModel, JsonValue, create_model
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
from starlette.responses import Response
|
||||
|
||||
from app.api.problem_details import ProblemDetails
|
||||
@@ -38,6 +39,14 @@ class Page(BaseModel, Generic[T]):
|
||||
offset: int
|
||||
|
||||
|
||||
async def _call_endpoint(endpoint, *args, **kwargs):
|
||||
"""Call async handlers directly and offload synchronous handlers."""
|
||||
if inspect.iscoroutinefunction(endpoint):
|
||||
return await endpoint(*args, **kwargs)
|
||||
result = await run_in_threadpool(endpoint, *args, **kwargs)
|
||||
return await result if inspect.isawaitable(result) else result
|
||||
|
||||
|
||||
_NAME_IS_NETWORK = {
|
||||
"pressure_sensor_placement_sensitivity_endpoint",
|
||||
"pressure_sensor_placement_kmeans_endpoint",
|
||||
@@ -59,7 +68,6 @@ _TIMESCALE_ROUTED_ENDPOINT_MODULES = {
|
||||
"app.api.v1.endpoints.leakage",
|
||||
"app.api.v1.endpoints.simulation",
|
||||
}
|
||||
_TIMESCALE_ROUTED_ENDPOINT_NAMES = {"open_project_endpoint"}
|
||||
|
||||
|
||||
def _clean_name(name: str) -> str:
|
||||
@@ -183,10 +191,7 @@ def _with_header_project_context(endpoint, route_name: str):
|
||||
if model_has_username:
|
||||
kwargs.pop(injected_user_name, None)
|
||||
with activate_project_routing(project_routing):
|
||||
result = endpoint(*args, **kwargs)
|
||||
if inspect.isawaitable(result):
|
||||
return await result
|
||||
return result
|
||||
return await _call_endpoint(endpoint, *args, **kwargs)
|
||||
|
||||
parameters = []
|
||||
for name, parameter in signature.parameters.items():
|
||||
@@ -206,7 +211,6 @@ def _with_header_project_context(endpoint, route_name: str):
|
||||
get_project_simulation_routing
|
||||
if (
|
||||
endpoint.__module__ in _TIMESCALE_ROUTED_ENDPOINT_MODULES
|
||||
or endpoint.__name__ in _TIMESCALE_ROUTED_ENDPOINT_NAMES
|
||||
)
|
||||
else get_project_business_routing
|
||||
)
|
||||
@@ -262,9 +266,7 @@ def _with_pagination(endpoint):
|
||||
else:
|
||||
limit = kwargs.pop("_rest_limit")
|
||||
offset = kwargs.pop("_rest_offset")
|
||||
result = endpoint(*args, **kwargs)
|
||||
if inspect.isawaitable(result):
|
||||
result = await result
|
||||
result = await _call_endpoint(endpoint, *args, **kwargs)
|
||||
if not isinstance(result, list):
|
||||
return result
|
||||
if handler_handles_pagination:
|
||||
@@ -313,9 +315,7 @@ def _with_jsonable_response(endpoint):
|
||||
|
||||
@wraps(endpoint)
|
||||
async def wrapper(*args, **kwargs):
|
||||
result = endpoint(*args, **kwargs)
|
||||
if inspect.isawaitable(result):
|
||||
result = await result
|
||||
result = await _call_endpoint(endpoint, *args, **kwargs)
|
||||
if isinstance(result, Response):
|
||||
return result
|
||||
return jsonable_encoder(result)
|
||||
|
||||
Reference in New Issue
Block a user