Forráskód Böngészése

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

zhouj1203@hotmail.com 2 éve
szülő
commit
525dbf2c97
35 módosított fájl, 1371 hozzáadás és 490 törlés
  1. 307 64
      TEAMModelBI/Controllers/BITest/TestController.cs
  2. 12 12
      TEAMModelBI/Controllers/Census/SchoolController.cs
  3. 6 4
      TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs
  4. 15 16
      TEAMModelBI/Tool/CosmosBank/StatsWay.cs
  5. 338 39
      TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs
  6. 1 1
      TEAMModelOS.FunctionV4/Program.cs
  7. 5 143
      TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs
  8. 59 8
      TEAMModelOS.FunctionV4/ServiceBus/ServiceBusSub.cs
  9. 3 3
      TEAMModelOS.SDK/Extension/JwtAuthExtension.cs
  10. 1 1
      TEAMModelOS.SDK/Models/Cosmos/BI/BISchool/BIRelation.cs
  11. 34 9
      TEAMModelOS.SDK/Models/Cosmos/BI/StatsInfo.cs
  12. 22 9
      TEAMModelOS.SDK/Models/Service/BI/BICommonWay.cs
  13. 404 0
      TEAMModelOS.SDK/Models/Service/BI/BIStats.cs
  14. 23 0
      TEAMModelOS.SDK/Models/Service/BI/TimeHelper.cs
  15. 9 9
      TEAMModelOS.SDK/Models/Service/BIStatsWay/ActivityStatsWay.cs
  16. 8 8
      TEAMModelOS.SDK/Models/Service/BIStatsWay/LessonRecordStatsWay.cs
  17. 17 14
      TEAMModelOS.SDK/Models/Service/BIStatsWay/SchoolStatsWay.cs
  18. 2 0
      TEAMModelOS.SDK/Models/Service/BIStatsWay/StudyStatsWay.cs
  19. 31 0
      TEAMModelOS.SDK/Models/Service/Common/BlobService.cs
  20. 2 2
      TEAMModelOS.SDK/Models/Service/GroupListService.cs
  21. 4 7
      TEAMModelOS.SDK/Models/Service/HomeworkService.cs
  22. 3 6
      TEAMModelOS.SDK/Models/Service/LessonService.cs
  23. 5 14
      TEAMModelOS/Controllers/Both/ItemController.cs
  24. 7 9
      TEAMModelOS/Controllers/Both/PaperController.cs
  25. 2 7
      TEAMModelOS/Controllers/Client/HiTeachController.cs
  26. 2 3
      TEAMModelOS/Controllers/Client/HiTeachccControlller.cs
  27. 1 1
      TEAMModelOS/Controllers/Common/AreaController.cs
  28. 9 21
      TEAMModelOS/Controllers/Common/ExamController.cs
  29. 9 16
      TEAMModelOS/Controllers/Common/HomeworkController.cs
  30. 1 1
      TEAMModelOS/Controllers/Common/StudyController.cs
  31. 5 15
      TEAMModelOS/Controllers/Common/SurveyController.cs
  32. 10 16
      TEAMModelOS/Controllers/Common/VoteController.cs
  33. 12 20
      TEAMModelOS/Controllers/System/BlobController.cs
  34. 1 8
      TEAMModelOS/Controllers/Teacher/CommentController.cs
  35. 1 4
      TEAMModelOS/Controllers/XTest/FixDataController.cs

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 307 - 64
TEAMModelBI/Controllers/BITest/TestController.cs


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

@@ -520,7 +520,7 @@ namespace TEAMModelBI.Controllers.Census
             {
                 bool isExist = true;
                 StatsInfo statsInfo = new();
-                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey("Stats"));
+                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{DateTimeOffset.UtcNow.Year}-{scId}", new PartitionKey("Statistics"));
                 if (scDataStats.Status == 200)
                 {
                     using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
@@ -569,9 +569,9 @@ namespace TEAMModelBI.Controllers.Census
                     scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
                     scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
                     scStats.lessStats.yearInter = statsInfo.lesson.yearInter;
-                    scStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
+                    //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;
+                    scStats.actStats.all = statsInfo.activity.all;
                     scStats.actStats.exam = statsInfo.activity.exam;
                     scStats.actStats.survey = statsInfo.activity.survey;
                     scStats.actStats.vote = statsInfo.activity.vote;
@@ -582,7 +582,7 @@ namespace TEAMModelBI.Controllers.Census
                     scStats.actStats.week = statsInfo.activity.week;
                     scStats.actStats.lastTerm = statsInfo.activity.lastTerm;
                     scStats.actStats.term = statsInfo.activity.term;
-                    scStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear, dateTime.Year, dateTime.Month);
+                    //scStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear, dateTime.Year, dateTime.Month);
                     scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
                     if (statsInfo.study != null)
                     {
@@ -662,13 +662,13 @@ namespace TEAMModelBI.Controllers.Census
             StringBuilder statsSql = new("select value(c) from c");
             if (scIds.Count > 0)
             {
-                statsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds)}");
+                statsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds, $"{DateTimeOffset.UtcNow.Year}-")}");
             }
 
             DateTimeOffset dateTime = DateTimeOffset.UtcNow;
             List<ScStats> scStatss = new();
             List<StatsInfo> statsInfos = new();
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StatsInfo>(queryText: statsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Stats") }))
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StatsInfo>(queryText: statsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
             {
                 statsInfos.Add(item);
             }
@@ -709,9 +709,9 @@ namespace TEAMModelBI.Controllers.Census
                 areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
                 areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
                 areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
-                areaScStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
+                //areaScStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
                 areaScStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
-                areaScStats.actStats.cnt = statsInfo.activity.cnt;
+                areaScStats.actStats.all = statsInfo.activity.all;
                 areaScStats.actStats.exam = statsInfo.activity.exam;
                 areaScStats.actStats.survey = statsInfo.activity.survey;
                 areaScStats.actStats.vote = statsInfo.activity.vote;
@@ -722,7 +722,7 @@ namespace TEAMModelBI.Controllers.Census
                 areaScStats.actStats.week = statsInfo.activity.week;
                 areaScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
                 areaScStats.actStats.term = statsInfo.activity.term;
-                areaScStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear, dateTime.Year, dateTime.Month);
+                //areaScStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear, dateTime.Year, dateTime.Month);
                 areaScStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
                 if (statsInfo.study != null)
                 {
@@ -736,9 +736,9 @@ namespace TEAMModelBI.Controllers.Census
                     areaScStats.srStats.finish = statsInfo.study.finish;
                 }
             }
-            var scInfos = statsInfos.Select(s => new { s.id, s.name, s.picture, actLess = (s.lesson.all + s.activity.cnt), actCnt = s.activity.cnt, lessCnt = s.lesson.all, lessOpen = s.lesson.open, lessUp = s.lesson.less }).ToList();
+            var scInfos = statsInfos.Select(s => new { s.id, s.schoolId, s.name, s.picture, actLess = (s.lesson.all + s.activity.all), actCnt = s.activity.all, lessCnt = s.lesson.all, lessOpen = s.lesson.open, lessUp = s.lesson.less }).ToList();
 
-            return Ok(new { state = RespondCode.Ok, areaScStats,  });
+            return Ok(new { state = RespondCode.Ok, areaScStats, scInfos });
         }
 
         /// <summary>
@@ -881,7 +881,7 @@ namespace TEAMModelBI.Controllers.Census
         /// </summary>
         public record ScActStats
         {
-            public int cnt { get; set; }
+            public int all { get; set; }
             public int exam { get; set; }
             public int survey { get; set; }
             public int vote { get; set; }

+ 6 - 4
TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs

@@ -508,12 +508,14 @@ namespace TEAMModelBI.Controllers.RepairApi
             else
                 scIds = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
 
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+
             List<StatsInfo> statsInfos = new();
             List<Task<ItemResponse<StatsInfo>>> taskStss = new();
             foreach (var sc in scIds) 
             {
                 StatsInfo statsInfo = new();
-                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{sc}", new PartitionKey("Stats"));
+                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{dateTime.Year}-{sc}", new PartitionKey("Statistics"));
                 if (scDataStats.Status == 200)
                 {
                     using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
@@ -521,15 +523,15 @@ namespace TEAMModelBI.Controllers.RepairApi
                 }
                 else
                 {
-                    statsInfo.id = sc;
+                    statsInfo.id = $"{dateTime.Year}-{sc}";
                 }
 
                 statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, sc);
 
                 if (scDataStats.Status == 200)
-                    taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, sc, new PartitionKey("Stats")));
+                    taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, $"{dateTime.Year}-{sc}", new PartitionKey("Statistics")));
                 else
-                    taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats")));
+                    taskStss.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Statistics")));
 
                 //statsInfo = await StatsWay.upSingleSc(cosmosClient, sc);
                 statsInfos.Add(statsInfo);

+ 15 - 16
TEAMModelBI/Tool/CosmosBank/StatsWay.cs

@@ -140,13 +140,13 @@ namespace TEAMModelBI.Tool.CosmosBank
             List<StartEndTime> leveryDay = TimeHelper.GetYearEveryDay(lyearDay);
             List<StartEndTime> everyDay = TimeHelper.GetYearEveryDay(DateTimeOffset.UtcNow);
 
