|
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using TEAMModelOS.SDK.Context.Exception;
|
|
|
|
|
|
namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
@@ -42,17 +43,24 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
bool pageBool = false;
|
|
|
GetPageNum(dict, ref offsetNum, ref limitNum, ref pageBool);
|
|
|
|
|
|
+ string OrderByValue = "";
|
|
|
|
|
|
// 处理OrderBy
|
|
|
- if (dict.TryGetValue("OrderBy", out object OrderBy))
|
|
|
+ if (dict.TryGetValue("@ASC", out object ASC))
|
|
|
{
|
|
|
- dict.Remove("OrderBy");
|
|
|
+ OrderByValue = Regex.Replace(ASC.ToString(), "\\s{1,}", "");
|
|
|
+ dict.Remove("@ASC");
|
|
|
}
|
|
|
- if (dict.TryGetValue("OrderByDESC", out object OrderByDESC))
|
|
|
+ if (dict.TryGetValue("@DESC", out object DESC))
|
|
|
{
|
|
|
- dict.Remove("OrderByDESC");
|
|
|
+ OrderByValue = Regex.Replace(DESC.ToString(), "\\s{1,}", "");
|
|
|
+ dict.Remove("@DESC");
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//处理顺序
|
|
|
Stack<KeyValuePair<string, object>> stack = new Stack<KeyValuePair<string, object>>();
|
|
|
|
|
@@ -182,22 +190,25 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
|
|
|
sql.Append(" where 1=1 ").Append(WhereString);
|
|
|
|
|
|
- if (OrderBy != null)
|
|
|
+ if (ASC != null)
|
|
|
{
|
|
|
- sql.Append(" Order By c." + OrderBy.ToString());
|
|
|
+ sql.Append(" Order By c." + OrderByValue );
|
|
|
+ //sql.Append(" Order By c." + "@OrderByValue");
|
|
|
}
|
|
|
- else if (OrderByDESC != null) {
|
|
|
- sql.Append(" Order By c." + OrderByDESC.ToString() + " DESC " );
|
|
|
+ else if (DESC != null) {
|
|
|
+ sql.Append(" Order By c." + OrderByValue );
|
|
|
+ // sql.Append(" Order By c." + "@OrderByValue"+ " DESC " );
|
|
|
}
|
|
|
|
|
|
- if (pageBool)
|
|
|
+ if (pageBool && offsetNum != 0 && limitNum != 0)
|
|
|
{
|
|
|
- sql.Append(" OFFSET " + offsetNum + " LIMIT " + limitNum);
|
|
|
+ //sql.Append(" OFFSET " + offsetNum + " LIMIT " + limitNum);
|
|
|
+ sql.Append(" OFFSET " + " @offsetNum " + " LIMIT " + " @limitNum ");
|
|
|
}
|
|
|
|
|
|
|
|
|
ReplaceKeyWords(ref sql);
|
|
|
- parmeters = GetParmeter(dict, parmeters);
|
|
|
+ parmeters = GetParmeter(dict, parmeters, offsetNum, limitNum);
|
|
|
CosmosDbQuery cosmosDbQuery = new CosmosDbQuery
|
|
|
{
|
|
|
QueryText = sql.ToString(),
|
|
@@ -210,10 +221,10 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
|
|
|
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");
|
|
|
+ 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;
|
|
@@ -604,7 +615,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
moreThan = 0, lessThan = 1, notMoreThan = 2, notLessThan = 3, equal = 4, notEqual = 5, like = 6, notLike = 7, IN = 8
|
|
|
}
|
|
|
|
|
|
- private static Dictionary<string, object> GetParmeter(Dictionary<string, object> dict, Dictionary<string, object> parmeters)
|
|
|
+ private static Dictionary<string, object> GetParmeter(Dictionary<string, object> dict, Dictionary<string, object> parmeters,int offset = 0,int limit = 0)
|
|
|
{
|
|
|
foreach (KeyValuePair<string, object> keyValue in dict)
|
|
|
{
|
|
@@ -723,6 +734,12 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
parmeters.Add("@" + key, keyValue.Value);
|
|
|
}
|
|
|
}
|
|
|
+ if (offset != 0 && limit != 0)
|
|
|
+ {
|
|
|
+ parmeters.Add("@offsetNum", offset);
|
|
|
+ parmeters.Add("@limitNum", limit);
|
|
|
+ }
|
|
|
+
|
|
|
return parmeters;
|
|
|
}
|
|
|
|