From d7d67fbcb6f49e71f7147b9f93670e47374eae53 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 14 Sep 2023 17:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=85=AC=E4=BC=9Aboos?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/guildgve/modelUniongve.go | 60 +++++++++++++++++++++++++++++++ modules/guildgve/module.go | 13 ++++--- modules/sociaty/model_sociaty.go | 22 ++++++++++-- 3 files changed, 88 insertions(+), 7 deletions(-) diff --git a/modules/guildgve/modelUniongve.go b/modules/guildgve/modelUniongve.go index 6772955ac..ebd61f506 100644 --- a/modules/guildgve/modelUniongve.go +++ b/modules/guildgve/modelUniongve.go @@ -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 +} diff --git a/modules/guildgve/module.go b/modules/guildgve/module.go index e2e43324b..6991b72dd 100644 --- a/modules/guildgve/module.go +++ b/modules/guildgve/module.go @@ -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 } diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index a0c7d43d7..a0877d90e 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -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,9 +170,24 @@ func (this *ModelSociaty) findByName(name string) *pb.DBSociaty { // 获取公会 func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty, err error) { sociaty = &pb.DBSociaty{} - 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 + 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 }