瀏覽代碼

cosmosDb SQL拼接

李思淳 5 年之前
父節點
當前提交
eef1fb122f

+ 775 - 0
TEAMModelOS.SDK/Module/AzureCosmosDB/Configuration/SQLHelper.cs

@@ -0,0 +1,775 @@
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using TEAMModelOS.SDK.Context.Exception;
+
+namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration
+{
+    public class SQLHelper
+    {
+
+        static readonly string[] LogicOpers = new string[] { " and ", " or " };
+        static readonly string[] CompareOpers = new string[] { " > ", " < ", " <= ", " >= ", " = ", " != ", " like ", " not like ", " in " };
+
+        public static void GetSQL(Dictionary<string, object> dict, ref StringBuilder sql)
+        {
+
+            if (dict != null)
+            {
+                int offsetNum = 0;
+                int limitNum = 0;
+                bool pageBool = false;
+                GetPageNum(dict, ref offsetNum, ref limitNum, ref pageBool);
+
+                //处理顺序
+                Stack<KeyValuePair<string, object>> stack = new Stack<KeyValuePair<string, object>>();
+
+                foreach (string item in dict.Keys)
+                {
+                    if (item.EndsWith(".|"))
+                    {
+                        stack.Push(new KeyValuePair<string, object>(item, dict[item]));
+                    }
+
+                }
+                foreach (string item in dict.Keys)
+                {
+                    if (!item.EndsWith(".|"))
+                    {
+                        stack.Push(new KeyValuePair<string, object>(item, dict[item]));
+                    }
+
+                }
+
+
+                string Join = " join ";
+                string instring = " in ";
+                Dictionary<string, string> keyValues = new Dictionary<string, string>();
+                StringBuilder WhereString = new StringBuilder();
+                int heada = 0;
+                string[] sqlHead = new string[] { "A", "B", "C", "D", "E", "F" };
+                int kslength = 0;
+                int logicOperNum = 0;
+
+                bool keyListValueList = true;
+                string distinctHead = "select distinct value(c) from c ";
+
+
+                int stackCount = stack.Count;
+                //foreach (KeyValuePair<string, object> item in newDict)
+                for (int k = 0; k < stackCount; k++)
+                {
+                    KeyValuePair<string, object> item = stack.Pop();
+                    bool isLikeSQL = false;
+                    if (item.Key.StartsWith("$.") || item.Key.StartsWith("!$."))
+                    {
+                        isLikeSQL = true;
+                    }
+
+
+                    string key = item.Key;
+                    string[] keyHead = key.Split(".");
+                    int index = 0;
+                    int compareOper = 4;
+                    int logicOper = 0;
+
+                    if (key.EndsWith(".&"))
+                    {
+                        logicOper = (int)LogicOper.and;
+                        key = key.Replace(".&", "");
+                    }
+                    else if (key.EndsWith(".|"))
+                    {
+                        logicOper = (int)LogicOper.or;
+                        key = key.Replace(".|", "");
+                    }
+                    CompareOperSwitch(keyHead[0], ref key, ref compareOper);
+                    string[] keyBody = key.Split("[*]");
+                    if (keyBody.Length > 1)
+                    {
+                        kslength += keyBody.Length;
+                        if (kslength < (7 + heada))
+                        {
+                            StringBuilder sqlitem = new StringBuilder();
+                            for (int i = 0; i < keyBody.Length - 1; i++)
+                            {
+                                //Console.WriteLine(ks[i]);
+                                if (i == 0)
+                                {
+                                    sqlitem.Append(Join);
+                                    string a = sqlHead[heada] + index;
+                                    sqlitem.Append(a + " ");
+                                    //keyValues.Add(ks[i], a);
+                                    keyValues[keyBody[i]] = a;
+                                    sqlitem.Append(instring);
+                                    sqlitem.Append("c.");
+                                    sqlitem.Append(keyBody[i]);
+                                }
+                                else
+                                {
+                                    sqlitem.Append(Join);
+                                    string a = sqlHead[heada] + index;
+                                    sqlitem.Append(a + " ");
+                                    //keyValues.Add(ks[i], a);
+                                    keyValues[keyBody[i]] = a;
+                                    sqlitem.Append(instring);
+                                    sqlitem.Append(keyValues[keyBody[i - 1]]);
+                                    sqlitem.Append(keyBody[i]);
+                                }
+                                index += 1;
+                            }
+                            sql.Append(sqlitem);
+                            string s = "";
+                            if (isLikeSQL)
+                            {
+                                if (item.Value is JArray array)
+                                {
+                                    s = ValueIsLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + "", array, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
+                                }
+                                else if (item.Value is IEnumerable enumerable && !(item.Value is String))
+                                {
+                                    s = ValueIsLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + "", enumerable, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
+                                }
+                                else if (item.Value is JsonElement jsonElement1)
+                                {
+                                    if (jsonElement1.ValueKind is JsonValueKind.Object)
+                                    {
+
+                                        string compareOperBool = " true ";
+                                        compareOperBool = CompareBoolSwitch(compareOper);
+                                        string logicOperString = " and ";
+                                        if (logicOperNum != 0) logicOperString = LogicOpers[logicOper];
+                                        s = logicOperString + "Contains(" + sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + " , \'" + item.Value.ToString() + "\') = " + compareOperBool + " ";
+                                    }
+                                    else
+                                    {
+                                        s = ValueIsLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + "", jsonElement1, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
+                                    }
+
+                                }
+                                else
+                                {
+                                    s = ValueIsLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + "", item.Value, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
+                                }
+                            }
+                            else
+                            {
+                                s = ValueNotLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index], item.Value, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
+                            }
+                            WhereString.Append(s);
+
+                            if (keyListValueList)
+                            {
+                                sql = sql.Replace("select ", "select distinct ");
+                               // sql.Append(sqlitem);
+                            }
+                        }
+                        else
+                        {
+                            throw new BizException("数组总共深度不能超过5层", ResponseCode.PARAMS_ERROR);
+                        }
+
+
+                    }
+                    else
+                    {
+
+                        WhereString.Append(KeyNotElement(dict[item.Key], item.Key, LogicOpers[logicOper], logicOperNum, compareOper));
+
+                    }
+                    heada += 1;
+                    logicOperNum += 1;
+                }
+                sql.Append(" where 1=1 ").Append(WhereString);
+                if (pageBool)
+                {
+                    sql.Append(" OFFSET " + offsetNum + " LIMIT " + limitNum);
+                }
+            }
+        }
+
+        private static void GetPageNum(Dictionary<string, object> dict, ref int offsetNum, ref int limitNum, ref bool pageBool)
+        {
+            dict.TryGetValue("OFFSET", out object offset);
+            dict.Remove("OFFSET");
+            dict.TryGetValue("LIMIT", out object limit);
+            dict.Remove("LIMIT");
+            if (offset != null && limit != null)
+            {
+                pageBool = true;
+                offsetNum = int.Parse(offset.ToString());
+                limitNum = int.Parse(limit.ToString());
+            }
+        }
+
+        private static void CompareOperSwitch(string keyHead, ref string key, ref int compareOper)
+        {
+            switch (keyHead)
+            {
+
+                case ">":
+                    compareOper = (int)CompareOper.moreThan;
+                    key = key.Replace(">.", "");
+                    break;
+                case "<":
+                    compareOper = (int)CompareOper.lessThan;
+                    key = key.Replace("<.", "");
+                    break;
+                case "<=":
+                    compareOper = (int)CompareOper.notMoreThan;
+                    key = key.Replace("<=.", "");
+                    break;
+                case ">=":
+                    compareOper = (int)CompareOper.notLessThan;
+                    key = key.Replace(">=.", "");
+                    break;
+                case "=":
+                    compareOper = (int)CompareOper.equal;
+                    key = key.Replace("=.", "");
+                    break;
+                case "!=":
+                    compareOper = (int)CompareOper.notEqual;
+                    key = key.Replace("!=.", "");
+                    break;
+                case "$":
+                    compareOper = (int)CompareOper.like;
+                    key = key.Replace("$.", "");
+                    break;
+                case "!$":
+                    compareOper = (int)CompareOper.notLike;
+                    key = key.Replace("!$.", "");
+                    break;
+                default:
+                    compareOper = 4;
+                    break;
+            }
+        }
+
+        private static string ValueNotLike(string key, object value, string logicOperParams, int logicOperNum, int compareOperNum, ref bool keyListValueList)
+        {
+
+            string logicOper = " and ";
+            string compareOper = " = ";
+            if (compareOperNum != 4) compareOper = CompareOpers[compareOperNum];
+            if (logicOperNum != 0) logicOper = logicOperParams;
+            StringBuilder sql = new StringBuilder(logicOper + key + " in (");
+            if (value is JArray array)
+            {
+                foreach (JValue obja in array)
+                {
+                    if (obja.Value is string a)
+                    {
+                        sql.Append("\'" + a + "\',");
+                    }
+                    if (obja.Value is int b)
+                    {
+                        sql.Append(b + ",");
+                    }
+                    if (obja.Value is double c)
+                    {
+                        sql.Append(c + ",");
+                    }
+                    if (obja.Value is bool d)
+                    {
+                        sql.Append(d + ",");
+                    }
+                    if (obja.Value is long e)
+                    {
+                        sql.Append(e + ",");
+                    }
+                    if (obja.Value is DateTime f)
+                    {
+                        sql.Append(f + ",");
+                    }
+                }
+                string sqls = sql.ToString().Substring(0, sql.Length - 1);
+                sqls += " ) ";
+                return sqls;
+            }
+            else if (value is IEnumerable enumerable && !(value is String))
+            {
+                foreach (object obja in enumerable)
+                {
+                    if (obja is string a)
+                    {
+                        sql.Append("\'" + a + "\',");
+                    }
+                    if (obja is int b)
+                    {
+                        sql.Append(" " + b + " ,");
+
+                    }
+                    if (obja is double c)
+                    {
+                        sql.Append(" " + c + " ,");
+                    }
+                    if (obja is bool d)
+                    {
+                        sql.Append(" " + d + " ,");
+
+                    }
+                    if (obja is long e)
+                    {
+                        sql.Append(" " + e + " ,");
+                    }
+                    if (obja is DateTime f)
+                    {
+                        sql.Append(" " + f + " ,");
+                    }
+                }
+                string sqls = sql.ToString().Substring(0, sql.Length - 1);
+                sqls += ") ";
+                return sqls;
+            }
+            else if (value is JsonElement jsonElement)
+            {
+                foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
+                {
+                    if (obja.ValueKind is JsonValueKind.String)
+                    {
+                        sql.Append("\'" + obja.ToString() + "\',");
+                    }
+                    if (obja.ValueKind is JsonValueKind.Number)
+                    {
+                        sql.Append(" " + int.Parse(obja.ToString()) + " ,");
+                    }
+                    if (obja.ValueKind is JsonValueKind.True)
+                    {
+                        sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
+                    }
+                    if (obja.ValueKind is JsonValueKind.False)
+                    {
+                        sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
+                    }
+                }
+                string sqls = sql.ToString().Substring(0, sql.Length - 1);
+                sqls += ") ";
+                return sqls;
+            }
+            else
+            {
+                Type s = value.GetType();
+                TypeCode typeCode = Type.GetTypeCode(s);
+                if (compareOperNum == 4) keyListValueList = false;
+                return typeCode switch
+                {
+                    TypeCode.String => logicOper + key + compareOper + "\'" + value.ToString() + "\'",
+                    TypeCode.Char => logicOper + key + compareOper + "\'" + value.ToString() + "\'",
+                    TypeCode.Int32 => logicOper + key + compareOper + int.Parse(value.ToString()),
+                    TypeCode.Double => logicOper + key + compareOper + double.Parse(value.ToString()),
+                    //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
+                    TypeCode.Boolean => logicOper + key + compareOper + bool.Parse(value.ToString()),
+                    TypeCode.DateTime => logicOper + key + compareOper + (DateTime)value,
+                    TypeCode.Int64 => logicOper + key + compareOper + long.Parse(value.ToString()),
+                    _ => null,
+                };
+            }
+        }
+
+        private static string ValueIsLike(string key, object value, string logicOperParams, int logicOperNum, int compareOperNum, ref bool keyListValueList)
+        {
+            string compareOperBool = " true ";
+            compareOperBool = CompareBoolSwitch(compareOperNum);
+            string logicOper = " and ";
+            if (logicOperNum != 0) logicOper = logicOperParams;
+            StringBuilder s = new StringBuilder(logicOper + " ( Contains( ");
+
+            if (value is JArray array)
+            {
+                int aa = 0;
+                foreach (JValue obja in array)
+                {
+                    if (aa != 0) s.Append("or Contains(");
+                    if (obja.Value is string a)
+                    {
+                        s.Append(key + "," + "\'" + a + "\') = " + compareOperBool + " ");
+                    }
+                    else if (obja.Value is int b)
+                    {
+                        s.Append(key + "," + " " + b + " ) = " + compareOperBool + " ");
+
+                    }
+                    else if (obja.Value is double c)
+                    {
+                        s.Append(key + "," + " " + c + " ) = " + compareOperBool + " ");
+                    }
+                    else if (obja.Value is bool d)
+                    {
+                        s.Append(key + "," + " " + d + " ) = " + compareOperBool + " ");
+
+                    }
+                    else if (obja.Value is long e)
+                    {
+                        s.Append(key + "," + " " + e + " ) = " + compareOperBool + " ");
+                    }
+                    else if (obja.Value is DateTime f)
+                    {
+                        s.Append(key + "," + " " + f + " ) = " + compareOperBool + " ");
+                    }
+                    aa++;
+                }
+            }
+            else if (value is IEnumerable enumerable && !(value is String))
+            {
+                int aa = 0;
+                foreach (object obja in enumerable)
+                {
+                    if (aa != 0) s.Append("or Contains(");
+                    if (obja is string a)
+                    {
+                        s.Append(key + "," + "\'" + a + "\') = " + compareOperBool + " ");
+                    }
+                    if (obja is int b)
+                    {
+                        s.Append(key + "," + " " + b + " ) = " + compareOperBool + " ");
+
+                    }
+                    if (obja is double c)
+                    {
+                        s.Append(key + "," + " " + c + " ) = " + compareOperBool + " ");
+                    }
+                    if (obja is bool d)
+                    {
+                        s.Append(key + "," + " " + d + " ) = " + compareOperBool + " ");
+
+                    }
+                    if (obja is long e)
+                    {
+                        s.Append(key + "," + " " + e + " ) = " + compareOperBool + " ");
+                    }
+                    if (obja is DateTime f)
+                    {
+                        s.Append(key + "," + " " + f + " ) = " + compareOperBool + " ");
+                    }
+                    aa++;
+                }
+
+            }
+            else if (value is JsonValueKind.Array && value is JsonElement jsonElement)
+            {
+                int aa = 0;
+                //jsonElement.EnumerateArray().ToArray();
+                foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
+                {
+                    if (aa != 0) s.Append("or Contains(");
+                    if (obja.ValueKind is JsonValueKind.String)
+                    {
+                        s.Append(key + "," + "\'" + obja.ToString() + "\') = " + compareOperBool + " ");
+                    }
+                    if (obja.ValueKind is JsonValueKind.Number)
+                    {
+                        s.Append(key + "," + " " + int.Parse(obja.ToString()) + " ) = " + compareOperBool + " ");
+                    }
+                    if (obja.ValueKind is JsonValueKind.True)
+                    {
+                        s.Append(key + "," + " " + bool.Parse(obja.ToString()) + " ) = " + compareOperBool + " ");
+                    }
+                    if (obja.ValueKind is JsonValueKind.False)
+                    {
+                        s.Append(key + "," + " " + bool.Parse(obja.ToString()) + " ) = " + compareOperBool + " ");
+                    }
+                    aa++;
+                }
+            }
+            else
+            {
+                Type stype = value.GetType();
+                TypeCode typeCode = Type.GetTypeCode(stype);
+                keyListValueList = false;
+                return typeCode switch
+                {
+                    TypeCode.String => logicOper + "Contains( " + key + " , \'" + value.ToString() + "\') = " + compareOperBool + " ",
+                    TypeCode.Char => logicOper + "Contains( " + key + " , \'" + value.ToString() + "\') = " + compareOperBool + " ",
+                    TypeCode.Object => logicOper + "Contains( " + key + " , \'" + value.ToString() + "\') = " + compareOperBool + " ",
+                    TypeCode.Int32 => logicOper + "Contains( " + key + " , " + int.Parse(value.ToString()) + ") = " + compareOperBool + " ",
+                    TypeCode.Double => logicOper + "Contains( " + key + " , " + double.Parse(value.ToString()) + ") = " + compareOperBool + " ",
+                    //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
+                    TypeCode.Boolean => logicOper + "Contains( " + key + " , " + bool.Parse(value.ToString()) + ") = " + compareOperBool + " ",
+                    TypeCode.DateTime => logicOper + "Contains( " + key + " , " + (DateTime)value + ") = " + compareOperBool + " ",
+                    TypeCode.Int64 => logicOper + "Contains( " + key + " , " + long.Parse(value.ToString()) + ") = " + compareOperBool + " ",
+                    _ => null,
+                };
+            }
+            s.Append(" )");
+            return s.ToString();
+        }
+
+        private static string CompareBoolSwitch(int compareOperNum)
+        {
+            return compareOperNum switch
+            {
+                6 => " true ",
+                7 => " false ",
+                _ => " true ",
+            };
+
+        }
+
+        private static string KeyNotElement(object value, string key, string logicOperParams, int logicOperNum, int compareOperNum)
+        {
+            string compareOperBool = " true ";
+            compareOperBool = CompareBoolSwitch(compareOperNum);
+            string logicOper = " and ";
+            int compareOper = 4;
+            if (logicOperNum != 0) logicOper = logicOperParams;
+            if (key.EndsWith(".&"))
+            {
+                key = key.Replace(".&", "");
+            }
+            else if (key.EndsWith(".|"))
+            {
+                key = key.Replace(".|", "");
+            }
+            string[] keyHead = key.Split(".");
+            CompareOperSwitch(keyHead[0], ref key, ref compareOper);
+
+            if (compareOper == 6 || compareOper == 7)
+            {
+                StringBuilder sql = new StringBuilder(logicOper + " ( Contains( ");
+                if (value is JArray jarray)
+                {
+                    int aa = 0;
+                    foreach (JValue obja in jarray)
+                    {
+                        if (aa != 0) sql.Append("or Contains(");
+                        if (obja.Value is string a)
+                        {
+                            sql.Append(" c." + key + ",\'" + a + "\')= " + compareOperBool + "  ");
+                        }
+                        if (obja.Value is int b)
+                        {
+                            sql.Append(" c." + key + ", " + b + " )= " + compareOperBool + "  ");
+                        }
+                        if (obja.Value is double c)
+                        {
+                            sql.Append(" c." + key + ", " + c + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja.Value is bool d)
+                        {
+                            sql.Append(" c." + key + ", " + d + " ) = " + compareOperBool + "  ");
+
+                        }
+                        if (obja.Value is long e)
+                        {
+                            sql.Append(" c." + key + ", " + e + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja.Value is DateTime f)
+                        {
+                            sql.Append(" c." + key + ", " + f + " ) = " + compareOperBool + "  ");
+                        }
+                        aa++;
+                    }
+                }
+                else if (value is IEnumerable enumerable && !(value is String))
+                {
+                    int aa = 0;
+                    foreach (object obja in enumerable)
+                    {
+                        if (aa != 0) sql.Append("or Contains(");
+                        if (obja is string a)
+                        {
+                            sql.Append(" c." + key + "," + "\'" + a + "\') = " + compareOperBool + "  ");
+                        }
+                        if (obja is int b)
+                        {
+                            sql.Append(" c." + key + "," + " " + b + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja is double c)
+                        {
+                            sql.Append(" c." + key + "," + " " + c + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja is bool d)
+                        {
+                            sql.Append(" c." + key + "," + " " + d + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja is long e)
+                        {
+                            sql.Append(" c." + key + "," + " " + e + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja is DateTime f)
+                        {
+                            sql.Append(" c." + key + "," + " " + f + " ) = " + compareOperBool + "  ");
+                        }
+                        aa++;
+                    }
+                }
+                else if (value is JsonElement jsonElement)
+                {
+                    int aa = 0;
+                    foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
+                    {
+                        if (aa != 0) sql.Append("or Contains(");
+                        if (obja.ValueKind is JsonValueKind.String)
+                        {
+                            sql.Append(" c." + key + "," + "\'" + obja.ToString() + "\') = " + compareOperBool + "  ");
+                        }
+                        if (obja.ValueKind is JsonValueKind.Number)
+                        {
+                            sql.Append(" c." + key + "," + " " + int.Parse(obja.ToString()) + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja.ValueKind is JsonValueKind.True)
+                        {
+                            sql.Append(" c." + key + "," + " " + bool.Parse(obja.ToString()) + " ) = " + compareOperBool + "  ");
+                        }
+                        if (obja.ValueKind is JsonValueKind.False)
+                        {
+                            sql.Append(" c." + key + "," + " " + bool.Parse(obja.ToString()) + " ) = " + compareOperBool + "  ");
+                        }
+                        aa++;
+                    }
+                }
+                else
+                {
+                    Type s = value.GetType();
+                    TypeCode typeCode = Type.GetTypeCode(s);
+
+                    return typeCode switch
+                    {
+                        TypeCode.String => logicOper + "Contains( c." + key + " , \'" + value.ToString() + "\') = " + compareOperBool + "  ",
+                        TypeCode.Char => logicOper + "Contains( c." + key + " , \'" + value.ToString() + "\') = " + compareOperBool + "  ",
+                        TypeCode.Int32 => logicOper + "Contains( c." + key + " , " + int.Parse(value.ToString()) + ") = " + compareOperBool + "  ",
+                        TypeCode.Double => logicOper + "Contains( c." + key + " , " + double.Parse(value.ToString()) + ") = " + compareOperBool + "  ",
+                        //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
+                        TypeCode.Boolean => logicOper + "Contains( c." + key + " , " + bool.Parse(value.ToString()) + ") = " + compareOperBool + "  ",
+                        TypeCode.DateTime => logicOper + "Contains( c." + key + " , " + (DateTime)value + ") = " + compareOperBool + "  ",
+                        TypeCode.Int64 => logicOper + "Contains( c." + key + " , " + long.Parse(value.ToString()) + ") = " + compareOperBool + "  ",
+                        _ => null,
+                    };
+                }
+
+                sql.Append(")");
+                return sql.ToString();
+            }
+            else
+            {
+                StringBuilder sql = new StringBuilder(logicOper + " c." + key + " in (");
+                if (value is JArray array)
+                {
+
+                    foreach (JValue obja in array)
+                    {
+                        if (obja.Value is string a)
+                        {
+                            sql.Append("\'" + a + "\',");
+                        }
+                        if (obja.Value is int b)
+                        {
+                            sql.Append(b + ",");
+                        }
+                        if (obja.Value is double c)
+                        {
+                            sql.Append(c + ",");
+                        }
+                        if (obja.Value is bool d)
+                        {
+                            sql.Append(d + ",");
+                        }
+                        if (obja.Value is long e)
+                        {
+                            sql.Append(e + ",");
+                        }
+                        if (obja.Value is DateTime f)
+                        {
+                            sql.Append(f + ",");
+                        }
+                    }
+                    string sqls = sql.ToString().Substring(0, sql.Length - 1);
+                    sqls += " ) ";
+                    return sqls;
+                }
+                else if (value is IEnumerable enumerable && !(value is String))
+                {
+                    foreach (object obja in enumerable)
+                    {
+                        if (obja is string a)
+                        {
+                            sql.Append("\'" + a + "\',");
+                        }
+                        if (obja is int b)
+                        {
+                            sql.Append(" " + b + " ,");
+                        }
+                        if (obja is double c)
+                        {
+                            sql.Append(" " + c + " ,");
+                        }
+                        if (obja is bool d)
+                        {
+                            sql.Append(" " + d + " ,");
+
+                        }
+                        if (obja is long e)
+                        {
+                            sql.Append(" " + e + " ,");
+                        }
+                        if (obja is DateTime f)
+                        {
+                            sql.Append(" " + f + " ,");
+                        }
+                    }
+                    string sqls = sql.ToString().Substring(0, sql.Length - 1);
+                    sqls += ") ";
+                    return sqls;
+                }
+                else if (value is JsonElement jsonElement)
+                {
+                    foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
+                    {
+                        if (obja.ValueKind is JsonValueKind.String)
+                        {
+                            sql.Append("\'" + obja.ToString() + "\',");
+                        }
+                        if (obja.ValueKind is JsonValueKind.Number)
+                        {
+                            sql.Append(" " + int.Parse(obja.ToString()) + " ,");
+                        }
+                        if (obja.ValueKind is JsonValueKind.True)
+                        {
+                            sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
+                        }
+                        if (obja.ValueKind is JsonValueKind.False)
+                        {
+                            sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
+                        }
+                    }
+                    string sqls = sql.ToString().Substring(0, sql.Length - 1);
+                    sqls += ") ";
+                    return sqls;
+                }
+                else
+                {
+                    Type s = value.GetType();
+                    TypeCode typeCode = Type.GetTypeCode(s);
+
+                    return typeCode switch
+                    {
+                        TypeCode.String => logicOper + " c." + key + CompareOpers[compareOperNum] + "\'" + value.ToString() + "\'",
+                        TypeCode.Char => logicOper + " c." + key + CompareOpers[compareOperNum] + "\'" + value.ToString() + "\'",
+                        TypeCode.Int32 => logicOper + "  c." + key + CompareOpers[compareOperNum] + int.Parse(value.ToString()),
+                        TypeCode.Double => logicOper + "  c." + key + CompareOpers[compareOperNum] + double.Parse(value.ToString()),
+                        //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
+                        TypeCode.Boolean => logicOper + "  c." + key + CompareOpers[compareOperNum] + bool.Parse(value.ToString()),
+                        TypeCode.DateTime => logicOper + "  c." + key + CompareOpers[compareOperNum] + (DateTime)value,
+                        TypeCode.Int64 => logicOper + "  c." + key + CompareOpers[compareOperNum] + long.Parse(value.ToString()),
+                        _ => null,
+                    };
+                }
+            }
+        }
+
+
+        public enum LogicOper : int
+        {
+            and = 0, or = 1
+        }
+        public enum CompareOper : int
+        {
+            moreThan = 0, lessThan = 1, notMoreThan = 2, notLessThan = 3, equal = 4, notEqual = 5, like = 6, notLike = 7, IN = 8
+        }
+
+    }
+}

+ 5 - 620
TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs

@@ -694,7 +694,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
             // List<T> objs = new List<T>();
             DocumentCollection collection=   await InitializeCollection<T>();
             StringBuilder sql = new StringBuilder("select value(c) from c");
-            GetSQL(dict, sql);
+            SQLHelper.GetSQL(dict,ref sql);
             //查询条数 -1是全部
             FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = IsPk };
             var query = CosmosClient.CreateDocumentQuery<T>(UriFactory.CreateDocumentCollectionUri(Database, collection.Id), sql.ToString(), queryOptions);
@@ -796,7 +796,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
                         }
                     }*/
                 StringBuilder sql = new StringBuilder("select value(c) from c");
-                GetSQL(dict, sql);
+                SQLHelper.GetSQL(dict,ref sql);
                 FeedOptions queryOptions;
                 if (collection.PartitionKey.Paths.Count > 0)
                 {
@@ -816,66 +816,15 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
             
         }
 
-        private static void GetSQL(Dictionary<string, object> dict, StringBuilder sql)
-        {
-            if (dict != null)
-            {
-                int offsetNum = 0;
-                int limitNum = 0;
-                bool pageBool = false;
-                GetPageNum(dict, ref offsetNum, ref limitNum, ref pageBool);
-
-                string Join = " join ";
-                string instring = "in ";
-                Dictionary<string, string> keyValues = new Dictionary<string, string>();
-                StringBuilder whereSting = new StringBuilder();
-                int heada = 0;
-                string[] sqlHead = new string[] { "A", "B", "C", "D", "E", "F" };
-                int kslength = 0;
-                foreach (KeyValuePair<string, object> item in dict)
-                {
-                    bool isLikeSQL = false;
-                    if (item.Key.StartsWith("$."))
-                    {
-                        isLikeSQL = true;
-                    }
-                    int index = 0;
-                    string[] ks = item.Key.Split("[*]");
-
-                    if (ks.Length > 1)
-                    {
-                        KeyIsElement(sql, Join, instring, keyValues, whereSting, heada, sqlHead, ref kslength, item, isLikeSQL, ref index, ks);
-                    }
-                    else
-                    {
-                        whereSting.Append(KeyNotElement(dict[item.Key], item.Key));
-                    }
-                    heada += 1;
-                }
-                sql.Append(" where 1=1 ").Append(whereSting);
-                if (pageBool)
-                {
-                    sql.Append(" OFFSET " + offsetNum + " LIMIT " + limitNum);
-                }
-
-            }
-        }
+     
 
         public IQueryable<dynamic> FindCountByDict(string CollectionName, Dictionary<string, object> dict)
         {
             if (DocumentCollectionDict.TryGetValue(CollectionName, out DocumentCollection collection))
             {
-                //  collection = await InitializeCollection(CollectionName, "");
-                /*    StringBuilder sql = new StringBuilder("select * from " + CollectionName + " c where 1=1 ");
-                    if (dict != null)
-                    {
-                        foreach (string key in dict.Keys)
-                        {
-                            sql.Append(GenSql(dict[key], key));
-                        }
-                    }*/
+                
                 StringBuilder sql = new StringBuilder("select value count(c) from c");
-                GetSQL(dict, sql);
+                SQLHelper.GetSQL(dict, ref sql);
                 FeedOptions queryOptions;
                 if (collection.PartitionKey.Paths.Count > 0)
                 {
@@ -908,569 +857,5 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
                 limitNum = int.Parse(limit.ToString());
             }
         }
-
-        private static void KeyIsElement(StringBuilder sql, string Join, string instring, Dictionary<string, string> keyValues, StringBuilder whereSting, int heada, string[] sqlHead, ref int kslength, KeyValuePair<string, object> item, bool isLikeSQL, ref int index, string[] ks)
-        {
-            kslength += ks.Length;
-            if (kslength < (7 + heada))
-            {
-                StringBuilder sqlitem = new StringBuilder();
-                for (int i = 0; i < ks.Length - 1; i++)
-                {
-
-                    //Console.WriteLine(ks[i]);
-                    if (i == 0)
-                    {
-                        sqlitem.Append(Join);
-                        string a = sqlHead[heada] + index;
-                        sqlitem.Append(a + " ");
-                        //keyValues.Add(ks[i], a);
-                        keyValues[ks[i]] = a;
-                        sqlitem.Append(instring);
-                        sqlitem.Append("c.");
-                        if (isLikeSQL)
-                        {
-                            sqlitem.Append(ks[i].Replace("$.", ""));
-                        }
-                        else
-                        {
-                            sqlitem.Append(ks[i]);
-                        }
-                    }
-                    else
-                    {
-                        sqlitem.Append(Join + " ");
-                        string a = sqlHead[heada] + index;
-                        sqlitem.Append(a + " ");
-                        //keyValues.Add(ks[i], a);
-                        keyValues[ks[i]] = a;
-                        sqlitem.Append(instring);
-                        sqlitem.Append(keyValues[ks[i - 1]]);
-                        sqlitem.Append(ks[i]);
-                    }
-                    index += 1;
-                }
-                // Console.WriteLine(sqlitem);
-                sql.Append(sqlitem);
-                string s = "";
-                if (isLikeSQL)
-                {
-                    if (item.Value is JArray array)
-                    {
-                        s = ValueIsLike(sqlHead[heada] + (ks.Length - 2) + ks[index] + "", array);
-                        //s = GenSql(array, sqlHead[heada] + (ks.Length - 2) + ks[index] + "");
-                    }
-                    else if (item.Value is IEnumerable enumerable && !(item.Value is String))
-                    {
-                        s = ValueIsLike(sqlHead[heada] + (ks.Length - 2) + ks[index] + "", enumerable);
-                        //s = GenSql(enumerable, sqlHead[heada] + (ks.Length - 2) + ks[index] + "");
-                    }
-                    else if (item.Value is JsonElement jsonElement1)
-                    {
-                        if (jsonElement1.ValueKind is JsonValueKind.Object)
-                        {
-                            s = "and " + "Contains(" + sqlHead[heada] + (ks.Length - 2) + ks[index] + " , \'" + item.Value.ToString() + "\') = true ";
-                        }
-                        else if (jsonElement1.ValueKind is JsonValueKind.Array)
-                        {
-                            s = ValueIsLike(sqlHead[heada] + (ks.Length - 2) + ks[index] + "", jsonElement1);
-                            // s = GenSql(jsonElement1, sqlHead[heada] + (ks.Length - 2) + ks[index] + "");
-                        }
-                    }
-                    else
-                    {
-                        //s = "and " + "Contains(" + sqlHead[heada] + (ks.Length - 2) + ks[index] + " , \'" + item.Value.ToString() + "\') = true ";
-                        s = ValueIsLike(sqlHead[heada] + (ks.Length - 2) + ks[index] + "", item.Value);
-                    }
-                }
-                else
-                {
-                    //s = "and " + sqlHead[heada] + (ks.Length - 2) + ks[index] + " = " + "\"" + item.Value.ToString() + "\"";
-                    s = ValueNotLike(sqlHead[heada] + (ks.Length - 2) + ks[index], item.Value);
-                }
-                whereSting.Append(s);
-            }
-            else
-            {
-                // throw new BizException("数组总共深度不能超过5层", ResponseCode.PARAMS_ERROR);
-            }
-        }
-
-        private static string ValueNotLike(string key, object value)
-        {
-
-            StringBuilder sql = new StringBuilder(" and  " + key + " in (");
-            if (value is JArray array)
-            {
-                foreach (JValue obja in array)
-                {
-                    if (obja.Value is string a)
-                    {
-                        sql.Append("\'" + a + "\',");
-                    }
-                    if (obja.Value is int b)
-                    {
-                        sql.Append(b + ",");
-                    }
-                    if (obja.Value is double c)
-                    {
-                        sql.Append(c + ",");
-                    }
-                    if (obja.Value is bool d)
-                    {
-                        sql.Append(d + ",");
-                    }
-                    if (obja.Value is long e)
-                    {
-                        sql.Append(e + ",");
-                    }
-                    if (obja.Value is DateTime f)
-                    {
-                        sql.Append(f + ",");
-                    }
-                }
-                string sqls = sql.ToString().Substring(0, sql.Length - 1);
-                sqls += " ) ";
-                return sqls;
-            }
-            else if (value is IEnumerable enumerable && !(value is String))
-            {
-                foreach (object obja in enumerable)
-                {
-                    if (obja is string a)
-                    {
-                        sql.Append("\'" + a + "\',");
-                    }
-                    if (obja is int b)
-                    {
-                        sql.Append(" " + b + " ,");
-
-                    }
-                    if (obja is double c)
-                    {
-                        sql.Append(" " + c + " ,");
-                    }
-                    if (obja is bool d)
-                    {
-                        sql.Append(" " + d + " ,");
-
-                    }
-                    if (obja is long e)
-                    {
-                        sql.Append(" " + e + " ,");
-                    }
-                    if (obja is DateTime f)
-                    {
-                        sql.Append(" " + f + " ,");
-                    }
-                }
-                string sqls = sql.ToString().Substring(0, sql.Length - 1);
-                sqls += ") ";
-                return sqls;
-            }
-            else if (value is JsonElement jsonElement)
-            {
-                foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
-                {
-                    if (obja.ValueKind is JsonValueKind.String)
-                    {
-                        sql.Append("\'" + obja.ToString() + "\',");
-                    }
-                    if (obja.ValueKind is JsonValueKind.Number)
-                    {
-                        sql.Append(" " + int.Parse(obja.ToString()) + " ,");
-                    }
-                    if (obja.ValueKind is JsonValueKind.True)
-                    {
-                        sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
-                    }
-                    if (obja.ValueKind is JsonValueKind.False)
-                    {
-                        sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
-                    }
-                }
-                string sqls = sql.ToString().Substring(0, sql.Length - 1);
-                sqls += ") ";
-                return sqls;
-            }
-            else
-            {
-                Type s = value.GetType();
-                TypeCode typeCode = Type.GetTypeCode(s);
-                return typeCode switch
-                {
-                    TypeCode.String => " and " + key + " = " + "\'" + value.ToString() + "\'",
-                    TypeCode.Char => " and " + key + " = " + "\'" + value.ToString() + "\'",
-                    TypeCode.Int32 => " and " + key + " = " + int.Parse(value.ToString()),
-                    TypeCode.Double => " and " + key + " = " + double.Parse(value.ToString()),
-                    //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
-                    TypeCode.Boolean => " and " + key + " = " + bool.Parse(value.ToString()),
-                    TypeCode.DateTime => " and " + key + " = " + (DateTime)value,
-                    TypeCode.Int64 => " and " + key + " = " + long.Parse(value.ToString()),
-                    _ => null,
-                };
-            }
-        }
-
-        private static string ValueIsLike(string key, object value)
-        {
-            StringBuilder s = new StringBuilder("and ( Contains( ");
-
-            if (value is JArray array)
-            {
-                int aa = 0;
-                foreach (JValue obja in array)
-                {
-                    if (aa != 0) s.Append("or Contains(");
-                    if (obja.Value is string a)
-                    {
-                        s.Append(key + "," + "\'" + a + "\') = true ");
-                    }
-                    else if (obja.Value is int b)
-                    {
-                        s.Append(key + "," + " " + b + " ) = true ");
-
-                    }
-                    else if (obja.Value is double c)
-                    {
-                        s.Append(key + "," + " " + c + " ) = true ");
-                    }
-                    else if (obja.Value is bool d)
-                    {
-                        s.Append(key + "," + " " + d + " ) = true ");
-
-                    }
-                    else if (obja.Value is long e)
-                    {
-                        s.Append(key + "," + " " + e + " ) = true ");
-                    }
-                    else if (obja.Value is DateTime f)
-                    {
-                        s.Append(key + "," + " " + f + " ) = true ");
-                    }
-                    aa++;
-                }
-            }
-            else if (value is IEnumerable enumerable && !(value is String))
-            {
-                int aa = 0;
-                foreach (object obja in enumerable)
-                {
-                    if (aa != 0) s.Append("or Contains(");
-                    if (obja is string a)
-                    {
-                        s.Append(key + "," + "\'" + a + "\') = true ");
-                    }
-                    if (obja is int b)
-                    {
-                        s.Append(key + "," + " " + b + " ) = true ");
-
-                    }
-                    if (obja is double c)
-                    {
-                        s.Append(key + "," + " " + c + " ) = true ");
-                    }
-                    if (obja is bool d)
-                    {
-                        s.Append(key + "," + " " + d + " ) = true ");
-
-                    }
-                    if (obja is long e)
-                    {
-                        s.Append(key + "," + " " + e + " ) = true ");
-                    }
-                    if (obja is DateTime f)
-                    {
-                        s.Append(key + "," + " " + f + " ) = true ");
-                    }
-                    aa++;
-                }
-
-            }
-            else if (value is JsonElement jsonElement)
-            {
-                int aa = 0;
-                //jsonElement.EnumerateArray().ToArray();
-                foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
-                {
-                    if (aa != 0) s.Append("or Contains(");
-                    if (obja.ValueKind is JsonValueKind.String)
-                    {
-                        s.Append(key + "," + "\'" + obja.ToString() + "\') = true ");
-                    }
-                    if (obja.ValueKind is JsonValueKind.Number)
-                    {
-                        s.Append(key + "," + " " + int.Parse(obja.ToString()) + " ) = true ");
-                    }
-                    if (obja.ValueKind is JsonValueKind.True)
-                    {
-                        s.Append(key + "," + " " + bool.Parse(obja.ToString()) + " ) = true ");
-                    }
-                    if (obja.ValueKind is JsonValueKind.False)
-                    {
-                        s.Append(key + "," + " " + bool.Parse(obja.ToString()) + " ) = true ");
-                    }
-                    aa++;
-                }
-            }
-            else
-            {
-                Type stype = value.GetType();
-                TypeCode typeCode = Type.GetTypeCode(stype);
-                return typeCode switch
-                {
-                    TypeCode.String => "and " + "Contains( " + key + " , \'" + value.ToString() + "\') = true ",
-                    TypeCode.Char => "and " + "Contains( " + key + " , \'" + value.ToString() + "\') = true ",
-                    TypeCode.Int32 => "and " + "Contains( " + key + " , " + int.Parse(value.ToString()) + ") = true ",
-                    TypeCode.Double => "and " + "Contains( " + key + " , " + double.Parse(value.ToString()) + ") = true ",
-                    //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
-                    TypeCode.Boolean => "and " + "Contains( " + key + " , " + bool.Parse(value.ToString()) + ") = true ",
-                    TypeCode.DateTime => "and " + "Contains( " + key + " , " + (DateTime)value + ") = true ",
-                    TypeCode.Int64 => "and " + "Contains( " + key + " , " + long.Parse(value.ToString()) + ") = true ",
-                    _ => null,
-                };
-            }
-            s.Append(" )");
-            return s.ToString();
-        }
-
-        private static string KeyNotElement(object value, string key)
-        {
-
-            if (key.StartsWith("$."))
-            {
-                string keyLike = key.Replace("$.", "");
-                StringBuilder sql = new StringBuilder(" and ( Contains( ");
-                if (value is JArray jarray)
-                {
-                    int aa = 0;
-                    foreach (JValue obja in jarray)
-                    {
-                        if (aa != 0) sql.Append("or Contains(");
-                        if (obja.Value is string a)
-                        {
-                            sql.Append(" c." + keyLike + ",\'" + a + "\')");
-                        }
-                        if (obja.Value is int b)
-                        {
-                            sql.Append(" c." + keyLike + ", " + b + " )");
-                        }
-                        if (obja.Value is double c)
-                        {
-                            sql.Append(" c." + keyLike + ", " + c + " )");
-                        }
-                        if (obja.Value is bool d)
-                        {
-                            sql.Append(" c." + keyLike + ", " + d + " )");
-
-                        }
-                        if (obja.Value is long e)
-                        {
-                            sql.Append(" c." + keyLike + ", " + e + " )");
-                        }
-                        if (obja.Value is DateTime f)
-                        {
-                            sql.Append(" c." + keyLike + ", " + f + " )");
-                        }
-                        aa++;
-                    }
-                }
-                else if (value is IEnumerable enumerable && !(value is String))
-                {
-                    int aa = 0;
-                    foreach (object obja in enumerable)
-                    {
-                        if (aa != 0) sql.Append("or Contains(");
-                        if (obja is string a)
-                        {
-                            sql.Append(" c." + keyLike + "," + "\'" + a + "\') = true ");
-                        }
-                        if (obja is int b)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + b + " ) = true ");
-                        }
-                        if (obja is double c)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + c + " ) = true ");
-                        }
-                        if (obja is bool d)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + d + " ) = true ");
-                        }
-                        if (obja is long e)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + e + " ) = true ");
-                        }
-                        if (obja is DateTime f)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + f + " ) = true ");
-                        }
-                        aa++;
-                    }
-                }
-                else if (value is JsonElement jsonElement)
-                {
-                    int aa = 0;
-                    foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
-                    {
-                        if (aa != 0) sql.Append("or Contains(");
-                        if (obja.ValueKind is JsonValueKind.String)
-                        {
-                            sql.Append(" c." + keyLike + "," + "\'" + obja.ToString() + "\') = true ");
-                        }
-                        if (obja.ValueKind is JsonValueKind.Number)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + int.Parse(obja.ToString()) + " ) = true ");
-                        }
-                        if (obja.ValueKind is JsonValueKind.True)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + bool.Parse(obja.ToString()) + " ) = true ");
-                        }
-                        if (obja.ValueKind is JsonValueKind.False)
-                        {
-                            sql.Append(" c." + keyLike + "," + " " + bool.Parse(obja.ToString()) + " ) = true ");
-                        }
-                        aa++;
-                    }
-                }
-                else
-                {
-                    Type s = value.GetType();
-                    TypeCode typeCode = Type.GetTypeCode(s);
-                    return typeCode switch
-                    {
-                        TypeCode.String => "and " + "Contains( c." + keyLike + " , \'" + value.ToString() + "\') = true ",
-                        TypeCode.Char => "and " + "Contains( c." + keyLike + " , \'" + value.ToString() + "\') = true ",
-                        TypeCode.Int32 => "and " + "Contains( c." + keyLike + " , " + int.Parse(value.ToString()) + ") = true ",
-                        TypeCode.Double => "and " + "Contains( c." + keyLike + " , " + double.Parse(value.ToString()) + ") = true ",
-                        //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
-                        TypeCode.Boolean => "and " + "Contains( c." + keyLike + " , " + bool.Parse(value.ToString()) + ") = true ",
-                        TypeCode.DateTime => "and " + "Contains( c." + keyLike + " , " + (DateTime)value + ") = true ",
-                        TypeCode.Int64 => "and " + "Contains( c." + keyLike + " , " + long.Parse(value.ToString()) + ") = true ",
-                        _ => null,
-                    };
-                }
-
-                sql.Append(")");
-                return sql.ToString();
-            }
-            else
-            {
-                StringBuilder sql = new StringBuilder(" and  c." + key + " in (");
-                if (value is JArray array)
-                {
-
-                    foreach (JValue obja in array)
-                    {
-                        if (obja.Value is string a)
-                        {
-                            sql.Append("\'" + a + "\',");
-                        }
-                        if (obja.Value is int b)
-                        {
-                            sql.Append(b + ",");
-
-                        }
-                        if (obja.Value is double c)
-                        {
-                            sql.Append(c + ",");
-                        }
-                        if (obja.Value is bool d)
-                        {
-                            sql.Append(d + ",");
-
-                        }
-                        if (obja.Value is long e)
-                        {
-                            sql.Append(e + ",");
-                        }
-                        if (obja.Value is DateTime f)
-                        {
-                            sql.Append(f + ",");
-                        }
-                    }
-                    string sqls = sql.ToString().Substring(0, sql.Length - 1);
-                    sqls += " ) ";
-                    return sqls;
-                }
-                else if (value is IEnumerable enumerable && !(value is String))
-                {
-                    foreach (object obja in enumerable)
-                    {
-                        if (obja is string a)
-                        {
-                            sql.Append("\'" + a + "\',");
-                        }
-                        if (obja is int b)
-                        {
-                            sql.Append(" " + b + " ,");
-
-                        }
-                        if (obja is double c)
-                        {
-                            sql.Append(" " + c + " ,");
-                        }
-                        if (obja is bool d)
-                        {
-                            sql.Append(" " + d + " ,");
-
-                        }
-                        if (obja is long e)
-                        {
-                            sql.Append(" " + e + " ,");
-                        }
-                        if (obja is DateTime f)
-                        {
-                            sql.Append(" " + f + " ,");
-                        }
-                    }
-                    string sqls = sql.ToString().Substring(0, sql.Length - 1);
-                    sqls += ") ";
-                    return sqls;
-                }
-                else if (value is JsonElement jsonElement)
-                {
-                    foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
-                    {
-                        if (obja.ValueKind is JsonValueKind.String)
-                        {
-                            sql.Append("\'" + obja.ToString() + "\',");
-                        }
-                        if (obja.ValueKind is JsonValueKind.Number)
-                        {
-                            sql.Append(" " + int.Parse(obja.ToString()) + " ,");
-                        }
-                        if (obja.ValueKind is JsonValueKind.True)
-                        {
-                            sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
-                        }
-                        if (obja.ValueKind is JsonValueKind.False)
-                        {
-                            sql.Append(" " + bool.Parse(obja.ToString()) + " ,");
-                        }
-                    }
-                    string sqls = sql.ToString().Substring(0, sql.Length - 1);
-                    sqls += ") ";
-                    return sqls;
-                }
-                else
-                {
-                    Type s = value.GetType();
-                    TypeCode typeCode = Type.GetTypeCode(s);
-                    return typeCode switch
-                    {
-                        TypeCode.String => " and c." + key + " = " + "\'" + value.ToString() + "\'",
-                        TypeCode.Char => " and c." + key + " = " + "\'" + value.ToString() + "\'",
-                        TypeCode.Int32 => " and c." + key + " = " + int.Parse(value.ToString()),
-                        TypeCode.Double => " and c." + key + " = " + double.Parse(value.ToString()),
-                        //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
-                        TypeCode.Boolean => " and c." + key + " = " + bool.Parse(value.ToString()),
-                        TypeCode.DateTime => " and c." + key + " = " + (DateTime)value,
-                        TypeCode.Int64 => " and c." + key + " = " + long.Parse(value.ToString()),
-                        _ => null,
-                    };
-                }
-            }
-        }
     }
 }