This commit is contained in:
hujiabin 2023-12-11 14:47:38 +08:00
parent dce1028661
commit 027c7c4af6
12 changed files with 561 additions and 256 deletions

View File

@ -39,6 +39,10 @@ func (this *app) Init() {
this.registerDataSources()
this.sessionHash = make(map[string]string)
this.accountIdHash = make(map[string]string)
//seasonMt := mt.Table.RankSeason.GetCurrentSeason()
//fmt.Println("SeasonMeta =====", seasonMt)
//
this.initCb()
}

View File

@ -3,3 +3,6 @@ package common
type App interface {
Run(func(), func())
}
type Task interface {
}

View File

@ -12,6 +12,7 @@ const (
const (
APP_MODULE_IDX = iota
TASK_MODULE_IDX
MAX_MODULE_IDX
)

View File

@ -8,13 +8,19 @@ import (
)
var modules [constant.MAX_MODULE_IDX]q5.Module
var initOrders = []int32{}
var initOrders = []int32{
constant.TASK_MODULE_IDX,
}
var app common.App
var task common.Task
func GetApp() common.App {
return app
}
func GetTask() common.Task {
return task
}
func RegModule(idx int32, m q5.Module) {
fmt.Printf("RegModule module %d\n", idx)
@ -24,6 +30,10 @@ func RegModule(idx int32, m q5.Module) {
{
app = m.(common.App)
}
case constant.TASK_MODULE_IDX:
{
task = m.(common.Task)
}
default:
{
panic("unknow module")

View File

@ -3,6 +3,7 @@ package initialize
import (
_ "main/app"
. "main/global"
_ "main/task"
)
func Init() {

View File

@ -0,0 +1,58 @@
package mt
import (
"f5"
"mtb"
"time"
)
type RankSeason struct {
mtb.RankSeason
_start_time int64
_end_time int64
}
type RankSeasonTable struct {
f5.IdMetaTable[RankSeason]
}
func (this *RankSeason) Init1() {
dt1, _ := time.Parse("2006-1-02 15:04:05", this.GetStartTime())
this._start_time = dt1.Unix()
dt2, _ := time.Parse("2006-1-02 15:04:05", this.GetEndTime())
this._end_time = dt2.Unix()
}
func (this *RankSeasonTable) PostInit1() {
}
func (this *RankSeasonTable) GetCurrentSeason() *RankSeason {
var result *RankSeason
this.Traverse(
func(meta *RankSeason) bool {
if f5.GetApp().GetNowSeconds() >= meta._start_time &&
f5.GetApp().GetNowSeconds() <= meta._end_time {
result = meta
return false
}
return true
})
return result
}
func (this *RankSeasonTable) GetLastSeason() *RankSeason {
var leastSeason *RankSeason
this.Traverse(
func(meta *RankSeason) bool {
if f5.GetApp().GetNowSeconds() >= meta._start_time {
if leastSeason == nil {
leastSeason = meta
} else if leastSeason._end_time < meta._end_time {
leastSeason = meta
}
}
return true
})
return leastSeason
}

View File

@ -1,34 +1,40 @@
package mt
import (
"f5"
)
type table struct {
AdminCluster *AdminClusterTable
GameDb *GameDbTable
FriendDb *FriendDbTable
Config *ConfigTable
}
var Table = f5.New(func (this* table) {
this.AdminCluster = f5.New(func (this *AdminClusterTable) {
this.FileName = "../config/adminserver.cluster.json"
this.PrimKey = "instance_id"
});
this.GameDb = f5.New(func (this *GameDbTable) {
this.FileName = "../config/gamedb.mysql.json"
this.PrimKey = ""
});
this.FriendDb = f5.New(func (this *FriendDbTable) {
this.FileName = "../config/frienddb.mysql.json"
this.PrimKey = ""
});
this.Config = f5.New(func (this *ConfigTable) {
this.FileName = "../config/config.json"
this.PrimKey = ""
});
})
package mt
import (
"f5"
)
type table struct {
AdminCluster *AdminClusterTable
GameDb *GameDbTable
FriendDb *FriendDbTable
Config *ConfigTable
RankSeason *RankSeasonTable
}
var Table = f5.New(func(this *table) {
this.AdminCluster = f5.New(func(this *AdminClusterTable) {
this.FileName = "../config/adminserver.cluster.json"
this.PrimKey = "instance_id"
})
this.GameDb = f5.New(func(this *GameDbTable) {
this.FileName = "../config/gamedb.mysql.json"
this.PrimKey = ""
})
this.FriendDb = f5.New(func(this *FriendDbTable) {
this.FileName = "../config/frienddb.mysql.json"
this.PrimKey = ""
})
this.Config = f5.New(func(this *ConfigTable) {
this.FileName = "../config/config.json"
this.PrimKey = ""
})
this.RankSeason = f5.New(func(this *RankSeasonTable) {
this.FileName = "../res/rankSeason@rankSeason.json"
this.PrimKey = "id"
})
})

View File

@ -1,221 +1,290 @@
package mtb
import (
"f5"
)
type AdminCluster struct {
instance_id int32
listen_port int32
http_listen_port int32
_flags1_ uint64
_flags2_ uint64
}
type MasterCluster struct {
instance_id int32
ip string
listen_port int32
_flags1_ uint64
_flags2_ uint64
}
type GameDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type FriendDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type Config struct {
gameapi_url string
_flags1_ uint64
_flags2_ uint64
}
func (this *AdminCluster) GetInstanceId() int32 {
return this.instance_id
}
func (this *AdminCluster) HasInstanceId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *AdminCluster) GetListenPort() int32 {
return this.listen_port
}
func (this *AdminCluster) HasListenPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *AdminCluster) GetHttpListenPort() int32 {
return this.http_listen_port
}
func (this *AdminCluster) HasHttpListenPort() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *MasterCluster) GetInstanceId() int32 {
return this.instance_id
}
func (this *MasterCluster) HasInstanceId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *MasterCluster) GetIp() string {
return this.ip
}
func (this *MasterCluster) HasIp() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *MasterCluster) GetListenPort() int32 {
return this.listen_port
}
func (this *MasterCluster) HasListenPort() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *GameDb) GetHost() string {
return this.host
}
func (this *GameDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *GameDb) GetPort() int32 {
return this.port
}
func (this *GameDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *GameDb) GetUser() string {
return this.user
}
func (this *GameDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *GameDb) GetPasswd() string {
return this.passwd
}
func (this *GameDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *GameDb) GetDatabase() string {
return this.database
}
func (this *GameDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *FriendDb) GetHost() string {
return this.host
}
func (this *FriendDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *FriendDb) GetPort() int32 {
return this.port
}
func (this *FriendDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *FriendDb) GetUser() string {
return this.user
}
func (this *FriendDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *FriendDb) GetPasswd() string {
return this.passwd
}
func (this *FriendDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *FriendDb) GetDatabase() string {
return this.database
}
func (this *FriendDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *Config) GetGameapiUrl() string {
return this.gameapi_url
}
func (this *Config) HasGameapiUrl() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *AdminCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.http_listen_port, "http_listen_port", &this._flags1_, 3, kv)
}
func (this *MasterCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.ip, "ip", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 3, kv)
}
func (this *GameDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *FriendDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv)
}
package mtb
import (
"f5"
)
type AdminCluster struct {
instance_id int32
listen_port int32
http_listen_port int32
_flags1_ uint64
_flags2_ uint64
}
type GameDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type FriendDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type AdminDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type Config struct {
gameapi_url string
_flags1_ uint64
_flags2_ uint64
}
type RankSeason struct {
id int32
name string
start_time string
end_time string
_flags1_ uint64
_flags2_ uint64
}
func (this *AdminCluster) GetInstanceId() int32 {
return this.instance_id
}
func (this *AdminCluster) HasInstanceId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *AdminCluster) GetListenPort() int32 {
return this.listen_port
}
func (this *AdminCluster) HasListenPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *AdminCluster) GetHttpListenPort() int32 {
return this.http_listen_port
}
func (this *AdminCluster) HasHttpListenPort() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *GameDb) GetHost() string {
return this.host
}
func (this *GameDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *GameDb) GetPort() int32 {
return this.port
}
func (this *GameDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *GameDb) GetUser() string {
return this.user
}
func (this *GameDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *GameDb) GetPasswd() string {
return this.passwd
}
func (this *GameDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *GameDb) GetDatabase() string {
return this.database
}
func (this *GameDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *FriendDb) GetHost() string {
return this.host
}
func (this *FriendDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *FriendDb) GetPort() int32 {
return this.port
}
func (this *FriendDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *FriendDb) GetUser() string {
return this.user
}
func (this *FriendDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *FriendDb) GetPasswd() string {
return this.passwd
}
func (this *FriendDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *FriendDb) GetDatabase() string {
return this.database
}
func (this *FriendDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *AdminDb) GetHost() string {
return this.host
}
func (this *AdminDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *AdminDb) GetPort() int32 {
return this.port
}
func (this *AdminDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *AdminDb) GetUser() string {
return this.user
}
func (this *AdminDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *AdminDb) GetPasswd() string {
return this.passwd
}
func (this *AdminDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *AdminDb) GetDatabase() string {
return this.database
}
func (this *AdminDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *Config) GetGameapiUrl() string {
return this.gameapi_url
}
func (this *Config) HasGameapiUrl() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *RankSeason) GetId() int32 {
return this.id
}
func (this *RankSeason) HasId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *RankSeason) GetName() string {
return this.name
}
func (this *RankSeason) HasName() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *RankSeason) GetStartTime() string {
return this.start_time
}
func (this *RankSeason) HasStartTime() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *RankSeason) GetEndTime() string {
return this.end_time
}
func (this *RankSeason) HasEndTime() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *AdminCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.http_listen_port, "http_listen_port", &this._flags1_, 3, kv)
}
func (this *GameDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *FriendDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *AdminDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv)
}
func (this *RankSeason) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.id, "id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.name, "name", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.start_time, "start_time", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.end_time, "end_time", &this._flags1_, 4, kv)
}

