From 2be033c9afacb5ae126e644c8613ba1e10bcbfe8 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sun, 26 Dec 2021 00:49:38 +0800 Subject: [PATCH] update where(tree) --- .../SqlSugar/Infrastructure/ContextMethods.cs | 54 ++++++++++++++++++- .../SqlSugar/Interface/IContextMethods.cs | 1 + 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 9d7eb770c..33daaa62f 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json.Linq; +using System; using System.Collections; using System.Collections.Generic; using System.Data; @@ -653,7 +654,7 @@ namespace SqlSugar } #endregion - #region + #region Page Each public void PageEach(IEnumerable pageItems,int pageSize, Action> action) { if (pageItems != null&& pageItems.Any()) @@ -694,6 +695,55 @@ namespace SqlSugar } } } + #endregion + + public List JsonToConditionalModels(string json) + { + List conditionalModels = new List(); + var jarray = this.Context.Utilities.DeserializeObject(json); + foreach (var item in jarray) + { + + if (item.Count() > 0) + { + IConditionalModel model = new ConditionalTree() + { + ConditionalList = GetConditionalList(item) + }; + conditionalModels.Add(model); + } + } + return conditionalModels; + } + private static List> GetConditionalList(JToken item) + { + List> result = new List>(); + var values = item.Values().First(); + foreach (var jToken in values) + { + WhereType type = (WhereType)Convert.ToInt32(jToken["Key"]); + IConditionalModel conditionalModel = null; + var value = jToken["Value"]; + if (value.ToString().Contains("ConditionalList")) + { + conditionalModel = new ConditionalTree() + { + ConditionalList = GetConditionalList(value) + }; + } + else + { + conditionalModel = new ConditionalModel() + { + ConditionalType = (ConditionalType)Convert.ToInt32(value["ConditionalType"]), + FieldName = value["FieldName"] + "", + FieldValue = value["FieldValue"] + "" + }; + } + result.Add(new KeyValuePair(type, conditionalModel)); + } + return result; + } } } diff --git a/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs b/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs index 854d2fcf6..78b844c15 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs @@ -37,5 +37,6 @@ namespace SqlSugar void PageEach(IEnumerable pageItems, int pageSize, Action> action); Task PageEachAsync(IEnumerable pageItems, int pageSize, Func, Task> action); Task PageEachAsync(IEnumerable pageItems, int pageSize, Func, Task> action); + List JsonToConditionalModels(string json); } }