ListPendingCollections

This commit is contained in:
2025-10-18 15:43:27 +08:00
parent 6a93346e87
commit fab26ffca4
4 changed files with 167 additions and 6 deletions

View File

@@ -215,3 +215,51 @@ func (c *Controller) ListTaskExecutionLogs(ctx *gin.Context) {
c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取任务执行日志成功", resp, actionType, "获取任务执行日志成功", req)
}
// ListPendingCollections godoc
// @Summary 获取待采集请求列表
// @Description 根据提供的过滤条件,分页获取待采集请求
// @Tags 数据监控
// @Security BearerAuth
// @Produce json
// @Param query query dto.ListPendingCollectionRequest true "查询参数"
// @Success 200 {object} controller.Response{data=dto.ListPendingCollectionResponse}
// @Router /api/v1/monitor/pending-collections [get]
func (c *Controller) ListPendingCollections(ctx *gin.Context) {
const actionType = "获取待采集请求列表"
var req dto.ListPendingCollectionRequest
if err := ctx.ShouldBindQuery(&req); err != nil {
c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
return
}
opts := repository.PendingCollectionListOptions{
DeviceID: req.DeviceID,
OrderBy: req.OrderBy,
StartTime: req.StartTime,
EndTime: req.EndTime,
}
if req.Status != nil {
status := models.PendingCollectionStatus(*req.Status)
opts.Status = &status
}
data, total, err := c.monitorService.ListPendingCollections(opts, req.Page, req.PageSize)
if err != nil {
if errors.Is(err, repository.ErrInvalidPagination) {
c.logger.Warnf("%s: 无效的分页参数: %v", actionType, err)
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的分页参数: "+err.Error(), actionType, "无效分页参数", req)
return
}
c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取待采集请求失败: "+err.Error(), actionType, "服务层查询失败", req)
return
}
resp := dto.NewListPendingCollectionResponse(data, total, req.Page, req.PageSize)
c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取待采集请求成功", resp, actionType, "获取待采集请求成功", req)
}