CrazyIter_Bin преди 2 години
родител
ревизия
dd21d48551

+ 1 - 1
TEAMModelOS.FunctionV4/Program.cs

@@ -71,7 +71,7 @@ namespace TEAMModelOS.FunctionV4
                    storageConnects.Add(("LogStorage", LogStorageConnectionString));   //防火墙日志统计文件
                }
                services.AddMultipleAzureStorage(storageConnects);
-              // services.AddHostedService<ServiceBusSub>();
+              services.AddHostedService<BlobRootServiceBusSub>();
                services.AddIPSearcher("");
            })
            .Build();

+ 4 - 85
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -276,82 +276,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
 
         }
 
-        /// <summary>
-        /// 根据容器的根目录刷新redis并获取redis的最新使用情况
-        /// </summary>
-        /// <param name="msg"></param>
-        /// <returns></returns>
-        [Function("BlobRoot")]
-        public async Task BlobRootFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blobroot", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
-        {
-            try
-            {
-
-                var jsonMsg = JsonDocument.Parse(msg);
-                return;
-                if (jsonMsg.RootElement.TryGetProperty("name", out JsonElement _name) && _name.ValueKind == JsonValueKind.String)
-                {
-                    if (jsonMsg.RootElement.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String && !string.IsNullOrWhiteSpace($"{root}"))
-                    {
-                        List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
-                        string[] uls = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/");
-                        string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
-                        string name = $"{_name}";
-                        string lockKey = $"Blob:Lock:{name}:{u}";
-                        bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
-
-                        if (!exist)
-                        {   ///key不存在则正常进行计算
-                            bool condition = false;
-                            TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(15).Ticks);
-                            timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
-                            //准备处理Blob刷新时间
-                            long action = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                            await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, action, expiry: timeSpan);
-                            await RefreshBlob(name, u);
-                            //将action 与Redis最新的时间进行比较,如果
-                            var rds = await CheckLockKey(lockKey, action);
-                            condition = rds.condition;
-                            exist = rds.exist;
-                            if (condition || !exist)
-                            {
-                                await RefreshBlob(name, u);
-                            }
-
-                            //使用  CancellationToken 
-                            //while (condition || !exist)
-                            //{
-
-                            //}
-                        }
-                        else
-                        {
-                            ///key存在则,则刷新key对应的值
-                            TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(15).Ticks);
-                            timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
-                            long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                            await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, now, expiry: timeSpan);
-                        }
-                    }
-                    else
-                    {
-                        var client = _azureStorage.GetBlobContainerClient($"{_name}");
-                        var size = await client.GetBlobsCatalogSize();
-                        await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{_name}", size.Item1);
-                        foreach (var key in size.Item2.Keys)
-                        {
-                            await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{_name}", key);
-                            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{_name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
-                        }
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
-            }
-        }
-
+      
        
         /// <param name="msg"></param>
         /// <returns></returns>
@@ -1512,12 +1437,9 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                         periodId = string.IsNullOrWhiteSpace(lessonRecord.periodId) ? new List<string>() : new List<string> { lessonRecord.periodId },
                                         size = size.HasValue ? size.Value : 0,
                                     };
-                                    await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog);
-                                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
-                                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                                    await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog); 
                                     //await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} blob刷新完成!", GroupNames.醍摩豆服務運維群組);
+                                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage {  progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration,_azureRedis);
                                     msgs.Add(update);
 
                                     DoLessonStudentRecord(_dingDing, _snowflakeId, lessonRecord, scope, client, school, tmdid, teacher,   _serviceBus, _azureStorage, _configuration, lessonBase);
@@ -1593,10 +1515,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     }
                                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, new List<string> { $"records/{_lessonId}" });
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(lessonRecord.id, new PartitionKey($"Bloblog-{blobname}"));
-                                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
-                                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage {   progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration, _azureRedis);
                                     msgs.Add(update);
                                 }
                                 catch (CosmosException)

+ 25 - 37
TEAMModelOS.FunctionV4/ServiceBus/ServiceBusSub.cs

