CrazyIter_Bin %!s(int64=2) %!d(string=hai) anos
pai
achega
42bf0ffb95

+ 8 - 8
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -133,7 +133,6 @@ namespace TEAMModelOS.FunctionV4
                     tag = 0;
                 }
                
-                string notifyCode = string.Empty;
                 List<IdNameCode> ids = new List<IdNameCode>();
                 Teacher teacher = null;
                 School school = null;
@@ -141,7 +140,6 @@ namespace TEAMModelOS.FunctionV4
                 if (scope.Equals("school", StringComparison.OrdinalIgnoreCase))
                 {
                     school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(name, new PartitionKey("Base"));
-                    notifyCode = "blob-space-school-notify";
                     string sql = $"select   value c from c    where c.code='Teacher-{name}' and c.status='join'  and  array_contains(c.roles,'admin') ";
                     List<SchoolTeacher> adminTeachers = new List<SchoolTeacher>();
                     await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
@@ -163,7 +161,6 @@ namespace TEAMModelOS.FunctionV4
                 }
                 else
                 {
-                    notifyCode = "blob-space-private-notify";
                     teacher=  await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(name, new PartitionKey("Base"));
                     ids.Add(new IdNameCode
                     {
@@ -188,9 +185,6 @@ namespace TEAMModelOS.FunctionV4
 
                         if (blobSpaceNotify == null)
                         {
-                            blobSpaceNotify = new BlobSpaceNotify { };
-                            await _azureRedis.GetRedisClient(8).HashSetAsync(key, name, blobSpaceNotify.ToJsonString());
-
                             if ("school".Equals(scope, StringComparison.OrdinalIgnoreCase))
                             {
                                 _coreAPIHttpService.PushNotify(ids, $"blob-space-school-notify", Constant.NotifyType_IES5_Management,
@@ -204,6 +198,9 @@ namespace TEAMModelOS.FunctionV4
                                     new Dictionary<string, object> { { "tmdname", name }, { "percent", $"{tag}" }, { "tmdid", idnamecode.id } },
                                     $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
                             }
+                            blobSpaceNotify = new BlobSpaceNotify { id = idnamecode.id, tag = tag, containerName = name, scope = scope, notifyIndex = Guid.NewGuid().ToString() };
+                            await _azureRedis.GetRedisClient(8).HashSetAsync(key, name, blobSpaceNotify.ToJsonString());
+                            await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(hours:7*24,minutes:0,seconds:0));
                         }
                         else { 
                             //已经发送过的不在提交
@@ -216,13 +213,16 @@ namespace TEAMModelOS.FunctionV4
                             //撤销
                             var index =  blobSpaceNotify.notifyIndex;
                             await _azureRedis.GetRedisClient(8).HashDeleteAsync(key, filed);
+                            _coreAPIHttpService.CancelNotify(index, $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration);
                         }
-                        //等撤销
+                        
                     }
                 }
                
             }
-            catch (Exception ex) { }
+            catch (Exception ex) {
+                await  _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},空间不足,通知发送处理异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
             return response;
         }
 

+ 1 - 1
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1638,7 +1638,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     if (scope.Equals("private"))
                                     {
                                         int lessonLimit = teacher.lessonLimit;
-                                        var space= await BlobService.GetSurplusSpace(tmdid, scope, _option, _azureCosmos, _azureRedis, _azureStorage, _dingDing);
+                                        var space= await BlobService.GetSurplusSpace(tmdid, scope, $"{Environment.GetEnvironmentVariable("Option:Location")}", _azureCosmos, _azureRedis, _azureStorage, _dingDing,_httpTrigger);
                                         //20230208调整之前  if (blobTotal * 1073741824 - blobsize > 2147483648)  //剩余空间大于2G 
                                         //剩余空间不足,则开启自动清理机制
                                         if (space .surplus> 0)

+ 42 - 0
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -185,7 +185,47 @@ namespace TEAMModelOS.SDK
             }
 
         }
