|
|
@ -80,95 +80,51 @@ func InitRankJob(svcCtx *svc.ServiceContext) {
|
|
|
|
// 3. 开启任务 定时落库
|
|
|
|
// 3. 开启任务 定时落库
|
|
|
|
func (j *Job) initJob() {
|
|
|
|
func (j *Job) initJob() {
|
|
|
|
logx.Info("开启排行榜服务...")
|
|
|
|
logx.Info("开启排行榜服务...")
|
|
|
|
j.initByType(model.RankTypeDamage)
|
|
|
|
// TODO 读取历史数据功能暂时移除
|
|
|
|
j.initByType(model.RankTypeDeDamage)
|
|
|
|
//j.initByType(model.RankTypeDamage)
|
|
|
|
j.initByType(model.RankTypeGeneral)
|
|
|
|
//j.initByType(model.RankTypeDeDamage)
|
|
|
|
j.initByType(model.RankTypeDeGeneral)
|
|
|
|
//j.initByType(model.RankTypeGeneral)
|
|
|
|
j.initByType(model.RankTypeKillUnit)
|
|
|
|
//j.initByType(model.RankTypeDeGeneral)
|
|
|
|
j.initByType(model.RankTypeDeKillUnit)
|
|
|
|
//j.initByType(model.RankTypeKillUnit)
|
|
|
|
j.initByType(model.RankTypeKillPlayer)
|
|
|
|
//j.initByType(model.RankTypeDeKillUnit)
|
|
|
|
j.initByType(model.RankTypeDeKillPlayer)
|
|
|
|
//j.initByType(model.RankTypeKillPlayer)
|
|
|
|
j.initByType(model.RankTypeWin)
|
|
|
|
//j.initByType(model.RankTypeDeKillPlayer)
|
|
|
|
j.initByType(model.RankTypeLost)
|
|
|
|
//j.initByType(model.RankTypeWin)
|
|
|
|
j.initByType(model.RankTypeFirstBlood)
|
|
|
|
//j.initByType(model.RankTypeLost)
|
|
|
|
j.initByType(model.RankTypeDeFirstBlood)
|
|
|
|
//j.initByType(model.RankTypeFirstBlood)
|
|
|
|
|
|
|
|
//j.initByType(model.RankTypeDeFirstBlood)
|
|
|
|
|
|
|
|
|
|
|
|
cfg := j.svcCtx.Config.Rank
|
|
|
|
cfg := j.svcCtx.Config.Rank
|
|
|
|
// job read and update
|
|
|
|
// job read and update
|
|
|
|
c := cron.New()
|
|
|
|
c := cron.New()
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
j.readAndUpdate(model.RankTypeDamage)
|
|
|
|
go j.readAndUpdate(model.RankTypeDamage)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeDamage)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeGeneral)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeGeneral)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeKillUnit)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeKillUnit)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeKillPlayer)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeKillPlayer)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeWin)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeLost)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeFirstBlood)
|
|
|
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeFirstBlood)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeDamage)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeGeneral)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeGeneral)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeKillUnit)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeKillUnit)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeKillPlayer)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeKillPlayer)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeWin)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeLost)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeFirstBlood)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeFirstBlood)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// persistence
|
|
|
|
// persistence
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
j.persistence(model.RankTypeDamage)
|
|
|
|
go j.persistence(model.RankTypeDamage)
|
|
|
|
})
|
|
|
|
go j.persistence(model.RankTypeDeDamage)
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
go j.persistence(model.RankTypeGeneral)
|
|
|
|
j.persistence(model.RankTypeDeDamage)
|
|
|
|
go j.persistence(model.RankTypeDeGeneral)
|
|
|
|
})
|
|
|
|
go j.persistence(model.RankTypeKillUnit)
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
go j.persistence(model.RankTypeDeKillUnit)
|
|
|
|
j.persistence(model.RankTypeGeneral)
|
|
|
|
go j.persistence(model.RankTypeKillPlayer)
|
|
|
|
})
|
|
|
|
go j.persistence(model.RankTypeDeKillPlayer)
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
go j.persistence(model.RankTypeWin)
|
|
|
|
j.persistence(model.RankTypeDeGeneral)
|
|
|
|
go j.persistence(model.RankTypeLost)
|
|
|
|
})
|
|
|
|
go j.persistence(model.RankTypeFirstBlood)
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
go j.persistence(model.RankTypeDeFirstBlood)
|
|
|
|
j.persistence(model.RankTypeKillUnit)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeDeKillUnit)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeKillPlayer)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeDeKillPlayer)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeWin)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeLost)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeFirstBlood)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
|
|
|
j.persistence(model.RankTypeDeFirstBlood)
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
c.Start()
|
|
|
|
c.Start()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -251,16 +207,14 @@ func (j *Job) readAndUpdate(rankType int32) {
|
|
|
|
|
|
|
|
|
|
|
|
rankLen := len(rank)
|
|
|
|
rankLen := len(rank)
|
|
|
|
var score int64
|
|
|
|
var score int64
|
|
|
|
if rankLen == 0 {
|
|
|
|
if rankLen > 0 {
|
|
|
|
score = 0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 取当前榜最后一名分数
|
|
|
|
// 取当前榜最后一名分数
|
|
|
|
score = rank[rankLen-1][1]
|
|
|
|
score = rank[rankLen-1][1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 若榜内数量不够,则直接取 max - len 数量的人 score排序一下
|
|
|
|
// 若榜内数量不够,则直接取 max - len 数量的人 score排序一下
|
|
|
|
limit := model.MaxRankN
|
|
|
|
limit := model.MaxRankN
|
|
|
|
if rankLen < model.MaxRankN {
|
|
|
|
if rankLen < model.MaxRankN {
|
|
|
|
limit = model.MaxRankN - rankLen + 1 // +1是避免取到自己后少取一位
|
|
|
|
limit = model.MaxRankN - rankLen + 1 // +1是避免取到自己 少取一位
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 末位 score
|
|
|
|
// 末位 score
|
|
|
|