CrazyIter_Bin 3 лет назад
Родитель
Сommit
faa16195d5

+ 5 - 2
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -15,6 +15,7 @@ using System.Text;
 using Azure.Core;
 using Azure;
 using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Extension;
 
 namespace TEAMModelOS.SDK.DI
 {
@@ -131,7 +132,7 @@ namespace TEAMModelOS.SDK.DI
         /// 
         /// </summary>      
         /// <param name="prefix">篩選開頭名稱,Null代表容器</param>        
-        public static async Task<bool> DeleteBlobs(this BlobServiceClient client, string blobContainerName, List<string> prefixs )
+        public static async Task<bool> DeleteBlobs(this BlobServiceClient client,DingDing _dingDing, string blobContainerName, List<string> prefixs )
         {
             if (!prefixs.IsNotEmpty()) return false;
             try
@@ -144,7 +145,8 @@ namespace TEAMModelOS.SDK.DI
                     if (prefix.StartsWith("/")) {
                         px= prefix.Substring(1);
                     }
-                    await foreach (var item in bcc.GetBlobsAsync(BlobTraits.None, BlobStates.None, px))
+                    var items = bcc.GetBlobsAsync(BlobTraits.None, BlobStates.None, px);
+                    await foreach (var item in items)
                     {
                         var urib = new UriBuilder(bcc.Uri);
                         if (prefix != item.Name)
@@ -210,6 +212,7 @@ namespace TEAMModelOS.SDK.DI
             }
             catch(Exception ex )
             {
+                await _dingDing.SendBotMsg($"文件删除异常{ex.Message}{ex.StackTrace}{prefixs.ToJsonString()}", GroupNames.成都开发測試群組);
                 return false;
             }
         }

+ 1 - 1
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -309,7 +309,7 @@ namespace TEAMModelOS.Controllers
                 //string school_code = code.ToString().Substring(typeof(ExamClassResult).Name.Length + 1);
                 var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Exam-{code}"));
                 //删除blob 相关资料
-                await _azureStorage.GetBlobServiceClient().DeleteBlobs(code.ToString(), new List<string> { $"exam/{id}" });
+                await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, code.ToString(), new List<string> { $"exam/{id}" });
                 //通知评测删除信息
                 var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"exam/{id}", name = $"{code}" }.ToJsonString());
                 messageBlob.ApplicationProperties.Add("name", "BlobRoot");

+ 5 - 4
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -28,6 +28,7 @@ using Azure.Messaging.ServiceBus;
 using Azure.Storage.Sas;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using Microsoft.Extensions.Configuration;
+using System.IO;
 
 namespace TEAMModelOS.Controllers
 {
@@ -240,7 +241,7 @@ namespace TEAMModelOS.Controllers
                 }; 
                 List<Survey> surveys = new List<Survey>();
                 var client = _azureCosmos.GetCosmosClient();
-                var query = $"select c.id,c.name,c.code,c.startTime,c.endTime,c.progress,c.classes,c.scope,c.school from c where  c.createTime >= {stimestamp} and c.createTime <= {etimestamp}  {progresssql } ";
+                var query = $"select c.id,c.name,c.code,c.startTime,c.endTime,c.progress,c.classes,c.scope,c.school from c where  c.createTime >= {stimestamp} and c.createTime <= {etimestamp}  {progresssql } and c.ttl=-1 ";
                 if (string.IsNullOrEmpty(school)) {
                     query = $"{query} and c.scope='private' ";
                 }
@@ -368,13 +369,13 @@ namespace TEAMModelOS.Controllers
                     //使用ttl删除,并处理相关事务逻辑
                     survey.ttl = 1;
                     survey.status = 404;
-                    survey = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
+                    survey = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey,survey.id, new PartitionKey($"{survey.code}"));
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
                     //删除blob 相关资料
-                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(code.ToString(),new List<string> { $"survey/{id}" });
+                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{code}".Replace("Survey-", ""), new List<string> { Path.Combine("survey" , survey.id)+"/" });
                     //通知删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"survey/{id}", name = $"{code}" }.ToJsonString());
+                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"survey/{survey.id}", name = $"{code}" }.ToJsonString());
                     messageBlob.ApplicationProperties.Add("name", "BlobRoot");
                     var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
                     await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);

+ 4 - 4
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -241,7 +241,7 @@ namespace TEAMModelOS.Controllers.Learn
                 };
                 List<Vote> votes = new List<Vote>();
                 var client = _azureCosmos.GetCosmosClient();
