51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package passon
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelPasson struct {
|
|
modules.MCompModel
|
|
module *Passon
|
|
}
|
|
|
|
func (this *modelPasson) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TablePasson
|
|
this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Passon)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(comm.TablePasson), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取用户全部的埋点数据
|
|
func (this *modelPasson) getUserPasson(uid string) (results *pb.DBPasson, err error) {
|
|
results = &pb.DBPasson{}
|
|
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
err = nil
|
|
results = &pb.DBPasson{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Teacher: make([]string, 5),
|
|
Student: make([]string, 12),
|
|
}
|
|
err = this.Add(uid, results)
|
|
}
|
|
return
|
|
}
|