Browse Source

优化统计接口。

Li 2 years ago
parent
commit
98f56a57b8

File diff suppressed because it is too large
+ 153 - 11
TEAMModelBI/Controllers/BITest/TestController.cs


+ 66 - 11
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -552,6 +552,7 @@ namespace TEAMModelBI.Controllers.Census
                     scStats.size = statsInfo.size;
                     scStats.scCreateTime = statsInfo.scCreateTime;
                     scStats.upTime = statsInfo.upTime;
+                    scStats.lessStats.open = statsInfo.lesson.all;
                     scStats.lessStats.open = statsInfo.lesson.open;
                     scStats.lessStats.less = statsInfo.lesson.less;
                     scStats.lessStats.lastDay = statsInfo.lesson.lastDay;
@@ -654,23 +655,16 @@ namespace TEAMModelBI.Controllers.Census
                 return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{areaId};相关的学区,请检查!" });
 
             List<string> scIds = new();
-            //scIds.Contains
             string scSql = $"select value(c.id) from c where c.areaId='{areaId}'";
-
             scIds = await CommonFind.FindScIds(cosmosClient, scSql, "Base");
-
-            //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<string>(queryText: scSql,requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")} ))
-            //{
-            //    scIds.Add(item);
-            //}
-
             StringBuilder statsSql = new("select value(c) from c");
             if (scIds.Count > 0) 
             {
                 statsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds)}");
             }
 
-            List<ScStats> scStats = new();
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            List<ScStats> scStatss = new();
             List<StatsInfo> statsInfos = new();
             await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryIterator<StatsInfo>(queryText:statsSql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Stats") }))
             {
@@ -678,9 +672,69 @@ namespace TEAMModelBI.Controllers.Census
             }
 
             StatsInfo statsInfo = new();
-            statsInfo = await SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds);
+            statsInfo = await SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds, area);
+            if (!string.IsNullOrEmpty(statsInfo.id))
+            {
+                areaScStats.id = statsInfo.id;
+                areaScStats.name = statsInfo.name;
+                areaScStats.picture = statsInfo.picture;
+                areaScStats.tch = statsInfo.tch;
+                areaScStats.dayTch = statsInfo.dayTch;
+                areaScStats.weekTch = statsInfo.weekTch;
+                areaScStats.monthTch = statsInfo.monthTch;
+                areaScStats.stu = statsInfo.stu;
+                areaScStats.dayStu = statsInfo.dayStu;
+                areaScStats.weekStu = statsInfo.weekStu;
+                areaScStats.monthStu = statsInfo.monthStu;
+                areaScStats.room = statsInfo.room;
+                areaScStats.witRoom = statsInfo.witRoom;
+                areaScStats.size = statsInfo.size;
+                areaScStats.scCreateTime = statsInfo.scCreateTime;
+                areaScStats.upTime = statsInfo.upTime;
+                areaScStats.lessStats.open = statsInfo.lesson.all;
+                areaScStats.lessStats.open = statsInfo.lesson.open;
+                areaScStats.lessStats.less = statsInfo.lesson.less;
+                areaScStats.lessStats.lastDay = statsInfo.lesson.lastDay;
+                areaScStats.lessStats.day = statsInfo.lesson.day;
+                areaScStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
+                areaScStats.lessStats.week = statsInfo.lesson.week;
+                areaScStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
+                areaScStats.lessStats.term = statsInfo.lesson.term;
+                areaScStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
+                areaScStats.lessStats.dayInter = statsInfo.lesson.dayInter;
+                areaScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
+                areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
+                areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
+                areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
+                areaScStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
+                areaScStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
+                areaScStats.actStats.cnt = statsInfo.activity.cnt;
+                areaScStats.actStats.exam = statsInfo.activity.exam;
+                areaScStats.actStats.survey = statsInfo.activity.survey;
+                areaScStats.actStats.vote = statsInfo.activity.vote;
+                areaScStats.actStats.homework = statsInfo.activity.homework;
+                areaScStats.actStats.lastDay = statsInfo.activity.lastDay;
+                areaScStats.actStats.dayCnt = statsInfo.activity.dayCnt;
+                areaScStats.actStats.lastWeek = statsInfo.activity.lastWeek;
+                areaScStats.actStats.week = statsInfo.activity.week;
+                areaScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
+                areaScStats.actStats.term = statsInfo.activity.term;
+                areaScStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear, dateTime.Year, dateTime.Month);
+                areaScStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
+                if (statsInfo.study != null)
+                {
+                    areaScStats.srStats.learnTime = statsInfo.study.learnTime;
+                    areaScStats.srStats.online = statsInfo.study.online;
+                    areaScStats.srStats.offline = statsInfo.study.offline;
+                    areaScStats.srStats.classRoom = statsInfo.study.classRoom;
+                    areaScStats.srStats.submit = statsInfo.study.submit;
+                    areaScStats.srStats.notStarted = statsInfo.study.notStarted;
+                    areaScStats.srStats.ongoing = statsInfo.study.ongoing;
+                    areaScStats.srStats.finish = statsInfo.study.finish;
+                }
+            }
 
-            return Ok(new { state = RespondCode.Ok ,area, statsInfo, scIds });
+            return Ok(new { state = RespondCode.Ok ,areaScStats });
         }
 
         /// <summary>
@@ -796,6 +850,7 @@ namespace TEAMModelBI.Controllers.Census
         /// </summary>
         public record ScLessStats
         {
+            public int all { get; set; }
             public int open { get; set; }
             public int less { get; set; }
             public int lastDay { get; set; }

+ 43 - 10
TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs

@@ -24,6 +24,10 @@ using TEAMModelBI.Tool;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using static TEAMModelBI.Controllers.Census.SchoolController;
+using DocumentFormat.OpenXml.Math;
+using TEAMModelOS.SDK.Models.Service.BI;
+using TEAMModelBI.Tool.CosmosBank;
+using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 
 namespace TEAMModelBI.Controllers.RepairApi
 {
@@ -402,10 +406,16 @@ namespace TEAMModelBI.Controllers.RepairApi
         {
             try
             {
+                jsonElement.TryGetProperty("scId", out JsonElement scId);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
-                List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
+                List<string> scIds = new();
+                if (!string.IsNullOrEmpty($"{scId}"))
+                    scIds.Add($"{scId}");
+                else
+                    scIds = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
+
                 List<BIRelation> scInfos = new();
-                foreach (var itemId in scId)
+                foreach (var itemId in scIds)
                 {
                     BIRelation bIRelation = null;
                     var resRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("BIRel"));
@@ -471,7 +481,7 @@ namespace TEAMModelBI.Controllers.RepairApi
                     scInfos.Add(bIRelation);
                 }
 
-                return Ok(new { state = RespondCode.Ok, cnt = scId.Count, scInfos });
+                return Ok(new { state = RespondCode.Ok, cnt = scIds.Count, scInfos });
             }
             catch (Exception ex)
             {
@@ -489,13 +499,21 @@ namespace TEAMModelBI.Controllers.RepairApi
         [HttpPost("set-allscstats")]
         public async Task<IActionResult> SetAllScStats(JsonElement jsonElement) 
         {
+            jsonElement.TryGetProperty("scId", out JsonElement scId);
             var cosmosClient = _azureCosmos.GetCosmosClient();
-            List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
+            
+            List<string> scIds = new();
+            if (!string.IsNullOrEmpty($"{scId}"))
+                scIds.Add($"{scId}");
+            else
+                scIds = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
 
-            foreach (var sc in scId) 
+            List<StatsInfo> statsInfos = new();
+            List<Task<ItemResponse<StatsInfo>>> taskStss = new();
+            foreach (var sc in scIds) 
             {
                 StatsInfo statsInfo = new();
-                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey("Stats"));
+                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{sc}", new PartitionKey("Stats"));
                 if (scDataStats.Status == 200)
                 {
                     using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
@@ -506,15 +524,30 @@ namespace TEAMModelBI.Controllers.RepairApi
                     statsInfo.id = sc;
                 }
 
+                statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, sc);
 
+                if (scDataStats.Status == 200)
+                    taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, sc, new PartitionKey("Stats")));
+                else
+                    taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats")));
 
+                //statsInfo = await StatsWay.upSingleSc(cosmosClient, sc);
+                statsInfos.Add(statsInfo);
             }
 