-                var query = $"select   c.id,c.name,c.code,c.startTime,c.endTime,c.progress ,c.scope,c.school from c where c.createTime >= {stimestamp} and c.createTime <= {etimestamp}  {progresssql } ";
+                var query = $"select   c.id,c.name,c.code,c.startTime,c.endTime,c.progress ,c.scope,c.school from c where c.createTime >= {stimestamp} and c.createTime <= {etimestamp}  {progresssql } and c.ttl=-1 ";
                 if (string.IsNullOrEmpty(school))
                 {
                     query = $"{query} and c.scope='private' ";
@@ -372,16 +372,16 @@ namespace TEAMModelOS.Controllers.Learn
                     //使用ttl删除,并处理相关事务逻辑
                     vote.ttl = 1;
                     vote.status = 404;
-                    vote = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(vote,  new PartitionKey($"{vote.code}"));
+                    vote = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote,vote.id,  new PartitionKey($"{vote.code}"));
                     await _dingDing.SendBotMsg($"{_option.Location}-投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
                     await _dingDing.SendBotMsg($"{_option.Location}-投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
 
                     //删除blob 相关资料
-                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(code.ToString(), new List<string> { $"vote/{id}" });
+                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{code}".Replace("Vote-",""), new List<string> { $"vote/{vote.id}" });
                     //通知删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"vote/{id}", name = $"{code}" }.ToJsonString());
+                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"vote/{vote.id}", name = $"{code}" }.ToJsonString());
                     messageBlob.ApplicationProperties.Add("name", "BlobRoot");
                     var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
                     await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);

+ 4 - 4
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -436,14 +436,14 @@ namespace TEAMModelOS.Controllers.Core
                         }
                         var turl = _azureStorage.GetBlobSAS($"{_cntr}", thum, BlobSasPermissions.Read | BlobSasPermissions.List);
                         bcc.GetBlobClient(tname).SyncCopyFromUri(new Uri(turl));
-                        await _azureStorage.GetBlobServiceClient().DeleteBlobs($"{_cntr}", new List<string> { thum });
+                        await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{_cntr}", new List<string> { thum });
                     }
                     string targetName = item.Name.Replace(px, newName);
                     var url = _azureStorage.GetBlobSAS($"{_cntr}", item.Name, BlobSasPermissions.Read | BlobSasPermissions.List);
                     bcc.GetBlobClient(targetName).SyncCopyFromUri(new Uri(url));
 
                 };
-                await _azureStorage.GetBlobServiceClient().DeleteBlobs($"{_cntr}", new List<string> { px });
+                await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{_cntr}", new List<string> { px });
                 await client.GetContainer("TEAMModelOS", tbname).ReplaceItemAsync<Bloblog>(bloblog, $"{_id}", new PartitionKey($"Bloblog-{_cntr}"));
                 string u = "";
                 string[] uls = System.Web.HttpUtility.UrlDecode(px, Encoding.UTF8).Split("/");
@@ -652,7 +652,7 @@ namespace TEAMModelOS.Controllers.Core
             }
             if (prefix != null && blobContainerName != null)
             {
-                var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(blobContainerName, new List<string> { prefix });
+                var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobContainerName, new List<string> { prefix });
                 string u = "";
                 string[] uls = System.Web.HttpUtility.UrlDecode($"{prefixjson}", Encoding.UTF8).Split("/");
                 if (uls != null)
@@ -754,7 +754,7 @@ namespace TEAMModelOS.Controllers.Core
                         }
                         deleteUrl.Add(delUrl);
                     });
-                    var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(blobContainerName, deleteUrl);
+                    var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobContainerName, deleteUrl);
                     //释放的空间
                     HashSet<string> root = new HashSet<string>();
                     foreach (var x in deleteUrl)

+ 7 - 3
TEAMModelOS/Controllers/Core/ImportController.cs

