Bladeren bron

优化统计查询异常和查询、增减量有误的BUG问题

Li 2 jaren geleden
bovenliggende
commit
e2ad6fabba

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


+ 70 - 64
TEAMModelOS.SDK/Models/Service/BI/BIStats.cs

@@ -29,11 +29,11 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="interaction">互动</param>
         /// <param name="careDate">时间</param>
         /// <returns></returns>
-        public static async Task SetTypeAddStats(CosmosClient cosmosClient, DingDing _dingDing,string scId, string type, int count, int lessType = 0, int interaction = 0, long careDate = 0)
+        public static async Task SetTypeAddStats(CosmosClient cosmosClient, DingDing _dingDing, string scId, string type, int count, int lessType = 0, int interaction = 0, long careDate = 0)
         {
             try
             {
-                if(string.IsNullOrEmpty(scId))
+                if (string.IsNullOrEmpty(scId))
                     return;
 
                 DateTimeOffset cuurDateOff = DateTimeOffset.UtcNow;
@@ -123,7 +123,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                         break;
                     case "Less":
                         //课例
-                        statsInfo.lesson.year[dateOff.DayOfYear] += count;
+                        statsInfo.lesson.year[dateOff.DayOfYear - 1] += count;
                         statsInfo.lesson.all += count;
 
                         if (lessType == 0)
@@ -131,12 +131,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                         else
                             statsInfo.lesson.less += count;
 
-                        statsInfo.lesson.lastDay = ((int)statsInfo.lesson.year[lastDay.DayOfYear]);
-                        statsInfo.lesson.day = ((int)statsInfo.lesson.year[dateOff.DayOfYear]);
+                        statsInfo.lesson.lastDay = ((int)statsInfo.lesson.year[lastDay.DayOfYear - 1]);
+                        statsInfo.lesson.day = ((int)statsInfo.lesson.year[dateOff.DayOfYear - 1]);
 
                         var lessList = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.lesson.year });
-                        statsInfo.lesson.lastWeek = ((int)lessList.SubMatrix(lWeekDayS.DayOfYear, lWeekDayE.DayOfYear - lWeekDayS.DayOfYear, 0, lessList.ColumnCount).ColumnSums().Sum());
-                        statsInfo.lesson.week = ((int)lessList.SubMatrix(weekDayS.DayOfYear, (dateOff.DayOfYear - weekDayS.DayOfYear), 0, lessList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.lastWeek = ((int)lessList.SubMatrix(lWeekDayS.DayOfYear - 1, lWeekDayE.DayOfYear - lWeekDayS.DayOfYear + 1, 0, lessList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.week = ((int)lessList.SubMatrix(weekDayS.DayOfYear - 1, (dateOff.DayOfYear - weekDayS.DayOfYear + 1), 0, lessList.ColumnCount).ColumnSums().Sum());
 
                         StatsInfo lastStats = null;
                         var resLast = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
@@ -152,13 +152,13 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             if (lastStats != null)
                             {
                                 var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStats.lesson.year });
-                                lastTerm += ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lastStats.lesson.year.Count - lTermDayS.DayOfYear, 0, 1).ColumnSums().Sum());
+                                lastTerm += ((int)actYer.SubMatrix(lTermDayS.DayOfYear - 1, lastStats.lesson.year.Count - lTermDayS.DayOfYear + 1, 0, 1).ColumnSums().Sum());
                             }
                             lastTerm += ((int)lessList.SubMatrix(0, lTermDayE.DayOfYear, 0, lessList.ColumnCount).ColumnSums().Sum());
                         }
                         else
                         {
-                            lastTerm += ((int)lessList.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear - lTermDayS.DayOfYear, 0, lessList.ColumnCount).ColumnSums().Sum());
+                            lastTerm += ((int)lessList.SubMatrix(lTermDayS.DayOfYear - 1, lTermDayE.DayOfYear - lTermDayS.DayOfYear + 1, 0, lessList.ColumnCount).ColumnSums().Sum());
                         }
                         statsInfo.lesson.lastTerm = lastTerm;
 
