Sfoglia il codice sorgente

更新BI数据结构,编写相关方法啊,已测试,function初步建立完成,待将方法移植到Function中去

Li 2 anni fa
parent
commit
aa84530f0e

+ 0 - 25
TEAMModelBI/Controllers/Census/ActivitySticsController.cs

@@ -952,31 +952,6 @@ namespace TEAMModelBI.Controllers.Census
             //public int stuCnt { get; set; } = 0;
         }
 
-        public class AreaStudy 
-        {
-            public string id { get; set; }
-
-            public string code { get; set; }
-
-            /// <summary>
-            /// 线上观看视频的学时
-            /// </summary>
-            public long onlineTime { get; set; }
-
-            /// <summary>
-            /// 线下研修学时
-            /// </summary>
-            public long offlineTime { get; set; }
-            /// <summary>
-            /// 课堂实录学时
-            /// </summary>
-            public long classTime { get; set; }
-            /// <summary>
-            /// 必修的
-            /// </summary>
-            public Currency currency { get; set; } = new Currency();
-        }
-
         private class SchoolInfo
         {
             public string id { get; set; }

+ 10 - 7
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -13,6 +13,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Models;
 using TEAMModelBI.Tool;
+using TEAMModelBI.Tool.BIStatsWay;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.Context.BI;
@@ -502,7 +503,7 @@ namespace TEAMModelBI.Controllers.Census
             School school = new();
             ScStats scStats = new();
 
-            var respSc = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"base-{scId}"));
+            var respSc = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"Base"));
             if (respSc.Status == 200)
             {
                 using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
@@ -513,7 +514,6 @@ namespace TEAMModelBI.Controllers.Census
 
             try
             {
-
                 StatsInfo statsInfo = new();
                 var scDataStats = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey("Stats"));
                 if (scDataStats.Status == 200)
@@ -521,6 +521,8 @@ namespace TEAMModelBI.Controllers.Census
                     using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
                     statsInfo = fileJson.ToObject<StatsInfo>();
                 }
+                else
+                    scStats.id = school.id;
 
                 bool isnew = false;
                 DateTimeOffset dateTime = DateTimeOffset.UtcNow;
@@ -556,7 +558,7 @@ namespace TEAMModelBI.Controllers.Census
                     scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
                     scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
                     scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
-                    scStats.lessStats.yearInter= TimeHelper.GetYearMonth(statsInfo.lesson.yearInter, dateTime.Year, dateTime.Month);
+                    scStats.lessStats.yearInter=statsInfo.lesson.yearInter;
                     scStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
                     scStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
                     scStats.actStats.cnt = statsInfo.activity.cnt;
@@ -592,16 +594,16 @@ namespace TEAMModelBI.Controllers.Census
                 if (statsInfo.upTime == 0 && isnew)
                     statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
 
+                statsInfo = await SchoolStatsWay.upSingleSc(cosmosClinet, school.id);
 
 
 
 
-
-                return Ok(new { state = RespondCode.Ok });
+                return Ok(new { state = RespondCode.Ok, statsInfo });
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"BI,{_option.Location}  /school/set-scstats   \n    {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                //await _dingDing.SendBotMsg($"BI,{_option.Location}  /school/set-scstats   \n    {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
         }
@@ -688,7 +690,8 @@ namespace TEAMModelBI.Controllers.Census
             public int lastMonthInter { get; set; }
             public int monthInter { get; set; }
             public int lastYearInter { get; set; }
-            public List<YearMonth> yearInter { get; set; } = new List<YearMonth>();//12个月
+            public int yearInter { get; set; }
+            //public List<YearMonth> yearInter { get; set; } = new List<YearMonth>();//12个月
             public List<YearMonth> LastYear { get; set; } = new List<YearMonth>();//12个月
             public List<YearMonth> year { get; set; } = new List<YearMonth>();    //12个月
         }

+ 63 - 0
TEAMModelBI/Models/FrontModel.cs

