84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package timer
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/lego/sys/log"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
// 此组件废弃
|
|
type PagodaRank struct {
|
|
cbase.ModuleBase
|
|
modules.MCompModel
|
|
service core.IService
|
|
module *Timer
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *PagodaRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
|
|
this.TableName = comm.TablePagodaRecord
|
|
this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Timer)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *PagodaRank) Start() (err error) {
|
|
err = this.MCompModel.Start()
|
|
//cron.AddFunc("*/60 * * * * ?", this.TimerPagoda) //每60s执行一次
|
|
//cron.AddFunc("*/60 * * * * ?", this.TimerSeason) //每60s执行一次
|
|
return
|
|
}
|
|
|
|
// 处理排行榜排序
|
|
func (this *PagodaRank) TimerPagoda() {
|
|
data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList)
|
|
if _data, err := this.DB.Find(comm.TablePagoda, bson.M{}, options.Find().SetSort(bson.M{"pagodaId": -1}).SetLimit(comm.MaxRankList)); err == nil {
|
|
for _data.Next(context.TODO()) {
|
|
temp := &pb.DBPagodaRecord{}
|
|
if err = _data.Decode(temp); err == nil {
|
|
data = append(data, temp)
|
|
}
|
|
}
|
|
}
|
|
if len(data) > 0 {
|
|
err := this.Redis.RPush(comm.TablePagodaRankList, data...)
|
|
if err == nil {
|
|
err = this.Redis.Ltrim(comm.TablePagodaRankList, -1*len(data), -1) //对一个列表进行修剪
|
|
if err != nil {
|
|
log.Errorf("delete failed")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// func (this *PagodaRank) TimerSeason() {
|
|
// data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList)
|
|
// if _data, err := this.DB.Find(comm.TableSeasonPagoda, bson.M{}, options.Find().SetSort(bson.M{"pagodaId": -1}).SetLimit(comm.MaxRankList)); err == nil {
|
|
// for _data.Next(context.TODO()) {
|
|
// temp := &pb.DBPagodaRecord{}
|
|
// if err = _data.Decode(temp); err == nil {
|
|
// data = append(data, temp)
|
|
// }
|
|
// }
|
|
// }
|
|
// if len(data) > 0 {
|
|
// err := this.Redis.RPush(comm.TableSeasonRankList, data...)
|
|
// if err == nil {
|
|
// err = this.Redis.Ltrim(comm.TableSeasonRankList, -1*len(data), -1) //对一个列表进行修剪
|
|
// if err != nil {
|
|
// log.Errorf("delete failed")
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|