61 lines
2.6 KiB
Python
61 lines
2.6 KiB
Python
from datetime import datetime
|
|
from fastapi import APIRouter, HTTPException, Path, Query
|
|
from typing import Any
|
|
from app.services.tjnetwork import get_scheme_schema, get_scheme, get_all_schemes
|
|
from app.services.scheme_management import query_scheme_detail
|
|
from app.services.time_api import extract_date
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/network-schemas/scheme", summary="获取方案模式", description="获取指定网络的方案模式定义")
|
|
async def fastapi_get_scheme_schema(network: str = Query(..., description="管网名称(或数据库名称)")) -> dict[str, dict[Any, Any]]:
|
|
"""
|
|
获取方案模式定义
|
|
|
|
返回指定网络的方案模式结构定义
|
|
"""
|
|
return get_scheme_schema(network)
|
|
|
|
@router.get("/schemes/detail", summary="获取单个方案", description="根据名称获取指定的方案信息")
|
|
async def fastapi_get_scheme(network: str = Query(..., description="管网名称(或数据库名称)"), schema_name: str = Query(..., description="方案名称")) -> dict[Any, Any]:
|
|
"""
|
|
获取单个方案详情
|
|
|
|
返回指定网络中指定名称的方案详细信息
|
|
"""
|
|
return get_scheme(network, schema_name)
|
|
|
|
@router.get("/schemes", summary="获取所有方案", description="获取指定网络的所有方案信息")
|
|
async def fastapi_get_all_schemes(
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
scheme_type: str | None = Query(None, description="方案类型;为空时返回全部类型"),
|
|
query_date: datetime | None = Query(None, description="查询日期(可选)"),
|
|
) -> list[dict[Any, Any]]:
|
|
"""
|
|
获取所有方案列表
|
|
|
|
返回指定网络中所有可用的方案
|
|
"""
|
|
parsed_date = (
|
|
extract_date(query_date, field_name="query_date")
|
|
if query_date is not None
|
|
else None
|
|
)
|
|
return get_all_schemes(network, scheme_type=scheme_type, query_date=parsed_date)
|
|
|
|
|
|
@router.get("/schemes/{scheme_name}", summary="获取方案详情", description="按方案类型获取指定方案详情")
|
|
async def fastapi_get_scheme_detail(
|
|
scheme_name: str = Path(..., description="方案名称"),
|
|
network: str = Query(..., description="管网名称(或数据库名称)"),
|
|
scheme_type: str | None = Query(None, description="方案类型;为空时返回通用方案详情"),
|
|
) -> dict[Any, Any]:
|
|
result = query_scheme_detail(
|
|
name=network,
|
|
scheme_name=scheme_name,
|
|
scheme_type=scheme_type,
|
|
)
|
|
if not result:
|
|
raise HTTPException(status_code=404, detail=f"Scheme {scheme_name} not found")
|
|
return result
|