+            if (taskStss.Count < 256)
+                await Task.WhenAll(taskStss);
+            else 
+            {
+                int pages = (taskStss.Count + 255) / 256;
+                for (int i = 0; i < pages; i++)
+                {
+                    List<Task<ItemResponse<StatsInfo>>> temTaskStss = taskStss.Skip(i * 256).Take(256).ToList();
+                    await Task.WhenAll(temTaskStss);
+                }
+            }
 
-
-
-
-            return Ok(new { state = 200 });
+            return Ok(new { state = RespondCode.Ok, statsInfos });
         }
 
     }

+ 298 - 83
TEAMModelBI/Tool/CosmosBank/StatsWay.cs

@@ -2,13 +2,22 @@
 using DocumentFormat.OpenXml.Bibliography;
 using DocumentFormat.OpenXml.Math;
 using DocumentFormat.OpenXml.Office2010.Excel;
+using Microsoft.OData.Edm;
 using NUnit.Framework.Constraints;
+using OpenXmlPowerTools;
 using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Models;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BITable;
 using TEAMModelOS.SDK.Models.Service.BI;
+using TEAMModelOS.SDK.Models.Service.BIStatsWay;
+using static TEAMModelBI.Tool.CosmosBank.StatsWay;
 
 namespace TEAMModelBI.Tool.CosmosBank
 {
@@ -50,38 +59,36 @@ namespace TEAMModelBI.Tool.CosmosBank
             statsInfo.picture = scBase.picture;
             statsInfo.size = scBase.size;
             statsInfo.scCreateTime = scBase.createTime;
+            statsInfo.areaId = scBase.areaId;
 
             string tchSql = $"{currSql} where ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'";
-            statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", tchSql, code: $"Teacher-{scBase.id}");
-            statsInfo.dayTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and {dayWhereSql} ", code: $"Teacher-{scBase.id}");
-            statsInfo.weekTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and  {weekWhereSql}", code: $"Teacher-{scBase.id}");
-            statsInfo.monthTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and  {monthWhereSql}", code: $"Teacher-{scBase.id}");
+            statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", tchSql, $"Teacher-{scBase.id}");
+            statsInfo.dayTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and {dayWhereSql} ", $"Teacher-{scBase.id}");
+            statsInfo.weekTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and  {weekWhereSql}", $"Teacher-{scBase.id}");
+            statsInfo.monthTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and  {monthWhereSql}", $"Teacher-{scBase.id}");
 
-            statsInfo.stu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", currSql, code: $"Base-{scBase.id}");
-            statsInfo.dayStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {dayWhereSql}", code: $"Base-{scBase.id}");
-            statsInfo.weekStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {weekWhereSql}", code: $"Base-{scBase.id}");
-            statsInfo.monthStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {monthWhereSql}", code: $"Base-{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.stu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", currSql, $"Base-{scBase.id}");
+            statsInfo.dayStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {dayWhereSql}", $"Base-{scBase.id}");
+            statsInfo.weekStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {weekWhereSql}", $"Base-{scBase.id}");
+            statsInfo.monthStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {monthWhereSql}", $"Base-{scBase.id}");
 
+            statsInfo.room = await JointlySingleQuery.GetValueInt(cosmosClient, "School", currSql, $"Room-{scBase.id}");
+            statsInfo.witRoom = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} where (c.serial != null or c.serial != '' or IS_DEFINED(c.serial) = true)", $"Room-{scBase.id}");
 
             statsInfo.lesson = await GetLessStats(cosmosClient, statsInfo.id);
             statsInfo.activity = await GetActStats(cosmosClient, statsInfo.id);
-
-
-
+            statsInfo.study = await GetStudyStats(cosmosClient, statsInfo.id);
 
             return statsInfo;
         }
 
 
-       /// <summary>
-       /// 课例
-       /// </summary>
-       /// <param name="cosmosClient"></param>
-       /// <param name="id"></param>
-       /// <returns></returns>
+        /// <summary>
+        /// 课例
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="id"></param>
+        /// <returns></returns>
         public static async Task<LessonStats> GetLessStats(CosmosClient cosmosClient, string id) 
         {
             LessonStats lessStats = new();
@@ -104,47 +111,88 @@ namespace TEAMModelBI.Tool.CosmosBank
             var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year");         //计算今年开始/结束时间
 
             string currSql = "select value(count(c.id)) from c  where c.pk='LessonRecord'";
+            lessStats.all = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql}", code: $"LessonRecord-{id}");
             lessStats.open = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 0", code: $"LessonRecord-{id}");
             lessStats.less = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 1", code: $"LessonRecord-{id}");
 
