update HouseCodeList
This commit is contained in:
@@ -15,7 +15,17 @@ namespace Ewide.Core.Extension
|
||||
{
|
||||
public static class PageExtensions
|
||||
{
|
||||
public static string OrderBuilder<T>(PageInputBase pageInput, bool descSort = true)
|
||||
private static string OrderBuilder(PageInputBase pageInput)
|
||||
{
|
||||
var orderStr = string.Empty;
|
||||
if (!string.IsNullOrEmpty(pageInput.SortField))
|
||||
{
|
||||
orderStr = $"{pageInput.SortField} {(pageInput.SortOrder == pageInput.DescStr ? "Desc" : "Asc")}";
|
||||
}
|
||||
return orderStr;
|
||||
}
|
||||
|
||||
private static string OrderBuilder<T>(PageInputBase pageInput, bool descSort = true)
|
||||
{
|
||||
var type = typeof(T);
|
||||
var hasId = type.GetProperty("Id") != null;
|
||||
@@ -24,12 +34,12 @@ namespace Ewide.Core.Extension
|
||||
var defaultField = hasSort ? "Sort" : (hasId ? "Id" : "");
|
||||
|
||||
// 约定默认每张表都有Id排序
|
||||
var orderStr = string.IsNullOrEmpty(defaultField) ? "" : defaultField + (descSort ? " Asc" : " Desc");
|
||||
var orderStr = string.IsNullOrEmpty(defaultField) ? "" : defaultField + (descSort ? " Desc" : " Asc");
|
||||
|
||||
// 排序是否可用-排序字段和排序顺序都为非空才启用排序
|
||||
if (!string.IsNullOrEmpty(pageInput.SortField) && !string.IsNullOrEmpty(pageInput.SortOrder))
|
||||
if (!string.IsNullOrEmpty(pageInput.SortField))
|
||||
{
|
||||
orderStr = $"{pageInput.SortField} {(pageInput.SortOrder == pageInput.DescStr ? "Asc" : "Desc")}";
|
||||
orderStr = OrderBuilder(pageInput);
|
||||
}
|
||||
return orderStr;
|
||||
}
|
||||
@@ -46,7 +56,7 @@ namespace Ewide.Core.Extension
|
||||
|
||||
public static Task<IEnumerable<dynamic>> QueryPageData(this IDapperRepository source, string sql, PageInputBase input, object param = null, System.Data.IDbTransaction transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null)
|
||||
{
|
||||
return source.QueryAsync(sql,
|
||||
return source.QueryAsync(PageSqlBuild(sql,input),
|
||||
param: param,
|
||||
transaction: transaction,
|
||||
commandTimeout: commandTimeout,
|
||||
@@ -63,5 +73,12 @@ namespace Ewide.Core.Extension
|
||||
commandType: commandType
|
||||
);
|
||||
}
|
||||
|
||||
private static string PageSqlBuild(string sql , PageInputBase input)
|
||||
{
|
||||
var orderStr = OrderBuilder(input);
|
||||
var r = "SELECT * FROM (" + sql + ") T " + (string.IsNullOrEmpty(orderStr) ? string.Empty : "Order by " + orderStr) + " LIMIT " + ((input.PageNo - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,6 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 降序排序(不要问我为什么是descend不是desc,前端约定参数就是这样)
|
||||
/// </summary>
|
||||
public virtual string DescStr { get; set; } = "descend";
|
||||
public virtual string DescStr => "descend";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user