Przeglądaj źródła

1.提交CosmosDBV3接口调用方法.
2.将验证的CosmosDB封装方法迁移至大云。

CrazyIter 5 lat temu
rodzic
commit
3efaf15f7d

+ 25 - 1
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -30,13 +30,37 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
 
         private string[] ScanModel { get; set; }
         private string[] ScanModel { get; set; }
 
 
+        public AzureCosmosDBV3Repository(AzureCosmosDBOptions options, CosmosSerializer cosmosSerializer)
+        {
+            try
+            {
+                if (!string.IsNullOrEmpty(options.ConnectionString))
+                {
+                    CosmosClient = CosmosDBV3ClientSingleton.getInstance(options.ConnectionString, options.ConnectionKey, cosmosSerializer).GetCosmosDBClient();
+
+                }
+                else
+                {
+                    throw new BizException("请设置正确的AzureCosmosDB数据库配置信息!");
+                }
+                DatabaseId = options.Database;
+                CollectionThroughput = options.CollectionThroughput;
+                ScanModel = options.ScanModel;
+                // InitializeDatabase().GetAwaiter().GetResult();
+            }
+            catch (CosmosException e)
+            {
+                Dispose(true);
+                throw new BizException(e.Message, 500, e.StackTrace);
+            }
+        }
         public AzureCosmosDBV3Repository(AzureCosmosDBOptions options)
         public AzureCosmosDBV3Repository(AzureCosmosDBOptions options)
         {
         {
             try
             try
             {
             {
                 if (!string.IsNullOrEmpty(options.ConnectionString))
                 if (!string.IsNullOrEmpty(options.ConnectionString))
                 {
                 {
-                    CosmosClient = CosmosDBV3ClientSingleton.getInstance(options.ConnectionString, options.ConnectionKey).GetCosmosDBClient();
+                    CosmosClient = CosmosDBV3ClientSingleton.getInstance(options.ConnectionString, options.ConnectionKey, null).GetCosmosDBClient();
 
 
                 }
                 }
                 else
                 else

+ 16 - 2
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3ServiceCollectionExtensions.cs

@@ -1,4 +1,5 @@
-using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Azure.Cosmos;
+using Microsoft.Extensions.DependencyInjection;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
@@ -31,13 +32,26 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 services.AddSingleton<IAzureCosmosDBV3Repository, AzureCosmosDBV3Repository>();
                 services.AddSingleton<IAzureCosmosDBV3Repository, AzureCosmosDBV3Repository>();
                 return builder;
                 return builder;
             }
             }
+
+        
             /// <summary>
             /// <summary>
             /// 
             /// 
             /// </summary>
             /// </summary>
             /// <param name="builder"></param>
             /// <param name="builder"></param>
             /// <param name="_connectionString"></param>
             /// <param name="_connectionString"></param>
             /// <returns></returns>
             /// <returns></returns>
-            public static AzureCosmosDBServiceBuilder AddCosmosDBConnection(this AzureCosmosDBServiceBuilder builder, AzureCosmosDBOptions databaseOptions)
+        public static AzureCosmosDBServiceBuilder AddCosmosDBV3Connection(this AzureCosmosDBServiceBuilder builder, AzureCosmosDBOptions databaseOptions)
+        {
+            builder.Services.AddSingleton(databaseOptions);
+            return builder;
+        }
+        /// <summary>
+        /// CosmosJsonDotNetSerializer  SystemTextJsonCosmosSerializer
+        /// </summary>
+        /// <param name="builder"></param>
+        /// <param name="_connectionString"></param>
+        /// <returns></returns>
+        public static AzureCosmosDBServiceBuilder AddCosmosSerializer(this AzureCosmosDBServiceBuilder builder, CosmosSerializer databaseOptions)
             {
             {
                 builder.Services.AddSingleton(databaseOptions);
                 builder.Services.AddSingleton(databaseOptions);
                 return builder;
                 return builder;

+ 26 - 3
TEAMModelOS.SDK/Module/AzureCosmosDBV3/CosmosDBV3ClientSingleton.cs

@@ -10,6 +10,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
     {
     {
         private static string _connectionUrl;
         private static string _connectionUrl;
         private static string _connectionKey;
         private static string _connectionKey;
+        private static CosmosSerializer _cosmosSerializer;
         private CosmosClient CosmosClient;
         private CosmosClient CosmosClient;
 
 
         private CosmosDBV3ClientSingleton() { }
         private CosmosDBV3ClientSingleton() { }
@@ -24,19 +25,41 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
             }
             else
             else
             {
             {
-                getInstance(_connectionUrl, _connectionKey);
+                getInstance(_connectionUrl, _connectionKey, _cosmosSerializer);
                 return CosmosClient;
                 return CosmosClient;
             }
             }
         }
         }
 
 
-        public static CosmosDBV3ClientSingleton getInstance(string connectionUrl, string connectionKey)
+        public static CosmosDBV3ClientSingleton getInstance(string connectionUrl, string connectionKey, CosmosSerializer cosmosSerializer)
         {
         {
             _connectionUrl = connectionUrl;
             _connectionUrl = connectionUrl;
             _connectionKey = connectionKey;
             _connectionKey = connectionKey;
+            _cosmosSerializer = cosmosSerializer;
+            if (cosmosSerializer != null && cosmosSerializer.GetType() == typeof(SystemTextJsonCosmosSerializer))
+            {
+                return SingletonCustomInstance.instance;
+            }
             return SingletonInstance.instance;
             return SingletonInstance.instance;
         }
         }
 
 
         private static class SingletonInstance
         private static class SingletonInstance
+        {
+            public static CosmosDBV3ClientSingleton instance = new CosmosDBV3ClientSingleton()
+            {
+                // CosmosClient    =new CosmosClient(_connectionUrl, _connectionKey, new CosmosClientOptions() { AllowBulkExecution = true } )
+                CosmosClient = new CosmosClientBuilder(_connectionUrl, _connectionKey).
+                WithBulkExecution(true).WithConnectionModeDirect()
+                //WithConnectionModeDirect().
+                .Build()
+                //CosmosClient = new CosmosClient(_connectionUrl, _connectionKey)
+            };
+            //private static readonly ConnectionPolicy ConnectionPolicy = new ConnectionPolicy
+            //{
+            //    ConnectionMode = ConnectionMode.Direct,
+            //    ConnectionProtocol = Protocol.Tcp
+            //};
+        }
+        private static class SingletonCustomInstance
         {
         {
             public static CosmosDBV3ClientSingleton instance = new CosmosDBV3ClientSingleton()
             public static CosmosDBV3ClientSingleton instance = new CosmosDBV3ClientSingleton()
             {
             {
@@ -44,7 +67,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 CosmosClient = new CosmosClientBuilder(_connectionUrl, _connectionKey).
                 CosmosClient = new CosmosClientBuilder(_connectionUrl, _connectionKey).
                 WithBulkExecution(true).WithConnectionModeDirect().
                 WithBulkExecution(true).WithConnectionModeDirect().
                 //WithConnectionModeDirect().
                 //WithConnectionModeDirect().
-                WithCustomSerializer(new SystemTextJsonCosmosSerializer(new System.Text.Json.JsonSerializerOptions()))
+                WithCustomSerializer(_cosmosSerializer)
                 .Build()
                 .Build()
                 //CosmosClient = new CosmosClient(_connectionUrl, _connectionKey)
                 //CosmosClient = new CosmosClient(_connectionUrl, _connectionKey)
             };
             };

+ 15 - 7
TEAMModelOS.SDK/Module/AzureCosmosDBV3/SQLHelperParametric.cs

@@ -72,6 +72,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 int kslength = 0;
                 int kslength = 0;
                 int logicOperNum = 0;
                 int logicOperNum = 0;
                 bool keyListValueList = true;
                 bool keyListValueList = true;
+                int keyListValueListNum = 0;
                 //string distinctHead = "select distinct value(c) from c ";
                 //string distinctHead = "select distinct value(c) from c ";
 
 
 
 
@@ -107,7 +108,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     string[] keyBody = key.Split("[*]");
                     string[] keyBody = key.Split("[*]");
                     if (keyBody.Length > 1)
                     if (keyBody.Length > 1)
                     {
                     {
-                        key = key.Replace("[*].", "");
+                        key = key.Replace("[*]", "");
                         key = key.Replace(".", "");
                         key = key.Replace(".", "");
 
 
                         kslength += keyBody.Length;
                         kslength += keyBody.Length;
@@ -162,7 +163,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                                         compareOperBool = CompareBoolSwitch(compareOper);
                                         compareOperBool = CompareBoolSwitch(compareOper);
                                         string logicOperString = " and ";
                                         string logicOperString = " and ";
                                         if (logicOperNum != 0) logicOperString = LogicOpers[logicOper];
                                         if (logicOperNum != 0) logicOperString = LogicOpers[logicOper];
-                                        s = logicOperString + "Contains(" + sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + " , \'" + item.Value.ToString() + "\') = " + compareOperBool + " ";
+                                        s = logicOperString + "Contains(" + sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + " , @" + key + " ) = " + compareOperBool + " ";
                                     }
                                     }
                                     else
                                     else
                                     {
                                     {
@@ -181,10 +182,12 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                             }
                             }
                             WhereString.Append(s);
                             WhereString.Append(s);
 
 
-                            if (keyListValueList)
-                            {
-                                sql = sql.Replace("select ", "select distinct ");
-                            }
+                            //if (keyListValueList && keyListValueListNum == 0)
+                            //{
+                            //    sql = sql.Replace("select ", "select distinct ");
+                            //    keyListValueList = false;
+                            //    keyListValueListNum++;
+                            //}
                         }
                         }
                         else
                         else
                         {
                         {
@@ -203,6 +206,11 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     // heada += 1;
                     // heada += 1;
                     logicOperNum += 1;
                     logicOperNum += 1;
                 }
                 }
+                if (keyListValueList)
+                {
+                    sql = sql.Replace("select ", "select distinct ");
+                    keyListValueList = false;
+                }
                 sql.Append(" where 1=1 ").Append(WhereString);
                 sql.Append(" where 1=1 ").Append(WhereString);
                 if (pageBool)
                 if (pageBool)
                 {
                 {
@@ -735,7 +743,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 {
                 {
                     key = key.Replace(".|", "");
                     key = key.Replace(".|", "");
                 }
                 }
-                key = key.Replace("[*].", "");
+                key = key.Replace("[*]", "");
                 key = key.Replace(".", "");
                 key = key.Replace(".", "");
                 if (keyValue.Value is JArray array)
                 if (keyValue.Value is JArray array)
                 {
                 {

+ 2 - 2
TEAMModelOS.SDK/Module/AzureCosmosDBV3/SystemTextJsonCosmosSerializer.cs

@@ -8,11 +8,11 @@ using System.Threading.Tasks;
 
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 {
 {
-    internal sealed class SystemTextJsonCosmosSerializer : CosmosSerializer
+    public class SystemTextJsonCosmosSerializer : CosmosSerializer
     {
     {
         private readonly JsonSerializerOptions _options;
         private readonly JsonSerializerOptions _options;
 
 
-        internal SystemTextJsonCosmosSerializer(JsonSerializerOptions options)
+        public SystemTextJsonCosmosSerializer(JsonSerializerOptions options)
         {
         {
             _options = options;
             _options = options;
         }
         }

+ 1 - 1
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -24,7 +24,7 @@
     <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.9.2" />
     <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.9.2" />
     <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
     <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
     <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0" />
     <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0" />
-    <PackageReference Include="Scrutor" Version="3.1.0" />
+    <PackageReference Include="Scrutor" Version="3.2.0" />
     <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
     <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
     <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.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" />

+ 2 - 1
TEAMModelOS.Service/Models/Core/Classroom.cs

@@ -3,11 +3,12 @@ using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Service.Models.Core
 namespace TEAMModelOS.Service.Models.Core
 {
 {
     [CosmosDB(RU = 400, Name = "CoreClassroom")]
     [CosmosDB(RU = 400, Name = "CoreClassroom")]
-    public class Classroom
+    public class Classroom:ID
     {
     {
         public Classroom()
         public Classroom()
         {
         {

+ 2 - 1
TEAMModelOS.Service/Models/Core/School.cs

@@ -2,11 +2,12 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Service.Models.Core
 namespace TEAMModelOS.Service.Models.Core
 {
 {
     [CosmosDB(RU = 400, Name = "CoreSchool")]
     [CosmosDB(RU = 400, Name = "CoreSchool")]
-    public class School
+    public class School:ID
     {
     {
         public School()
         public School()
         {
         {

+ 2 - 1
TEAMModelOS.Service/Models/Core/Student.cs

@@ -5,11 +5,12 @@ using System.ComponentModel.DataAnnotations;
 using System.Text;
 using System.Text;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Service.Models.Core
 namespace TEAMModelOS.Service.Models.Core
 {
 {
     [CosmosDB(RU = 400, Name = "CoreStudent")]
     [CosmosDB(RU = 400, Name = "CoreStudent")]
-    public class Student
+    public class Student :ID
     {
     {
    public Student()
    public Student()
     {
     {

+ 2 - 1
TEAMModelOS.Service/Models/Core/Teacher.cs

@@ -5,11 +5,12 @@ using System.ComponentModel.DataAnnotations;
 using System.Text;
 using System.Text;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Service.Models.Core
 namespace TEAMModelOS.Service.Models.Core
 {
 {
     [CosmosDB(RU = 400, Name = "CoreTeacher")]
     [CosmosDB(RU = 400, Name = "CoreTeacher")]
-    public class Teacher
+    public class Teacher:ID
     {
     {
         public string id { get; set; }
         public string id { get; set; }
         /// <summary>
         /// <summary>

+ 5 - 4
TEAMModelOS/Controllers/Core/ClassRoomController.cs

@@ -8,6 +8,7 @@ using TEAMModelOS.SDK.Context.Exception;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Controllers.Syllabus
 namespace TEAMModelOS.Controllers.Syllabus
 {
 {
@@ -15,8 +16,8 @@ namespace TEAMModelOS.Controllers.Syllabus
     [ApiController]
     [ApiController]
     public  class ClassroomController : BaseController
     public  class ClassroomController : BaseController
     {
     {
-        public readonly IAzureCosmosDBRepository cosmosrepository;
-        public ClassroomController(IAzureCosmosDBRepository _cosmosrepository) {
+        public readonly IAzureCosmosDBV3Repository cosmosrepository;
+        public ClassroomController(IAzureCosmosDBV3Repository _cosmosrepository) {
             cosmosrepository = _cosmosrepository;
             cosmosrepository = _cosmosrepository;
         }
         }
         [HttpPost("SaveOrUpdate")]
         [HttpPost("SaveOrUpdate")]
@@ -26,7 +27,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             
             
             if (request.@params.id != null)
             if (request.@params.id != null)
             {
             {
-                await cosmosrepository.ReplaceObject(request.@params, request.@params.id, request.@params.schoolCode);
+                await cosmosrepository.Update(request.@params);
 
 
             }
             }
             else
             else
@@ -42,7 +43,7 @@ namespace TEAMModelOS.Controllers.Syllabus
         public async Task<BaseJosnRPCResponse> FindClassInfo(JosnRPCRequest<Dictionary<string, object>> request)
         public async Task<BaseJosnRPCResponse> FindClassInfo(JosnRPCRequest<Dictionary<string, object>> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            List<Classroom> sc = await cosmosrepository.FindByDict<Classroom>(request.@params,true);
+            List<Classroom> sc = await cosmosrepository.FindByDict<Classroom>(request.@params);
             //sc.First11
             //sc.First11
             return builder.Data(sc).build();
             return builder.Data(sc).build();
         }
         }

+ 7 - 6
TEAMModelOS/Controllers/Core/CommonController.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 using static System.Text.Json.JsonElement;
 using static System.Text.Json.JsonElement;
 
 
 namespace TEAMModelOS.Controllers.Syllabus
 namespace TEAMModelOS.Controllers.Syllabus
@@ -25,9 +26,9 @@ namespace TEAMModelOS.Controllers.Syllabus
     public class CommonController : BaseController
     public class CommonController : BaseController
     {
     {
 
 
-        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
+        private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
         private readonly IWebHostEnvironment webHostEnvironment;
         private readonly IWebHostEnvironment webHostEnvironment;
-        public CommonController(IWebHostEnvironment _webHostEnvironment, IAzureCosmosDBRepository _azureCosmosDBRepository)
+        public CommonController(IWebHostEnvironment _webHostEnvironment, IAzureCosmosDBV3Repository _azureCosmosDBRepository)
         {
         {
             webHostEnvironment = _webHostEnvironment;
             webHostEnvironment = _webHostEnvironment;
             azureCosmosDBRepository = _azureCosmosDBRepository;
             azureCosmosDBRepository = _azureCosmosDBRepository;
@@ -133,20 +134,20 @@ namespace TEAMModelOS.Controllers.Syllabus
         }
         }
 
 
         [HttpPost("FindCollection")]
         [HttpPost("FindCollection")]
-        public  BaseJosnRPCResponse FindCollection(JosnRPCRequest<CommonQuery> request)
+        public async  Task<BaseJosnRPCResponse> FindCollection(JosnRPCRequest<CommonQuery> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            IQueryable<dynamic>  data =   azureCosmosDBRepository.FindByDict(request.@params.collectionName,request.@params.queryDict);
+            List<dynamic>  data =  await  azureCosmosDBRepository.FindByDict(request.@params.collectionName,request.@params.queryDict);
            // JsonElement json = JsonApiHelper.FromApiJson<JsonElement>( data.ToJson());
            // JsonElement json = JsonApiHelper.FromApiJson<JsonElement>( data.ToJson());
             return builder.Data(data).build();
             return builder.Data(data).build();
         }
         }
 
 
 
 
         [HttpPost("FindCollectionCount")]
         [HttpPost("FindCollectionCount")]
-        public BaseJosnRPCResponse FindCollectionCount(JosnRPCRequest<CommonQuery> request)
+        public async Task<BaseJosnRPCResponse> FindCollectionCount(JosnRPCRequest<CommonQuery> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            IQueryable<dynamic> data = azureCosmosDBRepository.FindCountByDict(request.@params.collectionName, request.@params.queryDict);
+            List<dynamic> data = await  azureCosmosDBRepository.FindCountByDict(request.@params.collectionName, request.@params.queryDict);
             return builder.Data(data).build();
             return builder.Data(data).build();
         }
         }
     }
     }

+ 4 - 3
TEAMModelOS/Controllers/Core/LoginController.cs

@@ -18,6 +18,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
 using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
 using TEAMModelOS.Service.Models.Core;
 using TEAMModelOS.Service.Models.Core;
 
 
@@ -28,9 +29,9 @@ namespace TEAMModelOS.Controllers.Core
     public class LoginController :BaseController
     public class LoginController :BaseController
     {
     {
         private readonly IAzureTableDBRepository azureTableDBRepository;
         private readonly IAzureTableDBRepository azureTableDBRepository;
-        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
+        private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
         private readonly IOptions<JwtSetting> options;
         private readonly IOptions<JwtSetting> options;
-        public LoginController(IAzureTableDBRepository _azureTableDBRepository, IAzureCosmosDBRepository _azureCosmosDBRepository, IOptions<JwtSetting> _options)
+        public LoginController(IAzureTableDBRepository _azureTableDBRepository, IAzureCosmosDBV3Repository _azureCosmosDBRepository, IOptions<JwtSetting> _options)
         {
         {
             azureTableDBRepository = _azureTableDBRepository;
             azureTableDBRepository = _azureTableDBRepository;
             azureCosmosDBRepository = _azureCosmosDBRepository;
             azureCosmosDBRepository = _azureCosmosDBRepository;
@@ -104,7 +105,7 @@ namespace TEAMModelOS.Controllers.Core
                     Ticket = ticketInfo.Ticket,
                     Ticket = ticketInfo.Ticket,
                     CountryCode = "86"
                     CountryCode = "86"
                 };
                 };
-                List<Teacher> users = await azureCosmosDBRepository.FindByDict<Teacher>(new Dictionary<string, object>() { { "TEAMModelId", ticketInfo.TEAMModelId } }, true);
+                List<Teacher> users = await azureCosmosDBRepository.FindByDict<Teacher>(new Dictionary<string, object>() { { "TEAMModelId", ticketInfo.TEAMModelId } });
                 Teacher user;
                 Teacher user;
                 if (users.IsEmpty())
                 if (users.IsEmpty())
                 {
                 {

+ 4 - 3
TEAMModelOS/Controllers/Core/SchoolController.cs

@@ -8,6 +8,7 @@ using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Controllers.Syllabus
 namespace TEAMModelOS.Controllers.Syllabus
 {
 {
@@ -16,8 +17,8 @@ namespace TEAMModelOS.Controllers.Syllabus
     public class SchoolController : Controller
     public class SchoolController : Controller
     {
     {
 
 
-        public IAzureCosmosDBRepository _cosmosrepository;
-        public SchoolController(IAzureCosmosDBRepository cosmosDBRepository)
+        public IAzureCosmosDBV3Repository _cosmosrepository;
+        public SchoolController(IAzureCosmosDBV3Repository cosmosDBRepository)
         {
         {
             _cosmosrepository = cosmosDBRepository;
             _cosmosrepository = cosmosDBRepository;
         }
         }
@@ -44,7 +45,7 @@ namespace TEAMModelOS.Controllers.Syllabus
         public async Task<BaseJosnRPCResponse> FindSchool(JosnRPCRequest<Dictionary<string, object>> request)
         public async Task<BaseJosnRPCResponse> FindSchool(JosnRPCRequest<Dictionary<string, object>> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            List<School> sc = await _cosmosrepository.FindByDict<School>(request.@params,true); 
+            List<School> sc = await _cosmosrepository.FindByDict<School>(request.@params); 
             return builder.Data(sc).build();
             return builder.Data(sc).build();
         }
         }
     }
     }

+ 13 - 15
TEAMModelOS/Controllers/Core/StudentController.cs

@@ -13,6 +13,7 @@ using System.Text.Json;
 using TEAMModelOS.Models;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.Extension.SnowFlake;
 using TEAMModelOS.SDK.Extension.SnowFlake;
 using TEAMModelOS.SDK.Helper.Security.TmdCrypt;
 using TEAMModelOS.SDK.Helper.Security.TmdCrypt;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 
 namespace TEAMModelOS.Controllers.Syllabus
 namespace TEAMModelOS.Controllers.Syllabus
 {
 {
@@ -21,8 +22,8 @@ namespace TEAMModelOS.Controllers.Syllabus
     // [Authorize]
     // [Authorize]
     public class StudentController : BaseController
     public class StudentController : BaseController
     {
     {
-        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
-        public StudentController(IAzureCosmosDBRepository _azureCosmosDBRepository)
+        private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
+        public StudentController(IAzureCosmosDBV3Repository _azureCosmosDBRepository)
         {
         {
             azureCosmosDBRepository = _azureCosmosDBRepository;
             azureCosmosDBRepository = _azureCosmosDBRepository;
         }
         }
@@ -57,7 +58,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             if (request.@params.TryGetValue("schoolCode", out object _))
             if (request.@params.TryGetValue("schoolCode", out object _))
             {
             {
-                List<Student> data = await azureCosmosDBRepository.FindByDict<Student>(request.@params,false);
+                List<Student> data = await azureCosmosDBRepository.FindByDict<Student>(request.@params);
                 return builder.Data(data).build();
                 return builder.Data(data).build();
             }
             }
             else
             else
@@ -77,7 +78,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             List<Student> students = new List<Student>();
             List<Student> students = new List<Student>();
             foreach (string key in dictInfo.Keys)
             foreach (string key in dictInfo.Keys)
             {
             {
-                List<Classroom> classrooms = await azureCosmosDBRepository.FindByDict<Classroom>(new Dictionary<string, object> { { "classroomCode", key } } ,true);
+                List<Classroom> classrooms = await azureCosmosDBRepository.FindByDict<Classroom>(new Dictionary<string, object> { { "classroomCode", key } } );
                 if (classrooms.IsNotEmpty())
                 if (classrooms.IsNotEmpty())
                 {
                 {
                     long createDate = DateTimeOffset.UtcNow.Ticks;
                     long createDate = DateTimeOffset.UtcNow.Ticks;
@@ -131,16 +132,12 @@ namespace TEAMModelOS.Controllers.Syllabus
             return builder.Data(data).build();
             return builder.Data(data).build();
         }
         }
         [HttpPost("UpdateAllStudent")]
         [HttpPost("UpdateAllStudent")]
-        public async Task<BaseJosnRPCResponse> UpdateAllStudent(JosnRPCRequest<Dictionary<string, Dictionary<string, object>>> request)
+        public async Task<BaseJosnRPCResponse> UpdateAllStudent(JosnRPCRequest<List<Student>> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            bool find = request.@params.TryGetValue("find", out Dictionary<string, object> findObj);
-            bool update = request.@params.TryGetValue("update", out Dictionary<string, object> updateObj);
-            List<Student> data = null;
-            if (find && update)
-            {
-                data = await azureCosmosDBRepository.UpdateAll<Student>(findObj, updateObj);
-            }
+            //bool find = request.@params.TryGetValue("find", out Dictionary<string, object> findObj);
+            //bool update = request.@params.TryGetValue("update", out Dictionary<string, object> updateObj);
+            List<Student> data = await azureCosmosDBRepository.UpdateAll<Student>(request.@params);
             return builder.Data(data).build();
             return builder.Data(data).build();
         }
         }
         /// <summary>
         /// <summary>
@@ -152,7 +149,7 @@ namespace TEAMModelOS.Controllers.Syllabus
         public async Task<BaseJosnRPCResponse> DeleteStudentInfo(JosnRPCRequest<Student> request)
         public async Task<BaseJosnRPCResponse> DeleteStudentInfo(JosnRPCRequest<Student> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            string data = await azureCosmosDBRepository.DeleteAsync<Student>(request.@params.id, request.@params.schoolCode);
+            Student data = await azureCosmosDBRepository.DeleteAsync<Student>(request.@params.id, request.@params.schoolCode);
             return builder.Data(data).build();
             return builder.Data(data).build();
         }  /// <summary>
         }  /// <summary>
            /// 根据ID删除
            /// 根据ID删除
@@ -163,8 +160,9 @@ namespace TEAMModelOS.Controllers.Syllabus
         public async Task<BaseJosnRPCResponse> DeleteStudentInfo(JosnRPCRequest<Dictionary<string,object>> request)
         public async Task<BaseJosnRPCResponse> DeleteStudentInfo(JosnRPCRequest<Dictionary<string,object>> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            List<Student> data = await azureCosmosDBRepository.DeleteAll<Student>(request.@params);
-            return builder.Data(data).build();
+            List<Student> students= await azureCosmosDBRepository.FindByDict<Student>(request.@params);
+             await azureCosmosDBRepository.DeleteAll<Student>(students);
+            return builder.build();
         }
         }
     }
     }
 }
 }

+ 6 - 1
TEAMModelOS/Startup.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.IdentityModel.Tokens.Jwt;
 using System.IdentityModel.Tokens.Jwt;
 using System.Linq;
 using System.Linq;
 using System.Reflection;
 using System.Reflection;
+using System.Text.Json;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Authentication.JwtBearer;
 using Microsoft.AspNetCore.Authentication.JwtBearer;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Builder;
@@ -20,6 +21,7 @@ using TEAMModelOS.SDK.Context.Filter;
 using TEAMModelOS.SDK.Extension.JwtAuth;
 using TEAMModelOS.SDK.Extension.JwtAuth;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 using TEAMModelOS.SDK.Module.AzureTable.Implements;
 using TEAMModelOS.SDK.Module.AzureTable.Implements;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
 using VueCliMiddleware;
 using VueCliMiddleware;
@@ -108,13 +110,16 @@ namespace TEAMModelOS
             //使用Blob配置
             //使用Blob配置
             services.AddAzureBlobStorage().AddConnection(Configuration.GetSection("Azure:Blob").Get<AzureBlobOptions>());
             services.AddAzureBlobStorage().AddConnection(Configuration.GetSection("Azure:Blob").Get<AzureBlobOptions>());
             //使用CosmosDB
             //使用CosmosDB
-            services.AddAzureCosmosDB().AddCosmosDBConnection(Configuration.GetSection("Azure:CosmosDB").Get<AzureCosmosDBOptions>());
+            services.AddAzureCosmosDBV3().AddCosmosDBV3Connection(Configuration.GetSection("Azure:CosmosDB").Get<AzureCosmosDBOptions>())
+                .AddCosmosSerializer(new SystemTextJsonCosmosSerializer(new JsonSerializerOptions()));
             //HttpContextAccessor,并用来访问HttpContext。
             //HttpContextAccessor,并用来访问HttpContext。
             services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
             services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
             //引入Jwt配置
             //引入Jwt配置
             services.JwtAuth(Configuration.GetSection("JwtSetting"));
             services.JwtAuth(Configuration.GetSection("JwtSetting"));
 
 
             //services.AddSingleton<PowerPointService, PowerPointService>();
             //services.AddSingleton<PowerPointService, PowerPointService>();
+
+
             //全局扫描基于IBusinessService接口的实现类
             //全局扫描基于IBusinessService接口的实现类
             services.Scan(scan => scan.FromApplicationDependencies()
             services.Scan(scan => scan.FromApplicationDependencies()
                .AddClasses(classes => classes.AssignableTo<IBusinessService>())
                .AddClasses(classes => classes.AssignableTo<IBusinessService>())