diff --git a/internal/routes/polling_cleanup.go b/internal/routes/polling_cleanup.go index 89db4e6..3a503bb 100644 --- a/internal/routes/polling_cleanup.go +++ b/internal/routes/polling_cleanup.go @@ -55,8 +55,7 @@ func registerPollingCleanupRoutes(router fiber.Router, handler *admin.PollingCle }) // 清理日志 - logsPath := basePath + "/data-cleanup-logs" - Register(router, doc, logsPath, "GET", "/data-cleanup-logs", handler.ListLogs, RouteSpec{ + Register(router, doc, basePath, "GET", "/data-cleanup-logs", handler.ListLogs, RouteSpec{ Summary: "获取数据清理日志列表", Tags: []string{"轮询管理-数据清理"}, Input: new(dto.ListDataCleanupLogReq), @@ -65,8 +64,7 @@ func registerPollingCleanupRoutes(router fiber.Router, handler *admin.PollingCle }) // 清理操作 - cleanupPath := basePath + "/data-cleanup" - Register(router, doc, cleanupPath+"/preview", "GET", "/data-cleanup/preview", handler.Preview, RouteSpec{ + Register(router, doc, basePath, "GET", "/data-cleanup/preview", handler.Preview, RouteSpec{ Summary: "预览待清理数据", Tags: []string{"轮询管理-数据清理"}, Input: nil, @@ -74,7 +72,7 @@ func registerPollingCleanupRoutes(router fiber.Router, handler *admin.PollingCle Auth: true, }) - Register(router, doc, cleanupPath+"/progress", "GET", "/data-cleanup/progress", handler.GetProgress, RouteSpec{ + Register(router, doc, basePath, "GET", "/data-cleanup/progress", handler.GetProgress, RouteSpec{ Summary: "获取数据清理进度", Tags: []string{"轮询管理-数据清理"}, Input: nil, @@ -82,7 +80,7 @@ func registerPollingCleanupRoutes(router fiber.Router, handler *admin.PollingCle Auth: true, }) - Register(router, doc, cleanupPath+"/trigger", "POST", "/data-cleanup/trigger", handler.TriggerCleanup, RouteSpec{ + Register(router, doc, basePath, "POST", "/data-cleanup/trigger", handler.TriggerCleanup, RouteSpec{ Summary: "手动触发数据清理", Tags: []string{"轮询管理-数据清理"}, Input: new(dto.TriggerDataCleanupReq), diff --git a/internal/store/postgres/polling_cleanup_store.go b/internal/store/postgres/polling_cleanup_store.go index 1c6c735..521554a 100644 --- a/internal/store/postgres/polling_cleanup_store.go +++ b/internal/store/postgres/polling_cleanup_store.go @@ -193,12 +193,11 @@ func (s *DataCleanupLogStore) CountOldRecords(ctx context.Context, tableName str return 0, err } default: - // 对于其他表,使用原始 SQL - row := s.db.WithContext(ctx).Raw( + // 对于其他表,使用原始 SQL(使用 GORM 的 Scan 避免 Row() 返回 nil 导致 panic) + if err := s.db.WithContext(ctx).Raw( "SELECT COUNT(*) FROM "+tableName+" WHERE created_at < ?", cutoffTime, - ).Row() - if err := row.Scan(&count); err != nil { + ).Scan(&count).Error; err != nil { return 0, err } }