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

@@ -40,7 +40,7 @@ func (s *IotCardDataSource) Count(ctx context.Context, params ExportParams) (int
// Headers 返回 IoT 卡导出表头。
func (s *IotCardDataSource) Headers(ctx context.Context, params ExportParams) ([]string, error) {
// 「关联手机号」「套餐到期时间」「使用流量(GB)」「剩余流量(GB)」依次固定追加在尾部:导出表头在 dispatch 阶段落库,历史任务重导出沿用同一列序。
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader, iotCardExportUsageGBHeader, iotCardExportRemainingGBHeader}, nil
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader, iotCardExportUsageGBHeader, iotCardExportRemainingGBHeader, iotCardExportPollingHeader}, nil
}
// Fetch 按 offset/limit 查询 IoT 卡导出数据。
@@ -60,6 +60,7 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
COALESCE(sh.shop_name, '') AS shop_name,
COALESCE(d.device_name, '') AS device_name,
c.real_name_status,
c.enable_polling,
c.first_realname_at,
c.network_status,
COALESCE(pkg.package_name, '') AS package_name,
@@ -81,7 +82,7 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
if err != nil {
return nil, err
}
includeExpiry, includeGB := iotCardExportTailColumns(params.ResolvedHeaders)
includeExpiry, includeGB, includePolling := iotCardExportTailColumns(params.ResolvedHeaders)
var finalExpiries map[uint]string
if includeExpiry {
finalExpiries, err = s.loadFinalExpiries(ctx, cardIDs)
@@ -114,6 +115,9 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
if includeGB {
row = append(row, formatMB(float64(item.DataUsageMB)/deviceExportMBPerGB), formatMB(float64(remainingMB)/deviceExportMBPerGB))
}
if includePolling {
row = append(row, yesNo(item.EnablePolling))
}
rows = append(rows, row)
}
return rows, nil
@@ -135,19 +139,21 @@ func (s *IotCardDataSource) loadFinalExpiries(ctx context.Context, cardIDs []uin
return result, nil
}
// iotCardExportTailColumns 按冻结表头末列识别尾部版本:末列「剩余流量(GB)」输出到期列与 GB 列,
// 末列「套餐到期时间」只输出到期列,更早的表头两者都不输出;无冻结表头按当前版本输出。
func iotCardExportTailColumns(headers []string) (includeExpiry, includeGB bool) {
// iotCardExportTailColumns 按冻结表头末列识别尾部版本:末列「是否轮询」输出到期、GB 与是否轮询列,
// 末列「剩余流量(GB)」输出到期列与 GB 列,末列「套餐到期时间」只输出到期列,更早的表头都不输出;无冻结表头按当前版本输出。
func iotCardExportTailColumns(headers []string) (includeExpiry, includeGB, includePolling bool) {
if len(headers) == 0 {
return true, true
return true, true, true
}
switch headers[len(headers)-1] {
case iotCardExportPollingHeader:
return true, true, true
case iotCardExportRemainingGBHeader:
return true, true
return true, true, false
case iotCardExportFinalExpiryHeader:
return true, false
return true, false, false
default:
return false, false
return false, false, false
}
}
@@ -268,6 +274,9 @@ func (s *IotCardDataSource) applyFilters(ctx context.Context, query *gorm.DB, pa
if carrierName, ok := filterString(params.Filters, "carrier_name"); ok {
query = query.Where("c.carrier_name LIKE ?", "%"+carrierName+"%")
}
if enablePolling, ok := filterOptionalBool(params.Filters, "enable_polling"); ok {
query = query.Where("c.enable_polling = ?", enablePolling)
}
if hasActivePackage, ok := filterOptionalBool(params.Filters, "has_active_package"); ok {
subQuery := s.db.WithContext(ctx).Table("tb_package_usage AS pu").
Select("1").
@@ -291,6 +300,8 @@ const iotCardExportFinalExpiryHeader = "套餐到期时间"
const (
iotCardExportUsageGBHeader = "使用流量(GB)"
iotCardExportRemainingGBHeader = "剩余流量(GB)"
// iotCardExportPollingHeader 是「是否轮询」列的表头,位于 GB 流量列之后、导出最后一列。
iotCardExportPollingHeader = "是否轮询"
)
type iotCardExportRow struct {
@@ -307,6 +318,7 @@ type iotCardExportRow struct {
PackageName string `gorm:"column:package_name"`
DataUsageMB int64 `gorm:"column:data_usage_mb"`
DataLimitMB int64 `gorm:"column:data_limit_mb"`
EnablePolling bool `gorm:"column:enable_polling"`
}
func remainingPackageDataMB(limit, used int64) int64 {