go_dreamfactory/modules/buried/modelburied.go
2023-05-25 13:42:09 +08:00

68 lines
1.7 KiB
Go

package buried
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"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"
)
type modelBuried struct {
modules.MCompModel
module *Buried
}
func (this *modelBuried) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableBuried)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Buried)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
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) {
temp := make([]*pb.DBBuried, 0)
if err = this.model.GetList(uid, &temp); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
for _, v := range temp {
results[v.Btype] = v
}
return
}
func (this *buriedModel) updateUserBurieds(bdatas map[int32]*pb.DBBuried) (err error) {
return
}