فهرست منبع

1、优化学校情况中的BI管理员统计查询
2、查询所有区接口雏形

Li 2 سال پیش
والد
کامیت
b015b81dae

+ 8 - 9
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -1773,6 +1773,7 @@ namespace TEAMModelBI.Controllers.BITest
             var (weekDayS, weekDayE) = TimeHelper.GetLongToTime(lastWeekS, lastWeekE);
             var (lTermDayS, lTermDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
             var (termDayS, termDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
+            var (lMonthS, lMonthE) = TimeHelper.GetLongToTime(lastMonthS, lastMonthE);
             var lastDay = dateOff.AddDays(-1);
 
             StatsInfo statsInfo = new();
@@ -2020,25 +2021,25 @@ namespace TEAMModelBI.Controllers.BITest
                     statsInfo.activity.all += all;
                     break;
                 case "Less":
-
                     statsInfo.lesson.year[dateOff.DayOfYear] += all;
                     statsInfo.lesson.lastDay = ((int)statsInfo.lesson.year[lastDay.DayOfYear]);
                     statsInfo.lesson.day = ((int)statsInfo.lesson.year[dateOff.DayOfYear]);
+                    var artList = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.lesson.year });
+                    statsInfo.lesson.lastMonthInter = (int)artList.SubMatrix(lMonthS.DayOfYear, lMonthE.DayOfYear, 0, artList.ColumnCount).ColumnSums().Sum();
 
                     if (DayS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= DayE)
                         statsInfo.lesson.dayInter += interaction.GetInt32();
                     else
                         statsInfo.lesson.dayInter = 0;
 
-                    //if (monthS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= monthE)
-                    //    statsInfo.lesson.monthInter += interaction.GetInt32();
-                    //else
-                    //    statsInfo.lesson.monthInter = 0;
+                    if (monthS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= monthE)
+                        statsInfo.lesson.monthInter += interaction.GetInt32();
+                    else
+                        statsInfo.lesson.monthInter = 0;
 
                     if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
                     {
-                        var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.lesson.year });
-                        statsInfo.lesson.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.lastWeek = ((int)artList.SubMatrix(weekDayS.DayOfYear, 7, 0, artList.ColumnCount).ColumnSums().Sum());
                         //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
                     }
 
@@ -2133,8 +2134,6 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { state = 200, statsInfo });
         }
 
-
-
         public class linqTest
         {
             public string id { get; set; }

+ 52 - 28
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -293,36 +293,36 @@ namespace TEAMModelBI.Controllers.Census
             var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
             var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year");         //计算今年开始/结束时间
 
-            tecCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", "SELECT value(count(c.id)) FROM c WHERE ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'", code: $"Teacher-{schoolId}");
-            stuCount = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", code: $"Base-{schoolId}");
-            classCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", code: $"Class-{schoolId}");
-            roomCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", code: $"Room-{schoolId}");
+            tecCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"Teacher-{schoolId}", "SELECT value(count(c.id)) FROM c WHERE ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'");
+            stuCount = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"Base-{schoolId}");
+            classCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Class-{schoolId}");
+            roomCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Room-{schoolId}");
 
             string unifyTimeSql = "select value(count(c.id)) from c where c.startTime>={0} and c.startTime<={1}";
             allLessCount = await LessonStatisWay.GetSchoolIdLessonCount(cosmosClient, $"{schoolId}");
