fix: include inactive channels in negative activity filters
This commit is contained in:
@@ -228,6 +228,11 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
|
||||
}
|
||||
}
|
||||
if metricFilter {
|
||||
if f.IncludesInactiveRows() {
|
||||
if err := includeInactiveAnalyticsRows(db, scope, f, rowMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for key, row := range rowMap {
|
||||
match, err := f.MatchesMetrics(row)
|
||||
if err != nil {
|
||||
@@ -313,6 +318,28 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func includeInactiveAnalyticsRows(db *gorm.DB, scope business.AnalyticsScope, f business.AnalyticsFilter, rows map[business.AnalyticsKey]*business.AnalyticsRow) error {
|
||||
q := analyticsPromotes(db, scope, f, "p")
|
||||
if len(f.GameNames) > 0 {
|
||||
applications := db.Table("tab_promote_apply a").Select("1").Joins("JOIN tab_game g ON g.source_db=a.source_db AND g.id=a.game_id").Where("a.source_db=p.source_db AND a.promote_id=p.id AND a.status=1 AND g.game_name IN ?", f.GameNames)
|
||||
q = q.Where("EXISTS (?)", applications)
|
||||
}
|
||||
id := "p.id"
|
||||
if scope.IncludeSub {
|
||||
id = "CASE WHEN p.promote_level=1 THEN p.id WHEN p.top_promote_id>0 THEN p.top_promote_id ELSE p.id END"
|
||||
}
|
||||
var keys []business.AnalyticsKey
|
||||
if err := q.Select("DISTINCT p.source_db," + id + " AS id").Scan(&keys).Error; err != nil {
|
||||
return business.ErrStorage
|
||||
}
|
||||
for _, key := range keys {
|
||||
if rows[key] == nil {
|
||||
rows[key] = &business.AnalyticsRow{AnalyticsKey: key, Pay: "0"}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *analyticsRepo) FillNames(ctx context.Context, kind business.AnalyticsKind, scope business.AnalyticsScope, f business.AnalyticsFilter, rows []*business.AnalyticsRow) error {
|
||||
if len(rows) == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user