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>
194 lines
5.9 KiB
Go
194 lines
5.9 KiB
Go
package admin
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
pollingService "github.com/break/junhong_cmp_fiber/internal/service/polling"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
// PollingConfigHandler 轮询配置 Handler
|
|
type PollingConfigHandler struct {
|
|
service *pollingService.ConfigService
|
|
}
|
|
|
|
// NewPollingConfigHandler 创建轮询配置 Handler 实例
|
|
func NewPollingConfigHandler(service *pollingService.ConfigService) *PollingConfigHandler {
|
|
return &PollingConfigHandler{service: service}
|
|
}
|
|
|
|
// List 获取轮询配置列表
|
|
// @Summary 获取轮询配置列表
|
|
// @Description 获取轮询配置列表,支持分页和筛选
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param page query int false "页码"
|
|
// @Param page_size query int false "每页数量"
|
|
// @Param status query int false "状态 (1:启用, 0:禁用)"
|
|
// @Param card_condition query string false "卡状态条件"
|
|
// @Param card_category query string false "卡业务类型"
|
|
// @Param carrier_id query int false "运营商ID"
|
|
// @Param config_name query string false "配置名称"
|
|
// @Success 200 {object} response.Response{data=dto.PollingConfigPageResult}
|
|
// @Router /api/admin/polling-configs [get]
|
|
func (h *PollingConfigHandler) List(c *fiber.Ctx) error {
|
|
var req dto.PollingConfigListRequest
|
|
if err := c.QueryParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
|
|
configs, total, err := h.service.List(c.UserContext(), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.SuccessWithPagination(c, configs, total, req.Page, req.PageSize)
|
|
}
|
|
|
|
// Create 创建轮询配置
|
|
// @Summary 创建轮询配置
|
|
// @Description 创建新的轮询配置
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body dto.CreatePollingConfigRequest true "创建轮询配置请求"
|
|
// @Success 200 {object} response.Response{data=dto.PollingConfigResponse}
|
|
// @Router /api/admin/polling-configs [post]
|
|
func (h *PollingConfigHandler) Create(c *fiber.Ctx) error {
|
|
var req dto.CreatePollingConfigRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
|
|
config, err := h.service.Create(c.UserContext(), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, config)
|
|
}
|
|
|
|
// Get 获取轮询配置详情
|
|
// @Summary 获取轮询配置详情
|
|
// @Description 根据 ID 获取轮询配置详情
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int true "配置ID"
|
|
// @Success 200 {object} response.Response{data=dto.PollingConfigResponse}
|
|
// @Router /api/admin/polling-configs/{id} [get]
|
|
func (h *PollingConfigHandler) Get(c *fiber.Ctx) error {
|
|
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的配置 ID")
|
|
}
|
|
|
|
config, err := h.service.Get(c.UserContext(), uint(id))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, config)
|
|
}
|
|
|
|
// Update 更新轮询配置
|
|
// @Summary 更新轮询配置
|
|
// @Description 根据 ID 更新轮询配置
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int true "配置ID"
|
|
// @Param body body dto.UpdatePollingConfigRequest true "更新轮询配置请求"
|
|
// @Success 200 {object} response.Response{data=dto.PollingConfigResponse}
|
|
// @Router /api/admin/polling-configs/{id} [put]
|
|
func (h *PollingConfigHandler) Update(c *fiber.Ctx) error {
|
|
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的配置 ID")
|
|
}
|
|
|
|
var req dto.UpdatePollingConfigRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
|
|
config, err := h.service.Update(c.UserContext(), uint(id), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, config)
|
|
}
|
|
|
|
// Delete 删除轮询配置
|
|
// @Summary 删除轮询配置
|
|
// @Description 根据 ID 删除轮询配置
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int true "配置ID"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /api/admin/polling-configs/{id} [delete]
|
|
func (h *PollingConfigHandler) Delete(c *fiber.Ctx) error {
|
|
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的配置 ID")
|
|
}
|
|
|
|
if err := h.service.Delete(c.UserContext(), uint(id)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, nil)
|
|
}
|
|
|
|
// UpdateStatus 更新轮询配置状态
|
|
// @Summary 更新轮询配置状态
|
|
// @Description 启用或禁用轮询配置
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int true "配置ID"
|
|
// @Param body body dto.UpdatePollingConfigStatusRequest true "更新状态请求"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /api/admin/polling-configs/{id}/status [put]
|
|
func (h *PollingConfigHandler) UpdateStatus(c *fiber.Ctx) error {
|
|
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的配置 ID")
|
|
}
|
|
|
|
var req dto.UpdatePollingConfigStatusRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam)
|
|
}
|
|
|
|
if err := h.service.UpdateStatus(c.UserContext(), uint(id), req.Status); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, nil)
|
|
}
|
|
|
|
// ListEnabled 获取所有启用的配置
|
|
// @Summary 获取所有启用的配置
|
|
// @Description 获取所有启用状态的轮询配置,按优先级排序
|
|
// @Tags 轮询配置管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} response.Response{data=[]dto.PollingConfigResponse}
|
|
// @Router /api/admin/polling-configs/enabled [get]
|
|
func (h *PollingConfigHandler) ListEnabled(c *fiber.Ctx) error {
|
|
configs, err := h.service.ListEnabled(c.UserContext())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, configs)
|
|
}
|