feat: 实现 IoT 卡轮询系统(支持千万级卡规模)
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m35s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m35s
实现功能: - 实名状态检查轮询(可配置间隔) - 卡流量检查轮询(支持跨月流量追踪) - 套餐检查与超额自动停机 - 分布式并发控制(Redis 信号量) - 手动触发轮询(单卡/批量/条件筛选) - 数据清理配置与执行 - 告警规则与历史记录 - 实时监控统计(队列/性能/并发) 性能优化: - Redis 缓存卡信息,减少 DB 查询 - Pipeline 批量写入 Redis - 异步流量记录写入 - 渐进式初始化(10万卡/批) 压测工具(scripts/benchmark/): - Mock Gateway 模拟上游服务 - 测试卡生成器 - 配置初始化脚本 - 实时监控脚本 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,4 +89,22 @@ func RegisterAdminRoutes(router fiber.Router, handlers *bootstrap.Handlers, midd
|
||||
if handlers.AdminOrder != nil {
|
||||
registerAdminOrderRoutes(authGroup, handlers.AdminOrder, doc, basePath)
|
||||
}
|
||||
if handlers.PollingConfig != nil {
|
||||
registerPollingConfigRoutes(authGroup, handlers.PollingConfig, doc, basePath)
|
||||
}
|
||||
if handlers.PollingConcurrency != nil {
|
||||
registerPollingConcurrencyRoutes(authGroup, handlers.PollingConcurrency, doc, basePath)
|
||||
}
|
||||
if handlers.PollingMonitoring != nil {
|
||||
registerPollingMonitoringRoutes(authGroup, handlers.PollingMonitoring, doc, basePath)
|
||||
}
|
||||
if handlers.PollingAlert != nil {
|
||||
registerPollingAlertRoutes(authGroup, handlers.PollingAlert, doc, basePath)
|
||||
}
|
||||
if handlers.PollingCleanup != nil {
|
||||
registerPollingCleanupRoutes(authGroup, handlers.PollingCleanup, doc, basePath)
|
||||
}
|
||||
if handlers.PollingManualTrigger != nil {
|
||||
registerPollingManualTriggerRoutes(authGroup, handlers.PollingManualTrigger, doc, basePath)
|
||||
}
|
||||
}
|
||||
|
||||
66
internal/routes/polling_alert.go
Normal file
66
internal/routes/polling_alert.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerPollingAlertRoutes 注册轮询告警路由
|
||||
func registerPollingAlertRoutes(router fiber.Router, handler *admin.PollingAlertHandler, doc *openapi.Generator, basePath string) {
|
||||
// 告警规则管理
|
||||
rules := router.Group("/polling-alert-rules")
|
||||
rulesPath := basePath + "/polling-alert-rules"
|
||||
|
||||
Register(rules, doc, rulesPath, "POST", "", handler.CreateRule, RouteSpec{
|
||||
Summary: "创建轮询告警规则",
|
||||
Tags: []string{"轮询管理-告警"},
|
||||
Input: new(dto.CreatePollingAlertRuleReq),
|
||||
Output: new(dto.PollingAlertRuleResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(rules, doc, rulesPath, "GET", "", handler.ListRules, RouteSpec{
|
||||
Summary: "获取轮询告警规则列表",
|
||||
Tags: []string{"轮询管理-告警"},
|
||||
Input: nil,
|
||||
Output: new(dto.PollingAlertRuleListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(rules, doc, rulesPath, "GET", "/:id", handler.GetRule, RouteSpec{
|
||||
Summary: "获取轮询告警规则详情",
|
||||
Tags: []string{"轮询管理-告警"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: new(dto.PollingAlertRuleResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(rules, doc, rulesPath, "PUT", "/:id", handler.UpdateRule, RouteSpec{
|
||||
Summary: "更新轮询告警规则",
|
||||
Tags: []string{"轮询管理-告警"},
|
||||
Input: new(dto.UpdatePollingAlertRuleParams),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(rules, doc, rulesPath, "DELETE", "/:id", handler.DeleteRule, RouteSpec{
|
||||
Summary: "删除轮询告警规则",
|
||||
Tags: []string{"轮询管理-告警"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
// 告警历史
|
||||
historyPath := basePath + "/polling-alert-history"
|
||||
Register(router, doc, historyPath, "GET", "/polling-alert-history", handler.ListHistory, RouteSpec{
|
||||
Summary: "获取轮询告警历史",
|
||||
Tags: []string{"轮询管理-告警"},
|
||||
Input: new(dto.ListPollingAlertHistoryReq),
|
||||
Output: new(dto.PollingAlertHistoryListResp),
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
92
internal/routes/polling_cleanup.go
Normal file
92
internal/routes/polling_cleanup.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerPollingCleanupRoutes 注册轮询数据清理路由
|
||||
func registerPollingCleanupRoutes(router fiber.Router, handler *admin.PollingCleanupHandler, doc *openapi.Generator, basePath string) {
|
||||
// 清理配置管理
|
||||
configs := router.Group("/data-cleanup-configs")
|
||||
configsPath := basePath + "/data-cleanup-configs"
|
||||
|
||||
Register(configs, doc, configsPath, "POST", "", handler.CreateConfig, RouteSpec{
|
||||
Summary: "创建数据清理配置",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: new(dto.CreateDataCleanupConfigReq),
|
||||
Output: new(dto.DataCleanupConfigResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, configsPath, "GET", "", handler.ListConfigs, RouteSpec{
|
||||
Summary: "获取数据清理配置列表",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: nil,
|
||||
Output: new(dto.DataCleanupConfigListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, configsPath, "GET", "/:id", handler.GetConfig, RouteSpec{
|
||||
Summary: "获取数据清理配置详情",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: new(dto.DataCleanupConfigResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, configsPath, "PUT", "/:id", handler.UpdateConfig, RouteSpec{
|
||||
Summary: "更新数据清理配置",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: new(dto.UpdateDataCleanupConfigParams),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, configsPath, "DELETE", "/:id", handler.DeleteConfig, RouteSpec{
|
||||
Summary: "删除数据清理配置",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
// 清理日志
|
||||
logsPath := basePath + "/data-cleanup-logs"
|
||||
Register(router, doc, logsPath, "GET", "/data-cleanup-logs", handler.ListLogs, RouteSpec{
|
||||
Summary: "获取数据清理日志列表",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: new(dto.ListDataCleanupLogReq),
|
||||
Output: new(dto.DataCleanupLogListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
// 清理操作
|
||||
cleanupPath := basePath + "/data-cleanup"
|
||||
Register(router, doc, cleanupPath+"/preview", "GET", "/data-cleanup/preview", handler.Preview, RouteSpec{
|
||||
Summary: "预览待清理数据",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: nil,
|
||||
Output: new(dto.DataCleanupPreviewResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(router, doc, cleanupPath+"/progress", "GET", "/data-cleanup/progress", handler.GetProgress, RouteSpec{
|
||||
Summary: "获取数据清理进度",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: nil,
|
||||
Output: new(dto.DataCleanupProgressResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(router, doc, cleanupPath+"/trigger", "POST", "/data-cleanup/trigger", handler.TriggerCleanup, RouteSpec{
|
||||
Summary: "手动触发数据清理",
|
||||
Tags: []string{"轮询管理-数据清理"},
|
||||
Input: new(dto.TriggerDataCleanupReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
47
internal/routes/polling_concurrency.go
Normal file
47
internal/routes/polling_concurrency.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerPollingConcurrencyRoutes 注册轮询并发控制路由
|
||||
func registerPollingConcurrencyRoutes(router fiber.Router, handler *admin.PollingConcurrencyHandler, doc *openapi.Generator, basePath string) {
|
||||
concurrency := router.Group("/polling-concurrency")
|
||||
groupPath := basePath + "/polling-concurrency"
|
||||
|
||||
Register(concurrency, doc, groupPath, "GET", "", handler.List, RouteSpec{
|
||||
Summary: "获取轮询并发配置列表",
|
||||
Tags: []string{"轮询管理-并发控制"},
|
||||
Input: nil,
|
||||
Output: new(dto.PollingConcurrencyListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(concurrency, doc, groupPath, "POST", "/reset", handler.Reset, RouteSpec{
|
||||
Summary: "重置轮询并发计数",
|
||||
Tags: []string{"轮询管理-并发控制"},
|
||||
Input: new(dto.ResetPollingConcurrencyReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(concurrency, doc, groupPath, "GET", "/:task_type", handler.Get, RouteSpec{
|
||||
Summary: "获取指定任务类型的并发配置",
|
||||
Tags: []string{"轮询管理-并发控制"},
|
||||
Input: new(dto.GetPollingConcurrencyReq),
|
||||
Output: new(dto.PollingConcurrencyResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(concurrency, doc, groupPath, "PUT", "/:task_type", handler.Update, RouteSpec{
|
||||
Summary: "更新轮询并发配置",
|
||||
Tags: []string{"轮询管理-并发控制"},
|
||||
Input: new(dto.UpdatePollingConcurrencyReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
71
internal/routes/polling_config.go
Normal file
71
internal/routes/polling_config.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerPollingConfigRoutes 注册轮询配置管理路由
|
||||
func registerPollingConfigRoutes(router fiber.Router, handler *admin.PollingConfigHandler, doc *openapi.Generator, basePath string) {
|
||||
configs := router.Group("/polling-configs")
|
||||
groupPath := basePath + "/polling-configs"
|
||||
|
||||
Register(configs, doc, groupPath, "GET", "", handler.List, RouteSpec{
|
||||
Summary: "获取轮询配置列表",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: new(dto.PollingConfigListRequest),
|
||||
Output: new(dto.PollingConfigPageResult),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, groupPath, "POST", "", handler.Create, RouteSpec{
|
||||
Summary: "创建轮询配置",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: new(dto.CreatePollingConfigRequest),
|
||||
Output: new(dto.PollingConfigResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, groupPath, "GET", "/enabled", handler.ListEnabled, RouteSpec{
|
||||
Summary: "获取所有启用的配置",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: nil,
|
||||
Output: []dto.PollingConfigResponse{},
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, groupPath, "GET", "/:id", handler.Get, RouteSpec{
|
||||
Summary: "获取轮询配置详情",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: new(dto.PollingConfigResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, groupPath, "PUT", "/:id", handler.Update, RouteSpec{
|
||||
Summary: "更新轮询配置",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: new(dto.UpdatePollingConfigParams),
|
||||
Output: new(dto.PollingConfigResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, groupPath, "DELETE", "/:id", handler.Delete, RouteSpec{
|
||||
Summary: "删除轮询配置",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(configs, doc, groupPath, "PUT", "/:id/status", handler.UpdateStatus, RouteSpec{
|
||||
Summary: "更新轮询配置状态",
|
||||
Tags: []string{"轮询配置管理"},
|
||||
Input: new(dto.UpdatePollingConfigStatusParams),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
63
internal/routes/polling_manual_trigger.go
Normal file
63
internal/routes/polling_manual_trigger.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerPollingManualTriggerRoutes 注册轮询手动触发路由
|
||||
func registerPollingManualTriggerRoutes(router fiber.Router, handler *admin.PollingManualTriggerHandler, doc *openapi.Generator, basePath string) {
|
||||
group := router.Group("/polling-manual-trigger")
|
||||
groupPath := basePath + "/polling-manual-trigger"
|
||||
|
||||
Register(group, doc, groupPath, "POST", "/single", handler.TriggerSingle, RouteSpec{
|
||||
Summary: "单卡手动触发",
|
||||
Tags: []string{"轮询管理-手动触发"},
|
||||
Input: new(dto.TriggerSingleReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(group, doc, groupPath, "POST", "/batch", handler.TriggerBatch, RouteSpec{
|
||||
Summary: "批量手动触发",
|
||||
Tags: []string{"轮询管理-手动触发"},
|
||||
Input: new(dto.TriggerBatchReq),
|
||||
Output: new(dto.ManualTriggerLogResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(group, doc, groupPath, "POST", "/by-condition", handler.TriggerByCondition, RouteSpec{
|
||||
Summary: "条件筛选触发",
|
||||
Tags: []string{"轮询管理-手动触发"},
|
||||
Input: new(dto.TriggerByConditionReq),
|
||||
Output: new(dto.ManualTriggerLogResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(group, doc, groupPath, "GET", "/status", handler.GetStatus, RouteSpec{
|
||||
Summary: "获取手动触发状态",
|
||||
Tags: []string{"轮询管理-手动触发"},
|
||||
Input: nil,
|
||||
Output: new(dto.ManualTriggerStatusResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(group, doc, groupPath, "GET", "/history", handler.ListHistory, RouteSpec{
|
||||
Summary: "获取手动触发历史",
|
||||
Tags: []string{"轮询管理-手动触发"},
|
||||
Input: new(dto.ListManualTriggerLogReq),
|
||||
Output: new(dto.ManualTriggerLogListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(group, doc, groupPath, "POST", "/cancel", handler.CancelTrigger, RouteSpec{
|
||||
Summary: "取消手动触发任务",
|
||||
Tags: []string{"轮询管理-手动触发"},
|
||||
Input: new(dto.CancelTriggerReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
47
internal/routes/polling_monitoring.go
Normal file
47
internal/routes/polling_monitoring.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerPollingMonitoringRoutes 注册轮询监控路由
|
||||
func registerPollingMonitoringRoutes(router fiber.Router, handler *admin.PollingMonitoringHandler, doc *openapi.Generator, basePath string) {
|
||||
stats := router.Group("/polling-stats")
|
||||
groupPath := basePath + "/polling-stats"
|
||||
|
||||
Register(stats, doc, groupPath, "GET", "", handler.GetOverview, RouteSpec{
|
||||
Summary: "获取轮询总览统计",
|
||||
Tags: []string{"轮询管理-监控"},
|
||||
Input: nil,
|
||||
Output: new(dto.PollingOverviewResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(stats, doc, groupPath, "GET", "/queues", handler.GetQueueStatuses, RouteSpec{
|
||||
Summary: "获取轮询队列状态",
|
||||
Tags: []string{"轮询管理-监控"},
|
||||
Input: nil,
|
||||
Output: new(dto.PollingQueueStatusListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(stats, doc, groupPath, "GET", "/tasks", handler.GetTaskStatuses, RouteSpec{
|
||||
Summary: "获取轮询任务统计",
|
||||
Tags: []string{"轮询管理-监控"},
|
||||
Input: nil,
|
||||
Output: new(dto.PollingTaskStatsListResp),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(stats, doc, groupPath, "GET", "/init-progress", handler.GetInitProgress, RouteSpec{
|
||||
Summary: "获取轮询初始化进度",
|
||||
Tags: []string{"轮询管理-监控"},
|
||||
Input: nil,
|
||||
Output: new(dto.PollingInitProgressResp),
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user