fix: 记录查询扫描结构显式指定列名,修复 ICCID 一直为空
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled

GORM 默认把字段 ICCID 映射成 icc_id,卡日流量的 c.iccid 和展示字段批量查询都读不到值;
扫描用的匿名结构统一写 gorm column tag。
This commit is contained in:
邹进
2026-11-07 17:33:28 +09:00
parent 3f593b912d
commit eb0d86df4f
2 changed files with 19 additions and 17 deletions

View File

@@ -257,10 +257,11 @@ func (s *Service) ListCardDailyUsages(ctx context.Context, req *dto.CardDailyUsa
if err != nil || scope.empty() {
return resp, err
}
// 显式列名:GORM 默认把字段 ICCID 映射成 icc_id,不写 tag 时 ICCID 一直为空。
type row struct {
model.CardFlowDay
ICCID string
CarrierID uint
ICCID string `gorm:"column:iccid"`
CarrierID uint `gorm:"column:carrier_id"`
}
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").
@@ -312,10 +313,10 @@ func (s *Service) ListPackageUsageDailyRecords(ctx context.Context, req *dto.Pac
}
type row struct {
model.PackageUsageDailyRecord
PackageID uint
PackageName string
IotCardID uint
DeviceID uint
PackageID uint `gorm:"column:package_id"`
PackageName string `gorm:"column:package_name"`
IotCardID uint `gorm:"column:iot_card_id"`
DeviceID uint `gorm:"column:device_id"`
}
query := s.db.WithContext(ctx).Table("tb_package_usage_daily_record AS r").
Select("r.*, pu.package_id, pu.package_name, COALESCE(pu.iot_card_id, 0) AS iot_card_id, COALESCE(pu.device_id, 0) AS device_id").