修改分页参数
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-08-20 13:59:52 +08:00
parent a579c26ada
commit 9e1cc1521f
4 changed files with 37 additions and 37 deletions
@@ -14,15 +14,15 @@ namespace IRaCIS.Core.Infrastructure.Extention
{
//单字段排序 异步 (或者默认排序字段是空,多字段排序,传递了,就以传递的单字段为准)
public static async Task<PageOutput<T>> ToPagedListAsync<T>(this IQueryable<T> source, PageInput pageInput, bool isMultiSortFiled = false, string[] sortArray = default, CancellationToken cancellationToken = default)
public static async Task<PageOutput<T>> ToPagedListAsync<T>(this IQueryable<T> source, PageInput pageInput, string[] sortArray = default, CancellationToken cancellationToken = default)
{
var isMultiSortFiled = true;
if (isMultiSortFiled && sortArray == default)
if (string.IsNullOrWhiteSpace(pageInput.SortField) && sortArray != default)
{
throw new InvalidOperationException("The sort field must be specified");
isMultiSortFiled = true;
}
if (pageInput.PageIndex <= 0)
{
pageInput.PageIndex = 1;
@@ -39,41 +39,41 @@ namespace IRaCIS.Core.Infrastructure.Extention
return new PageOutput<T>() { CurrentPageData = new T[0] };
}
var propName=string.Empty;
if (string.IsNullOrWhiteSpace(pageInput.SortField))
{
//没有指定,优先以Id排序,否则从属性里面随便取出来一个排序
var propertyNameList = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(t => t.CanWrite).Select(t => t.Name).OrderBy(t => t).ToList();
if (propertyNameList.Count == 0)
{
throw new InvalidOperationException("no default sort field.");
}
else
{
propName= propertyNameList.Contains("Id") ? "Id" : propertyNameList.FirstOrDefault();
}
}
else
{
//有值,以前段传输的为主
propName = pageInput.SortField;
}
if (!isMultiSortFiled)
{
source = pageInput.Asc ? source.OrderBy(propName) : source.OrderBy(propName + " desc");
}
else
if (isMultiSortFiled)
{
var sortString = string.Join(',', sortArray);
source = source.OrderBy(sortString);
}
else
{
var propName = string.Empty;
if (string.IsNullOrWhiteSpace(pageInput.SortField))
{
//没有指定,优先以Id排序,否则从属性里面随便取出来一个排序
var propertyNameList = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(t => t.CanWrite).Select(t => t.Name).OrderBy(t => t).ToList();
if (propertyNameList.Count == 0)
{
throw new InvalidOperationException("no default sort field.");
}
else
{
propName = propertyNameList.Contains("Id") ? "Id" : propertyNameList.FirstOrDefault();
}
}
else
{
//有值,以前段传输的为主
propName = pageInput.SortField;
}
source = pageInput.Asc ? source.OrderBy(propName) : source.OrderBy(propName + " desc");
}
source = source.Skip((pageInput.PageIndex - 1) * pageInput.PageSize);
var items = await source