@@ -5,27 +5,33 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net.Http;
+using System.ServiceModel.Channels;
 using System.Text;
 using System.Text.Json;
 using System.Threading;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Services;
 using static TEAMModelOS.FunctionV4.HttpTrigger.IESHttpTrigger;
 
 namespace TEAMModelOS.FunctionV4
 {
-    public class ServiceBusSub : BackgroundService, IDisposable
+    public class BlobRootServiceBusSub : BackgroundService, IDisposable
     {
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
         private readonly ServiceBusReceiver _receiver;
+        private readonly DingDing _dingDing;
         private const string Channel = "BlobRoot";
         public static SpinWait spinWait = new SpinWait(); // 构造SpinWait实例
-        public ServiceBusSub(AzureRedisFactory azureRedisFactory,  AzureStorageFactory azureStorage, AzureServiceBusFactory azureService)
+        public BlobRootServiceBusSub(DingDing dingDing, AzureRedisFactory azureRedisFactory,  AzureStorageFactory azureStorage, AzureServiceBusFactory azureService)
         {
-            _receiver = azureService.GetServiceBusClient("Default").CreateReceiver(Channel, new ServiceBusReceiverOptions { ReceiveMode = ServiceBusReceiveMode.PeekLock });
+            _receiver = azureService.GetServiceBusClient().CreateReceiver("dep-active-task", Channel, new ServiceBusReceiverOptions { ReceiveMode = ServiceBusReceiveMode.PeekLock });
             _azureStorage = azureStorage;
             _azureRedis = azureRedisFactory;
+            _dingDing = dingDing;
         }
         protected async override Task ExecuteAsync(CancellationToken stoppingToken)
         {
@@ -33,12 +39,25 @@ namespace TEAMModelOS.FunctionV4
             {
                 //30分钟。进入死信
                 IReadOnlyList<ServiceBusReceivedMessage> receivedMessages = await _receiver.ReceiveMessagesAsync(maxMessages: 1,maxWaitTime:new TimeSpan(0,30,0));
-                //单条数据 5 分钟未释放。进入死信
                 foreach (ServiceBusReceivedMessage receivedMessage in receivedMessages)
                 {
                     try
                     {
                         string body = receivedMessage.Body.ToString();
+                        var jsonMsg = body.ToObject<BlobRefreshMessage>();
+                        if ( !string.IsNullOrWhiteSpace($"{jsonMsg.root}") && !string.IsNullOrWhiteSpace($"{jsonMsg.name}"))
+                        {
+                            string lockKey = $"Blob:Lock:{jsonMsg.name}:{jsonMsg.root}";
+                            bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
+                            if (exist) {
+                                string[] uls = System.Web.HttpUtility.UrlDecode($"{jsonMsg.root}", Encoding.UTF8).Split("/");
+                                string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
+                                string name = $"{jsonMsg.name}";
+                                await RefreshBlob(name, u);
+                                await _azureRedis.GetRedisClient(8).KeyDeleteAsync(lockKey);
+                            }
+                        }
+                        await _receiver.CompleteMessageAsync(receivedMessage);
                     }
                     catch
                     {
@@ -50,40 +69,9 @@ namespace TEAMModelOS.FunctionV4
                 spinWait.SpinOnce();
             }
         }
+ 
 
-        private async Task<(bool condition, bool exist)> CheckLockKey(string lockKey, long nowTime)
-        {
-            //Redis的最新时间
-            long newestTime = 0;
-            RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(lockKey);
-            if (value != default && !value.IsNullOrEmpty)
-            {
-                JsonElement record = value.ToString().ToObject<JsonElement>();
-                if (record.TryGetInt64(out newestTime))
-                {
-                }
-            }
-            //说明key已经不存在
-            if (newestTime == 0)
-            {
-                return (false, true);
-            }
-            //说明key存在
-            else
-            {
-                //说明Redis记录了最新的时间戳
-                if (nowTime != newestTime)
-                {
-                    return (true, false);
-                }
-                //时间相同,没有被再次记录最新的时间戳
-                else
-                {
-                    await _azureRedis.GetRedisClient(8).KeyDeleteAsync(lockKey);
-                    return (false, true);
-                }
-            }
-        }
+      
         private async Task RefreshBlob(string name, string u)
         {
             long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

+ 3 - 3
TEAMModelOS.SDK/Extension/JwtAuthExtension.cs

@@ -22,7 +22,7 @@ namespace TEAMModelOS.SDK.Extension
                 { JwtRegisteredClaimNames.Iss, issuer }, //發行者
                 { JwtRegisteredClaimNames.Sub, id }, // 用戶ID                  
                 { JwtRegisteredClaimNames.Azp,schoolID}, // 學校簡碼,如果有的話
-                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
+                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds()},  // 到期的時間,必須為數字
                 { "name",name}, // 用戶的顯示名稱
                 { "picture",picture}, // 用戶頭像
                 { "roles",roles}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
@@ -180,7 +180,7 @@ namespace TEAMModelOS.SDK.Extension
                 { JwtRegisteredClaimNames.Azp,schoolID}, // 學校簡碼,如果有的話
                 {JwtRegisteredClaimNames.Jti,Guid.NewGuid().ToString() },
                 { "name",name}, // 用戶的顯示名稱
-                //{ JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
+                //{ JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds()},  // 到期的時間,必須為數字
                 //{ "name",name}, // 用戶的顯示名稱
                 //{ "picture",picture}, // 用戶頭像
                 { "auth",auth}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
@@ -269,7 +269,7 @@ namespace TEAMModelOS.SDK.Extension
             {
                 { JwtRegisteredClaimNames.Iss,issuser}, //发行者
                 { JwtRegisteredClaimNames.Sub,id},   //用户ID
-                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},//到期时间
+                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds()},//到期时间
                 { "name",name},//用户显示名称
                 { "picture",picture}, // 用户头像
                 { "roles",roles}, //登陆者的角色, (admin、dea) 

+ 31 - 0
TEAMModelOS.SDK/Models/Service/Common/BlobService.cs

@@ -1,7 +1,10 @@
 using Azure;
 using Azure.Cosmos;
+using Azure.Messaging.ServiceBus;
 using Azure.Storage.Blobs;
+using DocumentFormat.OpenXml.Wordprocessing;
 using HTEXLib.COMM.Helpers;
+using Microsoft.Extensions.Configuration;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -16,6 +19,28 @@ namespace TEAMModelOS.SDK.Services
 {
     public static class BlobService
     {
+
+        public static async Task RefreshBlobRoot(BlobRefreshMessage message, AzureServiceBusFactory _serviceBus,IConfiguration _configuration,AzureRedisFactory _azureRedis) {
+            if (!string.IsNullOrWhiteSpace(message.root) && !string.IsNullOrWhiteSpace(message.name)) {
+                string lockKey = $"Blob:Lock:{message.name}:{message.root}";
+                bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
+                //不存在Blob:Lock:hbcn:video 文件夹在队列中 则加入队列
+                if (!exist)
+                {
+                    //保持一天的时间
+                    TimeSpan timeSpan = new TimeSpan(1,0,0);
+                    //加入队列的时间
+                    long action = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, action, expiry: timeSpan);
+                    var messageBlob = new ServiceBusMessage(message.ToJsonString());
+                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                }
+                //如果已经存在,则忽略,不加入队列。
+            }
+        }
+        
         public static async Task<UsedBlob> GetBlobUsed(CosmosClient clientc, BlobContainerClient clients, IDatabase clientr, string scope, string containerName)
         {
             UsedBlob result = new UsedBlob();
@@ -152,4 +177,10 @@ namespace TEAMModelOS.SDK.Services
             public int count { get; set; }
         }
     }
+    public class BlobRefreshMessage{ 
+        public string id { get; set; }= Guid.NewGuid().ToString();
+        public string name { get; set; }
+        public string progress { get; set; }
+        public string root { get; set; }
+    }
 }

+ 2 - 2
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -1180,7 +1180,7 @@ namespace TEAMModelOS.SDK
                         });
                     }
                 }
