瀏覽代碼

升级AzureTable

CrazyIter 5 年之前
父節點
當前提交
1e85eabfb4

+ 1 - 1
TEAMModelOS.SDK/Extension/Language/LanguageExtension.cs

@@ -12,7 +12,7 @@ namespace TEAMModelOS.SDK.Extension.Language
         public static void AddLanguage(this IServiceCollection services, IConfigurationSection LangConfiguration)
         {
             services.Configure<List<SmsCountryCode>>(LangConfiguration);
-            services.AddSingleton<ILanguageService, LanguageService>();
+            services.AddScoped<ILanguageService, LanguageService>();
         }
     }
 }

+ 1 - 1
TEAMModelOS.SDK/Extension/MessagePush/MessagePushExtension.cs

@@ -14,7 +14,7 @@ namespace TEAMModelOS.SDK.Extension.MessagePush
         public static void SendCloud(this IServiceCollection services, IConfigurationSection configuration)
         {
             services.Configure<SmsSendCloud>(configuration);
-            services.AddSingleton<ISendCloudService, SendCloudService>();
+            services.AddScoped<ISendCloudService, SendCloudService>();
         }
     }
 }

+ 2 - 2
TEAMModelOS.SDK/Helper/Common/JsonHelper/JsonApiHelper.cs

@@ -16,12 +16,12 @@ namespace TEAMModelOS.SDK.Helper.Common.JsonHelper
             PropertyNameCaseInsensitive = true,                     //忽略大小写
             //PropertyNamingPolicy = JsonNamingPolicy.CamelCase     //命名方式是默认还是CamelCase
         };
-        public static string ToJson(this object input)
+        public static string ToApiJson(this object input)
         {
             return JsonSerializer.Serialize(input, options);
         }
 
-        public static T FromJson<T>(this string input)
+        public static T FromApiJson<T>(this string input)
         {
             return JsonSerializer.Deserialize<T>(input, options);
         }

+ 52 - 12
TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs

@@ -27,6 +27,7 @@ using System.Collections.Concurrent;
 using DataType = Microsoft.Azure.Documents.DataType;
 using RequestOptions = Microsoft.Azure.Documents.Client.RequestOptions;
 using PartitionKey = Microsoft.Azure.Documents.PartitionKey;
