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.
94 lines
3.6 KiB
Python
94 lines
3.6 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.common.response import ResponseSchema, SuccessResponse
|
|
from app.core.base_params import PaginationQueryParam
|
|
from app.core.base_schema import AuthSchema, PageResultSchema
|
|
from app.core.dependencies import AuthPermission
|
|
from app.core.router_class import OperationLogRoute
|
|
|
|
from .schema import (
|
|
EnergyReportTemplateCreateSchema,
|
|
EnergyReportTemplateOutSchema,
|
|
EnergyReportTemplateQueryParam,
|
|
EnergyReportTemplateUpdateSchema,
|
|
)
|
|
from .service import EnergyReportTemplateService
|
|
|
|
EnergyReportTemplateRouter = APIRouter(route_class=OperationLogRoute, prefix="/attachment-template", tags=["能源报告模板"])
|
|
|
|
|
|
@EnergyReportTemplateRouter.get(
|
|
"/list",
|
|
summary="查询能源报告模板列表",
|
|
response_model=ResponseSchema[PageResultSchema[EnergyReportTemplateOutSchema]],
|
|
)
|
|
async def get_energy_report_template_list_controller(
|
|
page: Annotated[PaginationQueryParam, Depends()],
|
|
search: Annotated[EnergyReportTemplateQueryParam, Depends()],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:attachment_template:query"]))],
|
|
) -> JSONResponse:
|
|
result = await EnergyReportTemplateService(auth).page(
|
|
page_no=page.page_no,
|
|
page_size=page.page_size,
|
|
search=search,
|
|
order_by=page.order_by or [{"order": "asc"}, {"id": "desc"}],
|
|
)
|
|
return SuccessResponse(data=result, msg="查询能源报告模板列表成功")
|
|
|
|
|
|
@EnergyReportTemplateRouter.get(
|
|
"/detail/{id}",
|
|
summary="查询能源报告模板详情",
|
|
response_model=ResponseSchema[EnergyReportTemplateOutSchema],
|
|
)
|
|
async def get_energy_report_template_detail_controller(
|
|
id: Annotated[int, Path(description="能源报告模板ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:attachment_template:detail"]))],
|
|
) -> JSONResponse:
|
|
result = await EnergyReportTemplateService(auth).detail(id=id)
|
|
return SuccessResponse(data=result, msg="查询能源报告模板详情成功")
|
|
|
|
|
|
@EnergyReportTemplateRouter.post(
|
|
"/create",
|
|
summary="创建能源报告模板",
|
|
response_model=ResponseSchema[EnergyReportTemplateOutSchema],
|
|
)
|
|
async def create_energy_report_template_controller(
|
|
data: EnergyReportTemplateCreateSchema,
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:attachment_template:create"]))],
|
|
) -> JSONResponse:
|
|
result = await EnergyReportTemplateService(auth).create(data=data)
|
|
return SuccessResponse(data=result, msg="创建能源报告模板成功")
|
|
|
|
|
|
@EnergyReportTemplateRouter.put(
|
|
"/update/{id}",
|
|
summary="修改能源报告模板",
|
|
response_model=ResponseSchema[EnergyReportTemplateOutSchema],
|
|
)
|
|
async def update_energy_report_template_controller(
|
|
data: EnergyReportTemplateUpdateSchema,
|
|
id: Annotated[int, Path(description="能源报告模板ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:attachment_template:update"]))],
|
|
) -> JSONResponse:
|
|
result = await EnergyReportTemplateService(auth).update(id=id, data=data)
|
|
return SuccessResponse(data=result, msg="修改能源报告模板成功")
|
|
|
|
|
|
@EnergyReportTemplateRouter.delete(
|
|
"/delete",
|
|
summary="删除能源报告模板",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def delete_energy_report_template_controller(
|
|
ids: Annotated[list[int], Body(description="ID列表")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_energy:attachment_template:delete"]))],
|
|
) -> JSONResponse:
|
|
await EnergyReportTemplateService(auth).delete(ids=ids)
|
|
return SuccessResponse(msg="删除能源报告模板成功")
|
|
|