添加查询条件是否导出字段

usertest
ZR20090193-陈敬勇 5 months ago
parent 502363e759
commit 3909977943

@ -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>

@ -9,7 +9,7 @@ public class PageCondition
/// 初始化一个 默认参数第1页每页20排序条件为空的分页查询条件信息类 的新实例
/// </summary>
public PageCondition()
: this(1, 20)
: this(1, 20,false)
{
}
@ -18,13 +18,18 @@ public class PageCondition
/// </summary>
/// <param name="pageIndex"> 页索引 </param>
/// <param name="pageSize"> 页大小 </param>
public PageCondition(int pageIndex, int pageSize)
/// <param name="isExport"></param>
public PageCondition(int pageIndex, int pageSize,bool isExport = false)
{
IsExport = isExport;
PageIndex = pageIndex;
PageSize = pageSize;
SortConditions = new SortCondition[] { };
}
/// <summary>
/// 是否导出
/// </summary>
public bool IsExport { get; set; } = false;
/// <summary>
/// 获取或设置 页索引
/// </summary>

Loading…
Cancel
Save