refactor: 重构查询参数实现,替换旧的__init__初始化方式为dataclass+post_init

feat: 新增岗位编码字段与校验
fix: 修复批量删除提示、请求缓存、任务状态等逻辑
perf: 优化表格列展示,移除冗余ID列
build: 降级fastapi版本至0.115.2,更新依赖锁文件
docs: 补充部分代码注释与说明
This commit is contained in:
zhangtao
2026-06-22 00:27:23 +08:00
parent 8949f6dc46
commit afdd805e11
44 changed files with 728 additions and 639 deletions
@@ -6,6 +6,7 @@ from fastapi.responses import JSONResponse
from sqlalchemy.ext.asyncio import AsyncSession
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, db_getter
from app.core.exceptions import CustomException
@@ -64,20 +65,22 @@ async def order_detail_controller(
)
async def order_list_controller(
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:order:query"]))],
tenant_id: Annotated[int | None, Query()] = None,
status: Annotated[int | None, Query()] = None,
order_type: Annotated[str | None, Query()] = None,
page: Annotated[int, Query(ge=1)] = 1,
page_size: Annotated[int, Query(ge=1, le=100)] = 20,
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[OrderQueryParam, Depends()],
) -> JSONResponse:
params = OrderQueryParam(tenant_id=tenant_id, status=status, order_type=order_type)
offset = (page - 1) * page_size
items, total = await OrderService.get_list(auth=auth, params=params, offset=offset, limit=page_size)
items, total = await OrderService.get_list(
auth=auth,
page_no=page.page_no,
page_size=page.page_size,
order_by=page.order_by,
search=search,
)
offset = (page.page_no - 1) * page.page_size
result = PageResultSchema(
page_no=page,
page_size=page_size,
page_no=page.page_no,
page_size=page.page_size,
total=total,
has_next=offset + page_size < total,
has_next=offset + page.page_size < total,
items=items,
)
return SuccessResponse(data=result)
@@ -126,24 +126,20 @@ class OrderOutSchema(BaseSchema, TenantBySchema):
class OrderQueryParam(BaseQueryParam):
"""订单查询参数"""
def __init__(
self,
tenant_id: int | None = Query(None, description="租户ID"),
status: int | None = Query(None, description="订单状态(0:待支付 1:已支付 2:已取消 3:已退款)"),
order_type: str | None = Query(None, description="订单类型"),
order_no: str | None = Query(None, description="订单号"),
*args,
**kwargs,
) -> None:
super().__init__(*args, **kwargs)
if tenant_id is not None:
self.tenant_id = (QueueEnum.eq.value, tenant_id)
if status is not None:
self.status = (QueueEnum.eq.value, status)
if order_type:
self.order_type = (QueueEnum.eq.value, order_type)
if order_no:
self.order_no = (QueueEnum.like.value, order_no)
tenant_id: int | None = Query(None, description="租户ID")
status: int | None = Query(None, description="订单状态(0:待支付 1:已支付 2:已取消 3:已退款)")
order_type: str | None = Query(None, description="订单类型")
order_no: str | None = Query(None, description="订单")
def __post_init__(self) -> None:
if self.tenant_id is not None:
self.tenant_id = (QueueEnum.eq.value, self.tenant_id)
if self.status is not None:
self.status = (QueueEnum.eq.value, self.status)
if self.order_type:
self.order_type = (QueueEnum.eq.value, self.order_type)
if self.order_no:
self.order_no = (QueueEnum.like.value, self.order_no)
class PaymentCallbackSchema(BaseModel):
@@ -116,25 +116,34 @@ class OrderService:
return OrderOutSchema.model_validate(order) if order else None
@classmethod
async def get_list(cls, auth: AuthSchema, params: OrderQueryParam, offset: int, limit: int) -> tuple[list, int]:
async def get_list(
cls,
auth: AuthSchema,
page_no: int,
page_size: int,
search: OrderQueryParam,
order_by: list[dict[str, str]] | None = None,
) -> tuple[list, int]:
"""
订单列表
参数:
- auth (AuthSchema): 认证信息模型
- params (OrderQueryParam): 查询参数
- offset (int): 偏移
- limit (int): 每页数量
- page_no (int): 当前页码
- page_size (int): 每页数
- search (OrderQueryParam): 查询参数
- order_by (list[dict] | None): 排序字段
返回:
- tuple[list, int]: (订单列表, 总数)
"""
offset = (page_no - 1) * page_size
rows, total = await OrderCRUD(auth).query(
tenant_id=params.tenant_id,
status=params.status,
order_type=params.order_type,
tenant_id=search.tenant_id,
status=search.status,
order_type=search.order_type,
offset=offset,
limit=limit,
limit=page_size,
)
items = [OrderOutSchema.model_validate(r) for r in rows]
return items, total