-            for (int i = 0; i < leveryDay.Count; i++)
-            {
-                if (lessStats.LastYear.Count == 366)
-                    lessStats.LastYear[i] = (double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count;
-                else
-                    lessStats.LastYear.Add((double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count);
-            }
+            //for (int i = 0; i < leveryDay.Count; i++)
+            //{
+            //    if (lessStats.LastYear.Count == 366)
+            //        lessStats.LastYear[i] = (double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count;
+            //    else
+            //        lessStats.LastYear.Add((double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count);
+            //}
 
             for (int i = 0; i < everyDay.Count; i++)
             {
@@ -329,14 +329,13 @@ namespace TEAMModelBI.Tool.CosmosBank
 
             if (tempAll.Count > 0) 
             {
-
-                for (int i = 0; i < leveryDay.Count; i++)
-                {
-                    if (actStats.LastYear.Count == 366)
-                        actStats.LastYear[i] = (double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count;
-                    else
-                        actStats.LastYear.Add((double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count);
-                }
+                //for (int i = 0; i < leveryDay.Count; i++)
+                //{
+                //    if (actStats.LastYear.Count == 366)
+                //        actStats.LastYear[i] = (double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count;
+                //    else
+                //        actStats.LastYear.Add((double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count);
+                //}
 
                 for (int i = 0; i < everyDay.Count; i++)
                 {
@@ -396,7 +395,7 @@ namespace TEAMModelBI.Tool.CosmosBank
             //            break;
             //    }
             //}
-            actStats.cnt = (exam + survey + vote + homework);
+            actStats.all = (exam + survey + vote + homework);
             actStats.exam = exam;
             actStats.survey = survey;
             actStats.vote = vote;

+ 338 - 39
TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs

@@ -9,11 +9,13 @@ using System.Threading.Tasks;
 using Azure.Cosmos;
 using Azure.Storage.Blobs;
 using DocumentFormat.OpenXml.Bibliography;
+using MathNet.Numerics.LinearAlgebra.Double;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Azure.Functions.Worker;
 using Microsoft.Azure.Functions.Worker.Http;
 using NUnit.Framework.Constraints;
 using StackExchange.Redis;
+using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
@@ -193,56 +195,54 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             dynamic jsondata = new ExpandoObject();
             try
             {
-                string scId = null,type = null;
-                var cosmosClient = _azureCosmos.GetCosmosClient();
-                var tableClient = _azureStorage.GetCloudTableClient();
-                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 string data = await new StreamReader(req.Body).ReadToEndAsync();
                 var json = JsonDocument.Parse(data).RootElement;
                 jsondata = json;
+
+                string scId = null, type = null;
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 long careDate = 0;
-                int cnt = 0;
-                                
+                int all = 0;
+
                 DateTimeOffset dateOff = DateTimeOffset.UtcNow;
-                if (!json.TryGetProperty("scId", out JsonElement _schoolId))
-                {
+                if (json.TryGetProperty("scId", out JsonElement _schoolId))
                     scId = $"{_schoolId}";
-                }
-                if (!json.TryGetProperty("type", out JsonElement _type))
-                {
+                if (json.TryGetProperty("type", out JsonElement _type))
                     type = $"{_type}";
-                }
-                if (string.IsNullOrEmpty(scId) && string.IsNullOrEmpty(type))
+                if (string.IsNullOrEmpty($"{_schoolId}") && string.IsNullOrEmpty($"{_type}"))
                 {
-                    await _dingDing.SendBotMsg($"set-scstats-type, {req.Body};转换后:{json}", GroupNames.成都开发測試群組);
+                    await _dingDing.SendBotMsg($"set-scstats-type, {json}", GroupNames.成都开发測試群組);
                     return response;
                 }
-                if (!json.TryGetProperty("cnt", out JsonElement _cnt)) 
-                {
-                    cnt = int.Parse($"{_cnt}");
-                }
+                if (json.TryGetProperty("cnt", out JsonElement _cnt))
+                    all = _cnt.GetInt32();
 
-                if (!json.TryGetProperty("date", out JsonElement _date)) 
-                {
-                    careDate = long.Parse($"{_date}");
-                }
+                json.TryGetProperty("interaction", out JsonElement interaction);
+
+                if (json.TryGetProperty("date", out JsonElement _date))
+                    careDate = _date.GetInt64();
                 else
-                {
                     careDate = dateOff.ToUnixTimeMilliseconds();
-                }
-
-                long currDay = dateOff.ToUnixTimeMilliseconds();
-                var (lastDays, lastDaye) = TimeHelper.GetStartOrEnd(dateOff.AddDays(-1));//昨天开始/结束时间
+                var (lastDayS, lastDayE) = TimeHelper.GetStartOrEnd(dateOff.AddDays(-1));//昨天开始/结束时间
                 var (DayS, DayE) = TimeHelper.GetStartOrEnd(dateOff);      //今天开始时间结束时间
                 var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateOff, "lastweek");   //计算上周开始/结束时间
                 var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateOff, "week");             //计算本周开始/结束时间
+                var (lastMonthS, lastMonthE) = TimeHelper.GetStartOrEnd(dateOff, "lastMonth");   //计算上月开始/结束时间
+                var (monthS, monthE) = TimeHelper.GetStartOrEnd(dateOff, "month");             //计算本月开始/结束时间
                 var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateOff, "lastterm");   //计算上学期开始/结束时间
                 var (termS, termE) = TimeHelper.GetStartOrEnd(dateOff, "term");   //计算本学期开始/结束时间
                 var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(dateOff, "lastYear"); //计算去年开始/结束时间
                 var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateOff, "year");         //计算今年开始/结束时间
-                StatsInfo statsInfo  = new();
 
-                var resStsInfo  = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(scId, new PartitionKey("BIRel"));
+                var (weekDayS, weekDayE) = TimeHelper.GetLongToTime(lastWeekS, lastWeekE);
+                var (lTermDayS, lTermDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
+                var (termDayS, termDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
+                var lastDay = dateOff.AddDays(-1);
+
+                StatsInfo statsInfo = new();
+                var resStsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{dateOff.Year}-{scId}", new PartitionKey("Statistics"));
                 if (resStsInfo.Status == 200)
                 {
                     using var fileJson = await JsonDocument.ParseAsync(resStsInfo.ContentStream);
@@ -251,52 +251,351 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                 else
                 {
                     ScBase scBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<ScBase>(scId, new PartitionKey("Base"));
-                    statsInfo.id = scBase.id;
+
+                    //var resLastStsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{dateOff.Year - 1}-{scId}", new PartitionKey("Statistics"));
+                    //if (resLastStsInfo.Status == 200)
+                    //{
+                    //    using var fileJson = await JsonDocument.ParseAsync(resStsInfo.ContentStream);
+                    //    statsInfo = fileJson.ToObject<StatsInfo>();
+                    //    statsInfo.id = $"{dateOff.Year}-{scBase.id}";
+                    //}
+                    //else 
+                    //{
+                    statsInfo.id = $"{dateOff.Year}-{scBase.id}";
                     statsInfo.name = scBase.name;
                     statsInfo.picture = scBase.picture;
                     statsInfo.size = scBase.size;
                     statsInfo.scCreateTime = scBase.createTime;
                     statsInfo.areaId = scBase.areaId;
-                    statsInfo.upTime = currDay;
+                    statsInfo.upTime = careDate;
+                    //}
                 }
 
                 switch ($"{type}")
                 {
                     case "Exam":
-                        if (statsInfo.upTime < DayS && statsInfo.upTime >= lastDays) 
+                        statsInfo.activity.year[dateOff.DayOfYear] += all;
+                        statsInfo.activity.exam += all;
+                        statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                        statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                        if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
                         {
-                            statsInfo.activity.lastDay = statsInfo.activity.dayCnt;
-                            statsInfo.activity.year[dateOff.DayOfYear-1] += statsInfo.activity.dayCnt;
+                            var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                            statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                            //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
                         }
-                        if (DayS <= statsInfo.upTime && statsInfo.upTime <= DayE)
+
+                        if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                            statsInfo.activity.week += all;
+
+                        if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
                         {
-                            statsInfo.activity.dayCnt += cnt;
-                            statsInfo.activity.exam += cnt;
-                            statsInfo.activity.year[dateOff.DayOfYear] += cnt;
+                            if (lTermDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.lastTerm = 0;
+                            }
                         }
 
+                        if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                        {
+                            if (termDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.term += all;
+                            }
+                        }
 
-                        statsInfo.activity.cnt += cnt;
+                        statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        statsInfo.activity.all += all;
                         break;
                     case "Survey":
+                        statsInfo.activity.year[dateOff.DayOfYear] += all;
+                        statsInfo.activity.survey += all;
+                        statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                        statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                        if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                        {
+                            var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                            statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                            //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                        }
 
+                        if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                            statsInfo.activity.week += all;
+
+                        if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                        {
+                            if (lTermDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.lastTerm = 0;
+                            }
+                        }
+
+                        if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                        {
+                            if (termDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.term += all;
+                            }
+                        }
+
+                        statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        statsInfo.activity.all += all;
                         break;
                     case "Vote":
+                        statsInfo.activity.year[dateOff.DayOfYear] += all;
+                        statsInfo.activity.vote += all;
+                        statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                        statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                        if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                        {
+                            var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                            statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                            //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                        }
 
+                        if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                            statsInfo.activity.week += all;
+
+                        if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                        {
+                            if (lTermDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.lastTerm = 0;
+                            }
+                        }
+
+                        if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                        {
+                            if (termDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.term += all;
+                            }
+                        }
+
+                        statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        statsInfo.activity.all += all;
                         break;
                     case "Homework":
+                        statsInfo.activity.year[dateOff.DayOfYear] += all;
+                        statsInfo.activity.homework += all;
+                        statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                        statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                        if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                        {
+                            var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                            statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                            //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                        }
 
+                        if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                            statsInfo.activity.week += all;
+
+                        if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                        {
+                            if (lTermDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.lastTerm = 0;
+                            }
+                        }
+
+                        if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                        {
+                            if (termDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                    statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.activity.term += all;
+                            }
+                        }
+
+                        statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        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]);
+
+                        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 (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.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                        }
+
+                        if (weekS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= weekE)
+                            statsInfo.activity.week += all;
+
+                        if (lastTermS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= lastTermE)
+                        {
+                            if (lTermDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.lesson.year, statsInfo.lesson.year });
+                                    statsInfo.lesson.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.lesson.lastTerm = 0;
+                            }
+                        }
+
+                        if (termS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= termE)
+                        {
+                            if (termDayS.Year < dateOff.Year)
+                            {
+                                var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                                if (lastSts.Status == 200)
+                                {
+                                    using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                    var tempSts = fileJson.ToObject<StatsInfo>();
+                                    var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.lesson.year, statsInfo.lesson.year });
+                                    statsInfo.lesson.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                                }
+                                else
+                                    statsInfo.lesson.term += all;
+                            }
+                        }
+
+                        statsInfo.lesson.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        statsInfo.lesson.all += all;
                         break;
                     case "stu":
+                        if (DayS <= statsInfo.stuUpTime && statsInfo.stuUpTime < DayE)
+                            statsInfo.dayStu += 1;
+                        else
+                            statsInfo.dayStu = 0;
 
+
+                        if (weekS <= statsInfo.stuUpTime && statsInfo.stuUpTime < weekE)
+                            statsInfo.weekStu += 1;
+                        else
+                            statsInfo.weekStu = 0;
+
+                        if (monthS <= statsInfo.stuUpTime && statsInfo.stuUpTime < monthE)
+                            statsInfo.monthStu += 1;
+                        else
+                            statsInfo.monthStu = 0;
+
+                        statsInfo.stuUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        statsInfo.stu += all;
                         break;
                     case "tch":
+                        if (DayS <= statsInfo.tchUpTime && statsInfo.tchUpTime < DayE)
+                            statsInfo.dayTch += 1;
+                        else
+                            statsInfo.dayTch = 0;
+
+                        if (weekS <= statsInfo.tchUpTime && statsInfo.tchUpTime < weekE)
+                            statsInfo.weekTch += 1;
+                        else
+                            statsInfo.weekTch = 0;
+
+                        if (monthS <= statsInfo.tchUpTime && statsInfo.tchUpTime < monthE)
+                            statsInfo.monthTch += 1;
+                        else
+                            statsInfo.monthTch = 0;
 
+                        statsInfo.tchUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        statsInfo.stu += all;
+
+                        statsInfo.tch += all;
                         break;
                 }
+
+                if (resStsInfo.Status == 200)
+                    statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, scId, new PartitionKey("Stats"));
+                else
+                    statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));
+
             }
             catch (Exception ex)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/Program.cs

