68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package guildgve
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"sync"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
type Modelbattlerank struct {
|
|
modules.MCompModel
|
|
module *GuildGve
|
|
conflock sync.RWMutex
|
|
bossconf *pb.DBGuildGveBossConf
|
|
}
|
|
|
|
func (this *Modelbattlerank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.TableName = comm.TableGuildGvebattlerank
|
|
this.module = module.(*GuildGve)
|
|
return
|
|
}
|
|
|
|
func (this *Modelbattlerank) Start() (err error) {
|
|
err = this.MCompModel.Start()
|
|
return
|
|
}
|
|
|
|
func (this *Modelbattlerank) key(boos int32) string {
|
|
return fmt.Sprintf("%s-%s:%d", this.DBModel.ServiceId, this.TableName, boos)
|
|
}
|
|
|
|
// 获取排行榜前50的用户名单
|
|
func (this *Modelbattlerank) queryRankUser(boos int32) (ranks []string, err error) {
|
|
var (
|
|
key string
|
|
result []string
|
|
)
|
|
key = this.key(boos)
|
|
if result, err = this.DBModel.Redis.ZRevRange(key, 0, 50).Result(); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
ranks = make([]string, 0)
|
|
for i := 0; i < len(result); i += 2 {
|
|
ranks = append(ranks, result[i])
|
|
}
|
|
return
|
|
}
|
|
|
|
// 更新排名
|
|
func (this *Modelbattlerank) updateRank(boos int32, score int32, member string) (err error) {
|
|
var (
|
|
key string
|
|
menbers *redis.Z
|
|
)
|
|
key = this.key(boos)
|
|
menbers = &redis.Z{Score: float64(score), Member: member}
|
|
if err = this.Redis.ZAdd(key, menbers); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
return
|
|
}
|