埋点中心跨服触发处理
This commit is contained in:
parent
c99a0dfd4a
commit
5915c6363d
@ -6,7 +6,6 @@ import (
|
||||
"go_dreamfactory/lego/sys/mgo"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
@ -28,30 +27,10 @@ func (this *modelBuried) Init(service core.IService, module core.IModule, comp c
|
||||
return
|
||||
}
|
||||
|
||||
//更新埋点数据到db中
|
||||
func (this *modelBuried) getburiedModel(uid string) (model *buriedModel, err error) {
|
||||
var m *db.DBModel
|
||||
if db.IsCross() {
|
||||
if m, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
return
|
||||
}
|
||||
model = &buriedModel{module: this.module, model: m}
|
||||
} else {
|
||||
model = &buriedModel{module: this.module, model: this.DBModel}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//埋点专属模型 会封装特殊的数据转换接口
|
||||
type buriedModel struct {
|
||||
module *Buried
|
||||
model *db.DBModel
|
||||
}
|
||||
|
||||
//获取用户全部的埋点数据
|
||||
func (this *buriedModel) getUserBurieds(uid string) (results map[int32]*pb.DBBuried, err error) {
|
||||
func (this *modelBuried) getUserBurieds(uid string) (results map[int32]*pb.DBBuried, err error) {
|
||||
temp := make([]*pb.DBBuried, 0)
|
||||
if err = this.model.GetList(uid, &temp); err != nil && err != mgo.MongodbNil {
|
||||
if err = this.GetList(uid, &temp); err != nil && err != mgo.MongodbNil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -63,11 +42,31 @@ func (this *buriedModel) getUserBurieds(uid string) (results map[int32]*pb.DBBur
|
||||
}
|
||||
|
||||
//更新用户数据
|
||||
func (this *buriedModel) updateUserBurieds(uid string, bdatas []*pb.DBBuried) (err error) {
|
||||
func (this *modelBuried) updateUserBurieds(uid string, bdatas []*pb.DBBuried) (err error) {
|
||||
data := make(map[string]interface{})
|
||||
for _, v := range bdatas {
|
||||
data[v.Id] = v
|
||||
}
|
||||
err = this.model.ChangeLists(uid, data)
|
||||
err = this.ChangeLists(uid, data)
|
||||
return
|
||||
}
|
||||
|
||||
//更新埋点数据到db中
|
||||
// func (this *modelBuried) getburiedModel(uid string) (model *buriedModel, err error) {
|
||||
// var m *db.DBModel
|
||||
// if db.IsCross() {
|
||||
// if m, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
// return
|
||||
// }
|
||||
// model = &buriedModel{module: this.module, model: m}
|
||||
// } else {
|
||||
// model = &buriedModel{module: this.module, model: this.DBModel}
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// //埋点专属模型 会封装特殊的数据转换接口
|
||||
// type buriedModel struct {
|
||||
// module *Buried
|
||||
// model *db.DBModel
|
||||
// }
|
||||
|
@ -48,6 +48,7 @@ func (this *Buried) Init(service core.IService, module core.IModule, options cor
|
||||
|
||||
func (this *Buried) Start() (err error) {
|
||||
err = this.ModuleBase.Start()
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_ModuleBuriedTrigger), this.Rpc_ModuleBuriedTrigger)
|
||||
return
|
||||
}
|
||||
|
||||
@ -59,19 +60,21 @@ func (this *Buried) OnInstallComp() {
|
||||
this.modelBuried = this.RegisterComp(new(modelBuried)).(*modelBuried)
|
||||
}
|
||||
|
||||
// 跨服埋点触发
|
||||
func (this *Buried) Rpc_ModuleBuriedTrigger(ctx context.Context, args *pb.Rpc_ModuleBuriedTriggerReq, reply *pb.Rpc_ModuleBuriedTriggerResp) {
|
||||
this.Debug("跨服埋点触发!", log.Field{Key: "uid", Value: args.Uid}, log.Field{Key: "burieds", Value: args.Burieds})
|
||||
this.trigger(args.Uid, args.Burieds...)
|
||||
}
|
||||
|
||||
//激活数据采集点
|
||||
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 {
|
||||
|
||||
if bdatas, err = this.modelBuried.getUserBurieds(uid); err != nil {
|
||||
return
|
||||
}
|
||||
chanage = make([]*pb.DBBuried, 0)
|
||||
@ -101,7 +104,7 @@ func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) {
|
||||
}
|
||||
}
|
||||
if len(chanage) > 0 {
|
||||
err = model.updateUserBurieds(uid, chanage)
|
||||
err = this.modelBuried.updateUserBurieds(uid, chanage)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -109,15 +112,10 @@ func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) {
|
||||
//激活数据采集点
|
||||
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 {
|
||||
if bdatas, err = this.modelBuried.getUserBurieds(uid); err != nil {
|
||||
return
|
||||
}
|
||||
condIds = make([]int32, 0)
|
||||
@ -139,16 +137,12 @@ func (this *Buried) CheckCondition(uid string, condiIds ...int32) (condIds []int
|
||||
//校验同时激活
|
||||
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 {
|
||||
|
||||
if bdatas, err = this.modelBuried.getUserBurieds(uid); err != nil {
|
||||
return
|
||||
}
|
||||
condIds = make([]int32, 0)
|
||||
@ -184,16 +178,24 @@ func (this *Buried) CheckAndActiveCondition(uid string, condiIds ...int32) (cond
|
||||
}
|
||||
}
|
||||
if len(chanage) > 0 {
|
||||
err = model.updateUserBurieds(uid, chanage)
|
||||
err = this.modelBuried.updateUserBurieds(uid, chanage)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//触发埋点
|
||||
func (this *Buried) TriggerBuried(uid string, burieds ...*pb.BuriedParam) {
|
||||
|
||||
if db.IsCross() {
|
||||
stag, _ := comm.UidToSTag(uid)
|
||||
if _, err := this.service.AcrossClusterRpcGo(
|
||||
var (
|
||||
stag string
|
||||
err error
|
||||
)
|
||||
if stag, err = comm.UidToSTag(uid); err != nil {
|
||||
this.Error("远程触发埋点错误!", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
if _, err = this.service.AcrossClusterRpcGo(
|
||||
context.Background(),
|
||||
stag,
|
||||
comm.Service_Worker,
|
||||
@ -203,6 +205,7 @@ func (this *Buried) TriggerBuried(uid string, burieds ...*pb.BuriedParam) {
|
||||
},
|
||||
nil); err != nil {
|
||||
this.Error("远程触发埋点错误!", log.Field{Key: "burieds", Value: burieds}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
this.trigger(uid, burieds...)
|
||||
@ -213,7 +216,6 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
var (
|
||||
pass map[*pb.BuriedParam][]*cfg.GameBuriedCondiData = make(map[*pb.BuriedParam][]*cfg.GameBuriedCondiData)
|
||||
bconf *cfg.GameBuriedTypeData
|
||||
model *buriedModel
|
||||
bdatas map[int32]*pb.DBBuried
|
||||
change []*pb.DBBuried
|
||||
bdata *pb.DBBuried
|
||||
@ -224,10 +226,6 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
)
|
||||
this.Debug("触发埋点!", log.Field{Key: "burieds", Value: burieds})
|
||||
|
||||
if model, err = this.modelBuried.getburiedModel(uid); err != nil {
|
||||
this.Error("获取用户埋点数据模型对象失败!", log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
for _, buried := range burieds {
|
||||
conds := this.configure.getCondiDatas(buried.TaskType)
|
||||
if bconf, err = this.configure.getburiedtypedata(buried.TaskType); err != nil {
|
||||
@ -244,7 +242,7 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
}
|
||||
}
|
||||
if len(pass) > 0 {
|
||||
if bdatas, err = model.getUserBurieds(uid); err != nil {
|
||||
if bdatas, err = this.modelBuried.getUserBurieds(uid); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -280,7 +278,7 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
}
|
||||
|
||||
if len(change) > 0 { //同步数据
|
||||
if err = model.updateUserBurieds(uid, change); err != nil {
|
||||
if err = this.modelBuried.updateUserBurieds(uid, change); err != nil {
|
||||
this.Error("更新用户埋点数据错误!", log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
|
@ -103,6 +103,11 @@ func (this *MCompModel) ChangeList(uid string, _id string, data map[string]inter
|
||||
return this.DBModel.ChangeList(uid, _id, data, opt...)
|
||||
}
|
||||
|
||||
//修改列表中多个数据 datas key是 _id value是 这个数据对象
|
||||
func (this *MCompModel) ChangeLists(uid string, datas map[string]interface{}, opt ...db.DBOption) (err error) {
|
||||
return this.DBModel.ChangeLists(uid, datas, opt...)
|
||||
}
|
||||
|
||||
//读取全部数据
|
||||
func (this *MCompModel) Get(id string, data interface{}, opt ...db.DBOption) (err error) {
|
||||
return this.DBModel.Get(id, data, opt...)
|
||||
|
@ -25,7 +25,8 @@ type Rpc_ModuleBuriedTriggerReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Burieds []*BuriedParam `protobuf:"bytes,1,rep,name=burieds,proto3" json:"burieds"`
|
||||
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"`
|
||||
Burieds []*BuriedParam `protobuf:"bytes,2,rep,name=burieds,proto3" json:"burieds"`
|
||||
}
|
||||
|
||||
func (x *Rpc_ModuleBuriedTriggerReq) Reset() {
|
||||
@ -60,6 +61,13 @@ func (*Rpc_ModuleBuriedTriggerReq) Descriptor() ([]byte, []int) {
|
||||
return file_buried_buried_msg_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Rpc_ModuleBuriedTriggerReq) GetUid() string {
|
||||
if x != nil {
|
||||
return x.Uid
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Rpc_ModuleBuriedTriggerReq) GetBurieds() []*BuriedParam {
|
||||
if x != nil {
|
||||
return x.Burieds
|
||||
@ -111,14 +119,15 @@ var file_buried_buried_msg_proto_rawDesc = []byte{
|
||||
0x0a, 0x17, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x2f, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x5f,
|
||||
0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x16, 0x62, 0x75, 0x72, 0x69, 0x65,
|
||||
0x64, 0x2f, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x22, 0x44, 0x0a, 0x1a, 0x52, 0x70, 0x63, 0x5f, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x42,
|
||||
0x6f, 0x22, 0x56, 0x0a, 0x1a, 0x52, 0x70, 0x63, 0x5f, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x42,
|
||||
0x75, 0x72, 0x69, 0x65, 0x64, 0x54, 0x72, 0x69, 0x67, 0x67, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12,
|
||||
0x26, 0x0a, 0x07, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
|
||||
0x32, 0x0c, 0x2e, 0x42, 0x75, 0x72, 0x69, 0x65, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x52, 0x07,
|
||||
0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x73, 0x22, 0x1d, 0x0a, 0x1b, 0x52, 0x70, 0x63, 0x5f, 0x4d,
|
||||
0x6f, 0x64, 0x75, 0x6c, 0x65, 0x42, 0x75, 0x72, 0x69, 0x65, 0x64, 0x54, 0x72, 0x69, 0x67, 0x67,
|
||||
0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69,
|
||||
0x64, 0x12, 0x26, 0x0a, 0x07, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03,
|
||||
0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x42, 0x75, 0x72, 0x69, 0x65, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d,
|
||||
0x52, 0x07, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x73, 0x22, 0x1d, 0x0a, 0x1b, 0x52, 0x70, 0x63,
|
||||
0x5f, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x42, 0x75, 0x72, 0x69, 0x65, 0x64, 0x54, 0x72, 0x69,
|
||||
0x67, 0x67, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user