Przeglądaj źródła

Merge branch 'develop5.0-tmd' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop5.0-tmd

liqk 4 lat temu
rodzic
commit
a964b1084e

+ 22 - 16
TEAMModelFunction/MonitorServicesBus.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using Azure.Cosmos;
@@ -143,31 +144,37 @@ namespace TEAMModelFunction
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
             }
         }
-
-        /*
-         public async Task Blob([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
+        /// <summary>
+        /// 根据容器的根目录刷新redis并获取redis的最新使用情况
+        /// </summary>
+        /// <param name="msg"></param>
+        /// <returns></returns>
+         public async Task BlobRoot([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blobroot", 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)
+                if (jsonMsg.RootElement.TryGetProperty("name", out JsonElement name) && name.ValueKind == JsonValueKind.String
+                    && jsonMsg.RootElement.TryGetProperty("root", out JsonElement root) && root.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)
+                    string u = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/")[0];
+                    var client = _azureStorage.GetBlobContainerClient($"{name}");
+                    var size = await client.GetBlobsSize(u);
+                    await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
+                    await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
+                    var scores=  await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
+                    double blobsize = 0;
+                    if (scores != default &&scores!=null) {
+                        foreach (var score in scores)
                         {
-                            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);
+                            blobsize = blobsize + score.Score;
                         }
                     }
+                    await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue($"{name}"), new RedisValue($"{blobsize}"));
+
                     await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:{name}使用:{root},文件分类:{list.ToJsonString()}",
-                            GroupNames.成都开发測試群組);
+                        GroupNames.成都开发測試群組);
                 }
             }
             catch (Exception ex)
@@ -176,7 +183,6 @@ namespace TEAMModelFunction
             }
         }
          
-         */
 
         /// <summary>
         /// 完善课程变更,StuListChange,  originCode是学校编码 则表示名单是学校自定义名单,如果是tmdid则表示醍摩豆的私有名单,scope=school,private。

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

@@ -4,6 +4,9 @@ using System.Text;
 
 namespace TEAMModelOS.SDK.Models
 {
+    /// <summary>
+    /// 内容上传记录
+    /// </summary>
     public class Bloblog :CosmosEntity
     {
         public string name { get; set; }

+ 16 - 4
TEAMModelOS/Controllers/School/StudentController.cs

@@ -1815,13 +1815,25 @@ namespace TEAMModelOS.Controllers
                         await foreach (var item in teacherClient.GetItemQueryStreamIterator(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("StuList") }))
                         {
                             using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                            var js = json.RootElement.ToJsonString();
                             if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                             {
                                 foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                                 {
-                                    string courseCode = obj.GetProperty("courseCode").ToString();
-                                    string courseId = obj.GetProperty("courseId").ToString();
-                                    string stulistId = obj.GetProperty("id").ToString();
+                                    string courseCode = "";
+                                    if (obj.TryGetProperty("courseCode", out var code)) {
+                                        courseCode = code.GetString();
+                                    }
+                                    string courseId = "";
+                                    if (obj.TryGetProperty("courseCode", out var cosid))
+                                    {
+                                        courseId = cosid.GetString();
+                                    }
+                                    string stulistId = "";
+                                    if (obj.TryGetProperty("courseCode", out var listId))
+                                    {
+                                        stulistId = listId.GetString();
+                                    }
                                     if (!stulistidsTea.ContainsKey(courseCode))
                                     {
                                         Dictionary<string, string> pCourseIdDic = new Dictionary<string, string>();
@@ -1887,7 +1899,7 @@ namespace TEAMModelOS.Controllers
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/login()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/login()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
         }