fix: 完成商务迁移复核与接口优化并清理历史资料
This commit is contained in:
@@ -41,14 +41,12 @@ func (r *reportBuildRepo) Rebuild(ctx context.Context, kind business.ReportBuild
|
||||
reportTable, keyTable = "tab_sw_report_server_day", "tab_sw_report_server_day_key"
|
||||
rawTable = "tab_user_play_info"
|
||||
}
|
||||
for _, table := range []string{reportTable, keyTable, rawTable, "tab_user", "tab_spend", "tab_game"} {
|
||||
available, err := businessTableAvailable(tx, table)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !available {
|
||||
return business.ErrReportBuildUnavailable
|
||||
}
|
||||
available, err := businessTablesAvailable(tx, reportTable, keyTable, rawTable, "tab_user", "tab_spend", "tab_game")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !available {
|
||||
return business.ErrReportBuildUnavailable
|
||||
}
|
||||
statDate := day.Format("2006-01-02")
|
||||
lock := reportBuildLockPO{Kind: string(kind), StatDate: statDate}
|
||||
@@ -133,7 +131,11 @@ func loadReportInput(db *gorm.DB, kind business.ReportBuildKind, day time.Time)
|
||||
cast = "CAST(register_time AS UNSIGNED)"
|
||||
}
|
||||
var registers, actives []reportEventPO
|
||||
if err := db.Table("tab_user").Select("id AS user_id,source_db,promote_id,fgame_id AS game_id").Where("puid=0").Where(cast+" BETWEEN ? AND ?", begin, end).Scan(®isters).Error; err != nil {
|
||||
registerQuery, err := reportRegistrationQuery(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := registerQuery.Select("id AS user_id,source_db,promote_id,fgame_id AS game_id").Where("puid=0").Where(cast+" BETWEEN ? AND ?", begin, end).Scan(®isters).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
if err := db.Table("tab_user_day_login").Select("user_id,source_db,promote_id,game_id").Where("login_time BETWEEN ? AND ?", begin, end).Scan(&actives).Error; err != nil {
|
||||
@@ -204,3 +206,37 @@ func loadReportInput(db *gorm.DB, kind business.ReportBuildKind, day time.Time)
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func reportRegistrationQuery(db *gorm.DB) (*gorm.DB, error) {
|
||||
q := db.Table("tab_user")
|
||||
if db.Dialector.Name() != "mysql" || !db.Migrator().HasIndex("tab_user", "idx_sw_user_registration") {
|
||||
return q, nil
|
||||
}
|
||||
// 跨平台任务也必须提供组合索引的首列,避免又回到数百万主账号扫描。
|
||||
// 平台值取同一事务中的实际数据,不写死平台名单,也保留历史 NULL。
|
||||
var rows []struct {
|
||||
SourceDB *string `gorm:"column:source_db"`
|
||||
}
|
||||
if err := db.Table("tab_user").Distinct("source_db").Scan(&rows).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
sources := []string{}
|
||||
hasNull := false
|
||||
for _, row := range rows {
|
||||
if row.SourceDB == nil {
|
||||
hasNull = true
|
||||
} else {
|
||||
sources = append(sources, *row.SourceDB)
|
||||
}
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
if hasNull {
|
||||
return q.Where("source_db IS NULL"), nil
|
||||
}
|
||||
return q.Where("1=0"), nil
|
||||
}
|
||||
if hasNull {
|
||||
return q.Where("(source_db IN ? OR source_db IS NULL)", sources), nil
|
||||
}
|
||||
return q.Where("source_db IN ?", sources), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user