feat: 分层轮询、重置日前加密与激活前流量结算
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m37s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m37s
- 轮询配置新增套餐状态、资产状态、重置日前窗口与窗口内流量间隔(迁移 248),间隔三态:正数按间隔、0 不检查、空继承 - 配置按 priority, id 排序合并;在库与已销售无套餐未匹配时告警不入队 - 新增优先级整体重排、匹配预览、立即重算到期时间(异步只提前)、分层统计与重置日前加密统计接口 - 已切换日快照计量的卡流量按观测时间归属,激活前用量只记已结算 - 订单购买与实名激活补齐资产级激活锁,激活前对已切换卡结算一次流量,失败只告警不阻塞,结算不触发通道阈值判定
This commit is contained in:
@@ -17,7 +17,11 @@ func (b *PollingBase) getCardWithCache(ctx context.Context, cardID uint) (*model
|
||||
|
||||
result, err := b.redis.HGetAll(ctx, key).Result()
|
||||
if err == nil && len(result) > 0 {
|
||||
return parseCardFromCache(cardID, result), nil
|
||||
card := parseCardFromCache(cardID, result)
|
||||
if _, ok := result["asset_status"]; !ok {
|
||||
b.backfillAssetStatus(ctx, key, card)
|
||||
}
|
||||
return card, nil
|
||||
}
|
||||
|
||||
card, err := b.iotCardStore.GetByID(ctx, cardID)
|
||||
@@ -32,6 +36,19 @@ func (b *PollingBase) getCardWithCache(ctx context.Context, cardID uint) (*model
|
||||
return card, nil
|
||||
}
|
||||
|
||||
// backfillAssetStatus 为分层轮询补齐旧缓存缺少的资产状态:只读取并回写这一个字段,
|
||||
// 不整条重建缓存,避免覆盖缓存中单独维护的读数等字段。
|
||||
func (b *PollingBase) backfillAssetStatus(ctx context.Context, key string, card *model.IotCard) {
|
||||
var statuses []int
|
||||
if err := b.db.WithContext(ctx).Model(&model.IotCard{}).Where("id = ?", card.ID).Limit(1).Pluck("asset_status", &statuses).Error; err != nil || len(statuses) == 0 {
|
||||
return
|
||||
}
|
||||
card.AssetStatus = statuses[0]
|
||||
if err := b.redis.HSet(ctx, key, "asset_status", card.AssetStatus).Err(); err != nil {
|
||||
b.logger.Debug("回写卡缓存资产状态失败", zap.Uint("card_id", card.ID), zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// updateCardCache 更新 Redis 卡信息缓存中的指定字段
|
||||
func (b *PollingBase) updateCardCache(ctx context.Context, cardID uint, updates map[string]any) {
|
||||
key := constants.RedisPollingCardInfoKey(cardID)
|
||||
@@ -100,6 +117,11 @@ func parseCardFromCache(cardID uint, result map[string]string) *model.IotCard {
|
||||
if v, ok := result["stop_reason"]; ok {
|
||||
card.StopReason = v
|
||||
}
|
||||
if v, ok := result["asset_status"]; ok {
|
||||
if status, err := strconv.Atoi(v); err == nil {
|
||||
card.AssetStatus = status
|
||||
}
|
||||
}
|
||||
if v, ok := result["is_standalone"]; ok {
|
||||
card.IsStandalone = v == "1" || v == "true"
|
||||
} else {
|
||||
@@ -136,6 +158,7 @@ func writeCardToCache(b *PollingBase, key string, card *model.IotCard) {
|
||||
"data_usage_mb": card.DataUsageMB,
|
||||
"stop_reason": card.StopReason,
|
||||
"is_standalone": boolToStr(card.IsStandalone),
|
||||
"asset_status": card.AssetStatus,
|
||||
"cached_at": time.Now().Unix(),
|
||||
}
|
||||
if card.SeriesID != nil {
|
||||
|
||||
Reference in New Issue
Block a user