|
@@ -1,4 +1,4 @@
|
|
|
-using Microsoft.Azure.Cosmos;
|
|
|
+using Microsoft.Azure.Cosmos;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Newtonsoft.Json;
|
|
@@ -18,6 +18,8 @@ using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using Azure.Storage.Blobs.Models;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.XTest
|
|
@@ -27,9 +29,11 @@ namespace TEAMModelOS.Controllers.XTest
|
|
|
public class BusinessController : ControllerBase
|
|
|
{
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
public BusinessController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, DingDing dingDing)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
}
|
|
|
/// <summary>
|
|
|
///
|
|
@@ -219,5 +223,61 @@ namespace TEAMModelOS.Controllers.XTest
|
|
|
return Ok(new { status = 500 });
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //取的特定Blob容器的使用量
|
|
|
+ [HttpPost("get-blob-list-size")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ public async Task<IActionResult> GetBlobListSize(JsonElement json)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!json.TryGetProperty("container", out JsonElement containerName))
|
|
|
+ {
|
|
|
+ return Ok(new { msg = "参数错误" });
|
|
|
+ }
|
|
|
+
|
|
|
+ //文件夹(关联id)导向的文件夹 exam homework art records survey vote item
|
|
|
+ string[] prefixDirId = new string[] { "exam", "homework", "art", "records", "survey", "vote", "item" };
|
|
|
+ HashSet<string> ids = new HashSet<string>();
|
|
|
+ Dictionary<string, List<KeyValuePair<string, long?>>> recordUrls = new Dictionary<string, List<KeyValuePair<string, long?>>>(); //單位:bytes
|
|
|
+ foreach (string prefix in prefixDirId)
|
|
|
+ {
|
|
|
+ await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
|
|
|
+ {
|
|
|
+ var path = blobItem.Name.Split("/");
|
|
|
+ if (path.Length > 2)
|
|
|
+ {
|
|
|
+ string id = path[0];
|
|
|
+ ids.Add(id);
|
|
|
+ if (recordUrls.ContainsKey(id))
|
|
|
+ {
|
|
|
+ recordUrls[id].Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ recordUrls[id] = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //資料整理
|
|
|
+ Dictionary<string, long> result = new Dictionary<string, long>();
|
|
|
+ foreach (KeyValuePair<string, List<KeyValuePair<string, long?>>> rec in recordUrls)
|
|
|
+ {
|
|
|
+ foreach (KeyValuePair<string, long?> recVal in rec.Value)
|
|
|
+ {
|
|
|
+ if (result.ContainsKey(rec.Key))
|
|
|
+ {
|
|
|
+ result[rec.Key] += (long)Convert.ToDouble(recVal.Value);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result.Add(rec.Key, (long)Convert.ToDouble(recVal.Value));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { result });
|
|
|
+ }
|
|
|
}
|
|
|
}
|