-            lastWeekLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, lastWeekStart, lastWeekEnd), $"LessonRecord-{schoolId}");
-            weekLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, weekStart, lastWeekEnd), $"LessonRecord-{schoolId}");
-            lastTermLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, lastTermStart, lastTermEnd), $"LessonRecord-{schoolId}");
-            termLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, termStart, termEnd), $"LessonRecord-{schoolId}");
-            lessYearLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, lastYearStart, lastYearEnd), $"LessonRecord-{schoolId}");
+            lastWeekLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, lastWeekStart, lastWeekEnd));
+            weekLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, weekStart, lastWeekEnd));
+            lastTermLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, lastTermStart, lastTermEnd));
+            termLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, termStart, termEnd));
+            lessYearLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, lastYearStart, lastYearEnd));
             yearLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, yearStart, yearEnd), $"LessonRecord-{schoolId}");
 
             //统计活动
             foreach (var type in StaticValue.activityTypes)
             {
                 string sqlTime = "select value(count(c.id)) from c where c.pk = '{0}' and c.school = '{1}' and c.createTime>={2} and c.createTime<={3}";
-                allActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"select value(count(c.id)) from c where c.pk = '{type}' and c.school = '{schoolId}'");
-                lastYearActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", string.Format(sqlTime, type, schoolId, lastYearStart, lastYearEnd));
-                yearActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", string.Format(sqlTime, type, schoolId, yearStart, yearEnd));
-                lastWeekActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", string.Format(sqlTime, type, schoolId, lastWeekStart, lastWeekEnd));
-                weekActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", string.Format(sqlTime, type, schoolId, weekStart, weekEnd));
+                allActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common",$"{type}-{schoolId}", $"select value(count(c.id)) from c where c.pk = '{type}' and c.school = '{schoolId}'");
+                lastYearActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, lastYearStart, lastYearEnd));
+                yearActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, yearStart, yearEnd));
+                lastWeekActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, lastWeekStart, lastWeekEnd));
+                weekActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, weekStart, weekEnd));
             }
 
             //学校资源
             string blobTimeSql = "select value(count(c.id)) from c where c.time>={0} and c.time<={1}";
-            allBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", code: $"Bloblog-{schoolId}");
-            lastYearBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(blobTimeSql, lastYearStart, lastYearEnd), $"Bloblog-{schoolId}");
-            yearBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(blobTimeSql, yearStart, yearEnd), $"Bloblog-{schoolId}");
+            allBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Bloblog-{schoolId}");
+            lastYearBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Bloblog-{schoolId}", string.Format(blobTimeSql, lastYearStart, lastYearEnd));
+            yearBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Bloblog-{schoolId}", string.Format(blobTimeSql, yearStart, yearEnd));
 
             //获取所有的课程记录
             List<LessonRecord> records = new();
@@ -571,10 +571,12 @@ namespace TEAMModelBI.Controllers.Census
                     scStats.lessStats.week = statsInfo.lesson.week;
                     scStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
                     scStats.lessStats.term = statsInfo.lesson.term;
+                    scStats.lessStats.month = statsInfo.lesson.month;
+                    scStats.lessStats.lastMonth = statsInfo.lesson.lastMonth;
                     scStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
                     scStats.lessStats.dayInter = statsInfo.lesson.dayInter;
-                    //scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
-                    //scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
+                    scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
+                    scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
                     scStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
                     scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
                     scStats.lessStats.yearInter = statsInfo.lesson.yearInter;
@@ -654,8 +656,8 @@ namespace TEAMModelBI.Controllers.Census
             jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
             jsonElement.TryGetProperty("role", out JsonElement role);
 
-            if (string.IsNullOrEmpty($"{areaId}") && string.IsNullOrEmpty($"{tmdId}"))
-                return Ok(new { stats = RespondCode.ParamsError, msg = "areaId/tmdId两者参数不能都为空!" });
+            //if (string.IsNullOrEmpty($"{areaId}") && string.IsNullOrEmpty($"{tmdId}"))
+            //    return Ok(new { stats = RespondCode.ParamsError, msg = "areaId/tmdId两者参数不能都为空!" });
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
             Area area = null;
@@ -755,8 +757,8 @@ namespace TEAMModelBI.Controllers.Census
                 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.lastMonthInter = statsInfo.lesson.lastMonthInter;
+                areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
                 areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
                 areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
                 areaScStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
@@ -846,12 +848,32 @@ namespace TEAMModelBI.Controllers.Census
             AllScStats allScStats = new();
             List<StatsInfo> statsInfos = 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 sql = "select value(count(c.id)) from c ";
