go_dreamfactory/modules/guidance/modelGuidance.go
2023-07-05 14:14:44 +08:00

51 lines
1.4 KiB
Go

package guidance
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type ModelGuidance struct {
modules.MCompModel
module *Guidance
}
func (this *ModelGuidance) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompModel.Init(service, module, comp, options)
this.TableName = comm.TableGuidance
this.module = module.(*Guidance)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 获取用户全部的埋点数据
func (this *ModelGuidance) getUserGourmet(uid string) (results *pb.DBGuidance, err error) {
results = &pb.DBGuidance{}
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
if err == mgo.MongodbNil {
err = nil
results = &pb.DBGuidance{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Complete: make([]int32, 0),
}
if err = this.Add(uid, results); err != nil {
this.module.Error("add User DBGuidance fail!", log.Field{Key: "err", Value: err.Error()})
}
}
return
}