feat: 分层轮询、重置日前加密与激活前流量结算
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m37s

- 轮询配置新增套餐状态、资产状态、重置日前窗口与窗口内流量间隔(迁移 248),间隔三态:正数按间隔、0 不检查、空继承
- 配置按 priority, id 排序合并;在库与已销售无套餐未匹配时告警不入队
- 新增优先级整体重排、匹配预览、立即重算到期时间(异步只提前)、分层统计与重置日前加密统计接口
- 已切换日快照计量的卡流量按观测时间归属,激活前用量只记已结算
- 订单购买与实名激活补齐资产级激活锁,激活前对已切换卡结算一次流量,失败只告警不阻塞,结算不触发通道阈值判定
This commit is contained in:
邹进
2026-10-24 17:06:38 +09:00
parent 02a842f066
commit 98017ac053
34 changed files with 2232 additions and 182 deletions

View File

@@ -11,6 +11,7 @@ import (
auditinfra "github.com/break/junhong_cmp_fiber/internal/infrastructure/audit"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
pollingcore "github.com/break/junhong_cmp_fiber/internal/polling"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -25,6 +26,8 @@ type ConfigService struct {
auditWriter *auditinfra.Writer
redis *redis.Client
logger *zap.Logger
configMgr *pollingcore.PollingConfigManager
queueClient TaskEnqueuer
}
// SetAudit 注入轮询配置事务与统一审计 Writer。
@@ -67,28 +70,28 @@ func (s *ConfigService) Create(ctx context.Context, req *dto.CreatePollingConfig
return nil, appErr
}
// 验证检查间隔(至少一个不为空)
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,
ProtectCheckInterval: req.ProtectCheckInterval,
CardStatusCheckInterval: req.CardStatusCheckInterval,
Status: 1,
Description: req.Description,
CreatedBy: &currentUserID,
UpdatedBy: &currentUserID,
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,
PackageState: req.PackageState,
AssetStatus: req.AssetStatus,
PreResetWindow: req.PreResetWindow,
PreResetCarddataInterval: req.PreResetCarddataInterval,
Status: 1,
Description: req.Description,
CreatedBy: &currentUserID,
UpdatedBy: &currentUserID,
}
if err := validatePollingConfig(config); err != nil {
return nil, err
}
err := runPollingTransaction(ctx, s.db, s.auditWriter, func(tx *gorm.DB) error {
@@ -114,7 +117,9 @@ func (s *ConfigService) Create(ctx context.Context, req *dto.CreatePollingConfig
}
s.notifyConfigChanged(ctx, "created")
return s.toResponse(config), nil
resp := s.toResponse(config)
resp.Warnings = s.priorityWarnings(ctx, config)
return resp, nil
}
// Get 获取轮询配置详情
@@ -189,9 +194,27 @@ func (s *ConfigService) Update(ctx context.Context, id uint, req *dto.UpdatePoll
if req.CardStatusCheckInterval != nil {
config.CardStatusCheckInterval = req.CardStatusCheckInterval
}
if req.PackageState != nil {
config.PackageState = req.PackageState
}
if req.AssetStatus != nil {
config.AssetStatus = req.AssetStatus
}
if req.PreResetWindow != nil {
config.PreResetWindow = req.PreResetWindow
}
if req.PreResetCarddataInterval != nil {
config.PreResetCarddataInterval = req.PreResetCarddataInterval
}
if req.Description != nil {
config.Description = *req.Description
}
if err := applyPollingConfigClearFields(config, req.ClearFields); err != nil {
return nil, err
}
if err := validatePollingConfig(config); err != nil {
return nil, err
}
config.UpdatedBy = &currentUserID
err = runPollingTransaction(ctx, s.db, s.auditWriter, func(tx *gorm.DB) error {
@@ -219,7 +242,9 @@ func (s *ConfigService) Update(ctx context.Context, id uint, req *dto.UpdatePoll
}
s.notifyConfigChanged(ctx, "updated")
return s.toResponse(config), nil
resp := s.toResponse(config)
resp.Warnings = s.priorityWarnings(ctx, config)
return resp, nil
}
// Delete 删除轮询配置
@@ -368,20 +393,24 @@ 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,
ProtectCheckInterval: c.ProtectCheckInterval,
CardStatusCheckInterval: c.CardStatusCheckInterval,
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,
PackageState: c.PackageState,
AssetStatus: c.AssetStatus,
PreResetWindow: c.PreResetWindow,
PreResetCarddataInterval: c.PreResetCarddataInterval,
Status: c.Status,
Description: c.Description,
CreatedAt: c.CreatedAt.Format(time.RFC3339),
UpdatedAt: c.UpdatedAt.Format(time.RFC3339),
}
}