HiITEdenX преди 2 години
родител
ревизия
5a7cbd2652
променени са 2 файла, в които са добавени 35 реда и са изтрити 5 реда
  1. 1 1
      TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs
  2. 34 4
      TEAMModelOS.SDK/Models/Service/LessonService.cs

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

@@ -1334,7 +1334,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     lessonRecord.upload = 1;
                                     lessonRecord.upload = 1;
                                     // await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 更新完成", GroupNames.醍摩豆服務運維群組);
                                     // await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 更新完成", GroupNames.醍摩豆服務運維群組);
 
 
-                                    LessonService.DoAutoDeleteSchoolLessonRecord(lessonRecord, scope, client, school, tmdid, teacher, _notificationService, _serviceBus, _azureStorage, _configuration,_coreAPIHttpService,_dingDing);
+                                    LessonService.DoAutoDeleteSchoolLessonRecord(lessonRecord, scope, client, school, tmdid, teacher, _notificationService, _serviceBus, _azureStorage, _configuration,_coreAPIHttpService,_dingDing, _azureRedis);
                                     long? size = await _azureStorage.GetBlobContainerClient(blobname).GetBlobsSize($"records/{_lessonId}");
                                     long? size = await _azureStorage.GetBlobContainerClient(blobname).GetBlobsSize($"records/{_lessonId}");
                                     Bloblog bloblog = new Bloblog
                                     Bloblog bloblog = new Bloblog
                                     {
                                     {

+ 34 - 4
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -1,9 +1,11 @@
-using Azure.Cosmos;
+using Azure.Core;
+using Azure.Cosmos;
 using Azure.Messaging.ServiceBus;
 using Azure.Messaging.ServiceBus;
 using HTEXLib.COMM.Helpers;
 using HTEXLib.COMM.Helpers;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Hosting;
 using OpenXmlPowerTools;
 using OpenXmlPowerTools;
+using StackExchange.Redis;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
@@ -357,7 +359,7 @@ namespace TEAMModelOS.SDK.Models.Service
         }
         }
 
 
         public static async void DoAutoDeleteSchoolLessonRecord(LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
         public static async void DoAutoDeleteSchoolLessonRecord(LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
-            Teacher teacher, NotificationService _notificationService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, CoreAPIHttpService _coreAPIHttpService,DingDing _dingDing)
+            Teacher teacher, NotificationService _notificationService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, CoreAPIHttpService _coreAPIHttpService,DingDing _dingDing,AzureRedisFactory _azureRedis)
         {
         {
             if (lessonRecord.scope.Equals("school"))
             if (lessonRecord.scope.Equals("school"))
             {
             {
@@ -570,8 +572,36 @@ namespace TEAMModelOS.SDK.Models.Service
                 }
                 }
                 else
                 else
                 {
                 {
-                    save = false;
-                    school_lesson_expire = Constant.school_lesson_expire;
+                    ///未设置openAutoClean=1时,则检查学校使用空间是否充足。
+                    var sbm = new List<ServiceBusMessage>();
+                    double usize = 0;
+                    int  tsize = schoolBase.tsize;
+                    //schoolBase.tsize
+                    //計算學校或個人的使用空間
+                    RedisValue redisValue = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{schoolBase.id}");
+                    if (redisValue.HasValue && long.TryParse(redisValue.ToString(), out var bsize))
+                    {
+                        usize = Math.Round(bsize / 1073741824.0 - (tsize), 2, MidpointRounding.AwayFromZero); //1073741824  1G
+                    }
+                    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);
+
+                    }
+                    ///空间充足的情况保存。
+                    if (schoolBase.size - usize > 0)
+                    {
+                        save = true;
+                    }
+                    else {
+                        save = false;
+                        school_lesson_expire = Constant.school_lesson_expire;
+                    }
+
+                   
                 }
                 }
                 if (!save && school_lesson_expire > 0)
                 if (!save && school_lesson_expire > 0)
                 {
                 {