package turntable import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "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 ModelTurntable struct { modules.MCompModel module *Turntable } func (this *ModelTurntable) 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.TableTurntable this.module = module.(*Turntable) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } func (this *ModelTurntable) getUserTurntable(uid string) (results *pb.DBTurntable, err error) { results = &pb.DBTurntable{} if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } if err == mgo.MongodbNil { results = &pb.DBTurntable{ Id: primitive.NewObjectID().Hex(), Uid: uid, Data: make(map[int32]int32), } err = this.Add(uid, results) } return }