JsonQueryableProvider.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Linq;
  6. namespace SqlSugar
  7. {
  8. /// <summary>
  9. /// JsonQueryableProvider
  10. /// </summary>
  11. public partial class JsonQueryableProvider : IJsonQueryableProvider<JsonQueryResult>
  12. {
  13. public JsonQueryableProvider(ISqlSugarClient context, JObject jobject)
  14. {
  15. this.jobject = jobject;
  16. this.context = context;
  17. this.jsonCommonProvider = new JsonCommonProvider(context);
  18. }
  19. public IJsonQueryableProvider<JsonQueryResult> ShowDesciption()
  20. {
  21. this.IsDescription = true;
  22. return this;
  23. }
  24. public IJsonQueryableProvider<JsonQueryResult> UseAuthentication(JsonTableConfig config)
  25. {
  26. if (config == null)
  27. {
  28. jsonTableConfigs =new List<JsonTableConfig>() { config };
  29. }
  30. else
  31. {
  32. jsonTableConfigs.Add(config);
  33. }
  34. return this;
  35. }
  36. public IJsonQueryableProvider<JsonQueryResult> UseAuthentication(List<JsonTableConfig> configs)
  37. {
  38. foreach (JsonTableConfig config in configs)
  39. {
  40. UseAuthentication(config);
  41. }
  42. return this;
  43. }
  44. public SqlObjectResult ToSql()
  45. {
  46. return this.ToSqlList().First();
  47. }
  48. public JsonQueryResult ToResult()
  49. {
  50. return ToResultDefault();
  51. }
  52. public List<SqlObjectResult> ToSqlList()
  53. {
  54. var result = ToSqlDefault();
  55. return result;
  56. }
  57. public List<string> ToSqlString()
  58. {
  59. throw new NotImplementedException();
  60. }
  61. private void AppendQueryableAll(JsonQueryParameter jsonQueryParameter, JToken item)
  62. {
  63. SetQueryableParameterIndex();
  64. var name = item.Path.ToLower();
  65. if (IsForm(name))
  66. {
  67. AppendFrom(item);
  68. }
  69. else if (IsWhere(name))
  70. {
  71. AppendWhere(item);
  72. }
  73. else if (IsOrderBy(name))
  74. {
  75. AppendOrderBy(item);
  76. }
  77. else if (IsJoinLastAfter(name))
  78. {
  79. ApendJoinLastAfter(item);
  80. }
  81. else if (IsGroupBy(name))
  82. {
  83. AppendGroupBy(item);
  84. }
  85. else if (IsHaving(name))
  86. {
  87. AppendHaving(item);
  88. }
  89. else if (IsSelect(name))
  90. {
  91. jsonQueryParameter.IsSelect = AppendSelect(item);
  92. }
  93. else if (IsPageNumber(name))
  94. {
  95. jsonQueryParameter.PageIndex = AppendPageNumber(item);
  96. }
  97. else if (IsPageSize(name))
  98. {
  99. jsonQueryParameter.PageSize = AppendPageSize(item);
  100. }
  101. else if (IsJoin(name))
  102. {
  103. jsonQueryParameter.IsSelect = AppendJoin(item);
  104. }
  105. }
  106. private void SetQueryableParameterIndex()
  107. {
  108. ((SqlBuilderProvider)sugarQueryable.SqlBuilder).GetParameterNameIndex = jsonCommonProvider.ParameterIndex;
  109. }
  110. }
  111. }