@@ -166,26 +166,26 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                         if (termDayE.Year > dateOff.Year)
                         {
                             if (lastStats != null)
-                                term = ((int)lessList.SubMatrix(termDayS.DayOfYear, (statsInfo.lesson.year.Count - termDayS.DayOfYear), 0, lessList.ColumnCount).ColumnSums().Sum());
+                                term = ((int)lessList.SubMatrix(termDayS.DayOfYear - 1, (statsInfo.lesson.year.Count - termDayS.DayOfYear + 1), 0, lessList.ColumnCount).ColumnSums().Sum());
                         }
                         else
                         {
-                            term = ((int)lessList.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear - termDayS.DayOfYear, 0, lessList.ColumnCount).ColumnSums().Sum());
+                            term = ((int)lessList.SubMatrix(termDayS.DayOfYear - 1, termDayE.DayOfYear - termDayS.DayOfYear + 1, 0, lessList.ColumnCount).ColumnSums().Sum());
                         }
                         statsInfo.lesson.term = term;
 
-                        statsInfo.lesson.lastMonth = ((int)lessList.SubMatrix(lMonthS.DayOfYear, lmthDay, 0, lessList.ColumnCount).ColumnSums().Sum());
-                        statsInfo.lesson.month += ((int)lessList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, lessList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.lastMonth = ((int)lessList.SubMatrix(lMonthS.DayOfYear - 1, lmthDay, 0, lessList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.month += ((int)lessList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, lessList.ColumnCount).ColumnSums().Sum());
 
                         //课例互动
-                        statsInfo.lesson.yearInters[dateOff.DayOfYear] += interaction;
+                        statsInfo.lesson.yearInters[dateOff.DayOfYear - 1] += interaction;
                         statsInfo.lesson.allInter += interaction;
-                        statsInfo.lesson.lastDayInter = ((int)statsInfo.lesson.yearInters[lastDay.DayOfYear]);
-                        statsInfo.lesson.dayInter = ((int)statsInfo.lesson.yearInters[dateOff.DayOfYear]);
+                        statsInfo.lesson.lastDayInter = ((int)statsInfo.lesson.yearInters[lastDay.DayOfYear - 1]);
+                        statsInfo.lesson.dayInter = ((int)statsInfo.lesson.yearInters[dateOff.DayOfYear - 1]);
 
                         var interList = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.lesson.yearInters });
-                        statsInfo.lesson.lastMonthInter = ((int)interList.SubMatrix(lMonthS.DayOfYear, lmthDay, 0, interList.ColumnCount).ColumnSums().Sum());
-                        statsInfo.lesson.monthInter += ((int)interList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, interList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.lastMonthInter = ((int)interList.SubMatrix(lMonthS.DayOfYear - 1, lmthDay, 0, interList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.lesson.monthInter += ((int)interList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, interList.ColumnCount).ColumnSums().Sum());
 
                         int lastTermI = 0;
                         if (lastStats != null)
@@ -198,25 +198,25 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                         statsInfo.lesson.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                         break;
                     case "Student":
-                        statsInfo.stuYear[dateOff.DayOfYear] += count;
+                        statsInfo.stuYear[dateOff.DayOfYear - 1] += count;
                         statsInfo.stu += count;
 
-                        statsInfo.dayStu = ((int)statsInfo.stuYear[dateOff.DayOfYear]);
+                        statsInfo.dayStu = ((int)statsInfo.stuYear[dateOff.DayOfYear - 1]);
                         var stuList = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.stuYear });