+            List<LessRelStats> lessRelStats = new();
+            string sql = $"select c.id,c.code,c.startTime,c.clientInteractionCount from c where c.pk='LessonRecord' and c.startTime >= {lastYearS} and c.startTime <= {yearE}";
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessRelStats>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{id}") })) 
+            {
+                lessRelStats.Add(item);
+            }
+
+            lessStats.lastDay = lessRelStats.FindAll(f => f.startTime >= lastDayS && f.startTime <= lastdayE).ToList().Count;
+            lessStats.day = lessRelStats.FindAll(f => f.startTime >= dayS && f.startTime <= dayE).ToList().Count;
+            lessStats.lastWeek = lessRelStats.FindAll(f => f.startTime >= lastWeekS && f.startTime <= lastWeekE).ToList().Count;
+            lessStats.week = lessRelStats.FindAll(f => f.startTime >= weekS && f.startTime <= weekE).ToList().Count;
+            lessStats.lastTerm = lessRelStats.FindAll(f => f.startTime >= lastTermS && f.startTime <= lastTermE).ToList().Count;
+            lessStats.term = lessRelStats.FindAll(f => f.startTime >= termS && f.startTime <= termE).ToList().Count;
+
+            lessStats.lastDayInter = lessRelStats.FindAll(f => f.startTime >= lastDayS && f.startTime <= lastdayE).ToList().Select(s=>s.clientInteractionCount).Sum();
+            lessStats.dayInter = lessRelStats.FindAll(f => f.startTime >= dayS && f.startTime <= dayS).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.lastMonthInter = lessRelStats.FindAll(f => f.startTime >= lastWeekS && f.startTime <= lastWeekE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.monthInter = lessRelStats.FindAll(f => f.startTime >= weekS && f.startTime <= weekS).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.lastYearInter = lessRelStats.FindAll(f => f.startTime >= lastTermS && f.startTime <= lastTermE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.yearInter = lessRelStats.FindAll(f => f.startTime >= termS && f.startTime <= termE).ToList().Select(s => s.clientInteractionCount).Sum();
+
+            DateTimeOffset lyearDay = new(DateTimeOffset.UtcNow.Year - 1, DateTimeOffset.UtcNow.Month, DateTimeOffset.UtcNow.Day, DateTimeOffset.UtcNow.Hour, DateTimeOffset.UtcNow.Minute, DateTimeOffset.UtcNow.Second, TimeSpan.Zero);
+            List<StartEndTime> leveryDay = TimeHelper.GetYearEveryDay(lyearDay);
+            List<StartEndTime> everyDay = TimeHelper.GetYearEveryDay(DateTimeOffset.UtcNow);
+
+            for (int i = 0; i < leveryDay.Count; i++)
+            {
+                if (lessStats.LastYear.Count == 366)
+                    lessStats.LastYear[i] = (double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count;
+                else
+                    lessStats.LastYear.Add((double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count);
+            }
 
-            string lastDaySql = $"{currSql} and c.startTime >= {lastDayS} and c.startTime <= {lastDayS}";
-            lessStats.lastDay = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDaySql, code: $"LessonRecord-{id}");
+            for (int i = 0; i < everyDay.Count; i++)
+            {
+                if (lessStats.year.Count == 366)
+                    lessStats.year[i] = lessRelStats.FindAll(f => (f.startTime >= everyDay[i].start && f.startTime <= everyDay[i].end)).Count;
+                else
+                    lessStats.year.Add(lessRelStats.FindAll(f => (f.startTime >= everyDay[i].start && f.startTime <= everyDay[i].end)).Count);
+            }
 
-            string daySql = $"{currSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
-            lessStats.day = await JointlySingleQuery.GetValueInt(cosmosClient, "School", daySql, code: $"LessonRecord-{id}");
+            //string lastDaySql = $"{currSql} and c.startTime >= {lastDayS} and c.startTime <= {lastDayS}";
+            //lessStats.lastDay = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDaySql, code: $"LessonRecord-{id}");
 
-            string lastWeekSql = $"{currSql}  and c.startTime >= {lastWeekS} and c.startTime <= {lastWeekE}";
-            lessStats.lastWeek = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastWeekSql, code: $"LessonRecord-{id}");
+            //string daySql = $"{currSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
+            //lessStats.day = await JointlySingleQuery.GetValueInt(cosmosClient, "School", daySql, code: $"LessonRecord-{id}");
 
-            string weekSql = $"{currSql}  and c.startTime >= {weekS} and c.startTime <= {weekE}";
-            lessStats.week = await JointlySingleQuery.GetValueInt(cosmosClient, "School", weekSql, code: $"LessonRecord-{id}");
+            //string lastWeekSql = $"{currSql}  and c.startTime >= {lastWeekS} and c.startTime <= {lastWeekE}";
+            //lessStats.lastWeek = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastWeekSql, code: $"LessonRecord-{id}");
 
-            string lastTermSql = $"{currSql} and c.startTime >= {lastTermS} and c.startTime <= {lastTermE}";
-            lessStats.lastTerm = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastTermSql, code: $"LessonRecord-{id}");
+            //string weekSql = $"{currSql}  and c.startTime >= {weekS} and c.startTime <= {weekE}";
+            //lessStats.week = await JointlySingleQuery.GetValueInt(cosmosClient, "School", weekSql, code: $"LessonRecord-{id}");
 
-            string termSql = $"{currSql} and c.startTime >= {termS} and c.startTime <= {termE}";
-            lessStats.term = await JointlySingleQuery.GetValueInt(cosmosClient, "School", termSql, code: $"LessonRecord-{id}");
+            //string lastTermSql = $"{currSql} and c.startTime >= {lastTermS} and c.startTime <= {lastTermE}";
+            //lessStats.lastTerm = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastTermSql, code: $"LessonRecord-{id}");
 
+            //string termSql = $"{currSql} and c.startTime >= {termS} and c.startTime <= {termE}";
+            //lessStats.term = await JointlySingleQuery.GetValueInt(cosmosClient, "School", termSql, code: $"LessonRecord-{id}");
 
-            string InterSql = "select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
-            string lastDayInterSql = $"{InterSql} and c.startTime >= {lastDayS} and c.startTime <= {lastdayE}";
-            lessStats.lastDayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDayInterSql, code: $"LessonRecord-{id}");
 
-            string dayInterSql = $"{InterSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
-            lessStats.dayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", dayInterSql, code: $"LessonRecord-{id}");
+            //string InterSql = "select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
+            //string lastDayInterSql = $"{InterSql} and c.startTime >= {lastDayS} and c.startTime <= {lastdayE}";
+            //lessStats.lastDayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDayInterSql, code: $"LessonRecord-{id}");
 
-            string lastMthInterSql = $"{InterSql} and c.startTime >= {lastMthS} and c.startTime <= {LastmthE}";
-            lessStats.lastMonthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastMthInterSql, code: $"LessonRecord-{id}");
+            //string dayInterSql = $"{InterSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
+            //lessStats.dayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", dayInterSql, code: $"LessonRecord-{id}");
 
-            string mthInterSql = $"{InterSql} and c.startTime >= {mthS} and c.startTime <= {mthE}";
-            lessStats.monthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", mthInterSql, code: $"LessonRecord-{id}");
+            //string lastMthInterSql = $"{InterSql} and c.startTime >= {lastMthS} and c.startTime <= {LastmthE}";
+            //lessStats.lastMonthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastMthInterSql, code: $"LessonRecord-{id}");
 
-            string lastYearInterSql = $"{InterSql} and c.startTime >= {lastYearS} and c.startTime <= {lastYearE}";
-            lessStats.lastYearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastYearInterSql, code: $"LessonRecord-{id}");
+            //string mthInterSql = $"{InterSql} and c.startTime >= {mthS} and c.startTime <= {mthE}";
+            //lessStats.monthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", mthInterSql, code: $"LessonRecord-{id}");
 
-            string yearInterSql = $"{InterSql} and c.startTime >= {yearS} and c.startTime <= {yearE}";
-            lessStats.yearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", yearInterSql, code: $"LessonRecord-{id}");
+            //string lastYearInterSql = $"{InterSql} and c.startTime >= {lastYearS} and c.startTime <= {lastYearE}";
+            //lessStats.lastYearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastYearInterSql, code: $"LessonRecord-{id}");
+
+            //string yearInterSql = $"{InterSql} and c.startTime >= {yearS} and c.startTime <= {yearE}";
+            //lessStats.yearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", yearInterSql, code: $"LessonRecord-{id}");
 
 
             return lessStats;
@@ -172,7 +220,11 @@ namespace TEAMModelBI.Tool.CosmosBank
             var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
             var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
 
+            var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
+            var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year");         //计算今年开始/结束时间
+
             string currSql = "select value(count(c.id)) from c ";
+            string yearSql = $"select c.id,c.code,c.createTime from c  where c.createTime >= {lastYearS} and c.createTime <= {yearE}";
             int exam = 0;
             int survey = 0;
             int vote = 0;
@@ -185,55 +237,165 @@ namespace TEAMModelBI.Tool.CosmosBank
             int lastTerm = 0;
             int term = 0;
 
