This commit is contained in:
aozhiwei 2023-12-11 18:53:55 +08:00
parent f37c61a5ca
commit c3960295ca
3 changed files with 57 additions and 42 deletions

View File

@ -62,6 +62,14 @@ func (this *app) registerDataSources() {
mt.Table.GameDb.GetById(0).GetPasswd(),
mt.Table.GameDb.GetById(0).GetDatabase(),
30)
f5.GetGoStyleDb().RegisterDataSource(
constant.GAME_DB,
mt.Table.GameDb.GetById(0).GetHost(),
mt.Table.GameDb.GetById(0).GetPort(),
mt.Table.GameDb.GetById(0).GetUser(),
mt.Table.GameDb.GetById(0).GetPasswd(),
mt.Table.GameDb.GetById(0).GetDatabase(),
30)
f5.GetJsStyleDb().RegisterDataSource(
constant.FRIEND_DB,
mt.Table.FriendDb.GetById(0).GetHost(),

View File

@ -32,11 +32,9 @@ type userDb struct {
}
type SeasonRankMgr struct {
userData map[int64]*userDb
}
func (this *SeasonRankMgr) Init() {
this.userData = make(map[int64]*userDb)
this.CalcRanking()
fmt.Println("Task init success")
}
@ -46,50 +44,58 @@ func (this *SeasonRankMgr) UnInit() {
}
func (this *SeasonRankMgr) CalcRanking() {
lastIdx := int64(0)
this.getUsersRecords(lastIdx, 100)
//for !done {
// this.getUsersRecords(lastIdx, 10)
//}
this.pushRankingResult()
go this.goGetUsersRecords()
}
func (this *SeasonRankMgr) getUsersRecords(lastIdx int64, limit int64) {
sql := fmt.Sprintf("SELECT * FROM t_user WHERE score > %d and idx > %d limit %d",
constant.BASE_SCORE, lastIdx, limit)
f5.GetJsStyleDb().SelectCustomQuery(
constant.GAME_DB,
sql,
func(err error, rows *f5.DataSet) {
if err != nil {
f5.GetSysLog().Info("getUsersRecords Error:%v \n", err)
return
}
empty := true
for rows.Next() {
empty = false
user := userDb{}
user.idx = q5.ToInt64(rows.GetByName("idx"))
user.account_id = q5.ToString(rows.GetByName("account_id"))
user.address = q5.ToString(rows.GetByName("address"))
user.channel = q5.ToInt32(rows.GetByName("channel"))
user.rank = q5.ToInt32(rows.GetByName("rank"))
user.score = q5.ToInt32(rows.GetByName("score"))
user.score_modifytime = q5.ToInt64(rows.GetByName("score_modifytime"))
this.userData[user.idx] = &user
lastIdx = q5.ToInt64(rows.GetByName("idx"))
f5.GetSysLog().Info("get User:%s \n", user.channel)
}
if empty {
//done = true
}
fmt.Println(this.userData)
},
)
//return userDbs
func (this *SeasonRankMgr) goGetUsersRecords() {
userData := make(map[int64]*userDb)
var lastIdx int64 = 0
sucess := true
done := false
for !done {
sql := fmt.Sprintf("SELECT * FROM t_user WHERE idx > %d AND score > %d limit %d",
lastIdx,
constant.BASE_SCORE,
1000)
f5.GetGoStyleDb().SyncSelectCustomQuery(
constant.GAME_DB,
sql,
func(err error, rows *f5.DataSet) {
if err != nil {
sucess = false
done = true
f5.GetSysLog().Info("getUsersRecords Error:%v \n", err)
return
}
for rows.Next() {
user := userDb{}
user.idx = q5.ToInt64(rows.GetByName("idx"))
user.account_id = q5.ToString(rows.GetByName("account_id"))
user.address = q5.ToString(rows.GetByName("address"))
user.channel = q5.ToInt32(rows.GetByName("channel"))
user.rank = q5.ToInt32(rows.GetByName("rank"))
user.score = q5.ToInt32(rows.GetByName("score"))
user.score_modifytime = q5.ToInt64(rows.GetByName("score_modifytime"))
userData[user.idx] = &user
if user.idx > lastIdx {
lastIdx = user.idx
}
f5.GetSysLog().Info("get User:%s \n", user.idx)
}
if rows.NumOfReaded() <= 0 {
sucess = true;
done = true
}
},
)
}
if sucess {
}
}
func (this *SeasonRankMgr) pushRankingResult() {
/*
for _, v := range this.userData {
fields := [][]string{
{"account_id", v.account_id},
@ -113,4 +119,5 @@ func (this *SeasonRankMgr) pushRankingResult() {
},
)
}
*/
}

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit 30a7e2a6ea30e98772c16e28d3be8b2bec440bb8
Subproject commit 2d79f0c481291b077a532690399bf5571654345d