@@ -71,7 +71,7 @@ namespace TEAMModelOS.FunctionV4
                    storageConnects.Add(("LogStorage", LogStorageConnectionString));   //防火墙日志统计文件
                }
                services.AddMultipleAzureStorage(storageConnects);
-              // services.AddHostedService<ServiceBusSub>();
+              services.AddHostedService<BlobRootServiceBusSub>();
                services.AddIPSearcher("");
            })
            .Build();

+ 5 - 143
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -276,140 +276,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
 
         }
 
-        /// <summary>
-        /// 根据容器的根目录刷新redis并获取redis的最新使用情况
-        /// </summary>
-        /// <param name="msg"></param>
-        /// <returns></returns>
-        [Function("BlobRoot")]
-        public async Task BlobRootFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blobroot", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
-        {
-            try
-            {
-
-                var jsonMsg = JsonDocument.Parse(msg);
-                return;
-                if (jsonMsg.RootElement.TryGetProperty("name", out JsonElement _name) && _name.ValueKind == JsonValueKind.String)
-                {
-                    if (jsonMsg.RootElement.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String && !string.IsNullOrWhiteSpace($"{root}"))
-                    {
-                        List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
-                        string[] uls = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/");
-                        string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
-                        string name = $"{_name}";
-                        string lockKey = $"Blob:Lock:{name}:{u}";
-                        bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
-
-                        if (!exist)
-                        {   ///key不存在则正常进行计算
-                            bool condition = false;
-                            TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(15).Ticks);
-                            timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
-                            //准备处理Blob刷新时间
-                            long action = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                            await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, action, expiry: timeSpan);
-                            await RefreshBlob(name, u);
-                            //将action 与Redis最新的时间进行比较,如果
-                            var rds = await CheckLockKey(lockKey, action);
-                            condition = rds.condition;
-                            exist = rds.exist;
-                            if (condition || !exist)
-                            {
-                                await RefreshBlob(name, u);
-                            }
-
-                            //使用  CancellationToken 
-                            //while (condition || !exist)
-                            //{
-
-                            //}
-                        }
-                        else
-                        {
-                            ///key存在则,则刷新key对应的值
-                            TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(15).Ticks);
-                            timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
-                            long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                            await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, now, expiry: timeSpan);
-                        }
-                    }
-                    else
-                    {
-                        var client = _azureStorage.GetBlobContainerClient($"{_name}");
-                        var size = await client.GetBlobsCatalogSize();
-                        await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{_name}", size.Item1);
-                        foreach (var key in size.Item2.Keys)
-                        {
-                            await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{_name}", key);
-                            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{_name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
-                        }
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
-            }
-        }
-
-        private async Task<(bool condition, bool exist)> CheckLockKey(string lockKey, long nowTime)
-        {
-            //Redis的最新时间
-            long newestTime = 0;
-            RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(lockKey);
-            if (value != default && !value.IsNullOrEmpty)
-            {
-                JsonElement record = value.ToString().ToObject<JsonElement>();
-                if (record.TryGetInt64(out newestTime))
-                {
-                }
-            }
-            //说明key已经不存在
-            if (newestTime == 0)
-            {
-                return (false, true);
-            }
-            //说明key存在
-            else
-            {
-                //说明Redis记录了最新的时间戳
-                if (nowTime != newestTime)
-                {
-                    return (true, false);
-                }
-                //时间相同,没有被再次记录最新的时间戳
-                else
-                {
-                    await _azureRedis.GetRedisClient(8).KeyDeleteAsync(lockKey);
-                    return (false, true);
-                }
-            }
-        }
-        private async Task RefreshBlob(string name, string u)
-        {
-            long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-            var client = _azureStorage.GetBlobContainerClient(name);
-            var size = await client.GetBlobsSize(u);
-            await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
-            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
-            var scores = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
-            double blobsize = 0;
-            if (scores != default && scores != null)
-            {
-                foreach (var score in scores)
-                {
-                    blobsize = blobsize + score.Score;
-                }
-            }
-            await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue(name), new RedisValue($"{blobsize}"));
-            long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-            long dis = (end - statr) / 1000;
-            long timeout = 60 * 5;
-            if (dis > timeout)
-            {
-                await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:空间计算已经超过{timeout}秒\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}", GroupNames.醍摩豆服務運維群組);
-            }
-        }
+      
+       
         /// <param name="msg"></param>
         /// <returns></returns>
         [Function("TeacherTrainChange")]
@@ -1569,12 +1437,9 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                         periodId = string.IsNullOrWhiteSpace(lessonRecord.periodId) ? new List<string>() : new List<string> { lessonRecord.periodId },
                                         size = size.HasValue ? size.Value : 0,
                                     };
-                                    await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog);
-                                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
-                                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                                    await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog); 
                                     //await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} blob刷新完成!", GroupNames.醍摩豆服務運維群組);
+                                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage {  progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration,_azureRedis);
                                     msgs.Add(update);
 
                                     DoLessonStudentRecord(_dingDing, _snowflakeId, lessonRecord, scope, client, school, tmdid, teacher,   _serviceBus, _azureStorage, _configuration, lessonBase);
@@ -1650,10 +1515,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     }
                                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, new List<string> { $"records/{_lessonId}" });
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(lessonRecord.id, new PartitionKey($"Bloblog-{blobname}"));
-                                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
-                                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage {   progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration, _azureRedis);
                                     msgs.Add(update);
                                 }
                                 catch (CosmosException)

+ 59 - 8
TEAMModelOS.FunctionV4/ServiceBus/ServiceBusSub.cs

@@ -1,41 +1,63 @@
 using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Hosting;
+using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net.Http;
+using System.ServiceModel.Channels;
 using System.Text;
