|
@@ -34,7 +34,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly NotificationService _notificationService;
|
|
private readonly NotificationService _notificationService;
|
|
|
|
|
|
- public SchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis, IConfiguration configuration, NotificationService notificationService)
|
|
|
|
|
|
+ public SchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis, IConfiguration configuration, NotificationService notificationService)
|
|
{
|
|
{
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
_dingDing = dingDing;
|
|
_dingDing = dingDing;
|
|
@@ -51,14 +51,14 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[HttpPost("get-notarea")]
|
|
[HttpPost("get-notarea")]
|
|
- public async Task<IActionResult> GetNotAreaSchool()
|
|
|
|
|
|
+ public async Task<IActionResult> GetNotAreaSchool()
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
string sqltxt = $"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period FROM c WHERE c.standard=null";
|
|
string sqltxt = $"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period FROM c WHERE c.standard=null";
|
|
List<NotAreaSchool> notAreaSchools = new List<NotAreaSchool>();
|
|
List<NotAreaSchool> notAreaSchools = new List<NotAreaSchool>();
|
|
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
@@ -99,7 +99,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[AuthToken(Roles = "assist")]
|
|
[AuthToken(Roles = "assist")]
|
|
[HttpPost("set-schooljoinarea")]
|
|
[HttpPost("set-schooljoinarea")]
|
|
- public async Task<IActionResult> SetSchoolJoinArea(JsonElement jsonElement)
|
|
|
|
|
|
+ public async Task<IActionResult> SetSchoolJoinArea(JsonElement jsonElement)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -112,13 +112,13 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
List<string> schoolCodes = _schoolCode.ToObject<List<string>>();
|
|
List<string> schoolCodes = _schoolCode.ToObject<List<string>>();
|
|
|
|
|
|
var cosmosCliet = _azureCosmos.GetCosmosClient();
|
|
var cosmosCliet = _azureCosmos.GetCosmosClient();
|
|
-
|
|
|
|
- if (schoolCodes.Count > 0)
|
|
|
|
|
|
+
|
|
|
|
+ if (schoolCodes.Count > 0)
|
|
{
|
|
{
|
|
- foreach (var tempCode in schoolCodes)
|
|
|
|
|
|
+ foreach (var tempCode in schoolCodes)
|
|
{
|
|
{
|
|
- School school = await cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(tempCode,new PartitionKey("Base"));
|
|
|
|
- if (school != null)
|
|
|
|
|
|
+ School school = await cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(tempCode, new PartitionKey("Base"));
|
|
|
|
+ if (school != null)
|
|
{
|
|
{
|
|
school.standard = $"{standard}";
|
|
school.standard = $"{standard}";
|
|
school.areaId = $"{_areaId}";
|
|
school.areaId = $"{_areaId}";
|
|
@@ -144,13 +144,13 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- [HttpPost("get-assustschool")]
|
|
|
|
|
|
+ [HttpPost("get-assistschool")]
|
|
public async Task<IActionResult> GetAssistSchool(JsonElement jsonElement)
|
|
public async Task<IActionResult> GetAssistSchool(JsonElement jsonElement)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
-
|
|
|
|
|
|
+
|
|
List<object> schools = new List<object>();
|
|
List<object> schools = new List<object>();
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
//List<string> schoolIds = new List<string>();
|
|
//List<string> schoolIds = new List<string>();
|
|
@@ -182,7 +182,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
- await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-assustschool {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-assustschool \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -205,7 +205,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
if (rsponse.Status == 200)
|
|
if (rsponse.Status == 200)
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(rsponse.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(rsponse.ContentStream);
|
|
- School school = json.ToObject<School>();
|
|
|
|
|
|
+ School school = json.ToObject<School>();
|
|
|
|
|
|
return Ok(new { state = 200, school });
|
|
return Ok(new { state = 200, school });
|
|
}
|
|
}
|
|
@@ -215,7 +215,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
- await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-schoolid {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-schoolid \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -257,8 +257,8 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
}
|
|
}
|
|
await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
|
|
await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
|
|
}
|
|
}
|
|
- schoolInfo = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<School>(school,school.id, new PartitionKey($"Base"));
|
|
|
|
-
|
|
|
|
|
|
+ schoolInfo = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey($"Base"));
|
|
|
|
+
|
|
//保存操作记录
|
|
//保存操作记录
|
|
await _azureStorage.SaveBILog("school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
|
|
await _azureStorage.SaveBILog("school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
|
|
}
|
|
}
|
|
@@ -309,18 +309,19 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- [HttpPost("get-space")]
|
|
|
|
- public async Task<IActionResult> GetAssistSchoolSpace(JsonElement jsonElement)
|
|
|
|
|
|
+ [HttpPost("get-assistspace")]
|
|
|
|
+ public async Task<IActionResult> GetAssistSchoolSpace(JsonElement jsonElement)
|
|
{
|
|
{
|
|
if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+
|
|
List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
- List<SchoolSpace> schoolSpaces = new List<SchoolSpace>();
|
|
|
|
|
|
+ List<SchoolSpace> schoolSpaces = new();
|
|
foreach (var sid in schools)
|
|
foreach (var sid in schools)
|
|
{
|
|
{
|
|
School school = new();
|
|
School school = new();
|
|
var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(sid, new PartitionKey("Base"));
|
|
var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(sid, new PartitionKey("Base"));
|
|
- if (response.Status == 200)
|
|
|
|
|
|
+ if (response.Status == 200)
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
school = json.ToObject<School>();
|
|
school = json.ToObject<School>();
|
|
@@ -340,7 +341,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- SchoolSpace schoolSpace = new SchoolSpace() { id = sid, name = school != null ? school.name : sid };
|
|
|
|
|
|
+ SchoolSpace schoolSpace = new() { id = sid, name = school != null ? school.name : sid };
|
|
|
|
|
|
Space space = new Space();
|
|
Space space = new Space();
|
|
long blobsize = 0; //使用大小
|
|
long blobsize = 0; //使用大小
|
|
@@ -354,7 +355,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
var client = _azureStorage.GetBlobContainerClient(sid);
|
|
var client = _azureStorage.GetBlobContainerClient(sid);
|
|
var size = await client.GetBlobsCatalogSize();
|
|
var size = await client.GetBlobsCatalogSize();
|
|
@@ -398,8 +399,8 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{sid}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{sid}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
}
|
|
}
|
|
|
|
|
|
- space.useSize = (long)size.Item1;
|
|
|
|
- space.tSize = teach;
|
|
|
|
|
|
+ space.useSize = (long)size.Item1;
|
|
|
|
+ space.tSize = teach;
|
|
space.catalogSize = size.Item2;
|
|
space.catalogSize = size.Item2;
|
|
schoolSpace.space = space;
|
|
schoolSpace.space = space;
|
|
schoolSpaces.Add(schoolSpace);
|
|
schoolSpaces.Add(schoolSpace);
|
|
@@ -429,7 +430,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
{
|
|
{
|
|
schoolTeacher.roles.Remove("assist");
|
|
schoolTeacher.roles.Remove("assist");
|
|
SchoolTeacher newSchoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<SchoolTeacher>($"{_shiftTeacher}", new PartitionKey($"Teacher-{_school}"));
|
|
SchoolTeacher newSchoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<SchoolTeacher>($"{_shiftTeacher}", new PartitionKey($"Teacher-{_school}"));
|
|
- if (!newSchoolTeacher.roles.Contains("assist"))
|
|
|
|
|
|
+ if (!newSchoolTeacher.roles.Contains("assist"))
|
|
{
|
|
{
|
|
newSchoolTeacher.roles.Add("assist");
|
|
newSchoolTeacher.roles.Add("assist");
|
|
newSchoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(newSchoolTeacher, $"{_shiftTeacher}", new PartitionKey($"Teacher-{_school}"));
|
|
newSchoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(newSchoolTeacher, $"{_shiftTeacher}", new PartitionKey($"Teacher-{_school}"));
|
|
@@ -452,7 +453,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
};
|
|
};
|
|
|
|
|
|
- if (notification != null)
|
|
|
|
|
|
+ if (notification != null)
|
|
{
|
|
{
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
@@ -474,7 +475,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[HttpPost("get-schoolmanage")]
|
|
[HttpPost("get-schoolmanage")]
|
|
- public async Task<IActionResult> GetSchoolManage(JsonElement jsonElement)
|
|
|
|
|
|
+ public async Task<IActionResult> GetSchoolManage(JsonElement jsonElement)
|
|
{
|
|
{
|
|
if (!jsonElement.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("isAdmin", out JsonElement isAdmin)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("isAdmin", out JsonElement isAdmin)) return BadRequest();
|
|
@@ -512,7 +513,6 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
return Ok(new { state = 200, schoolTeachers });
|
|
return Ok(new { state = 200, schoolTeachers });
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 设置学校管理员
|
|
/// 设置学校管理员
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -575,7 +575,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/set-schoolme \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/set-schoolme \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -610,32 +610,167 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
return Ok(new { state = 200, schools });
|
|
return Ok(new { state = 200, schools });
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 修改学校的结构
|
|
|
|
|
|
+ /// 依据区域Id查询区域空间统计
|
|
/// </summary>
|
|
/// </summary>
|
|
- public record ReplaceSchool()
|
|
|
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-spance")]
|
|
|
|
+ public async Task<IActionResult> GetAreaSpace(JsonElement jsonElement)
|
|
{
|
|
{
|
|
- /// <summary>
|
|
|
|
- /// 醍摩豆账户ID
|
|
|
|
- /// </summary>
|
|
|
|
- public string tmdId { get; set; }
|
|
|
|
|
|
+ jsonElement.TryGetProperty("areaId", out JsonElement areaId);
|
|
|
|
+ jsonElement.TryGetProperty("schoolId", out JsonElement schoolId);
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+ long allSize = 0; //全部大小
|
|
|
|
+ int teacherSpace = 0; //学校分配给教师的空间
|
|
|
|
+ long useSize = 0; //已使用大小
|
|
|
|
+ Dictionary<string, double?> useSpaceInfo = new(); //学校使用详情
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 醍摩豆账户名称
|
|
|
|
- /// </summary>
|
|
|
|
- public string tmdName { get; set; }
|
|
|
|
|
|
+ //查询区域所有学校
|
|
|
|
+ if (!string.IsNullOrEmpty($"{areaId}"))
|
|
|
|
+ {
|
|
|
|
+ List<string> schools = new();
|
|
|
|
+ schools = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.areaId='{areaId}'", "Base");
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 学校
|
|
|
|
- /// </summary>
|
|
|
|
- public School school { get; set; }
|
|
|
|
|
|
+ allSize = await CommonFind.FindTotals(cosmosClient, $"select sum(c.size) as totals from c where c.areaId='{areaId}'", new List<string> { "School" }); //区域所有学校空间
|
|
|
|
+
|
|
|
|
+ foreach (var school in schools)
|
|
|
|
+ {
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"SELECT sum(c.size) as size FROM c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
|
|
|
|
+ {
|
|
|
|
+ var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
+ foreach (var elmt in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
+ {
|
|
|
|
+ if (elmt.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
|
|
|
|
+ {
|
|
|
|
+ teacherSpace += _size.GetInt32();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ long blobsize = 0;
|
|
|
|
+ RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{school}");
|
|
|
|
+ if (!value.IsNullOrEmpty)
|
|
|
|
+ {
|
|
|
|
+ JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
|
+ if (record.TryGetInt64(out blobsize))
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var storageClient = _azureStorage.GetBlobContainerClient("school");
|
|
|
|
+ var size = await storageClient.GetBlobsCatalogSize();
|
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{school}", size.Item1);
|
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
|
+ {
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Bolb:Catalog:{school}", key);
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Bolb:Catalog:school", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ useSize += size.Item1.Value;
|
|
|
|
+ useSpaceInfo = useSpaceInfo.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
|
|
|
|
+ //useSpaceInfo = (from e in useSpaceInfo.Concat(size.Item2) group e by e.Key into g select new { Name = g.Key, value = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.value); //linq 方式合并
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{school}");
|
|
|
|
+ if (Scores != null)
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, double?> catalog = new();
|
|
|
|
+ foreach (var score in Scores)
|
|
|
|
+ {
|
|
|
|
+ double val = score.Score;
|
|
|
|
+ string key = score.Element.ToString();
|
|
|
|
+ catalog.Add(key, val);
|
|
|
|
+ }
|
|
|
|
+ useSpaceInfo = useSpaceInfo.Concat(catalog).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
|
|
|
|
+ //useSpaceInfo = (from e in useSpaceInfo.Concat(catalog) group e by e.Key into g select new { Name = g.Key, value = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.value); //linq 方式合并
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var client = _azureStorage.GetBlobContainerClient("school");
|
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{school}", size.Item1);
|
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
|
+ {
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{school}", key);
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{school}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
|
+ }
|
|
|
|
+ useSize += size.Item1.Value;
|
|
|
|
+ useSpaceInfo = useSpaceInfo.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
|
|
|
|
+ //useSpaceInfo = (from e in useSpaceInfo.Concat(size.Item2) group e by e.Key into g select new { Name = g.Key, value = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.value); //linq 方式合并
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询学校
|
|
|
|
+ if (!string.IsNullOrEmpty($"{schoolId}"))
|
|
|
|
+ {
|
|
|
|
+ allSize = await CommonFind.FindTotals(cosmosClient, $"SELECT c.size as totals FROM c where c.id='{schoolId}'", "School", "Base");
|
|
|
|
+
|
|
|
|
+ teacherSpace = await CommonFind.FindTotals(cosmosClient, $"SELECT sum(c.size) as totals FROM c", "School", $"Teacher-{schoolId}");
|
|
|
|
+
|
|
|
|
+ long blobsize = 0;
|
|
|
|
+ RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{schoolId}");
|
|
|
|
+ if (!value.IsNullOrEmpty)
|
|
|
|
+ {
|
|
|
|
+ JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
|
+ if (record.TryGetInt64(out blobsize))
|
|
|
|
+ {
|
|
|
|
+ useSize = blobsize;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var storageClient = _azureStorage.GetBlobContainerClient("school");
|
|
|
|
+ var size = await storageClient.GetBlobsCatalogSize();
|
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{schoolId}", size.Item1);
|
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
|
+ {
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Bolb:Catalog:{schoolId}", key);
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Bolb:Catalog:school", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
|
+ }
|
|
|
|
+ useSpaceInfo = size.Item2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Dictionary<string, double?> catalog = new();
|
|
|
|
+ SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{schoolId}");
|
|
|
|
+ if (Scores != null)
|
|
|
|
+ {
|
|
|
|
+ foreach (var score in Scores)
|
|
|
|
+ {
|
|
|
|
+ double val = score.Score;
|
|
|
|
+ string key = score.Element.ToString();
|
|
|
|
+ catalog.Add(key, val);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ useSpaceInfo = catalog;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var client = _azureStorage.GetBlobContainerClient("school");
|
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{schoolId}", size.Item1);
|
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
|
+ {
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{schoolId}", key);
|
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{schoolId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ useSize = size.Item1.Value;
|
|
|
|
+ useSpaceInfo = size.Item2;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = 200, allSize, useSize, teacherSpace, useSpaceInfo });
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 未加入区域的学校
|
|
/// 未加入区域的学校
|
|
/// </summary>
|
|
/// </summary>
|
|
- public record NotAreaSchool
|
|
|
|
|
|
+ public record NotAreaSchool
|
|
{
|
|
{
|
|
public string id { get; set; }
|
|
public string id { get; set; }
|
|
|
|
|
|
@@ -657,7 +792,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 学校空间使用情况
|
|
/// 学校空间使用情况
|
|
/// </summary>
|
|
/// </summary>
|
|
- public record SchoolSpace
|
|
|
|
|
|
+ public record SchoolSpace
|
|
{
|
|
{
|
|
public string id { get; set; }
|
|
public string id { get; set; }
|
|
|
|
|
|
@@ -669,7 +804,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 空间
|
|
/// 空间
|
|
/// </summary>
|
|
/// </summary>
|
|
- public record Space
|
|
|
|
|
|
+ public record Space
|
|
{
|
|
{
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 已使用空间
|
|
/// 已使用空间
|