ソースを参照

优化统计接口雏形

Li 2 年 前
コミット
37728f817e

+ 10 - 0
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -1245,6 +1245,16 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { state = 200, linqTests, set });
             return Ok(new { state = 200, linqTests, set });
         }
         }
 
 
+        [HttpPost("set-addreducestats")]
+        public async Task<IActionResult> SetAddReduceStats(JsonElement jsonElement) 
+        {
+
+
+
+            return Ok(new { state = 200 });
+        }
+
+
         /// <summary>
         /// <summary>
         /// 多个连接字符串方式
         /// 多个连接字符串方式
         /// </summary>
         /// </summary>

+ 25 - 25
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -594,31 +594,31 @@ namespace TEAMModelBI.Controllers.Census
                     }
                     }
                 }
                 }
 
 
-                if(statsInfo.upTime > 0 && !isnew) {
-                    long timedis = 20 * 60 * 1000;//20分钟
-                    if (now - statsInfo.upTime < timedis)
-                        isnew = true;
-                }
-                if (statsInfo.upTime == 0 && isnew)
-                    statsInfo.upTime = now;
-                if (statsInfo.upTime == 0 && isnew)
-                    statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
-                if (!isnew)
-                {
-                    //Function 处理Function 更新或者新增
-                    //_ = _httpTrigger.RequestHttpTrigger(new { schoolId = $"{school.id}"}, _option.Location, "stats-sc-info");
-
-                    //异步方法处理 同步更新
-                    statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, school.id);
-
-                    statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                    if (isExist)
-                        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats"));
-                    else
-                        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));
-                }
-
-                return Ok(new { state = RespondCode.Ok, statsInfo });
+                //if(statsInfo.upTime > 0 && !isnew) {
+                //    long timedis = 20 * 60 * 1000;//20分钟
+                //    if (now - statsInfo.upTime < timedis)
+                //        isnew = true;
+                //}
+                //if (statsInfo.upTime == 0 && isnew)
+                //    statsInfo.upTime = now;
+                //if (statsInfo.upTime == 0 && isnew)
+                //    statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
+                //if (!isnew)
+                //{
+                //    //Function 处理Function 更新或者新增
+                //    //_ = _httpTrigger.RequestHttpTrigger(new { schoolId = $"{school.id}"}, _option.Location, "stats-sc-info");
+
+                //    //异步方法处理 同步更新
+                //    statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, school.id);
+
+                //    statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                //    if (isExist)
+                //        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats"));
+                //    else
+                //        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));
+                //}
+
+                return Ok(new { state = RespondCode.Ok, scStats });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {

+ 38 - 0
TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs

@@ -23,6 +23,7 @@ using Pipelines.Sockets.Unofficial.Arenas;
 using TEAMModelBI.Tool;
 using TEAMModelBI.Tool;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using static TEAMModelBI.Controllers.Census.SchoolController;
 
 
 namespace TEAMModelBI.Controllers.RepairApi
 namespace TEAMModelBI.Controllers.RepairApi
 {
 {
@@ -479,5 +480,42 @@ namespace TEAMModelBI.Controllers.RepairApi
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// 修复所有学校统计数据中间件接口
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("set-allscstats")]
+        public async Task<IActionResult> SetAllScStats(JsonElement jsonElement) 
+        {
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
+
+            foreach (var sc in scId) 
+            {
+                StatsInfo statsInfo = new();
+                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey("Stats"));
+                if (scDataStats.Status == 200)
+                {
+                    using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
+                    statsInfo = fileJson.ToObject<StatsInfo>();
+                }
+                else
+                {
+                    statsInfo.id = sc;
+                }
+
+
+
+            }
+
+
+
+
+
+            return Ok(new { state = 200 });
+        }
+
     }
     }
 }
 }

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

@@ -207,7 +207,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                 {
                 {
                     type = $"{_type}";
                     type = $"{_type}";
                 }
                 }
-                if (string.IsNullOrEmpty(scId) && string.IsNullOrEmpty(scId))
+                if (string.IsNullOrEmpty(scId) && string.IsNullOrEmpty(type))
                 {
                 {
                     await _dingDing.SendBotMsg($"set-scstats-type, {req.Body};转换后:{json}", GroupNames.成都开发測試群組);
                     await _dingDing.SendBotMsg($"set-scstats-type, {req.Body};转换后:{json}", GroupNames.成都开发測試群組);
                     return response;
                     return response;

+ 29 - 0
TEAMModelOS.SDK/Models/Service/BIStatsWay/LessonRecordStatsWay.cs

@@ -1,4 +1,5 @@
 using Azure.Cosmos;
 using Azure.Cosmos;
+using DocumentFormat.OpenXml.Office2010.PowerPoint;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
@@ -38,6 +39,34 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 
 
             var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
             var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
             var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year");         //计算今年开始/结束时间
             var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year");         //计算今年开始/结束时间
+
+            List<LessonRecord> lessonRecords = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonRecord>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{id}") })) 
+            {
+                
+            
+            }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
             string currSql = "select value(count(c.id)) from c  where c.pk='LessonRecord'";
             string currSql = "select value(count(c.id)) from c  where c.pk='LessonRecord'";
             lessStats.open = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 0", code: $"LessonRecord-{id}");
             lessStats.open = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 0", code: $"LessonRecord-{id}");

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

@@ -68,6 +68,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             statsInfo.room = await JointlySingleQuery.GetValueInt(cosmosClient, "School", currSql, code: $"Room-{scBase.id}");
             statsInfo.room = await JointlySingleQuery.GetValueInt(cosmosClient, "School", currSql, code: $"Room-{scBase.id}");
             statsInfo.witRoom = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} where (c.serial != null or c.serial != '' or IS_DEFINED(c.serial) = true)", code: $"Room-{scBase.id}");
             statsInfo.witRoom = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} where (c.serial != null or c.serial != '' or IS_DEFINED(c.serial) = true)", code: $"Room-{scBase.id}");
 
 
+            //statsInfo.lesson = 
+
             statsInfo.lesson = await LessonRecordStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
             statsInfo.lesson = await LessonRecordStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
             statsInfo.activity = await ActivityStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
             statsInfo.activity = await ActivityStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
             statsInfo.study = await StudyStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
             statsInfo.study = await StudyStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);