+        /// <summary>
+        /// 撤销通知
+        /// </summary>
+        /// <param name="indexNums"></param>
+        /// <param name="location"></param>
+        /// <param name="_configuration"></param>
+        public async void CancelNotify(string indexNums,  string location, IConfiguration _configuration)
+        {
 
+            var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
+            var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
+            var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
+            if (location.Contains("China"))
+            {
+                location = "China";
+            }
+            else if (location.Contains("Global"))
+            {
+                location = "Global";
+            }
+            var client = _httpClient;
+            var token =await CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, location);
+            if (client.DefaultRequestHeaders.Contains("Authorization"))
+            {
+                client.DefaultRequestHeaders.Remove("Authorization");
+                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
+            }
+            else
+            {
+                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
+            }
+            HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{url}/service/DelNotify", new { indexNums= new List<string> { indexNums } });
+            if (responseMessage.StatusCode == HttpStatusCode.OK)
+            {
+                string content = await responseMessage.Content.ReadAsStringAsync();
+                
+            }
+            else
+            {
+            }
+        }
         /*
         hubName	string	Optional	指定要傳送到哪個訊息中樞,若沒給則不傳送端外通知,只會發送端內通知。(目前只有"hita"及"hita5"能使用)
         sender	string	Optional	發送訊息的來源端
@@ -397,6 +437,8 @@ namespace TEAMModelOS.SDK
             }
         }
 
+
+        
         /// <summary>
         /// BI发送端外通知消息
         /// </summary>

+ 6 - 4
TEAMModelOS.SDK/Models/Service/Common/BlobService.cs

@@ -21,6 +21,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Service;
+using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
 
 namespace TEAMModelOS.SDK.Services
 {
@@ -54,7 +55,8 @@ namespace TEAMModelOS.SDK.Services
         /// <param name="scope"></param>
         /// <param name="_azureCosmos"></param>
         /// <param name="_azureRedis"></param>
-        public static async Task<(long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog)> GetSurplusSpace(string name, string scope,Option _option, AzureCosmosFactory _azureCosmos, AzureRedisFactory _azureRedis, AzureStorageFactory _azureStorage,DingDing _dingDing )
+        public static async Task<(long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog)> 
+            GetSurplusSpace(string name, string scope,string location, AzureCosmosFactory _azureCosmos, AzureRedisFactory _azureRedis, AzureStorageFactory _azureStorage,DingDing _dingDing, HttpTrigger _httpTrigger)
         {
             //已经存储的空间
             long usedSize = 0;
@@ -176,14 +178,14 @@ namespace TEAMModelOS.SDK.Services
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"IES5,{_option.Location},blob/used-space()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"IES5,{location},blob/used-space()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return (usedSize, teach, total, surplus, catalog);
             }
             if (usedSize > 0 && total > 0) {
 
                 double percent = surplus / total * 1073741824 * 100;
-
-
+                //
+                _ = _httpTrigger.RequestHttpTrigger(new { }, location, "surplus-space-notify");
             }
             return (usedSize, teach, total, surplus, catalog);
         }

+ 2 - 2
TEAMModelOS/Controllers/Client/HiTAControlller.cs

@@ -257,7 +257,7 @@ namespace TEAMModelOS.Controllers.Client
                             var clientss = _azureStorage.GetBlobContainerClient(schoolCodeNow);
                             //Blob使用狀況
                             //UsedBlob schoolUsedBlob = await BlobService.GetBlobUsed(clientc, clientss, clientr, "school", schoolCodeNow);
-                            (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) schoolUsedBlob = await BlobService.GetSurplusSpace(schoolCodeNow, "school", _option, _azureCosmos, _azureRedis, _azureStorage, _dingDing);
+                            (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) schoolUsedBlob = await BlobService.GetSurplusSpace(schoolCodeNow, "school", _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing,_httpTrigger);
 
                             //管理者名單
                             List<Dictionary<string, string>> adminList = new List<Dictionary<string, string>>();
@@ -379,7 +379,7 @@ namespace TEAMModelOS.Controllers.Client
                     size.total = Convert.ToInt64(size.total) * 1073741824;
 
                     ////個人空間使用狀況
-                    (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) teacherUsedBlob = await BlobService.GetSurplusSpace(id, "private", _option, _azureCosmos, _azureRedis, _azureStorage, _dingDing);
+                    (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) teacherUsedBlob = await BlobService.GetSurplusSpace(id, "private", _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing,_httpTrigger);
                    // UsedBlob teacherUsedBlob = await BlobService.GetBlobUsed(clientc, clientst, clientr, "private", id);
                     size.used = teacherUsedBlob.usedSize;
                     foreach (KeyValuePair<string, double?> blobCatalog in teacherUsedBlob.catalog)

+ 1 - 1
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -205,7 +205,7 @@ namespace TEAMModelOS.Controllers.Client
                         size += st.size;
                     }
                 }
-                (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) space = await BlobService.GetSurplusSpace($"{(sp ? request.school : tid)}", request.sp, _option, _azureCosmos, _azureRedis, _azureStorage, _dingDing);
+                (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) space = await BlobService.GetSurplusSpace($"{(sp ? request.school : tid)}", request.sp, _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing,_httpTrigger);
                 //計算學校或個人的使用空間
                 //  RedisValue redisValue = r8.HashGet($"Blob:Record", $"{(sp ? request.school : tid)}");
                 if (space.usedSize>0)

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

@@ -40,7 +40,7 @@ namespace TEAMModelOS.Controllers.Client
         private readonly IConfiguration _configuration;
         private readonly SnowflakeId _snowflakeId;
         private readonly CoreAPIHttpService _coreAPIHttpService;
-
+        private readonly HttpTrigger _httpTrigger;
         public HiTeachccControlller(
             AzureStorageFactory azureStorage,
             AzureRedisFactory azureRedis,
@@ -50,8 +50,9 @@ namespace TEAMModelOS.Controllers.Client
             IConfiguration configuration,
             SnowflakeId snowflakeId,
             CoreAPIHttpService coreAPIHttpService,
-            IOptionsSnapshot<Option> option)
+            IOptionsSnapshot<Option> option, HttpTrigger httpTrigger)
         {
+            _httpTrigger = httpTrigger;
             _azureStorage = azureStorage;
             _azureRedis = azureRedis;
             _azureCosmos = azureCosmos;
@@ -174,7 +175,7 @@ namespace TEAMModelOS.Controllers.Client
                 {
                     (uri, sas) = _azureStorage.GetBlobContainerSAS(request.school, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
                 }
-                (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) space = await BlobService.GetSurplusSpace($"{(sp ? request.school : tid)}", request.sp, _option, _azureCosmos, _azureRedis, _azureStorage, _dingDing);
+                (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) space = await BlobService.GetSurplusSpace($"{(sp ? request.school : tid)}", request.sp, _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing,_httpTrigger);
                 //計算學校或個人的使用空間
                 
                 if (space.usedSize>0)

+ 4 - 2
TEAMModelOS/Controllers/System/BlobController.cs

@@ -48,8 +48,9 @@ namespace TEAMModelOS.Controllers
         private readonly DingDing _dingDing;
         private readonly Option _option;
         private readonly AzureCosmosFactory _azureCosmos;
+        private readonly HttpTrigger _httpTrigger;
         public IConfiguration _configuration { get; set; }
-        public BlobController(AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IHttpClientFactory clientFactory, AzureRedisFactory azureRedis, IConfiguration configuration,
+        public BlobController(HttpTrigger httpTrigger, AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IHttpClientFactory clientFactory, AzureRedisFactory azureRedis, IConfiguration configuration,
             DingDing dingDing,
             IOptionsSnapshot<Option> option, AzureCosmosFactory azureCosmos)
         {
@@ -61,6 +62,7 @@ namespace TEAMModelOS.Controllers
             _dingDing = dingDing;
             _option = option?.Value;
             _azureCosmos = azureCosmos;
+            _httpTrigger = httpTrigger;
         }
         /// <summary>
         /// 上传文件到指定的0-public
@@ -232,7 +234,7 @@ namespace TEAMModelOS.Controllers
         {
             request.TryGetProperty("scope", out JsonElement _scope);
             if (!request.TryGetProperty("containerName", out JsonElement containerName)) return BadRequest();
-            (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog)space =await BlobService.GetSurplusSpace(containerName.ToString(), $"{_scope}",_option, _azureCosmos, _azureRedis, _azureStorage,_dingDing);
+            (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog)space =await BlobService.GetSurplusSpace(containerName.ToString(), $"{_scope}",_option.Location, _azureCosmos, _azureRedis, _azureStorage,_dingDing,_httpTrigger);
             return Ok(new { size = space.usedSize, catalog = space.catalog, teach=space. teach , surplus = space.surplus, total=space.total });
         }