go_dreamfactory/modules/practice/modelPandata.go
2023-02-22 19:02:42 +08:00

56 lines
1.4 KiB
Go

package practice
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 modelPandata struct {
modules.MCompModel
module *Practice
}
func (this *modelPandata) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.TableName = comm.TablePandata
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Practice)
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
///询用户的练功房信息
func (this *modelPandata) queryUserMartialhall(uid string) (result *pb.DBPandataKekan, err error) {
result = &pb.DBPandataKekan{}
if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
}
if err == mgo.MongodbNil {
result = &pb.DBPandataKekan{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Pillar1: &pb.DBPandataPillar{Index: 1},
Pillar2: &pb.DBPandataPillar{Index: 2},
Pillar3: &pb.DBPandataPillar{Index: 3},
Pillarf: &pb.DBPandataPillar{Index: 4},
}
if err = this.Add(uid, result); err != nil {
this.module.Errorln(err)
return
}
}
err = nil
return
}