Exemplo n.º 1
0
        private static RankingList GetHistoryRanking(String listtablename, String objid, int year, int month, int weekofyear, int dayofyear)
        {
            QueryComplete qc = Query.EQ("Year", year);
            if (month != -1) qc = Query.And(Query.EQ("Year", year), Query.EQ("Month", month));
            if (weekofyear != -1) qc = Query.And(Query.EQ("Year", year), Query.EQ("WeekOfYear", weekofyear));
            if (dayofyear != -1) qc = Query.And(Query.EQ("Year", year), Query.EQ("DayOfYear", dayofyear));

            RankingList iv = new RankingList();
            try
            {
                MongoDatabase md = MongoDBHelper.MongoDB;
                MongoCollection<RankingList> mc = md.GetCollection<RankingList>(listtablename);
                iv = mc.FindOne(
                        Query.And(
                            Query.EQ("ObjID", objid),
                            qc
                        )
                    );
                if (iv == null) iv = new RankingList();
                iv.ObjID = objid;
                iv.PositionInRanking = 0;
                return iv;
            }
            catch (System.Exception err)
            {
                throw new CBB.ExceptionHelper.OperationException(
                    CBB.ExceptionHelper.ErrType.SystemErr,
                    CBB.ExceptionHelper.ErrNo.DBOperationError,
                    err);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取年度排名
        /// </summary>
        /// <param name="yearrankingtablename">排名表</param>
        /// <param name="year">年度</param>
        /// <param name="pageno">获取排名页码</param>
        /// <param name="pagesize">每页排名数量</param>
        /// <returns></returns>
        public static IList<RankingList> CreateYearRankingList(String yearrankingtablename, int year)
        {
            try
            {
                MongoCursor<EachYearRanking> mc = MongoDBHelper.GetCursor<EachYearRanking>(
                    yearrankingtablename,
                    Query.EQ("Year",year),
                    new SortByDocument("Scores", -1),
                    0,
                    0);

                List<EachYearRanking> objs = new List<EachYearRanking>();
                objs.AddRange(mc);

                //排名表
                List<RankingList> raklist = new List<RankingList>();
                for (int i=0;i<objs.Count;i++)
                {
                    RankingList rk = new RankingList();
                    rk.ObjID = objs[i].ObjID;
                    rk.Scores = objs[i].Scores;
                    rk.Year = objs[i].Year;
                    rk.Month = -1;
                    rk.DayOfYear = -1;
                    rk.WeekOfYear = -1;
                    rk.PositionInRanking = i + 1;
                    raklist.Add(rk);
                }

                return raklist;
            }
            catch (System.Exception err)
            {
                throw new CBB.ExceptionHelper.OperationException(
                    CBB.ExceptionHelper.ErrType.SystemErr,
                    CBB.ExceptionHelper.ErrNo.DBOperationError,
                    err);
            }
        }