-                /*
+                
                 if (tmdids.IsNotEmpty() && _coreAPIHttpService.check) {
                     ///获取真实的名称 ,大于50则不处理
                     if (tmdids.Count < 60)
@@ -1227,7 +1227,7 @@ namespace TEAMModelOS.SDK
                     }
                    
                 }
-               */
+               
                 tmdids.ForEach(x =>
                 {
                     var user = tmdsData.Find(y => y.id.Equals(x.id));

+ 4 - 7
TEAMModelOS.SDK/Models/Service/HomeworkService.cs

@@ -8,12 +8,13 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.SDK.Models.Service
 {
     public static class HomeworkService
     {
-        public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Homework work, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration)
+        public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Homework work, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, AzureRedisFactory _azureRedis)
         {
             try
             {
@@ -21,15 +22,11 @@ namespace TEAMModelOS.SDK.Models.Service
                 work.code = "Homework-" + work.school;
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 work.createTime = now;
-                var messageBlob = new ServiceBusMessage();
+                
                 string blobcntr = null;
                 blobcntr = work.school;
                 work.size = await _azureStorage.GetBlobContainerClient(work.school).GetBlobsSize($"homework/{work.id}");
-                messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"homework/{work.id}", name = $"{work.school}" }.ToJsonString());
-
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework/{work.id}", name = $"{blobcntr}" }, _serviceBus, _configuration, _azureRedis);
                 work.recordUrl = $"/homework/{work.id}/record.json";
                 var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
                 await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "homework", $"{work.id}/record.json");

+ 3 - 6
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -16,6 +16,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.SDK.Models.Service
 {
@@ -587,7 +588,7 @@ namespace TEAMModelOS.SDK.Models.Service
                 else
                 {
                     ///未设置openAutoClean=1时,则检查学校使用空间是否充足。
-                    var sbm = new List<ServiceBusMessage>();
+                  
                     double usize = 0;
                     int  tsize = schoolBase.tsize;
                     //schoolBase.tsize
@@ -599,11 +600,7 @@ namespace TEAMModelOS.SDK.Models.Service
                     }
                     else //如果檢測不到緩存,觸發刷新計算空間
                     {
-                        var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{schoolBase.id}" }.ToJsonString()); ;
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        sbm.Add(messageBlob);
-                        await _serviceBus.GetServiceBusClient().SendBatchMessageAsync(_configuration.GetValue<string>("Azure:ServiceBus:ActiveTask"), sbm);
-
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{schoolBase.id}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     ///空间充足的情况保存。
                     if (schoolBase.size - usize > 0)

+ 5 - 14
TEAMModelOS/Controllers/Both/ItemController.cs

@@ -17,12 +17,12 @@ using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 
 using HTEXLib.COMM.Helpers;
-using StackExchange.Redis;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.SDK.Services;
 using System.Text.RegularExpressions;
 using TEAMModelOS.Filter;
 
+
 namespace TEAMModelOS.Controllers
 {
     [ProducesResponseType(StatusCodes.Status200OK)]
@@ -228,10 +228,7 @@ namespace TEAMModelOS.Controllers
                 foreach (var itemInfo in itemInfos) {
                     itemInfo.ttl = -1;
                     itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}"  }, _serviceBus, _configuration, _azureRedis);
                     if (option.ToString().Equals("insert"))
                     {
                         itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
@@ -353,10 +350,8 @@ namespace TEAMModelOS.Controllers
                 ItemInfo itemInfo;
                 itemInfo = item.ToObject<ItemInfo>();
                 itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }.ToJsonString());
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+               
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }, _serviceBus, _configuration, _azureRedis);
                 if (option.ToString().Equals("insert"))
                 {
                     itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
@@ -572,11 +567,7 @@ namespace TEAMModelOS.Controllers
                 var client = _azureCosmos.GetCosmosClient();
                 //删除blob 相关资料
                 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");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"item/{id}", name = code.ToString().Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
                 if (scope.ToString().Equals("school"))
                 {
                     ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>($"{id}", new PartitionKey($"{code}"));

+ 7 - 9
TEAMModelOS/Controllers/Both/PaperController.cs

@@ -19,6 +19,8 @@ using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.Filter;
+using TEAMModelOS.SDK.Services;
+using DocumentFormat.OpenXml.Office2010.Excel;
 
 namespace TEAMModelOS.Controllers
 {
@@ -34,9 +36,10 @@ namespace TEAMModelOS.Controllers
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureServiceBusFactory _serviceBus;
         private readonly DingDing _dingDing;
+        private readonly AzureRedisFactory _azureRedis;
 
         public IConfiguration _configuration { get; set; }
-        public PaperController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId,AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration, DingDing dingDing)
+        public PaperController(AzureRedisFactory azureRedis,AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId,AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration, DingDing dingDing)
         {
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
@@ -44,6 +47,7 @@ namespace TEAMModelOS.Controllers
             _serviceBus = serviceBus;
             _configuration = configuration;
             _dingDing = dingDing;
+            _azureRedis = azureRedis;
         }
         /// <summary>
         /// 删除
@@ -69,10 +73,7 @@ namespace TEAMModelOS.Controllers
             //删除blob 相关资料
             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");
-            var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-            await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"paper/{id}", name = code.ToString().Replace("Paper-", "") }, _serviceBus, _configuration, _azureRedis);
             if (scope.ToString().Equals("school"))
             {
                 paper = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Paper>(id.ToString(), new PartitionKey($"{code}"));
@@ -260,10 +261,7 @@ namespace TEAMModelOS.Controllers
             paper = _paper.ToObject<Paper>();            
             paper.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             paper.size = await _azureStorage.GetBlobContainerClient(paper.code).GetBlobsSize($"paper/{paper.id}");
-            var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"paper/{paper.id}", name = $"{paper.code}" }.ToJsonString());
-            messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-            var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-            await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"paper/{paper.id}", name = $"{paper.code}" }, _serviceBus, _configuration, _azureRedis);
             paper.code = "Paper-" + paper.code;
             if (option.ToString().Equals("insert"))
             {

+ 2 - 7
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -211,9 +211,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 else //如果檢測不到緩存,觸發刷新計算空間
                 {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{(sp ? request.school : tid)}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    sbm.Add(messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{(sp ? request.school : tid)}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 //取得學校或個人名單
                 (List<RMember> students, _) = await GroupListService.GetMemberByListids(_coreAPIHttpService, db, _dingDing, new List<string>() { request.sid }, request.school);
@@ -348,10 +346,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 else
                 {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{blobName}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{blobName}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 double blobUsed = blobsize / 1073741824.0 + teach; //1073741824  1G
                 if (tbname == null)

+ 2 - 3
TEAMModelOS/Controllers/Client/HiTeachccControlller.cs

@@ -22,6 +22,7 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.Controllers.Client
 {
@@ -181,9 +182,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 else //如果檢測不到緩存,觸發刷新計算空間
                 {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{(sp ? request.school : tid)}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    sbm.Add(messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{(sp ? request.school : tid)}" }, _serviceBus, _configuration, _azureRedis);
                 }
 
                 //取得學校或個人名單

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

@@ -361,7 +361,7 @@ namespace TEAMModelOS.Controllers
                             homework.tchLists.Add(list.id);
                             //homework.blob = $"/{homework.areaId}/survey/{study.pId}/index.json";
                             //await getMoreWork(pa, homework);
-                            string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework, _serviceBus, _azureStorage, _configuration);
+                            string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework, _serviceBus, _azureStorage, _configuration,_azureRedis);
                             if (string.IsNullOrEmpty(workId))
                             {
                                 return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "作业活动异常" });

+ 9 - 21
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -31,6 +31,7 @@ using DocumentFormat.OpenXml.Wordprocessing;
 using Item = TEAMModelOS.SDK.Models.Cosmos.Common.Item;
 using DocumentFormat.OpenXml.Office2016.Excel;
 using OpenXmlPowerTools;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.Controllers
 {
@@ -184,16 +185,13 @@ namespace TEAMModelOS.Controllers
                     if (request.scope.Equals("school"))
                     {
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.school }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam/{request.id}", name = request.school }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.creatorId }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam/{request.id}", name = request.creatorId }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     int n = 0;
                     List<string> sheetIds = new List<string>();
                     foreach (PaperSimple simple in request.papers)
@@ -220,18 +218,14 @@ namespace TEAMModelOS.Controllers
                         if (request.scope.Equals("school"))
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"exam/{request.id}", name = request.school }.ToJsonString());
-
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"exam/{request.id}", name = request.school }, _serviceBus, _configuration, _azureRedis);
                         }
                         else
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"exam/{request.id}", name = request.creatorId }.ToJsonString());
-
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"exam/{request.id}", name = request.creatorId }, _serviceBus, _configuration, _azureRedis);
                         }
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                        
                         request.progress = info.progress;
                         int n = 0;
                         foreach (PaperSimple simple in request.papers)
