Sfoglia il codice sorgente

删除操作完善

CrazyIter 5 anni fa
parent
commit
11eae89429

+ 38 - 24
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -236,7 +236,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         }
         }
 
 
 
 
-        public async Task DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID
+        public async Task<List<IdPk>> DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID
         {
         {
             Container container = await InitializeCollection<T>();
             Container container = await InitializeCollection<T>();
             //string partitionKey = GetPartitionKey<T>();
             //string partitionKey = GetPartitionKey<T>();
@@ -245,7 +245,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             //    Task.WaitAll(DeleteAsync<T>(item.Value, item.Key));
             //    Task.WaitAll(DeleteAsync<T>(item.Value, item.Key));
             //}));
             //}));
 
 
-
+            List<IdPk> idPks = new List<IdPk>();
             int pages = (int)Math.Ceiling((double)ids.Count / pageSize);
             int pages = (int)Math.Ceiling((double)ids.Count / pageSize);
             Stopwatch stopwatch = Stopwatch.StartNew();
             Stopwatch stopwatch = Stopwatch.StartNew();
             for (int i = 0; i < pages; i++)
             for (int i = 0; i < pages; i++)
@@ -257,22 +257,30 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     tasks.Add(container.DeleteItemStreamAsync(item.Value, new PartitionKey(item.Key))
                     tasks.Add(container.DeleteItemStreamAsync(item.Value, new PartitionKey(item.Key))
                         .ContinueWith((Task<ResponseMessage> task) =>
                         .ContinueWith((Task<ResponseMessage> task) =>
                         {
                         {
-                            //using (ResponseMessage response = task.Result)
-                            //{
-                            //    if (!response.IsSuccessStatusCode)
-                            //    {
-                            //    }
-                            //}
+                             using (ResponseMessage response = task.Result)
+                           {
+                                idPks.Add(new IdPk { id = item.Value, pk = item.Key.ToString(), StatusCode = response.StatusCode });
+                                //    if (!response.IsSuccessStatusCode)
+                                //    {
+                                //    }
+                            }
                         }
                         }
                         ));
                         ));
                 });
                 });
                 await Task.WhenAll(tasks);
                 await Task.WhenAll(tasks);
             }
             }
             stopwatch.Stop();
             stopwatch.Stop();
+            return idPks;
         }
         }
-
-        public async Task DeleteAll<T>(List<T> enyites) where T : ID
+        public async Task<List<IdPk>> DeleteAll<T>(Dictionary<string,object> dict) where T : ID
+        {
+            List<T> list=   await FindByDict<T>(dict);
+            return await DeleteAll(list); 
+        }
+        public async Task<List<IdPk>> DeleteAll<T>(List<T> enyites) where T : ID
         {
         {
+
+            List<IdPk> idPks = new List<IdPk>();
             Container container = await InitializeCollection<T>();
             Container container = await InitializeCollection<T>();
             string pk = GetPartitionKey<T>();
             string pk = GetPartitionKey<T>();
             Type type = typeof(T);
             Type type = typeof(T);
@@ -293,36 +301,42 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 itemsToInsert.ForEach(item =>
                 itemsToInsert.ForEach(item =>
                 {
                 {
                     tasks.Add(container.DeleteItemStreamAsync(item.Value, item.Key)
                     tasks.Add(container.DeleteItemStreamAsync(item.Value, item.Key)
-                        .ContinueWith((Task<ResponseMessage> task) =>
+                    .ContinueWith((Task<ResponseMessage> task) =>
                         {
                         {
-                            //using (ResponseMessage response = task.Result)
-                            //{
-                            //    if (!response.IsSuccessStatusCode)
-                            //    {
-                            //    }
-                            //}
+                            using (ResponseMessage response = task.Result)
+                            {
+                                
+                                idPks.Add(new IdPk { id = item.Value, pk = item.Key.ToString(), StatusCode = response.StatusCode });
+                                 
+                            }
                         }
                         }
-                        ));
+                    ));
                 });
                 });
                 await Task.WhenAll(tasks);
                 await Task.WhenAll(tasks);
             }
             }
             stopwatch.Stop();
             stopwatch.Stop();
