package arena import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) ///竞技场 数据组件 type modelArena struct { modules.MCompModel module *Arena } //组件初始化接口 func (this *modelArena) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { this.TableName = comm.TableArena this.MCompModel.Init(service, module, comp, opt) this.module = module.(*Arena) //创建uid索引 this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } //获取目标去陪数据 func (this *modelArena) matche(integral int32) (results []*pb.DBArenaUser, err error) { var ( cursor *mongo.Cursor ) project := bson.M{"$project": bson.M{ "diff": bson.M{ "$abs": bson.M{"$subtract": bson.A{integral, "$start"}}, }, }} if cursor, err = this.DBModel.DB.Aggregate(comm.TableArena, bson.A{project}); err != nil { this.module.Errorln(err) return } else { for cursor.Next(context.Background()) { temp := &pb.DBArenaUser{} if err = cursor.Decode(temp); err != nil { this.module.Errorln(err) return } } } return }