@@ -38,6 +38,7 @@ namespace TEAMModelOS.Controllers
     [ApiController]
     public class ImportController : ControllerBase
     {
+        public readonly DingDing _dingDing;
 
         public PPTX2HTEXTranslator _PPTX2HTEXTranslator { get; set; }
         public DOXC2HTMLTranslator _DOXC2HTMLTranslator { get; set; }
@@ -47,13 +48,14 @@ namespace TEAMModelOS.Controllers
         public HTML2ITEMV3Translator _HTML2ITEMV3Translator { get; set; }
         public ImportController(
             PPTX2HTEXTranslator PPTX2HTEXTranslator, IHttpClientFactory clientFactory,
-            DOXC2HTMLTranslator DOXC2HTMLTranslator, HTML2ITEMV3Translator HTML2ITEMV3Translator, AzureStorageFactory azureStorage)
+            DOXC2HTMLTranslator DOXC2HTMLTranslator, HTML2ITEMV3Translator HTML2ITEMV3Translator, AzureStorageFactory azureStorage,DingDing ding)
         {
             _HTML2ITEMV3Translator = HTML2ITEMV3Translator;
             _DOXC2HTMLTranslator = DOXC2HTMLTranslator;
             _clientFactory = clientFactory;
             _azureStorage = azureStorage;
             this._PPTX2HTEXTranslator = PPTX2HTEXTranslator;
+            _dingDing = ding;
 
         }
         private static string ReplaceLast(string input, string oldValue, string newValue)
@@ -119,15 +121,18 @@ namespace TEAMModelOS.Controllers
                 if (ext.ToLower() == "pptx" || ext.ToLower() == "xml")
                 {
                     string index = await PPTXTranslator(containerid, FileName, stream);
+                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, containerid, new List<string>() { $"{FileName}.{ext}" });
                     return Ok(new { index = index });
                 }
                 else if (ext.ToLower() == "docx" || ext.ToLower() == "doc")
                 {
                     return Ok(new { index = "" });
+                   // await _azureStorage.GetBlobServiceClient().DeleteBlobs(containerid, new List<string>() { $"{FileName}.{ext}" });
                 }
                 else if (ext.ToLower() == "htex")
                 {
                     var index = await HTEXTranslator(containerid, FileName, stream);
+                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, containerid, new List<string>() {$"{FileName}.{ext}" });
                     return Ok(new { index = index });
                 }
                 else
@@ -140,7 +145,6 @@ namespace TEAMModelOS.Controllers
 
         private async Task<string> HTEXTranslator(string containerid, string FileName, Stream stream)
         {
-            await _azureStorage.GetBlobServiceClient().DeleteBlobs(containerid,new List<string> { $"res/{FileName}" });
             Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
             //处理中文乱码问题
             Encoding encoding = Encoding.GetEncoding("GB2312");
@@ -308,7 +312,7 @@ namespace TEAMModelOS.Controllers
             {
                 containerid = "teammodelos";
             }
-            var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(containerid, new List<string> { $"res/{FileName}" });
+            var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, containerid, new List<string> { $"res/{FileName}" });
 
             string shaCode = Guid.NewGuid().ToString();
             HTEXLib.Htex htex = _PPTX2HTEXTranslator.Translate(streamFile);

+ 1 - 1
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -291,7 +291,7 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
                 //删除blob 相关资料
-                await _azureStorage.GetBlobServiceClient().DeleteBlobs(code.ToString().Replace("Item-",""),new List<string> { $"item/{id}" });
+                await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, code.ToString().Replace("Item-",""),new List<string> { $"item/{id}" });
                 //通知删除信息
                 var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"item/{id}", name = code.ToString().Replace("Item-", "") }.ToJsonString());
                 messageBlob.ApplicationProperties.Add("name", "BlobRoot");

+ 5 - 2
TEAMModelOS/Controllers/Paper/PaperController.cs

@@ -31,14 +31,17 @@ namespace TEAMModelOS.Controllers
         private readonly AzureCosmosFactory _azureCosmos;
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureServiceBusFactory _serviceBus;
+        private readonly DingDing _dingDing;
+
         public IConfiguration _configuration { get; set; }
-        public PaperController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId,AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration)
+        public PaperController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId,AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration, DingDing dingDing)
         {
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
             _azureStorage = azureStorage;
             _serviceBus = serviceBus;
             _configuration = configuration;
+            _dingDing = dingDing;
         }
         /// <summary>
         /// 删除
@@ -57,7 +60,7 @@ namespace TEAMModelOS.Controllers
             Paper paper;
             var client = _azureCosmos.GetCosmosClient();
             //删除blob 相关资料
-            await _azureStorage.GetBlobServiceClient().DeleteBlobs(code.ToString().Replace("Paper-",""), new List<string> { $"paper/{id}" });
+            await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, code.ToString().Replace("Paper-",""), new List<string> { $"paper/{id}" });
             //通知删除信息
             var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"paper/{id}", name = code.ToString().Replace("Paper-", "")}.ToJsonString());
             messageBlob.ApplicationProperties.Add("name", "BlobRoot");