@@ -0,0 +1,63 @@
+using TEAMModelOS.SDK.Models;
+
+namespace TEAMModelBI.Models
+{
+    /// <summary>
+    /// 前端显示相关的结构
+    /// </summary>
+    public class FrontModel
+    {
+    }
+
+    public class YearMonth
+    {
+        public string id { get; set; }
+
+        public double cnt { get; set; }
+    }
+
+    /// <summary>
+    /// 学校基础信息
+    /// </summary>
+    public class ScBase
+    {
+        public string id { get; set; }
+        public string code { get; set; }
+        public string name { get; set; }
+        public string picture { get; set; }
+        public int size { get; set; }
+        public long createTime { get; set; }
+    }
+
+    /// <summary>
+    /// 研修活动统计
+    /// </summary>
+    public class AreaStudy
+    {
+        public string id { get; set; }
+
+        public string code { get; set; }
+
+        /// <summary>
+        /// 线上观看视频的学时
+        /// </summary>
+        public long onlineTime { get; set; }
+
+        /// <summary>
+        /// 线下研修学时
+        /// </summary>
+        public long offlineTime { get; set; }
+        /// <summary>
+        /// 课堂实录学时
+        /// </summary>
+        public long classTime { get; set; }
+        /// <summary>
+        /// 必修的
+        /// </summary>
+        public Currency currency { get; set; } = new Currency();
+    }
+
+
+
+
+}

+ 0 - 7
TEAMModelBI/Models/ItemInfo.cs

@@ -46,11 +46,4 @@ namespace TEAMModelBI.Models
         public string code { get; set; }
         public string value { get; set; }
     }
-
-    public class YearMonth 
-    {
-        public string id { get; set; }
-
-        public double cnt { get; set; }
-    }
 }

+ 110 - 0
TEAMModelBI/Tool/BIStatsWay/ActivityStatsWay.cs

@@ -0,0 +1,110 @@
+using System.Threading.Tasks;
+using System;
+using TEAMModelBI.Tool.CosmosBank;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using Azure.Cosmos;
+
+namespace TEAMModelBI.Tool.BIStatsWay
+{
+    public static class ActivityStatsWay
+    {
+        /// <summary>
+        /// 统计学校活动
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="scId"></param>
+        /// <returns></returns>
+        public static async Task<ActivityStats> GetActStats(CosmosClient cosmosClient, string scId)
+        {
+            ActivityStats actStats = new();
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+
+            var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));   //昨天开始时间
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间   
+
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
+
+            string currSql = "select value(count(c.id)) from c ";
+            int exam = 0;
+            int survey = 0;
+            int vote = 0;
+            int homework = 0;
+
+            int lastDay = 0;
+            int dayCnt = 0;
+            int lastWeek = 0;
+            int week = 0;
+            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)
+            {
+                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;
+            actStats.vote = vote;
+            actStats.homework = homework;
+            actStats.lastDay = lastDay;
+            actStats.dayCnt = dayCnt;
+            actStats.lastWeek = lastWeek;
+            actStats.week = week;
+            actStats.lastTerm = lastTerm;
+            actStats.term = term;
+
+            return actStats;
+        }
+
+    }
+}

+ 87 - 0
TEAMModelBI/Tool/BIStatsWay/LessonRecordStatsWay.cs

@@ -0,0 +1,87 @@
+using System.Threading.Tasks;
+using System;
+using TEAMModelBI.Tool.CosmosBank;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using Azure.Cosmos;
+
+namespace TEAMModelBI.Tool.BIStatsWay
+{
+    public  static class LessonRecordStatsWay
+    {
+
+        /// <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();
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+
+            var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));   //昨天开始时间
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间   
+
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
+
+            var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth");  //上月开始/结束时间
+            var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month");  //本月开始/结束时间
+
+            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  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}");
+
+
+            return lessStats;
+        }
+
+    }
+}

+ 74 - 0
TEAMModelBI/Tool/BIStatsWay/SchoolStatsWay.cs

