refactor: 统一分页组件和UI优化
- 使用公共Pagination组件统一各页面的分页逻辑 - 优化exceptions页面异常列表展示 - 简化settings/rules页面规则管理 - 后端tasks.py增加分页参数支持
This commit is contained in:
+41
-21
@@ -21,19 +21,19 @@ from app.schemas.user import UserResponse
|
||||
router = APIRouter(prefix="/api/tasks", tags=["对账任务"])
|
||||
|
||||
|
||||
@router.get("/", response_model=List[Dict[str, Any]])
|
||||
@router.get("/", response_model=Dict[str, Any])
|
||||
async def list_tasks(
|
||||
period: Optional[str] = Query(None, description="筛选月份,格式: 2026-04"),
|
||||
status: Optional[str] = Query(None, description="筛选状态"),
|
||||
skip: int = Query(0, ge=0, description="跳过记录数"),
|
||||
limit: int = Query(50, ge=1, le=100, description="返回记录数"),
|
||||
page: int = Query(1, ge=1, description="页码"),
|
||||
page_size: int = Query(10, ge=1, le=100, description="每页数量"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
company_id: Optional[int] = Depends(get_current_company_id),
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
获取对账任务列表
|
||||
|
||||
支持按月份和状态筛选
|
||||
支持按月份和状态筛选,返回分页结构
|
||||
"""
|
||||
# 构建查询
|
||||
query = select(ReconciliationTask).where(
|
||||
@@ -46,27 +46,45 @@ async def list_tasks(
|
||||
if status:
|
||||
query = query.where(ReconciliationTask.status == status)
|
||||
|
||||
# 按创建时间倒序
|
||||
query = query.order_by(ReconciliationTask.created_at.desc())
|
||||
# 计算总数
|
||||
count_query = select(func.count()).select_from(ReconciliationTask).where(
|
||||
ReconciliationTask.company_id == company_id
|
||||
)
|
||||
if period:
|
||||
count_query = count_query.where(ReconciliationTask.period == period)
|
||||
if status:
|
||||
count_query = count_query.where(ReconciliationTask.status == status)
|
||||
count_result = await db.execute(count_query)
|
||||
total = count_result.scalar() or 0
|
||||
|
||||
# 分页
|
||||
query = query.offset(skip).limit(limit)
|
||||
# 按创建时间倒序 + 分页
|
||||
skip = (page - 1) * page_size
|
||||
query = query.order_by(ReconciliationTask.created_at.desc())
|
||||
query = query.offset(skip).limit(page_size)
|
||||
|
||||
result = await db.execute(query)
|
||||
tasks = result.scalars().all()
|
||||
|
||||
return [
|
||||
{
|
||||
"id": task.id,
|
||||
"period": task.period,
|
||||
"status": task.status,
|
||||
"total_employees": task.total_employees,
|
||||
"matched_count": task.matched_count,
|
||||
"exception_count": task.exception_count,
|
||||
"created_at": task.created_at.isoformat() if task.created_at else None,
|
||||
}
|
||||
for task in tasks
|
||||
]
|
||||
return {
|
||||
"items": [
|
||||
{
|
||||
"id": task.id,
|
||||
"name": f"{task.period} 对账任务",
|
||||
"period": task.period,
|
||||
"status": task.status,
|
||||
"total_employees": task.total_employees,
|
||||
"matched_count": task.matched_count,
|
||||
"exception_count": task.exception_count,
|
||||
"created_at": task.created_at.isoformat() if task.created_at else None,
|
||||
"completed_at": task.updated_at.isoformat() if task.status == "COMPLETED" and task.updated_at else None,
|
||||
}
|
||||
for task in tasks
|
||||
],
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"total_pages": (total + page_size - 1) // page_size if page_size > 0 else 0,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/stats", response_model=Dict[str, Any])
|
||||
@@ -169,6 +187,7 @@ async def get_task(
|
||||
|
||||
return {
|
||||
"id": task.id,
|
||||
"name": f"{task.period} 对账任务",
|
||||
"period": task.period,
|
||||
"status": task.status,
|
||||
"total_employees": task.total_employees,
|
||||
@@ -177,5 +196,6 @@ async def get_task(
|
||||
"file_ids": task.file_ids,
|
||||
"reconciliation_result": task.reconciliation_result,
|
||||
"created_at": task.created_at.isoformat() if task.created_at else None,
|
||||
"completed_at": task.updated_at.isoformat() if task.status == "COMPLETED" and task.updated_at else None,
|
||||
"error_message": task.error_message,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user