feat: 第1批 M5 补充 IoT 卡导出追加使用/剩余流量(GB)列
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m35s

- 新任务在「套餐到期时间」后追加「使用流量(GB)」「剩余流量(GB)」,同行 MB ÷ 1024 两位小数
- 冻结表头按末列识别三版尾列,历史任务行宽不变
- OpenSpec 补充提案、设计、spec 与任务 3.2/5.6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-10-14 18:00:44 +09:00
parent 7e54fe2ba7
commit 1d6c212d04
5 changed files with 55 additions and 9 deletions

View File

@@ -39,8 +39,8 @@ func (s *IotCardDataSource) Count(ctx context.Context, params ExportParams) (int
// Headers 返回 IoT 卡导出表头。
func (s *IotCardDataSource) Headers(ctx context.Context, params ExportParams) ([]string, error) {
// 「关联手机号」「套餐到期时间」依次固定追加在尾部:导出表头在 dispatch 阶段落库,历史任务重导出沿用同一列序。
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader}, nil
// 「关联手机号」「套餐到期时间」「使用流量(GB)」「剩余流量(GB)」依次固定追加在尾部:导出表头在 dispatch 阶段落库,历史任务重导出沿用同一列序。
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader, iotCardExportUsageGBHeader, iotCardExportRemainingGBHeader}, nil
}
// Fetch 按 offset/limit 查询 IoT 卡导出数据。
@@ -81,7 +81,7 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
if err != nil {
return nil, err
}
includeExpiry := len(params.ResolvedHeaders) == 0 || iotCardHeadersIncludeFinalExpiry(params.ResolvedHeaders)
includeExpiry, includeGB := iotCardExportTailColumns(params.ResolvedHeaders)
var finalExpiries map[uint]string
if includeExpiry {
finalExpiries, err = s.loadFinalExpiries(ctx, cardIDs)
@@ -92,6 +92,7 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
rows := make([][]string, 0, len(items))
for _, item := range items {
remainingMB := remainingPackageDataMB(item.DataLimitMB, item.DataUsageMB)
row := []string{
item.ICCID,
item.MSISDN,
@@ -104,12 +105,15 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
constants.GetNetworkStatusName(item.NetworkStatus),
item.PackageName,
strconv.FormatInt(item.DataUsageMB, 10),
strconv.FormatInt(remainingPackageDataMB(item.DataLimitMB, item.DataUsageMB), 10),
strconv.FormatInt(remainingMB, 10),
associatedPhones[item.ID],
}
if includeExpiry {
row = append(row, finalExpiries[item.ID])
}
if includeGB {
row = append(row, formatMB(float64(item.DataUsageMB)/deviceExportMBPerGB), formatMB(float64(remainingMB)/deviceExportMBPerGB))
}
rows = append(rows, row)
}
return rows, nil
@@ -131,9 +135,20 @@ func (s *IotCardDataSource) loadFinalExpiries(ctx context.Context, cardIDs []uin
return result, nil
}
// iotCardHeadersIncludeFinalExpiry 判断冻结表头是否为带“套餐到期时间”末列的新表头。
func iotCardHeadersIncludeFinalExpiry(headers []string) bool {
return len(headers) > 0 && headers[len(headers)-1] == iotCardExportFinalExpiryHeader
// iotCardExportTailColumns 按冻结表头末列识别尾部版本:末列「剩余流量(GB)」输出到期列与 GB 列,
// 末列「套餐到期时间」只输出到期列,更早的表头两者都不输出;无冻结表头按当前版本输出。
func iotCardExportTailColumns(headers []string) (includeExpiry, includeGB bool) {
if len(headers) == 0 {
return true, true
}
switch headers[len(headers)-1] {
case iotCardExportRemainingGBHeader:
return true, true
case iotCardExportFinalExpiryHeader:
return true, false
default:
return false, false
}
}
// baseQuery 构造卡导出的基础查询。
@@ -269,9 +284,15 @@ func (s *IotCardDataSource) applyFilters(ctx context.Context, query *gorm.DB, pa
// iotCardExportAssociatedPhoneHeader 是「关联手机号」列的表头,固定位于导出尾部。
const iotCardExportAssociatedPhoneHeader = "关联手机号"
// iotCardExportFinalExpiryHeader 是「套餐到期时间」列的表头,固定位于导出最后一列。
// iotCardExportFinalExpiryHeader 是「套餐到期时间」列的表头,位于两列 GB 流量之前。
const iotCardExportFinalExpiryHeader = "套餐到期时间"
// iotCardExportUsageGBHeader、iotCardExportRemainingGBHeader 是 GB 流量列的表头,固定位于导出最后两列。
const (
iotCardExportUsageGBHeader = "使用流量(GB)"
iotCardExportRemainingGBHeader = "剩余流量(GB)"
)
type iotCardExportRow struct {
ID uint `gorm:"column:id"`
ICCID string `gorm:"column:iccid"`