public static IList<SystemInterView> GetSystemInterView(InterViewType type, int count,String[] exceptobjs) { try { List<SystemInterView> objs = new List<SystemInterView>(); //随机取count个记录 double random = new Random(DateTime.Now.Second).NextDouble(); objs = getinterview(InterViewType.m_normal, count, exceptobjs, random, Query.GTE("Random", random)); if (objs.Count < count) { objs = getinterview(InterViewType.m_normal, count, exceptobjs, random, Query.LTE("Random", random)); } return objs; } catch (System.Exception err) { throw new CBB.ExceptionHelper.OperationException( CBB.ExceptionHelper.ErrType.SystemErr, CBB.ExceptionHelper.ErrNo.DBOperationError, err); } }
private static List<SystemInterView> getinterview(InterViewType type, int count, String[] exceptobjs, double random, QueryConditionList qc) { BsonArray bv = new BsonArray(); foreach(string s in exceptobjs) { bv.Add(ObjectId.Parse(s)); } MongoCursor<SystemInterView> mc = MongoDBHelper.GetCursor<SystemInterView>( "SystemInterview", Query.And(Query.EQ("type", type), qc, Query.NotIn("_id", bv)), new SortByDocument("Random", 1), 1, count); List<SystemInterView> objs = new List<SystemInterView>(); objs.AddRange(mc); return objs; }