public static async Task <List <T> > QueryJsonDBInfos <T>(this DBProxyComponent self, string time, long uid)
        {
            DBComponent          dbComponent      = Game.Scene.GetComponent <DBComponent>();
            FilterDefinition <T> filterDefinition = new JsonFilterDefinition <T>($"{{CreateTime:/^{time}/,Uid:{uid}}}");
            IAsyncCursor <T>     cursor           = await dbComponent.GetDBDataCollection <T>(typeof(T).Name).FindAsync(filterDefinition);

            List <T> components = await cursor.ToListAsync();

            return(components);
        }
        public static async Task <List <T> > QueryJsonDB <T>(this DBProxyComponent self, string json) where T : ComponentWithId
        {
            DBComponent          dbComponent      = Game.Scene.GetComponent <DBComponent>();
            FilterDefinition <T> filterDefinition = new JsonFilterDefinition <T>(json);
            IAsyncCursor <T>     cursor           = await dbComponent.GetDBDataCollection <T>(typeof(T).Name).FindAsync(filterDefinition);

            List <T> components = await cursor.ToListAsync();

            return(components);
        }
Пример #3
0
        public static async Task <string> getRecord(long uid)
        {
            string jsonData = "";

            List <FriendRoomRecordInfo> listData = new List <FriendRoomRecordInfo>();

            DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
            DBComponent      dbComponent    = Game.Scene.GetComponent <DBComponent>();

            string time    = CommonUtil.timeAddDays(CommonUtil.getCurTimeNormalFormat(), -90);
            var    filter1 = (Builders <Log_Game> .Filter.Gt("CreateTime", time) & Builders <Log_Game> .Filter.Eq("RoomName", "好友房")) & (Builders <Log_Game> .Filter.Eq("Player1_uid", uid) | Builders <Log_Game> .Filter.Eq("Player2_uid", uid)
                                                                                                                                         | Builders <Log_Game> .Filter.Eq("Player3_uid", uid) | Builders <Log_Game> .Filter.Eq("Player4_uid", uid));
            List <Log_Game> list = await dbComponent.GetDBDataCollection <Log_Game>(typeof(Log_Game).Name).Find(filter1).ToListAsync();

            Log.Debug(JsonHelper.ToJson(list) + "=====");
            int roomNum = -1;
            FriendRoomRecordInfo FriendRoomRecordInfo = null;

            for (int i = list.Count - 1; i >= 0; i--)
            {
                // 如果房间号跟之前的不一样,说明这是另一局的
                if (list[i].RoomNum != roomNum)
                {
                    // 最多显示50条
                    if (listData.Count >= 50)
                    {
                        break;
                    }

                    roomNum = list[i].RoomNum;
                    FriendRoomRecordInfo = new FriendRoomRecordInfo();
                    listData.Add(FriendRoomRecordInfo);

                    FriendRoomRecordInfo.result   = 1;
                    FriendRoomRecordInfo.allScore = 100;
                    FriendRoomRecordInfo.roomNum  = list[i].RoomNum;
                    FriendRoomRecordInfo.time     = list[i].CreateTime;
                }

                // 每一小局对局信息
                {
                    FriendRoomRecordInfo.gameList.Add(new FriendRoomRecordInfo.ResultDetails(new List <string>()
                    {
                        list[i].Player1_info, list[i].Player2_info, list[i].Player3_info, list[i].Player4_info,
                    }, list[i].CreateTime));
                }
            }

            jsonData = JsonConvert.SerializeObject(listData);
            Log.Debug("------------------" + jsonData);
            return(jsonData);
        }
        //刷新周排行榜 1,周财富榜,2,周战绩榜
        public static async Task <List <Log_Rank> > QueryJsonRank(this DBProxyComponent self, int type)
        {
            DBComponent dbComponent = Game.Scene.GetComponent <DBComponent>();
            FilterDefinition <Log_Rank> filterDefinition = new JsonFilterDefinition <Log_Rank>($"{{}}");

            FilterDefinition <Log_Rank> filterEmpty    = Builders <Log_Rank> .Filter.Empty;
            SortDefinition <Log_Rank>   sortDefinition = Builders <Log_Rank> .Sort.Descending("");

            IAsyncCursor <Log_Rank> asyncCursor = await dbComponent.GetDBDataCollection <Log_Rank>(typeof(Log_Rank).Name).FindAsync(filterDefinition);



            List <Log_Rank> components = new List <Log_Rank>();

            if (type == 1)
            {
                components = await dbComponent.GetDBDataCollection <Log_Rank>(typeof(Log_Rank).Name).Find(filterDefinition).SortByDescending(a => a.Wealth).Limit(50).ToListAsync();
            }
            else if (type == 2)
            {
                components = await dbComponent.GetDBDataCollection <Log_Rank>(typeof(Log_Rank).Name).Find(filterDefinition).SortByDescending(a => a.WinGameCount).Limit(50).ToListAsync();
            }
            return(components);
        }