View File

@ -40,3 +40,11 @@ message Config
{
optional string gameapi_url = 1;
}
message RankSeason
{
optional int32 id = 1;
optional string name = 2;
optional string start_time = 3;
optional string end_time = 4;
}

View File

@ -0,0 +1,12 @@
package task
import (
"main/constant"
"main/global"
)
var _task = new(taskMgr)
func init() {
global.RegModule(constant.TASK_MODULE_IDX, _task)
}

View File

@ -0,0 +1,119 @@
package task
import (
"f5"
"fmt"
"main/constant"
"q5"
)
type RankingList struct {
idx int64
account_id string
address string
channel int32
rank int32
score int32
ranking int32
ranking_point int32
season int32
createtime int32
modifytime int32
}
type userDb struct {
idx int64
account_id string
address string
channel int32
rank int32
score int32
score_modifytime int64
}
type SeasonRankMgr struct {
userData map[int64]*userDb
}
func (this *SeasonRankMgr) Init() {
this.userData = make(map[int64]*userDb)
this.CalcRanking()
fmt.Println("Task init success")
}
func (this *SeasonRankMgr) UnInit() {
}
// var lastIdx int64 = 0
var done bool = false
var baseScore int32 = 4000
func (this *SeasonRankMgr) CalcRanking() {
lastIdx := int64(0)
this.getUsersRecords(lastIdx, 100)
//for !done {
// this.getUsersRecords(lastIdx, 10)
//}
this.pushRankingResult()
}
func (this *SeasonRankMgr) getUsersRecords(lastIdx int64, limit int64) {
sql := fmt.Sprintf("SELECT idx,account_id,channel,`rank`,score,score_modifytime,`address` FROM t_user WHERE score > %d and idx > %d limit %d",
baseScore, 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"))
}
if empty {
done = true
}
fmt.Println(this.userData)
},
)
//return userDbs
}
func (this *SeasonRankMgr) pushRankingResult() {
for _, v := range this.userData {
fields := [][]string{
{"account_id", v.account_id},
{"address", v.address},
{"channel", q5.ToString(v.channel)},
{"rank", q5.ToString(v.rank)},
{"score", q5.ToString(v.score)},
{"season", q5.ToString(2)},
{"createtime", q5.ToString(f5.GetApp().GetNowSeconds())},
{"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())},
}
f5.GetJsStyleDb().Insert(
constant.GAME_DB,
"t_season_ranking",
fields,
func(err error, id int64, affectedRows int64) {
if err != nil || affectedRows != 1 {
// 插入失败,处理错误逻辑
fmt.Printf("Failed to insert guild: %v", err)
}
},
)
}
}

View File

@ -0,0 +1,14 @@
package task
type taskMgr struct {
SeasonRankMgr
}
func (t *taskMgr) Init() {
t.SeasonRankMgr.Init()
}
func (t *taskMgr) UnInit() {
t.SeasonRankMgr.UnInit()
}