+            int areaCnt = await JointlySingleQuery.GetValueInt(cosmosClient,"Normal", "Base-Area" , sql);
+            int scCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base", sql);
+            int scWeekCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base", $"{sql} where c.createTime >= {weekS} and c.createTime <= {weekE}");
+            int scMonthCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base", $"{sql} where c.createTime >= {mthS} and c.createTime <= {mthE}");
 
             await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StatsInfo>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
             {
                 statsInfos.Add(item);
             }
-            var areaCnt = statsInfos.GroupBy(g => g.areaId).ToList().Select(s=>s.Where(w=>w.areaId.Equals(s.Key)));
+            var areaGrup = statsInfos.GroupBy(g => g.areaId).ToList().Select(s=>s.Where(w=>w.areaId.Equals(s.Key)));
 
             StatsInfo statsInfo = null;
             statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos);
@@ -881,8 +903,8 @@ namespace TEAMModelBI.Controllers.Census
                 allScStats.lessStats.term = statsInfo.lesson.term;
                 allScStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
                 allScStats.lessStats.dayInter = statsInfo.lesson.dayInter;
-                //allScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
-                //allScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
+                allScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
+                allScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
                 allScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
                 allScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
                 allScStats.actStats.all = statsInfo.activity.all;
@@ -1019,10 +1041,12 @@ namespace TEAMModelBI.Controllers.Census
             public int week { get; set; }
             public int lastTerm { get; set; }
             public int term { get; set; }
+            public int month { get; set; }
+            public int lastMonth { get; set; }
             public int lastDayInter { get; set; }
             public int dayInter { get; set; }
-            //public int lastMonthInter { get; set; }
-            //public int monthInter { get; set; }
+            public int lastMonthInter { get; set; }
+            public int monthInter { get; set; }
             public int lastYearInter { get; set; }
             public int yearInter { get; set; }
         }

+ 5 - 5
TEAMModelBI/Tool/CosmosBank/StatsWay.cs

@@ -111,9 +111,9 @@ 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}");
+            lessStats.all = await JointlySingleQuery.GetValueInt(cosmosClient, "School", code: $"LessonRecord-{id}", $"{currSql}");
+            lessStats.open = await JointlySingleQuery.GetValueInt(cosmosClient, "School", code: $"LessonRecord-{id}", $"{currSql} and c.upload = 0");
+            lessStats.less = await JointlySingleQuery.GetValueInt(cosmosClient, "School", code: $"LessonRecord-{id}", $"{currSql} and c.upload = 1");
 
             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}";
@@ -131,8 +131,8 @@ namespace TEAMModelBI.Tool.CosmosBank
 
             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.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();
 

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

@@ -496,10 +496,10 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                         else
                             statsInfo.lesson.dayInter = 0;
 