@@ -255,16 +249,13 @@ namespace TEAMModelOS.Controllers
                         if (request.scope.Equals("school"))
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.school }.ToJsonString());
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam/{request.id}", name = request.school }, _serviceBus, _configuration, _azureRedis);
                         }
                         else
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.creatorId }.ToJsonString());
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam/{request.id}", name = request.creatorId }, _serviceBus, _configuration, _azureRedis);
                         }
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                         int n = 0;
                         List<string> sheetIds = new List<string>();
                         foreach (PaperSimple simple in request.papers)
@@ -373,10 +364,7 @@ namespace TEAMModelOS.Controllers
                     //删除blob 相关资料
                     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");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"exam/{id}", name = $"{code}" }, _serviceBus, _configuration, _azureRedis);
                     //删除阅卷配置
                     var cresponse = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Correct-{code}"));
                     if (cresponse.Status == 200)

+ 9 - 16
TEAMModelOS/Controllers/Common/HomeworkController.cs

@@ -27,6 +27,8 @@ using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Hosting;
 using Azure.Storage.Blobs.Models;
 using static TEAMModelOS.SDK.SchoolService;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.Controllers.Learn
 {
@@ -111,23 +113,19 @@ namespace TEAMModelOS.Controllers.Learn
                         }
                     }                   
                    // homework.progress = "going";
