fix: 卡日流量查询改用卡日快照 tb_card_flow_day
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 12m2s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 12m2s
tb_card_daily_usage 为已停用旧表(测试库为空,且列名与模型不一致), 卡日流量列表与索引改用采集链路写入的 tb_card_flow_day,当日用量取 settled_mb。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -237,13 +237,13 @@ func (s *Service) ListCardDailyUsages(ctx context.Context, req *dto.CardDailyUsa
|
||||
return resp, err
|
||||
}
|
||||
type row struct {
|
||||
model.CardDailyUsage
|
||||
model.CardFlowDay
|
||||
ICCID string
|
||||
CarrierID uint
|
||||
}
|
||||
query := s.db.WithContext(ctx).Table("tb_card_daily_usage AS u").
|
||||
query := s.db.WithContext(ctx).Table("tb_card_flow_day AS u").
|
||||
Select("u.*, c.iccid, c.carrier_id").Joins("LEFT JOIN tb_iot_card c ON c.id = u.iot_card_id").
|
||||
Where("u.date >= ? AND u.date <= ?", from.Format(recordDateLayout), to.Format(recordDateLayout))
|
||||
Where("u.flow_date >= ? AND u.flow_date <= ?", from.Format(recordDateLayout), to.Format(recordDateLayout))
|
||||
if !scope.all {
|
||||
query = query.Where("u.iot_card_id IN ?", scope.cardIDs)
|
||||
}
|
||||
@@ -251,16 +251,17 @@ func (s *Service) ListCardDailyUsages(ctx context.Context, req *dto.CardDailyUsa
|
||||
query = query.Where("c.carrier_id = ?", *req.CarrierID)
|
||||
}
|
||||
if req.MinUsageMB != nil {
|
||||
query = query.Where("u.usage_mb >= ?", *req.MinUsageMB)
|
||||
query = query.Where("u.settled_mb >= ?", *req.MinUsageMB)
|
||||
}
|
||||
rows, total, err := pageQuery[row](query, "u.date DESC, u.id DESC", page, size)
|
||||
rows, total, err := pageQuery[row](query, "u.flow_date DESC, u.id DESC", page, size)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询卡日流量失败")
|
||||
}
|
||||
for _, item := range rows {
|
||||
resp.Items = append(resp.Items, dto.CardDailyUsageItem{
|
||||
ID: item.ID, IotCardID: item.IotCardID, ICCID: item.ICCID, CarrierID: item.CarrierID,
|
||||
Date: item.Date.Format(recordDateLayout), UsageMB: item.UsageMB, UpdatedAt: item.UpdatedAt,
|
||||
Date: item.FlowDate.Format(recordDateLayout), SettledMB: item.SettledMB, MonthUsedMB: item.MonthUsedMB,
|
||||
VendorUsedMB: item.VendorUsedMB, StaleGuarded: item.StaleGuarded, ObsCount: item.ObsCount, UpdatedAt: item.UpdatedAt,
|
||||
})
|
||||
}
|
||||
resp.Total = total
|
||||
|
||||
Reference in New Issue
Block a user