Browse Source

处理CosmosDB更新保存

CrazyIter 5 years ago
parent
commit
422967617d

+ 69 - 36
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -564,36 +564,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
             }
         }
         }
 
 
-        //public async Task<List<T>> FindSQL<T>(string sql, bool isPK) where T : ID
-        //{
-        //    Container container = await InitializeCollection<T>();
-        //    QueryDefinition queryDefinition = new QueryDefinition(sql);
-        //    return await ResultsFromFeedIterator<T>(container.GetItemQueryIterator<T>(queryDefinition));
-        //}
-
-        public async Task<T> ReplaceObject<T>(T entity) where T : ID
-        {
-            Container container = await InitializeCollection<T>();
-            ItemResponse<T> response = await container.ReplaceItemAsync(item: entity, id: entity.id);
-            if (response.StatusCode.Equals(HttpStatusCode.OK))
-            {
-                return response.Resource;
-            }
-            else { throw new BizException("error"); }
-
-        }
-
-        //public async Task<T> ReplaceObject<T>(T entity, string key, string partitionKey) where T : ID
-        //{
-        //    Container container = await InitializeCollection<T>();
-        //    ItemResponse<T> response = await container.ReplaceItemAsync(item: entity, id: entity.id);
-        //    if (response.StatusCode.Equals(HttpStatusCode.OK))
-        //    {
-        //        return response.Resource;
-        //    }
-        //    else { throw new BizException("error"); }
-
-        //}
+       
 
 
         public async Task<T> Save<T>(T entity) where T : ID
         public async Task<T> Save<T>(T entity) where T : ID
         {
         {
@@ -649,14 +620,77 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             stopwatch.Stop();
             stopwatch.Stop();
             return enyites;
             return enyites;
         }
         }
+        public async Task<T> SaveOrUpdate<T>(T entity) where T : ID
+        {
+            Container container = await InitializeCollection<T>();
+            ItemResponse<T> response = await container.UpsertItemAsync(item: entity);
+            if (response.StatusCode.Equals(HttpStatusCode.OK))
+            {
+                return response.Resource;
+            }
+            else { throw new BizException("error"); }
+        }
+        public async Task<List<T>> SaveOrUpdateAll<T>(List<T> enyites) where T : ID
+        {
+            //await Task.Run(() => Parallel.ForEach(entities, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
+            //{
+            //    Task.WaitAll(Update(item));
+            //}));
+
+            int pages = (int)Math.Ceiling((double)enyites.Count / pageSize);
+            Container container = await InitializeCollection<T>();
+            string pk = GetPartitionKey<T>();
+            Type type = typeof(T);
+            Stopwatch stopwatch = Stopwatch.StartNew();
+            for (int i = 0; i < pages; i++)
+            {
+                List<T> lists = enyites.Skip((i) * pageSize).Take(pageSize).ToList();
+                List<KeyValuePair<PartitionKey, Stream>> itemsToInsert = new List<KeyValuePair<PartitionKey, Stream>>();
+                lists.ForEach(async x =>
+                {
+                    MemoryStream stream = new MemoryStream();
+                    await JsonSerializer.SerializeAsync(stream, x);
+                    object o = type.GetProperty(pk).GetValue(x, null);
+                    KeyValuePair<PartitionKey, Stream> keyValue = new KeyValuePair<PartitionKey, Stream>(new PartitionKey(o.ToString()), stream);
+                    itemsToInsert.Add(keyValue);
+                });
+                List<Task> tasks = new List<Task>(lists.Count);
+                itemsToInsert.ForEach(item =>
+                {
+                    tasks.Add(container.UpsertItemStreamAsync(item.Value, item.Key)
+                        .ContinueWith((Task<ResponseMessage> task) =>
+                        {
+                            //using (ResponseMessage response = task.Result)
+                            //{
+                            //    if (!response.IsSuccessStatusCode)
+                            //    {
+                            //    }
+                            //}
+                        }
+                        ));
+                });
+                await Task.WhenAll(tasks);
+            }
+            stopwatch.Stop();
+            return enyites;
+        }
 
 
         public async Task<T> Update<T>(T entity) where T : ID
         public async Task<T> Update<T>(T entity) where T : ID
         {
         {
             Container container = await InitializeCollection<T>();
             Container container = await InitializeCollection<T>();
-            ItemResponse<T> response = await container.UpsertItemAsync(entity);
+            string pk =  GetPartitionKey<T>();
+            object o = typeof(T).GetProperty(pk).GetValue(entity, null);
+            ItemResponse<T> response = await container.ReplaceItemAsync(entity,entity.id,new PartitionKey(o.ToString()));
             return response.Resource;
             return response.Resource;
         }
         }
 
 
