From d3515e2bc0689000553e1f604167b7f9cc8b0d39 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Thu, 25 Jul 2024 17:31:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=85=E4=BF=AE=E6=9F=A5=E8=AF=A2=E8=A1=A8?= =?UTF-8?q?=20=20=E5=91=98=E5=B7=A5/=E9=83=A8=E9=97=A8/=E5=B2=97=E4=BD=8D/?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=20=E6=96=B0=E5=A2=9E=E5=8F=AF=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E6=9F=A5=E8=AF=A2=EF=BC=8C=E6=9F=A5=E8=AF=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tiobon.Core.Services/BASE/BaseServices.cs | 59 +++++++++++++++++++ .../Ghre/Ghre_QuestionServices.cs | 55 +---------------- .../Ghre/Ghre_RequiredCourseServices.cs | 33 +---------- 3 files changed, 62 insertions(+), 85 deletions(-) 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