+using System.Text.Json;
 using System.Threading;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Services;
 using static TEAMModelOS.FunctionV4.HttpTrigger.IESHttpTrigger;
 
 namespace TEAMModelOS.FunctionV4
 {
-    public class ServiceBusSub : BackgroundService, IDisposable
+    public class BlobRootServiceBusSub : BackgroundService, IDisposable
     {
         private readonly AzureStorageFactory _azureStorage;
-        private readonly AzureRedisFactory _azureRedisFactory;
+        private readonly AzureRedisFactory _azureRedis;
         private readonly ServiceBusReceiver _receiver;
-        private const string Channel = "screenpdf";
+        private readonly DingDing _dingDing;
+        private const string Channel = "BlobRoot";
         public static SpinWait spinWait = new SpinWait(); // 构造SpinWait实例
-        public ServiceBusSub(AzureRedisFactory azureRedisFactory,  AzureStorageFactory azureStorage, AzureServiceBusFactory azureService)
+        public BlobRootServiceBusSub(DingDing dingDing, AzureRedisFactory azureRedisFactory,  AzureStorageFactory azureStorage, AzureServiceBusFactory azureService)
         {
-            _receiver = azureService.GetServiceBusClient("Default").CreateReceiver(Channel, new ServiceBusReceiverOptions { ReceiveMode = ServiceBusReceiveMode.PeekLock });
+            _receiver = azureService.GetServiceBusClient().CreateReceiver(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), Channel, new ServiceBusReceiverOptions { ReceiveMode = ServiceBusReceiveMode.PeekLock });
             _azureStorage = azureStorage;
-            _azureRedisFactory = azureRedisFactory;
+            _azureRedis = azureRedisFactory;
+            _dingDing = dingDing;
         }
         protected async override Task ExecuteAsync(CancellationToken stoppingToken)
         {
             while (true)
             {
-                IReadOnlyList<ServiceBusReceivedMessage> receivedMessages = await _receiver.ReceiveMessagesAsync(maxMessages: 1);
-                //单条数据 5 分钟未释放。进入死信
+                //30分钟。进入死信
+                IReadOnlyList<ServiceBusReceivedMessage> receivedMessages = await _receiver.ReceiveMessagesAsync(maxMessages: 1,maxWaitTime:new TimeSpan(0,30,0));
                 foreach (ServiceBusReceivedMessage receivedMessage in receivedMessages)
                 {
                     try
                     {
                         string body = receivedMessage.Body.ToString();
+                        var jsonMsg = body.ToObject<BlobRefreshMessage>();
+                        if ( !string.IsNullOrWhiteSpace($"{jsonMsg.root}") && !string.IsNullOrWhiteSpace($"{jsonMsg.name}"))
+                        {
+                            string lockKey = $"Blob:Lock:{jsonMsg.name}:{jsonMsg.root}";
+                            bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
+                            if (exist) {
+                                string[] uls = System.Web.HttpUtility.UrlDecode($"{jsonMsg.root}", Encoding.UTF8).Split("/");
+                                string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
+                                string name = $"{jsonMsg.name}";
+                                await RefreshBlob(name, u);
+                                await _azureRedis.GetRedisClient(8).KeyDeleteAsync(lockKey);
+                            }
+                        }
+                        await _receiver.CompleteMessageAsync(receivedMessage);
                     }
                     catch
                     {
@@ -47,5 +69,34 @@ namespace TEAMModelOS.FunctionV4
                 spinWait.SpinOnce();
             }
         }
+ 
+
+      
+        private async Task RefreshBlob(string name, string u)
+        {
+            long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            var client = _azureStorage.GetBlobContainerClient(name);
+            var size = await client.GetBlobsSize(u);
+            await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
+            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
+            var scores = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
+            double blobsize = 0;
+            if (scores != default && scores != null)
+            {
+                foreach (var score in scores)
+                {
+                    blobsize = blobsize + score.Score;
+                }
+            }
+            await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue(name), new RedisValue($"{blobsize}"));
+            long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            long dis = (end - statr) / 1000;
+            long timeout = 60 * 5;
+            if (dis > timeout)
+            {
+                await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:空间计算已经超过{timeout}秒\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}\n文件夹大小:{blobsize}", GroupNames.醍摩豆服務運維群組);
+            }
+            //await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}\n文件夹大小:{blobsize}", GroupNames.醍摩豆服務運維群組);
+        }
     }
 }

+ 3 - 3
TEAMModelOS.SDK/Extension/JwtAuthExtension.cs

@@ -22,7 +22,7 @@ namespace TEAMModelOS.SDK.Extension
                 { JwtRegisteredClaimNames.Iss, issuer }, //發行者
                 { JwtRegisteredClaimNames.Sub, id }, // 用戶ID                  
                 { JwtRegisteredClaimNames.Azp,schoolID}, // 學校簡碼,如果有的話
-                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
+                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds()},  // 到期的時間,必須為數字
                 { "name",name}, // 用戶的顯示名稱
                 { "picture",picture}, // 用戶頭像
                 { "roles",roles}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
@@ -180,7 +180,7 @@ namespace TEAMModelOS.SDK.Extension
                 { JwtRegisteredClaimNames.Azp,schoolID}, // 學校簡碼,如果有的話
                 {JwtRegisteredClaimNames.Jti,Guid.NewGuid().ToString() },
                 { "name",name}, // 用戶的顯示名稱
-                //{ JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
+                //{ JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds()},  // 到期的時間,必須為數字
                 //{ "name",name}, // 用戶的顯示名稱
                 //{ "picture",picture}, // 用戶頭像
                 { "auth",auth}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
@@ -269,7 +269,7 @@ namespace TEAMModelOS.SDK.Extension
             {
                 { JwtRegisteredClaimNames.Iss,issuser}, //发行者
                 { JwtRegisteredClaimNames.Sub,id},   //用户ID
-                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},//到期时间
+                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds()},//到期时间
                 { "name",name},//用户显示名称
                 { "picture",picture}, // 用户头像
                 { "roles",roles}, //登陆者的角色, (admin、dea) 

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/BI/BISchool/BIRelation.cs

@@ -17,7 +17,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI.BISchool
         public BIRelation()
         {
             code = "BIRel";
-            pk = "Stats";
+            pk = "Statistics";
         }
         /// <summary>
         /// 学校名称

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

@@ -8,16 +8,18 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
 {
     public class StatsInfo : CosmosEntity
     {
-        //id  学校id
-        //pk   Stats
-        //code Stats
+        //id   2022-hbcn  年份-学校id
+        //pk   Statistics
+        //code Statistics
         ///code   Stats-hbcn  Stats-学校id   Stats-学区id    暂未启用
         public StatsInfo()
         {
-            pk = "Stats";
-            code = "Stats";
+            pk = "Statistics";
+            code = "Statistics";
         }
 
+        public string schoolId { get; set; }
+        public int year { get; set; }
         /// <summary>
         /// 学校头像
         /// </summary>
@@ -57,7 +59,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// 本月新增教师
         /// </summary>
         public int monthTch { get; set; }
-
+        /// <summary>
+        /// 教师更新时间
+        /// </summary>
+        public long tchUpTime { get; set; }
         /// <summary>
         /// 学生总数
         /// </summary>
@@ -78,6 +83,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         public int monthStu { get; set; }
 
+        /// <summary>
+        /// 学生信息更新时间
+        /// </summary>
+        public long stuUpTime { get; set; }
         /// <summary>
         /// 教室数
         /// </summary>
@@ -197,13 +206,18 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 去年每天的数据  366天
         /// </summary>
-        public List<double> LastYear { get; set; } = new List<double>();
+        //public List<double> LastYear { get; set; } = new List<double>();
 
         /// <summary>
         /// 今年每天的数据 366天
         /// </summary>
         public List<double> year { get; set; } = new List<double>();
 
+        /// <summary>
+        /// 更新数据时间
+        /// </summary>
+        public long upTime { get; set; }
+
     }
 
     /// <summary>
@@ -214,7 +228,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 所有活动总数
         /// </summary>
-        public int cnt { get; set; }
+        public int all { get; set; }
         /// <summary>
         /// 评测活动总数
         /// </summary>
@@ -258,11 +272,17 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 去年活动 366个天
         /// </summary>
-        public List<double> LastYear { get; set; } = new List<double>();
+        //public List<double> LastYear { get; set; } = new List<double>();
+
         /// <summary>
         /// 今年活动 366个天
         /// </summary>
         public List<double> year { get; set; } = new List<double>();
+
+        /// <summary>
+        /// 活动更新数据时间
+        /// </summary>
+        public long upTime { get; set; }
     }
 
     /// <summary>
@@ -302,6 +322,11 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// 完成的研修人数
         /// </summary>
         public int finish { get; set; }
+
+        /// <summary>
+        /// 研修更新数据时间
+        /// </summary>
+        public long upTime { get; set; }
     }
 
 

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

@@ -40,7 +40,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="condName"></param>
         /// <param name="scIds"></param>
         /// <returns></returns>
-        public static string ManyScSql(string condName, List<string> scIds) 
+        public static string ManyScSql(string condName, List<string> scIds, string addStr = null)
         {
             StringBuilder scSql = new();
             if (scIds.Count > 0)
@@ -49,9 +49,20 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                 for (int i = 0; i < scIds.Count; i++)
                 {
                     if (i == scIds.Count - 1)
-                        scSql.Append($"'{scIds[i]}'");
+                    {
+                        if (string.IsNullOrEmpty(addStr))
+                            scSql.Append($"'{scIds[i]}'");
+                        else
+                            scSql.Append($"'{addStr}{scIds[i]}'");
+                    }
                     else
-                        scSql.Append($"'{scIds[i]}',");
+                    {
+                        if (string.IsNullOrEmpty(addStr))
+                            scSql.Append($"'{scIds[i]}',");
+                        else
+                            scSql.Append($"'{addStr}{scIds[i]}',");
+                    }
+
                 }
                 scSql.Append($" )");
             }
@@ -67,14 +78,16 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         public static List<double> ManyDoubleMerge(List<List<double>> doubles)
         {
             List<double> retDou = new();
-            var artYear = DenseMatrix.OfColumns(doubles);
-            //var rc = artYear.RowCount;
-            var cc = artYear.ColumnCount;
-            for (int i = 0; i < artYear.RowCount; i++)
+            if (doubles.Count > 0) 
             {
-                retDou.Add(artYear.SubMatrix(i, 1, 0, cc).ColumnSums().Sum());
+                var artYear = DenseMatrix.OfColumns(doubles);
+                //var rc = artYear.RowCount;
+                var cc = artYear.ColumnCount;
+                for (int i = 0; i < artYear.RowCount; i++)
+                {
+                    retDou.Add(artYear.SubMatrix(i, 1, 0, cc).ColumnSums().Sum());
+                }
             }
-
             return retDou;
         }
 

+ 404 - 0
TEAMModelOS.SDK/Models/Service/BI/BIStats.cs