+
+        internal class Item { 
+            public  string id { get; set; }
+            public string pk { get; set; }
+            public MemoryStream stream { get; set; }
+        }
+
         public async Task<List<T>> UpdateAll<T>(List<T> enyites) where T : ID
         public async Task<List<T>> UpdateAll<T>(List<T> enyites) where T : ID
         {
         {
             //await Task.Run(() => Parallel.ForEach(entities, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
             //await Task.Run(() => Parallel.ForEach(entities, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (item) =>
@@ -672,20 +706,19 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             for (int i = 0; i < pages; i++)
             for (int i = 0; i < pages; i++)
             {
             {
                 List<T> lists = enyites.Skip((i) * pageSize).Take(pageSize).ToList();
                 List<T> lists = enyites.Skip((i) * pageSize).Take(pageSize).ToList();
-                List<KeyValuePair<PartitionKey, Stream>> itemsToInsert = new List<KeyValuePair<PartitionKey, Stream>>();
+                List<Item> itemsToInsert = new List<Item>();
                 lists.ForEach(async x =>
                 lists.ForEach(async x =>
                 {
                 {
                     MemoryStream stream = new MemoryStream();
                     MemoryStream stream = new MemoryStream();
                     await JsonSerializer.SerializeAsync(stream, x);
                     await JsonSerializer.SerializeAsync(stream, x);
                     object o = type.GetProperty(pk).GetValue(x, null);
                     object o = type.GetProperty(pk).GetValue(x, null);
-                    KeyValuePair<PartitionKey, Stream> keyValue = new KeyValuePair<PartitionKey, Stream>(new PartitionKey(o.ToString()), stream);
+                    Item keyValue = new Item { id=x.id,pk=o.ToString(),stream=stream};
                     itemsToInsert.Add(keyValue);
                     itemsToInsert.Add(keyValue);
                 });
                 });
-              
                 List<Task> tasks = new List<Task>(lists.Count);
                 List<Task> tasks = new List<Task>(lists.Count);
                 itemsToInsert.ForEach(item =>
                 itemsToInsert.ForEach(item =>
                 {
                 {
-                    tasks.Add(container.UpsertItemStreamAsync(item.Value, item.Key)
+                    tasks.Add(container.ReplaceItemStreamAsync(item.stream, item.id,new PartitionKey(item.pk))
                         .ContinueWith((Task<ResponseMessage> task) =>
                         .ContinueWith((Task<ResponseMessage> task) =>
                         {
                         {
                         //using (ResponseMessage response = task.Result)
                         //using (ResponseMessage response = task.Result)
@@ -694,7 +727,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                         //    {
                         //    {
                         //    }
                         //    }
                         //}
                         //}
-                    }
+                        }
                         ));
                         ));
                 });
                 });
                 await Task.WhenAll(tasks);
                 await Task.WhenAll(tasks);

+ 18 - 2
TEAMModelOS.SDK/Module/AzureCosmosDBV3/IAzureCosmosDBV3Repository.cs

@@ -6,6 +6,22 @@ using System.Threading.Tasks;
 
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 {
 {
+    /// <summary>
+    /// "$.name":"明",
+    /// "!$.name":"小"
+    /// "code.|":{"aaa"}
+    /// "<.birthday":20150101,  
+    /// "!=.type":"测试", 
+    /// "<=.day":"1515" 
+    /// ">.age.&":18, 
+    /// "codes[*]":{"aaa"}
+    /// "codes[*]":["aaa","bbb"]
+    /// "code":["aaa","bbb"]
+    /// "@OFFSET":1,
+  	/// "@LIMIT":10,
+  	/// "@DESC","crateTime"
+    /// "@ASC","crateTime"
+    /// </summary>
     public interface IAzureCosmosDBV3Repository
     public interface IAzureCosmosDBV3Repository
     {
     {
 
 
@@ -17,8 +33,8 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         Task DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID;
         Task DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID;
         Task<T> Update<T>(T entity) where T : ID;
         Task<T> Update<T>(T entity) where T : ID;
         Task<List<T>> UpdateAll<T>(List<T> entities) where T : ID;
         Task<List<T>> UpdateAll<T>(List<T> entities) where T : ID;
-        Task<T> ReplaceObject<T>(T entity) where T : ID;
-
+        Task<T> SaveOrUpdate<T>(T entity) where T : ID;
+        Task<List<T>> SaveOrUpdateAll<T>(List<T> entities) where T : ID;
         Task<T> FindById<T>(string id) where T : ID;
         Task<T> FindById<T>(string id) where T : ID;
         Task<T> FindByIdPk<T>(string id, string pk) where T : ID;
         Task<T> FindByIdPk<T>(string id, string pk) where T : ID;
         // Task<string> ReplaceObject<T>(T entity, string key, string partitionKey) where T : ID;
         // Task<string> ReplaceObject<T>(T entity, string key, string partitionKey) where T : ID;

+ 6 - 1
TEAMModelOS.Service/Models/Evaluation/Models/ItemInfo.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Text;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
@@ -22,6 +23,7 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         }
         }
         public string shaCode { get; set; }
         public string shaCode { get; set; }
         //题干
         //题干
+        [Required(ErrorMessage = "{0} 必须填写")]
         public string question { get; set; }
         public string question { get; set; }
         // 选项 单选 多选 判断
         // 选项 单选 多选 判断
         public List<CodeValue> option { get; set; }
         public List<CodeValue> option { get; set; }
@@ -52,6 +54,7 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         /// <summary>
         /// <summary>
         /// 来源编码  个人 学校
         /// 来源编码  个人 学校
         /// </summary>
         /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
         [PartitionKey]
         [PartitionKey]
         public string scopeCode { get; set; }
         public string scopeCode { get; set; }
         /// <summary>
         /// <summary>
@@ -76,7 +79,9 @@ namespace TEAMModelOS.Service.Models.Evaluation.Models
         /// </summary>
         /// </summary>
         public bool lite { get; set; } = false;
         public bool lite { get; set; } = false;
 
 
-        //创建时间  
+        //创建时间 
+        public int crateTime { get; set; }
         //使用次数
         //使用次数
+        public int usageCount { get; set; }
     }
     }
 }
 }

+ 1 - 1
TEAMModelOS/Controllers/Analysis/ChangeController.cs

@@ -194,7 +194,7 @@ namespace TEAMModelOS.Controllers.Analysis
             //_cosmosrepository.Save(sc);
             //_cosmosrepository.Save(sc);
             //_cosmosrepository.Save(simple);
             //_cosmosrepository.Save(simple);
             //_cosmosrepository.SaveAll(classrooms);
             //_cosmosrepository.SaveAll(classrooms);
-            _cosmosrepository.SaveAll(students);
+            _cosmosrepository.SaveOrUpdateAll(students);
             //_examInfoService.SaveListToCosmos(students);
             //_examInfoService.SaveListToCosmos(students);
 
 
 
 

+ 2 - 2
TEAMModelOS/Controllers/Core/ClassRoomController.cs

@@ -27,13 +27,13 @@ namespace TEAMModelOS.Controllers.Syllabus
             
             
             if (request.@params.id != null)
             if (request.@params.id != null)
             {
             {
-                await cosmosrepository.Update(request.@params);
+                await cosmosrepository.SaveOrUpdate(request.@params);
 
 
             }
             }
             else
             else
             {
             {
                 request.@params.id = Guid.NewGuid().ToString();
                 request.@params.id = Guid.NewGuid().ToString();
-                await cosmosrepository.Save<Classroom>(request.@params);
+                await cosmosrepository.SaveOrUpdate<Classroom>(request.@params);
                 
                 
             }
             }
             return builder.Data(request.@params).build();
             return builder.Data(request.@params).build();

+ 1 - 1
TEAMModelOS/Controllers/Core/LoginController.cs

@@ -124,7 +124,7 @@ namespace TEAMModelOS.Controllers.Core
                 loginInfo.Scope = jwtToken.Scope;
                 loginInfo.Scope = jwtToken.Scope;
                 result.JwtToken = jwtToken;
                 result.JwtToken = jwtToken;
                 await azureTableDBRepository.Save<LoginInfo>(loginInfo);
                 await azureTableDBRepository.Save<LoginInfo>(loginInfo);
-                await azureCosmosDBRepository.SaveAll<Teacher>(new List<Teacher>() { user });
+                await azureCosmosDBRepository.SaveOrUpdateAll<Teacher>(new List<Teacher>() { user });
                 //  JosnRPCResponse<TeamModelIdInfo> response = MessagePackHelper.JsonToObject<JosnRPCResponse<TeamModelIdInfo>>(jsonStr);
                 //  JosnRPCResponse<TeamModelIdInfo> response = MessagePackHelper.JsonToObject<JosnRPCResponse<TeamModelIdInfo>>(jsonStr);
                 return result;
                 return result;
                 #endregion
                 #endregion

+ 1 - 1
TEAMModelOS/Controllers/Core/SchoolController.cs

@@ -38,7 +38,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                 request.@params.id = Guid.NewGuid().ToString();
                 request.@params.id = Guid.NewGuid().ToString();
             }
             }
 
 