@@ -0,0 +1,74 @@
+using System.Threading.Tasks;
+using System;
+using TEAMModelBI.Models;
+using TEAMModelBI.Tool.CosmosBank;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using Azure.Cosmos;
+
+namespace TEAMModelBI.Tool.BIStatsWay
+{
+    public static class SchoolStatsWay
+    {
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="scId"></param>
+        /// <returns></returns>
+        public static async Task<StatsInfo> upSingleSc(CosmosClient cosmosClient, string scId)
+        {
+
+            StatsInfo statsInfo = new() { id = $"{scId}" };
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间    13位
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
+
+            var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth");  //上月开始/结束时间
+            var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month");  //本月开始/结束时间
+
+            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 dayWhereSql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
+            string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
+            string monthWhereSql = $"c.createTime >= {mthS} and c.createTime <= {mthE}";
+
+            ScBase scBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<ScBase>(statsInfo.id, new PartitionKey("Base"));
+            statsInfo.name = scBase.name;
+            statsInfo.picture = scBase.picture;
+            statsInfo.size = scBase.size;
+            statsInfo.scCreateTime = scBase.createTime;
+
+            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.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.lesson = await LessonRecordStatsWay.GetLessStats(cosmosClient, statsInfo.id);
+            statsInfo.activity = await ActivityStatsWay.GetActStats(cosmosClient, statsInfo.id);
+
+
+
+
+            return statsInfo;
+        }
+
+    }
+}

+ 77 - 0
TEAMModelBI/Tool/BIStatsWay/StudyStatsWay.cs

@@ -0,0 +1,77 @@
+using Azure.Cosmos;
+using System.Collections.Generic;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelBI.Models;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+
+namespace TEAMModelBI.Tool.BIStatsWay
+{
+    public static class StudyStatsWay
+    {
+        /// <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 rschool = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<School>($"{scId}", new PartitionKey("AreaSetting"));
+
+            AreaSetting setting = null;
+
+            var responSett = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"123", new PartitionKey("AreaSetting"));
+            if (responSett.Status == 200) 
+            {
+                
+            }
+            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.onlineTime,c.offlineTime,c.classTime,c.currency from c where c.pk='TeacherTrain' and c.school='{scId}'", requestOptions: new QueryRequestOptions() { }))
+            {
+                trains.Add(item);
+            }
+
+
+
+            trains.ForEach(x =>
+            {
+                //线上研修
+                if (x.onlineTime == 0) studyStats++; else if (x.onlineTime >= setting.onlineTime) onLineCount++; else onLineCount++;
+
+                //线下研修
+                if (x.offlineTime == 0) offlineCount++; else if (x.onlineTime >= setting.offlineTime) offlineCount++; else offlineCount++;
+
+                //课堂实录
+                if (x.classTime == 0) classRoomCount++; else if (x.classTime >= setting.classTime) classRoomCount++; else classRoomCount++;
+
+                //认证材料
+                if (x.currency.submitTime == 0) submitCount++; else if (x.currency.submitTime >= setting.submitTime) submitCount++; else submitCount++;
+
+                if (x.currency.submitTime == 0 && x.classTime == 0 && x.offlineTime == 0 && x.onlineTime == 0) noCount++;
+                else if (x.currency.submitTime >= setting.submitTime && x.classTime >= setting.classTime && x.onlineTime >= setting.offlineTime && x.onlineTime >= setting.onlineTime) fulfilCount++;
+                else carryOnCount++;
+            });
+
+
+
+            return studyStats;
+        }
+    }
+}

+ 264 - 0
TEAMModelBI/Tool/CosmosBank/StatsWay.cs

