feat: 按原型更新商务明细与游戏分析并清理临时资料

This commit is contained in:
Yvan
2026-11-04 18:13:03 +08:00
parent 19926d275c
commit f866cac768
41 changed files with 392 additions and 2955 deletions
+5 -4
View File
@@ -17,6 +17,7 @@ func NewServerAnalysisRepo(data Provider) business.ServerAnalysisRepo {
func serverReportQuery(db *gorm.DB, scope business.AnalyticsScope, f business.ServerAnalysisFilter, table string, mode int) *gorm.DB {
q := ledgerScopeQuery(db, business.LedgerScope{Viewer: scope.Viewer, IncludeSub: scope.IncludeSub, Unrestricted: scope.Viewer.All}, business.LedgerFilter{Sources: f.Sources}, table)
q = q.Where("r.stat_date >= ? AND r.stat_date <= ? AND r.dedup_mode=? AND r.server_num != ''", f.Begin, f.End, mode).Where("r.game_name IN ?", f.GameNames)
q = q.Where("(r.source_db,r.game_id) IN (?)", approvedGamesQuery(db, scope.Viewer, f.Sources).Select("g.source_db,g.id"))
if f.ServerNum != "" {
q = q.Where("r.server_num=?", f.ServerNum)
}
@@ -44,7 +45,7 @@ func (r *serverAnalysisRepo) Aggregate(ctx context.Context, scope business.Analy
if empty || !available {
return out, nil
}
for _, table := range []string{"tab_sw_report_server_day", "tab_sw_report_server_day_key", "tab_game_server", "tab_game"} {
for _, table := range []string{"tab_sw_report_server_day", "tab_sw_report_server_day_key", "tab_game_server", "tab_game", "tab_promote_apply"} {
available, err := businessTableAvailable(db, table)
if err != nil {
return nil, err
@@ -144,9 +145,9 @@ func fillServerAnalysisNames(db *gorm.DB, rows map[business.ServerAnalysisKey]*b
}
return nil
}
func (r *serverAnalysisRepo) Servers(ctx context.Context, sources, games []string, keyword string, limit int) ([]*business.ServerOption, error) {
func (r *serverAnalysisRepo) Servers(ctx context.Context, viewer business.UserScope, sources, games []string, keyword string, limit int) ([]*business.ServerOption, error) {
db := r.data.DB().WithContext(ctx)
for _, table := range []string{"tab_game", "tab_game_server"} {
for _, table := range []string{"tab_game", "tab_game_server", "tab_promote", "tab_promote_apply"} {
available, err := businessTableAvailable(db, table)
if err != nil {
return nil, err
@@ -158,7 +159,7 @@ func (r *serverAnalysisRepo) Servers(ctx context.Context, sources, games []strin
// MySQL 5.7 不会将相关 EXISTS 展开为半连接,导致扫描全部区服。
// 多列 IN 让优化器先按游戏名索引定位,再使用区服的 game_id 索引,
// 同时保留平台匹配和重复游戏资料不扩增结果的语义。
gamesQuery := db.Table("tab_game g").Select("g.source_db,g.id").Where("g.game_name IN ?", games)
gamesQuery := approvedGamesQuery(db, viewer, sources).Select("g.source_db,g.id").Where("g.game_name IN ?", games)
q := db.Table("tab_game_server s").Where("(s.source_db,s.game_id) IN (?)", gamesQuery)
if len(sources) > 0 {
q = q.Where("s.source_db IN ?", sources)