|
@@ -71,11 +71,47 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
return sql;
|
|
return sql;
|
|
}
|
|
}
|
|
|
|
|
|
- public static CosmosDbQuery GetSQL(Dictionary<string, object> dict, StringBuilder sql)
|
|
|
|
|
|
+ public static void DictIsNotNULL(Dictionary<string, object> dict)
|
|
{
|
|
{
|
|
|
|
+ Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
|
|
|
|
+ foreach (KeyValuePair<string, object> keyValuePair in dict)
|
|
|
|
+ {
|
|
|
|
+ if (keyValuePair.Value is JArray array)
|
|
|
|
+ {
|
|
|
|
+ if (array == null || array.Count == 0) keyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
|
|
|
+ }
|
|
|
|
+ else if (keyValuePair.Value is IList enumerable && !(keyValuePair.Value is String))
|
|
|
|
+ {
|
|
|
|
+ if (enumerable == null || enumerable.Count == 0) keyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
|
|
|
+ }
|
|
|
|
+ else if (keyValuePair.Value is JsonElement jsonElement && jsonElement.ValueKind is JsonValueKind.Array)
|
|
|
|
+ {
|
|
|
|
|
|
|
|
+ if (jsonElement.EnumerateArray().Count() == 0)
|
|
|
|
+ {
|
|
|
|
+ keyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if (keyValuePair.Value is null)
|
|
|
|
+ {
|
|
|
|
+ keyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (keyValuePairs.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (KeyValuePair<string, object> keyValuePair in keyValuePairs)
|
|
|
|
+ {
|
|
|
|
+ dict.Remove(keyValuePair.Key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static CosmosDbQuery GetSQL(Dictionary<string, object> dict, StringBuilder sql)
|
|
|
|
+ {
|
|
if (dict != null)
|
|
if (dict != null)
|
|
{
|
|
{
|
|
|
|
+ DictIsNotNULL(dict);
|
|
Dictionary<string, object> parmeters = new Dictionary<string, object>();
|
|
Dictionary<string, object> parmeters = new Dictionary<string, object>();
|
|
|
|
|
|
int offsetNum = 0;
|
|
int offsetNum = 0;
|
|
@@ -245,9 +281,13 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
sql.Append(" OFFSET " + " @offsetNum " + " LIMIT " + " @limitNum ");
|
|
sql.Append(" OFFSET " + " @offsetNum " + " LIMIT " + " @limitNum ");
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ //替换关键字
|
|
ReplaceKeyWords(ref sql);
|
|
ReplaceKeyWords(ref sql);
|
|
|
|
+
|
|
|
|
+ //参数化查询拼接 参数dict
|
|
parmeters = GetParmeter(dict, parmeters, offsetNum, limitNum);
|
|
parmeters = GetParmeter(dict, parmeters, offsetNum, limitNum);
|
|
|
|
+
|
|
|
|
+
|
|
CosmosDbQuery cosmosDbQuery = new CosmosDbQuery
|
|
CosmosDbQuery cosmosDbQuery = new CosmosDbQuery
|
|
{
|
|
{
|
|
QueryText = sql.ToString(),
|
|
QueryText = sql.ToString(),
|
|
@@ -535,7 +575,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
aa++;
|
|
aa++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if (value is JsonElement jsonElement && jsonElement.ValueKind! is JsonValueKind.Array)
|
|
|
|
|
|
+ else if (value is JsonElement jsonElement && jsonElement.ValueKind is JsonValueKind.Array)
|
|
{
|
|
{
|
|
int aa = 0;
|
|
int aa = 0;
|
|
foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
|
|
foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
|
|
@@ -562,6 +602,10 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
{
|
|
{
|
|
sql1 = logicOper + "Contains( c." + key + " , @" + key1 + " ) = " + compareOperBool + " ";
|
|
sql1 = logicOper + "Contains( c." + key + " , @" + key1 + " ) = " + compareOperBool + " ";
|
|
}
|
|
}
|
|
|
|
+ if (value is JsonElement jsonElement1 && jsonElement1.ValueKind is JsonValueKind.String)
|
|
|
|
+ {
|
|
|
|
+ sql1 = logicOper + "Contains( c." + key + " , @" + key1 + " ) = " + compareOperBool + " ";
|
|
|
|
+ }
|
|
else
|
|
else
|
|
{
|
|
{
|
|
sql1 = logicOper + "Contains( ToString( c." + key + " ), \'@" + key1 + "\' ) = " + compareOperBool + " ";
|
|
sql1 = logicOper + "Contains( ToString( c." + key + " ), \'@" + key1 + "\' ) = " + compareOperBool + " ";
|