From 637fb163dda5c5d2dbc1c5be99ea3a627a9e7b90 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 26 Sep 2022 19:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=98=E6=96=97=E7=BB=93=E6=9D=9F=E7=BB=99?= =?UTF-8?q?=E8=8B=B1=E9=9B=84=E5=8A=A0=E7=BB=8F=E9=AA=8C=20=E5=81=9A?= =?UTF-8?q?=E4=B8=8B=E8=8B=B1=E9=9B=84id=20=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_strengthenUplv.go | 1 + modules/hero/model_hero.go | 4 +++- modules/hero/module.go | 4 ++++ sys/db/dbconn.go | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/hero/api_strengthenUplv.go b/modules/hero/api_strengthenUplv.go index 50f5d024d..3e0dce16a 100644 --- a/modules/hero/api_strengthenUplv.go +++ b/modules/hero/api_strengthenUplv.go @@ -52,6 +52,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren if code != pb.ErrorCode_Success { return } + //this.module.Debug("StrengthenUplv", log.Field{Key: "hero", Value: _hero}) // 只有英雄卡才能升级 if _hero.CardType != comm.CardTypeHero { code = pb.ErrorCode_HeroTypeErr diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 172ad6712..2a0930a25 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -545,10 +545,12 @@ func (this *ModelHero) AddCardExp(uid string, hero *pb.DBHero, exp int32) (newhe hero.Exp = curExp hero.IsOverlying = false hero.SameCount = 1 - + this.moduleHero.Debugf("add hero exp :%v", hero) if err := this.ChangeList(uid, hero.Id, update); err != nil { + this.moduleHero.Errorf("add hero exp failed ChangeList %v", err) code = pb.ErrorCode_DBError } + } return } diff --git a/modules/hero/module.go b/modules/hero/module.go index f2aae5d06..0f723eb7e 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -283,10 +283,14 @@ func (this *Hero) AddHeroExp(session comm.IUserSession, heroObjID string, exp in newhero *pb.DBHero _changeHero []*pb.DBHero // 变化的英雄 ) + if heroObjID == "" { + return + } _hero, code = this.GetHeroByObjID(session.GetUserId(), heroObjID) if code != pb.ErrorCode_Success { return } + //this.Debug("AddHeroExp", log.Field{Key: "hero", Value: _hero}) newhero, code = this.modelHero.AddCardExp(session.GetUserId(), _hero, exp) if code != pb.ErrorCode_Success { return diff --git a/sys/db/dbconn.go b/sys/db/dbconn.go index 7cf6cd1df..ba8698277 100644 --- a/sys/db/dbconn.go +++ b/sys/db/dbconn.go @@ -151,6 +151,7 @@ func (this *DBModel) UpdateModelLogs(table string, uID string, where bson.M, tar //添加新的数据 func (this *DBModel) Add(uid string, data interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel Add", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "data", Value: data}) if err = this.Redis.HMSet(this.ukey(uid), data); err != nil { return } @@ -167,6 +168,7 @@ func (this *DBModel) Add(uid string, data interface{}, opt ...DBOption) (err err //添加新的数据到列表 func (this *DBModel) AddList(uid string, id string, data interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel AddList", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "_id", Value: id}, log.Field{Key: "data", Value: data}) key := this.ukeylist(uid, id) if err = this.Redis.HMSet(key, data); err != nil { return @@ -187,6 +189,7 @@ func (this *DBModel) AddList(uid string, id string, data interface{}, opt ...DBO //添加新的多个数据到列表 data map[string]type func (this *DBModel) AddLists(uid string, data interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel AddLists", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "data", Value: data}) vof := reflect.ValueOf(data) if !vof.IsValid() { return fmt.Errorf("Model_Comp: AddLists(nil)") @@ -229,6 +232,7 @@ func (this *DBModel) AddLists(uid string, data interface{}, opt ...DBOption) (er //添加队列 func (this *DBModel) AddQueues(key string, uplimit int64, data interface{}) (outkey []string, err error) { + //defer log.Debug("DBModel AddQueues", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "key", Value: key}, log.Field{Key: "data", Value: data}) vof := reflect.ValueOf(data) if !vof.IsValid() { err = fmt.Errorf("Model_Comp: AddLists(nil)") @@ -268,6 +272,7 @@ func (this *DBModel) AddQueues(key string, uplimit int64, data interface{}) (out //修改数据多个字段 uid 作为主键 func (this *DBModel) Change(uid string, data map[string]interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel Change", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "data", Value: data}) if err = this.Redis.HMSet(this.ukey(uid), data); err != nil { return } @@ -284,7 +289,9 @@ func (this *DBModel) Change(uid string, data map[string]interface{}, opt ...DBOp //修改数据多个字段 uid 作为主键 func (this *DBModel) ChangeList(uid string, _id string, data map[string]interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel ChangeList", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "_id", Value: _id}, log.Field{Key: "data", Value: data}) if err = this.Redis.HMSet(this.ukeylist(uid, _id), data); err != nil { + log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err}) return } @@ -301,6 +308,7 @@ func (this *DBModel) ChangeList(uid string, _id string, data map[string]interfac //读取全部数据 func (this *DBModel) Get(uid string, data interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel Get", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "data", Value: data}) if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil && err != lgredis.RedisNil { return } @@ -320,6 +328,7 @@ func (this *DBModel) Get(uid string, data interface{}, opt ...DBOption) (err err //获取列表数据 注意 data 必须是 切片的指针 *[]type func (this *DBModel) GetList(uid string, data interface{}) (err error) { + //defer log.Debug("DBModel GetList", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "data", Value: data}) var ( dtype reflect2.Type dkind reflect.Kind @@ -435,6 +444,7 @@ func (this *DBModel) GetList(uid string, data interface{}) (err error) { //获取队列数据 func (this *DBModel) GetQueues(key string, count int, data interface{}) (err error) { + //defer log.Debug("DBModel GetQueues", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "key", Value: key}, log.Field{Key: "data", Value: data}) var ( dtype reflect2.Type dkind reflect.Kind @@ -505,6 +515,7 @@ func (this *DBModel) GetQueues(key string, count int, data interface{}) (err err //读取单个数据中 多个字段数据 func (this *DBModel) GetFields(uid string, data interface{}, fields ...string) (err error) { + //defer log.Debug("DBModel GetFields", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "data", Value: data}) if err = this.Redis.HMGet(this.ukey(uid), data, fields...); err != nil && err != lgredis.RedisNil { return } @@ -524,6 +535,7 @@ func (this *DBModel) GetFields(uid string, data interface{}, fields ...string) ( //读取List列表中单个数据中 多个字段数据 func (this *DBModel) GetListFields(uid string, id string, data interface{}, fields ...string) (err error) { + //defer log.Debug("DBModel GetListFields", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "id", Value: id}, log.Field{Key: "data", Value: data}) var ( c *mongo.Cursor keys map[string]string @@ -578,6 +590,7 @@ func (this *DBModel) GetListFields(uid string, id string, data interface{}, fiel //读取列表数据中单个数据 func (this *DBModel) GetListObj(uid string, id string, data interface{}) (err error) { + //defer log.Debug("DBModel GetListObj", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "id", Value: id}, log.Field{Key: "data", Value: data}) var ( c *mongo.Cursor keys map[string]string @@ -642,6 +655,7 @@ func (this *DBModel) GetListObj(uid string, id string, data interface{}) (err er //读取列表数据中单个数据 func (this *DBModel) GetListObjs(uid string, ids []string, data interface{}) (err error) { + //defer log.Debug("DBModel GetListObjs", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "ids", Value: ids}, log.Field{Key: "data", Value: data}) var ( dtype reflect2.Type dkind reflect.Kind @@ -754,6 +768,7 @@ func (this *DBModel) GetListObjs(uid string, ids []string, data interface{}) (er //删除用户数据 func (this *DBModel) Del(uid string, opt ...DBOption) (err error) { + //defer log.Debug("DBModel Del", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}) err = this.Redis.Delete(this.ukey(uid)) if err != nil { return err @@ -767,6 +782,7 @@ func (this *DBModel) Del(uid string, opt ...DBOption) (err error) { //删除多条数据 func (this *DBModel) DelListlds(uid string, ids ...string) (err error) { + //defer log.Debug("DBModel DelListlds", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "ids", Value: ids}) listkey := this.ukey(uid) pipe := this.Redis.RedisPipe(context.TODO()) for _, v := range ids { @@ -782,6 +798,7 @@ func (this *DBModel) DelListlds(uid string, ids ...string) (err error) { //批量删除数据 func (this *DBModel) BatchDelLists(uid string) (err error) { + //defer log.Debug("DBModel BatchDelLists", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}) var keys map[string]string pipe := this.Redis.RedisPipe(context.TODO()) if keys, err = this.Redis.HGetAllToMapString(this.ukey(uid)); err == nil {