-            List<School> datas = await  _cosmosrepository.SaveAll<School>(new List<School>() { request.@params });
+            List<School> datas = await  _cosmosrepository.SaveOrUpdateAll<School>(new List<School>() { request.@params });
             return builder.Data(datas.IsEmpty()?null:datas[0]).build();
             return builder.Data(datas.IsEmpty()?null:datas[0]).build();
         }
         }
         [HttpPost("FindSchool")]
         [HttpPost("FindSchool")]

+ 3 - 3
TEAMModelOS/Controllers/Core/StudentController.cs

@@ -47,7 +47,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             };
             };
             request.@params.id = request.@params.studentId.Replace("#","-");
             request.@params.id = request.@params.studentId.Replace("#","-");
             request.@params.classroom = classroom;
             request.@params.classroom = classroom;
-            Student data = await azureCosmosDBRepository.Save<Student>(request.@params);
+            Student data = await azureCosmosDBRepository.SaveOrUpdate<Student>(request.@params);
             return builder.Data(data).build();
             return builder.Data(data).build();
         }
         }
 
 
@@ -112,7 +112,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                         student.classroom = classroom;
                         student.classroom = classroom;
                         students.Add(student);
                         students.Add(student);
                     });
                     });
-                    await azureCosmosDBRepository.SaveAll(students);
+                    await azureCosmosDBRepository.SaveOrUpdateAll(students);
                 }
                 }
             }
             }
             return builder.Data(students).build();
             return builder.Data(students).build();