-            string lastDaySql = $"c.createTime >= {lastDayS} and c.createTime <= {lastdayE}";
-            string daySql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
-            string lastWeekSql = $"c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE}";
-            string weekSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
-            string lastTermSql = $"c.createTime >= {lastTermS} and c.createTime <= {lastTermE}";
-            string termSql = $"c.createTime >= {termS} and c.createTime <= {termE}";
-            foreach (var type in StaticValue.activityTypes)
+            DateTimeOffset lyearDay = new(DateTimeOffset.UtcNow.Year - 1, DateTimeOffset.UtcNow.Month, DateTimeOffset.UtcNow.Day, DateTimeOffset.UtcNow.Hour, DateTimeOffset.UtcNow.Minute, DateTimeOffset.UtcNow.Second, TimeSpan.Zero);
+            List<StartEndTime> leveryDay = TimeHelper.GetYearEveryDay(lyearDay);
+            List<StartEndTime> everyDay = TimeHelper.GetYearEveryDay(DateTimeOffset.UtcNow);
+            List<ArtRelStats> examSts = new();
+            List<ArtRelStats> surveySts = new();
+            List<ArtRelStats> voteSts = new();
+            List<ArtRelStats> homeworkSts = new();
+
+            foreach (var artType in StaticValue.activityTypes)
             {
-                switch (type)
+                switch (artType)
                 {
                     case "Exam":
-                        exam += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam'", code: $"Exam-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastDaySql}", code: $"Exam-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {daySql}", code: $"Exam-{scId}");
-                        lastWeek+= await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastWeekSql}", code: $"Exam-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {weekSql}", code: $"Exam-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastTermSql}", code: $"Exam-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {termSql}", code: $"Exam-{scId}");                        
+                        exam = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Exam-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{scId}")}))
+                        {
+                            examSts.Add(item);
+                        }
                         break;
                     case "Survey":
-                        survey += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey'", code: $"Survey-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastDaySql}", code: $"Survey-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {daySql}", code: $"Survey-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastWeekSql}", code: $"Survey-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {weekSql}", code: $"Survey-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastTermSql}", code: $"Survey-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {termSql}", code: $"Survey-{scId}");
-                        
+                        survey = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Survey-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{scId}") }))
+                        {
+                            surveySts.Add(item);
+                        }
+
                         break;
                     case "Vote":
-                        vote += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote'", code: $"Vote-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastDaySql}", code: $"Vote-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {daySql}", code: $"Vote-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastWeekSql}", code: $"Vote-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {weekSql}", code: $"Vote-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastTermSql}", code: $"Vote-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {termSql}", code: $"Vote-{scId}");                        
+                        vote = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Vote-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{scId}") }))
+                        {
+                            voteSts.Add(item);
+                        }
                         break;
                     case "Homework":
-                        homework += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework'", code: $"Homework-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastDaySql}", code: $"Homework-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {daySql}", code: $"Homework-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastWeekSql}", code: $"Homework-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {weekSql}", code: $"Homework-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastTermSql}", code: $"Homework-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {termSql}", code: $"Homework-{scId}");                        
+                        homework = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Homework-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Homework-{scId}") }))
+                        {
+                            homeworkSts.Add(item);
+                        }
                         break;
                 }
             }
+
+
+            List<ArtRelStats> tempAll = new();
+            if (examSts.Count > 0) 
+            {
+                tempAll.AddRange(examSts);
+                lastDay += examSts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += examSts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += examSts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += examSts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += examSts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += examSts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+            
+            if (surveySts.Count > 0)
+            {
+                tempAll.AddRange(surveySts);
+                lastDay += surveySts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += surveySts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += surveySts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += surveySts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += surveySts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += surveySts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;                
+            }
+
+            if (voteSts.Count > 0)
+            {
+                tempAll.AddRange(voteSts);
+                lastDay += voteSts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += voteSts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += voteSts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += voteSts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += voteSts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += voteSts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+
+            if (homeworkSts.Count > 0)
+            {
+                tempAll.AddRange(homeworkSts);
+                lastDay += homeworkSts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += homeworkSts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += homeworkSts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += homeworkSts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += homeworkSts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += homeworkSts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+
+            if (tempAll.Count > 0) 
+            {
+
+                for (int i = 0; i < leveryDay.Count; i++)
+                {
+                    if (actStats.LastYear.Count == 366)
+                        actStats.LastYear[i] = (double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count;
+                    else
+                        actStats.LastYear.Add((double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count);
+                }
+
+                for (int i = 0; i < everyDay.Count; i++)
+                {
+                    if (actStats.year.Count == 366)
+                        actStats.year[i] = tempAll.FindAll(f => (f.createTime >= everyDay[i].start && f.createTime <= everyDay[i].end)).Count;
+                    else
+                        actStats.year.Add(tempAll.FindAll(f => (f.createTime >= everyDay[i].start && f.createTime <= everyDay[i].end)).Count);
+                }
+            }
+
+            //string lastDaySql = $"c.createTime >= {lastDayS} and c.createTime <= {lastdayE}";
+            //string daySql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
+            //string lastWeekSql = $"c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE}";
+            //string weekSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
+            //string lastTermSql = $"c.createTime >= {lastTermS} and c.createTime <= {lastTermE}";
+            //string termSql = $"c.createTime >= {termS} and c.createTime <= {termE}";
+            //foreach (var type in StaticValue.activityTypes)
+            //{
+            //    switch (type)
+            //    {
+            //        case "Exam":
+            //            exam += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam'", code: $"Exam-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastDaySql}", code: $"Exam-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {daySql}", code: $"Exam-{scId}");
+            //            lastWeek+= await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastWeekSql}", code: $"Exam-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {weekSql}", code: $"Exam-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastTermSql}", code: $"Exam-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {termSql}", code: $"Exam-{scId}");                        
+            //            break;
+            //        case "Survey":
+            //            survey += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey'", code: $"Survey-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastDaySql}", code: $"Survey-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {daySql}", code: $"Survey-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastWeekSql}", code: $"Survey-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {weekSql}", code: $"Survey-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastTermSql}", code: $"Survey-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {termSql}", code: $"Survey-{scId}");
+                        
+            //            break;
+            //        case "Vote":
+            //            vote += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote'", code: $"Vote-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastDaySql}", code: $"Vote-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {daySql}", code: $"Vote-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastWeekSql}", code: $"Vote-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {weekSql}", code: $"Vote-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastTermSql}", code: $"Vote-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {termSql}", code: $"Vote-{scId}");                        
+            //            break;
+            //        case "Homework":
+            //            homework += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework'", code: $"Homework-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastDaySql}", code: $"Homework-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {daySql}", code: $"Homework-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastWeekSql}", code: $"Homework-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {weekSql}", code: $"Homework-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastTermSql}", code: $"Homework-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {termSql}", code: $"Homework-{scId}");                        
+            //            break;
+            //    }
+            //}
             actStats.cnt = (exam + survey + vote + homework);
             actStats.exam = exam;
             actStats.survey = survey;
@@ -249,17 +411,70 @@ namespace TEAMModelBI.Tool.CosmosBank
             return actStats;
         }
 
-
+        /// <summary>
+        /// 研修
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="scId"></param>
+        /// <returns></returns>
         public static async Task<StudyStats> GetStudyStats(CosmosClient cosmosClient, string scId) 
         {
             StudyStats studyStats = new();
 
 
+            List<AreaStudy> trains = new();
+
+            School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{scId}", new PartitionKey("Base"));
+            //cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText:$"select value(c.areaId) from c where c.id='{scId}'", requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")});
+
+            AreaSetting setting = null;
+            var responSett = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"{school.areaId}", new PartitionKey("AreaSetting"));
+            if (responSett.Status == 200)
+            {
+                using var fileJson = await JsonDocument.ParseAsync(responSett.ContentStream);
+                setting = fileJson.ToObject<AreaSetting>();
+            }
+            if (setting == null)
+            {
+                setting = new AreaSetting
+                {
+                    allTime = 50,
+                    classTime = 5,
+                    submitTime = 15,
+                    onlineTime = 20,
+                    offlineTime = 10,
+                    lessonMinutes = 45,
+                };
+            }
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<AreaStudy>(queryText: $"select c.id,c.code,c.totalTime,c.onlineTime,c.offlineTime,c.classTime,c.currency from c where c.pk='TeacherTrain' and c.school='{scId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{scId}") }))
+            {
+                trains.Add(item);
+            }
+
+            studyStats.learnTime = trains.Select(s => s.totalTime).Sum();
+            trains.ForEach(x =>
+            {
+                //线上研修
+                if (x.onlineTime == 0) studyStats.online++; else if (x.onlineTime >= setting.onlineTime) studyStats.online++; else studyStats.online++;
+
+                //线下研修
+                if (x.offlineTime == 0) studyStats.offline++; else if (x.onlineTime >= setting.offlineTime) studyStats.offline++; else studyStats.offline++;
+
+                //课堂实录
+                if (x.classTime == 0) studyStats.classRoom++; else if (x.classTime >= setting.classTime) studyStats.classRoom++; else studyStats.classRoom++;
 
+                //认证材料
+                if (x.currency.submitTime == 0) studyStats.submit++; else if (x.currency.submitTime >= setting.submitTime) studyStats.submit++; else studyStats.submit++;
 
+                if (x.currency.submitTime == 0 && x.classTime == 0 && x.offlineTime == 0 && x.onlineTime == 0) studyStats.notStarted++;
+                else if (x.currency.submitTime >= setting.submitTime && x.classTime >= setting.classTime && x.onlineTime >= setting.offlineTime && x.onlineTime >= setting.onlineTime) studyStats.finish++;
+                else studyStats.ongoing++;
+            });
 
             return studyStats;
         }
 
