go_dreamfactory/modules/buried/modelburied.go
2023-05-30 14:48:11 +08:00

79 lines
2.1 KiB
Go

package buried
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"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
}
//获取用户全部的埋点数据
func (this *modelBuried) getUserBurieds(uid string) (results map[int32]*pb.DBBuried, err error) {
temp := make([]*pb.DBBuried, 0)
if err = this.GetList(uid, &temp); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
results = make(map[int32]*pb.DBBuried)
for _, v := range temp {
results[v.Btype] = v
}
return
}
//更新用户数据
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.ChangeLists(uid, data)
return
}
func (this *modelBuried) userlock(uid string) (result *redis.RedisMutex, err error) {
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("ulockburied:%s", uid))
}
//更新埋点数据到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
// }