+            return idPks;
+        }
+
+        public async Task<IdPk> DeleteAsync<T>(IdPk idPk) where T : ID {
+            return await DeleteAsync<T>(idPk.id, idPk.pk);
         }
         }
-        public async Task<T> DeleteAsync<T>(string id, string pk) where T : ID
+        public async Task<IdPk> DeleteAsync<T>(string id, string pk) where T : ID
         {
         {
             Container container = await InitializeCollection<T>();
             Container container = await InitializeCollection<T>();
-            ItemResponse<T> response = await container.DeleteItemAsync<T>(id: id, partitionKey: new PartitionKey(pk));
-            return response.Resource;
+            ResponseMessage  response = await container.DeleteItemStreamAsync(id: id, partitionKey: new PartitionKey(pk));
+            
+            return new IdPk { id =id, pk = pk, StatusCode = response.StatusCode };
         }
         }
 
 
-        public async Task<T> DeleteAsync<T>(T entity) where T : ID
+        public async Task<IdPk> DeleteAsync<T>(T entity) where T : ID
         {
         {
             Container container = await InitializeCollection<T>();
             Container container = await InitializeCollection<T>();
             string partitionKey = GetPartitionKey<T>();
             string partitionKey = GetPartitionKey<T>();
             Type type = typeof(T);
             Type type = typeof(T);
             object o = type.GetProperty(partitionKey).GetValue(entity, null);
             object o = type.GetProperty(partitionKey).GetValue(entity, null);
-            ItemResponse<T> response = await container.DeleteItemAsync<T>(id: entity.id, partitionKey: new PartitionKey(o.ToString()));
-            return response.Resource;
+            ResponseMessage  response = await container.DeleteItemStreamAsync (id: entity.id, partitionKey: new PartitionKey(o.ToString()));
+            return new IdPk { id = entity.id, pk = o.ToString(), StatusCode = response.StatusCode };
 
 
         }
         }
         //public async Task<T> DeleteAsync<T>(string id) where T : ID
         //public async Task<T> DeleteAsync<T>(string id) where T : ID

+ 6 - 4
TEAMModelOS.SDK/Module/AzureCosmosDBV3/IAzureCosmosDBV3Repository.cs

@@ -27,10 +27,12 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
 
         Task<T> Save<T>(T entity) where T : ID;
         Task<T> Save<T>(T entity) where T : ID;
         Task<List<T>> SaveAll<T>(List<T> enyites) where T : ID;
         Task<List<T>> SaveAll<T>(List<T> enyites) where T : ID;
-        Task<T> DeleteAsync<T>(T entity) where T : ID;
-        Task<T> DeleteAsync<T>(string id, string pk) where T : ID;
-        Task DeleteAll<T>(List<T> entities) where T : ID;
-        Task DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID;
+        Task<IdPk> DeleteAsync<T>(T entity) where T : ID;
+        Task<IdPk> DeleteAsync<T>(string id, string pk) where T : ID;
+        Task<IdPk> DeleteAsync<T>(IdPk idPk) where T : ID;
+        Task<List<IdPk>> DeleteAll<T>(List<T> entities) where T : ID;
+        Task<List<IdPk>> DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID;
+        Task<List<IdPk>> DeleteAll<T>(Dictionary<string, object> dict) 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> SaveOrUpdate<T>(T entity) where T : ID;
         Task<T> SaveOrUpdate<T>(T entity) where T : ID;

+ 4 - 2
TEAMModelOS/Models/IdPk.cs

