diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 72822fce..92f16b3d 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -1350,6 +1350,65 @@ public class BaseServices : IBaseServ } #endregion + #region 处理json查询条件 + public string DealConditions(string conditions, string name, string value) + { + var jsonParam = JsonHelper.JsonToObj(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; + case "GreaterOrEqual"://大于等于 + conditions += $" AND {name} >='{jsonParam.columnValue}'"; + break; + case "Greater"://大于 + conditions += $" AND {name} >'{jsonParam.columnValue}'"; + break; + case "LessOrEqual"://小于等于 + conditions += $" AND {name} <='{jsonParam.columnValue}'"; + break; + case "Less"://小于 + conditions += $" AND {name} <'{jsonParam.columnValue}'"; + break; + case "EqualAny":// + if (jsonParam.columnValue != null) + { + var ids1 = JsonHelper.JsonToObj>(jsonParam.columnValue.ToString()); + + conditions += $" AND {name} IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))})"; + } + break; + case "NotEqualAny":// + if (jsonParam.columnValue != null) + { + var ids1 = JsonHelper.JsonToObj>(jsonParam.columnValue.ToString()); + + conditions += $" AND ({name} NOT IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))}) OR {name} IS NULL)"; + } + break; + default: + break; + } + return conditions; + } + #endregion + public string GetQueryString(string sqlSelect, int? currentPage = null, int? pageSize = null, string sortField = null, string sortDirection = null) { string queryString = string.Empty; diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 45e274ba..bf769eec 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -204,61 +204,8 @@ public class Ghre_QuestionServices : BaseServices(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; - case "GreaterOrEqual"://大于等于 - conditions += $" AND {name} >='{jsonParam.columnValue}'"; - break; - case "Greater"://大于 - conditions += $" AND {name} >'{jsonParam.columnValue}'"; - break; - case "LessOrEqual"://小于等于 - conditions += $" AND {name} <='{jsonParam.columnValue}'"; - break; - case "Less"://小于 - conditions += $" AND {name} <'{jsonParam.columnValue}'"; - break; - case "EqualAny":// - if (jsonParam.columnValue != null) - { - var ids1 = JsonHelper.JsonToObj>(jsonParam.columnValue.ToString()); + conditions = DealConditions(conditions, name, value); - conditions += $" AND {name} IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))})"; - } - break; - case "NotEqualAny":// - if (jsonParam.columnValue != null) - { - var ids1 = JsonHelper.JsonToObj>(jsonParam.columnValue.ToString()); - - conditions += $" AND ({name} NOT IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))}) OR {name} IS NULL)"; - } - break; - default: - break; - } - } } if (filter.pageSize == 0) filter.pageSize = 10000; diff --git a/Tiobon.Core.Services/Ghre/Ghre_RequiredCourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_RequiredCourseServices.cs index f4f08136..7c755ea6 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_RequiredCourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_RequiredCourseServices.cs @@ -5,10 +5,10 @@ using Tiobon.Core.Services.BASE; using Tiobon.Core.IRepository.Base; using Tiobon.Core.Common.Caches; using Newtonsoft.Json.Linq; -using Tiobon.Core.Common.DB.Dapper.Extensions; using Tiobon.Core.Common; using Tiobon.Core.Model; using Newtonsoft.Json; +using Tiobon.Core.Common.Helper; namespace Tiobon.Core.Services; @@ -54,33 +54,7 @@ public class Ghre_RequiredCourseServices : BaseServices(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; - } - } + conditions = DealConditions(conditions, name, value); } sql += conditions; @@ -101,9 +75,6 @@ public class Ghre_RequiredCourseServices : BaseServices