Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
dbf0e35c37
@ -122,6 +122,8 @@ const (
|
||||
TablePagodaRankList = "pagodaranklist"
|
||||
|
||||
TableSeasonRankList = "seasonranklist" // 赛季塔列表
|
||||
|
||||
TableSeasonRecord = "seasonRecord" // 赛季塔记录
|
||||
/// 美食馆
|
||||
TableSmithy = "smithy"
|
||||
/// 赛季塔数据表
|
||||
|
@ -2,8 +2,11 @@ package pagoda
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -107,7 +110,23 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
}
|
||||
}
|
||||
}
|
||||
this.module.modulerank.addPagodaList(session, pagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime)
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||
newData := &pb.DBPagodaRecord{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: session.GetUserId(),
|
||||
PagodaId: pagoda.PagodaId,
|
||||
Type: pagoda.Type,
|
||||
Nickname: userinfo.Name,
|
||||
Icon: "", // icon 暂无
|
||||
Lv: userinfo.Lv,
|
||||
CostTime: req.Report.Costtime,
|
||||
}
|
||||
conn.Mgo.InsertOne(comm.TablePagodaRecord, newData)
|
||||
}
|
||||
}
|
||||
//this.module.modulerank.addPagodaList(session, pagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime)
|
||||
}
|
||||
// 普通塔通关了
|
||||
Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1)
|
||||
@ -122,7 +141,13 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
|
||||
seasonPagoda.Uid = session.GetUserId()
|
||||
seasonPagoda.PagodaId = 0 // 初始数据0层
|
||||
seasonPagoda.Type = 201
|
||||
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{})
|
||||
server := &pb.DBServerData{}
|
||||
rst.Decode(server)
|
||||
seasonPagoda.Type = server.SeasonType // 动态获取塔数据
|
||||
}
|
||||
this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), seasonPagoda)
|
||||
// 推送新的
|
||||
pagoda.PagodaId = seasonPagoda.PagodaId
|
||||
@ -142,13 +167,57 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
}
|
||||
}
|
||||
}
|
||||
this.module.modulerank.addPagodaRankList(session, seasonPagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime)
|
||||
// 数据直接插入跨服数据库中
|
||||
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||
newData := &pb.DBPagodaRecord{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: session.GetUserId(),
|
||||
PagodaId: seasonPagoda.PagodaId,
|
||||
Type: seasonPagoda.Type,
|
||||
Nickname: userinfo.Name,
|
||||
Icon: "", // icon 暂无
|
||||
Lv: userinfo.Lv,
|
||||
CostTime: req.Report.Costtime,
|
||||
}
|
||||
// 数据写到跨服中
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
conn.Mgo.InsertOne(comm.TableSeasonRecord, newData)
|
||||
}
|
||||
}
|
||||
//this.module.modulerank.addPagodaRankList(session, seasonPagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime)
|
||||
}
|
||||
|
||||
// 挑战处理
|
||||
seasonPagoda.PagodaId = conf.LayerNum
|
||||
mapData["pagodaId"] = conf.LayerNum
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
data := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: seasonPagoda.Uid,
|
||||
Act: string(comm.LogHandleType_Update),
|
||||
}
|
||||
table := comm.TableSeasonRecord //, uid, , data)
|
||||
data.D = append(data.D, table) // D[0]
|
||||
data.D = append(data.D, bson.M{"uid": session.GetUserId()}) // D[1]
|
||||
data.D = append(data.D, seasonPagoda) // D[2]
|
||||
|
||||
_, err = conn.Mgo.InsertOne("model_log", data)
|
||||
if err != nil {
|
||||
log.Errorf("insert model db err %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData)
|
||||
pagoda = &pb.DBPagoda{
|
||||
Id: seasonPagoda.Id,
|
||||
Uid: seasonPagoda.Uid,
|
||||
PagodaId: seasonPagoda.PagodaId,
|
||||
Reward: seasonPagoda.Reward,
|
||||
Type: seasonPagoda.Type,
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda})
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq
|
||||
}
|
||||
} else {
|
||||
season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
|
||||
if season.PagodaId == 0 { // 创建一条新的数据
|
||||
if season.Id == "" {
|
||||
season.Id = primitive.NewObjectID().Hex()
|
||||
season.Uid = session.GetUserId()
|
||||
season.PagodaId = 0 // 初始数据0层
|
||||
@ -51,6 +51,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq
|
||||
}
|
||||
this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), season)
|
||||
}
|
||||
|
||||
list = &pb.DBPagoda{
|
||||
Id: season.Id,
|
||||
Uid: season.Uid,
|
||||
@ -59,7 +60,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq
|
||||
Type: season.Type,
|
||||
}
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list})
|
||||
return
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@ -55,7 +56,10 @@ func (this *ModelRank) ChangeUserRank(uid string, value map[string]interface{})
|
||||
|
||||
func (this *ModelRank) GetRankData() (data []*pb.DBPagodaRecord, err error) {
|
||||
data = make([]*pb.DBPagodaRecord, 0)
|
||||
err = this.Redis.LRange(comm.TablePagodaRankList, 0, -1, &data)
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
err = conn.Redis.LRange(comm.TableSeasonRankList, 0, -1, &data)
|
||||
}
|
||||
//err = this.Redis.LRange(comm.TablePagodaRankList, 0, -1, &data)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -4,11 +4,12 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
)
|
||||
@ -34,9 +35,7 @@ func (this *ModelSeasonPagoda) Init(service core.IService, module core.IModule,
|
||||
func (this *ModelSeasonPagoda) getSeasonPagodaList(uid string) (result *pb.DBSeasonPagoda, err error) {
|
||||
result = &pb.DBSeasonPagoda{}
|
||||
if err = this.Get(uid, result); err != nil {
|
||||
if redis.RedisNil != err {
|
||||
result = nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
@ -55,6 +54,25 @@ func (this *ModelSeasonPagoda) addNewSeasonPagoda(uId string, data *pb.DBSeasonP
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
data1 := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: uId,
|
||||
Act: string(comm.LogHandleType_Update),
|
||||
}
|
||||
table := comm.TableSeasonRecord //, uid, , data)
|
||||
data1.D = append(data1.D, table) // D[0]
|
||||
data1.D = append(data1.D, bson.M{"uid": uId}) // D[1]
|
||||
data1.D = append(data1.D, data) // D[2]
|
||||
|
||||
_, err = conn.Mgo.InsertOne("model_log", data1)
|
||||
if err != nil {
|
||||
log.Errorf("insert model db err %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ func (this *ChatComp) Start() (err error) {
|
||||
} else {
|
||||
weekStr = "*"
|
||||
}
|
||||
|
||||
cronStr := fmt.Sprintf("0 %d %d ? * %s", v1.TimeM, v1.TimeH, weekStr)
|
||||
this.module.Debug("注册Chat广播公告消息", log.Field{Key: "cronStr", Value: cronStr}, log.Field{Key: "text", Value: v1.Text})
|
||||
if id, err = cron.AddFunc(cronStr, this.chatNoticen(v1.Text)); err != nil {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
"go_dreamfactory/lego/sys/cron"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
|
||||
@ -15,8 +16,10 @@ import (
|
||||
)
|
||||
|
||||
type PagodaRank struct {
|
||||
cbase.ModuleBase
|
||||
modules.MCompModel
|
||||
service core.IService
|
||||
module *Timer
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
@ -24,20 +27,25 @@ func (this *PagodaRank) Init(service core.IService, module core.IModule, comp co
|
||||
|
||||
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.Timer) //每60s执行一次
|
||||
|
||||
cron.AddFunc("*/60 * * * * ?", this.TimerPagoda) //每60s执行一次
|
||||
|
||||
cron.AddFunc("*/60 * * * * ?", this.TimerSeason) //每60s执行一次
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 处理排行榜排序
|
||||
func (this *PagodaRank) Timer() {
|
||||
func (this *PagodaRank) TimerPagoda() {
|
||||
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 {
|
||||
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 {
|
||||
@ -55,3 +63,24 @@ func (this *PagodaRank) Timer() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,20 +49,19 @@ func (this *SeasonPagoda) Start() (err error) {
|
||||
cron.AddFunc("0 0 23 L * ?", this.TimerSeasonOver) //每月最后一天23点执行一次
|
||||
cron.AddFunc("0 0 5 /* * ?", this.TimerSeasonStar) //每月第一天5点执行一次
|
||||
|
||||
// _data := this.GetSeasonLoop(2)
|
||||
// this.module.Debugf("%v", _data)
|
||||
// for i := 0; i < 10000; i++ {
|
||||
// this.CreatTestData(i)
|
||||
// }
|
||||
newData := &pb.DBPagoda{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: "sdsd",
|
||||
PagodaId: 2,
|
||||
Reward: map[int32]bool{},
|
||||
Type: 101,
|
||||
}
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
rst, _ := conn.Mgo.InsertOne(comm.TableSeasonPagoda, newData)
|
||||
|
||||
// if conn, err := db.Cross(); err == nil {
|
||||
// rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{})
|
||||
// server := &pb.DBServerData{}
|
||||
// rst.Decode(server)
|
||||
// fmt.Printf("%v", server)
|
||||
// }
|
||||
fmt.Printf("%v", rst)
|
||||
}
|
||||
|
||||
this.TimerSeasonOver()
|
||||
return
|
||||
}
|
||||
func (this *SeasonPagoda) CreatTestData(index int) {
|
||||
@ -135,3 +134,49 @@ func (this *SeasonPagoda) TimerSeasonOver() {
|
||||
func (this *SeasonPagoda) TimerSeasonStar() {
|
||||
this.module.Debugf("TimerSeasonStar:%d", time.Now().Unix())
|
||||
}
|
||||
|
||||
// 测试用 后面删
|
||||
func (this *SeasonPagoda) TestFunc() {
|
||||
// newData1 := &pb.DBSeasonPagoda{
|
||||
// Id: primitive.NewObjectID().Hex(),
|
||||
// Uid: "sdsdassd",
|
||||
// PagodaId: 1,
|
||||
// Reward: map[int32]bool{},
|
||||
// Type: 201,
|
||||
// }
|
||||
// if conn, err := db.Cross(); err == nil {
|
||||
// rst, err := conn.Mgo.InsertOne(comm.TableSeasonPagoda, newData)
|
||||
|
||||
// fmt.Printf("%v,%v", rst, err)
|
||||
// }
|
||||
// _data := this.GetSeasonLoop(2)
|
||||
// this.module.Debugf("%v", _data)
|
||||
// for i := 0; i < 10000; i++ {
|
||||
// this.CreatTestData(i)
|
||||
// }
|
||||
|
||||
// if conn, err := db.Cross(); err == nil {
|
||||
// rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{})
|
||||
// server := &pb.DBServerData{}
|
||||
// rst.Decode(server)
|
||||
// fmt.Printf("%v", server)
|
||||
// }
|
||||
|
||||
// newData := &pb.DBPagodaRecord{
|
||||
// Id: primitive.NewObjectID().Hex(),
|
||||
// Uid: "sdsd",
|
||||
// PagodaId: 1,
|
||||
// Type: 2,
|
||||
// Nickname: "userinfo.Name",
|
||||
// Icon: "", // icon 暂无
|
||||
// Lv: 12,
|
||||
// CostTime: 12000,
|
||||
// }
|
||||
// // 数据写到跨服中
|
||||
// if !db.IsCross() {
|
||||
// if conn, err := db.Cross(); err == nil {
|
||||
// conn.Mgo.InsertOne(comm.TableSeasonRecord, newData)
|
||||
// }
|
||||
// }
|
||||
//this.TimerSeasonOver()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user