Commit 9027c4fd authored by hujiebin's avatar hujiebin

1

parent cee5287b
......@@ -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
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)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment