feat: 卡流量改为日快照计量并统一停复机规则
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
卡流量计量(按名单灰度,默认 off): - 新增卡日快照与切换水位表(000241),按通道上游流量重置日换算自然月、重置日防旧值 - 已切换的卡按月对账产生增量,无生效中套餐只结算不发事件;第一次切换写水位 - 已切换卡读数有效即判定通道阈值,卡表本月用量用快照覆盖,日流量读快照 - 配置 JUNHONG_TRAFFIC_CALC_MODE/CARDS、JUNHONG_TRAFFIC_FLOW_SNAPSHOT_ENABLED 停复机规则(总开关 JUNHONG_STOP_RESUME_UNIFIED_RULE_ENABLED,默认关闭): - 复机不看停机原因,持通道阈值锁仍拒绝;暂停轮询的卡不自动停复机 - 通道新增实名管控 realname_control_enabled(000242,默认 0),开启后不区分行业卡与实名策略 - 实名管控从 0 改 1 需确认,修改并入通道更新审计 OpenSpec Change: rebuild-card-traffic-metering-and-stop-resume
This commit is contained in:
@@ -2,6 +2,7 @@ package carrier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -54,7 +55,7 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateCarrierRequest) (*d
|
||||
|
||||
// 阈值字段只由超级管理员与平台账号配置:非平台账号提交即整体拒绝,不落任何配置。
|
||||
if req.HasTrafficThresholdFields() && !canManageThreshold(ctx) {
|
||||
s.recordDenied(ctx, constants.AuditOperationCarrierCreate, "拒绝非平台账号配置运营商通道流量阈值",
|
||||
s.recordDenied(ctx, constants.AuditOperationCarrierCreate, "拒绝非平台账号配置运营商通道流量阈值或实名管控",
|
||||
thresholdCreateProbe(req), errors.CodeForbidden)
|
||||
return nil, errors.New(errors.CodeForbidden, constants.PlatformManagementForbiddenMessage)
|
||||
}
|
||||
@@ -92,6 +93,9 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateCarrierRequest) (*d
|
||||
TrafficThresholdValue: thresholdValue,
|
||||
TrafficThresholdUnit: thresholdUnit,
|
||||
}
|
||||
if req.RealnameControlEnabled != nil {
|
||||
carrier.RealnameControlEnabled = *req.RealnameControlEnabled
|
||||
}
|
||||
if req.DataResetDay != nil {
|
||||
carrier.DataResetDay = *req.DataResetDay
|
||||
}
|
||||
@@ -145,7 +149,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateCarrierReq
|
||||
|
||||
// 阈值字段只由超级管理员与平台账号修改:非平台账号提交即整体拒绝。
|
||||
if req.HasTrafficThresholdFields() && !canManageThreshold(ctx) {
|
||||
s.recordDenied(ctx, constants.AuditOperationCarrierUpdate, "拒绝非平台账号配置运营商通道流量阈值",
|
||||
s.recordDenied(ctx, constants.AuditOperationCarrierUpdate, "拒绝非平台账号配置运营商通道流量阈值或实名管控",
|
||||
&before, errors.CodeForbidden)
|
||||
return nil, errors.New(errors.CodeForbidden, constants.PlatformManagementForbiddenMessage)
|
||||
}
|
||||
@@ -168,6 +172,12 @@ func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateCarrierReq
|
||||
carrier.TrafficThresholdEnabled = thresholdEnabled
|
||||
carrier.TrafficThresholdValue = thresholdValue
|
||||
carrier.TrafficThresholdUnit = thresholdUnit
|
||||
if req.RealnameControlEnabled != nil {
|
||||
if err := s.confirmRealnameControl(ctx, &before, *req.RealnameControlEnabled, req.RealnameControlConfirm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
carrier.RealnameControlEnabled = *req.RealnameControlEnabled
|
||||
}
|
||||
|
||||
if req.CarrierName != nil {
|
||||
carrier.CarrierName = *req.CarrierName
|
||||
@@ -375,9 +385,31 @@ func carrierAuditSnapshot(carrier *model.Carrier) map[string]any {
|
||||
"traffic_threshold_enabled": carrier.TrafficThresholdEnabled,
|
||||
"traffic_threshold_value": carrier.TrafficThresholdValue,
|
||||
"traffic_threshold_unit": carrier.TrafficThresholdUnit,
|
||||
// 通道实名管控的修改同样并入运营商更新审计。
|
||||
"realname_control_enabled": carrier.RealnameControlEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
// confirmRealnameControl 在把通道实名管控从 0 改为 1 时要求显式确认:
|
||||
// 未确认时返回该通道未实名开机卡数,提示这些卡会在下一次评估时被停机,本次不保存。
|
||||
func (s *Service) confirmRealnameControl(ctx context.Context, before *model.Carrier, next int, confirm *bool) error {
|
||||
if before.RealnameControlEnabled == next || next != constants.StatusEnabled {
|
||||
return nil
|
||||
}
|
||||
if confirm != nil && *confirm {
|
||||
return nil
|
||||
}
|
||||
var count int64
|
||||
if err := s.carrierStore.DB().WithContext(ctx).Model(&model.IotCard{}).
|
||||
Where("carrier_id = ? AND real_name_status <> ? AND network_status = ?",
|
||||
before.ID, constants.RealNameStatusVerified, constants.NetworkStatusOnline).
|
||||
Count(&count).Error; err != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "统计通道未实名开机卡数失败")
|
||||
}
|
||||
return errors.New(errors.CodeInvalidParam, fmt.Sprintf(
|
||||
"开启实名管控后,该通道 %d 张未实名的开机卡会在下一次评估时被停机;确认后请携带 realname_control_confirm=true 重新提交", count))
|
||||
}
|
||||
|
||||
// canManageThreshold 判断当前账号是否具备通道流量阈值字段的读写权限。
|
||||
// 只有超级管理员与平台账号可见可写,与 requirePlatformManagement 的判定一致(引用同一用户类型枚举)。
|
||||
func canManageThreshold(ctx context.Context) bool {
|
||||
@@ -438,6 +470,8 @@ func (s *Service) toResponse(ctx context.Context, c *model.Carrier) *dto.Carrier
|
||||
}
|
||||
enabled := c.TrafficThresholdEnabled
|
||||
result.TrafficThresholdEnabled = &enabled
|
||||
realnameControl := c.RealnameControlEnabled
|
||||
result.RealnameControlEnabled = &realnameControl
|
||||
result.TrafficThresholdValue = c.TrafficThresholdValue
|
||||
if c.TrafficThresholdUnit != "" {
|
||||
unit := c.TrafficThresholdUnit
|
||||
|
||||
Reference in New Issue
Block a user