-                        statsInfo.weekStu = ((int)stuList.SubMatrix(weekDayS.DayOfYear, (dateOff.DayOfYear - weekDayS.DayOfYear), 0, stuList.ColumnCount).ColumnSums().Sum());
-                        statsInfo.monthStu = ((int)stuList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, stuList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.weekStu = ((int)stuList.SubMatrix(weekDayS.DayOfYear - 1, (dateOff.DayOfYear - weekDayS.DayOfYear + 1), 0, stuList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.monthStu = ((int)stuList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, stuList.ColumnCount).ColumnSums().Sum());
 
                         statsInfo.stuUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                         break;
                     case "Teacher":
 
-                        statsInfo.tchYear[dateOff.DayOfYear] += count;
+                        statsInfo.tchYear[dateOff.DayOfYear - 1] += count;
                         statsInfo.tch += count;
 
-                        statsInfo.dayTch = ((int)statsInfo.tchYear[dateOff.DayOfYear]);
+                        statsInfo.dayTch = ((int)statsInfo.tchYear[dateOff.DayOfYear - 1]);
                         var tchList = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.tchYear });
-                        statsInfo.weekTch = ((int)tchList.SubMatrix(weekDayS.DayOfYear, (dateOff.DayOfYear - weekDayS.DayOfYear), 0, tchList.ColumnCount).ColumnSums().Sum());
-                        statsInfo.monthTch = ((int)tchList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, tchList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.weekTch = ((int)tchList.SubMatrix(weekDayS.DayOfYear - 1, (dateOff.DayOfYear - weekDayS.DayOfYear + 1), 0, tchList.ColumnCount).ColumnSums().Sum());
+                        statsInfo.monthTch = ((int)tchList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, tchList.ColumnCount).ColumnSums().Sum());
 
                         statsInfo.tchUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                         break;
@@ -229,12 +229,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                     {
                         if (count > 0)
                         {
-                            statsInfo.activity.year[dateOff.DayOfYear] += count;
+                            statsInfo.activity.year[dateOff.DayOfYear - 1] += count;
                             DenseMatrix matris = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
-                            statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
-                            statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
-                            statsInfo.activity.lastWeek = ((int)matris.SubMatrix(lWeekDayS.DayOfYear, lWeekDayE.DayOfYear - lWeekDayS.DayOfYear, 0, matris.ColumnCount).ColumnSums().Sum());
-                            statsInfo.activity.week = ((int)matris.SubMatrix(weekDayS.DayOfYear, weekDayE.DayOfYear - weekDayS.DayOfYear, 0, matris.ColumnCount).ColumnSums().Sum());
+                            statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear - 1]);
+                            statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear - 1]);
+                            statsInfo.activity.lastWeek = ((int)matris.SubMatrix(lWeekDayS.DayOfYear - 1, lWeekDayE.DayOfYear - lWeekDayS.DayOfYear + 1, 0, matris.ColumnCount).ColumnSums().Sum());
+                            statsInfo.activity.week = ((int)matris.SubMatrix(weekDayS.DayOfYear - 1, dateOff.DayOfYear - weekDayS.DayOfYear + 1, 0, matris.ColumnCount).ColumnSums().Sum());
 
                             StatsInfo lastStats = null;
                             var resLast = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
@@ -250,13 +250,13 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                 if (lastStats != null)
                                 {
                                     var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStats.lesson.year });
-                                    lastTerm += ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lastStats.lesson.year.Count - lTermDayS.DayOfYear, 0, 1).ColumnSums().Sum());
+                                    lastTerm += ((int)actYer.SubMatrix(lTermDayS.DayOfYear - 1, lastStats.lesson.year.Count - lTermDayS.DayOfYear + 1, 0, 1).ColumnSums().Sum());
                                 }
                                 lastTerm += ((int)matris.SubMatrix(0, lTermDayE.DayOfYear, 0, matris.ColumnCount).ColumnSums().Sum());
                             }
                             else
                             {
-                                lastTerm += ((int)matris.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear - lTermDayS.DayOfYear, 0, matris.ColumnCount).ColumnSums().Sum());
+                                lastTerm += ((int)matris.SubMatrix(lTermDayS.DayOfYear - 1, lTermDayE.DayOfYear - lTermDayS.DayOfYear + 1, 0, matris.ColumnCount).ColumnSums().Sum());
                             }
                             statsInfo.activity.lastTerm = lastTerm;
 
