浏览代码

调整Blob相关代码

CrazyIter_Bin 4 年之前
父节点
当前提交
a5cf3fafec

+ 24 - 0
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -294,6 +294,7 @@ namespace TEAMModelFunction
             }
             return new OkObjectResult(new { });
         }
+
         /// <summary>
         /// 设置问卷调查未初始化学生列表的业务
         /// </summary>
@@ -470,5 +471,28 @@ namespace TEAMModelFunction
                 return new BadRequestResult();
             }
         }
+        /// <summary>
+        ///获取单个目录的大小,用于获取评测,试题,试卷,问卷,投票等 文件层级超过两层的文件。
+        ///例如 /exam/uuid/xxx  /item/uuid/xxx   /paper/uuid/xxx  /vote/uuid/xxx  /suervy/uuid/xxx
+        /// {""}
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [FunctionName("get-blobsize")]
+        public async Task<IActionResult> GetBlobsize(
+            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
+            ILogger log)
+        {
+            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
+            var data = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(requestBody);
+            if (data.TryGetProperty("name", out JsonElement name)) {
+                await _azureStorage.GetBlobContainerClient($"{name}").GetBlobsSize();
+            }
+           
+            return new OkObjectResult(new { code = 200 });
+        }
+          
     }
+  
 }

+ 34 - 0
TEAMModelFunction/MonitorServicesBus.cs

@@ -144,6 +144,40 @@ namespace TEAMModelFunction
             }
         }
 
+        /*
+         public async Task Blob([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
+            try
+            {
+               // await _dingDing.SendBotMsg($"ServiceBus,Blob(){msg}", GroupNames.醍摩豆服務運維群組);
+                var jsonMsg = JsonDocument.Parse(msg);
+                if(jsonMsg.RootElement.TryGetProperty("name", out JsonElement name)&& name.ValueKind==JsonValueKind.String)
+                {
+                    jsonMsg.RootElement.TryGetProperty("root", out JsonElement root);
+                    List<string> roots= root.ToObject<List<string>>();
+                    List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
+                    foreach (var rt in roots) {
+                        var client = _azureStorage.GetBlobContainerClient($"{name}");
+                        var size = await client.GetBlobsCatalogSize(rt);
+                        list.Add(size.Item2);
+                        await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue($"{name}"), new RedisValue($"{long.Parse($"{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);
+                        }
+                    }
+                    await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:{name}使用:{root},文件分类:{list.ToJsonString()}",
+                            GroupNames.成都开发測試群組);
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+            }
+        }
+         
+         */
+
         /// <summary>
         /// 完善课程变更,StuListChange,  originCode是学校编码 则表示名单是学校自定义名单,如果是tmdid则表示醍摩豆的私有名单,scope=school,private。
         /// </summary>

+ 15 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Bloblog.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models
+{
+    public class Bloblog :CosmosEntity
+    {
+        public string name { get; set; }
+        public string url { get; set; }
+        public string time { get; set; }
+        public long  size { get; set; }
+        public string period { get; set; }
+    }
+}

+ 40 - 9
TEAMModelOS.SDK/Models/Cosmos/School/School.cs

@@ -8,38 +8,69 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.DI;
 
 namespace TEAMModelOS.SDK.Models
