feat: PollingConfig DTO 和 Service 支持卡状态检查间隔
dto: 新增 CardStatusCheckInterval 字段(validate min=30,description 含枚举说明) config_service.go: 创建/更新/响应映射均支持 CardStatusCheckInterval Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -2,28 +2,32 @@ package dto
|
|||||||
|
|
||||||
// CreatePollingConfigRequest 创建轮询配置请求
|
// CreatePollingConfigRequest 创建轮询配置请求
|
||||||
type CreatePollingConfigRequest struct {
|
type CreatePollingConfigRequest struct {
|
||||||
ConfigName string `json:"config_name" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" 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:已停用)"`
|
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:行业卡)"`
|
CardCategory string `json:"card_category" validate:"omitempty,oneof=normal industry" description:"卡业务类型 (normal:普通卡, industry:行业卡)"`
|
||||||
CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"`
|
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:"优先级(数字越小优先级越高)"`
|
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秒"`
|
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秒"`
|
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秒"`
|
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:"配置说明"`
|
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 更新轮询配置请求
|
// UpdatePollingConfigRequest 更新轮询配置请求
|
||||||
type UpdatePollingConfigRequest struct {
|
type UpdatePollingConfigRequest struct {
|
||||||
ConfigName *string `json:"config_name" validate:"omitempty,min=1,max=100" minLength:"1" maxLength:"100" 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:已停用)"`
|
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:行业卡)"`
|
CardCategory *string `json:"card_category" validate:"omitempty,oneof=normal industry" description:"卡业务类型 (normal:普通卡, industry:行业卡)"`
|
||||||
CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"`
|
CarrierID *uint `json:"carrier_id" validate:"omitempty" description:"运营商ID(可选,精确匹配)"`
|
||||||
Priority *int `json:"priority" validate:"omitempty,min=1,max=1000" minimum:"1" maximum:"1000" description:"优先级(数字越小优先级越高)"`
|
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秒"`
|
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秒"`
|
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秒"`
|
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:"配置说明"`
|
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 轮询配置列表请求
|
// PollingConfigListRequest 轮询配置列表请求
|
||||||
@@ -44,19 +48,21 @@ type UpdatePollingConfigStatusRequest struct {
|
|||||||
|
|
||||||
// PollingConfigResponse 轮询配置响应
|
// PollingConfigResponse 轮询配置响应
|
||||||
type PollingConfigResponse struct {
|
type PollingConfigResponse struct {
|
||||||
ID uint `json:"id" description:"配置ID"`
|
ID uint `json:"id" description:"配置ID"`
|
||||||
ConfigName string `json:"config_name" description:"配置名称"`
|
ConfigName string `json:"config_name" description:"配置名称"`
|
||||||
CardCondition string `json:"card_condition" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"`
|
CardCondition string `json:"card_condition" description:"卡状态条件 (not_real_name:未实名, real_name:已实名, activated:已激活, suspended:已停用)"`
|
||||||
CardCategory string `json:"card_category" description:"卡业务类型 (normal:普通卡, industry:行业卡)"`
|
CardCategory string `json:"card_category" description:"卡业务类型 (normal:普通卡, industry:行业卡)"`
|
||||||
CarrierID *uint `json:"carrier_id" description:"运营商ID"`
|
CarrierID *uint `json:"carrier_id" description:"运营商ID"`
|
||||||
Priority int `json:"priority" description:"优先级(数字越小优先级越高)"`
|
Priority int `json:"priority" description:"优先级(数字越小优先级越高)"`
|
||||||
RealnameCheckInterval *int `json:"realname_check_interval" description:"实名检查间隔(秒),NULL表示不检查"`
|
RealnameCheckInterval *int `json:"realname_check_interval" description:"实名检查间隔(秒),NULL表示不检查"`
|
||||||
CarddataCheckInterval *int `json:"carddata_check_interval" description:"流量检查间隔(秒),NULL表示不检查"`
|
CarddataCheckInterval *int `json:"carddata_check_interval" description:"流量检查间隔(秒),NULL表示不检查"`
|
||||||
PackageCheckInterval *int `json:"package_check_interval" description:"套餐检查间隔(秒),NULL表示不检查"`
|
PackageCheckInterval *int `json:"package_check_interval" description:"套餐检查间隔(秒),NULL表示不检查"`
|
||||||
Status int16 `json:"status" description:"状态 (1:启用, 0:禁用)"`
|
ProtectCheckInterval *int `json:"protect_check_interval" description:"保护期一致性检查间隔(秒),NULL表示不检查"`
|
||||||
Description string `json:"description" description:"配置说明"`
|
CardStatusCheckInterval *int `json:"card_status_check_interval" description:"卡状态检查间隔(秒),NULL表示不检查"`
|
||||||
CreatedAt string `json:"created_at" description:"创建时间"`
|
Status int16 `json:"status" description:"状态 (1:启用, 0:禁用)"`
|
||||||
UpdatedAt string `json:"updated_at" description:"更新时间"`
|
Description string `json:"description" description:"配置说明"`
|
||||||
|
CreatedAt string `json:"created_at" description:"创建时间"`
|
||||||
|
UpdatedAt string `json:"updated_at" description:"更新时间"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePollingConfigParams 更新轮询配置参数
|
// UpdatePollingConfigParams 更新轮询配置参数
|
||||||
|
|||||||
@@ -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, "至少需要配置一种检查间隔")
|
return nil, errors.New(errors.CodeInvalidParam, "至少需要配置一种检查间隔")
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &model.PollingConfig{
|
config := &model.PollingConfig{
|
||||||
ConfigName: req.ConfigName,
|
ConfigName: req.ConfigName,
|
||||||
CardCondition: req.CardCondition,
|
CardCondition: req.CardCondition,
|
||||||
CardCategory: req.CardCategory,
|
CardCategory: req.CardCategory,
|
||||||
CarrierID: req.CarrierID,
|
CarrierID: req.CarrierID,
|
||||||
Priority: req.Priority,
|
Priority: req.Priority,
|
||||||
RealnameCheckInterval: req.RealnameCheckInterval,
|
RealnameCheckInterval: req.RealnameCheckInterval,
|
||||||
CarddataCheckInterval: req.CarddataCheckInterval,
|
CarddataCheckInterval: req.CarddataCheckInterval,
|
||||||
PackageCheckInterval: req.PackageCheckInterval,
|
PackageCheckInterval: req.PackageCheckInterval,
|
||||||
Status: 1, // 默认启用
|
ProtectCheckInterval: req.ProtectCheckInterval,
|
||||||
Description: req.Description,
|
CardStatusCheckInterval: req.CardStatusCheckInterval,
|
||||||
CreatedBy: ¤tUserID,
|
Status: 1,
|
||||||
UpdatedBy: ¤tUserID,
|
Description: req.Description,
|
||||||
|
CreatedBy: ¤tUserID,
|
||||||
|
UpdatedBy: ¤tUserID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.configStore.Create(ctx, config); err != nil {
|
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 {
|
if req.PackageCheckInterval != nil {
|
||||||
config.PackageCheckInterval = req.PackageCheckInterval
|
config.PackageCheckInterval = req.PackageCheckInterval
|
||||||
}
|
}
|
||||||
|
if req.ProtectCheckInterval != nil {
|
||||||
|
config.ProtectCheckInterval = req.ProtectCheckInterval
|
||||||
|
}
|
||||||
|
if req.CardStatusCheckInterval != nil {
|
||||||
|
config.CardStatusCheckInterval = req.CardStatusCheckInterval
|
||||||
|
}
|
||||||
if req.Description != nil {
|
if req.Description != nil {
|
||||||
config.Description = *req.Description
|
config.Description = *req.Description
|
||||||
}
|
}
|
||||||
@@ -235,18 +245,20 @@ func (s *ConfigService) ListEnabled(ctx context.Context) ([]*dto.PollingConfigRe
|
|||||||
// toResponse 转换为响应 DTO
|
// toResponse 转换为响应 DTO
|
||||||
func (s *ConfigService) toResponse(c *model.PollingConfig) *dto.PollingConfigResponse {
|
func (s *ConfigService) toResponse(c *model.PollingConfig) *dto.PollingConfigResponse {
|
||||||
return &dto.PollingConfigResponse{
|
return &dto.PollingConfigResponse{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
ConfigName: c.ConfigName,
|
ConfigName: c.ConfigName,
|
||||||
CardCondition: c.CardCondition,
|
CardCondition: c.CardCondition,
|
||||||
CardCategory: c.CardCategory,
|
CardCategory: c.CardCategory,
|
||||||
CarrierID: c.CarrierID,
|
CarrierID: c.CarrierID,
|
||||||
Priority: c.Priority,
|
Priority: c.Priority,
|
||||||
RealnameCheckInterval: c.RealnameCheckInterval,
|
RealnameCheckInterval: c.RealnameCheckInterval,
|
||||||
CarddataCheckInterval: c.CarddataCheckInterval,
|
CarddataCheckInterval: c.CarddataCheckInterval,
|
||||||
PackageCheckInterval: c.PackageCheckInterval,
|
PackageCheckInterval: c.PackageCheckInterval,
|
||||||
Status: c.Status,
|
ProtectCheckInterval: c.ProtectCheckInterval,
|
||||||
Description: c.Description,
|
CardStatusCheckInterval: c.CardStatusCheckInterval,
|
||||||
CreatedAt: c.CreatedAt.Format(time.RFC3339),
|
Status: c.Status,
|
||||||
UpdatedAt: c.UpdatedAt.Format(time.RFC3339),
|
Description: c.Description,
|
||||||
|
CreatedAt: c.CreatedAt.Format(time.RFC3339),
|
||||||
|
UpdatedAt: c.UpdatedAt.Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user