@@ -0,0 +1,264 @@
+using Azure.Cosmos;
+using DocumentFormat.OpenXml.Bibliography;
+using DocumentFormat.OpenXml.Math;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using NUnit.Framework.Constraints;
+using System;
+using System.Threading.Tasks;
+using TEAMModelBI.Models;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Cosmos.BI.BITable;
+
+namespace TEAMModelBI.Tool.CosmosBank
+{
+    public static class StatsWay
+    {
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="scId"></param>
+        /// <returns></returns>
+        public static async Task<StatsInfo> upSingleSc(CosmosClient cosmosClient, string scId)
+        {
+
+            StatsInfo statsInfo = new() { id = $"{scId}" };
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间    13位
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
+
+            var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth");  //上月开始/结束时间
+            var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month");  //本月开始/结束时间
+
+            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 dayWhereSql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
+            string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
+            string monthWhereSql = $"c.createTime >= {mthS} and c.createTime <= {mthE}";
+
+            ScBase scBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<ScBase>(statsInfo.id, new PartitionKey("Base"));
+            statsInfo.name = scBase.name;
+            statsInfo.picture = scBase.picture;
+            statsInfo.size = scBase.size;
+            statsInfo.scCreateTime = scBase.createTime;
+
+            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.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.lesson = await GetLessStats(cosmosClient, statsInfo.id);
+            statsInfo.activity = await GetActStats(cosmosClient, statsInfo.id);
+
+
+
+
+            return statsInfo;
+        }
+
+
+       /// <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();
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+
+            var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));   //昨天开始时间
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间   
+
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
+
+            var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth");  //上月开始/结束时间
+            var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month");  //本月开始/结束时间
+
+            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  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}");
+
+
+            return lessStats;
+        }
+
+
+        /// <summary>
+        /// 统计学校活动
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="scId"></param>
+        /// <returns></returns>
+        public static async Task<ActivityStats> GetActStats(CosmosClient cosmosClient, string scId) 
+        {
+            ActivityStats actStats = new();
+
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+
+            var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));   //昨天开始时间
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间   
+
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term");   //计算本学期开始/结束时间
+
+            string currSql = "select value(count(c.id)) from c ";
+            int exam = 0;
+            int survey = 0;
+            int vote = 0;
+            int homework = 0;
+
+            int lastDay = 0;
+            int dayCnt = 0;
+            int lastWeek = 0;
+            int week = 0;
+            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)
+            {
+                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;
+            actStats.vote = vote;
+            actStats.homework = homework;
+            actStats.lastDay = lastDay;
+            actStats.dayCnt = dayCnt;
+            actStats.lastWeek = lastWeek;
+            actStats.week = week;
+            actStats.lastTerm = lastTerm;
+            actStats.term = term;
+
+            return actStats;
+        }
+
+
+        public static async Task<StudyStats> GetStudyStats(CosmosClient cosmosClient, string scId) 
+        {
+            StudyStats studyStats = new();
+
+
+
+
+
+            return studyStats;
+        }
+
+    }
+}

+ 5 - 0
TEAMModelBI/Tool/TimeHelper.cs

@@ -331,6 +331,11 @@ namespace TEAMModelBI.Tool
                             }
                         }
                         break;
+                    //上个月
+                    case "lastMonth":
+                        tempStrart = new DateTimeOffset(year, month - 1, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month - 1, DateTime.DaysInMonth(year, month - 1), 23, 59, 59, TimeSpan.Zero);
+                        break;
                     //本月1号至当天
                     case "monthDay":
                         tempStrart = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero);

+ 45 - 0
TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs

@@ -0,0 +1,45 @@
+using System.Collections.Generic;
+using System.Net;
+using System.Net.Http;
+using Microsoft.Azure.Functions.Worker;
+using Microsoft.Azure.Functions.Worker.Http;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelOS.FunctionV4.HttpTrigger
+{
+    public class BIHttpTrigger
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly AzureRedisFactory _azureRedis;
+        private readonly HttpClient _httpClient;
+
+
+        public BIHttpTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, HttpClient httpClient)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _azureStorage = azureStorage;
+            _azureRedis = azureRedis;
+            _httpClient = httpClient;
+        }
+
+        /// <summary>
+        /// 统计学校的信息
+        /// </summary>
+        /// <param name="req"></param>
+        /// <returns></returns>
+        [Function("stats-sc-info")]
+        public HttpResponseData StatsSchoolInfo([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestData req)
+        {
+
+            var response = req.CreateResponse(HttpStatusCode.OK);
+            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
+
+            response.WriteString("Welcome to Azure Functions!");
+
+            return response;
+        }
+    }
+}

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/BI/BITable/LessStats.cs

