95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package parkour
|
|
|
|
import (
|
|
"fmt"
|
|
"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 ModelTeamComp struct {
|
|
modules.MCompModel
|
|
module *Parkour
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *ModelTeamComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableParkourTeam
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Parkour)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *ModelTeamComp) queryteam(uid string) (result *pb.DBRaceTeam, err error) {
|
|
result = &pb.DBRaceTeam{}
|
|
if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
var tuser *pb.DBUser
|
|
if tuser = this.module.ModuleUser.GetUser(uid); tuser == nil {
|
|
err = fmt.Errorf("no found udata:%s", uid)
|
|
return
|
|
}
|
|
result = &pb.DBRaceTeam{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Captainid: uid,
|
|
State: pb.RaceTeamState_teaming,
|
|
Invite: make([]*pb.DBRaceInvite, 0),
|
|
Member: []*pb.DBRaceMember{{Uid: tuser.Uid, Name: tuser.Name}},
|
|
}
|
|
if err = this.Add(uid, result); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
err = nil
|
|
return
|
|
}
|
|
|
|
func (this *ModelTeamComp) queryteams(uids []string) (results []*pb.DBRaceTeam, err error) {
|
|
results = make([]*pb.DBRaceTeam, 0)
|
|
var (
|
|
onfound []string
|
|
newdata map[string]interface{} = make(map[string]interface{})
|
|
)
|
|
if onfound, err = this.Gets(uids, &results); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if len(onfound) > 0 {
|
|
for _, v := range onfound {
|
|
var tuser *pb.DBUser
|
|
if tuser = this.module.ModuleUser.GetUser(v); tuser == nil {
|
|
err = fmt.Errorf("no found udata:%s", v)
|
|
return
|
|
}
|
|
temp := &pb.DBRaceTeam{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Captainid: v,
|
|
State: pb.RaceTeamState_teaming,
|
|
Invite: make([]*pb.DBRaceInvite, 0),
|
|
Member: []*pb.DBRaceMember{{Uid: tuser.Uid, Name: tuser.Name}},
|
|
}
|
|
newdata[v] = temp
|
|
}
|
|
if err = this.Adds(newdata); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|