Browse Source

处理CosmosV3接口方法注入的问题

CrazyIter 5 năm trước cách đây
mục cha
commit
16c78a98dd

+ 8 - 5
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -26,7 +26,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
         private string DatabaseId { get; set; }
         private int CollectionThroughput { get; set; }
-        private Database database = null;
+        private Database database { get; set; }
 
         private string[] ScanModel { get; set; }
 
@@ -330,7 +330,8 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
                 //};
                 StringBuilder sql = new StringBuilder("select value(c) from c");
-                CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict, sql);
+                SQLHelper.GetSQL(dict, ref sql);
+                CosmosDbQuery cosmosDbQuery = new CosmosDbQuery { QueryText = sql.ToString() };
                 QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(itemsPerPage, maxItemCount));
                 FeedIterator<dynamic> query = container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
                 return await ResultsFromFeedIterator(query, maxItemCount);
@@ -354,7 +355,8 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
                 //};
                 StringBuilder sql = new StringBuilder("select  value count(c)  from c");
-                CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict, sql);
+                SQLHelper.GetSQL(dict, ref sql);
+                CosmosDbQuery cosmosDbQuery = new CosmosDbQuery { QueryText = sql.ToString() };
                 QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(itemsPerPage, maxItemCount));
                 FeedIterator<dynamic> query = container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
                 return await ResultsFromFeedIterator(query, maxItemCount);
@@ -373,8 +375,9 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         {
 
             StringBuilder sql = new StringBuilder("select value(c) from c");
-            CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict,sql);
-            QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(itemsPerPage, maxItemCount));
+             SQLHelper.GetSQL(dict,ref sql);
+            CosmosDbQuery cosmosDbQuery = new CosmosDbQuery { QueryText = sql.ToString() };
+           QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(itemsPerPage, maxItemCount));
             return await ResultsFromQueryAndOptions<T>(cosmosDbQuery, queryRequestOptions);
         }
 

+ 3 - 2
TEAMModelOS.Service/Models/Evaluation/Models/ExamAnswer.cs

@@ -3,18 +3,19 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
     [CosmosDB(RU = 400, Name = "ExamAnswer")]