@@ -0,0 +1,404 @@
+using Azure.Cosmos;
+using MathNet.Numerics.LinearAlgebra.Double;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Context.Constant;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+
+namespace TEAMModelOS.SDK.Models.Service.BI
+{
+    public static class BIStats
+    {
+        /// <summary>
+        /// 依据类型增/减量统计方法
+        /// </summary>
+        /// <param name="cosmosClient">连接字符</param>
+        /// <param name="scId">学校id</param>
+        /// <param name="type">类型:Exam(测验) Survey(问卷调查) Vote(投票) Homework(作业)  Less(课例) Student(学生)  Tchaer(教师) </param>
+        /// <param name="count">增减数量 </param>
+        /// <param name="careDate">时间</param>
+        /// <param name="interaction">互动</param>
+        /// <returns></returns>
+        public static async Task SetTypeAddStats(CosmosClient cosmosClient,string scId,string type,int count,long careDate = 0,int interaction=0)
+        {
+            DateTimeOffset dateOff = DateTimeOffset.UtcNow;
+            if (careDate == 0)
+                careDate = dateOff.ToUnixTimeMilliseconds();
+
+            var (lastDayS, lastDayE) = TimeHelper.GetStartOrEnd(dateOff.AddDays(-1));//昨天开始/结束时间
+            var (DayS, DayE) = TimeHelper.GetStartOrEnd(dateOff);      //今天开始时间结束时间
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateOff, "lastweek");   //计算上周开始/结束时间
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateOff, "week");             //计算本周开始/结束时间
+            var (lastMonthS, lastMonthE) = TimeHelper.GetStartOrEnd(dateOff, "lastMonth");   //计算上月开始/结束时间
+            var (monthS, monthE) = TimeHelper.GetStartOrEnd(dateOff, "month");             //计算本月开始/结束时间
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateOff, "lastterm");   //计算上学期开始/结束时间
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dateOff, "term");   //计算本学期开始/结束时间
+            var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(dateOff, "lastYear"); //计算去年开始/结束时间
+            var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateOff, "year");         //计算今年开始/结束时间
+
+            var (weekDayS, weekDayE) = TimeHelper.GetLongToTime(lastWeekS, lastWeekE);
+            var (lTermDayS, lTermDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
+            var (termDayS, termDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
+            var lastDay = dateOff.AddDays(-1);
+
+            StatsInfo statsInfo = new();
+            var resStsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{dateOff.Year}-{scId}", new PartitionKey("Statistics"));
+            if (resStsInfo.Status == 200)
+            {
+                using var fileJson = await JsonDocument.ParseAsync(resStsInfo.ContentStream);
+                statsInfo = fileJson.ToObject<StatsInfo>();
+            }
+            else
+            {
+                ScBase scBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<ScBase>(scId, new PartitionKey("Base"));
+
+                //var resLastStsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{dateOff.Year - 1}-{scId}", new PartitionKey("Statistics"));
+                //if (resLastStsInfo.Status == 200)
+                //{
+                //    using var fileJson = await JsonDocument.ParseAsync(resStsInfo.ContentStream);
+                //    statsInfo = fileJson.ToObject<StatsInfo>();
+                //    statsInfo.id = $"{dateOff.Year}-{scBase.id}";
+                //}
+                //else 
+                //{
+                statsInfo.id = $"{dateOff.Year}-{scBase.id}";
+                statsInfo.name = scBase.name;
+                statsInfo.picture = scBase.picture;
+                statsInfo.size = scBase.size;
+                statsInfo.scCreateTime = scBase.createTime;
+                statsInfo.areaId = scBase.areaId;
+                statsInfo.upTime = careDate;
+                //}
+            }
+
+            switch ($"{type}")
+            {
+                case "Exam":
+                    statsInfo.activity.year[dateOff.DayOfYear] += count;
+                    statsInfo.activity.exam += count;
+                    statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                    statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                    if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                    {
+                        var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                        statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                        //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                    }
+
+                    if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                        statsInfo.activity.week += count;
+
+                    if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                    {
+                        if (lTermDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.lastTerm = 0;
+                        }
+                    }
+
+                    if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                    {
+                        if (termDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.term += count;
+                        }
+                    }
+
+                    statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.activity.all += count;
+                    break;
+                case "Survey":
+                    statsInfo.activity.year[dateOff.DayOfYear] += count;
+                    statsInfo.activity.survey += count;
+                    statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                    statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                    if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                    {
+                        var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                        statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                        //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                    }
+
+                    if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                        statsInfo.activity.week += count;
+
+                    if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                    {
+                        if (lTermDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.lastTerm = 0;
+                        }
+                    }
+
+                    if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                    {
+                        if (termDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.term += count;
+                        }
+                    }
+
+                    statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.activity.all += count;
+                    break;
+                case "Vote":
+                    statsInfo.activity.year[dateOff.DayOfYear] += count;
+                    statsInfo.activity.vote += count;
+                    statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                    statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                    if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                    {
+                        var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                        statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                        //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                    }
+
+                    if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                        statsInfo.activity.week += count;
+
+                    if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                    {
+                        if (lTermDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.lastTerm = 0;
+                        }
+                    }
+
+                    if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                    {
+                        if (termDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.term += count;
+                        }
+                    }
+
+                    statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.activity.all += count;
+                    break;
+                case "Homework":
+                    statsInfo.activity.year[dateOff.DayOfYear] += count;
+                    statsInfo.activity.homework += count;
+                    statsInfo.activity.lastDay = ((int)statsInfo.activity.year[lastDay.DayOfYear]);
+                    statsInfo.activity.dayCnt = ((int)statsInfo.activity.year[dateOff.DayOfYear]);
+
+                    if (lastWeekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastWeekE)
+                    {
+                        var artWeek = DenseMatrix.OfColumns(new List<List<double>>() { statsInfo.activity.year });
+                        statsInfo.activity.lastWeek = ((int)artWeek.SubMatrix(weekDayS.DayOfYear, 7, 0, artWeek.ColumnCount).ColumnSums().Sum());
+                        //statsInfo.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                    }
+
+                    if (weekS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= weekE)
+                        statsInfo.activity.week += count;
+
+                    if (lastTermS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= lastTermE)
+                    {
+                        if (lTermDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.lastTerm = 0;
+                        }
+                    }
+
+                    if (termS <= statsInfo.activity.upTime && statsInfo.activity.upTime <= termE)
+                    {
+                        if (termDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.activity.year, statsInfo.activity.year });
+                                statsInfo.activity.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.activity.term += count;
+                        }
+                    }
+
+                    statsInfo.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.activity.all += count;
+                    break;
+                case "Less":
+
+                    statsInfo.lesson.year[dateOff.DayOfYear] += count;
+                    statsInfo.lesson.lastDay = ((int)statsInfo.lesson.year[lastDay.DayOfYear]);
+                    statsInfo.lesson.day = ((int)statsInfo.lesson.year[dateOff.DayOfYear]);
+
+                    if (DayS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= DayE)
+                        statsInfo.lesson.dayInter += interaction;
+                    else
+                        statsInfo.lesson.dayInter = 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)
+                    {
+                        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.activity.lastWeek = ((int)statsInfo.activity.year.GetRange(weekDayS.DayOfYear, 7).Sum());
+                    }
+
+                    if (weekS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= weekE)
+                        statsInfo.activity.week += count;
+
+                    if (lastTermS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= lastTermE)
+                    {
+                        if (lTermDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lTermDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.lesson.year, statsInfo.lesson.year });
+                                statsInfo.lesson.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.lesson.lastTerm = 0;
+                        }
+                    }
+
+                    if (termS <= statsInfo.lesson.upTime && statsInfo.lesson.upTime <= termE)
+                    {
+                        if (termDayS.Year < dateOff.Year)
+                        {
+                            var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{termDayS.Year}-{scId}", new PartitionKey("Statistics"));
+                            if (lastSts.Status == 200)
+                            {
+                                using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
+                                var tempSts = fileJson.ToObject<StatsInfo>();
+                                var actYer = DenseMatrix.OfColumns(new List<List<double>>() { tempSts.lesson.year, statsInfo.lesson.year });
+                                statsInfo.lesson.term = ((int)actYer.SubMatrix(termDayS.DayOfYear, termDayE.DayOfYear, 0, 1).ColumnSums().Sum());
+                            }
+                            else
+                                statsInfo.lesson.term += count;
+                        }
+                    }
+
+                    statsInfo.lesson.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.lesson.all += count;
+                    break;
+                case "Student":
+                    if (DayS <= statsInfo.stuUpTime && statsInfo.stuUpTime < DayE)
+                        statsInfo.dayStu += count;
+                    else
+                        statsInfo.dayStu = 0;
+
+
+                    if (weekS <= statsInfo.stuUpTime && statsInfo.stuUpTime < weekE)
+                        statsInfo.weekStu += count;
+                    else
+                        statsInfo.weekStu = 0;
+
+                    if (monthS <= statsInfo.stuUpTime && statsInfo.stuUpTime < monthE)
+                        statsInfo.monthStu += count;
+                    else
+                        statsInfo.monthStu = 0;
+
+                    statsInfo.stuUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.stu += count;
+                    break;
+                case "Teacher":
+                    if (DayS <= statsInfo.tchUpTime && statsInfo.tchUpTime < DayE)
+                        statsInfo.dayTch += count;
+                    else
+                        statsInfo.dayTch = 0;
+
+                    if (weekS <= statsInfo.tchUpTime && statsInfo.tchUpTime < weekE)
+                        statsInfo.weekTch += count;
+                    else
+                        statsInfo.weekTch = 0;
+
+                    if (monthS <= statsInfo.tchUpTime && statsInfo.tchUpTime < monthE)
+                        statsInfo.monthTch += count;
+                    else
+                        statsInfo.monthTch = 0;
+
+                    statsInfo.tchUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    statsInfo.tch += count;
+                    break;
+            }
+
+            if (resStsInfo.Status == 200)
+                statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, scId, new PartitionKey("Stats"));
+            else
+                statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));            
+        }
+    }
+}