-                        //if (monthS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= monthE)
-                        //    statsInfo.lesson.monthInter += interaction.GetInt32();
-                        //else
-                        //    statsInfo.lesson.monthInter = 0;
+                        if (monthS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= monthE)
+                            statsInfo.lesson.monthInter += interaction.GetInt32();
+                        else
+                            statsInfo.lesson.monthInter = 0;
 
                         if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
                         {

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

@@ -17,7 +17,6 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
     {
         public string id { get; set; }
         public string code { get; set; }
-
         /// <summary>
         /// 学校名称
         /// </summary>
@@ -57,10 +56,6 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         public string address { get; set; }
         /// <summary>
-        /// 所在区级Id
-        /// </summary>
-        public string areaId { get; set; }
-        /// <summary>
         /// 规模大小
         /// </summary>
         public int scale { get; set; }

+ 15 - 5
TEAMModelOS.SDK/Models/Cosmos/BI/StatsInfo.cs

@@ -172,6 +172,16 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         public int term { get; set; }
 
+        /// <summary>
+        ///本月
+        /// </summary>
+        public int month { get; set; }
+
+        /// <summary>
+        /// 上月
+        /// </summary>
+        public int lastMonth { get; set; }
+
         /// <summary>
         /// 所有互动
         /// </summary>
@@ -189,12 +199,12 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 上个月互动
         /// </summary>
-        //public int lastMonthInter { get; set; }
+        public int lastMonthInter { get; set; }
 
         /// <summary>
         /// 本月互动
         /// </summary>
-        //public int monthInter { get; set; }
+        public int monthInter { get; set; }
 
         /// <summary>
         /// 去年互动
@@ -208,7 +218,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 今年互动
         /// </summary>
-        public List<double> yearInters { get; set; } = new List<double>();
+        public List<double> yearInters { get; set; } = new List<double>(366);
 
         /// <summary>
         /// 去年每天的数据  366天
@@ -218,7 +228,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 今年每天的数据 366天
         /// </summary>
-        public List<double> year { get; set; } = new List<double>();
+        public List<double> year { get; set; } = new List<double>(366);
 
         /// <summary>
         /// 更新数据时间
@@ -284,7 +294,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 今年活动 366个天
         /// </summary>
-        public List<double> year { get; set; } = new List<double>();
+        public List<double> year { get; set; } = new List<double>(366);
 
         /// <summary>
         /// 活动更新数据时间

+ 6 - 6
TEAMModelOS.SDK/Models/Service/BI/BIStats.cs

@@ -302,10 +302,10 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                     else
                         statsInfo.lesson.dayInter = 0;
 
-                    //if (monthS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= monthE)
-                    //    statsInfo.lesson.monthInter += interaction;
-                    //else
-                    //    statsInfo.lesson.monthInter = 0;
+                    if (monthS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= monthE)
+                        statsInfo.lesson.monthInter += interaction;
+                    else
+                        statsInfo.lesson.monthInter = 0;
 
                     if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
                     {
@@ -396,9 +396,9 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             }
 
             if (resStsInfo.Status == 200)
-                statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, scId, new PartitionKey("Stats"));
+                statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, scId, new PartitionKey("Statistics"));
             else
-                statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));            
+                statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Statistics"));            
         }
     }
 }

+ 7 - 6
TEAMModelOS.SDK/Models/Service/BI/JointlySingleQuery.cs

@@ -1,4 +1,5 @@
 using Azure.Cosmos;
+using DocumentFormat.OpenXml.Bibliography;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -17,7 +18,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="sqlTxt"></param>
         /// <param name="code"></param>
         /// <returns></returns>
-        public static async Task<int> GetValueInt(CosmosClient cosmosClient, List<string> containerId, string sqlTxt = null, string code = null)
+        public static async Task<int> GetValueInt(CosmosClient cosmosClient, List<string> containerId, string code, string sqlTxt = null)
         {
             int totals = 0;
             string sql = $"select value(count(c.id)) from c";
@@ -28,7 +29,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
 
             foreach (string conId in containerId)
             {
-                await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", conId).GetItemQueryIterator<int>(queryText: sql, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+                await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", conId).GetItemQueryIterator<int>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
                 {
                     totals += itemInt;
                 }
@@ -45,7 +46,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="sqlTxt"></param>
         /// <param name="code"></param>
         /// <returns></returns>
-        public static async Task<int> GetValueInt(CosmosClient cosmosClient, string container, string sqlTxt = null, string code = null)
+        public static async Task<int> GetValueInt(CosmosClient cosmosClient, string container, string code, string sqlTxt = null)
         {
             int totals = 0;
             string sql = $"select value(count(c.id)) from c";
@@ -54,7 +55,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                 sql = sqlTxt;
             }
 
-            await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: sql, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
             {
                 totals += itemInt;
             }
@@ -70,11 +71,11 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="sqlTxt"></param>
         /// <param name="code"></param>
         /// <returns></returns>
-        public static async Task<List<string>> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code = null)
+        public static async Task<List<string>> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code)
         {
             List<string> strList = new();
 
-            await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", containerId).GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", containerId).GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
             {
                 strList.Add(itemInt);
             }