@@ -267,13 +267,13 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                 if (lastStats != null)
                                 {
                                     var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStats.lesson.year });
-                                    term += ((int)actYer.SubMatrix(termDayS.DayOfYear, lastStats.lesson.year.Count - termDayS.DayOfYear, 0, 1).ColumnSums().Sum());
+                                    term += ((int)actYer.SubMatrix(termDayS.DayOfYear - 1, lastStats.lesson.year.Count - termDayS.DayOfYear + 1, 0, 1).ColumnSums().Sum());
                                 }
-                                term += ((int)matris.SubMatrix(0, termDayE.DayOfYear, 0, matris.ColumnCount).ColumnSums().Sum());
+                                term += ((int)matris.SubMatrix(0, termDayE.DayOfYear + 1, 0, matris.ColumnCount).ColumnSums().Sum());
                             }
                             else
                             {
-                                term += ((int)matris.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear - termDayS.DayOfYear, 0, matris.ColumnCount).ColumnSums().Sum());
+                                term += ((int)matris.SubMatrix(termDayS.DayOfYear - 1, termDayE.DayOfYear - termDayS.DayOfYear + 1, 0, matris.ColumnCount).ColumnSums().Sum());
                             }
                             statsInfo.activity.term = term;
 
@@ -326,7 +326,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                 statsInfo.tch = 1;
                 statsInfo.weekTch = 1;
                 statsInfo.monthTch = 1;
-                statsInfo.tchUpTime = dateOff.ToUnixTimeMilliseconds();                
+                statsInfo.tchUpTime = dateOff.ToUnixTimeMilliseconds();
                 statsInfo.lesson.year = new double[366].ToList();
                 statsInfo.lesson.yearInters = new double[366].ToList();
                 statsInfo.activity.year = new double[366].ToList();
@@ -359,7 +359,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="_dingDing"></param>
         /// <param name="school"></param>
         /// <returns></returns>
-        public static async Task SetSchoolBIRelation(CosmosClient cosmosClient,  BlobContainerClient blobClient, CloudTableClient tableClient, DingDing _dingDing, School school) 
+        public static async Task SetSchoolBIRelation(CosmosClient cosmosClient, BlobContainerClient blobClient, CloudTableClient tableClient, DingDing _dingDing, School school)
         {
             string type = "";
             BIRelation bIRelation = new();
@@ -375,7 +375,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             }
 
             string aName = null;
-            if (!string.IsNullOrEmpty($"{school.areaId}")) 
+            if (!string.IsNullOrEmpty($"{school.areaId}"))
             {
                 aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{school.areaId}'", "Base-Area");
             }
@@ -464,73 +464,79 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                         }
 
                         var tchList = DenseMatrix.OfColumns(new List<List<double>>() { item.tchYear });
-                        item.dayTch = ((int)item.tchYear[lastDay.DayOfYear]);
-                        item.weekTch = ((int)tchList.SubMatrix(weekDayS.DayOfYear, 7, 0, tchList.ColumnCount).ColumnSums().Sum());
-                        item.monthTch = ((int)tchList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, tchList.ColumnCount).ColumnSums().Sum());
+                        item.dayTch = ((int)item.tchYear[lastDay.DayOfYear - 1]);
+                        item.weekTch = ((int)tchList.SubMatrix(weekDayS.DayOfYear - 1, 7, 0, tchList.ColumnCount).ColumnSums().Sum());
+                        item.monthTch = ((int)tchList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, tchList.ColumnCount).ColumnSums().Sum());
                         item.tchUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
 
                         var stuList = DenseMatrix.OfColumns(new List<List<double>>() { item.stuYear });
