|
|
|
@ -1,6 +1,8 @@ |
|
|
|
|
using System.Data; |
|
|
|
|
using System.Linq.Expressions; |
|
|
|
|
using System.Reflection; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.DB; |
|
|
|
@ -465,19 +467,42 @@ namespace Tiobon.Core.Repository.Base |
|
|
|
|
/// <param name="pageSize">页大小</param> |
|
|
|
|
/// <param name="orderByFields">排序字段,如name asc,age desc</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<ServicePageResult<TEntity>> QueryFilterPage([FromFilter] QueryFilter filter) |
|
|
|
|
public async Task<ServicePageResult<TEntity>> QueryFilterPage(QueryBody filter) |
|
|
|
|
{ |
|
|
|
|
RefAsync<int> totalCount = 0; |
|
|
|
|
var query = _db.Queryable<TEntity>(); |
|
|
|
|
if (!filter.Conditions.IsNullOrEmpty()) |
|
|
|
|
query = query.Where(filter.Conditions); |
|
|
|
|
|
|
|
|
|
string conditions = "1=1"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (JProperty jProperty in filter.jsonParam.Properties()) |
|
|
|
|
{ |
|
|
|
|
var name = jProperty.Name; |
|
|
|
|
var value = jProperty.Value.ToString(); |
|
|
|
|
if (!string.IsNullOrWhiteSpace(value)) |
|
|
|
|
{ |
|
|
|
|
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value); |
|
|
|
|
|
|
|
|
|
switch (jsonParam.operationKey) |
|
|
|
|
{ |
|
|
|
|
case "Include": |
|
|
|
|
conditions += $" AND {name} ='{jsonParam.columnValue}'"; |
|
|
|
|
break; |
|
|
|
|
case "NotInclude": |
|
|
|
|
conditions += $" AND {name} !='{jsonParam.columnValue}'"; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
query = query.Where(conditions); |
|
|
|
|
var list = await query |
|
|
|
|
.OrderByIF(!string.IsNullOrEmpty(filter.Sorting), filter.Sorting) |
|
|
|
|
.ToPageListAsync(filter.PageIndex, filter.PageSize, totalCount); |
|
|
|
|
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); |
|
|
|
|
|
|
|
|
|
return new ServicePageResult<TEntity>(filter.PageIndex, totalCount, filter.PageSize, list); |
|
|
|
|
return new ServicePageResult<TEntity>(filter.pageNum, totalCount, filter.pageSize, list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|