This commit is contained in:
yangduo 2024-10-11 16:19:46 +08:00
parent e39a25d864
commit c4977b93a2
5 changed files with 115 additions and 4 deletions

View File

@ -4,5 +4,6 @@
"immutable_base_url": "https://api.sandbox.immutable.com",
"hero_contract_address": "0x65570A86E5aA2B14325f8a13C70b74f7d1E2f5c9",
"immutable_api_key": "sk_imapik-test-kbe8ZWVEzySQPmdiOd8H_ac92cd",
"chain_name": "imtbl-zkevm-testnet"
"chain_name": "imtbl-zkevm-testnet",
"scoreboard_height": 100
}

View File

@ -84,6 +84,7 @@ type Config struct {
immutable_base_url string
chain_name string
immutable_api_key string
scoreboard_height int32
_flags1_ uint64
_flags2_ uint64
@ -481,6 +482,14 @@ func (this *Config) HasImmutableApiKey() bool {
return (this._flags1_ & (uint64(1) << 6)) > 0
}
func (this *Config) GetScoreboardHeight() int32 {
return this.scoreboard_height
}
func (this *Config) HasScoreboardHeight() bool {
return (this._flags1_ & (uint64(1) << 7)) > 0
}
func (this *Item) GetName() string {
return this.name
}
@ -688,6 +697,7 @@ func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.immutable_base_url, "immutable_base_url", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.chain_name, "chain_name", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.immutable_api_key, "immutable_api_key", &this._flags1_, 6, kv)
f5.ReadMetaTableField(&this.scoreboard_height, "scoreboard_height", &this._flags1_, 7, kv)
}
func (this *Item) LoadFromKv(kv map[string]interface{}) {

View File

@ -71,6 +71,7 @@ message Config
optional string immutable_base_url = 3;
optional string chain_name = 4;
optional string immutable_api_key = 6;
optional int32 scoreboard_height = 7;
}
message Item

View File

@ -0,0 +1,99 @@
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++
}
}

View File

@ -1,8 +1,5 @@
package task
import (
)
type taskMgr struct {
webHook
repairNft
@ -16,6 +13,7 @@ type taskMgr struct {
esCecTransfer
stackingCec
vester
rankchart
}
func (this *taskMgr) Init() {
@ -31,6 +29,7 @@ func (this *taskMgr) Init() {
this.esCecTransfer.init()
this.stackingCec.init()
this.vester.init()
this.rankchart.init()
}
func (this *taskMgr) UnInit() {
@ -46,4 +45,5 @@ func (this *taskMgr) UnInit() {
this.sysMail.unInit()
this.repairNft.unInit()
this.webHook.unInit()
this.rankchart.unInit()
}