@@ -128,7 +128,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                 request.@params.password.value = TmdCrypt.Encrypt(request.@params.password.value);
                 request.@params.password.value = TmdCrypt.Encrypt(request.@params.password.value);
                 request.@params.password.isSet = true;
                 request.@params.password.isSet = true;
             }
             }
-            Student data = await azureCosmosDBRepository.Update<Student>(request.@params);
+            Student data = await azureCosmosDBRepository.SaveOrUpdate<Student>(request.@params);
             return builder.Data(data).build();
             return builder.Data(data).build();
         }
         }
         //[HttpPost("UpdateAllStudent")]
         //[HttpPost("UpdateAllStudent")]

+ 1 - 1
TEAMModelOS/Controllers/Courses/CourseController.cs

@@ -29,7 +29,7 @@ namespace TEAMModelOS.Controllers.Courses
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             List<Course> courses = request.@params;
             List<Course> courses = request.@params;
-            List<Course> response = await _cosmos.UpdateAll<Course>(courses);
+            List<Course> response = await _cosmos.SaveOrUpdateAll<Course>(courses);
             if (response.Count > 0) builder.Data(response).Extend(new Dictionary<string, object> { { "count", response.Count } });
             if (response.Count > 0) builder.Data(response).Extend(new Dictionary<string, object> { { "count", response.Count } });
             else builder.Error(false, ResponseCode.FAILED, "失败");
             else builder.Error(false, ResponseCode.FAILED, "失败");
             return builder.build();
             return builder.build();

