|
|
|
@ -3,8 +3,10 @@ using System.Data; |
|
|
|
|
using System.Dynamic; |
|
|
|
|
using System.Linq.Expressions; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using MathNet.Numerics.Distributions; |
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
using MySqlX.XDevAPI.Common; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using NPOI.Util; |
|
|
|
|
using SqlSugar; |
|
|
|
@ -695,13 +697,85 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ |
|
|
|
|
return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public virtual async Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody body) |
|
|
|
|
public virtual async Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody filter) |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrWhiteSpace(body.orderBy)) |
|
|
|
|
body.orderBy = "CreateTime DESC"; |
|
|
|
|
var data = await BaseDal.QueryFilterPage(body); |
|
|
|
|
return await QueryFilterPage(filter, null); |
|
|
|
|
} |
|
|
|
|
public virtual async Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody filter, string condition) |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrWhiteSpace(filter.orderBy)) |
|
|
|
|
filter.orderBy = "CreateTime DESC"; |
|
|
|
|
|
|
|
|
|
if (filter.pageSize == 0) |
|
|
|
|
filter.pageSize = 10000; |
|
|
|
|
|
|
|
|
|
Type entityType = typeof(TEntity); |
|
|
|
|
|
|
|
|
|
var countSql = @$" SELECT COUNT(1) FROM {entityType.GetEntityTableName()}"; |
|
|
|
|
var sql1 = @$"DECLARE @langId INT = {filter.langId};"; |
|
|
|
|
var sql = @$" SELECT *,
|
|
|
|
|
ISNULL ((SELECT CASE WHEN @langId = 1 THEN UserName ELSE UserEname END |
|
|
|
|
FROM Ghrs_User B |
|
|
|
|
WHERE B.UserId = A.CreateBy), |
|
|
|
|
'') CreateDataInfo, |
|
|
|
|
ISNULL ((SELECT CASE WHEN @langId = 1 THEN UserName ELSE UserEname END |
|
|
|
|
FROM Ghrs_User B |
|
|
|
|
WHERE B.UserId = A.UpdateBy), |
|
|
|
|
'') UpdateDataInfo |
|
|
|
|
FROM {entityType.GetEntityTableName()} A";
|
|
|
|
|
|
|
|
|
|
string conditions = " WHERE IsEnable = 1"; |
|
|
|
|
if (!string.IsNullOrWhiteSpace(condition)) |
|
|
|
|
conditions += "AND " + condition; |
|
|
|
|
if (filter.jsonParam != null) |
|
|
|
|
foreach (JProperty jProperty in filter.jsonParam.Properties()) |
|
|
|
|
{ |
|
|
|
|
var name = jProperty.Name; |
|
|
|
|
var value = jProperty.Value.ToString(); |
|
|
|
|
if (name == "page" || name == "pageSize") |
|
|
|
|
continue; |
|
|
|
|
if (!string.IsNullOrWhiteSpace(value)) |
|
|
|
|
{ |
|
|
|
|
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value); |
|
|
|
|
|
|
|
|
|
switch (jsonParam.operationKey) |
|
|
|
|
{ |
|
|
|
|
case "Include": |
|
|
|
|
conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; |
|
|
|
|
break; |
|
|
|
|
case "NotInclude": |
|
|
|
|
conditions += $" AND {name} NOT LIKE '%{jsonParam.columnValue}%'"; |
|
|
|
|
break; |
|
|
|
|
case "IsNull": |
|
|
|
|
conditions += $" AND {name} IS NULL"; |
|
|
|
|
break; |
|
|
|
|
case "NotNull": |
|
|
|
|
conditions += $" AND {name} IS NOT NULL"; |
|
|
|
|
break; |
|
|
|
|
case "Equal": |
|
|
|
|
conditions += $" AND {name} ='{jsonParam.columnValue}'"; |
|
|
|
|
break; |
|
|
|
|
case "NotEqual": |
|
|
|
|
conditions += $" AND {name} !='{jsonParam.columnValue}'"; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sql += conditions; |
|
|
|
|
countSql += conditions; |
|
|
|
|
int total = await Db.Ado.GetIntAsync(countSql); |
|
|
|
|
|
|
|
|
|
sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; |
|
|
|
|
sql += ") A ) B ) C"; |
|
|
|
|
|
|
|
|
|
sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; |
|
|
|
|
sql = sql1 + sql; |
|
|
|
|
var entitys = await Db.Ado.SqlQueryAsync<TEntityDto>(sql); |
|
|
|
|
|
|
|
|
|
return new ServicePageResult<TEntityDto>(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, Mapper.Map(data.result.DT_TableDataT1).ToANew<List<TEntityDto>>()); |
|
|
|
|
return new ServicePageResult<TEntityDto>(filter.pageNum, total, filter.pageSize, entitys); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public async Task<ServiceResult<long>> Export(QueryBody body) |
|
|
|
|