fix: 修复数据清理预览接口 panic 及路由文档路径翻倍问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m12s

1. CountOldRecords 改用 GORM .Scan() 替代 .Row().Scan(),避免查询不存在的表时 nil pointer panic
2. polling_cleanup 路由注册的 basePath 参数去掉多余拼接,修复生成的 OpenAPI 文档路径翻倍
This commit is contained in:
2026-03-30 15:09:14 +08:00
parent 06ee422e34
commit 33e7f99fdc
2 changed files with 7 additions and 10 deletions

View File

@@ -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),

View File

@@ -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
}
}