浏览代码

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

liqk 4 年之前
父节点
当前提交
9f95b4c1ef

+ 22 - 5
TEAMModelFunction/ExamTrigger.cs

@@ -20,17 +20,34 @@ namespace TEAMModelFunction
             ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
             ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
             List<ExamClassResult> examClassResults = new List<ExamClassResult>();
             List<ExamClassResult> examClassResults = new List<ExamClassResult>();
             List<ExamSubject> examSubjects = new List<ExamSubject>();
             List<ExamSubject> examSubjects = new List<ExamSubject>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{school}") }))
+            if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
             {
             {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{info.creatorId}") }))
                 {
                 {
-                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                     {
                     {
-                        examClassResults.Add(obj.ToObject<ExamClassResult>());
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            examClassResults.Add(obj.ToObject<ExamClassResult>());
+                        }
+                    }
+                }
+            }
+            else {
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{school}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            examClassResults.Add(obj.ToObject<ExamClassResult>());
+                        }
                     }
                     }
                 }
                 }
             }
             }
+            
 
 
             List<ChangeRecord> records = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", info.progress } });
             List<ChangeRecord> records = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", info.progress } });
             //ChangeRecord record = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
             //ChangeRecord record = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));

+ 14 - 7
TEAMModelFunction/MonitorServicesBus.cs

@@ -151,14 +151,21 @@ namespace TEAMModelFunction
         public async Task Blob([ServiceBusTrigger("active-task", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
         public async Task Blob([ServiceBusTrigger("active-task", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
             try
             try
             {
             {
-                await _dingDing.SendBotMsg($"ServiceBus,Blob(){msg}", GroupNames.醍摩豆服務運維群組);
+               // await _dingDing.SendBotMsg($"ServiceBus,Blob(){msg}", GroupNames.醍摩豆服務運維群組);
                 var jsonMsg = JsonDocument.Parse(msg);
                 var jsonMsg = JsonDocument.Parse(msg);
-                jsonMsg.RootElement.TryGetProperty("code", out JsonElement name);
-                var client = _azureStorage.GetBlobContainerClient($"{name}");
-                var size = await client.GetBlobsCatalogSize();
-                await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record",new RedisValue($"{name}"),new RedisValue($"{long.Parse($"{size.Item1}")}"));
-                await _dingDing.SendBotMsg($"ServiceBus,Blob() 容器:{name}更新大小:{size.Item1}",
-                        GroupNames.醍摩豆服務運維群組);
+                if(jsonMsg.RootElement.TryGetProperty("name", out JsonElement name)&& name.ValueKind==JsonValueKind.String)
+                {
+                    var client = _azureStorage.GetBlobContainerClient($"{name}");
+                    var size = await client.GetBlobsCatalogSize();
+                    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($"ServiceBus,Blob() 容器:{name}使用:{size.Item1},文件分类:{size.Item2.ToJsonString()}",
+                            GroupNames.醍摩豆服務運維群組);
+                }
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {

+ 4 - 0
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -370,6 +370,10 @@ namespace TEAMModelOS.Controllers
                     int newIndex = result.studentIds.IndexOf(studentId.ToString());
                     int newIndex = result.studentIds.IndexOf(studentId.ToString());
                     /*if (flagCount != standard.Count)
                     /*if (flagCount != standard.Count)
                     {*/
                     {*/
+/*                    StringBuilder builder = new StringBuilder();
+                    builder.Append(result.examId + "/");
+                    builder.Append(result.subjectId + "/");
+                    builder.Append(studentId);*/
                         string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
                         string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
                         string blob = FileName + "/" + "ans.json";
                         string blob = FileName + "/" + "ans.json";
                         tasks.Add(_azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json", false));
                         tasks.Add(_azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json", false));

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

@@ -271,6 +271,7 @@ namespace TEAMModelOS.Controllers.Core
             var size = await client.GetBlobsCatalogSize();
             var size = await client.GetBlobsCatalogSize();
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
             foreach (var key in size.Item2.Keys) {
             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 _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue?size.Item2[key].Value:0);
             }
             }
             return Ok(new { size = size.Item1, catalog = size.Item2 });
             return Ok(new { size = size.Item1, catalog = size.Item2 });
@@ -294,6 +295,19 @@ namespace TEAMModelOS.Controllers.Core
             return Ok(new {  urlsSize });
             return Ok(new {  urlsSize });
         }
         }
 
 
+        /*
+         * 
+         {
+            "containerName": "hbcn",
+            "cache": true,
+            "optUrls": [
+                {
+                    "url": "video%2F37Z888piCvm9.mp4",
+                    "size": 1000
+                }
+            ]
+         }
+        */
         /// <summary>
         /// <summary>
         /// 测试单个文本内容的上传
         /// 测试单个文本内容的上传
         /// {"containerName":"hbcn","uploadSize":5000,"optUrls":[{"url":"video/37Z888piCvm9.mp4","size":0},{}]}
         /// {"containerName":"hbcn","uploadSize":5000,"optUrls":[{"url":"video/37Z888piCvm9.mp4","size":0},{}]}
@@ -310,7 +324,6 @@ namespace TEAMModelOS.Controllers.Core
             var client = _azureStorage.GetBlobContainerClient(name);
             var client = _azureStorage.GetBlobContainerClient(name);
             var disSize = urls.Select(x => x.size).Sum();
             var disSize = urls.Select(x => x.size).Sum();
             RedisValue value = default;
             RedisValue value = default;
-            long? useSize = 0;
             long blobSize = 0;
             long blobSize = 0;
             value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
             value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
             if (value != default && !value.IsNullOrEmpty)
             if (value != default && !value.IsNullOrEmpty)
@@ -320,9 +333,13 @@ namespace TEAMModelOS.Controllers.Core
                 {
                 {
                 }
                 }
             }
             }
-            useSize = useSize + disSize;
+            long? useSize = blobSize + disSize;
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
-            var messageBlob = new ServiceBusMessage(new {id=Guid.NewGuid().ToString(), progress = "update",code=name}.ToJsonString());
+             
+            foreach (var x in urls) {
+                await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", System.Web.HttpUtility.UrlDecode(x.url, Encoding.UTF8).Split("/")[0], x.size);
+            }
+            var messageBlob = new ServiceBusMessage(new {id=Guid.NewGuid().ToString(), progress = "update",name=name}.ToJsonString());
             messageBlob.ApplicationProperties.Add("name", "Blob");
             messageBlob.ApplicationProperties.Add("name", "Blob");
             await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageBlob);
             await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageBlob);
             return Ok(new { size=useSize });
             return Ok(new { size=useSize });

+ 0 - 1
TEAMModelOS/TEAMModelOS.csproj

@@ -51,7 +51,6 @@
   <ItemGroup>
   <ItemGroup>
     <Folder Include="JwtRsaFile\" />
     <Folder Include="JwtRsaFile\" />
     <Folder Include="Services\Evaluation\" />
     <Folder Include="Services\Evaluation\" />
-    <Folder Include="wwwroot\" />
   </ItemGroup>
   </ItemGroup>
   
   
   <ItemGroup>
   <ItemGroup>