CrazyIter_Bin 3 年之前
父節點
當前提交
43ef100dcd
共有 2 個文件被更改,包括 49 次插入5 次删除
  1. 28 0
      TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs
  2. 21 5
      TEAMModelOS/Controllers/XTest/TestController.cs

+ 28 - 0
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1070,6 +1070,34 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                             }
                                         }
                                     }
+                                    #region
+                                    //start处理历史数据
+                                    var blobclient = _azureStorage.GetBlobContainerClient(blobname);
+                                    List<BlobItem> blobItems = new List<BlobItem>();
+                                    HashSet<string> ids = new HashSet<string>();
+                                    string path = $"records";
+                                    await foreach (BlobItem item in blobclient.GetBlobsAsync(BlobTraits.None, BlobStates.None, path))
+                                    {
+                                        var p = item.Name.Split("/");
+                                        if (p.Length > 2)
+                                        {
+                                            ids.Add(p[1]);
+                                        }
+                                    }
+                                    List<string> lessonIds = new List<string>();
+                                    string sql = "select value(c.id) from c ";
+                                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
+                                        .GetItemQueryIterator<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(code) }))
+                                    {
+                                        lessonIds.Add(item);
+                                    }
+                                    var notdata = ids.Except(lessonIds);
+                                    var notblob = lessonIds.Except(ids).ToList();
+                                    List<string> paths = notdata.Select(x => $"records/{x}").ToList();
+                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).DeleteItemsStreamAsync(notblob, code);
+                                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, paths);
+                                    //end 处理历史数据
+                                    #endregion
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
                                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, new List<string> { $"records/{_lessonId}" });
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(lessonRecord.id,new PartitionKey ($"Bloblog-{blobname}"));

+ 21 - 5
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -706,13 +706,29 @@ namespace TEAMModelOS.Controllers
         [HttpPost("test-blob-folder")]
         public async Task<IActionResult> TestBlobFolder(JsonElement json)
         {
-            var client=  _azureStorage.GetBlobContainerClient("1595321354") ;
+            var client =  _azureStorage.GetBlobContainerClient("1595321354") ;
             List<BlobItem> blobItems = new List<BlobItem>();
-            await foreach (BlobItem item in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"records/207784031177150464/")) {
-                blobItems.Add(item);
-                break;
+            HashSet<string> ids = new HashSet<string>();
+            string path = $"records";
+            await foreach (BlobItem item in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, path)) {
+                var p=   item.Name.Split("/");
+                if (p.Length > 2) {
+                    ids.Add(p[1]);
+                }
+            }
+            List<string> lessonIds = new List<string>();
+            string sql = "select value(c.id) from c ";
+            await foreach(var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                .GetItemQueryIterator<string>(queryText:sql ,requestOptions:new QueryRequestOptions { PartitionKey= new PartitionKey("LessonRecord-1595321354") }))
+            {
+                lessonIds.Add(item);
             }
-            return Ok(blobItems);
+            var notdata =  ids.Except(lessonIds);
+            var notblob = lessonIds.Except(ids).ToList() ;
+            List<string> paths = notdata.Select(x => $"records/{x}").ToList() ;
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemsStreamAsync(notblob, "LessonRecord-1595321354");
+            await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, "1595321354", paths);
+            return Ok(new { lessonIds , ids , notdata, notblob });
         }
     }