소스 검색

Merge branch 'PL/develop-BI' into develop

Li 2 년 전
부모
커밋
b0fa8cce6d

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 38 - 3
TEAMModelBI/Controllers/Census/SchoolController.cs


+ 4 - 3
TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs

@@ -500,8 +500,9 @@ namespace TEAMModelBI.Controllers.RepairApi
         {
         {
             jsonElement.TryGetProperty("scId", out JsonElement scId);
             jsonElement.TryGetProperty("scId", out JsonElement scId);
             jsonElement.TryGetProperty("year", out JsonElement _year);
             jsonElement.TryGetProperty("year", out JsonElement _year);
-            var cosmosClient = _azureCosmos.GetCosmosClient();
-            
+            var cosmosClient = _azureCosmos.GetCosmosClient(); 
+            var redisClinet = _azureRedis.GetRedisClient(8);
+
             List<string> scIds = new();
             List<string> scIds = new();
             if (!string.IsNullOrEmpty($"{scId}"))
             if (!string.IsNullOrEmpty($"{scId}"))
                 scIds.Add($"{scId}");
                 scIds.Add($"{scId}");
@@ -532,7 +533,7 @@ namespace TEAMModelBI.Controllers.RepairApi
                     statsInfo.id = $"{year}-{sc}";
                     statsInfo.id = $"{year}-{sc}";
                 }
                 }
 
 
-                statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, sc, year);
+                statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, redisClinet, sc, year);
 
 
                 if (scDataStats.Status == 200)
                 if (scDataStats.Status == 200)
                     taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, $"{year}-{sc}", new PartitionKey("Statistics")));
                     taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, $"{year}-{sc}", new PartitionKey("Statistics")));

+ 2 - 1
TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs

@@ -132,6 +132,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             {
             {
                 string scId = null;
                 string scId = null;
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var redisClinet = _azureRedis.GetRedisClient(8);
                 var tableClient = _azureStorage.GetCloudTableClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
                 var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 string data = await new StreamReader(req.Body).ReadToEndAsync();
                 string data = await new StreamReader(req.Body).ReadToEndAsync();
@@ -164,7 +165,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                     else                    
                     else                    
                         isExist = false;
                         isExist = false;
 
 
-                    statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, scId);
+                    statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient,redisClinet, scId);
                     statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
 
 
                     if (isExist)
                     if (isExist)

+ 14 - 0
TEAMModelOS.SDK/Models/Cosmos/BI/StatsInfo.cs

@@ -40,6 +40,11 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         /// </summary>
         public int size { get; set; }
         public int size { get; set; }
 
 
+        /// <summary>
+        /// 已使用空间
+        /// </summary>
+        public long useSize { get; set; }
+
         /// <summary>
         /// <summary>
         /// 教师总数
         /// 教师总数
         /// </summary>
         /// </summary>
@@ -365,6 +370,15 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         public long upTime { get; set; }
         public long upTime { get; set; }
     }
     }
 
 
+    /// <summary>
+    /// 文件使用情况
+    /// </summary>
+    public class FileSize 
+    {
+        public string name { get; set; }
+        public string socre { get; set; }
+    }
+
 
 
     /// <summary>
     /// <summary>
     /// 课例统计(读取)
     /// 课例统计(读取)

+ 12 - 2
TEAMModelOS.SDK/Models/Service/BIStatsWay/SchoolStatsWay.cs

@@ -4,6 +4,7 @@ using DocumentFormat.OpenXml.Math;
 using MathNet.Numerics.LinearAlgebra.Double;
 using MathNet.Numerics.LinearAlgebra.Double;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Azure.Amqp.Framing;
 using Microsoft.Azure.Amqp.Framing;
+using StackExchange.Redis;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
@@ -26,11 +27,18 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
         /// <param name="cosmosClient"></param>
         /// <param name="cosmosClient"></param>
         /// <param name="scId"></param>
         /// <param name="scId"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static async Task<StatsInfo> GetSingleSc(CosmosClient cosmosClient, string scId, int year = 0)
+        public static async Task<StatsInfo> GetSingleSc(CosmosClient cosmosClient,IDatabase redisClinet, string scId, int year = 0)
         {
         {
             DateTimeOffset dateTime = DateTimeOffset.UtcNow;
             DateTimeOffset dateTime = DateTimeOffset.UtcNow;
             if (year < dateTime.Year)
             if (year < dateTime.Year)
                 dateTime = new(year, 12, 31, 23, 59, 59, TimeSpan.Zero);
                 dateTime = new(year, 12, 31, 23, 59, 59, TimeSpan.Zero);
+            long userSize = 0;
+            RedisValue redisValue = redisClinet.HashGet($"Blob:Record", scId);
+            if (redisValue != default && !redisValue.IsNullOrEmpty)
+            {
+                JsonElement record = redisValue.ToString().ToObject<JsonElement>();
+                if (record.TryGetInt64(out userSize)) { }
+            }
 
 
             StatsInfo statsInfo = new() { id = $"{year}-{scId}" };
             StatsInfo statsInfo = new() { id = $"{year}-{scId}" };
             var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间    13位
             var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间    13位
@@ -62,6 +70,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             statsInfo.scCreateTime = scBase.createTime;
             statsInfo.scCreateTime = scBase.createTime;
             statsInfo.areaId = scBase.areaId;
             statsInfo.areaId = scBase.areaId;
             statsInfo.year = year;
             statsInfo.year = year;
+            statsInfo.useSize = userSize;
 
 
             string tchSql = $"{currSql} where ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'";
             string tchSql = $"{currSql} where ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'";
             statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Teacher-{scBase.id}", tchSql);
             statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Teacher-{scBase.id}", tchSql);
@@ -138,7 +147,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 monthStu = statsInfos.Select(s => s.monthStu).Sum(),
                 monthStu = statsInfos.Select(s => s.monthStu).Sum(),
                 room = statsInfos.Select(s => s.room).Sum(),
                 room = statsInfos.Select(s => s.room).Sum(),
                 witRoom = statsInfos.Select(s => s.witRoom).Sum(),
                 witRoom = statsInfos.Select(s => s.witRoom).Sum(),
-                size = statsInfos.Select(s => s.size).Sum()
+                size = statsInfos.Select(s => s.size).Sum(),
+                useSize = statsInfos.Select(s => s.useSize).Sum()
             };
             };
             areaInfo.lesson.all = statsInfos.Select(s => s.lesson.all).Sum();
             areaInfo.lesson.all = statsInfos.Select(s => s.lesson.all).Sum();
             areaInfo.lesson.open = statsInfos.Select(s => s.lesson.open).Sum();
             areaInfo.lesson.open = statsInfos.Select(s => s.lesson.open).Sum();