feat: 停复机新规则转正,删除总开关与旧口径
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m35s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m35s
- 删除总开关 stop_resume.unified_rule_enabled(配置、加载、部署工作流与 docker-compose.prod.yml 环境变量) - 复机不看停机原因:删除只对轮询停因复机的旧分支与 ListByDeviceIDAndPollingStopReasons;设备复机取全部停机卡 - 实名门槛只按卡所属通道实名管控判断,删除行业卡与卡/设备实名策略放行;暂停轮询的卡不自动停复机无条件生效 - 通道阈值新周期解锁后的复机条件固定为新规则复机条件 - 资产自动续费复机同步新规则:不看停因、暂停轮询不复机、设备取全部停机卡、复机成功清除停因 - 实名轮询不再按行业卡跳过;所属运营商账户未开启实名管控时跳过查询,但卡未实名且所在资产有等待实名激活的套餐时照常查询,避免囤货套餐无法激活
This commit is contained in:
@@ -166,7 +166,7 @@ func (s *StopResumeService) QueryAutoRenewalResumeState(ctx context.Context, ass
|
||||
}
|
||||
|
||||
// autoRenewalResumeCards 解析自动续费资产对应的待复机卡:卡资产取自身,设备资产取该设备下
|
||||
// 因轮询原因停机的绑定卡(复用既有设备卡查询,不另立绑定关系口径)。
|
||||
// 全部停机的绑定卡(不看停机原因,复用既有设备卡查询,不另立绑定关系口径)。
|
||||
func (s *StopResumeService) autoRenewalResumeCards(ctx context.Context, assetType string, assetID uint) ([]*model.IotCard, error) {
|
||||
if assetID == 0 {
|
||||
return nil, errors.New(errors.CodeInvalidParam, "自动续费复机资产无效")
|
||||
@@ -179,7 +179,7 @@ func (s *StopResumeService) autoRenewalResumeCards(ctx context.Context, assetTyp
|
||||
}
|
||||
return []*model.IotCard{card}, nil
|
||||
case constants.AssetWalletResourceTypeDevice:
|
||||
cards, err := s.iotCardStore.ListByDeviceIDAndPollingStopReasons(ctx, assetID)
|
||||
cards, err := s.iotCardStore.ListByDeviceIDAndNetworkStatus(ctx, assetID, constants.NetworkStatusOffline)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询设备待复机卡失败")
|
||||
}
|
||||
@@ -197,11 +197,13 @@ func (s *StopResumeService) autoRenewalCardReady(ctx context.Context, card *mode
|
||||
if card.NetworkStatus == constants.NetworkStatusOnline {
|
||||
return false, "卡当前已在线,无需复机", nil
|
||||
}
|
||||
if isRiskGatewayExtend(card.GatewayExtend) {
|
||||
return false, "网关扩展状态为风险停机或已销户,不自动复机", nil
|
||||
// 与停复机规则一致:不看停机原因;卡或所在设备暂停轮询的不自动复机(风险停机与已销户的卡已关闭轮询)。
|
||||
suspended, err := s.autoControlSuspended(ctx, card)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
if !isPollingStopReason(card.StopReason) {
|
||||
return false, "停因不属于可轮询复机范围,不自动复机", nil
|
||||
if suspended {
|
||||
return false, "卡或所在设备已暂停轮询,不自动复机", nil
|
||||
}
|
||||
blocked, err := s.channelThresholdBlocked(ctx, card)
|
||||
if err != nil {
|
||||
@@ -266,10 +268,8 @@ func (s *StopResumeService) autoRenewalResumeCard(ctx context.Context, card *mod
|
||||
"network_status": constants.NetworkStatusOnline,
|
||||
"resumed_at": time.Now(),
|
||||
}
|
||||
// 判定已限定停因属于可轮询复机范围,复机成功后清除停因,与既有轮询复机口径一致。
|
||||
if isPollingStopReason(card.StopReason) {
|
||||
fields["stop_reason"] = ""
|
||||
}
|
||||
// 复机成功后清除停因,与轮询复机口径一致。
|
||||
fields["stop_reason"] = ""
|
||||
if err := s.updateCardAndAppendNetworkSeries(ctx, card, fields,
|
||||
constants.CardObservationSceneBusinessResume, "online", uuid.NewString(), actionCode, summary, attempt.log.IntegrationID); err != nil {
|
||||
if logErr := s.completeCardCommandAttempt(ctx, attempt, nil, false); logErr != nil {
|
||||
|
||||
@@ -100,30 +100,20 @@ func (s *StopResumeService) ResumeCardForChannelThreshold(ctx context.Context, c
|
||||
|
||||
// ChannelThresholdResumeReady 判断通道阈值跨期解锁后的卡是否满足自动复机条件。
|
||||
//
|
||||
// 条件全部复用既有单一事实源:有效主套餐、流量未耗尽、实名满足、非风险网关扩展,且不存在其他停机锁
|
||||
// (停因为空或正是通道阈值本身)。返回的 reason 是不满足原因(可安全记录),满足时为空。
|
||||
// 复机条件固定为停复机规则的复机条件:未暂停轮询、有效主套餐、流量未耗尽、实名满足;不看停机原因与网关扩展
|
||||
// (风险停机与已销户的卡已关闭轮询)。返回的 reason 是不满足原因(可安全记录),满足时为空。
|
||||
func (s *StopResumeService) ChannelThresholdResumeReady(ctx context.Context, cardID uint) (bool, string, error) {
|
||||
card, err := s.iotCardStore.GetByID(ctx, cardID)
|
||||
if err != nil {
|
||||
return false, "", errors.Wrap(errors.CodeDatabaseError, err, "读取通道阈值复机判定卡事实失败")
|
||||
}
|
||||
if unifiedStopResumeEnabled() {
|
||||
// 总开关开启时不看其他停因与网关扩展状态,卡或所在设备暂停轮询时只解锁不复机。
|
||||
suspended, suspendErr := s.autoControlSuspended(ctx, card)
|
||||
if suspendErr != nil {
|
||||
return false, "", suspendErr
|
||||
}
|
||||
if suspended {
|
||||
return false, "卡或所在设备已暂停轮询,不自动复机", nil
|
||||
}
|
||||
} else {
|
||||
// 其他停机锁:风险网关扩展(风险停机/销户)或非通道阈值的停因。
|
||||
if isRiskGatewayExtend(card.GatewayExtend) {
|
||||
return false, "网关扩展状态为风险停机或已销户,不自动复机", nil
|
||||
}
|
||||
if card.StopReason != "" && card.StopReason != constants.StopReasonChannelThreshold {
|
||||
return false, "存在其他停机原因,不自动复机", nil
|
||||
}
|
||||
// 卡或所在设备暂停轮询时只解锁不复机。
|
||||
suspended, suspendErr := s.autoControlSuspended(ctx, card)
|
||||
if suspendErr != nil {
|
||||
return false, "", suspendErr
|
||||
}
|
||||
if suspended {
|
||||
return false, "卡或所在设备已暂停轮询,不自动复机", nil
|
||||
}
|
||||
hasPackage, err := s.hasValidPackage(ctx, card)
|
||||
if err != nil {
|
||||
|
||||
@@ -172,11 +172,7 @@ func (s *StopResumeService) EvaluateAndAct(ctx context.Context, card *model.IotC
|
||||
return stopErr
|
||||
|
||||
case constants.NetworkStatusOffline:
|
||||
// 卡停机,检查是否可以复机
|
||||
// 总开关关闭时只处理轮询系统引起的停机原因(手动停机等不自动复机);开启时不看停机原因
|
||||
if !autoResumableStopReason(card.StopReason) {
|
||||
return nil
|
||||
}
|
||||
// 卡停机,检查是否可以复机:不看停机原因,是否复机只由本系统规则决定
|
||||
shouldResume, err := s.shouldResume(ctx, card)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -208,17 +204,6 @@ func isRiskGatewayExtend(extend string) bool {
|
||||
trimmed == constants.GatewayCardExtendCancelled
|
||||
}
|
||||
|
||||
// isPollingStopReason 判断停机原因是否为轮询系统引起(可自动复机)
|
||||
func isPollingStopReason(reason string) bool {
|
||||
switch reason {
|
||||
case constants.StopReasonTrafficExhausted,
|
||||
constants.StopReasonNoPackage,
|
||||
constants.StopReasonNotRealname:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// containsStopReason 判断停机原因集合是否包含指定原因。
|
||||
func containsStopReason(reasons []string, target string) bool {
|
||||
for _, reason := range reasons {
|
||||
@@ -346,32 +331,6 @@ func (s *StopResumeService) isTrafficExhausted(ctx context.Context, card *model.
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// isRealnameOK 检查卡是否满足实名要求
|
||||
// 行业卡、已实名卡直接放行;其他卡按有效设备或自身的无需实名策略判断。
|
||||
func (s *StopResumeService) isRealnameOK(ctx context.Context, card *model.IotCard) (bool, error) {
|
||||
// 总开关开启时实名只按卡所属通道的实名管控判断,不区分行业卡、不看卡或设备实名策略。
|
||||
if unifiedStopResumeEnabled() {
|
||||
return s.unifiedRealnameOK(ctx, card)
|
||||
}
|
||||
if card.CardCategory == constants.CardCategoryIndustry || card.RealNameStatus == constants.RealNameStatusVerified {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
deviceID, bound, err := s.getCardDeviceID(ctx, card)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(errors.CodeDatabaseError, err, "查询卡实名策略绑定关系失败")
|
||||
}
|
||||
if !bound {
|
||||
return card.RealnamePolicy == constants.RealnamePolicyNone, nil
|
||||
}
|
||||
|
||||
var device model.Device
|
||||
if err := s.db.WithContext(ctx).Select("realname_policy").First(&device, deviceID).Error; err != nil {
|
||||
return false, errors.Wrap(errors.CodeDatabaseError, err, "查询设备实名策略失败")
|
||||
}
|
||||
return device.RealnamePolicy == constants.RealnamePolicyNone, nil
|
||||
}
|
||||
|
||||
// checkStopReasons 检查卡的停机原因列表,按优先级排序
|
||||
// 优先级:no_package > traffic_exhausted > not_realname
|
||||
func (s *StopResumeService) checkStopReasons(ctx context.Context, card *model.IotCard) ([]string, error) {
|
||||
@@ -492,14 +451,8 @@ func (s *StopResumeService) resumeDeviceCards(ctx context.Context, deviceID uint
|
||||
}
|
||||
defer s.redis.Del(ctx, lockKey)
|
||||
|
||||
// 查询设备下待复机的卡:总开关关闭时只取因轮询原因停机的卡,开启时取全部停机卡(不看停机原因)
|
||||
var cards []*model.IotCard
|
||||
var err error
|
||||
if unifiedStopResumeEnabled() {
|
||||
cards, err = s.iotCardStore.ListByDeviceIDAndNetworkStatus(ctx, deviceID, constants.NetworkStatusOffline)
|
||||
} else {
|
||||
cards, err = s.iotCardStore.ListByDeviceIDAndPollingStopReasons(ctx, deviceID)
|
||||
}
|
||||
// 查询设备下全部停机卡(不看停机原因)
|
||||
cards, err := s.iotCardStore.ListByDeviceIDAndNetworkStatus(ctx, deviceID, constants.NetworkStatusOffline)
|
||||
if err != nil {
|
||||
s.logger.Error("查询设备停机卡失败",
|
||||
zap.Uint("device_id", deviceID), zap.Error(err))
|
||||
@@ -597,14 +550,6 @@ func (s *StopResumeService) resumeSingleCard(ctx context.Context, cardID uint) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// 总开关关闭时只处理轮询系统引起的停机;开启时不看停机原因
|
||||
if !autoResumableStopReason(card.StopReason) {
|
||||
s.logger.Debug("卡非轮询停机原因,不自动复机",
|
||||
zap.Uint("card_id", cardID),
|
||||
zap.String("stop_reason", card.StopReason))
|
||||
return nil
|
||||
}
|
||||
|
||||
// 检查复机条件
|
||||
resume, err := s.shouldResume(ctx, card)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/config"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
)
|
||||
@@ -15,25 +14,12 @@ import (
|
||||
// realnameControlEnabled 是通道实名管控开启时的取值。
|
||||
const realnameControlEnabled = 1
|
||||
|
||||
// unifiedStopResumeEnabled 判定停复机新规则总开关是否开启。
|
||||
//
|
||||
// 开启后:复机不看停机原因;实名按卡所属通道的实名管控判断(不区分行业卡、不看卡/设备实名策略);
|
||||
// 卡或所在设备暂停轮询时不自动停复机。关闭时全部停复机路径与原有行为一致。
|
||||
func unifiedStopResumeEnabled() bool {
|
||||
cfg := config.Get()
|
||||
return cfg != nil && cfg.StopResume.UnifiedRuleEnabled
|
||||
}
|
||||
// 停复机规则(已转正为唯一口径):复机不看停机原因;实名按卡所属通道的实名管控判断
|
||||
// (不区分行业卡、不看卡或设备实名策略);卡或所在设备暂停轮询时不自动停复机。
|
||||
|
||||
// autoResumableStopReason 判定该停因的停机卡能否进入自动复机判断:总开关开启时不看停因,
|
||||
// 关闭时只处理轮询系统引起的停机。
|
||||
func autoResumableStopReason(reason string) bool {
|
||||
return unifiedStopResumeEnabled() || isPollingStopReason(reason)
|
||||
}
|
||||
|
||||
// autoControlSuspended 判定总开关开启时该卡是否因暂停轮询而不自动停复机:卡自身或其有效绑定设备暂停轮询。
|
||||
// 总开关关闭时恒为 false。
|
||||
// autoControlSuspended 判定该卡是否因暂停轮询而不自动停复机:卡自身或其有效绑定设备暂停轮询。
|
||||
func (s *StopResumeService) autoControlSuspended(ctx context.Context, card *model.IotCard) (bool, error) {
|
||||
if !unifiedStopResumeEnabled() || card == nil {
|
||||
if card == nil {
|
||||
return false, nil
|
||||
}
|
||||
if !card.EnablePolling {
|
||||
@@ -69,8 +55,9 @@ func (s *StopResumeService) channelRealnameControlled(ctx context.Context, card
|
||||
return values[0] == realnameControlEnabled, nil
|
||||
}
|
||||
|
||||
// unifiedRealnameOK 是总开关开启后的实名门槛:通道未开启实名管控即满足;开启时只看卡是否已实名。
|
||||
func (s *StopResumeService) unifiedRealnameOK(ctx context.Context, card *model.IotCard) (bool, error) {
|
||||
// isRealnameOK 是停复机的实名门槛:通道未开启实名管控即满足;开启时只看卡是否已实名。
|
||||
// 查询通道失败时返回错误,调用方本次不对该卡发起停复机。
|
||||
func (s *StopResumeService) isRealnameOK(ctx context.Context, card *model.IotCard) (bool, error) {
|
||||
controlled, err := s.channelRealnameControlled(ctx, card)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
Reference in New Issue
Block a user