+ 5 - 15
TEAMModelOS/Controllers/Evaluation/ExamController.cs

@@ -32,10 +32,10 @@ namespace TEAMModelOS.Controllers.Evaluation
             if (string.IsNullOrEmpty(request.@params.id))
             if (string.IsNullOrEmpty(request.@params.id))
             {
             {
                 request.@params.id = Guid.NewGuid().ToString();
                 request.@params.id = Guid.NewGuid().ToString();
-                await cosmosDBV3Repository.Save(request.@params);
+                await cosmosDBV3Repository.SaveOrUpdate(request.@params);
             }
             }
             else {
             else {
-              await  cosmosDBV3Repository.Update(request.@params);
+              await  cosmosDBV3Repository.SaveOrUpdate(request.@params);
             }
             }
             return builder.Data(request.@params).build();
             return builder.Data(request.@params).build();
         }
         }
@@ -51,11 +51,11 @@ namespace TEAMModelOS.Controllers.Evaluation
             if (string.IsNullOrEmpty(request.@params.id))
             if (string.IsNullOrEmpty(request.@params.id))
             {
             {
                 request.@params.id = Guid.NewGuid().ToString();
                 request.@params.id = Guid.NewGuid().ToString();
-                await cosmosDBV3Repository.Save(request.@params);
+                await cosmosDBV3Repository.SaveOrUpdate(request.@params);
             }
             }
             else
             else
             {
             {
-                await cosmosDBV3Repository.Update(request.@params);
+                await cosmosDBV3Repository.SaveOrUpdate(request.@params);
             }
             }
             return builder.Data(request.@params).build();
             return builder.Data(request.@params).build();
         }
         }
@@ -109,17 +109,7 @@ namespace TEAMModelOS.Controllers.Evaluation
             "57088641-14d1-498d-ae8e-61627e0d8e4a", "2222f52f-cc3f-4ac3-96b8-638078455f64",
             "57088641-14d1-498d-ae8e-61627e0d8e4a", "2222f52f-cc3f-4ac3-96b8-638078455f64",
             "1687d096-4d58-4828-97de-d31e23784b36", "45ae3d97-cd76-4c53-a821-e220367eb2c2" };
             "1687d096-4d58-4828-97de-d31e23784b36", "45ae3d97-cd76-4c53-a821-e220367eb2c2" };
 
 
-        /// <summary>
-        /// 手动挑题
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [HttpPost("Manual")]
-        public async Task<BaseJosnRPCResponse> Manual(JosnRPCRequest<Dictionary<string,object>> request) {
-            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(request.@params);
-            return builder.Data(items).build();
-        }
+        
         /// <summary>
         /// <summary>
         /// 自动组题
         /// 自动组题
         /// </summary>
         /// </summary>

+ 58 - 15
TEAMModelOS/Controllers/Evaluation/ItemInfoController.cs

@@ -21,7 +21,7 @@ namespace TEAMModelOS.Controllers.Evaluation
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// 手动挑题
+        /// 批量保存题目
         /// </summary>
         /// </summary>
         /// <param name="request"></param>
         /// <param name="request"></param>
         /// <returns></returns>
         /// <returns></returns>
