namespace Cis.Core;
///
/// 分页泛型集合
///
///
public class SqlSugarPagedList
where TEntity : new()
{
///
/// 页码
///
public int Page { get; set; }
///
/// 页容量
///
public int PageSize { get; set; }
///
/// 总条数
///
public int Total { get; set; }
///
/// 总页数
///
public int TotalPages { get; set; }
///
/// 当前页集合
///
public IEnumerable Items { get; set; }
///
/// 是否有上一页
///
public bool HasPrevPage { get; set; }
///
/// 是否有下一页
///
public bool HasNextPage { get; set; }
}
///
/// 分页拓展类
///
public static class SqlSugarPagedExtensions
{
///
/// 分页拓展
///
///
///
///
///
public static SqlSugarPagedList ToPagedList(this ISugarQueryable entity, int pageIndex, int pageSize)
where TEntity : new()
{
var total = 0;
var items = entity.ToPageList(pageIndex, pageSize, ref total);
var totalPages = (int)Math.Ceiling(total / (double)pageSize);
return new SqlSugarPagedList
{
Page = pageIndex,
PageSize = pageSize,
Items = items,
Total = total,
TotalPages = totalPages,
HasNextPage = pageIndex < totalPages,
HasPrevPage = pageIndex - 1 > 0
};
}
///
/// 分页拓展
///
///
///
///
///
public static async Task> ToPagedListAsync(this ISugarQueryable entity, int pageIndex, int pageSize)
where TEntity : new()
{
RefAsync total = 0;
var items = await entity.ToPageListAsync(pageIndex, pageSize, total);
var totalPages = (int)Math.Ceiling(total / (double)pageSize);
return new SqlSugarPagedList
{
Page = pageIndex,
PageSize = pageSize,
Items = items,
Total = total,
TotalPages = totalPages,
HasNextPage = pageIndex < totalPages,
HasPrevPage = pageIndex - 1 > 0
};
}
}