Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev

This commit is contained in:
meixiongfeng 2022-10-21 17:43:17 +08:00
commit dbf0e35c37
8 changed files with 193 additions and 25 deletions

View File

@ -122,6 +122,8 @@ const (
TablePagodaRankList = "pagodaranklist" TablePagodaRankList = "pagodaranklist"
TableSeasonRankList = "seasonranklist" // 赛季塔列表 TableSeasonRankList = "seasonranklist" // 赛季塔列表
TableSeasonRecord = "seasonRecord" // 赛季塔记录
/// 美食馆 /// 美食馆
TableSmithy = "smithy" TableSmithy = "smithy"
/// 赛季塔数据表 /// 赛季塔数据表

View File

@ -2,8 +2,11 @@ package pagoda
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "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/bson/primitive"
"google.golang.org/protobuf/proto" "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) 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.Uid = session.GetUserId()
seasonPagoda.PagodaId = 0 // 初始数据0层 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) this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), seasonPagoda)
// 推送新的 // 推送新的
pagoda.PagodaId = seasonPagoda.PagodaId 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 seasonPagoda.PagodaId = conf.LayerNum
mapData["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) 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}) session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda})
} }

View File

@ -39,7 +39,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq
} }
} else { } else {
season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
if season.PagodaId == 0 { // 创建一条新的数据 if season.Id == "" {
season.Id = primitive.NewObjectID().Hex() season.Id = primitive.NewObjectID().Hex()
season.Uid = session.GetUserId() season.Uid = session.GetUserId()
season.PagodaId = 0 // 初始数据0层 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) this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), season)
} }
list = &pb.DBPagoda{ list = &pb.DBPagoda{
Id: season.Id, Id: season.Id,
Uid: season.Uid, Uid: season.Uid,
@ -59,7 +60,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq
Type: season.Type, Type: season.Type,
} }
} }
session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list})
return return
} }

View File

@ -8,6 +8,7 @@ import (
"go_dreamfactory/lego/sys/redis" "go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"sort" "sort"
"time" "time"
@ -55,7 +56,10 @@ func (this *ModelRank) ChangeUserRank(uid string, value map[string]interface{})
func (this *ModelRank) GetRankData() (data []*pb.DBPagodaRecord, err error) { func (this *ModelRank) GetRankData() (data []*pb.DBPagodaRecord, err error) {
data = make([]*pb.DBPagodaRecord, 0) 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 return
} }

View File

@ -4,11 +4,12 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx" "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) { func (this *ModelSeasonPagoda) getSeasonPagodaList(uid string) (result *pb.DBSeasonPagoda, err error) {
result = &pb.DBSeasonPagoda{} result = &pb.DBSeasonPagoda{}
if err = this.Get(uid, result); err != nil { if err = this.Get(uid, result); err != nil {
if redis.RedisNil != err {
result = nil
}
return return
} }
err = nil err = nil
@ -55,6 +54,25 @@ func (this *ModelSeasonPagoda) addNewSeasonPagoda(uId string, data *pb.DBSeasonP
this.module.Errorf("err:%v", err) this.module.Errorf("err:%v", err)
return 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 return nil
} }

View File

@ -66,6 +66,7 @@ func (this *ChatComp) Start() (err error) {
} else { } else {
weekStr = "*" weekStr = "*"
} }
cronStr := fmt.Sprintf("0 %d %d ? * %s", v1.TimeM, v1.TimeH, 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}) 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 { if id, err = cron.AddFunc(cronStr, this.chatNoticen(v1.Text)); err != nil {

View File

@ -7,6 +7,7 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/cron"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
@ -15,8 +16,10 @@ import (
) )
type PagodaRank struct { type PagodaRank struct {
cbase.ModuleBase
modules.MCompModel modules.MCompModel
service core.IService 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.TableName = comm.TablePagodaRecord
this.MCompModel.Init(service, module, comp, options) this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Timer)
this.service = service this.service = service
return return
} }
func (this *PagodaRank) Start() (err error) { func (this *PagodaRank) Start() (err error) {
err = this.MCompModel.Start() err = this.MCompModel.Start()
cron.AddFunc("*/60 * * * * ?", this.Timer) //每60s执行一次
cron.AddFunc("*/60 * * * * ?", this.TimerPagoda) //每60s执行一次
cron.AddFunc("*/60 * * * * ?", this.TimerSeason) //每60s执行一次
return return
} }
// 处理排行榜排序 // 处理排行榜排序
func (this *PagodaRank) Timer() { func (this *PagodaRank) TimerPagoda() {
data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList) 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()) { for _data.Next(context.TODO()) {
temp := &pb.DBPagodaRecord{} temp := &pb.DBPagodaRecord{}
if err = _data.Decode(temp); err == nil { 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")
}
}
}
}

View File

@ -49,20 +49,19 @@ func (this *SeasonPagoda) Start() (err error) {
cron.AddFunc("0 0 23 L * ?", this.TimerSeasonOver) //每月最后一天23点执行一次 cron.AddFunc("0 0 23 L * ?", this.TimerSeasonOver) //每月最后一天23点执行一次
cron.AddFunc("0 0 5 /* * ?", this.TimerSeasonStar) //每月第一天5点执行一次 cron.AddFunc("0 0 5 /* * ?", this.TimerSeasonStar) //每月第一天5点执行一次
// _data := this.GetSeasonLoop(2) newData := &pb.DBPagoda{
// this.module.Debugf("%v", _data) Id: primitive.NewObjectID().Hex(),
// for i := 0; i < 10000; i++ { Uid: "sdsd",
// this.CreatTestData(i) 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 { fmt.Printf("%v", rst)
// rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) }
// server := &pb.DBServerData{}
// rst.Decode(server)
// fmt.Printf("%v", server)
// }
this.TimerSeasonOver()
return return
} }
func (this *SeasonPagoda) CreatTestData(index int) { func (this *SeasonPagoda) CreatTestData(index int) {
@ -135,3 +134,49 @@ func (this *SeasonPagoda) TimerSeasonOver() {
func (this *SeasonPagoda) TimerSeasonStar() { func (this *SeasonPagoda) TimerSeasonStar() {
this.module.Debugf("TimerSeasonStar:%d", time.Now().Unix()) 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()
}