public object Read(LogQueryCondition condition) { ISplitTableStrategy splitTableStrategy = new MongoSplitTableStrategy("LogRecord", condition.AppId, DateTime.Now.ToString("yyyyMM")); var mongodb = MongoDBHelper.GetMongoDB(); var collection = mongodb.GetCollection <LogEntity>(splitTableStrategy.GetTableName()); return(collection.Find <LogEntity>(FormFilterDefinitionBy(condition)).Skip(condition.skipNum).Limit(condition.TakeNum).ToList <LogEntity>()); }
/// <summary> /// 查询方案一 /// </summary> /// <param name="condition"></param> /// <returns></returns> private FilterDefinition <LogEntity> FormFilterDefinitionBy(LogQueryCondition condition) { FilterDefinition <LogEntity> wheres = null; if (!string.IsNullOrWhiteSpace(condition.AppId)) { wheres = Builders <LogEntity> .Filter.Eq("AppId", condition.AppId); } else { throw new Exception("appid is null!"); } if (!string.IsNullOrWhiteSpace(condition.LogTypeId)) { FilterDefinition <LogEntity> where = Builders <LogEntity> .Filter.Eq("LogTypeId", condition.LogTypeId); wheres = wheres == null ? where : wheres & where; } else { throw new Exception("LogTypeId is null!"); } if (!string.IsNullOrWhiteSpace(condition.OrderId)) { FilterDefinition <LogEntity> where = Builders <LogEntity> .Filter.Eq("OrderId", condition.OrderId); wheres = wheres == null ? where : wheres & where; } if (!string.IsNullOrWhiteSpace(condition.RelatedId)) { FilterDefinition <LogEntity> where = Builders <LogEntity> .Filter.Eq("RelatedId", condition.RelatedId); wheres = wheres == null ? where : wheres & where; } if (!string.IsNullOrWhiteSpace(condition.UserId)) { FilterDefinition <LogEntity> where = Builders <LogEntity> .Filter.Eq("UserId", condition.UserId); wheres = wheres == null ? where : wheres & where; } if (!string.IsNullOrWhiteSpace(condition.UserName)) { FilterDefinition <LogEntity> where = Builders <LogEntity> .Filter.Eq("UserName", condition.UserName); wheres = wheres == null ? where : wheres & where; } if (!string.IsNullOrWhiteSpace(condition.Label)) { FilterDefinition <LogEntity> where = (Builders <LogEntity> .Filter.Regex("Label", new BsonRegularExpression(new Regex(condition.Label, RegexOptions.IgnoreCase)))); wheres = wheres == null ? where : wheres & where; } return(wheres); }
public object Read(LogQueryCondition condition) { using (IDbConnection connection = new SqlConnection(connectionString)) { //appid,logtype查询 //标签查询 var idList = connection.Query("select LogIdCollection from LogIndex where LogLabel=@LogLabel"); var resList = connection.Query("select * from LogEntity where Id=@IdList"); //orderid,relateid,userid,username查询 } return(null); }
/// <summary> /// 查询方案二 /// </summary> /// <param name="condition"></param> /// <returns></returns> private Expression <Func <LogEntity, bool> > FormWhereExpressionBy(LogQueryCondition condition) { Expression <Func <LogEntity, bool> > exp = null; if (!string.IsNullOrWhiteSpace(condition.AppId)) { Expression <Func <LogEntity, bool> > exp1 = a => a.AppId == condition.AppId; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } else { throw new Exception("appid is null!"); } if (!string.IsNullOrWhiteSpace(condition.LogTypeId)) { Expression <Func <LogEntity, bool> > exp1 = a => a.LogTypeId == condition.LogTypeId; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } else { throw new Exception("LogTypeId is null!"); } if (!string.IsNullOrWhiteSpace(condition.OrderId)) { Expression <Func <LogEntity, bool> > exp1 = a => a.OrderId == condition.OrderId; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } if (!string.IsNullOrWhiteSpace(condition.RelatedId)) { Expression <Func <LogEntity, bool> > exp1 = a => a.RelatedId == condition.RelatedId; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } if (!string.IsNullOrWhiteSpace(condition.UserId)) { Expression <Func <LogEntity, bool> > exp1 = a => a.UserId == condition.UserId; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } if (!string.IsNullOrWhiteSpace(condition.UserName)) { Expression <Func <LogEntity, bool> > exp1 = a => a.UserName == condition.UserName; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } if (!string.IsNullOrWhiteSpace(condition.Label)) { Expression <Func <LogEntity, bool> > exp1 = a => a.Label == condition.Label; exp = exp == null ? exp1 : exp.And <LogEntity>(exp1); } return(exp); }
public static object QueryLogRecordData(LogQueryCondition condition) { return(new MongoLogRecordDriver().Read(condition)); }