You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, Path, Query
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.common.response import ResponseSchema, SuccessResponse
|
|
from app.core.base_schema import AuthSchema
|
|
from app.core.dependencies import AuthPermission
|
|
from app.core.router_class import OperationLogRoute
|
|
|
|
from .schema import VariableSaveSchema
|
|
from .service import VariableService
|
|
|
|
VariableRouter = APIRouter(route_class=OperationLogRoute, prefix="/variable", tags=["能源报告变量关联"])
|
|
|
|
|
|
@VariableRouter.get(
|
|
"/list",
|
|
summary="查询模板的变量-章节关联列表",
|
|
response_model=ResponseSchema[list[dict]],
|
|
)
|
|
async def get_variable_list_controller(
|
|
template_id: Annotated[int, Query(ge=1, description="模板ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:variable:query"]))],
|
|
) -> JSONResponse:
|
|
result = await VariableService(auth).list_by_template(template_id=template_id)
|
|
return SuccessResponse(data=result, msg="查询变量关联列表成功")
|
|
|
|
|
|
@VariableRouter.get(
|
|
"/chapter/{chapter_id}",
|
|
summary="查询章节标注详情和变量勾选状态",
|
|
response_model=ResponseSchema[dict],
|
|
)
|
|
async def get_variable_list_by_chapter_controller(
|
|
chapter_id: Annotated[int, Path(ge=1, description="章节标注ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:variable:query"]))],
|
|
) -> JSONResponse:
|
|
result = await VariableService(auth).list_by_chapter(chapter_id=chapter_id)
|
|
return SuccessResponse(data=result, msg="查询章节标注变量配置成功")
|
|
|
|
|
|
@VariableRouter.post(
|
|
"/save",
|
|
summary="批量保存变量-章节关联",
|
|
response_model=ResponseSchema[list[dict]],
|
|
)
|
|
async def save_variable_controller(
|
|
data: VariableSaveSchema,
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:variable:save"]))],
|
|
) -> JSONResponse:
|
|
result = await VariableService(auth).save(data=data)
|
|
return SuccessResponse(data=result, msg="保存变量关联成功")
|
|
|
|
|
|
@VariableRouter.delete(
|
|
"/delete",
|
|
summary="删除某个变量的全部关联",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def delete_variable_controller(
|
|
template_id: Annotated[int, Query(ge=1, description="模板ID")],
|
|
variable_name: Annotated[str, Query(description="变量名称")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:variable:delete"]))],
|
|
) -> JSONResponse:
|
|
await VariableService(auth).delete_by_variable(template_id=template_id, variable_name=variable_name)
|
|
return SuccessResponse(msg="删除变量关联成功")
|