-                    var messageBlob = new ServiceBusMessage();
                     string blobcntr = null;
                     if (homework.scope.Equals("school"))
                     {
                         blobcntr = homework.school;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.school).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"homework/{homework.id}", name = $"{homework.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework/{homework.id}", name = $"{homework.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = homework.creatorId;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.creatorId).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"homework/{homework.id}", name = $"{homework.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework/{homework.id}", name = $"{homework.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     homework.recordUrl = $"/homework/{homework.id}/record.json";
                     var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
                     await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "homework", $"{homework.id}/record.json");
@@ -137,22 +135,19 @@ namespace TEAMModelOS.Controllers.Learn
                 {
                     string blobcntr = null;
                     var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(homework.id, new PartitionKey($"{homework.code}"));
-                    var messageBlob = new ServiceBusMessage();
                     if (homework.scope.Equals("school"))
                     {
                         blobcntr = homework.school;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.school).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"homework/{homework.id}", name = $"{homework.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"homework/{homework.id}", name = $"{homework.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = homework.creatorId;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.creatorId).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"homework/{homework.id}", name = $"{homework.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"homework/{homework.id}", name = $"{homework.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    
                     if (response.Status == 200)
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -418,10 +413,8 @@ namespace TEAMModelOS.Controllers.Learn
                     //删除blob 相关资料
                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{__code}".Replace("Homework-", ""), new List<string> { Path.Combine("homework", homeworkd.id) + "/" });
                     //通知删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"homework/{homeworkd.id}", name = $"{__code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                 
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"homework/{homeworkd.id}", name = $"{__code}" }, _serviceBus, _configuration, _azureRedis);
                     await _dingDing.SendBotMsg($"{_option.Location}-作业活动【{homeworkd.name}-{homeworkd.id}】被删除", GroupNames.醍摩豆服務運維群組);
                     return Ok(new { flag });
                 }

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

