| | |
| | | } |
| | | |
| | | |
| | | //protected string ValidatePageOptions(PageDataOptions options) |
| | | //{ |
| | | // options = options ?? new PageDataOptions(); |
| | | // string where = ""; |
| | | // List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | // if (options.Filter != null && options.Filter.Count > 0) |
| | | // { |
| | | // searchParametersList.AddRange(options.Filter); |
| | | // } |
| | | // else if (!string.IsNullOrEmpty(options.Wheres)) |
| | | // { |
| | | // try |
| | | // { |
| | | // searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | // options.Filter = searchParametersList; |
| | | // } |
| | | // catch { } |
| | | // } |
| | | // QueryRelativeList?.Invoke(searchParametersList); |
| | | |
| | | // for (int i = 0; i < searchParametersList.Count; i++) |
| | | // { |
| | | // if (string.IsNullOrEmpty(searchParametersList[i].Value)) |
| | | // { |
| | | // continue; |
| | | // } |
| | | |
| | | // PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault(); |
| | | |
| | | // if (property == null) continue; |
| | | |
| | | // List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList(); |
| | | // if (results == null || results.Count() == 0) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // for (int j = 0; j < results.Count(); j++) |
| | | // { |
| | | // if (j == 0) |
| | | // { |
| | | // where += "("; |
| | | // } |
| | | // LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | // if (expressionType == LinqExpressionType.Equal) |
| | | // { |
| | | // where += $"{searchParametersList[i].Name} like '%{results[j].Item3}%'"; |
| | | // } |
| | | // else |
| | | // { |
| | | // where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'"; |
| | | // } |
| | | |
| | | // if (j == results.Count() - 1) |
| | | // { |
| | | // where += ")"; |
| | | // } |
| | | // else |
| | | // { |
| | | // where += " or "; |
| | | // } |
| | | // } |
| | | // if (i < searchParametersList.Count - 1) |
| | | // where += " and "; |
| | | // } |
| | | // return where; |
| | | //} |
| | | protected string ValidatePageOptions(PageDataOptions options) |
| | | { |
| | | options = options ?? new PageDataOptions(); |
| | |
| | | |
| | | if (property == null) continue; |
| | | |
| | | List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList(); |
| | | if (results == null || results.Count() == 0) |
| | | (bool, string, object) result = property.ValidationVal(searchParametersList[i].Value); |
| | | if (!result.Item1) |
| | | { |
| | | continue; |
| | | } |
| | | for (int j = 0; j < results.Count(); j++) |
| | | { |
| | | if (j == 0) |
| | | { |
| | | where += "("; |
| | | } |
| | | LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | if (expressionType == LinqExpressionType.Equal) |
| | | { |
| | | where += $"{searchParametersList[i].Name} like '%{results[j].Item3}%'"; |
| | | } |
| | | else |
| | | { |
| | | where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'"; |
| | | } |
| | | |
| | | if (j == results.Count() - 1) |
| | | LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | if (expressionType == LinqExpressionType.Equal) |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | { |
| | | where += ")"; |
| | | // 针对字符串类型的字段使用模糊查询 |
| | | //where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false") |
| | | { |
| | | where += $" {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'"; |
| | | } |
| | | else |
| | | { |
| | | where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | where += " or "; |
| | | // 针对布尔类型字段进行精确查询 |
| | | if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false") |
| | | { |
| | | where += $" and {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'"; |
| | | } |
| | | else |
| | | { |
| | | where += $" and {searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | } |
| | | } |
| | | } |
| | | if (i < searchParametersList.Count - 1) |
| | | where += " and "; |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'"; |
| | | else |
| | | where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'"; |
| | | } |
| | | } |
| | | return where; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取排序字段 |
| | | /// </summary> |