+ 23 - 0
TEAMModelOS.SDK/Models/Service/BI/TimeHelper.cs

@@ -21,6 +21,29 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// </summary>
         public static List<int> leapY = new() { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
+
+        /// <summary>
+        /// 将时间戳转换成时间
+        /// </summary>
+        /// <param name="dateS"></param>
+        /// <param name="dateE"></param>
+        /// <returns></returns>
+        public static (DateTimeOffset timeS, DateTimeOffset timeE) GetLongToTime(long dateS,long dateE)
+        {
+            DateTimeOffset timeS = new(), timeE = new();
+            if (dateS > 1000000000000)
+                timeS = DateTimeOffset.FromUnixTimeMilliseconds(dateS);
+            else
+                timeS = DateTimeOffset.FromUnixTimeSeconds(dateS);
+
+            if (dateE > 1000000000000)
+                timeE = DateTimeOffset.FromUnixTimeMilliseconds(dateE);
+            else
+                timeE = DateTimeOffset.FromUnixTimeSeconds(dateE);
+
+            return (timeS, timeE);
+        }
+
         /// <summary>
         /// 通过时间戳转换为时间
         /// </summary>

+ 9 - 9
TEAMModelOS.SDK/Models/Service/BIStatsWay/ActivityStatsWay.cs

@@ -140,14 +140,13 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 
             if (tempAll.Count > 0)
             {
-
-                for (int i = 0; i < leveryDay.Count; i++)
-                {
-                    if (actStats.LastYear.Count == 366)
-                        actStats.LastYear[i] = (double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count;
-                    else
-                        actStats.LastYear.Add((double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count);
-                }
+                //for (int i = 0; i < leveryDay.Count; i++)
+                //{
+                //    if (actStats.LastYear.Count == 366)
+                //        actStats.LastYear[i] = (double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count;
+                //    else
+                //        actStats.LastYear.Add((double)tempAll.FindAll(f => (f.createTime >= leveryDay[i].start && f.createTime <= leveryDay[i].end)).Count);
+                //}
 
                 for (int i = 0; i < everyDay.Count; i++)
                 {
@@ -207,7 +206,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             //            break;
             //    }
             //}
-            actStats.cnt = (exam + survey + vote + homework);
+            actStats.all = (exam + survey + vote + homework);
             actStats.exam = exam;
             actStats.survey = survey;
             actStats.vote = vote;
@@ -218,6 +217,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             actStats.week = week;
             actStats.lastTerm = lastTerm;
             actStats.term = term;
+            actStats.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
 
             return actStats;
         }

+ 8 - 8
TEAMModelOS.SDK/Models/Service/BIStatsWay/LessonRecordStatsWay.cs

@@ -70,13 +70,13 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             List<StartEndTime> leveryDay = TimeHelper.GetYearEveryDay(lyearDay);
             List<StartEndTime> everyDay = TimeHelper.GetYearEveryDay(DateTimeOffset.UtcNow);
 
-            for (int i = 0; i < leveryDay.Count; i++)
-            {
-                if (lessStats.LastYear.Count == 366)
-                    lessStats.LastYear[i] = (double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count;
-                else
-                    lessStats.LastYear.Add((double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count);
-            }
+            //for (int i = 0; i < leveryDay.Count; i++)
+            //{
+            //    if (lessStats.LastYear.Count == 366)
+            //        lessStats.LastYear[i] = (double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count;
+            //    else
+            //        lessStats.LastYear.Add((double)lessRelStats.FindAll(f => (f.startTime >= leveryDay[i].start && f.startTime <= leveryDay[i].end)).Count);
+            //}
 
             for (int i = 0; i < everyDay.Count; i++)
             {
@@ -124,7 +124,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 
             //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;
         }

+ 17 - 14
TEAMModelOS.SDK/Models/Service/BIStatsWay/SchoolStatsWay.cs

@@ -28,9 +28,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
         /// <returns></returns>
         public static async Task<StatsInfo> GetSingleSc(CosmosClient cosmosClient, string scId)
         {
-            StatsInfo statsInfo = new() { id = $"{scId}" };
-
             DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            StatsInfo statsInfo = new() { id = $"{dateTime.Year}-{scId}" };
             var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime);  //今天开始时间    13位
             var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek");   //计算上周开始/结束时间
             var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
@@ -49,7 +48,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             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"));
+            ScBase scBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<ScBase>(scId, new PartitionKey("Base"));
+            statsInfo.schoolId = scBase.id;
             statsInfo.name = scBase.name;
             statsInfo.picture = scBase.picture;
             statsInfo.size = scBase.size;
@@ -61,11 +61,13 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             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.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.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}");
@@ -73,9 +75,9 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             //statsInfo.lesson = 
 
             statsInfo.upTime = dateTime.ToUnixTimeMilliseconds();
-            statsInfo.lesson = await LessonRecordStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
-            statsInfo.activity = await ActivityStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
-            statsInfo.study = await StudyStatsWay.GetSchoolAll(cosmosClient, statsInfo.id);
+            statsInfo.lesson = await LessonRecordStatsWay.GetSchoolAll(cosmosClient, statsInfo.schoolId);
+            statsInfo.activity = await ActivityStatsWay.GetSchoolAll(cosmosClient, statsInfo.schoolId);
+            statsInfo.study = await StudyStatsWay.GetSchoolAll(cosmosClient, statsInfo.schoolId);
 
             return statsInfo;
         }
@@ -94,10 +96,11 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
         {
             StatsInfo areaInfo = new()
             {
-                id = area == null ? "" : area.id,
-                pk = "Stats",
-                code = "Stats",
+                id = area == null ? "" : $"{DateTimeOffset.UtcNow.Year}-{area.id}",
+                pk = "Statistics",
+                code = "Statistics",
                 name = area == null ? "" : area.name,
+                areaId = area == null ? "" :area.id,
                 picture = "",
                 tch = statsInfos.Select(s => s.tch).Sum(),
                 dayTch = statsInfos.Select(s => s.dayTch).Sum(),
@@ -126,11 +129,11 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             areaInfo.lesson.monthInter = statsInfos.Select(s => s.lesson.monthInter).Sum();
             areaInfo.lesson.lastYearInter = statsInfos.Select(s => s.lesson.lastYearInter).Sum();
             areaInfo.lesson.yearInter = statsInfos.Select(s => s.lesson.yearInter).Sum();
-            areaInfo.lesson.LastYear = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.lesson.LastYear).ToList());
-            areaInfo.lesson.year = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.lesson.year).ToList());
+            //areaInfo.lesson.LastYear = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.lesson.LastYear).ToList());
+            areaInfo.lesson.year = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList());
 
 
-            areaInfo.activity.cnt = statsInfos.Select(s => s.activity.cnt).Sum();
+            areaInfo.activity.all = statsInfos.Select(s => s.activity.all).Sum();
             areaInfo.activity.exam = statsInfos.Select(s => s.activity.exam).Sum();
             areaInfo.activity.survey = statsInfos.Select(s => s.activity.survey).Sum();
             areaInfo.activity.vote = statsInfos.Select(s => s.activity.vote).Sum();
@@ -141,8 +144,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
             areaInfo.activity.week = statsInfos.Select(s => s.activity.week).Sum();
             areaInfo.activity.lastTerm = statsInfos.Select(s => s.activity.lastTerm).Sum();
             areaInfo.activity.term = statsInfos.Select(s => s.activity.term).Sum();
-            areaInfo.activity.LastYear = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.activity.LastYear).ToList());
-            areaInfo.activity.year = BICommonWay.ManyDoubleMerge(statsInfos.Select(s => s.activity.year).ToList());
+            //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();
 

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

@@ -73,6 +73,8 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
                 else studyStats.ongoing++;
             });
 
+            studyStats.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+
             return studyStats;
         }
     }

+ 31 - 0
TEAMModelOS.SDK/Models/Service/Common/BlobService.cs

@@ -1,7 +1,10 @@
 using Azure;
 using Azure.Cosmos;
+using Azure.Messaging.ServiceBus;
 using Azure.Storage.Blobs;
+using DocumentFormat.OpenXml.Wordprocessing;
 using HTEXLib.COMM.Helpers;
+using Microsoft.Extensions.Configuration;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -16,6 +19,28 @@ namespace TEAMModelOS.SDK.Services
 {
     public static class BlobService
     {
+
+        public static async Task RefreshBlobRoot(BlobRefreshMessage message, AzureServiceBusFactory _serviceBus,IConfiguration _configuration,AzureRedisFactory _azureRedis) {
+            if (!string.IsNullOrWhiteSpace(message.root) && !string.IsNullOrWhiteSpace(message.name)) {
+                string lockKey = $"Blob:Lock:{message.name}:{message.root}";
+                bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
+                //不存在Blob:Lock:hbcn:video 文件夹在队列中 则加入队列
+                if (!exist)
+                {
+                    //保持一天的时间
+                    TimeSpan timeSpan = new TimeSpan(1,0,0);
+                    //加入队列的时间
+                    long action = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, action, expiry: timeSpan);
+                    var messageBlob = new ServiceBusMessage(message.ToJsonString());
+                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                }
+                //如果已经存在,则忽略,不加入队列。
+            }
+        }
+        
         public static async Task<UsedBlob> GetBlobUsed(CosmosClient clientc, BlobContainerClient clients, IDatabase clientr, string scope, string containerName)
         {
             UsedBlob result = new UsedBlob();
@@ -152,4 +177,10 @@ namespace TEAMModelOS.SDK.Services
             public int count { get; set; }
         }
     }