@@ -2,15 +2,17 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Linq;
+using System.Net;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
-namespace TEAMModelOS.Models
+namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 {
 {
     public class IdPk
     public class IdPk
     {
     {
         [Required(ErrorMessage = "{0} 必须填写")]
         [Required(ErrorMessage = "{0} 必须填写")]
         public string id { get; set; }
         public string id { get; set; }
-        [Required(ErrorMessage = "{0} 必须填写")]
+
         public string pk { get; set; }
         public string pk { get; set; }
+        public HttpStatusCode StatusCode { get;set;}
     }
     }
 }
 }

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

@@ -21,7 +21,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             cosmosrepository = _cosmosrepository;
             cosmosrepository = _cosmosrepository;
         }
         }
         [HttpPost("SaveOrUpdate")]
         [HttpPost("SaveOrUpdate")]
-        public async Task<BaseJosnRPCResponse> SaveOrUpdate(JosnRPCRequest<Classroom> request)
+        public async ValueTask<BaseJosnRPCResponse> SaveOrUpdate(JosnRPCRequest<Classroom> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             
             

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

@@ -154,7 +154,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();
-            Student data = await azureCosmosDBRepository.DeleteAsync<Student>(request.@params.id, request.@params.schoolCode);
+            IdPk 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删除

+ 2 - 2
TEAMModelOS/Controllers/Exam/ExamController.cs

@@ -53,7 +53,7 @@ namespace TEAMModelOS.Controllers.Exam
         public async Task<BaseJosnRPCResponse> DeleteExamInfo(JosnRPCRequest<IdPk> request)
         public async Task<BaseJosnRPCResponse> DeleteExamInfo(JosnRPCRequest<IdPk> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            ExamInfo items = await cosmosDBV3Repository.DeleteAsync<ExamInfo>(request.@params.id, request.@params.pk);
+            IdPk items = await cosmosDBV3Repository.DeleteAsync<ExamInfo>(request.@params.id, request.@params.pk);
             return builder.Data(items).build();
             return builder.Data(items).build();
         }
         }
         /// <summary>
         /// <summary>
@@ -76,7 +76,7 @@ namespace TEAMModelOS.Controllers.Exam
         public async Task<BaseJosnRPCResponse> DeleteExamPaper(JosnRPCRequest<IdPk> request)
         public async Task<BaseJosnRPCResponse> DeleteExamPaper(JosnRPCRequest<IdPk> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            ExamPaper items = await cosmosDBV3Repository.DeleteAsync<ExamPaper>(request.@params.id, request.@params.pk);
+            IdPk items = await cosmosDBV3Repository.DeleteAsync<ExamPaper>(request.@params.id, request.@params.pk);
             return builder.Data(items).build();
             return builder.Data(items).build();
         }
         }
 
 

+ 2 - 2
TEAMModelOS/Controllers/Exam/ItemInfoController.cs

@@ -115,8 +115,8 @@ namespace TEAMModelOS.Controllers.Exam
         public async Task<BaseJosnRPCResponse> DeleteExamItem(JosnRPCRequest<IdPk> request)
         public async Task<BaseJosnRPCResponse> DeleteExamItem(JosnRPCRequest<IdPk> request)
         {
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            ExamItem items = await cosmosDBV3Repository.DeleteAsync<ExamItem>(request.@params.id,request.@params.pk);
-            return builder.Data(items).build();
+            IdPk idPk = await cosmosDBV3Repository.DeleteAsync<ExamItem>( request.@params );
+            return builder.Data(idPk).build();
         }
         }
         /// <summary>
         /// <summary>
         /// 手动挑题
         /// 手动挑题

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

@@ -326,8 +326,8 @@ namespace TEAMModelOS.Controllers.Syllabus
             if (schoolBlocks.IsNotEmpty())
             if (schoolBlocks.IsNotEmpty())
             {
             {
                 foreach (T item  in schoolBlocks) {
                 foreach (T item  in schoolBlocks) {
-                   
-                    list.Add(await _cosmos.DeleteAsync<T>(item));
+                    await _cosmos.DeleteAsync<T>(item);
+                    list.Add(item);
 
 
                 }
                 }
                 if (list.Count > 0)
                 if (list.Count > 0)