+
     }
 }

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/BI/CurrencyModel.cs

@@ -26,6 +26,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// 学校log
         /// </summary>
         public string picture { get; set; }
+        public string areaId { get; set; }
         public int size { get; set; }
         public long createTime { get; set; }
     }

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

@@ -28,6 +28,11 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         public string name { get; set; }
 
+        /// <summary>
+        /// 学区id
+        /// </summary>
+        public string areaId { get; set; }
+
         /// <summary>
         /// 空间
         /// </summary>
@@ -114,6 +119,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
     /// </summary>
     public class LessonStats
     {
+        /// <summary>
+        /// 所有课例
+        /// </summary>
+        public int all { get; set; }
         /// <summary>
         /// 开课数
         /// </summary>
@@ -295,4 +304,29 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         public int finish { get; set; }
     }
 
+
+    /// <summary>
+    /// 课例统计(读取)
+    /// </summary>
+    public class LessRelStats
+    {
+        public string id { get; set; }
+        public string code { get; set; }
+        public long startTime { get; set; }
+        /// <summary>
+        /// 学生互动总数
+        /// </summary>
+        public int clientInteractionCount { get; set; } = 0;
+    };
+
+    /// <summary>
+    /// 活动统计 (读取)
+    /// </summary>
+    public class ArtRelStats
+    {
+        public string id { get; set; }
+        public string code { get; set; }
+        public long createTime { get; set; }
+
+    }
 }

+ 22 - 1
TEAMModelOS.SDK/Models/Service/BI/BICommonWay.cs

@@ -1,4 +1,6 @@
-using System;
+using MathNet.Numerics.LinearAlgebra.Double;
+using NUnit.Framework;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -57,5 +59,24 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             return scSql.ToString();
         }
 
+        /// <summary>
+        /// 每列合并 多个数组合并成一个数组 列合并
+        /// </summary>
+        /// <param name="doubles"></param>
+        /// <returns></returns>
+        public static List<double> ManyDoubleMerge(List<List<double>> doubles)
+        {
+            List<double> retDou = new();
+            var artYear = DenseMatrix.OfColumns(doubles);
+            //var rc = artYear.RowCount;
+            var cc = artYear.ColumnCount;
+            for (int i = 0; i < artYear.RowCount; i++)
+            {
+                retDou.Add(artYear.SubMatrix(i, 1, 0, cc).ColumnSums().Sum());
+            }
+
+            return retDou;
+        }
+
     }
 }

+ 40 - 1
TEAMModelOS.SDK/Models/Service/BI/TimeHelper.cs

@@ -463,7 +463,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         }
 
         /// <summary>
-        /// 12个月
+        /// 12个月 单个list<double>
         /// </summary>
         /// <param name="doubles"></param>
         /// <param name="year"></param>
@@ -499,5 +499,44 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             return months;
         }
 
+        /// <summary>
+        /// 12个月 多个list<double>
+        /// </summary>
+        /// <param name="listDoubles"></param>
+        /// <param name="year"></param>
+        /// <param name="month"></param>
+        /// <returns></returns>
+        public static List<YearMonth> GetYearMonths(List<List<double>> listDoubles, int year = 0, int month = 0)
+        {
+            List<YearMonth> months = new();
+            foreach (var doubles in listDoubles)
+            {
+                if (doubles.Count > 0)
+                {
+                    DateTimeOffset dateTime = DateTimeOffset.Now;
+                    if (year == 0)
+                        year = dateTime.Year;
+                    if (month == 0)
+                        month = dateTime.Month;
+
+                    List<int> isLeapYear = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? isLeapYear = leapY : isLeapYear = flatY;
+                    double[] array = doubles.ToArray();
+                    double ser = doubles.Sum();
+                    int moth = 1;
+                    int primaryD = 0;
+                    for (int i = 0; i < isLeapYear.Count; i++)
+                    {
+                        if (month < moth)
+                            break;
+                        double[] temp = new double[isLeapYear[i]];
+                        Array.ConstrainedCopy(array, primaryD, temp, 0, isLeapYear[i]);
+                        months.Add(new YearMonth() { id = $"{year}-{moth}", cnt = temp.Sum() });
+                        moth += 1;
+                        primaryD += isLeapYear[i];
+                    }
+                }
+            }
+            return months;
+        }
     }
 }

+ 149 - 36
TEAMModelOS.SDK/Models/Service/BIStatsWay/ActivityStatsWay.cs

@@ -32,7 +32,11 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
             var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
 
+            var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
+            var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year");         //计算今年开始/结束时间
+
             string currSql = "select value(count(c.id)) from c ";
+            string yearSql = $"select c.id,c.code,c.createTime from c  where c.createTime >= {lastYearS} and c.createTime <= {yearE}";
             int exam = 0;
             int survey = 0;
             int vote = 0;
@@ -45,55 +49,164 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             int lastTerm = 0;
             int term = 0;
 
