feature:自定义排序
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="1.19.2" />
|
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="1.19.2" />
|
||||||
<PackageReference Include="Furion.Extras.Logging.Serilog" Version="1.19.2" />
|
<PackageReference Include="Furion.Extras.Logging.Serilog" Version="1.19.2" />
|
||||||
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="1.19.2" />
|
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="1.19.2" />
|
||||||
|
<PackageReference Include="Kendo.DynamicLinqCore" Version="3.1.1" />
|
||||||
<PackageReference Include="Quartz" Version="3.3.2" />
|
<PackageReference Include="Quartz" Version="3.3.2" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
|
||||||
|
|||||||
33
Api/Ewide.Core/Extension/PageInputOrder.cs
Normal file
33
Api/Ewide.Core/Extension/PageInputOrder.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.Core.Extension
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 通用输入帮助类
|
||||||
|
/// </summary>
|
||||||
|
public class PageInputOrder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 排序方式(默认降序)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageInput"></param>
|
||||||
|
/// <param name="descSort">是否降序</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string OrderBuilder(PageInputBase pageInput, bool descSort = true)
|
||||||
|
{
|
||||||
|
// 约定默认每张表都有Id排序
|
||||||
|
var orderStr = descSort ? "Id Desc" : "Id Asc";
|
||||||
|
|
||||||
|
// 排序是否可用-排序字段和排序顺序都为非空才启用排序
|
||||||
|
if (!string.IsNullOrEmpty(pageInput.SortField) && !string.IsNullOrEmpty(pageInput.SortOrder))
|
||||||
|
{
|
||||||
|
orderStr = $"{pageInput.SortField} {(pageInput.SortOrder == pageInput.DescStr ? "Desc" : "Asc")}";
|
||||||
|
}
|
||||||
|
return orderStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,5 +56,20 @@ namespace Ewide.Core
|
|||||||
/// 搜索结束时间
|
/// 搜索结束时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual string SearchEndTime { get; set; }
|
public virtual string SearchEndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序字段
|
||||||
|
/// </summary>
|
||||||
|
public virtual string SortField { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序方法,默认升序,否则降序(配合antd前端,约定参数为 Ascend,Dscend)
|
||||||
|
/// </summary>
|
||||||
|
public virtual string SortOrder { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 降序排序(不要问我为什么是descend不是desc,前端约定参数就是这样)
|
||||||
|
/// </summary>
|
||||||
|
public virtual string DescStr { get; set; } = "descend";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Furion.DatabaseAccessor;
|
using Ewide.Core.Extension;
|
||||||
|
using Furion.DatabaseAccessor;
|
||||||
using Furion.DatabaseAccessor.Extensions;
|
using Furion.DatabaseAccessor.Extensions;
|
||||||
using Furion.DependencyInjection;
|
using Furion.DependencyInjection;
|
||||||
using Furion.DynamicApiController;
|
using Furion.DynamicApiController;
|
||||||
@@ -7,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Dynamic.Core;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Ewide.Core.Service
|
namespace Ewide.Core.Service
|
||||||
@@ -41,7 +43,7 @@ namespace Ewide.Core.Service
|
|||||||
.Where(success, u => u.Success == input.Success.Value)
|
.Where(success, u => u.Success == input.Success.Value)
|
||||||
.Where(searchBeginTime, u => u.OpTime >= DateTime.Parse(input.SearchBeginTime.Trim()) &&
|
.Where(searchBeginTime, u => u.OpTime >= DateTime.Parse(input.SearchBeginTime.Trim()) &&
|
||||||
u.OpTime <= DateTime.Parse(input.SearchEndTime.Trim()))
|
u.OpTime <= DateTime.Parse(input.SearchEndTime.Trim()))
|
||||||
.OrderByDescending(u => u.Id)
|
.OrderBy(PageInputOrder.OrderBuilder(input)) // 封装了任意字段排序示例
|
||||||
.Select(u => u.Adapt<OpLogOutput>())
|
.Select(u => u.Adapt<OpLogOutput>())
|
||||||
.ToPagedListAsync(input.PageNo, input.PageSize);
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
||||||
return XnPageResult<OpLogOutput>.PageResult(opLogs);
|
return XnPageResult<OpLogOutput>.PageResult(opLogs);
|
||||||
|
|||||||
Reference in New Issue
Block a user