-                        item.dayStu = ((int)item.stuYear[lastDay.DayOfYear]);
-                        item.weekStu = ((int)stuList.SubMatrix(weekDayS.DayOfYear, 7, 0, stuList.ColumnCount).ColumnSums().Sum());
-                        item.monthStu = ((int)stuList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, stuList.ColumnCount).ColumnSums().Sum());
+                        item.dayStu = ((int)item.stuYear[lastDay.DayOfYear - 1]);
+                        item.weekStu = ((int)stuList.SubMatrix(weekDayS.DayOfYear - 1, 7, 0, stuList.ColumnCount).ColumnSums().Sum());
+                        item.monthStu = ((int)stuList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, stuList.ColumnCount).ColumnSums().Sum());
                         item.stuUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
 
                         var lessList = DenseMatrix.OfColumns(new List<List<double>>() { item.lesson.year });
                         item.lesson.lastDay = item.lesson.day;
-                        item.lesson.lastWeek = ((int)lessList.SubMatrix(lWeekDayS.DayOfYear, 7, 0, lessList.ColumnCount).ColumnSums().Sum());
-                        item.lesson.week = ((int)lessList.SubMatrix(weekDayS.DayOfYear, 7, 0, lessList.ColumnCount).ColumnSums().Sum());
+                        item.lesson.lastWeek = ((int)lessList.SubMatrix(lWeekDayS.DayOfYear - 1, 7, 0, lessList.ColumnCount).ColumnSums().Sum());
+                        item.lesson.week = ((int)lessList.SubMatrix(weekDayS.DayOfYear - 1, (dateOff.DayOfYear - weekDayS.DayOfYear + 1), 0, lessList.ColumnCount).ColumnSums().Sum());
 
                         if (lTermDayS.Year < dateOff.Year)
                         {
                             if (lastStatsInfo != null)
                             {
                                 var lessYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.lesson.year, item.lesson.year });
-                                item.lesson.lastTerm = ((int)lessYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                item.lesson.lastTerm = ((int)lessYer.SubMatrix(lTermDayS.DayOfYear - 1, lTermDayE.DayOfYear + 1, 0, 1).ColumnSums().Sum());
                             }
                         }
-                        item.lesson.term = ((int)lessList.SubMatrix(termDayS.DayOfYear, termDay, 0, 1).ColumnSums().Sum());
+                        item.lesson.term = ((int)lessList.SubMatrix(termDayS.DayOfYear - 1, termDay + 1, 0, 1).ColumnSums().Sum());
 
                         item.lesson.day = 0;
-                        item.lesson.lastMonth = ((int)lessList.SubMatrix(lMonthS.DayOfYear, lmthDay, 0, lessList.ColumnCount).ColumnSums().Sum());
-                        item.lesson.month += ((int)lessList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, lessList.ColumnCount).ColumnSums().Sum());
+                        item.lesson.lastMonth = ((int)lessList.SubMatrix(lMonthS.DayOfYear - 1, lmthDay + 1, 0, lessList.ColumnCount).ColumnSums().Sum());
+                        item.lesson.month += ((int)lessList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, lessList.ColumnCount).ColumnSums().Sum());
                         item.lesson.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
 
                         var interList = DenseMatrix.OfColumns(new List<List<double>>() { item.lesson.yearInters });
-                        item.lesson.lastDayInter = ((int)item.lesson.yearInters[lastDay.DayOfYear]);
+                        item.lesson.lastDayInter = ((int)item.lesson.yearInters[lastDay.DayOfYear - 1]);
                         item.lesson.dayInter = 0;
-                        item.lesson.lastMonthInter = ((int)interList.SubMatrix(lMonthS.DayOfYear, lmthDay, 0, interList.ColumnCount).ColumnSums().Sum());
-                        item.lesson.monthInter = ((int)interList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, interList.ColumnCount).ColumnSums().Sum());
+                        item.lesson.lastMonthInter = ((int)interList.SubMatrix(lMonthS.DayOfYear - 1, lmthDay + 1, 0, interList.ColumnCount).ColumnSums().Sum());
+                        item.lesson.monthInter = ((int)interList.SubMatrix(monthDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, interList.ColumnCount).ColumnSums().Sum());
 
                         if (lastStatsInfo != null)
                         {
                             var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.lesson.yearInters });
