Files
FastapiAdmin/backend/app/api/v1/module_platform/invoice/controller.py
T
zhangtao 7d2367e34e refactor: 统一项目代码风格并修复多处类型与调用问题
本次提交包含多项优化:
1.  移除大量冗余的文件头注释与过时的from __future__导入
2.  将CRUD的list方法统一重命名为get_list保持接口一致
3.  修复前后端状态字段类型不匹配问题,将string类型status改为number
4.  修正前端文案错别字,将"代办事项"修正为标准写法
5.  更新sqlalchemy版本并调整依赖配置
6.  新增缓存工具类替代fastapi-cache2,重构缓存调用逻辑
7.  新增开源授权函生成相关工具与数据库字段支持
8.  为多个业务模块添加防重复提交loading状态
9.  修复邮件模型的外键关联缺失问题
10. 优化pdf生成工具的导入时机与文档注释
2026-06-21 17:34:11 +08:00

106 lines
4.8 KiB
Python

from typing import Annotated
from fastapi import APIRouter, Body, Depends, Path, Query
from fastapi.responses import JSONResponse
from app.common.response import ResponseSchema, SuccessResponse
from app.core.base_schema import AuthSchema, PageResultSchema
from app.core.dependencies import AuthPermission
from app.core.router_class import OperationLogRoute
from .schema import (
InvoiceApplySchema,
InvoiceIssueSchema,
InvoiceOutSchema,
InvoiceQueryParam,
InvoiceVoidSchema,
)
from .service import InvoicePlatformService, InvoiceTenantService
TenantInvoiceRouter = APIRouter(prefix="/tenant/invoice", route_class=OperationLogRoute, tags=["平台管理", "发票管理"])
@TenantInvoiceRouter.post("/apply", summary="申请开票", response_model=ResponseSchema[InvoiceOutSchema])
async def invoice_apply_controller(
data: Annotated[InvoiceApplySchema, Body()],
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
) -> JSONResponse:
result = await InvoiceTenantService.apply(auth, data, auth.tenant_id)
return SuccessResponse(data=result, msg="发票申请成功")
@TenantInvoiceRouter.get("/list", summary="我的发票列表", response_model=ResponseSchema[PageResultSchema[InvoiceOutSchema]])
async def invoice_list_my_controller(
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
invoice_type: Annotated[str | None, Query()] = None,
status: Annotated[int | None, Query()] = None,
page_no: Annotated[int, Query(ge=1)] = 1,
page_size: Annotated[int, Query(ge=1, le=100)] = 10,
) -> JSONResponse:
result = await InvoiceTenantService.list_my(
auth,
auth.tenant_id,
InvoiceQueryParam(invoice_type=invoice_type, status=status, page_no=page_no, page_size=page_size),
)
return SuccessResponse(data=result, msg="查询成功")
@TenantInvoiceRouter.get("/{id}/download", summary="下载发票PDF与授权函", response_model=ResponseSchema[dict])
async def invoice_download_controller(
id: Annotated[int, Path(ge=1)],
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
) -> JSONResponse:
pdf_url = await InvoiceTenantService.download(auth, id, auth.tenant_id)
oss_license_pdf_url = await InvoiceTenantService.download_license(auth, id, auth.tenant_id)
return SuccessResponse(
msg="下载地址",
data={"pdf_url": pdf_url, "oss_license_pdf_url": oss_license_pdf_url},
)
@TenantInvoiceRouter.get("/{id}/license/download", summary="下载开源授权函PDF", response_model=ResponseSchema[dict])
async def invoice_license_download_controller(
id: Annotated[int, Path(ge=1)],
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
) -> JSONResponse:
oss_license_pdf_url = await InvoiceTenantService.download_license(auth, id, auth.tenant_id)
return SuccessResponse(msg="授权函下载地址", data={"oss_license_pdf_url": oss_license_pdf_url})
PlatformInvoiceRouter = APIRouter(prefix="/invoice", route_class=OperationLogRoute, tags=["平台管理", "发票管理"])
@PlatformInvoiceRouter.get("/list", summary="全部发票列表", response_model=ResponseSchema[PageResultSchema[InvoiceOutSchema]])
async def invoice_list_all_controller(
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
invoice_type: Annotated[str | None, Query()] = None,
status: Annotated[int | None, Query()] = None,
tenant_id: Annotated[int | None, Query()] = None,
page_no: Annotated[int, Query(ge=1)] = 1,
page_size: Annotated[int, Query(ge=1, le=100)] = 10,
) -> JSONResponse:
result = await InvoicePlatformService.list_all(
auth,
InvoiceQueryParam(invoice_type=invoice_type, status=status, tenant_id=tenant_id, page_no=page_no, page_size=page_size),
)
return SuccessResponse(data=result, msg="查询成功")
@PlatformInvoiceRouter.put("/issue/{id}", summary="开具发票", response_model=ResponseSchema[InvoiceOutSchema])
async def invoice_issue_controller(
id: Annotated[int, Path(ge=1)],
data: Annotated[InvoiceIssueSchema, Body()],
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
) -> JSONResponse:
result = await InvoicePlatformService.issue(
auth,
id,
data.pdf_url or "",
data.api_response or "",
data.oss_license_pdf_url or "",
)
return SuccessResponse(data=result, msg="发票开具成功")
@PlatformInvoiceRouter.put("/void/{id}", summary="作废发票", response_model=ResponseSchema[InvoiceOutSchema])
async def invoice_void_controller(
id: Annotated[int, Path(ge=1)],
auth: Annotated[AuthSchema, Depends(AuthPermission(["*:*:*"]))],
data: Annotated[InvoiceVoidSchema, Body()] = InvoiceVoidSchema(),
) -> JSONResponse:
result = await InvoicePlatformService.void(auth, id, data)
return SuccessResponse(data=result, msg="发票已作废")