@@ -123,7 +123,7 @@ namespace TEAMModelOS.Controllers.Common
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},study/save()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},study/save()\n{ex.Message}\n{ex.StackTrace}\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
 

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

@@ -109,17 +109,14 @@ namespace TEAMModelOS.Controllers
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"survey/{request.id}", name = $"{request.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"survey/{request.id}", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"survey/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"survey/{request.id}", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     request.recordUrl = $"/survey/{request.id}/record.json";
                     var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
                     await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "survey", $"{request.id}/record.json");
@@ -129,22 +126,18 @@ namespace TEAMModelOS.Controllers
                 {
                     string blobcntr = null;
                     var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
-                    var messageBlob = new ServiceBusMessage();
                     if (request.scope.Equals("school"))
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"survey/{request.id}", name = $"{request.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"survey/{request.id}", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"survey/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"survey/{request.id}", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     if (response.Status == 200)
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -435,10 +428,7 @@ namespace TEAMModelOS.Controllers
                     //删除blob 相关资料
                     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/{survey.id}", name = $"{code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"survey/{survey.id}", name = $"{code}" }, _serviceBus, _configuration, _azureRedis);
                     await _dingDing.SendBotMsg($"{_option.Location}-问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.醍摩豆服務運維群組);
                     return Ok(new { flag });
                 }

+ 10 - 16
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -16,6 +16,7 @@ using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.SDK.Services;
+using DocumentFormat.OpenXml.Office2013.Excel;
 
 namespace TEAMModelOS.Controllers
 {
@@ -91,22 +92,19 @@ namespace TEAMModelOS.Controllers
                     }
                     
                     string blobcntr = null;
