feat: 采集记录成功失败分表并保存网关原始数据,到期归档 csv.gz,新增记录分页查询接口
- 网关客户端新增原始数据收集器,记录最后一次尝试的明文请求、HTTP 状态、响应体与 code/msg/trace_id - tb_card_traffic_collection 只写成功读数,新增 carrier_id 与原始数据列;新增 tb_card_traffic_collection_failure,失败不判断有无套餐并带错误详情 - 采集记录在线保留当月加最近 2 个整月,到期分区摘出、导出 csv.gz、校验行数与 SHA-256 后删除,本地保留 3 个月 - 新增采集成功/失败、卡日流量、套餐日流量详单、冲正流水、退款后处理尝试列表接口:可查单个也可查全部,分页与条件筛选 - 停复机记录支持资产标识、场景、原因、指令号筛选;单卡历史支持动作、结果、来源筛选 - 单卡采集记录支持筛选与合并失败记录;套餐日流量详单支持分页;退款列表支持后处理状态筛选 - 测试环境 api、worker 日志分目录,保留 40 个压缩备份;worker 挂载 archive 目录 - 迁移 000272、000273 需维护者在测试库执行后再部署 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,8 @@ func NewDailyRecordService(
|
||||
|
||||
// GetDailyRecords 任务 13.2-13.5: 查询套餐流量详单
|
||||
// 查询指定套餐使用记录的日流量明细
|
||||
func (s *DailyRecordService) GetDailyRecords(ctx context.Context, packageUsageID uint, startDate, endDate string) (*dto.PackageUsageDetailResponse, error) {
|
||||
// GetDailyRecords 查询套餐流量详单;page_size 大于 0 时按日期倒序分页,否则按日期正序返回全部(兼容旧调用)。
|
||||
func (s *DailyRecordService) GetDailyRecords(ctx context.Context, packageUsageID uint, startDate, endDate string, page, pageSize int) (*dto.PackageUsageDetailResponse, error) {
|
||||
// 查询套餐使用记录
|
||||
var usage model.PackageUsage
|
||||
if err := s.db.WithContext(ctx).First(&usage, packageUsageID).Error; err != nil {
|
||||
@@ -73,7 +74,27 @@ func (s *DailyRecordService) GetDailyRecords(ctx context.Context, packageUsageID
|
||||
query = query.Where("date <= ?", end)
|
||||
}
|
||||
|
||||
if err := query.Order("date ASC").Find(&records).Error; err != nil {
|
||||
var summary struct {
|
||||
Total int64
|
||||
Usage int64
|
||||
}
|
||||
if err := query.Session(&gorm.Session{}).Model(&model.PackageUsageDailyRecord{}).
|
||||
Select("count(*) AS total, COALESCE(sum(daily_usage_mb), 0) AS usage").Scan(&summary).Error; err != nil {
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "统计日流量记录失败")
|
||||
}
|
||||
if pageSize > 0 {
|
||||
if pageSize > 100 {
|
||||
pageSize = 100
|
||||
}
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
query = query.Order("date DESC").Offset((page - 1) * pageSize).Limit(pageSize)
|
||||
} else {
|
||||
page = 0
|
||||
query = query.Order("date ASC")
|
||||
}
|
||||
if err := query.Find(&records).Error; err != nil {
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询日流量记录失败")
|
||||
}
|
||||
|
||||
@@ -87,14 +108,17 @@ func (s *DailyRecordService) GetDailyRecords(ctx context.Context, packageUsageID
|
||||
DailyUsageMB: record.DailyUsageMB,
|
||||
CumulativeUsageMB: record.CumulativeUsageMB,
|
||||
}
|
||||
totalUsageMB += int64(record.DailyUsageMB)
|
||||
}
|
||||
totalUsageMB = summary.Usage
|
||||
|
||||
response := &dto.PackageUsageDetailResponse{
|
||||
PackageUsageID: packageUsageID,
|
||||
PackageName: pkg.PackageName,
|
||||
Records: recordResponses,
|
||||
TotalUsageMB: totalUsageMB,
|
||||
Total: summary.Total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
}
|
||||
|
||||
return response, nil
|
||||
|
||||
Reference in New Issue
Block a user