feat: 不轮询清单与批量开关轮询
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m35s

- 新增不轮询清单 tb_card_polling_pause(迁移 000256 补写存量),所有改 enable_polling 的入口同事务写清单
- 卡、设备勾选批量开关轮询(单次 500,逐项结果,开启跳过风险停机与已销户)与 CSV 文件导入
- 订单套餐生效、改有效期后自动恢复轮询并按规则评估复机
- 不轮询清单查询与导出;卡、设备列表与导出增加是否轮询
- 失败告警停机被拒视图、导出与批量关闭轮询;开关轮询影响说明

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-10-26 03:07:20 +09:00
parent a4e3fe4d8f
commit 7ddb9312e3
45 changed files with 2250 additions and 50 deletions

View File

@@ -3,6 +3,7 @@ package iot_card
import (
"context"
stderrors "errors"
"github.com/break/junhong_cmp_fiber/internal/infrastructure/pollingpause"
"strings"
"time"
@@ -265,6 +266,9 @@ func (s *Service) ListStandalone(ctx context.Context, req *dto.ListStandaloneIot
if req.RealNameStatus != nil {
filters["real_name_status"] = *req.RealNameStatus
}
if req.EnablePolling != nil {
filters["enable_polling"] = *req.EnablePolling
}
if req.AuthorizedEnterpriseID != nil {
filters["authorized_enterprise_id"] = *req.AuthorizedEnterpriseID
}
@@ -1717,6 +1721,12 @@ func (s *Service) UpdatePollingStatus(ctx context.Context, cardID uint, enablePo
return appErr
}
beforePolling := card.EnablePolling
if enablePolling && !beforePolling && pollingpause.IsRiskExtend(card.GatewayExtend) {
// 风险停机、已销户的卡必须关闭轮询,不能开启。
denyErr := errors.New(errors.CodeForbidden, pollingpause.RiskEnableDeniedReason(card.GatewayExtend))
s.recordPollingStatusFailure(ctx, constants.AuditActionIotCardPollingStatusUpdated, constants.AuditResultDenied, card, enablePolling, denyErr)
return denyErr
}
err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if beforePolling != enablePolling {
result := tx.Model(&model.IotCard{}).Where("id = ? AND enable_polling = ?", card.ID, beforePolling).Update("enable_polling", enablePolling)
@@ -1726,6 +1736,9 @@ func (s *Service) UpdatePollingStatus(ctx context.Context, cardID uint, enablePo
if result.RowsAffected == 0 {
return errors.New(errors.CodeConflict, "轮询状态已变更,请刷新后重试")
}
if err := pollingpause.Record(ctx, tx, pollingpause.CardChange(card, enablePolling), constants.PollingToggleSourceSingle); err != nil {
return err
}
}
return s.appendPollingStatusAudit(ctx, tx, card, beforePolling, enablePolling)
})
@@ -1758,14 +1771,36 @@ func (s *Service) BatchUpdatePollingStatus(ctx context.Context, cardIDs []uint,
return nil
}
cards, err := s.iotCardStore.GetByIDs(ctx, cardIDs)
// 设备级联:清单来源记"设备级联",原因沿用设备变更的原因。
origin := pollingpause.OriginFrom(ctx, constants.PollingToggleSourceCascade)
origin.Source = constants.PollingToggleSourceCascade
ctx = pollingpause.WithOrigin(ctx, origin)
loaded, err := s.iotCardStore.GetByIDs(ctx, cardIDs)
if err != nil {
return err
}
// 开启时跳过风险停机、已销户的卡:这类卡必须保持关闭轮询。
cards := make([]*model.IotCard, 0, len(loaded))
cardIDs = make([]uint, 0, len(loaded))
for _, card := range loaded {
if card == nil || (enablePolling && pollingpause.IsRiskExtend(card.GatewayExtend)) {
continue
}
cards = append(cards, card)
cardIDs = append(cardIDs, card.ID)
}
if len(cardIDs) == 0 {
return nil
}
err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if updateErr := tx.Model(&model.IotCard{}).Where("id IN ?", cardIDs).Update("enable_polling", enablePolling).Error; updateErr != nil {
return errors.Wrap(errors.CodeDatabaseError, updateErr, "批量更新 IoT 卡轮询状态失败")
}
for _, card := range cards {
if err := pollingpause.Record(ctx, tx, pollingpause.CardChange(card, enablePolling), constants.PollingToggleSourceCascade); err != nil {
return err
}
}
return s.appendBatchPollingStatusAudit(ctx, tx, cards, enablePolling)
})
if err != nil {