@@ -29,20 +29,63 @@ namespace TEAMModelOS.Controllers.Evaluation
         public async Task<BaseJosnRPCResponse> SaveAll(JosnRPCRequest<List<ItemInfo>> request)
         public async Task<BaseJosnRPCResponse> SaveAll(JosnRPCRequest<List<ItemInfo>> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            // habook#0001
-            //  HBCN
-            Random rangdomRed = new Random();
-            foreach (ItemInfo item in request.@params) {
-                int rnd = rangdomRed.Next(1, 8);
-                if (rnd == 2 || rnd == 5)
-                {
-                    item.scopeCode = "habook#0001".Replace("#", "");
-                }
-                else {
-                    item.scopeCode = "HBCN";
-                }
-            }
-            return builder.Data(await cosmosDBV3Repository.SaveAll(request.@params)).build();
+            //// habook#0001
+            ////  HBCN
+            //Random rangdomRed = new Random();
+            //foreach (ItemInfo item in request.@params) {
+            //    int rnd = rangdomRed.Next(1, 8);
+            //    if (rnd == 2 || rnd == 5)
+            //    {
+            //        item.scopeCode = "habook#0001".Replace("#", "");
+            //    }
+            //    else {
+            //        item.scopeCode = "HBCN";
+            //    }
+            //}
+            request.@params.ForEach(x => {
+                x.scopeCode = x.scopeCode.replace("#", "");
+                if (string.IsNullOrEmpty(x.id)) {
+                    x.id = Guid.NewGuid().ToString();
+                };
+            });
+            return builder.Data(await cosmosDBV3Repository.SaveOrUpdateAll(request.@params)).build();
+        }
+        [HttpPost("Save")]
+        public async Task<BaseJosnRPCResponse> Save(JosnRPCRequest<ItemInfo> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            //// habook#0001
+            ////  HBCN
+            //Random rangdomRed = new Random();
+            //foreach (ItemInfo item in request.@params) {
+            //    int rnd = rangdomRed.Next(1, 8);
+            //    if (rnd == 2 || rnd == 5)
+            //    {
+            //        item.scopeCode = "habook#0001".Replace("#", "");
+            //    }
+            //    else {
+            //        item.scopeCode = "HBCN";
+            //    }
+            //}
+
+            request.@params.scopeCode = request.@params.scopeCode.replace("#", "");
+            if (string.IsNullOrEmpty(request.@params.id))
+            {
+            request.@params.id = Guid.NewGuid().ToString();
+            };
+            return builder.Data(await cosmosDBV3Repository.SaveOrUpdate(request.@params)).build();
+        }
+        /// <summary>
+        /// 手动挑题
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("Find")]
+        public async Task<BaseJosnRPCResponse> Find(JosnRPCRequest<Dictionary<string, object>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(request.@params);
+            return builder.Data(items).build();
         }
         }
     }
     }
 }
 }

+ 4 - 4
TEAMModelOS/Controllers/Syllabus/KnowledgeController.cs

@@ -268,12 +268,12 @@ namespace TEAMModelOS.Controllers.Syllabus
                                 knowledge.points.Remove(item.id);
                                 knowledge.points.Remove(item.id);
                                 knowledge.points.Add(item.id);
                                 knowledge.points.Add(item.id);
                             }
                             }
-                            await _cosmos.UpdateAll(knowledges);
+                            await _cosmos.SaveOrUpdateAll(knowledges);
                         }
                         }
                         item.points.Clear();
                         item.points.Clear();
                     }
                     }
                 }
                 }
-                List<Knowledge> ts = await _cosmos.UpdateAll(schoolBlocks);
+                List<Knowledge> ts = await _cosmos.SaveOrUpdateAll(schoolBlocks);
                 if (ts.Count > 0) builder.Data(ts).Extend(new Dictionary<string, object> { { "count", ts.Count } });
                 if (ts.Count > 0) builder.Data(ts).Extend(new Dictionary<string, object> { { "count", ts.Count } });
                 else builder.Error(false, ResponseCode.FAILED, "失败");
                 else builder.Error(false, ResponseCode.FAILED, "失败");
             }
             }
@@ -297,8 +297,8 @@ namespace TEAMModelOS.Controllers.Syllabus
                     List<SyllabusResource> Resources = await _cosmos.FindSQL<SyllabusResource>("SELECT value(c) FROM c join a in c.points where Contains(a, '" + Knowledge.id + "') = true ");
                     List<SyllabusResource> Resources = await _cosmos.FindSQL<SyllabusResource>("SELECT value(c) FROM c join a in c.points where Contains(a, '" + Knowledge.id + "') = true ");
                     foreach (Knowledge knowledge in knowledges) knowledge.points.Remove(Knowledge.id);
                     foreach (Knowledge knowledge in knowledges) knowledge.points.Remove(Knowledge.id);
                     foreach (SyllabusResource Resource in Resources) Resource.points.Remove(Knowledge.id);
                     foreach (SyllabusResource Resource in Resources) Resource.points.Remove(Knowledge.id);