+using Newtonsoft.Json.Linq;
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 { /// <summary>
@@ -668,19 +669,58 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 
         private static string GenSql(object obj, string key)
         {
-            Type s = obj.GetType();
-            TypeCode typeCode = Type.GetTypeCode(s);
-            return typeCode switch
+
+            if (obj is JArray array)
             {
-                TypeCode.String => " and c." + key + "=" + "'" + obj.ToString() + "'",
-                TypeCode.Int32 => " and c." + key + "=" + int.Parse(obj.ToString()),
-                TypeCode.Double => " and c." + key + "=" + double.Parse(obj.ToString()),
-                //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
-                TypeCode.Boolean => " and c." + key + "=" + bool.Parse(obj.ToString()),
-                TypeCode.DateTime => " and c." + key + "=" + (DateTime)obj,
-                TypeCode.Int64 => " and c." + key + "=" + long.Parse(obj.ToString()),
-                _ => null,
-            };
+                StringBuilder sql = new StringBuilder(" and  c." + key + " in (");
+                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 {
+                Type s = obj.GetType();
+                TypeCode typeCode = Type.GetTypeCode(s);
+
+                return typeCode switch
+                {
+                    TypeCode.String => " and c." + key + "=" + "'" + obj.ToString() + "'",
+                    TypeCode.Int32 => " and c." + key + "=" + int.Parse(obj.ToString()),
+                    TypeCode.Double => " and c." + key + "=" + double.Parse(obj.ToString()),
+                    //case TypeCode.Byte: return "and c." + key + "=" + (Byte)obj ;   
+                    TypeCode.Boolean => " and c." + key + "=" + bool.Parse(obj.ToString()),
+                    TypeCode.DateTime => " and c." + key + "=" + (DateTime)obj,
+                    TypeCode.Int64 => " and c." + key + "=" + long.Parse(obj.ToString()),
+                    _ => null,
+                };
+            }
+            
         }
 
         public  IQueryable<dynamic> FindByDict(string CollectionName,  Dictionary<string, object> dict)

+ 0 - 12
TEAMModelOS.SDK/Module/AzureTable/Configuration/AzureTableConfig.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace TEAMModelOS.SDK.Module.AzureTable.Configuration
-{
-    public class AzureTableConfig
-    {
-        public readonly static string AZURE_CHINA = "AzureChina";
-        public readonly static string AZURE_GLOBAL = "AzureGlobal";
-    }
-}

+ 0 - 22
TEAMModelOS.SDK/Module/AzureTable/Configuration/AzureTableServiceBuilder.cs

@@ -1,22 +0,0 @@
-using Microsoft.Extensions.DependencyInjection;
-using System;
-
-namespace TEAMModelOS.SDK.Module.AzureTable.Configuration
-{
-    public class AzureTableServiceBuilder : ServiceCollection
-    {
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="services"></param>
-        public AzureTableServiceBuilder(IServiceCollection services)
-        {
-            Services = services ?? throw new ArgumentNullException(nameof(services));
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public IServiceCollection Services { get; }
-    }
-}

+ 0 - 50
TEAMModelOS.SDK/Module/AzureTable/Configuration/AzureTableServiceCollectionExtensions.cs

@@ -1,50 +0,0 @@
-using TEAMModelOS.SDK.Module.AzureTable.Implements;
-using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
-using Microsoft.Extensions.DependencyInjection;
-using System;
-
-namespace TEAMModelOS.SDK.Module.AzureTable.Configuration
-{
-    public static class AzureTableServiceCollectionExtensions
-    {
-        public static AzureTableServiceBuilder Builder { get; set; }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="services"></param>
-        /// <returns></returns>
-        private static AzureTableServiceBuilder AddServerBuilder(this IServiceCollection services)
-        {
-            return new AzureTableServiceBuilder(services);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="services"></param>
-        /// <returns></returns>
-        public static AzureTableServiceBuilder AddAzureTableStorage(this IServiceCollection services)
-        {
-            if (Builder == null)
-            {
-                Builder = services.AddServerBuilder();
-            }
-            services.AddSingleton<IAzureTableDBRepository, AzureTableDBRepository>();
-            return Builder;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="builder"></param>
-        /// <param name="_connectionString"></param>
-        /// <returns></returns>
-        public static AzureTableServiceBuilder AddConnection(this AzureTableServiceBuilder builder, AzureTableOptions databaseOptions)
-        {
-            builder.Services.AddSingleton(databaseOptions);
-            return builder;
-        }
-        
-    }
-}

+ 0 - 35
TEAMModelOS.SDK/Module/AzureTable/Configuration/TableClientSingleton.cs

@@ -1,35 +0,0 @@
-using Microsoft.Azure.Cosmos.Table;
-
-namespace TEAMModelOS.SDK.Module.AzureTable.Configuration
-{
-    public sealed class TableClientSingleton
-    {
-        private static string _connectionString;
-        private CloudTableClient TableClient;
-        private TableClientSingleton() { }
-        public CloudTableClient GetTableClient()
-        {
-            if (TableClient != null)
-            {
-                return TableClient;
-            }
-            else
-            {
-                getInstance(_connectionString);
-                return TableClient;
-            }
-        }
-        public static TableClientSingleton getInstance(string connectionString)
-        {
-            _connectionString = connectionString;
-            return SingletonInstance.instance;
-        }
-        private static class SingletonInstance
-        {
-            public static TableClientSingleton instance = new TableClientSingleton()
-            {
-                TableClient = CloudStorageAccount.Parse(_connectionString).CreateCloudTableClient()
-            };
-        }
-    }
-}

+ 4 - 3
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -2,7 +2,10 @@
 
   <PropertyGroup>
     <TargetFramework>netcoreapp3.1</TargetFramework>
-    <Version>2.0.0</Version>
+    <Version>2.0.3</Version>
+    <AssemblyVersion>2.0.0.3</AssemblyVersion>
+    <FileVersion>2.0.0.3</FileVersion>
+    <PackageReleaseNotes>jsonapi</PackageReleaseNotes>
   </PropertyGroup>
 
   <ItemGroup>
@@ -24,9 +27,7 @@
     <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
     <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
     <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
-  <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
     <PackageReference Include="XC.Framework.Security.RSAUtil" Version="1.0.1" />
     <PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="2.0.0-preview" />
   </ItemGroup>
-
 </Project>

+ 8 - 0
TEAMModelOS.Service/Models/Syllabus/SyllabusNode.cs

@@ -7,6 +7,11 @@ namespace TEAMModelOS.Service.Models.Syllabus
     [CosmosDB(RU = 400, Name = "SyllabusNode")]
     public class SyllabusNode
     {
+
+        public SyllabusNode() {
+            resources = new List<string>();
+            knowledges = new List<string>();
+        }
         /// <summary>
         /// 
         /// </summary>
@@ -70,5 +75,8 @@ namespace TEAMModelOS.Service.Models.Syllabus
         /// </summary>
         [Required(ErrorMessage = "{0} 必须填写")]
         public int status { get; set; } = 1;
+        public List<string> resources { get; set; }
+        public List<string> knowledges { get; set; }
+        
     }
 }

+ 1 - 0
TEAMModelOS/Models/CommonQuery.cs

@@ -9,5 +9,6 @@ namespace TEAMModelOS.Models
     {
         public string collectionName { get; set; }
         public Dictionary<string ,object> queryDict { get; set; }
+      
     }
 }