-                            item.lesson.lastYearInter = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, 366, 0, 1).ColumnSums().Sum());
+                            item.lesson.lastYearInter = ((int)actYer.SubMatrix(lTermDayS.DayOfYear - 1, actYer.RowCount, 0, actYer.ColumnCount).ColumnSums().Sum());
                         }
 
                         item.lesson.yearInter = ((int)item.lesson.yearInters.Sum());
 
-                        item.activity.dayCnt = ((int)item.activity.year[dateOff.DayOfYear]);
-                        item.activity.lastDay = ((int)item.activity.year[lastDay.DayOfYear]);
+                        item.activity.dayCnt = ((int)item.activity.year[dateOff.DayOfYear - 1]);
+                        item.activity.lastDay = ((int)item.activity.year[lastDay.DayOfYear - 1]);
                         var actList = DenseMatrix.OfColumns(new List<List<double>>() { item.activity.year });
-                        item.activity.lastWeek = ((int)actList.SubMatrix(lWeekDayS.DayOfYear, 7, 0, actList.ColumnCount).ColumnSums().Sum());
-                        item.activity.week = ((int)actList.SubMatrix(weekDayS.DayOfYear, 7, 0, actList.ColumnCount).ColumnSums().Sum());
+                        item.activity.lastWeek = ((int)actList.SubMatrix(lWeekDayS.DayOfYear - 1, 7, 0, actList.ColumnCount).ColumnSums().Sum());
+                        item.activity.week = ((int)actList.SubMatrix(weekDayS.DayOfYear - 1, (dateOff.DayOfYear - monthDayS.DayOfYear + 1), 0, actList.ColumnCount).ColumnSums().Sum());
 
                         if (lMonthS.Year == dateOff.Year)
                         {
-                            item.activity.lastMonth = ((int)actList.SubMatrix(lMonthS.DayOfYear, lMonthE.DayOfYear, 0, actList.ColumnCount).ColumnSums().Sum());
+                            item.activity.lastMonth = ((int)actList.SubMatrix(lMonthS.DayOfYear - 1, lMonthE.DayOfYear + 1, 0, actList.ColumnCount).ColumnSums().Sum());
                         }
                         else
                         {
                             var lastMthYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.activity.year });
-                            item.activity.lastMonth = ((int)lastMthYer.SubMatrix(lMonthS.DayOfYear, lMonthE.DayOfYear, 0, actList.ColumnCount).ColumnSums().Sum());
+                            item.activity.lastMonth = ((int)lastMthYer.SubMatrix(lMonthS.DayOfYear - 1, lMonthE.DayOfYear + 1, 0, actList.ColumnCount).ColumnSums().Sum());
+                        }
+                        if (monthDayE.Year > dateOff.Year)
+                        {
+                            item.activity.month = ((int)actList.SubMatrix(monthDayS.DayOfYear - 1, actList.RowCount, 0, actList.ColumnCount).ColumnSums().Sum());
+                        }
+                        else
+                        {
+                            item.activity.month = ((int)actList.SubMatrix(monthDayS.DayOfYear - 1, monthDayE.DayOfYear + 1, 0, actList.ColumnCount).ColumnSums().Sum());
                         }
-
-                        item.activity.month = ((int)actList.SubMatrix(monthDayS.DayOfYear, monthDayE.DayOfYear, 0, actList.ColumnCount).ColumnSums().Sum());
 
                         if (lastStatsInfo != null)
                         {
                             var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.activity.year });
-                            item.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            item.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear - 1, lTermDayE.DayOfYear + 1, 0, 1).ColumnSums().Sum());
                         }
 
                         item.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

+ 8 - 89
TEAMModelOS.SDK/Models/Service/BIStatsWay/SchoolStatsWay.cs

@@ -75,18 +75,18 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             string tchSql = $"{currSql} where ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'";
             statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Teacher-{scBase.id}", tchSql);
 