@@ -44,9 +44,9 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI.BITable
     /// BI活动  0 Exam评测  1 Survey问卷  2 Vote投票 3 Homework作业活动  
     /// </summary>
     [TableName(Name = "BIStats")]
-    public class ActivityStats : TableEntity
+    public class TableActivityStats : TableEntity
     {
-        public ActivityStats()
+        public TableActivityStats()
         {
             //PartitionKey LessonYear 记录一年的数据  天    RowKey 2022 一年所有; 2022-学校编码   学校一年所有
             //PartitionKey LessonHour 记录一天的数据  小时   RowKey 20220615 一天的记录; 20220615-学校编码   学校一天的记录

+ 2 - 1
TEAMModelOS.SDK/Models/Cosmos/BI/StatsInfo.cs

@@ -182,7 +182,8 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 今年互动
         /// </summary>
-        public List<double> yearInter { get; set; } = new List<double>();
+        public int yearInter { get; set; }
+        //public List<double> yearInter { get; set; } = new List<double>();
 
         /// <summary>
         /// 去年每天的数据  366天

+ 8 - 8
TEAMModelOS.SDK/Models/Service/BI/BIActivityService.cs

@@ -91,7 +91,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                 daYear[hour] = num;
                 string yearStats = string.Join(',', daYear);
 
-                ActivityStats actHour = table.Get<ActivityStats>("ACTHour", $"{dateDay}");
+                TableActivityStats actHour = table.Get<TableActivityStats>("ACTHour", $"{dateDay}");
                 if (actHour == null)
                     actHour = new() { PartitionKey = "ACTHour", RowKey = $"{dateDay}" };
 
@@ -126,11 +126,11 @@ namespace TEAMModelOS.SDK.Models.Service.BI
 
                 try
                 {
-                    await table.SaveOrUpdate<ActivityStats>(actHour);
+                    await table.SaveOrUpdate<TableActivityStats>(actHour);
                 }
                 catch { }
 
-                ActivityStats actYear = table.Get<ActivityStats>("ACTYear", $"{year}");
+                TableActivityStats actYear = table.Get<TableActivityStats>("ACTYear", $"{year}");
 
                 if (actYear == null)
                     actYear = new() { PartitionKey = "ACTYear", RowKey = $"{year}" };
@@ -166,7 +166,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
 
                 try
                 {
-                    await table.SaveOrUpdate<ActivityStats>(actYear);
+                    await table.SaveOrUpdate<TableActivityStats>(actYear);
                 }
                 catch { }
 
@@ -192,7 +192,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                     }
                     catch { }
 
-                    ActivityStats ActScHour = table.Get<ActivityStats>("ACTHour", $"{dateDay}-{schoolId}");
+                    TableActivityStats ActScHour = table.Get<TableActivityStats>("ACTHour", $"{dateDay}-{schoolId}");
                     if (ActScHour == null)
                         ActScHour = new() { PartitionKey = "ACTHour", RowKey = $"{dateDay}-{schoolId}" };
 
@@ -227,11 +227,11 @@ namespace TEAMModelOS.SDK.Models.Service.BI
 
                     try
                     {
-                        await table.SaveOrUpdate<ActivityStats>(ActScHour);
+                        await table.SaveOrUpdate<TableActivityStats>(ActScHour);
                     }
                     catch { }
 
-                    ActivityStats actScYear = table.Get<ActivityStats>("ACTYear", $"{year}-{schoolId}");
+                    TableActivityStats actScYear = table.Get<TableActivityStats>("ACTYear", $"{year}-{schoolId}");
                     if (actScYear == null)
                         actScYear = new() { PartitionKey = "ACTYear", RowKey = $"{year}-{schoolId}" };
 
@@ -267,7 +267,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
 
                     try
                     {
-                        await table.SaveOrUpdate<ActivityStats>(actScYear);
+                        await table.SaveOrUpdate<TableActivityStats>(actScYear);
                     }
                     catch { }
                 }