100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
package task
|
|
|
|
import (
|
|
"encoding/json"
|
|
"f5"
|
|
"main/constant"
|
|
"main/mt"
|
|
"q5"
|
|
"time"
|
|
)
|
|
|
|
type rankchart struct {
|
|
}
|
|
|
|
type rankitem struct {
|
|
Idx int64 `json:"idx"`
|
|
Account string `json:"account_id"`
|
|
Name string `json:"name"`
|
|
Head int32 `json:"head_id"`
|
|
HeadFrame int32 `json:"head_frame"`
|
|
Score int32 `json:"score"`
|
|
Rank int32 `json:"rank"`
|
|
}
|
|
|
|
func (r *rankchart) init() {
|
|
// go r.processLoop()
|
|
}
|
|
|
|
func (r *rankchart) unInit() {
|
|
}
|
|
|
|
func (r *rankchart) processLoop() {
|
|
for {
|
|
height := mt.Table.Config.GetById(0).GetScoreboardHeight()
|
|
r.processScoreRank(height)
|
|
time.Sleep(time.Minute)
|
|
}
|
|
}
|
|
|
|
func (r *rankchart) processScoreRank(height int32) {
|
|
sql := `SELECT idx, account_id, name, head_id, head_frame, score, score_modifytime FROM t_user WHERE idx > 0`
|
|
order := " ORDER BY score DESC, score_modifytime ASC, idx ASC "
|
|
const perpage = int32(512)
|
|
pageno := int32(1)
|
|
item := new(rankitem)
|
|
|
|
for {
|
|
datalist := []string{}
|
|
var queryerr error
|
|
lastpage := false
|
|
f5.GetGoStyleDb().PageQuery(
|
|
constant.GAME_DB,
|
|
perpage,
|
|
pageno,
|
|
sql,
|
|
[]string{},
|
|
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
|
|
order,
|
|
func(err error, p *f5.Pagination) {
|
|
if err != nil {
|
|
queryerr = err
|
|
return
|
|
}
|
|
|
|
if p.CurrentPage == p.TotalPages {
|
|
lastpage = true
|
|
}
|
|
|
|
for p.Rows.Next() {
|
|
item.Rank = int32(p.Rows.NumOfReaded()) + (pageno-1)*(perpage)
|
|
if height > 0 && item.Rank > height {
|
|
lastpage = true
|
|
return
|
|
}
|
|
|
|
item.Idx = q5.SafeToInt64(p.Rows.GetByName("idx"))
|
|
item.Account = p.Rows.GetByName("account_id")
|
|
item.Name = p.Rows.GetByName("name")
|
|
item.Head = q5.SafeToInt32(p.Rows.GetByName("head_id"))
|
|
item.HeadFrame = q5.SafeToInt32(p.Rows.GetByName("head_frame"))
|
|
item.Score = q5.SafeToInt32(p.Rows.GetByName("score"))
|
|
rankdata, _ := json.Marshal(item)
|
|
datalist = append(datalist, string(rankdata))
|
|
}
|
|
})
|
|
|
|
if len(datalist) > 0 {
|
|
// push to redis
|
|
// fmt.Println(datalist)
|
|
|
|
}
|
|
|
|
if queryerr != nil || lastpage {
|
|
break
|
|
}
|
|
|
|
pageno++
|
|
}
|
|
}
|