fix: 兼容MySQL渠道状态汇总查询并补充数据库回归

This commit is contained in:
Yvan
2026-11-05 11:14:57 +08:00
parent 413a4ebc21
commit c7d4ffbd9c
2 changed files with 27 additions and 4 deletions
+4 -4
View File
@@ -128,12 +128,12 @@ func (r *channelRepo) List(ctx context.Context, scope business.UserScope, filter
q = q.Where("e.qualified_at IS NULL")
}
}
var counts struct{ Total, Normal, Locked, Terminated int64 }
if err := q.Session(&gorm.Session{}).Select("COUNT(*) AS total,COALESCE(SUM(CASE WHEN COALESCE(p.lock_status,0)=0 THEN 1 ELSE 0 END),0) AS normal,COALESCE(SUM(CASE WHEN COALESCE(p.lock_status,0) NOT IN (0,-2) THEN 1 ELSE 0 END),0) AS locked,COALESCE(SUM(CASE WHEN p.lock_status=-2 THEN 1 ELSE 0 END),0) AS terminated").Scan(&counts).Error; err != nil {
var counts struct{ TotalCount, NormalCount, LockedCount, TerminatedCount int64 }
if err := q.Session(&gorm.Session{}).Select("COUNT(*) AS total_count,COALESCE(SUM(CASE WHEN COALESCE(p.lock_status,0)=0 THEN 1 ELSE 0 END),0) AS normal_count,COALESCE(SUM(CASE WHEN COALESCE(p.lock_status,0) NOT IN (0,-2) THEN 1 ELSE 0 END),0) AS locked_count,COALESCE(SUM(CASE WHEN p.lock_status=-2 THEN 1 ELSE 0 END),0) AS terminated_count").Scan(&counts).Error; err != nil {
return nil, business.ErrStorage
}
page.Total = counts.Total
page.StatusCounts = &business.ChannelStatusCounts{Normal: counts.Normal, Locked: counts.Locked, Terminated: counts.Terminated}
page.Total = counts.TotalCount
page.StatusCounts = &business.ChannelStatusCounts{Normal: counts.NormalCount, Locked: counts.LockedCount, Terminated: counts.TerminatedCount}
var pos []channelPO
o := business.NewListOptions(options...)
order := "p.create_time DESC,p.id DESC,p.source_db ASC"