上传公会boos代码

This commit is contained in:
liwei1dao 2023-09-14 17:16:50 +08:00
parent 2e214bf274
commit d7d67fbcb6
3 changed files with 88 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import (
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"sync"
)
@ -280,3 +281,62 @@ func (this *ModelUniongve) infochangepush(unionid string, info *pb.DBGuildGve) {
Info: info,
}, users...)
}
// 更新埋点数据到db中
func (this *ModelUniongve) guildgveModel() (model *guildgveModel, err error) {
var (
conn *db.DBConn
m *db.DBModel
)
if db.IsCross() {
model = &guildgveModel{module: this.module, model: this.DBModel}
} else {
if conn, err = db.Cross(); err != nil {
return
}
m = db.NewDBModel(this.TableName, conn)
model = &guildgveModel{module: this.module, model: m}
}
return
}
// 埋点专属模型 会封装特殊的数据转换接口
type guildgveModel struct {
module *GuildGve
model *db.DBModel
}
// 分布式锁
func (this *guildgveModel) userlock(id string) (result *redis.RedisMutex, err error) {
return this.model.Redis.NewRedisMutex(fmt.Sprintf("lockuniongve:%s", id))
}
// 获取用户全部的埋点数据
func (this *guildgveModel) getGuildGve(guildid string) (results *pb.DBGuildGve, err error) {
results = &pb.DBGuildGve{
Boos: make([]*pb.DBGuildGveBoss, 0),
}
if err = this.model.GetByID(guildid, results); err != nil {
this.module.Errorln(err)
return
}
return
}
func (this *guildgveModel) updateGuildGve(data *pb.DBGuildGve) (err error) {
if err = this.model.ChangeById(data.Guildid, map[string]interface{}{
"fire": data.Fire,
"notice": data.Notice,
"currstage": data.Currstage,
"rtime": data.Rtime,
"kills": data.Kills,
"lastkilltime": data.Lastkilltime,
"rank": data.Rank,
"boos": data.Boos,
}); err != nil {
this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()})
return
}
return
}

View File

@ -119,20 +119,25 @@ func (this *GuildGve) ModifyBooslv(session comm.IUserSession, lv int32) (errdata
members []*pb.SociatyMemberInfo
users []string = make([]string, 0)
conf *cfg.GameGuildBossData
model *guildgveModel
err error
)
if sociaty = this.ModuleSociaty.GetSociaty(session.GetUserId()); sociaty != nil {
if sociaty = this.ModuleSociaty.GetSociaty(session.GetUserId()); sociaty == nil {
return
}
lock, _ := this.modelGuildGve.userlock(sociaty.Id)
if model, err = this.modelGuildGve.guildgveModel(); err != nil {
this.Error("guildgveModel err!", log.Field{Key: "Unionid", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()})
return
}
lock, _ := model.userlock(sociaty.Id)
err = lock.Lock()
if err != nil {
this.Error("公会战分布式锁 err!", log.Field{Key: "Unionid", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()})
return
}
defer lock.Unlock()
if info, err = this.modelGuildGve.getGuildGve(sociaty.Id); err != nil {
if info, err = model.getGuildGve(sociaty.Id); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
@ -150,7 +155,7 @@ func (this *GuildGve) ModifyBooslv(session comm.IUserSession, lv int32) (errdata
v.Hp = conf.Hp
v.Record = make([]*pb.DBGveRecord, 0)
}
if err = this.modelGuildGve.updateGuildGve(info); err != nil {
if err = model.updateGuildGve(info); err != nil {
this.Errorln(err)
return
}

View File

@ -11,6 +11,7 @@ import (
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"sort"
@ -169,10 +170,25 @@ func (this *ModelSociaty) findByName(name string) *pb.DBSociaty {
// 获取公会
func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty, err error) {
sociaty = &pb.DBSociaty{}
if db.IsCross() {
if err = this.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil {
this.module.Error("获取工会信息 失败", log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "err", Value: err.Error()})
return
}
} else {
var (
conn *db.DBConn
model *db.DBModel
)
if conn, err = db.Cross(); err != nil {
return
}
model = db.NewDBModel(this.TableName, conn)
if err = model.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil {
this.module.Error("获取工会信息 失败", log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "err", Value: err.Error()})
return
}
}
return
}