-                    var messageBlob = new ServiceBusMessage();
                     if (request.scope.Equals("school"))
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"vote/{request.id}", name = $"{request.school}" }.ToJsonString());                       
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"vote/{request.id}", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"vote/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"vote/{request.id}", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                   
                     string url = $"/vote/{request.id}/record.json";
                     request.recordUrl = url;
                     await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(new { options = new List<string>(), records = new List<VoteRecord>() }.ToJsonString(), "vote", $"{request.id}/record.json");
@@ -115,23 +113,20 @@ namespace TEAMModelOS.Controllers
                 else
                 {
                     var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
-                    var messageBlob = new ServiceBusMessage();
                     string blobcntr = null;
                     if (request.scope.Equals("school"))
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"vote/{request.id}", name = $"{request.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"vote/{request.id}", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"vote/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"vote/{request.id}", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                     
                     if (response.Status == 200)
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -399,10 +394,9 @@ namespace TEAMModelOS.Controllers
                     //删除blob 相关资料
                     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/{vote.id}", name = $"{code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"vote/{vote.id}", name = $"{code}" }, _serviceBus, _configuration, _azureRedis);
+
 
                     return Ok(new { flag });
                 }

+ 12 - 20
TEAMModelOS/Controllers/System/BlobController.cs

@@ -30,6 +30,9 @@ using System.IO;
 using Azure.Storage.Blobs.Models;
 using Azure.Storage.Sas;
 using ContentTypeDict = TEAMModelOS.SDK.ContentTypeDict;
+using TEAMModelOS.SDK.Services;
+using DocumentFormat.OpenXml.Wordprocessing;
+using OpenXmlPowerTools;
 
 namespace TEAMModelOS.Controllers
 {
@@ -442,10 +445,8 @@ namespace TEAMModelOS.Controllers
                     u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                 }
                 if (!string.IsNullOrEmpty(u)) {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = u, name = $"{_cntr}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = u, name = $"{_cntr}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 return Ok(new { status = true });
             }
@@ -593,10 +594,8 @@ namespace TEAMModelOS.Controllers
                     }
                 }
                 root.ToList().ForEach(async x => {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = x, name = $"{name}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                   
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = x, name = $"{name}" }, _serviceBus, _configuration, _azureRedis);
                 });
                 return Ok(new { bloblog, status = 200 });
                  
@@ -643,10 +642,8 @@ namespace TEAMModelOS.Controllers
                 {
                     u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                 }
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = u, name = $"{blobContainerName}" }.ToJsonString()); ;
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+               
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = u, name = $"{blobContainerName}" }, _serviceBus, _configuration, _azureRedis);
                 return Ok(new { status });
             }
             else
@@ -702,10 +699,8 @@ namespace TEAMModelOS.Controllers
                 {
                     u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                 }
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = u, name = $"{blobContainerName}" }.ToJsonString()); ;
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+              
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = u, name = $"{blobContainerName}" }, _serviceBus, _configuration, _azureRedis);
                 return Ok(new { status });
             }
             else
@@ -818,10 +813,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                     root.ToList().ForEach(async x => {
-                        var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = x, name = $"{blobContainerName}" }.ToJsonString()); ;
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = x, name = $"{blobContainerName}" }, _serviceBus, _configuration, _azureRedis);
                     });
                     return Ok(new { status });
                 }

+ 1 - 8
TEAMModelOS/Controllers/Teacher/CommentController.cs

@@ -248,14 +248,7 @@ namespace TEAMModelOS.Controllers
                     classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
                 }
                 await Task.WhenAll(tasks);
-                /* //变更blob 大小
-                 ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new Azure.Cosmos.PartitionKey($"Exam-{school}"));
-                 info.size = await _azureStorage.GetBlobContainerClient(school.ToString()).GetBlobsSize($"exam/{id}");
-                 var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "annotation", root = $"exam/{id}", name = school }.ToJsonString());
-
-                 messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                 var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                 await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);*/
+               
                 return Ok(new { classResult });
             }
             catch (Exception e)

+ 1 - 4
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -2312,10 +2312,7 @@ namespace TEAMModelOS.Controllers
                         size = size.HasValue ? size.Value : 0,
                     };
                     await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog);
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 catch (RequestFailedException ex) when (ex.Status == 404)
                 {