-            string lastDaySql = $"c.createTime >= {lastDayS} and c.createTime <= {lastdayE}";
-            string daySql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
-            string lastWeekSql = $"c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE}";
-            string weekSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
-            string lastTermSql = $"c.createTime >= {lastTermS} and c.createTime <= {lastTermE}";
-            string termSql = $"c.createTime >= {termS} and c.createTime <= {termE}";
-            foreach (var type in StaticValue.activityTypes)
+            DateTimeOffset lyearDay = new(DateTimeOffset.UtcNow.Year - 1, DateTimeOffset.UtcNow.Month, DateTimeOffset.UtcNow.Day, DateTimeOffset.UtcNow.Hour, DateTimeOffset.UtcNow.Minute, DateTimeOffset.UtcNow.Second, TimeSpan.Zero);
+            List<StartEndTime> leveryDay = TimeHelper.GetYearEveryDay(lyearDay);
+            List<StartEndTime> everyDay = TimeHelper.GetYearEveryDay(DateTimeOffset.UtcNow);
+            List<ArtRelStats> examSts = new();
+            List<ArtRelStats> surveySts = new();
+            List<ArtRelStats> voteSts = new();
+            List<ArtRelStats> homeworkSts = new();
+
+            foreach (var artType in StaticValue.activityTypes)
             {
-                switch (type)
+                switch (artType)
                 {
                     case "Exam":
-                        exam += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam'", code: $"Exam-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastDaySql}", code: $"Exam-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {daySql}", code: $"Exam-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastWeekSql}", code: $"Exam-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {weekSql}", code: $"Exam-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastTermSql}", code: $"Exam-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {termSql}", code: $"Exam-{scId}");
+                        exam = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Exam-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{scId}") }))
+                        {
+                            examSts.Add(item);
+                        }
                         break;
                     case "Survey":
-                        survey += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey'", code: $"Survey-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastDaySql}", code: $"Survey-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {daySql}", code: $"Survey-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastWeekSql}", code: $"Survey-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {weekSql}", code: $"Survey-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastTermSql}", code: $"Survey-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {termSql}", code: $"Survey-{scId}");
+                        survey = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Survey-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{scId}") }))
+                        {
+                            surveySts.Add(item);
+                        }
 
                         break;
                     case "Vote":
-                        vote += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote'", code: $"Vote-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastDaySql}", code: $"Vote-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {daySql}", code: $"Vote-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastWeekSql}", code: $"Vote-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {weekSql}", code: $"Vote-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastTermSql}", code: $"Vote-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {termSql}", code: $"Vote-{scId}");
+                        vote = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Vote-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{scId}") }))
+                        {
+                            voteSts.Add(item);
+                        }
                         break;
                     case "Homework":
-                        homework += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework'", code: $"Homework-{scId}");
-                        lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastDaySql}", code: $"Homework-{scId}");
-                        dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {daySql}", code: $"Homework-{scId}");
-                        lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastWeekSql}", code: $"Homework-{scId}");
-                        week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {weekSql}", code: $"Homework-{scId}");
-                        lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastTermSql}", code: $"Homework-{scId}");
-                        term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {termSql}", code: $"Homework-{scId}");
+                        homework = await JointlySingleQuery.GetValueInt(cosmosClient, "Common", currSql, $"Homework-{scId}");
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ArtRelStats>(queryText: yearSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Homework-{scId}") }))
+                        {
+                            homeworkSts.Add(item);
+                        }
                         break;
                 }
             }
