using System.Collections.Generic;
using System.Linq;
namespace Myshipping.Core;
///
/// 通用输入帮助类
///
public class PageInputOrder
{
///
/// 排序方式(默认降序)
///
///
public static string OrderBuilder(string SortField, bool descSort = true)
{
// 约定默认每张表都有Id排序
var orderStr = descSort ? "Id Desc" : "Id Asc";
// 排序是否可用-排序字段和排序顺序都为非空才启用排序
if (!string.IsNullOrEmpty(SortField))
{
orderStr = $"{SortField} {(descSort ? "Desc" : "Asc")}";
}
return orderStr;
}
///
/// 多列排序
///
///
///
public static string MultiOrderBuilder(List 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;
}
}