|
@@ -712,17 +712,26 @@ def has_matching_column_comments(
|
|
|
|
|
|
|
|
|
@router.post("/reports_by_creator/")
|
|
|
+@router.get("/reports_by_creator/")
|
|
|
async def get_reports_by_creator(
|
|
|
- # creator_id: str, # 精确匹配的必选参数
|
|
|
- field_comment: Optional[str] = Query(None, description="Optional comment of the field to match"),
|
|
|
- db: Session = Depends(get_db),
|
|
|
- creator_id = Depends(valid_access_token)
|
|
|
+ field_comment: Optional[str] = Query(None, description="Optional comment of the field to match"),
|
|
|
+ page: int = Query(default=1, gt=0), # 分页参数:当前页码,默认为1
|
|
|
+ pageSize: int = Query(default=10, gt=0), # 分页参数:每页大小,默认为10
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ creator_id=Depends(valid_access_token)
|
|
|
):
|
|
|
# 获取数据库Inspector
|
|
|
inspector: Inspector = inspect(db.bind)
|
|
|
|
|
|
# 查询 ReportManagement 表以获取所有相关的记录
|
|
|
- reports = db.query(ReportManagement).filter(ReportManagement.creator_id == creator_id).all()
|
|
|
+ query = db.query(ReportManagement).filter(ReportManagement.creator_id == creator_id)
|
|
|
+
|
|
|
+ # 计算总数
|
|
|
+ total_count = query.count()
|
|
|
+
|
|
|
+ # 分页查询
|
|
|
+ offset = (page - 1) * pageSize
|
|
|
+ reports = query.offset(offset).limit(pageSize).all()
|
|
|
|
|
|
# 存储结果
|
|
|
results = []
|
|
@@ -749,7 +758,19 @@ async def get_reports_by_creator(
|
|
|
if not results:
|
|
|
raise HTTPException(status_code=404, detail="没有找到与该创建人ID相关的记录")
|
|
|
|
|
|
- return {"data": results}
|
|
|
+ # 构造分页结果
|
|
|
+ result = {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "查询成功",
|
|
|
+ "total": total_count,
|
|
|
+ "totalPages": (total_count + pageSize - 1) // pageSize,
|
|
|
+ "page": page,
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "data": results
|
|
|
+ }
|
|
|
+
|
|
|
+ return result
|
|
|
+
|
|
|
|
|
|
|
|
|
@router.put("/update_collection_status/")
|