diff --git a/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs index 667630c2..7b548cdc 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs @@ -1,5 +1,6 @@ using MySqlX.XDevAPI.Common; using Org.BouncyCastle.Utilities; +using System.Data; namespace Tiobon.Core.Services; @@ -17,7 +18,111 @@ public class Ghre_StaffGroupServices : BaseServices> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) { - var result = await base.QueryFilterPage(filter, condition, IsEnable); + + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "CreateTime1 DESC"; + + if (filter.pageSize == 0) + filter.pageSize = 10000; + + Type entityType = typeof(Ghre_StaffGroup); + + var countSql = @$" SELECT COUNT(1) FROM {entityType.GetEntityTableName()} A"; + 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, ISNULL(A.UpdateTime, A.CreateTime) CreateTime1 + FROM {entityType.GetEntityTableName()} A"; + + string conditions = " WHERE 1=1 "; + + if (IsEnable == true) + conditions += " AND IsEnable = 1"; + else if (IsEnable == false) + conditions += " AND IsEnable = 0"; + + if (!string.IsNullOrWhiteSpace(condition)) + conditions += " AND " + condition; + + var properties = entityType.GetGenericProperties(); + + 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" || !properties.Any(x => x.Name == name)) + continue; + if (name == "StaffType1" || name == "StaffType2") + { + var jsonParam = JsonHelper.JsonToObj(value); + + switch (jsonParam.operationKey) + { + case "EqualAny":// + if (jsonParam.columnValue != null) + { + //var ids1 = JsonHelper.JsonToObj>(jsonParam.columnValue.ToString()); + + conditions += $" AND Exists(select 1 from openjson(A.{name}) depts where Exists(select 1 from openjson('{jsonParam.columnValue.ToString()}') where value =depts.[value] ) )"; + } + break; + case "NotEqualAny":// + if (jsonParam.columnValue != null) + { + conditions += $" AND NOT Exists(select 1 from openjson(A.{name}) depts where Exists(select 1 from openjson('{jsonParam.columnValue.ToString()}') where value =depts.[value] ) )"; + + } + break; + default: + break; + } + continue; + } + + if (name == "ZoneId" || name == "DeptId" || name == "JobId" || name == "GradeId" || name == "TitleId" || name == "StaffId") + { + var jsonParam = JsonHelper.JsonToObj(value); + + switch (jsonParam.operationKey) + { + case "EqualAny":// + if (jsonParam.columnValue != null) + conditions += $" AND (Exists(select 1 from openjson(A.{name}) depts where Exists(select 1 from openjson('{jsonParam.columnValue.ToString()}') where value =depts.[value] ) ) OR " + + $"Exists(select 1 from openjson(A.Excl{name}) depts where Exists(select 1 from openjson('{jsonParam.columnValue.ToString()}') where value =depts.[value] ) ))"; + break; + case "NotEqualAny":// + if (jsonParam.columnValue != null) + conditions += $" AND NOT (Exists(select 1 from openjson(A.{name}) depts where Exists(select 1 from openjson('{jsonParam.columnValue.ToString()}') where value =depts.[value] ) ) AND " + + $"Exists(select 1 from openjson(A.Excl{name}) depts where Exists(select 1 from openjson('{jsonParam.columnValue.ToString()}') where value =depts.[value] ) ))"; + break; + default: + break; + } + continue; + } + if (!string.IsNullOrWhiteSpace(value)) + conditions = DealConditions(conditions, name, value); + } + + 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(sql); + + var result = new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); var zoneIds = new List(); var exclZoneIds = new List(); @@ -62,6 +167,22 @@ public class Ghre_StaffGroupServices : BaseServices(); @@ -79,7 +200,6 @@ public class Ghre_StaffGroupServices : BaseServices().Where(x => zoneIds.Contains(x.ZoneID.Value)).ToListAsync(); @@ -193,7 +313,6 @@ public class Ghre_StaffGroupServices : BaseServices Add(InsertGhre_StaffGroupInput entity) { entity.StaffType1 = JsonHelper.ObjToJson(entity.StaffType1s);