+
+            List<ArtRelStats> tempAll = new();
+            if (examSts.Count > 0)
+            {
+                tempAll.AddRange(examSts);
+                lastDay += examSts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += examSts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += examSts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += examSts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += examSts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += examSts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+
+            if (surveySts.Count > 0)
+            {
+                tempAll.AddRange(surveySts);
+                lastDay += surveySts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += surveySts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += surveySts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += surveySts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += surveySts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += surveySts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+
+            if (voteSts.Count > 0)
+            {
+                tempAll.AddRange(voteSts);
+                lastDay += voteSts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += voteSts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += voteSts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += voteSts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += voteSts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += voteSts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+
+            if (homeworkSts.Count > 0)
+            {
+                tempAll.AddRange(homeworkSts);
+                lastDay += homeworkSts.FindAll(f => f.createTime >= lastDayS && f.createTime <= lastdayE).ToList().Count;
+                dayCnt += homeworkSts.FindAll(f => f.createTime >= dayS && f.createTime <= dayE).ToList().Count;
+                lastWeek += homeworkSts.FindAll(f => f.createTime >= lastWeekS && f.createTime <= lastWeekE).ToList().Count;
+                week += homeworkSts.FindAll(f => f.createTime >= weekS && f.createTime <= weekE).ToList().Count;
+                lastTerm += homeworkSts.FindAll(f => f.createTime >= lastTermS && f.createTime <= lastTermE).ToList().Count;
+                term += homeworkSts.FindAll(f => f.createTime >= termS && f.createTime <= termE).ToList().Count;
+            }
+
+            if (tempAll.Count > 0)
+            {
+
+                for (int i = 0; i < leveryDay.Count; i++)
+                {
+                    if (actStats.LastYear.Count == 366)
+                        actStats.LastYear[i] = (double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count;
+                    else
+                        actStats.LastYear.Add((double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count);
+                }
+
+                for (int i = 0; i < everyDay.Count; i++)
+                {
+                    if (actStats.year.Count == 366)
+                        actStats.year[i] = tempAll.FindAll(f => (f.createTime >= everyDay[i].start && f.createTime <= everyDay[i].end)).Count;
+                    else
+                        actStats.year.Add(tempAll.FindAll(f => (f.createTime >= everyDay[i].start && f.createTime <= everyDay[i].end)).Count);
+                }
+            }
+
+            //string lastDaySql = $"c.createTime >= {lastDayS} and c.createTime <= {lastdayE}";
+            //string daySql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
+            //string lastWeekSql = $"c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE}";
+            //string weekSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
+            //string lastTermSql = $"c.createTime >= {lastTermS} and c.createTime <= {lastTermE}";
+            //string termSql = $"c.createTime >= {termS} and c.createTime <= {termE}";
+            //foreach (var type in StaticValue.activityTypes)
+            //{
+            //    switch (type)
+            //    {
+            //        case "Exam":
+            //            exam += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam'", code: $"Exam-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastDaySql}", code: $"Exam-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {daySql}", code: $"Exam-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastWeekSql}", code: $"Exam-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {weekSql}", code: $"Exam-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastTermSql}", code: $"Exam-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {termSql}", code: $"Exam-{scId}");
+            //            break;
+            //        case "Survey":
+            //            survey += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey'", code: $"Survey-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastDaySql}", code: $"Survey-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {daySql}", code: $"Survey-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastWeekSql}", code: $"Survey-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {weekSql}", code: $"Survey-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastTermSql}", code: $"Survey-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {termSql}", code: $"Survey-{scId}");
+
+            //            break;
+            //        case "Vote":
+            //            vote += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote'", code: $"Vote-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastDaySql}", code: $"Vote-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {daySql}", code: $"Vote-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastWeekSql}", code: $"Vote-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {weekSql}", code: $"Vote-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastTermSql}", code: $"Vote-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {termSql}", code: $"Vote-{scId}");
+            //            break;
+            //        case "Homework":
+            //            homework += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework'", code: $"Homework-{scId}");
+            //            lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastDaySql}", code: $"Homework-{scId}");
+            //            dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {daySql}", code: $"Homework-{scId}");
+            //            lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastWeekSql}", code: $"Homework-{scId}");
+            //            week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {weekSql}", code: $"Homework-{scId}");
+            //            lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastTermSql}", code: $"Homework-{scId}");
+            //            term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {termSql}", code: $"Homework-{scId}");
+            //            break;
+            //    }
+            //}
             actStats.cnt = (exam + survey + vote + homework);
             actStats.exam = exam;
             actStats.survey = survey;

+ 66 - 52
TEAMModelOS.SDK/Models/Service/BIStatsWay/LessonRecordStatsWay.cs

@@ -40,76 +40,90 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "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'";
+            lessStats.all = await JointlySingleQuery.GetValueInt(cosmosClient, "School", currSql, $"LessonRecord-{id}");
+            lessStats.open = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 0", $"LessonRecord-{id}");
+            lessStats.less = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 1", $"LessonRecord-{id}");
+
+            List<LessRelStats> lessRelStats = new();
+            string sql = $"select c.id,c.code,c.startTime,c.clientInteractionCount from c where c.pk='LessonRecord' and c.startTime >= {lastYearS} and c.startTime <= {yearE}";
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessRelStats>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{id}") }))
             {
-                
-            
+                lessRelStats.Add(item);
             }
 
+            lessStats.lastDay = lessRelStats.FindAll(f => f.startTime >= lastDayS && f.startTime <= lastdayE).ToList().Count;
+            lessStats.day = lessRelStats.FindAll(f => f.startTime >= dayS && f.startTime <= dayE).ToList().Count;
+            lessStats.lastWeek = lessRelStats.FindAll(f => f.startTime >= lastWeekS && f.startTime <= lastWeekE).ToList().Count;
+            lessStats.week = lessRelStats.FindAll(f => f.startTime >= weekS && f.startTime <= weekE).ToList().Count;
+            lessStats.lastTerm = lessRelStats.FindAll(f => f.startTime >= lastTermS && f.startTime <= lastTermE).ToList().Count;
+            lessStats.term = lessRelStats.FindAll(f => f.startTime >= termS && f.startTime <= termE).ToList().Count;
+
+            lessStats.lastDayInter = lessRelStats.FindAll(f => f.startTime >= lastDayS && f.startTime <= lastdayE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.dayInter = lessRelStats.FindAll(f => f.startTime >= dayS && f.startTime <= dayS).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.lastMonthInter = lessRelStats.FindAll(f => f.startTime >= lastWeekS && f.startTime <= lastWeekE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.monthInter = lessRelStats.FindAll(f => f.startTime >= weekS && f.startTime <= weekS).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.lastYearInter = lessRelStats.FindAll(f => f.startTime >= lastTermS && f.startTime <= lastTermE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.yearInter = lessRelStats.FindAll(f => f.startTime >= termS && f.startTime <= termE).ToList().Select(s => s.clientInteractionCount).Sum();
+
+            DateTimeOffset lyearDay = new(DateTimeOffset.UtcNow.Year - 1, DateTimeOffset.UtcNow.Month, DateTimeOffset.UtcNow.Day, DateTimeOffset.UtcNow.Hour, DateTimeOffset.UtcNow.Minute, DateTimeOffset.UtcNow.Second, TimeSpan.Zero);
+            List<StartEndTime> leveryDay = TimeHelper.GetYearEveryDay(lyearDay);
+            List<StartEndTime> everyDay = TimeHelper.GetYearEveryDay(DateTimeOffset.UtcNow);
+
+            for (int i = 0; i < leveryDay.Count; i++)
+            {
+                if (lessStats.LastYear.Count == 366)
+                    lessStats.LastYear[i] = (double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count;
+                else
+                    lessStats.LastYear.Add((double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count);
+            }
 
+            for (int i = 0; i < everyDay.Count; i++)
+            {
+                if (lessStats.year.Count == 366)
+                    lessStats.year[i] = lessRelStats.FindAll(f => (f.startTime >= everyDay[i].start && f.startTime <= everyDay[i].end)).Count;
+                else
+                    lessStats.year.Add(lessRelStats.FindAll(f => (f.startTime >= everyDay[i].start && f.startTime <= everyDay[i].end)).Count);
+            }
 
 
+            //string lastDaySql = $"{currSql} and c.startTime >= {lastDayS} and c.startTime <= {lastDayS}";
+            //lessStats.lastDay = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDaySql, code: $"LessonRecord-{id}");
 
+            //string daySql = $"{currSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
+            //lessStats.day = await JointlySingleQuery.GetValueInt(cosmosClient, "School", daySql, code: $"LessonRecord-{id}");
 
+            //string lastWeekSql = $"{currSql}  and c.startTime >= {lastWeekS} and c.startTime <= {lastWeekE}";
+            //lessStats.lastWeek = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastWeekSql, code: $"LessonRecord-{id}");
 
+            //string weekSql = $"{currSql}  and c.startTime >= {weekS} and c.startTime <= {weekE}";
+            //lessStats.week = await JointlySingleQuery.GetValueInt(cosmosClient, "School", weekSql, code: $"LessonRecord-{id}");
 
+            //string lastTermSql = $"{currSql} and c.startTime >= {lastTermS} and c.startTime <= {lastTermE}";
+            //lessStats.lastTerm = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastTermSql, code: $"LessonRecord-{id}");
 
+            //string termSql = $"{currSql} and c.startTime >= {termS} and c.startTime <= {termE}";
+            //lessStats.term = await JointlySingleQuery.GetValueInt(cosmosClient, "School", termSql, code: $"LessonRecord-{id}");
 
 
+            //string InterSql = "select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
+            //string lastDayInterSql = $"{InterSql} and c.startTime >= {lastDayS} and c.startTime <= {lastdayE}";
+            //lessStats.lastDayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDayInterSql, code: $"LessonRecord-{id}");
 
+            //string dayInterSql = $"{InterSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
+            //lessStats.dayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", dayInterSql, code: $"LessonRecord-{id}");
 
+            //string lastMthInterSql = $"{InterSql} and c.startTime >= {lastMthS} and c.startTime <= {LastmthE}";
+            //lessStats.lastMonthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastMthInterSql, code: $"LessonRecord-{id}");
 
+            //string mthInterSql = $"{InterSql} and c.startTime >= {mthS} and c.startTime <= {mthE}";
+            //lessStats.monthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", mthInterSql, code: $"LessonRecord-{id}");
 
+            //string lastYearInterSql = $"{InterSql} and c.startTime >= {lastYearS} and c.startTime <= {lastYearE}";
+            //lessStats.lastYearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastYearInterSql, code: $"LessonRecord-{id}");
 
-
-
-
-
-
-
-            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.less = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 1", code: $"LessonRecord-{id}");
-
-
-            string lastDaySql = $"{currSql} and c.startTime >= {lastDayS} and c.startTime <= {lastDayS}";
-            lessStats.lastDay = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDaySql, code: $"LessonRecord-{id}");
-
-            string daySql = $"{currSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
-            lessStats.day = await JointlySingleQuery.GetValueInt(cosmosClient, "School", daySql, code: $"LessonRecord-{id}");
-
-            string lastWeekSql = $"{currSql}  and c.startTime >= {lastWeekS} and c.startTime <= {lastWeekE}";
-            lessStats.lastWeek = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastWeekSql, code: $"LessonRecord-{id}");
-
-            string weekSql = $"{currSql}  and c.startTime >= {weekS} and c.startTime <= {weekE}";
-            lessStats.week = await JointlySingleQuery.GetValueInt(cosmosClient, "School", weekSql, code: $"LessonRecord-{id}");
-
-            string lastTermSql = $"{currSql} and c.startTime >= {lastTermS} and c.startTime <= {lastTermE}";
-            lessStats.lastTerm = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastTermSql, code: $"LessonRecord-{id}");
-
-            string termSql = $"{currSql} and c.startTime >= {termS} and c.startTime <= {termE}";
-            lessStats.term = await JointlySingleQuery.GetValueInt(cosmosClient, "School", termSql, code: $"LessonRecord-{id}");
-
-
-            string InterSql = "select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
-            string lastDayInterSql = $"{InterSql} and c.startTime >= {lastDayS} and c.startTime <= {lastdayE}";
-            lessStats.lastDayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDayInterSql, code: $"LessonRecord-{id}");
-
-            string dayInterSql = $"{InterSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
-            lessStats.dayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", dayInterSql, code: $"LessonRecord-{id}");
-
-            string lastMthInterSql = $"{InterSql} and c.startTime >= {lastMthS} and c.startTime <= {LastmthE}";
-            lessStats.lastMonthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastMthInterSql, code: $"LessonRecord-{id}");
-
-            string mthInterSql = $"{InterSql} and c.startTime >= {mthS} and c.startTime <= {mthE}";
-            lessStats.monthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", mthInterSql, code: $"LessonRecord-{id}");
-
-            string lastYearInterSql = $"{InterSql} and c.startTime >= {lastYearS} and c.startTime <= {lastYearE}";
-            lessStats.lastYearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastYearInterSql, code: $"LessonRecord-{id}");
-
-            string yearInterSql = $"{InterSql} and c.startTime >= {yearS} and c.startTime <= {yearE}";
-            lessStats.yearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", yearInterSql, code: $"LessonRecord-{id}");
+            //string yearInterSql = $"{InterSql} and c.startTime >= {yearS} and c.startTime <= {yearE}";
+            //lessStats.yearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", yearInterSql, code: $"LessonRecord-{id}");
 
 
             return lessStats;

+ 70 - 61
TEAMModelOS.SDK/Models/Service/BIStatsWay/SchoolStatsWay.cs

@@ -1,7 +1,9 @@
 using Azure.Cosmos;
 using DocumentFormat.OpenXml.Bibliography;
 using DocumentFormat.OpenXml.Math;
+using MathNet.Numerics.LinearAlgebra.Double;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Azure.Amqp.Framing;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -18,7 +20,6 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 {
     public static class SchoolStatsWay
     {
-
         /// <summary>
         /// 统计单个学校
         /// </summary>
@@ -53,6 +54,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             statsInfo.picture = scBase.picture;
             statsInfo.size = scBase.size;
             statsInfo.scCreateTime = scBase.createTime;
+            statsInfo.areaId = scBase.areaId;
 
             string tchSql = $"{currSql} where ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'";
             statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", tchSql, code: $"Teacher-{scBase.id}");
@@ -108,6 +110,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 witRoom = statsInfos.Select(s => s.witRoom).Sum(),
                 size = statsInfos.Select(s => s.size).Sum()
             };
+            areaInfo.lesson.all = statsInfos.Select(s => s.lesson.all).Sum();
             areaInfo.lesson.open = statsInfos.Select(s => s.lesson.open).Sum();
             areaInfo.lesson.less = statsInfos.Select(s => s.lesson.less).Sum();
             areaInfo.lesson.lastDay = statsInfos.Select(s => s.lesson.lastDay).Sum();
@@ -122,6 +125,9 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             areaInfo.lesson.monthInter = statsInfos.Select(s => s.lesson.monthInter).Sum();
             areaInfo.lesson.lastYearInter = statsInfos.Select(s => s.lesson.lastYearInter).Sum();
             areaInfo.lesson.yearInter = statsInfos.Select(s => s.lesson.yearInter).Sum();
+            areaInfo.lesson.LastYear = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.lesson.LastYear).ToList());
+            areaInfo.lesson.year = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.lesson.year).ToList());
+
 
             areaInfo.activity.cnt = statsInfos.Select(s => s.activity.cnt).Sum();
             areaInfo.activity.exam = statsInfos.Select(s => s.activity.exam).Sum();
@@ -134,68 +140,71 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             areaInfo.activity.week = statsInfos.Select(s => s.activity.week).Sum();
             areaInfo.activity.lastTerm = statsInfos.Select(s => s.activity.lastTerm).Sum();
             areaInfo.activity.term = statsInfos.Select(s => s.activity.term).Sum();
-
-            List<Task<ItemResponse<StatsInfo>>> taskStatsInfos = new();
-
-            foreach (var itemId in scIds)
-            {
-                bool isExist = true;
-                StatsInfo statsInfo = new();
-                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemId}", new PartitionKey("Stats"));
-                if (scDataStats.Status == 200)
-                {
-                    using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
-                    statsInfo = fileJson.ToObject<StatsInfo>();
-                }
-                else
-                {
-                    statsInfo.id = itemId;
-                    isExist = false;
-                }
-
-                bool isnew = false;
-                DateTimeOffset dateTime = DateTimeOffset.UtcNow;
-                long now = dateTime.ToUnixTimeMilliseconds();
-
-                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 = $"{itemId}"}, _option.Location, "stats-sc-info");
-
-                    //异步方法处理 同步更新
-                    statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, itemId);
-
-                    statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                    if (isExist)
-                        taskStatsInfos.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats")));
-                    else
-                        taskStatsInfos.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats")));
-                }
-            }
-
-            if (taskStatsInfos.Count < 256)
-                await Task.WhenAll(taskStatsInfos);
-            else 
-            {
-                int pages = (taskStatsInfos.Count + 256) / 256;
-                for (int i = 0; i < pages; i++)
-                {
-                    List<Task<ItemResponse<StatsInfo>>> tempStatsInfos = taskStatsInfos.Skip((i) * 256).Take(256).ToList();
-                    await Task.WhenAll(tempStatsInfos);
-                }
-            }
+            areaInfo.activity.LastYear = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.activity.LastYear).ToList());
+            areaInfo.activity.year = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.activity.year).ToList());
+
+            //List<Task<ItemResponse<StatsInfo>>> taskStatsInfos = new();
+
+            //foreach (var itemId in scIds)
+            //{
+            //    bool isExist = true;
+            //    StatsInfo statsInfo = new();
+            //    var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemId}", new PartitionKey("Stats"));
+            //    if (scDataStats.Status == 200)
+            //    {
+            //        using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
+            //        statsInfo = fileJson.ToObject<StatsInfo>();
+            //    }
+            //    else
+            //    {
+            //        statsInfo.id = itemId;
+            //        isExist = false;
+            //    }
+
+            //    bool isnew = false;
+            //    DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            //    long now = dateTime.ToUnixTimeMilliseconds();
+
+            //    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 = $"{itemId}"}, _option.Location, "stats-sc-info");
+
+            //        //异步方法处理 同步更新
+            //        statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, itemId);
+
+            //        statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            //        if (isExist)
+            //            taskStatsInfos.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats")));
+            //        else
+            //            taskStatsInfos.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats")));
+            //    }
+            //}
+
+            //if (taskStatsInfos.Count < 256)
+            //    await Task.WhenAll(taskStatsInfos);
+            //else 
+            //{
+            //    int pages = (taskStatsInfos.Count + 256) / 256;
+            //    for (int i = 0; i < pages; i++)
+            //    {
+            //        List<Task<ItemResponse<StatsInfo>>> tempStatsInfos = taskStatsInfos.Skip((i) * 256).Take(256).ToList();
+            //        await Task.WhenAll(tempStatsInfos);
+            //    }
+            //}
 
             return areaInfo;
         }
+
     }
 }

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

@@ -73,8 +73,6 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 else studyStats.ongoing++;
             });
 
-
-
             return studyStats;
         }
     }