You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Core/Extension/PageInputOrder.cs

52 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace Myshipping.Core;
2 years ago
/// <summary>
/// 通用输入帮助类
/// </summary>
public class PageInputOrder
{
/// <summary>
/// 排序方式(默认降序)
/// </summary>
/// <returns></returns>
public static string OrderBuilder(string SortField, bool descSort = true)
2 years ago
{
// 约定默认每张表都有Id排序
var orderStr = descSort ? "Id Desc" : "Id Asc";
// 排序是否可用-排序字段和排序顺序都为非空才启用排序
2 years ago
if (!string.IsNullOrEmpty(SortField))
2 years ago
{
2 years ago
orderStr = $"{SortField} {(descSort ? "Desc" : "Asc")}";
2 years ago
}
return orderStr;
}
/// <summary>
/// 多列排序
/// </summary>
/// <param name="sortList"></param>
/// <returns></returns>
public static string MultiOrderBuilder(List<QuerySortModel> sortList)
{
string orderStr = null;
// 约定默认每张表都有Id排序
if (sortList == null || sortList.Count == 0)
{
orderStr = "Id Desc";
}
else
{
var lst = sortList.Select(x => $"{x.SortField} {(x.DescSort ? "Desc" : "Asc")}").ToList();
orderStr = string.Join(",", lst);
}
return orderStr;
}
2 years ago
}