Bladeren bron

优化首页空间

Li 3 jaren geleden
bovenliggende
commit
f3b39a9427
1 gewijzigde bestanden met toevoegingen van 14 en 22 verwijderingen
  1. 14 22
      TEAMModelBI/Controllers/BIHome/HomeStatisController.cs

+ 14 - 22
TEAMModelBI/Controllers/BIHome/HomeStatisController.cs

@@ -698,7 +698,7 @@ namespace TEAMModelBI.Controllers.BIHome
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-sticsbipower  {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-sticsbipower  \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
         }
@@ -720,16 +720,10 @@ namespace TEAMModelBI.Controllers.BIHome
 
                 List<string> schoolId = new();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+
                 //查询学校空间和学校Id
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryStreamIterator(queryText:$"select c.id,c.size from c",requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
-                {
-                    var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    foreach (var tempItem in json.RootElement.GetProperty("Documents").EnumerateArray())
-                    {
-                        totalSize += tempItem.GetProperty("size").GetInt64();
-                        schoolId.Add(tempItem.GetProperty("id").GetString());
-                    }
-                }
+                totalSize = await CommonFind.FindTotals(cosmosClient, "select sum(c.size) as totals from c", "School", "Base");
+                schoolId = await CommonFind.FindSchoolIds(cosmosClient, "select c.id,c.size from c", "Base");
 
                 //查询学校已使用空间大小
                 foreach (var itemId in schoolId)
@@ -748,16 +742,13 @@ namespace TEAMModelBI.Controllers.BIHome
                         }
                     }
 
-                    Dictionary<string, double?> schoolStics = new(); //学校空间
                     long blobsize = 0;
                     RedisValue value = default;
                     value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemId);
                     if (value != default && !value.IsNullOrEmpty)
                     {
                         JsonElement record = value.ToString().ToObject<JsonElement>();
-                        if (record.TryGetInt64(out blobsize))
-                        {
-                        }
+                        if (record.TryGetInt64(out blobsize)){}
                     }
                     else
                     {
@@ -769,15 +760,16 @@ namespace TEAMModelBI.Controllers.BIHome
                             await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemId}", key);
                             await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
                         }
-                        useSize += (long)size.Item1;
-                        schoolStics = size.Item2;
-                        typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
+                        useSize += size.Item1.Value;
+                        typeStics1 = typeStics1.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value));  //lamebda表达式
+                        //typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
                         continue;
                     }
 
                     SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{itemId}");
                     if (Scores != null)
                     {
+                        Dictionary<string, double?> schoolStics = new(); //学校空间
                         foreach (var score in Scores)
                         {
                             double val = score.Score;
@@ -786,10 +778,10 @@ namespace TEAMModelBI.Controllers.BIHome
                         }
 
                         useSize += blobsize;
-                        typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
+                        typeStics1 = typeStics1.Concat(schoolStics).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value));  //lamebda表达式
+                        //typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
                         continue;
 
-                        //return Ok(new { size = blobsize, catalog = catalog, teach });
                     }
                     else
                     {
@@ -802,9 +794,9 @@ namespace TEAMModelBI.Controllers.BIHome
                             await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
                         }
 
-                        useSize += (long)size.Item1;
-                        schoolStics = size.Item2;
-                        typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
+                        useSize += size.Item1.Value;
+                        typeStics1 = typeStics1.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value));  //lamebda表达式
+                        //typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
                         continue;
                     }