-            List<double> tchDoubles = await UserStatsWay.GetYearTecherStudent(cosmosClient, scBase.id, year, 1); 
+            List<double> tchDoubles = await UserStatsWay.GetYearTecherStudent(cosmosClient, scBase.id, year, 1);
             statsInfo.tchYear = tchDoubles;
-            statsInfo.dayTch = ((int)tchDoubles[dateTime.DayOfYear]);
+            statsInfo.dayTch = ((int)tchDoubles[dateTime.DayOfYear - 1]);
             DenseMatrix tchDouble = DenseMatrix.OfColumns(new List<List<double>>() { tchDoubles });
             int weekDay = 0;
-            if ((dateTime.DayOfYear - weekDayS.DayOfYear) <= 7) 
-                weekDay = dateTime.DayOfYear - weekDayS.DayOfYear;
+            if ((dateTime.DayOfYear - weekDayS.DayOfYear) <= 7)
+                weekDay = dateTime.DayOfYear - weekDayS.DayOfYear + 1;
             else
                 weekDay = 7;
 
-            statsInfo.weekTch = ((int)tchDouble.SubMatrix(weekDayS.DayOfYear, weekDay, 0, tchDouble.ColumnCount).ColumnSums().Sum());
-            statsInfo.monthTch += ((int)tchDouble.SubMatrix(monthDayS.DayOfYear, (dateTime.DayOfYear - monthDayS.DayOfYear), 0, tchDouble.ColumnCount).ColumnSums().Sum());
+            statsInfo.weekTch = ((int)tchDouble.SubMatrix(weekDayS.DayOfYear-1, weekDay, 0, tchDouble.ColumnCount).ColumnSums().Sum());
+            statsInfo.monthTch += ((int)tchDouble.SubMatrix(monthDayS.DayOfYear-1, (dateTime.DayOfYear - monthDayS.DayOfYear+1), 0, tchDouble.ColumnCount).ColumnSums().Sum());
 
             //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}");
@@ -98,8 +98,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             statsInfo.stuYear = stuDoubles;
             statsInfo.dayStu = ((int)stuDoubles[dateTime.DayOfYear]);
             DenseMatrix stuDouble = DenseMatrix.OfColumns(new List<List<double>>() { stuDoubles });
-            statsInfo.weekStu = ((int)stuDouble.SubMatrix(weekDayS.DayOfYear, weekDay, 0, stuDouble.ColumnCount).ColumnSums().Sum());
-            statsInfo.monthStu += ((int)stuDouble.SubMatrix(monthDayS.DayOfYear, (dateTime.DayOfYear - monthDayS.DayOfYear), 0, stuDouble.ColumnCount).ColumnSums().Sum());
+            statsInfo.weekStu = ((int)stuDouble.SubMatrix(weekDayS.DayOfYear-1, weekDay, 0, stuDouble.ColumnCount).ColumnSums().Sum());
+            statsInfo.monthStu += ((int)stuDouble.SubMatrix(monthDayS.DayOfYear-1, (dateTime.DayOfYear - monthDayS.DayOfYear+1), 0, stuDouble.ColumnCount).ColumnSums().Sum());
 
             //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}");
@@ -187,89 +187,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             //areaInfo.activity.LastYear = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.activity.LastYear).ToList());
             areaInfo.activity.year = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.activity.year).Where(w => w.Count > 0).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;
         }
-
-        public static async Task<List<T>> GetLastYearType<T>(CosmosClient cosmosClient, List<string> scIds)
-        {
-            List<T> list = new();
-            StringBuilder statsSql = new("select value(c) from c");
-            if (scIds.Count > 0)
-            {
-                statsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds, $"{DateTimeOffset.UtcNow.Year - 1}-")}");
-            }
-
-
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<T>(queryText: statsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
-            {
-                list.Add(item);
-
-            }
-
-            return list;
-        }
-
-
        
     }
 }