/// <summary> /// where子句 /// </summary> /// <param name="filterOption"></param> /// <returns></returns> protected string BuildSqlFilter(IFilterOption filterOption, bool withOutStatusCode = false) { var builder = new StringBuilder(256); if (filterOption is INodeFilterOption nodeFilterOption && nodeFilterOption.Nodes?.Length > 0) { CheckSqlWhere(builder).Append($"Node in ({string.Join(",", nodeFilterOption.Nodes.Select(m => $"'{m}'"))}) "); } if (!withOutStatusCode && filterOption is IStatusCodeFilterOption statusCodeFilterOption && statusCodeFilterOption.StatusCodes?.Length > 0) { if (statusCodeFilterOption.StatusCodes.Length == 1) { CheckSqlWhere(builder).Append($"StatusCode = {statusCodeFilterOption.StatusCodes[0]} "); } else { CheckSqlWhere(builder).Append($"StatusCode in ({string.Join(",", statusCodeFilterOption.StatusCodes)}) "); } } if (filterOption is ITimeSpanFilterOption timeSpanFilterOption) { if (timeSpanFilterOption.StartTime.HasValue) { CheckSqlWhere(builder).Append($"CreateTime >= '{timeSpanFilterOption.StartTime.Value.ToString(timeSpanFilterOption.StartTimeFormat)}' "); } if (timeSpanFilterOption.EndTime.HasValue) { CheckSqlWhere(builder).Append($"CreateTime < '{timeSpanFilterOption.EndTime.Value.ToString(timeSpanFilterOption.EndTimeFormat)}' "); } } return(builder.ToString()); }
protected string BuildSqlControl(IFilterOption filterOption) { var builder = new StringBuilder(512); if (filterOption is IOrderFilterOption orderFilterOption) { if (orderFilterOption.IsOrderByField) { builder.Append($"ORDER BY {orderFilterOption.GetOrderField()} {(orderFilterOption.IsAscend ? "Asc" : "Desc")} "); } else { builder.Append($"{(orderFilterOption.IsAscend ? "Asc" : "Desc")} "); } } if (filterOption is ITakeFilterOption takeFilterOption && takeFilterOption.Take > 0) { if (takeFilterOption.Skip > 0) { builder.Append($"LIMIT {takeFilterOption.Take} OFFSET {takeFilterOption.Skip} "); } else { builder.Append($"LIMIT {takeFilterOption.Take} "); } } return(builder.ToString()); }
private static BinaryExpression GetExpression <T>(ParameterExpression param, IFilterOption filter1, IFilterOption filter2) { Expression bin1 = GetExpression <T>(param, filter1); Expression bin2 = GetExpression <T>(param, filter2); return(Expression.AndAlso(bin1, bin2)); }
public static void BuildFilterOption(IFilterOption property, PropertyBuilder p) { if (!string.IsNullOrEmpty(property.Criteria)) { p.ModelDefault("DataSourceCriteria", property.Criteria); } if (!string.IsNullOrEmpty(property.DataSourceProperty)) { p.ModelDefault("DataSourceProperty", property.DataSourceProperty); } if (!string.IsNullOrEmpty(property.DataSourceCriteriaProperty)) { p.ModelDefault("DataSourceCriteriaProperty", property.DataSourceCriteriaProperty); } }
/// <summary> /// where子句 /// </summary> /// <param name="filterOption"></param> /// <returns></returns> protected string BuildSqlFilter(IFilterOption filterOption, bool withOutStatusCode = false) { var builder = new StringBuilder(256); if (filterOption is INodeFilterOption nodeFilterOption) { if (!nodeFilterOption.Service.IsEmpty()) { CheckSqlWhere(builder).Append($"Node = '{nodeFilterOption.Service}' "); } if (!nodeFilterOption.LocalIP.IsEmpty()) { CheckSqlWhere(builder).Append($"`LocalIP` = '{nodeFilterOption.LocalIP}' "); } if (nodeFilterOption.LocalPort > 0) { CheckSqlWhere(builder).Append($"`LocalPort` = {nodeFilterOption.LocalPort} "); } } if (!withOutStatusCode && filterOption is IStatusCodeFilterOption statusCodeFilterOption && statusCodeFilterOption.StatusCodes?.Length > 0) { if (statusCodeFilterOption.StatusCodes.Length == 1) { CheckSqlWhere(builder).Append($"StatusCode = {statusCodeFilterOption.StatusCodes[0]} "); } else { CheckSqlWhere(builder).Append($"StatusCode in ({string.Join(",", statusCodeFilterOption.StatusCodes)}) "); } } if (filterOption is ITimeSpanFilterOption timeSpanFilterOption) { if (timeSpanFilterOption.StartTime.HasValue) { CheckSqlWhere(builder).Append($"CreateTime >= '{timeSpanFilterOption.StartTime.Value.ToString(timeSpanFilterOption.StartTimeFormat)}' "); } if (timeSpanFilterOption.EndTime.HasValue) { CheckSqlWhere(builder).Append($"CreateTime < '{timeSpanFilterOption.EndTime.Value.ToString(timeSpanFilterOption.EndTimeFormat)}' "); } } return(builder.ToString()); }
private static Expression GetExpression <T>(ParameterExpression param, IFilterOption filter) { MemberExpression member = Expression.Property(param, filter.PropertyName); ConstantExpression constant = Expression.Constant(filter.Value); switch (filter.Operator) { case FilterOperator.Equal: return(Expression.Equal(member, constant)); case FilterOperator.Contain: return(Expression.Call(member, containsMethod, constant)); } return(null); }
/// <summary> /// 控制子句 /// </summary> /// <param name="filterOption"></param> /// <returns></returns> protected string BuildSqlControl(IFilterOption filterOption) { var builder = new StringBuilder(512); if (filterOption is IOrderFilterOption orderFilterOption) { if (orderFilterOption.IsOrderByField) { builder.Append($"ORDER BY {orderFilterOption.GetOrderField()} {(orderFilterOption.IsAscend ? "Asc" : "Desc")} "); } else { builder.Append($"{(orderFilterOption.IsAscend ? "Asc" : "Desc")} "); } } return(builder.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="IssueFilter"/> class. /// Initializes a new instance of the <see cref="RuleFilter"/> class. /// </summary> /// <param name="filterOption"> /// The filter option. /// </param> public IssueFilter(IFilterOption filterOption) { this.filterOption = filterOption; }
public ProductNameContainsFilter(IFilterOption filterOption) { _filterOption = filterOption; }