diff --git a/internal/model/dto/polling_config_dto.go b/internal/model/dto/polling_config_dto.go index 5de6b33..7d05ff5 100644 --- a/internal/model/dto/polling_config_dto.go +++ b/internal/model/dto/polling_config_dto.go @@ -2,28 +2,32 @@ package dto // CreatePollingConfigRequest 创建轮询配置请求 type CreatePollingConfigRequest struct { - ConfigName string `json:"config_name" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" description:"配置名称"` - CardCondition string `json:"card_condition" validate:"omitempty,oneof=not_real_name real_name activated suspended" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"` - CardCategory string `json:"card_category" validate:"omitempty,oneof=normal industry" description:"卡业务类型 (normal:普通卡, industry:行业卡)"` - CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"` - Priority int `json:"priority" validate:"required,min=1,max=1000" required:"true" minimum:"1" maximum:"1000" description:"优先级(数字越小优先级越高)"` - RealnameCheckInterval *int `json:"realname_check_interval" validate:"omitempty,min=30" minimum:"30" description:"实名检查间隔(秒),NULL表示不检查,最小30秒"` - CarddataCheckInterval *int `json:"carddata_check_interval" validate:"omitempty,min=60" minimum:"60" description:"流量检查间隔(秒),NULL表示不检查,最小60秒"` - PackageCheckInterval *int `json:"package_check_interval" validate:"omitempty,min=60" minimum:"60" description:"套餐检查间隔(秒),NULL表示不检查,最小60秒"` - Description string `json:"description" validate:"omitempty,max=500" maxLength:"500" description:"配置说明"` + ConfigName string `json:"config_name" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" description:"配置名称"` + CardCondition string `json:"card_condition" validate:"omitempty,oneof=not_real_name real_name activated suspended" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"` + CardCategory string `json:"card_category" validate:"omitempty,oneof=normal industry" description:"卡业务类型 (normal:普通卡, industry:行业卡)"` + CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"` + Priority int `json:"priority" validate:"required,min=1,max=1000" required:"true" minimum:"1" maximum:"1000" description:"优先级(数字越小优先级越高)"` + RealnameCheckInterval *int `json:"realname_check_interval" validate:"omitempty,min=30" minimum:"30" description:"实名检查间隔(秒),NULL表示不检查,最小30秒"` + CarddataCheckInterval *int `json:"carddata_check_interval" validate:"omitempty,min=60" minimum:"60" description:"流量检查间隔(秒),NULL表示不检查,最小60秒"` + PackageCheckInterval *int `json:"package_check_interval" validate:"omitempty,min=60" minimum:"60" description:"套餐检查间隔(秒),NULL表示不检查,最小60秒"` + ProtectCheckInterval *int `json:"protect_check_interval" validate:"omitempty,min=30" minimum:"30" description:"保护期一致性检查间隔(秒),NULL表示不检查,最小30秒"` + CardStatusCheckInterval *int `json:"card_status_check_interval" validate:"omitempty,min=30" minimum:"30" description:"卡状态检查间隔(秒),NULL表示不检查,最小30秒"` + Description string `json:"description" validate:"omitempty,max=500" maxLength:"500" description:"配置说明"` } // UpdatePollingConfigRequest 更新轮询配置请求 type UpdatePollingConfigRequest struct { - ConfigName *string `json:"config_name" validate:"omitempty,min=1,max=100" minLength:"1" maxLength:"100" description:"配置名称"` - CardCondition *string `json:"card_condition" validate:"omitempty,oneof=not_real_name real_name activated suspended" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"` - CardCategory *string `json:"card_category" validate:"omitempty,oneof=normal industry" description:"卡业务类型 (normal:普通卡, industry:行业卡)"` - CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"` - Priority *int `json:"priority" validate:"omitempty,min=1,max=1000" minimum:"1" maximum:"1000" description:"优先级(数字越小优先级越高)"` - RealnameCheckInterval *int `json:"realname_check_interval" validate:"omitempty,min=30" minimum:"30" description:"实名检查间隔(秒),NULL表示不检查,最小30秒"` - CarddataCheckInterval *int `json:"carddata_check_interval" validate:"omitempty,min=60" minimum:"60" description:"流量检查间隔(秒),NULL表示不检查,最小60秒"` - PackageCheckInterval *int `json:"package_check_interval" validate:"omitempty,min=60" minimum:"60" description:"套餐检查间隔(秒),NULL表示不检查,最小60秒"` - Description *string `json:"description" validate:"omitempty,max=500" maxLength:"500" description:"配置说明"` + ConfigName *string `json:"config_name" validate:"omitempty,min=1,max=100" minLength:"1" maxLength:"100" description:"配置名称"` + CardCondition *string `json:"card_condition" validate:"omitempty,oneof=not_real_name real_name activated suspended" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"` + CardCategory *string `json:"card_category" validate:"omitempty,oneof=normal industry" description:"卡业务类型 (normal:普通卡, industry:行业卡)"` + CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"` + Priority *int `json:"priority" validate:"omitempty,min=1,max=1000" minimum:"1" maximum:"1000" description:"优先级(数字越小优先级越高)"` + RealnameCheckInterval *int `json:"realname_check_interval" validate:"omitempty,min=30" minimum:"30" description:"实名检查间隔(秒),NULL表示不检查,最小30秒"` + CarddataCheckInterval *int `json:"carddata_check_interval" validate:"omitempty,min=60" minimum:"60" description:"流量检查间隔(秒),NULL表示不检查,最小60秒"` + PackageCheckInterval *int `json:"package_check_interval" validate:"omitempty,min=60" minimum:"60" description:"套餐检查间隔(秒),NULL表示不检查,最小60秒"` + ProtectCheckInterval *int `json:"protect_check_interval" validate:"omitempty,min=30" minimum:"30" description:"保护期一致性检查间隔(秒),NULL表示不检查,最小30秒"` + CardStatusCheckInterval *int `json:"card_status_check_interval" validate:"omitempty,min=30" minimum:"30" description:"卡状态检查间隔(秒),NULL表示不检查,最小30秒"` + Description *string `json:"description" validate:"omitempty,max=500" maxLength:"500" description:"配置说明"` } // PollingConfigListRequest 轮询配置列表请求 @@ -44,19 +48,21 @@ type UpdatePollingConfigStatusRequest struct { // PollingConfigResponse 轮询配置响应 type PollingConfigResponse struct { - ID uint `json:"id" description:"配置ID"` - ConfigName string `json:"config_name" description:"配置名称"` - CardCondition string `json:"card_condition" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"` - CardCategory string `json:"card_category" description:"卡业务类型 (normal:普通卡, industry:行业卡)"` - CarrierID *uint `json:"carrier_id" description:"运营商ID"` - Priority int `json:"priority" description:"优先级(数字越小优先级越高)"` - RealnameCheckInterval *int `json:"realname_check_interval" description:"实名检查间隔(秒),NULL表示不检查"` - CarddataCheckInterval *int `json:"carddata_check_interval" description:"流量检查间隔(秒),NULL表示不检查"` - PackageCheckInterval *int `json:"package_check_interval" description:"套餐检查间隔(秒),NULL表示不检查"` - Status int16 `json:"status" description:"状态 (1:启用, 0:禁用)"` - Description string `json:"description" description:"配置说明"` - CreatedAt string `json:"created_at" description:"创建时间"` - UpdatedAt string `json:"updated_at" description:"更新时间"` + ID uint `json:"id" description:"配置ID"` + ConfigName string `json:"config_name" description:"配置名称"` + CardCondition string `json:"card_condition" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"` + CardCategory string `json:"card_category" description:"卡业务类型 (normal:普通卡, industry:行业卡)"` + CarrierID *uint `json:"carrier_id" description:"运营商ID"` + Priority int `json:"priority" description:"优先级(数字越小优先级越高)"` + RealnameCheckInterval *int `json:"realname_check_interval" description:"实名检查间隔(秒),NULL表示不检查"` + CarddataCheckInterval *int `json:"carddata_check_interval" description:"流量检查间隔(秒),NULL表示不检查"` + PackageCheckInterval *int `json:"package_check_interval" description:"套餐检查间隔(秒),NULL表示不检查"` + ProtectCheckInterval *int `json:"protect_check_interval" description:"保护期一致性检查间隔(秒),NULL表示不检查"` + CardStatusCheckInterval *int `json:"card_status_check_interval" description:"卡状态检查间隔(秒),NULL表示不检查"` + Status int16 `json:"status" description:"状态 (1:启用, 0:禁用)"` + Description string `json:"description" description:"配置说明"` + CreatedAt string `json:"created_at" description:"创建时间"` + UpdatedAt string `json:"updated_at" description:"更新时间"` } // UpdatePollingConfigParams 更新轮询配置参数 diff --git a/internal/service/polling/config_service.go b/internal/service/polling/config_service.go index 6dcce82..d3f0848 100644 --- a/internal/service/polling/config_service.go +++ b/internal/service/polling/config_service.go @@ -39,23 +39,27 @@ func (s *ConfigService) Create(ctx context.Context, req *dto.CreatePollingConfig } // 验证检查间隔(至少一个不为空) - if req.RealnameCheckInterval == nil && req.CarddataCheckInterval == nil && req.PackageCheckInterval == nil { + if req.RealnameCheckInterval == nil && req.CarddataCheckInterval == nil && + req.PackageCheckInterval == nil && req.ProtectCheckInterval == nil && + req.CardStatusCheckInterval == nil { return nil, errors.New(errors.CodeInvalidParam, "至少需要配置一种检查间隔") } config := &model.PollingConfig{ - ConfigName: req.ConfigName, - CardCondition: req.CardCondition, - CardCategory: req.CardCategory, - CarrierID: req.CarrierID, - Priority: req.Priority, - RealnameCheckInterval: req.RealnameCheckInterval, - CarddataCheckInterval: req.CarddataCheckInterval, - PackageCheckInterval: req.PackageCheckInterval, - Status: 1, // 默认启用 - Description: req.Description, - CreatedBy: ¤tUserID, - UpdatedBy: ¤tUserID, + ConfigName: req.ConfigName, + CardCondition: req.CardCondition, + CardCategory: req.CardCategory, + CarrierID: req.CarrierID, + Priority: req.Priority, + RealnameCheckInterval: req.RealnameCheckInterval, + CarddataCheckInterval: req.CarddataCheckInterval, + PackageCheckInterval: req.PackageCheckInterval, + ProtectCheckInterval: req.ProtectCheckInterval, + CardStatusCheckInterval: req.CardStatusCheckInterval, + Status: 1, + Description: req.Description, + CreatedBy: ¤tUserID, + UpdatedBy: ¤tUserID, } if err := s.configStore.Create(ctx, config); err != nil { @@ -122,6 +126,12 @@ func (s *ConfigService) Update(ctx context.Context, id uint, req *dto.UpdatePoll if req.PackageCheckInterval != nil { config.PackageCheckInterval = req.PackageCheckInterval } + if req.ProtectCheckInterval != nil { + config.ProtectCheckInterval = req.ProtectCheckInterval + } + if req.CardStatusCheckInterval != nil { + config.CardStatusCheckInterval = req.CardStatusCheckInterval + } if req.Description != nil { config.Description = *req.Description } @@ -235,18 +245,20 @@ func (s *ConfigService) ListEnabled(ctx context.Context) ([]*dto.PollingConfigRe // toResponse 转换为响应 DTO func (s *ConfigService) toResponse(c *model.PollingConfig) *dto.PollingConfigResponse { return &dto.PollingConfigResponse{ - ID: c.ID, - ConfigName: c.ConfigName, - CardCondition: c.CardCondition, - CardCategory: c.CardCategory, - CarrierID: c.CarrierID, - Priority: c.Priority, - RealnameCheckInterval: c.RealnameCheckInterval, - CarddataCheckInterval: c.CarddataCheckInterval, - PackageCheckInterval: c.PackageCheckInterval, - Status: c.Status, - Description: c.Description, - CreatedAt: c.CreatedAt.Format(time.RFC3339), - UpdatedAt: c.UpdatedAt.Format(time.RFC3339), + ID: c.ID, + ConfigName: c.ConfigName, + CardCondition: c.CardCondition, + CardCategory: c.CardCategory, + CarrierID: c.CarrierID, + Priority: c.Priority, + RealnameCheckInterval: c.RealnameCheckInterval, + CarddataCheckInterval: c.CarddataCheckInterval, + PackageCheckInterval: c.PackageCheckInterval, + ProtectCheckInterval: c.ProtectCheckInterval, + CardStatusCheckInterval: c.CardStatusCheckInterval, + Status: c.Status, + Description: c.Description, + CreatedAt: c.CreatedAt.Format(time.RFC3339), + UpdatedAt: c.UpdatedAt.Format(time.RFC3339), } }