+ 4 - 43
TEAMModelOS.SDK/Models/Service/BIStatsWay/LessonRecordStatsWay.cs

@@ -12,7 +12,6 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 {
     public static class LessonRecordStatsWay
     {
-
         /// <summary>
         /// 课例
         /// </summary>
@@ -22,7 +21,6 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
         public static async Task<LessonStats> GetSchoolAll(CosmosClient cosmosClient, string id,int year = 0)
         {
             LessonStats lessStats = new();
-
             DateTimeOffset dateTime = DateTimeOffset.UtcNow;
             if (year == 0)
                 year = dateTime.Year;
@@ -62,12 +60,13 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             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.month = lessRelStats.FindAll(f => f.startTime >= mthS && f.startTime <= mthE).ToList().Count;
+            lessStats.lastMonth = lessRelStats.FindAll(f => f.startTime >= lastMthS && f.startTime <= LastmthE).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 >= lastMthS && f.startTime <= LastmthE).ToList().Select(s => s.clientInteractionCount).Sum();
-            //lessStats.monthInter = lessRelStats.FindAll(f => f.startTime >= mthS && f.startTime <= mthE).ToList().Select(s => s.clientInteractionCount).Sum();
-            //lessStats.lastYearInter = lessRelStats.FindAll(f => f.startTime >= lastYearS && f.startTime <= lastYearE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.lastMonthInter = lessRelStats.FindAll(f => f.startTime >= lastMthS && f.startTime <= LastmthE).ToList().Select(s => s.clientInteractionCount).Sum();
+            lessStats.monthInter = lessRelStats.FindAll(f => f.startTime >= mthS && f.startTime <= mthE).ToList().Select(s => s.clientInteractionCount).Sum();
             lessStats.allInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"select value(sum(c.clientInteractionCount)) from c where c.startTime <= {yearE}", $"LessonRecord-{id}");
             lessStats.lastYearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"select value(sum(c.clientInteractionCount)) from c where c.startTime >= {lastYearS} and c.startTime <= {lastYearE}", $"LessonRecord-{id}");
             //lessStats.yearInter = lessRelStats.FindAll(f => f.startTime >= yearS && f.startTime <= yearE).ToList().Select(s => s.clientInteractionCount).Sum();
@@ -91,44 +90,6 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                     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 yearInterSql = $"{InterSql} and c.startTime >= {yearS} and c.startTime <= {yearE}";
-            //lessStats.yearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", yearInterSql, code: $"LessonRecord-{id}");
             lessStats.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); 
 
             return lessStats;

+ 10 - 10
TEAMModelOS.SDK/Models/Service/BIStatsWay/SchoolStatsWay.cs

@@ -63,20 +63,20 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             statsInfo.year = year;
 
             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", $"Teacher-{scBase.id}", tchSql);
+            statsInfo.dayTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"Teacher-{scBase.id}", $"{tchSql} and {dayWhereSql} ");
+            statsInfo.weekTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Teacher-{scBase.id}", $"{tchSql} and  {weekWhereSql}");
+            statsInfo.monthTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"Teacher-{scBase.id}", $"{tchSql} and  {monthWhereSql}");
             statsInfo.tchUpTime = dateTime.ToUnixTimeMilliseconds();
 
-            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.stu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"Base-{scBase.id}", currSql);
+            statsInfo.dayStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"Base-{scBase.id}", $"{currSql} where {dayWhereSql}");
+            statsInfo.weekStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"Base-{scBase.id}", $"{currSql} where {weekWhereSql}");
+            statsInfo.monthStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"Base-{scBase.id}", $"{currSql} where {monthWhereSql}");
             statsInfo.stuUpTime = dateTime.ToUnixTimeMilliseconds();
 
-            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.room = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"Room-{scBase.id}" ,currSql);
+            statsInfo.witRoom = await JointlySingleQuery.GetValueInt(cosmosClient, "School",  $"Room-{scBase.id}", $"{currSql} where (c.serial != null or c.serial != '' or IS_DEFINED(c.serial) = true)");
 
             //statsInfo.lesson =