-    public class ExamAnswer
+    public class ExamAnswer :ID
     {
         public ExamAnswer()
         {
             Answer = new List<List<string>>();
         }
         [JsonProperty(PropertyName = "id")]
-        public string Id { get; set; }
+        public string id { get; set; }
         [PartitionKey]
         public string Code { get; set; }
         public List<List<string>> Answer { get; set; }

+ 3 - 2
TEAMModelOS.Service/Models/Evaluation/Models/ExamInfo.cs

@@ -3,18 +3,19 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
     [CosmosDB(RU = 400, Name = "ExamInfo")]
-    public class ExamInfo
+    public class ExamInfo :ID
     {
         public ExamInfo() {
 
             Conditions = new Condition();
         }
         [JsonProperty(PropertyName = "id")]
-        public string Id { get; set; }
+        public string id { get; set; }
         [PartitionKey]
         public string Code { get; set; }
         public string Name { get; set; }

+ 3 - 2
TEAMModelOS.Service/Models/Evaluation/Models/ExamPaper.cs

@@ -3,17 +3,18 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Evaluation.Models
 {
     [CosmosDB(RU = 400, Name = "ExamPaper")]
-    public class ExamPaper
+    public class ExamPaper :ID
     {
         public ExamPaper() {
             item = new List<ItemInfo>();
         }
         [JsonProperty(PropertyName = "id")]
-        public string Id { get; set; }
+        public string id { get; set; }
         [PartitionKey]
         public string code { get; set; }
         public List<ItemInfo> item { get; set; }       

+ 3 - 2
TEAMModelOS.Service/Models/Evaluation/Models/SimpleExam.cs

@@ -3,11 +3,12 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Model.Evaluation.Models
 {
     [CosmosDB(RU = 400, Name = "SimpleExam")]
-    public class SimpleExam
+    public class SimpleExam :ID
     {
         public SimpleExam()
         {
@@ -17,7 +18,7 @@ namespace TEAMModelOS.Service.Model.Evaluation.Models
             Point = new List<int>();
         }
         [JsonProperty(PropertyName = "id")]
-        public string Id { get; set; }
+        public string id { get; set; }
         public string Name { get; set; }
         public string Time { get; set; }
         [PartitionKey]

+ 2 - 1
TEAMModelOS.Service/Models/Syllabus/SyllabusNode.cs

@@ -1,11 +1,12 @@
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Syllabus
 {
     [CosmosDB(RU = 400, Name = "SyllabusNode")]
-    public class SyllabusNode
+    public class SyllabusNode:ID
     {
 
         public SyllabusNode() {

+ 2 - 1
TEAMModelOS.Service/Models/Syllabus/SyllabusVolume.cs

@@ -5,11 +5,12 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 using System.Text.Json.Serialization;
 using System.ComponentModel.DataAnnotations;
 using Newtonsoft.Json;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Models.Syllabus
 {
     [CosmosDB(RU = 400, Name = "SyllabusVolume")]
-    public class SyllabusVolume
+    public class SyllabusVolume :ID
     { 
         /// <summary>
         /// id生成规则

+ 3 - 2
TEAMModelOS.Service/Services/Analysis/Implements/AchievementService.cs

@@ -6,14 +6,15 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.Service.Analysis.Interfaces;
 using TEAMModelOS.Service.Models.Core;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Service.Analysis.Implements
 {
     public class AchievementService : IAchievementService
     {
-        public IAzureCosmosDBRepository _cosmosrepository;
+        public IAzureCosmosDBV3Repository _cosmosrepository;
 
-        public AchievementService(IAzureCosmosDBRepository cosmosDBRepository)
+        public AchievementService(IAzureCosmosDBV3Repository cosmosDBRepository)
         {
             _cosmosrepository = cosmosDBRepository;
         }

+ 11 - 10
TEAMModelOS/Controllers/Analysis/AchievementController.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.Service.Analysis.Interfaces;
 
 using TEAMModelOS.Service.Models.Core;
 using TEAMModelOS.Service.Models.Evaluation.Models;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Controllers.Analysis
 {
@@ -23,9 +24,9 @@ namespace TEAMModelOS.Controllers.Analysis
     public class AchievementController : Controller
     {
 
-        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
+        private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
         private readonly IAchievementService achievementService;
-        public AchievementController(IAchievementService _achievementService, IAzureCosmosDBRepository _azureCosmosDBRepository)
+        public AchievementController(IAchievementService _achievementService, IAzureCosmosDBV3Repository _azureCosmosDBRepository)
         {
             azureCosmosDBRepository = _azureCosmosDBRepository;
             achievementService = _achievementService;
@@ -43,7 +44,7 @@ namespace TEAMModelOS.Controllers.Analysis
             };
             //声明进行标准
             request.@params.TryGetValue("Standard", out object Standard);
-            List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap,true);
+            List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
             Console.WriteLine(DateTimeOffset.Now.Second);
             List<Dictionary<string, object>> examList = new List<Dictionary<string, object>>();
             HashSet<string> classList = new HashSet<string>();
@@ -449,12 +450,12 @@ namespace TEAMModelOS.Controllers.Analysis
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             List<Dictionary<string, object>> scatterAnalysis = new List<Dictionary<string, object>>();
             //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
-            List<SimpleExam> exams = await azureCosmosDBRepository.FindByDict<SimpleExam>(request.@params, true);
+            List<SimpleExam> exams = await azureCosmosDBRepository.FindByDict<SimpleExam>(request.@params);
             Dictionary<string, object> stuMap = new Dictionary<string, object>
             {
                 { "schoolCode", "Habook" }
             };
-            List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap, true);
+            List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
             List<string> key = new List<string>
             {
                 "name",
@@ -599,8 +600,8 @@ namespace TEAMModelOS.Controllers.Analysis
 
 
             };
-            List<SimpleExam> exams = await azureCosmosDBRepository.FindByDict<SimpleExam>(examMap, true);
-            List<ExamPaper> paper = await azureCosmosDBRepository.FindByDict<ExamPaper>(sub, true);
+            List<SimpleExam> exams = await azureCosmosDBRepository.FindByDict<SimpleExam>(examMap);
+            List<ExamPaper> paper = await azureCosmosDBRepository.FindByDict<ExamPaper>(sub);
             List<string> key = new List<string>
             {
                 "id",
@@ -813,8 +814,8 @@ namespace TEAMModelOS.Controllers.Analysis
               
 
             };
-            List<ExamPaper> paper = await azureCosmosDBRepository.FindByDict<ExamPaper>(sub, true);
-            List<SimpleExam> exams = await azureCosmosDBRepository.FindByDict<SimpleExam>(examMap, true);
+            List<ExamPaper> paper = await azureCosmosDBRepository.FindByDict<ExamPaper>(sub);
+            List<SimpleExam> exams = await azureCosmosDBRepository.FindByDict<SimpleExam>(examMap);
             Dictionary<string, object> stuMap = new Dictionary<string, object>
             {
                 { "schoolCode", "Habook" }
@@ -1248,7 +1249,7 @@ namespace TEAMModelOS.Controllers.Analysis
             exams.ForEach( async e => {
                 Dictionary<string, object> sub = new Dictionary<string, object>
                 {
-                    { "ExamCode",  e.Id}
+                    { "ExamCode",  e.id}
                 };
                 List<string> subjects = new List<string>();
                 List<List<string>> SubjectClassAverage = new List<List<string>>();

+ 3 - 2
TEAMModelOS/Controllers/Analysis/ChangeController.cs

@@ -10,6 +10,7 @@ using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.Service.Models.Core;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Controllers.Analysis
 {
@@ -19,8 +20,8 @@ namespace TEAMModelOS.Controllers.Analysis
     {
        
         private readonly IWebHostEnvironment _hostingEnvironment;
-        public IAzureCosmosDBRepository _cosmosrepository;
-        public ChangeController(IWebHostEnvironment hostingEnvironment,   IAzureCosmosDBRepository cosmosDBRepository)
+        public IAzureCosmosDBV3Repository _cosmosrepository;
+        public ChangeController(IWebHostEnvironment hostingEnvironment, IAzureCosmosDBV3Repository cosmosDBRepository)
         {
             _hostingEnvironment = hostingEnvironment;
             _cosmosrepository = cosmosDBRepository;

+ 6 - 5
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -11,6 +11,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using System;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using System.Linq;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Controllers.Syllabus
 {
@@ -19,8 +20,8 @@ namespace TEAMModelOS.Controllers.Syllabus
     //[Authorize]
     public class SyllabusController : BaseController
     {
-        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
-        public SyllabusController(IAzureCosmosDBRepository _azureCosmosDBRepository)
+        private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
+        public SyllabusController(IAzureCosmosDBV3Repository _azureCosmosDBRepository)
         {
             azureCosmosDBRepository = _azureCosmosDBRepository;
         }
@@ -112,7 +113,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             bool flag = false;
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             List<SyllabusNode> nodes = new List<SyllabusNode>();
-            List<SyllabusNode> data = await azureCosmosDBRepository.FindByDict<SyllabusNode>(request.@params, true);
+            List<SyllabusNode> data = await azureCosmosDBRepository.FindByDict<SyllabusNode>(request.@params);
             if (data.IsNotEmpty())
             {
                 await FindByPid(data, nodes, azureCosmosDBRepository);
@@ -131,11 +132,11 @@ namespace TEAMModelOS.Controllers.Syllabus
 
 
 
-        public static async Task<List<SyllabusNode>>  FindByPid(List<SyllabusNode> data, List<SyllabusNode> nodes , IAzureCosmosDBRepository azureCosmosDBRepository) {
+        public static async Task<List<SyllabusNode>>  FindByPid(List<SyllabusNode> data, List<SyllabusNode> nodes , IAzureCosmosDBV3Repository azureCosmosDBRepository) {
             nodes.AddRange(data);
             foreach (SyllabusNode node  in data)
             {
-                List<SyllabusNode>  syllabusNodes=  await  azureCosmosDBRepository.FindByDict<SyllabusNode>(new Dictionary<string, object>() { { "pid", node.id } }, true);
+                List<SyllabusNode>  syllabusNodes=  await  azureCosmosDBRepository.FindByDict<SyllabusNode>(new Dictionary<string, object>() { { "pid", node.id } });
                 if (syllabusNodes.IsNotEmpty()) {
                    await FindByPid(syllabusNodes, nodes ,azureCosmosDBRepository);
                 }

+ 8 - 7
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
 using TEAMModelOS.Controllers;
 using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 
 namespace TEAMModelOS.Controllers.Syllabus
 {
@@ -22,8 +23,8 @@ namespace TEAMModelOS.Controllers.Syllabus
     [ApiController]
     public class VolumeController : BaseController
     {
-        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
-        public VolumeController(IAzureCosmosDBRepository _azureCosmosDBRepository)
+        private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
+        public VolumeController(IAzureCosmosDBV3Repository _azureCosmosDBRepository)
         {
             azureCosmosDBRepository = _azureCosmosDBRepository;
         }
@@ -49,7 +50,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                         { "schoolCode",request.@params.schoolCode},{ "periodCode", request.@params.periodCode},
                         { "subjectCode", request.@params.subjectCode},{ "gradeCode", request.@params.gradeCode},
                         { "semesterCode",request.@params.semesterCode},{ "volumeName",request.@params.volumeName}  ,
-                        { "status",1} ,{ "type",0} }, true);
+                        { "status",1} ,{ "type",0} });
                     if (volumesFind.IsNotEmpty())
                     {
                         throw new BizException("已存在!", ResponseCode.DATA_EXIST);
@@ -65,7 +66,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                         { "schoolCode",request.@params.schoolCode},{ "periodCode", request.@params.periodCode},
                         { "subjectCode", request.@params.subjectCode},{ "gradeCode", request.@params.gradeCode},
                         { "semesterCode",request.@params.semesterCode},{ "volumeName",request.@params.volumeName},
-                        { "TEAMModelId",request.@params.TEAMModelId}, { "status",1} ,{ "type",1} }, true);
+                        { "TEAMModelId",request.@params.TEAMModelId}, { "status",1} ,{ "type",1} });
                     if (volumesFind.IsNotEmpty())
                     {
                         throw new BizException("已存在!", ResponseCode.DATA_EXIST);
@@ -91,7 +92,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                     { "schoolCode",request.@params.schoolCode},{ "periodCode", request.@params.periodCode},
                         { "subjectCode", request.@params.subjectCode},{ "gradeCode", request.@params.gradeCode},
                         { "semesterCode",request.@params.semesterCode},{ "volumeName",request.@params.volumeName}  ,
-                        { "status",1} ,{ "type",0} }, true);
+                        { "status",1} ,{ "type",0} });
                     if (volumesFind.IsNotEmpty())
                     {
                         if (!volumesFind[0].id.Equals(request.@params.id)) {
@@ -105,7 +106,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                         { "schoolCode",request.@params.schoolCode},{ "periodCode", request.@params.periodCode},
                         { "subjectCode", request.@params.subjectCode},{ "gradeCode", request.@params.gradeCode},
                         { "semesterCode",request.@params.semesterCode},{ "volumeName",request.@params.volumeName},
-                        { "TEAMModelId",request.@params.TEAMModelId}, { "status",1} ,{ "type",1} }, true);
+                        { "TEAMModelId",request.@params.TEAMModelId}, { "status",1} ,{ "type",1} });
                     if (volumesFind.IsNotEmpty())
                     {
                         if (!volumesFind[0].id.Equals(request.@params.id))
@@ -170,7 +171,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             List<SyllabusVolume> volumes ;
             if (request.@params.TryGetValue("schoolCode", out _))
             {
-                volumes = await azureCosmosDBRepository.FindByDict<SyllabusVolume>(request.@params,true);
+                volumes = await azureCosmosDBRepository.FindByDict<SyllabusVolume>(request.@params);
             }
             else
             {

+ 2 - 1
TEAMModelOS/Startup.cs

@@ -128,12 +128,13 @@ namespace TEAMModelOS
         }
      
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
-        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAzureCosmosDBV3Repository cosmosDBV3Repository)
         {
             if (env.IsDevelopment())
             {
                 app.UseDeveloperExceptionPage();
             }
+            cosmosDBV3Repository.InitializeDatabase();
             app.UseMiddleware<HttpGlobalExceptionInvoke>();
             //以下需要按照順序載入中間件  如果应用调用 UseStaticFiles,请将 UseStaticFiles 置于 UseRouting之前。
             app.UseStaticFiles();