+    public class BlobRefreshMessage{ 
+        public string id { get; set; }= Guid.NewGuid().ToString();
+        public string name { get; set; }
+        public string progress { get; set; }
+        public string root { get; set; }
+    }
 }

+ 2 - 2
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -1180,7 +1180,7 @@ namespace TEAMModelOS.SDK
                         });
                     }
                 }
-                /*
+                
                 if (tmdids.IsNotEmpty() && _coreAPIHttpService.check) {
                     ///获取真实的名称 ,大于50则不处理
                     if (tmdids.Count < 60)
@@ -1227,7 +1227,7 @@ namespace TEAMModelOS.SDK
                     }
                    
                 }
-               */
+               
                 tmdids.ForEach(x =>
                 {
                     var user = tmdsData.Find(y => y.id.Equals(x.id));

+ 4 - 7
TEAMModelOS.SDK/Models/Service/HomeworkService.cs

@@ -8,12 +8,13 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.SDK.Models.Service
 {
     public static class HomeworkService
     {
-        public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Homework work, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration)
+        public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Homework work, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, AzureRedisFactory _azureRedis)
         {
             try
             {
@@ -21,15 +22,11 @@ namespace TEAMModelOS.SDK.Models.Service
                 work.code = "Homework-" + work.school;
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 work.createTime = now;
-                var messageBlob = new ServiceBusMessage();
+                
                 string blobcntr = null;
                 blobcntr = work.school;
                 work.size = await _azureStorage.GetBlobContainerClient(work.school).GetBlobsSize($"homework/{work.id}");
-                messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"homework/{work.id}", name = $"{work.school}" }.ToJsonString());
-
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework", name = $"{blobcntr}" }, _serviceBus, _configuration, _azureRedis);
                 work.recordUrl = $"/homework/{work.id}/record.json";
                 var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
                 await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "homework", $"{work.id}/record.json");

+ 3 - 6
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -16,6 +16,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.SDK.Models.Service
 {
@@ -587,7 +588,7 @@ namespace TEAMModelOS.SDK.Models.Service
                 else
                 {
                     ///未设置openAutoClean=1时,则检查学校使用空间是否充足。
-                    var sbm = new List<ServiceBusMessage>();
+                  
                     double usize = 0;
                     int  tsize = schoolBase.tsize;
                     //schoolBase.tsize
@@ -599,11 +600,7 @@ namespace TEAMModelOS.SDK.Models.Service
                     }
                     else //如果檢測不到緩存,觸發刷新計算空間
                     {
-                        var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{schoolBase.id}" }.ToJsonString()); ;
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        sbm.Add(messageBlob);
-                        await _serviceBus.GetServiceBusClient().SendBatchMessageAsync(_configuration.GetValue<string>("Azure:ServiceBus:ActiveTask"), sbm);
-
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{schoolBase.id}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     ///空间充足的情况保存。
                     if (schoolBase.size - usize > 0)

+ 5 - 14
TEAMModelOS/Controllers/Both/ItemController.cs

@@ -17,12 +17,12 @@ using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 
 using HTEXLib.COMM.Helpers;
-using StackExchange.Redis;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.SDK.Services;
 using System.Text.RegularExpressions;
 using TEAMModelOS.Filter;
 
+
 namespace TEAMModelOS.Controllers
 {
     [ProducesResponseType(StatusCodes.Status200OK)]
@@ -228,10 +228,7 @@ namespace TEAMModelOS.Controllers
                 foreach (var itemInfo in itemInfos) {
                     itemInfo.ttl = -1;
                     itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
                     if (option.ToString().Equals("insert"))
                     {
                         itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
@@ -353,10 +350,8 @@ namespace TEAMModelOS.Controllers
                 ItemInfo itemInfo;
                 itemInfo = item.ToObject<ItemInfo>();
                 itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }.ToJsonString());
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+               
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
                 if (option.ToString().Equals("insert"))
                 {
                     itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
@@ -572,11 +567,7 @@ namespace TEAMModelOS.Controllers
                 var client = _azureCosmos.GetCosmosClient();
                 //删除blob 相关资料
                 await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, code.ToString().Replace("Item-",""),new List<string> { $"item/{id}" });
-                //通知删除信息
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"item/{id}", name = code.ToString().Replace("Item-", "") }.ToJsonString());
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"item", name = code.ToString().Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
                 if (scope.ToString().Equals("school"))
                 {
                     ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>($"{id}", new PartitionKey($"{code}"));

+ 7 - 9
TEAMModelOS/Controllers/Both/PaperController.cs

@@ -19,6 +19,8 @@ using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.Filter;
+using TEAMModelOS.SDK.Services;
+using DocumentFormat.OpenXml.Office2010.Excel;
 
 namespace TEAMModelOS.Controllers
 {
@@ -34,9 +36,10 @@ namespace TEAMModelOS.Controllers
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureServiceBusFactory _serviceBus;
         private readonly DingDing _dingDing;
+        private readonly AzureRedisFactory _azureRedis;
 
         public IConfiguration _configuration { get; set; }
-        public PaperController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId,AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration, DingDing dingDing)
+        public PaperController(AzureRedisFactory azureRedis,AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId,AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration, DingDing dingDing)
         {
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
@@ -44,6 +47,7 @@ namespace TEAMModelOS.Controllers
             _serviceBus = serviceBus;
             _configuration = configuration;
             _dingDing = dingDing;
+            _azureRedis = azureRedis;
         }
         /// <summary>
         /// 删除
@@ -69,10 +73,7 @@ namespace TEAMModelOS.Controllers
             //删除blob 相关资料
             await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, code.ToString().Replace("Paper-",""), new List<string> { $"paper/{id}" });
             //通知删除信息
-            var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"paper/{id}", name = code.ToString().Replace("Paper-", "")}.ToJsonString());
-            messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-            var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-            await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"paper", name = code.ToString().Replace("Paper-", "") }, _serviceBus, _configuration, _azureRedis);
             if (scope.ToString().Equals("school"))
             {
                 paper = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Paper>(id.ToString(), new PartitionKey($"{code}"));
@@ -260,10 +261,7 @@ namespace TEAMModelOS.Controllers
             paper = _paper.ToObject<Paper>();            
             paper.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             paper.size = await _azureStorage.GetBlobContainerClient(paper.code).GetBlobsSize($"paper/{paper.id}");
-            var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"paper/{paper.id}", name = $"{paper.code}" }.ToJsonString());
-            messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-            var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-            await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"paper", name = $"{paper.code}".Replace("Paper-", "") }, _serviceBus, _configuration, _azureRedis);
             paper.code = "Paper-" + paper.code;
             if (option.ToString().Equals("insert"))
             {

+ 2 - 7
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -211,9 +211,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 else //如果檢測不到緩存,觸發刷新計算空間
                 {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{(sp ? request.school : tid)}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    sbm.Add(messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{(sp ? request.school : tid)}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 //取得學校或個人名單
                 (List<RMember> students, _) = await GroupListService.GetMemberByListids(_coreAPIHttpService, db, _dingDing, new List<string>() { request.sid }, request.school);
@@ -348,10 +346,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 else
                 {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{blobName}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{blobName}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 double blobUsed = blobsize / 1073741824.0 + teach; //1073741824  1G
                 if (tbname == null)

+ 2 - 3
TEAMModelOS/Controllers/Client/HiTeachccControlller.cs

@@ -22,6 +22,7 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.Controllers.Client
 {
@@ -181,9 +182,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 else //如果檢測不到緩存,觸發刷新計算空間
                 {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", name = $"{(sp ? request.school : tid)}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    sbm.Add(messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{(sp ? request.school : tid)}" }, _serviceBus, _configuration, _azureRedis);
                 }
 
                 //取得學校或個人名單

+ 1 - 1
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -361,7 +361,7 @@ namespace TEAMModelOS.Controllers
                             homework.tchLists.Add(list.id);
                             //homework.blob = $"/{homework.areaId}/survey/{study.pId}/index.json";
                             //await getMoreWork(pa, homework);
-                            string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework, _serviceBus, _azureStorage, _configuration);
+                            string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework, _serviceBus, _azureStorage, _configuration,_azureRedis);
                             if (string.IsNullOrEmpty(workId))
                             {
                                 return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "作业活动异常" });

+ 9 - 21
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -31,6 +31,7 @@ using DocumentFormat.OpenXml.Wordprocessing;
 using Item = TEAMModelOS.SDK.Models.Cosmos.Common.Item;
 using DocumentFormat.OpenXml.Office2016.Excel;
 using OpenXmlPowerTools;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.Controllers
 {
@@ -184,16 +185,13 @@ namespace TEAMModelOS.Controllers
                     if (request.scope.Equals("school"))
                     {
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.school }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = request.school }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.creatorId }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = request.creatorId }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     int n = 0;
                     List<string> sheetIds = new List<string>();
                     foreach (PaperSimple simple in request.papers)
@@ -220,18 +218,14 @@ namespace TEAMModelOS.Controllers
                         if (request.scope.Equals("school"))
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"exam/{request.id}", name = request.school }.ToJsonString());
-
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"exam", name = request.school }, _serviceBus, _configuration, _azureRedis);
                         }
                         else
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"exam/{request.id}", name = request.creatorId }.ToJsonString());
-
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"exam", name = request.creatorId }, _serviceBus, _configuration, _azureRedis);
                         }
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                        
                         request.progress = info.progress;
                         int n = 0;
                         foreach (PaperSimple simple in request.papers)
@@ -255,16 +249,13 @@ namespace TEAMModelOS.Controllers
                         if (request.scope.Equals("school"))
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.school }.ToJsonString());
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = request.school }, _serviceBus, _configuration, _azureRedis);
                         }
                         else
                         {
                             request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"exam/{request.id}");
