|
|
|
@ -40,9 +40,8 @@ public static partial class Extensions
|
|
|
|
|
public static DataResult<List<TEntity>> ToQueryPage<TEntity>(this ISugarQueryable<TEntity> source,
|
|
|
|
|
PageCondition page)
|
|
|
|
|
{
|
|
|
|
|
page.NotNull(nameof(page));
|
|
|
|
|
|
|
|
|
|
var result = source.Where(page.PageIndex, page.PageSize, page.SortConditions);
|
|
|
|
|
page.NotNull(nameof(page));
|
|
|
|
|
var result = page.IsExport? source.WhereNoPage(page.SortConditions) : source.Where(page.PageIndex, page.PageSize, page.SortConditions);
|
|
|
|
|
var list = result.data;
|
|
|
|
|
var total = result.totalNumber;
|
|
|
|
|
return DataResult<List<TEntity>>.PageList(total, list, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
@ -59,7 +58,7 @@ public static partial class Extensions
|
|
|
|
|
PageCondition page)
|
|
|
|
|
{
|
|
|
|
|
page.NotNull(nameof(page));
|
|
|
|
|
var result = await source.WhereAsync(page.PageIndex, page.PageSize, page.SortConditions);
|
|
|
|
|
var result = page.IsExport ? await source.WhereNoPageAsync(page.SortConditions) : await source.WhereAsync(page.PageIndex, page.PageSize, page.SortConditions);
|
|
|
|
|
var list = result.Item1;
|
|
|
|
|
var total = result.Item2;
|
|
|
|
|
return DataResult<List<TEntity>>.PageList(total, list, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
@ -99,7 +98,27 @@ public static partial class Extensions
|
|
|
|
|
? source.ToPageList(pageIndex, pageSize, ref total)
|
|
|
|
|
: Enumerable.Empty<TEntity>().ToList(), total);
|
|
|
|
|
}
|
|
|
|
|
private static (List<TEntity> data, int totalNumber) WhereNoPage<TEntity>(this ISugarQueryable<TEntity> source,SortCondition[] orderConditions)
|
|
|
|
|
{
|
|
|
|
|
var total = source.Count();
|
|
|
|
|
|
|
|
|
|
ISugarQueryable<TEntity> orderSource;
|
|
|
|
|
if (orderConditions == null || orderConditions.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
orderSource = source.OrderBy("Id");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
orderSource = source.OrderBy(orderConditions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = orderSource;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
source.Count() != 0
|
|
|
|
|
? source.ToList()
|
|
|
|
|
: Enumerable.Empty<TEntity>().ToList(), total);
|
|
|
|
|
}
|
|
|
|
|
private static async Task<Tuple<List<TEntity>, int>> WhereAsync<TEntity>(this ISugarQueryable<TEntity> source,
|
|
|
|
|
int pageIndex, int pageSize, SortCondition[] orderConditions)
|
|
|
|
|
{
|
|
|
|
@ -120,7 +139,26 @@ public static partial class Extensions
|
|
|
|
|
|
|
|
|
|
return new Tuple<List<TEntity>, int>(list, total.Value);
|
|
|
|
|
}
|
|
|
|
|
private static async Task<Tuple<List<TEntity>, int>> WhereNoPageAsync<TEntity>(this ISugarQueryable<TEntity> source, SortCondition[] orderConditions)
|
|
|
|
|
{
|
|
|
|
|
ISugarQueryable<TEntity> orderSource;
|
|
|
|
|
if (orderConditions == null || orderConditions.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
orderSource = source.OrderBy("Id");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
orderSource = source.OrderBy(orderConditions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = orderSource;
|
|
|
|
|
|
|
|
|
|
var total = new RefAsync<int>();
|
|
|
|
|
var list = await source.ToListAsync();
|
|
|
|
|
total = list.Count;
|
|
|
|
|
|
|
|
|
|
return new Tuple<List<TEntity>, int>(list, total.Value);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 转换SqlSugar条件查询表达式
|
|
|
|
|
/// </summary>
|
|
|
|
|