-                    await _cosmos.UpdateAll(Resources);
-                    await _cosmos.UpdateAll(knowledges);
+                    await _cosmos.SaveOrUpdateAll(Resources);
+                    await _cosmos.SaveOrUpdateAll(knowledges);
                 }
                 }
             }
             }
             return builder.build();
             return builder.build();

+ 1 - 1
TEAMModelOS/Controllers/Syllabus/ResourceController.cs

@@ -54,7 +54,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                         
                         
                     }
                     }
                 }
                 }
-                List<SyllabusResource> ts = await _cosmos.UpdateAll(resource);
+                List<SyllabusResource> ts = await _cosmos.SaveOrUpdateAll(resource);
                 if (ts.Count > 0) builder.Data("保存或新增成功");
                 if (ts.Count > 0) builder.Data("保存或新增成功");
                 else builder.Error(false, ResponseCode.FAILED, "失败");
                 else builder.Error(false, ResponseCode.FAILED, "失败");
             }
             }

+ 3 - 3
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -44,7 +44,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             syllabus.children = nodes;
             syllabus.children = nodes;
             syllabus.id = request.@params[0].volumeCode;
             syllabus.id = request.@params[0].volumeCode;
             syllabus.volumeCode = request.@params[0].volumeCode;
             syllabus.volumeCode = request.@params[0].volumeCode;
-            await azureCosmosDBRepository.Update<Syllabuses>(syllabus);
+            await azureCosmosDBRepository.SaveOrUpdate<Syllabuses>(syllabus);
             List<SyllabusTree> treess = ListToTree(nodes);
             List<SyllabusTree> treess = ListToTree(nodes);
             return builder.Data(treess).build();
             return builder.Data(treess).build();
         }
         }
@@ -97,7 +97,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                 data[0].children.AddRange(syllabusNodes);
                 data[0].children.AddRange(syllabusNodes);
 
 
 
 
-                List<Syllabuses> syllabuses = await azureCosmosDBRepository.UpdateAll<Syllabuses>(data);
+                List<Syllabuses> syllabuses = await azureCosmosDBRepository.SaveOrUpdateAll<Syllabuses>(data);
                 if (syllabuses != null) return builder.Data(request.@params).build();
                 if (syllabuses != null) return builder.Data(request.@params).build();
                 else return builder.Error(false, ResponseCode.FAILED, "保存失败").build();
                 else return builder.Error(false, ResponseCode.FAILED, "保存失败").build();
             }
             }
@@ -209,7 +209,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                 }
                 }
                 else
                 else
                 {
                 {
-                    List<Syllabuses> data1 = await azureCosmosDBRepository.UpdateAll<Syllabuses>(data);
+                    List<Syllabuses> data1 = await azureCosmosDBRepository.SaveOrUpdateAll<Syllabuses>(data);
                     return builder.Data(data1).build();
                     return builder.Data(data1).build();
                 }
                 }
             }
             }

+ 2 - 2
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -125,7 +125,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             {
             {
                 request.@params
                 request.@params
             };
             };
-            List<SyllabusVolume> volume = await azureCosmosDBRepository.SaveAll<SyllabusVolume>(volumes);
+            List<SyllabusVolume> volume = await azureCosmosDBRepository.SaveOrUpdateAll<SyllabusVolume>(volumes);
             return builder.Data(volume.IsEmpty() ? null : volume[0]).build();
             return builder.Data(volume.IsEmpty() ? null : volume[0]).build();
         }
         }
         /// <summary>
         /// <summary>
@@ -147,7 +147,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                     {
                     {
                         request.@params
                         request.@params
                     };
                     };
-                    await azureCosmosDBRepository.SaveAll<SyllabusVolume>(volumes);
+                    await azureCosmosDBRepository.SaveOrUpdateAll<SyllabusVolume>(volumes);
                     flag = true;
                     flag = true;
                 //}
                 //}
                 //else
                 //else