-                            messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"exam/{request.id}", name = request.creatorId }.ToJsonString());
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = request.creatorId }, _serviceBus, _configuration, _azureRedis);
                         }
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                         int n = 0;
                         List<string> sheetIds = new List<string>();
                         foreach (PaperSimple simple in request.papers)
@@ -373,10 +364,7 @@ namespace TEAMModelOS.Controllers
                     //删除blob 相关资料
                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, code.ToString(), new List<string> { $"exam/{id}" });
                     //通知评测删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"exam/{id}", name = $"{code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"exam", name = $"{code}" }, _serviceBus, _configuration, _azureRedis);
                     //删除阅卷配置
                     var cresponse = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Correct-{code}"));
                     if (cresponse.Status == 200)

+ 9 - 16
TEAMModelOS/Controllers/Common/HomeworkController.cs

@@ -27,6 +27,8 @@ using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Hosting;
 using Azure.Storage.Blobs.Models;
 using static TEAMModelOS.SDK.SchoolService;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using TEAMModelOS.SDK.Services;
 
 namespace TEAMModelOS.Controllers.Learn
 {
@@ -111,23 +113,19 @@ namespace TEAMModelOS.Controllers.Learn
                         }
                     }                   
                    // homework.progress = "going";
-                    var messageBlob = new ServiceBusMessage();
                     string blobcntr = null;
                     if (homework.scope.Equals("school"))
                     {
                         blobcntr = homework.school;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.school).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"homework/{homework.id}", name = $"{homework.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework", name = $"{homework.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = homework.creatorId;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.creatorId).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"homework/{homework.id}", name = $"{homework.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework", name = $"{homework.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     homework.recordUrl = $"/homework/{homework.id}/record.json";
                     var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
                     await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "homework", $"{homework.id}/record.json");
@@ -137,22 +135,19 @@ namespace TEAMModelOS.Controllers.Learn
                 {
                     string blobcntr = null;
                     var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(homework.id, new PartitionKey($"{homework.code}"));
-                    var messageBlob = new ServiceBusMessage();
                     if (homework.scope.Equals("school"))
                     {
                         blobcntr = homework.school;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.school).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"homework/{homework.id}", name = $"{homework.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"homework", name = $"{homework.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = homework.creatorId;
                         homework.size = await _azureStorage.GetBlobContainerClient(homework.creatorId).GetBlobsSize($"homework/{homework.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"homework/{homework.id}", name = $"{homework.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"homework", name = $"{homework.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    
                     if (response.Status == 200)
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -418,10 +413,8 @@ namespace TEAMModelOS.Controllers.Learn
                     //删除blob 相关资料
                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{__code}".Replace("Homework-", ""), new List<string> { Path.Combine("homework", homeworkd.id) + "/" });
                     //通知删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"homework/{homeworkd.id}", name = $"{__code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                 
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"homework", name = $"{__code}".Replace("Homework-", "") }, _serviceBus, _configuration, _azureRedis);
                     await _dingDing.SendBotMsg($"{_option.Location}-作业活动【{homeworkd.name}-{homeworkd.id}】被删除", GroupNames.醍摩豆服務運維群組);
                     return Ok(new { flag });
                 }

+ 1 - 1
TEAMModelOS/Controllers/Common/StudyController.cs

@@ -123,7 +123,7 @@ namespace TEAMModelOS.Controllers.Common
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},study/save()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},study/save()\n{ex.Message}\n{ex.StackTrace}\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
 

+ 5 - 15
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -109,17 +109,14 @@ namespace TEAMModelOS.Controllers
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"survey/{request.id}", name = $"{request.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"survey", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"survey/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"survey", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     request.recordUrl = $"/survey/{request.id}/record.json";
                     var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
                     await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "survey", $"{request.id}/record.json");
@@ -129,22 +126,18 @@ namespace TEAMModelOS.Controllers
                 {
                     string blobcntr = null;
                     var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
-                    var messageBlob = new ServiceBusMessage();
                     if (request.scope.Equals("school"))
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"survey/{request.id}", name = $"{request.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"survey", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"survey/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"survey/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"survey", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     if (response.Status == 200)
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -435,10 +428,7 @@ namespace TEAMModelOS.Controllers
                     //删除blob 相关资料
                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{code}".Replace("Survey-", ""), new List<string> { Path.Combine("survey", survey.id) + "/" });
                     //通知删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"survey/{survey.id}", name = $"{code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"survey", name = $"{code}".Replace("Survey-", "") }, _serviceBus, _configuration, _azureRedis);
                     await _dingDing.SendBotMsg($"{_option.Location}-问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.醍摩豆服務運維群組);
                     return Ok(new { flag });
                 }

+ 10 - 16
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -16,6 +16,7 @@ using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.SDK.Services;
+using DocumentFormat.OpenXml.Office2013.Excel;
 
 namespace TEAMModelOS.Controllers
 {
@@ -91,22 +92,19 @@ namespace TEAMModelOS.Controllers
                     }
                     
                     string blobcntr = null;
-                    var messageBlob = new ServiceBusMessage();
                     if (request.scope.Equals("school"))
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"vote/{request.id}", name = $"{request.school}" }.ToJsonString());                       
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"vote", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"vote/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"vote", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                   
                     string url = $"/vote/{request.id}/record.json";
                     request.recordUrl = url;
                     await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(new { options = new List<string>(), records = new List<VoteRecord>() }.ToJsonString(), "vote", $"{request.id}/record.json");
@@ -115,23 +113,20 @@ namespace TEAMModelOS.Controllers
                 else
                 {
                     var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
-                    var messageBlob = new ServiceBusMessage();
                     string blobcntr = null;
                     if (request.scope.Equals("school"))
                     {
                         blobcntr = request.school;
                         request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"vote/{request.id}", name = $"{request.school}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"vote", name = $"{request.school}" }, _serviceBus, _configuration, _azureRedis);
                     }
                     else
                     {
                         blobcntr = request.creatorId;
                         request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"vote/{request.id}");
-                        messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"vote/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"vote", name = $"{request.creatorId}" }, _serviceBus, _configuration, _azureRedis);
                     }
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                     
                     if (response.Status == 200)
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -399,10 +394,9 @@ namespace TEAMModelOS.Controllers
                     //删除blob 相关资料
                     await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, $"{code}".Replace("Vote-",""), new List<string> { $"vote/{vote.id}" });
                     //通知删除信息
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"vote/{vote.id}", name = $"{code}" }.ToJsonString());
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "delete", root = $"vote", name = $"{code}".Replace("Vote-", "") }, _serviceBus, _configuration, _azureRedis);
+
 
                     return Ok(new { flag });
                 }

+ 12 - 20
TEAMModelOS/Controllers/System/BlobController.cs

@@ -30,6 +30,9 @@ using System.IO;
 using Azure.Storage.Blobs.Models;
 using Azure.Storage.Sas;
 using ContentTypeDict = TEAMModelOS.SDK.ContentTypeDict;
+using TEAMModelOS.SDK.Services;
+using DocumentFormat.OpenXml.Wordprocessing;
+using OpenXmlPowerTools;
 
 namespace TEAMModelOS.Controllers
 {
@@ -442,10 +445,8 @@ namespace TEAMModelOS.Controllers
                     u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                 }
                 if (!string.IsNullOrEmpty(u)) {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = u, name = $"{_cntr}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = u, name = $"{_cntr}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 return Ok(new { status = true });
             }
@@ -593,10 +594,8 @@ namespace TEAMModelOS.Controllers
                     }
                 }
                 root.ToList().ForEach(async x => {
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = x, name = $"{name}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                   
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = x, name = $"{name}" }, _serviceBus, _configuration, _azureRedis);
                 });
                 return Ok(new { bloblog, status = 200 });
                  
@@ -643,10 +642,8 @@ namespace TEAMModelOS.Controllers
                 {
                     u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                 }
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = u, name = $"{blobContainerName}" }.ToJsonString()); ;
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+               
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = u, name = $"{blobContainerName}" }, _serviceBus, _configuration, _azureRedis);
                 return Ok(new { status });
             }
             else
@@ -702,10 +699,8 @@ namespace TEAMModelOS.Controllers
                 {
                     u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
                 }
-                var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = u, name = $"{blobContainerName}" }.ToJsonString()); ;
-                messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+              
+                await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = u, name = $"{blobContainerName}" }, _serviceBus, _configuration, _azureRedis);
                 return Ok(new { status });
             }
             else
@@ -818,10 +813,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                     root.ToList().ForEach(async x => {
-                        var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = x, name = $"{blobContainerName}" }.ToJsonString()); ;
-                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = x, name = $"{blobContainerName}" }, _serviceBus, _configuration, _azureRedis);
                     });
                     return Ok(new { status });
                 }

+ 1 - 8
TEAMModelOS/Controllers/Teacher/CommentController.cs

@@ -248,14 +248,7 @@ namespace TEAMModelOS.Controllers
                     classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
                 }
                 await Task.WhenAll(tasks);
-                /* //变更blob 大小
-                 ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new Azure.Cosmos.PartitionKey($"Exam-{school}"));
-                 info.size = await _azureStorage.GetBlobContainerClient(school.ToString()).GetBlobsSize($"exam/{id}");
-                 var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "annotation", root = $"exam/{id}", name = school }.ToJsonString());
-
-                 messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                 var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                 await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);*/
+               
                 return Ok(new { classResult });
             }
             catch (Exception e)

+ 1 - 4
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -2312,10 +2312,7 @@ namespace TEAMModelOS.Controllers
                         size = size.HasValue ? size.Value : 0,
                     };
                     await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog);
-                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
-                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
-                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{blobname}" }, _serviceBus, _configuration, _azureRedis);
                 }
                 catch (RequestFailedException ex) when (ex.Status == 404)
                 {