diff --git a/script/Makefile b/script/Makefile index dbecdef0f432f8f2e86d7be60224e335033e0898..4a6e1bf8135f17a9caeb176a42ec9ea8022a9c85 100644 --- a/script/Makefile +++ b/script/Makefile @@ -24,4 +24,6 @@ fruit_day_award: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o fruit_day_award fruit_day_award.go race_day_award: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o race_day_award race_day_award.go +race_ksa_rank: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o race_ksa_rank race_ksa_rank.go diff --git a/script/race_ksa_rank.go b/script/race_ksa_rank.go new file mode 100644 index 0000000000000000000000000000000000000000..3bed0526c57da9884932024a3055746db16fa42a --- /dev/null +++ b/script/race_ksa_rank.go @@ -0,0 +1,60 @@ +package main + +import ( + "git.hilo.cn/hilo-common/script/mysql" + "gorm.io/gorm" + "gorm.io/gorm/clause" +) + +type RaceDayRankKsa struct { + Period string + UserId uint64 + Stake uint64 + Award uint64 +} + +type TmpRank struct { + D string + UserId uint64 + Stake uint64 + Award uint64 +} + +func main() { + stakeSql := `SELECT DATE_FORMAT(created_time,"%Y-%m-%d") d,user_id,SUM(stake) stake FROM game_race_stake GROUP BY d,user_id ;` + var stakeRanks []TmpRank + if err := mysql.ProdWriteDB.Raw(stakeSql).Scan(&stakeRanks).Error; err != nil { + panic(err) + } + for _, v := range stakeRanks { + if err := mysql.ProdWriteDB.Model(RaceDayRankKsa{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "period"}, {Name: "user_id"}}, + DoUpdates: clause.Assignments(map[string]interface{}{ + "stake": gorm.Expr("stake+ ?", v.Stake), + }), + }).Create(&RaceDayRankKsa{ + Period: v.D, + UserId: v.UserId, + Stake: v.Stake, + }).Error; err != nil { + panic(err) + } + } + awardSql := `SELECT DATE_FORMAT(created_time,"%Y-%m-%d") d,user_id,SUM(award) award FROM game_race_player GROUP BY d,user_id;` + var awardRanks []TmpRank + if err := mysql.ProdWriteDB.Raw(awardSql).Scan(&awardRanks).Error; err != nil { + panic(err) + } + for _, v := range awardRanks { + if err := mysql.ProdWriteDB.Model(RaceDayRankKsa{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "period"}, {Name: "user_id"}}, + DoUpdates: clause.Assignments(map[string]interface{}{ + "award": gorm.Expr("award+ ?", v.Award), + }), + }).Create(&RaceDayRankKsa{ + Period: v.D, + UserId: v.UserId, + Award: v.Award, + }).Error; err != nil { + panic(err) + } + } +}