From 1318e14db0a10c13a0f46e349fab9838ed8e584b Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 29 May 2023 17:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=BB=E5=8A=A1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 6 +- modules/buried/configure.go | 19 ++++++ modules/buried/module.go | 125 ++++++++++++++++++++++++++++++++++-- 3 files changed, 144 insertions(+), 6 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index b1630095e..d3bd790eb 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -508,8 +508,10 @@ type ( //埋点中心触发 TriggerBuried(uid string, burieds ...*BuriedParam) //校验条件是否达成 - CheckCondition(uid string, condiIds ...int32) (condIds []int32) + CheckCondition(uid string, condiIds ...int32) (condIds []int32, err error) //激活条件 - ActiveCondition(uid string, condiIds ...int32) + ActiveCondition(uid string, condiIds ...int32) (err error) + //校验的同时激活条件 + CheckAndActiveCondition(uid string, condiIds ...int32) (condIds []int32, err error) } ) diff --git a/modules/buried/configure.go b/modules/buried/configure.go index 8a1cf613b..87d1cb5a4 100644 --- a/modules/buried/configure.go +++ b/modules/buried/configure.go @@ -51,6 +51,25 @@ func (this *configureComp) getburiedtypedata(tt comm.TaskType) (result *cfg.Game return } +//读取条件任务id配置 +func (this *configureComp) getburiedcondidata(cid int32) (result *cfg.GameBuriedCondiData, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_buriedcondi); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + if result, ok = v.(*cfg.GameBuriedCondi).GetDataMap()[cid]; !ok { + err = comm.NewNotFoundConfErr(moduleName, game_buriedtype, cid) + this.module.Errorf("err:%v", err) + return + } + } + return +} + //动态更新配置 func (this *configureComp) updateconfigure() { if v, err := this.GetConfigure(game_buriedcondi); err != nil { diff --git a/modules/buried/module.go b/modules/buried/module.go index ccc0e16cf..fbe08221f 100644 --- a/modules/buried/module.go +++ b/modules/buried/module.go @@ -58,15 +58,132 @@ func (this *Buried) OnInstallComp() { } //激活数据采集点 -func (this *Buried) ActiveCondition(uid string, condiIds ...int32) { - +func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) { + var ( + model *buriedModel + conf *cfg.GameBuriedCondiData + bdatas map[int32]*pb.DBBuried + chanage []*pb.DBBuried //变化埋点 + ) + if model, err = this.modelBuried.getburiedModel(uid); err != nil { + this.Error("获取用户埋点数据模型对象失败!", log.Field{Key: "err", Value: err.Error()}) + return + } + if bdatas, err = model.getUserBurieds(uid); err != nil { + return + } + chanage = make([]*pb.DBBuried, 0) + for _, v := range condiIds { + if conf, err = this.configure.getburiedcondidata(v); err != nil { + return + } + if bdata, ok := bdatas[conf.Type]; ok { + if conf.Rtype == rtype2 { + if item, ok := bdata.Items[v]; !ok { + bdata.Items[v] = &pb.DBBuriedItem{ + Conid: v, + State: pb.BuriedItemState_Activated, + Value: 0, + Statistics: make([]string, 0), + Timestamp: time.Now().Unix(), + } + chanage = append(chanage, bdata) + } else { + item.Value = 0 + item.Statistics = make([]string, 0) + item.Timestamp = time.Now().Unix() + item.State = pb.BuriedItemState_Activated + chanage = append(chanage, bdata) + } + } + } + } + if len(chanage) > 0 { + err = model.updateUserBurieds(uid, chanage) + } return } //激活数据采集点 -func (this *Buried) CheckCondition(uid string, condiIds ...int32) (condIds []int32) { +func (this *Buried) CheckCondition(uid string, condiIds ...int32) (condIds []int32, err error) { + var ( + model *buriedModel + bdatas map[int32]*pb.DBBuried + conf *cfg.GameBuriedCondiData + ) + if model, err = this.modelBuried.getburiedModel(uid); err != nil { + this.Error("获取用户埋点数据模型对象失败!", log.Field{Key: "err", Value: err.Error()}) + return + } + if bdatas, err = model.getUserBurieds(uid); err != nil { + return + } + condIds = make([]int32, 0) + for _, v := range condiIds { + if conf, err = this.configure.getburiedcondidata(v); err != nil { + return + } + if bdata, ok := bdatas[conf.Type]; ok { + if data, ok := bdata.Items[v]; ok { + if data.Value >= conf.Value { + condIds = append(condIds, v) + } + } + } + } + return +} - +//校验同时激活 +func (this *Buried) CheckAndActiveCondition(uid string, condiIds ...int32) (condIds []int32, err error) { + var ( + model *buriedModel + bdatas map[int32]*pb.DBBuried + conf *cfg.GameBuriedCondiData + chanage []*pb.DBBuried //变化埋点 + ) + if model, err = this.modelBuried.getburiedModel(uid); err != nil { + this.Error("获取用户埋点数据模型对象失败!", log.Field{Key: "err", Value: err.Error()}) + return + } + if bdatas, err = model.getUserBurieds(uid); err != nil { + return + } + condIds = make([]int32, 0) + chanage = make([]*pb.DBBuried, 0) + for _, v := range condiIds { + if conf, err = this.configure.getburiedcondidata(v); err != nil { + return + } + if bdata, ok := bdatas[conf.Type]; ok { + if data, ok := bdata.Items[v]; ok { + if data.Value >= conf.Value { + condIds = append(condIds, v) + } + } + if conf.Rtype == rtype2 { + if item, ok := bdata.Items[v]; !ok { + bdata.Items[v] = &pb.DBBuriedItem{ + Conid: v, + State: pb.BuriedItemState_Activated, + Value: 0, + Statistics: make([]string, 0), + Timestamp: time.Now().Unix(), + } + chanage = append(chanage, bdata) + } else { + item.Value = 0 + item.Statistics = make([]string, 0) + item.Timestamp = time.Now().Unix() + item.State = pb.BuriedItemState_Activated + chanage = append(chanage, bdata) + } + } + } + } + if len(chanage) > 0 { + err = model.updateUserBurieds(uid, chanage) + } return }