-{    
+{
     public class School : CosmosEntity
-    {        
+    {
         public School()
         {
             pk = "Base";
             timeZone = new TimeZone();
             period = new List<Period>();
         }
-        
+
+        /// <summary>
+        /// 学校编码
+        /// </summary>
         public string schoolCode { get; set; }
+        /// <summary>
+        /// 学校名称
+        /// </summary>
         public string name { get; set; }
+        /// <summary>
+        /// 学段
+        /// </summary>
         public List<Period> period { get; set; }
-        public List<Campus> campuses { get; set; }  
-        
+        /// <summary>
+        /// 校区
+        /// </summary>
+        public List<Campus> campuses { get; set; }
+        /// <summary>
+        /// 地区
+        /// </summary>
         public string region { get; set; }
         public string province { get; set; }
+        /// <summary>
+        /// 省份
+        /// </summary>
         public string city { get; set; }
+        /// <summary>
+        ///授权给 学校的Blob 容器空间大小 单位为G
+        ///1252748378/1024/1024/1024
+        ///1GB=1024MB,1MB=1024KB,1KB=1024B  存储最小单位为B字节
+        /// </summary>
         public int size { get; set; }
-
-
+        /// <summary>
+        /// 地址
+        /// </summary>
         public string address { get; set; }
+        /// <summary>
+        /// Logo
+        /// </summary>
         public string picture { get; set; }
-
+        /// <summary>
+        /// 时区
+        /// </summary>
         public TimeZone timeZone { get; set; }
         /// <summary>
         /// 1 普教,2 高职教
         /// </summary>
         public int type { get; set; }
+      
 
     }
-
+    /// <summary>
+    /// 课表计划
+    /// </summary>
     public class TimeTable
     {
         public string id { get; set; }

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

@@ -153,7 +153,7 @@ namespace TEAMModelOS.Controllers.Core
                     await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{blobContainerName}", u);
                     catalog[u] = 0;
                 }
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = blobContainerName }.ToJsonString());
+                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update",root=new string[] { u }, name = blobContainerName }.ToJsonString());
                 messageBlob.ApplicationProperties.Add("name", "Blob");
                 var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
                 await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
@@ -227,9 +227,11 @@ namespace TEAMModelOS.Controllers.Core
                     long? useSize = blobSize + urlSize.Select(x=>x.size).Sum();
                     await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", blobContainerName, useSize);
                     Dictionary<string, double?> catalog = new Dictionary<string, double?>();
+                    HashSet<string> root = new HashSet<string>();
                     foreach (var x in urlSize)
                     {
                         string u = System.Web.HttpUtility.UrlDecode(x.url, Encoding.UTF8).Split("/")[0];
+                        root.Add(u);
                         //释放文件夹空间
                         await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{blobContainerName}", u, -x.size);
                         catalog[u] = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{blobContainerName}", u);
@@ -239,7 +241,7 @@ namespace TEAMModelOS.Controllers.Core
                             catalog[u] = 0;
                         }
                     }
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = blobContainerName }.ToJsonString());
+                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = root.ToArray(), name = blobContainerName }.ToJsonString());
                     messageBlob.ApplicationProperties.Add("name", "Blob");
                     var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
                     await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
@@ -427,8 +429,10 @@ namespace TEAMModelOS.Controllers.Core
             long? useSize = blobSize + disSize;
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
             Dictionary<string, double?> catalog = new Dictionary<string, double?>();
+            HashSet<string> root = new HashSet<string>();
             foreach (var x in urls) {
                 string u = System.Web.HttpUtility.UrlDecode(x.url, Encoding.UTF8).Split("/")[0];
+                root.Add(u);
                 await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, x.size);
                 catalog[u]= await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{name}", u);
                 if (catalog[u] < 0) {
@@ -436,7 +440,7 @@ namespace TEAMModelOS.Controllers.Core
                     catalog[u] = 0;
                 }
             }
-            var messageBlob = new ServiceBusMessage(new {id=Guid.NewGuid().ToString(), progress = "update",name=name}.ToJsonString());
+            var messageBlob = new ServiceBusMessage(new {id=Guid.NewGuid().ToString(), progress = "update", root= root.ToArray(), name=name}.ToJsonString());;
             messageBlob.ApplicationProperties.Add("name", "Blob");
             var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
             await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);

+ 1 - 1
TEAMModelOS/TEAMModelOS.csproj

@@ -22,7 +22,7 @@
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="DotNetZip" Version="1.15.0" />
-    <PackageReference Include="HTEXLib" Version="2.5.5" />
+    <PackageReference Include="HTEXLib" Version="2.5.6" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
     <PackageReference Include="VueCliMiddleware" Version="5.0.0" />
   </ItemGroup>