فهرست منبع

编写IES5中的区级统计接口。
编写IES5中的学校统计接口。

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

+ 6 - 219
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -541,7 +541,6 @@ namespace TEAMModelBI.Controllers.Census
                 lastYear.Add(item);
             }
 
-            bool isnew = false;
             DateTimeOffset dateTime = DateTimeOffset.UtcNow;
             long now = dateTime.ToUnixTimeMilliseconds();
             if (!string.IsNullOrEmpty(statsInfo.id))
@@ -668,7 +667,6 @@ namespace TEAMModelBI.Controllers.Census
                     lastYear.Add(item);
                 }
 
-                bool isnew = false;
                 DateTimeOffset dateTime = DateTimeOffset.UtcNow;
                 long now = dateTime.ToUnixTimeMilliseconds();
                 if (!string.IsNullOrEmpty(statsInfo.id))
@@ -769,7 +767,7 @@ namespace TEAMModelBI.Controllers.Census
             }
             catch (Exception ex)
             {
-                //await _dingDing.SendBotMsg($"BI,{_option.Location}  /school/set-scstats   \n    {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"BI,{_option.Location}  /school/set-scstats()   \n    {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
         }
@@ -871,7 +869,7 @@ namespace TEAMModelBI.Controllers.Census
             }
 
             StatsInfo statsInfo = null;
-            statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds, area);
+            statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _option, statsInfos, scIds, area);
             if (statsInfo != null)
             {
                 areaScStats.id = statsInfo.id;
@@ -963,7 +961,7 @@ namespace TEAMModelBI.Controllers.Census
             Area area = null;
             AreaStats areaScStats = new();
             List<string> scIds = new();
-            List<SchoolInfo> schoolInfos = new();
+            List<BISchoolInfo> schoolInfos = new();
             List<ScStats> scStatss = new();
             List<StatsInfo> statsInfos = new();
             long useSize = 0;
@@ -971,7 +969,7 @@ namespace TEAMModelBI.Controllers.Census
             var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
             var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month");  //本月开始/结束时间
 
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolInfo>(queryText: $"select c.id,c.name,c.picture,c.areaId,c.areaName,c.size,c.scale,c.assists,c.sales,c.createDate,c.serial,c.service,c.hard from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BISchoolInfo>(queryText: $"select c.id,c.name,c.picture,c.areaId,c.areaName,c.size,c.scale,c.assists,c.sales,c.createDate,c.serial,c.service,c.hard from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
             {
                 schoolInfos.Add(item);
             }
@@ -1000,7 +998,7 @@ namespace TEAMModelBI.Controllers.Census
             }
 
             StatsInfo statsInfo = null;
-            statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds, area);
+            statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _option, statsInfos, scIds, area);
             if (statsInfo != null)
             {
                 //areaScStats = new
@@ -1236,7 +1234,7 @@ namespace TEAMModelBI.Controllers.Census
             List<AreaInfoStats> areaGroup = statsInfos.GroupBy(p => p.areaId).Select(s => new AreaInfoStats() { areaId = s.Key, name = easyInfos.Where(f => f.id.Equals(s.Key)).Select(sn=>sn.name).FirstOrDefault(), lessAct = (s.Select(sl => sl.lesson.all).Sum() + s.Select(sa => sa.activity.all).Sum()), lessCnt = s.Select(sl => sl.lesson.all).Sum(), actCnt = s.Select(sa => sa.activity.all).Sum() }).ToList();
 
             StatsInfo statsInfo = null;
-            statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos);
+            statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _option, statsInfos);
             if (statsInfo != null)
             {
                 allScStats.areaCnt = easyInfos.Count;
@@ -1385,216 +1383,5 @@ namespace TEAMModelBI.Controllers.Census
             public long dataCount { get; set; }
         }
 
-        /// <summary>
-        /// 学校列表信息
-        /// </summary>
-        public record SchoolInfo
-        {
-            public string id { get; set; }
-            public string name { get; set; }
-            public string picture { get; set; }
-            public string areaId { get; set; }
-            public string areaName { get; set; }
-            public int size { get; set; }
-            public int scale { get; set; }
-            public long createDate { get; set; }
-            public List<IdInfo> assists { get; set; } = new List<IdInfo>();
-            public List<IdInfo> sales { get; set; } = new List<IdInfo>();
-            public List<string> serial { get; set; } = new List<string>();
-            public List<string> service { get; set; } = new List<string>();
-            public List<string> hard { get; set; } = new List<string>();
-            public int less { get; set; }
-
-            public int lastWeekLess { get; set; }
-            public int monthLess { get; set; }
-        }
-
-        /// <summary>
-        /// 区级信息
-        /// </summary>
-        public record AreaStats
-        {
-            public string id { get; set; }
-            public string name { get; set; }
-            public int weekSc { get; set; }
-            public int monthSc { get; set; }
-            public int tch { get; set; }
-            public int dayTch { get; set; }
-            public int weekTch { get; set; }
-            public int monthTch { get; set; }
-            public int room { get; set; }
-            public int witRoom { get; set; }
-            public int resourceCnt { get; set; }
-            public int size { get; set; }
-            public long useSize { get; set; }
-            public int stu { get; set; }
-            public int dayStu { get; set; }
-            public int weekStu { get; set; }
-            public int monthStu { get; set; }
-            public ManyLessStats lessStats { get; set; } = new ManyLessStats();
-            public ManyScActStats actStats { get; set; } = new ManyScActStats();
-            public ScSRStats srStats { get; set; } = new ScSRStats();
-        }
-
-        /// <summary>
-        /// 前端显示学校统计数据
-        /// </summary>
-        public record ScStats
-        {
-            public string id { get; set; }
-            public string schoolId { get; set; }
-            public string name { get; set; }
-            public string picture { get; set; }
-            public string areaId { get; set; }
-            public int tch { get; set; }
-            public int dayTch { get; set; }
-            public int weekTch { get; set; }
-            public int monthTch { get; set; }
-            public int stu { get; set; }
-            public int dayStu { get; set; }
-            public int weekStu { get; set; }
-            public int monthStu { get; set; }
-            public int room { get; set; }
-            public int witRoom { get; set; }
-            public int resourceCnt { get; set; }
-            public int size { get; set; }
-            public long scCreateTime { get; set; }
-            public long upTime { get; set; }
-            public ManyLessStats lessStats { get; set; } = new ManyLessStats();
-            public ManyScActStats actStats { get; set; } = new ManyScActStats();
-
-            public ScSRStats srStats { get; set; } = new ScSRStats();
-        }
-
-        /// <summary>
-        /// 所有
-        /// </summary>
-        public record AllScStats
-        {
-            public int areaCnt { get; set; }
-            public int sc { get; set; }
-            public int weekSc { get; set; }
-            public int monthSc { get; set; }
-            public int tch { get; set; }
-            public int dayTch { get; set; }
-            public int weekTch { get; set; }
-            public int monthTch { get; set; }
-            public int stu { get; set; }
-            public int dayStu { get; set; }
-            public int weekStu { get; set; }
-            public int monthStu { get; set; }
-            public int room { get; set; }
-            public int witRoom { get; set; }
-            public int resourceCnt { get; set; }
-            public int size { get; set; }
-            public long scCreateTime { get; set; }
-            public long upTime { get; set; }
-            public ScLessStats lessStats { get; set; } = new ScLessStats();
-            public ScActStats actStats { get; set; } = new ScActStats();
-
-            public ScSRStats srStats { get; set; } = new ScSRStats();
-
-        }
-
-        public record AreaInfoStats
-        {
-            public string areaId { get; set; }
-            public string name { get; set; }
-            public int lessAct { get; set; }
-            public int lessCnt { get; set; }
-            public int actCnt { get; set; }
-        }
-
-        /// <summary>
-        /// 课例活动数据
-        /// </summary>
-        public record ScLessStats
-        {
-            public int all { get; set; }
-            public int open { get; set; }
-            public int less { get; set; }
-            public int lastDay { get; set; }
-            public int day { get; set; }
-            public int lastWeek { get; set; }
-            public int week { get; set; }
-            public int lastTerm { get; set; }
-            public int term { get; set; }
-            public int month { get; set; }
-            public int lastMonth { get; set; }
-            public int lastDayInter { get; set; }
-            public int dayInter { get; set; }
-            public int lastMonthInter { get; set; }
-            public int monthInter { get; set; }
-            public int lastYearInter { get; set; }
-            public int yearInter { get; set; }
-        }
-
-        /// <summary>
-        /// 课例活动数据
-        /// </summary>
-        public record ManyLessStats : ScLessStats
-        {
-            public int lastYear { get; set; }
-            public List<YearMonth> yearInters { get; set; } = new List<YearMonth>();//12个月
-            public List<YearMonth> year { get; set; } = new List<YearMonth>();    //12个月
-        }
-
-        public record ScActStats
-        {
-            public int all { get; set; }
-            public int exam { get; set; }
-            public int survey { get; set; }
-            public int vote { get; set; }
-            public int homework { get; set; }
-            public int lastDay { get; set; }
-            public int dayCnt { get; set; }
-            public int lastWeek { get; set; }
-            public int week { get; set; }
-            public int lastTerm { get; set; }
-            public int term { get; set; }
-            public int lastMonth { get; set; }
-            public int month { get; set; }
-
-        }
-
-        /// <summary>
-        /// 学校活动数据
-        /// </summary>
-        public record ManyScActStats : ScActStats
-        {
-            public int lastYear { get; set; }
-            public List<YearMonth> year { get; set; } = new List<YearMonth>();    //12个月
-        }
-
-        /// <summary>
-        /// 研修统计数据
-        /// </summary>
-        public record ScSRStats
-        {
-            public int learnTime { get; set; }
-            public int online { get; set; }
-            public int offline { get; set; }
-            public int classRoom { get; set; }
-            public int submit { get; set; }
-            public int notStarted { get; set; }
-            public int ongoing { get; set; }
-            public int finish { get; set; }
-        }
-
-        /// <summary>
-        /// 查询去年的统计
-        /// </summary>
-        public record LastYearLessAndAct
-        {
-            /// <summary>
-            /// 课例活动
-            /// </summary>
-            public LessonStats lesson { get; set; } = new LessonStats();
-
-            /// <summary>
-            /// 活动
-            /// </summary>
-            public ActivityStats activity { get; set; } = new ActivityStats();
-        }
     }
 }

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

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 
 namespace TEAMModelOS.SDK.Models.Cosmos.BI
 {
@@ -100,4 +101,217 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         public Currency currency { get; set; } = new Currency();
     }
+
+    /// <summary>
+    /// 学校列表信息
+    /// </summary>
+    public record BISchoolInfo
+    {
+        public string id { get; set; }
+        public string name { get; set; }
+        public string picture { get; set; }
+        public string areaId { get; set; }
+        public string areaName { get; set; }
+        public int size { get; set; }
+        public int scale { get; set; }
+        public Edition edition { get; set; }
+        public long createDate { get; set; }
+        public List<IdInfo> assists { get; set; } = new List<IdInfo>();
+        public List<IdInfo> sales { get; set; } = new List<IdInfo>();
+        public List<string> serial { get; set; } = new List<string>();
+        public List<string> service { get; set; } = new List<string>();
+        public List<string> hard { get; set; } = new List<string>();
+        public int less { get; set; }
+
+        public int lastWeekLess { get; set; }
+        public int monthLess { get; set; }
+    }
+
+    /// <summary>
+    /// 区级信息
+    /// </summary>
+    public record AreaStats
+    {
+        public string id { get; set; }
+        public string name { get; set; }
+        public int weekSc { get; set; }
+        public int monthSc { get; set; }
+        public int tch { get; set; }
+        public int dayTch { get; set; }
+        public int weekTch { get; set; }
+        public int monthTch { get; set; }
+        public int room { get; set; }
+        public int witRoom { get; set; }
+        public int resourceCnt { get; set; }
+        public int size { get; set; }
+        public long useSize { get; set; }
+        public int stu { get; set; }
+        public int dayStu { get; set; }
+        public int weekStu { get; set; }
+        public int monthStu { get; set; }
+        public ManyLessStats lessStats { get; set; } = new ManyLessStats();
+        public ManyScActStats actStats { get; set; } = new ManyScActStats();
+        public ScSRStats srStats { get; set; } = new ScSRStats();
+    }
+
+    /// <summary>
+    /// 前端显示学校统计数据
+    /// </summary>
+    public record ScStats
+    {
+        public string id { get; set; }
+        public string schoolId { get; set; }
+        public string name { get; set; }
+        public string picture { get; set; }
+        public string areaId { get; set; }
+        public int tch { get; set; }
+        public int dayTch { get; set; }
+        public int weekTch { get; set; }
+        public int monthTch { get; set; }
+        public int stu { get; set; }
+        public int dayStu { get; set; }
+        public int weekStu { get; set; }
+        public int monthStu { get; set; }
+        public int room { get; set; }
+        public int witRoom { get; set; }
+        public int resourceCnt { get; set; }
+        public int size { get; set; }
+        public long scCreateTime { get; set; }
+        public long upTime { get; set; }
+        public ManyLessStats lessStats { get; set; } = new ManyLessStats();
+        public ManyScActStats actStats { get; set; } = new ManyScActStats();
+
+        public ScSRStats srStats { get; set; } = new ScSRStats();
+    }
+
+    /// <summary>
+    /// 所有
+    /// </summary>
+    public record AllScStats
+    {
+        public int areaCnt { get; set; }
+        public int sc { get; set; }
+        public int weekSc { get; set; }
+        public int monthSc { get; set; }
+        public int tch { get; set; }
+        public int dayTch { get; set; }
+        public int weekTch { get; set; }
+        public int monthTch { get; set; }
+        public int stu { get; set; }
+        public int dayStu { get; set; }
+        public int weekStu { get; set; }
+        public int monthStu { get; set; }
+        public int room { get; set; }
+        public int witRoom { get; set; }
+        public int resourceCnt { get; set; }
+        public int size { get; set; }
+        public long scCreateTime { get; set; }
+        public long upTime { get; set; }
+        public ScLessStats lessStats { get; set; } = new ScLessStats();
+        public ScActStats actStats { get; set; } = new ScActStats();
+
+        public ScSRStats srStats { get; set; } = new ScSRStats();
+
+    }
+
+    public record AreaInfoStats
+    {
+        public string areaId { get; set; }
+        public string name { get; set; }
+        public int lessAct { get; set; }
+        public int lessCnt { get; set; }
+        public int actCnt { get; set; }
+    }
+
+    /// <summary>
+    /// 课例活动数据
+    /// </summary>
+    public record ScLessStats
+    {
+        public int all { get; set; }
+        public int open { get; set; }
+        public int less { get; set; }
+        public int lastDay { get; set; }
+        public int day { get; set; }
+        public int lastWeek { get; set; }
+        public int week { get; set; }
+        public int lastTerm { get; set; }
+        public int term { get; set; }
+        public int month { get; set; }
+        public int lastMonth { get; set; }
+        public int lastDayInter { get; set; }
+        public int dayInter { get; set; }
+        public int lastMonthInter { get; set; }
+        public int monthInter { get; set; }
+        public int lastYearInter { get; set; }
+        public int yearInter { get; set; }
+    }
+
+    /// <summary>
+    /// 课例活动数据
+    /// </summary>
+    public record ManyLessStats : ScLessStats
+    {
+        public int lastYear { get; set; }
+        public List<YearMonth> yearInters { get; set; } = new List<YearMonth>();//12个月
+        public List<YearMonth> year { get; set; } = new List<YearMonth>();    //12个月
+    }
+
+    public record ScActStats
+    {
+        public int all { get; set; }
+        public int exam { get; set; }
+        public int survey { get; set; }
+        public int vote { get; set; }
+        public int homework { get; set; }
+        public int lastDay { get; set; }
+        public int dayCnt { get; set; }
+        public int lastWeek { get; set; }
+        public int week { get; set; }
+        public int lastTerm { get; set; }
+        public int term { get; set; }
+        public int lastMonth { get; set; }
+        public int month { get; set; }
+
+    }
+
+    /// <summary>
+    /// 学校活动数据
+    /// </summary>
+    public record ManyScActStats : ScActStats
+    {
+        public int lastYear { get; set; }
+        public List<YearMonth> year { get; set; } = new List<YearMonth>();    //12个月
+    }
+
+    /// <summary>
+    /// 研修统计数据
+    /// </summary>
+    public record ScSRStats
+    {
+        public int learnTime { get; set; }
+        public int online { get; set; }
+        public int offline { get; set; }
+        public int classRoom { get; set; }
+        public int submit { get; set; }
+        public int notStarted { get; set; }
+        public int ongoing { get; set; }
+        public int finish { get; set; }
+    }
+
+    /// <summary>
+    /// 查询去年的统计
+    /// </summary>
+    public record LastYearLessAndAct
+    {
+        /// <summary>
+        /// 课例活动
+        /// </summary>
+        public LessonStats lesson { get; set; } = new LessonStats();
+
+        /// <summary>
+        /// 活动
+        /// </summary>
+        public ActivityStats activity { get; set; } = new ActivityStats();
+    }
 }

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

@@ -128,7 +128,7 @@ namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
         /// <param name="_option"></param>
         /// <param name="area"></param>
         /// <returns></returns>
-        public static StatsInfo GetAreaStats(CosmosClient cosmosClient, HttpTrigger _httpTrigger, Option _option, List<StatsInfo> statsInfos, List<string> scIds = null, Area area = null)
+        public static StatsInfo GetAreaStats(CosmosClient cosmosClient, Option _option, List<StatsInfo> statsInfos, List<string> scIds = null, Area area = null)
         {
             StatsInfo areaInfo = new()
             {

+ 321 - 2
TEAMModelOS/Controllers/Normal/AreaController.cs

@@ -3,15 +3,23 @@ using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
+using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
+using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
+using TEAMModelOS.SDK.Models.Service.BI;
+using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 
 namespace TEAMModelOS.Controllers.Research
 {
@@ -23,15 +31,17 @@ namespace TEAMModelOS.Controllers.Research
     public class AreaController : ControllerBase
     {
         private readonly AzureCosmosFactory _azureCosmos;
+        private readonly AzureRedisFactory _azureRedis;
         private readonly SnowflakeId _snowflakeId;
         private readonly DingDing _dingDing;
         private readonly Option _option;
-        public AreaController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
+        public AreaController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
         {
             _azureCosmos = azureCosmos;
+            _azureRedis = azureRedis;
             _snowflakeId = snowflakeId;
             _dingDing = dingDing;
-            _option = option?.Value; ;
+            _option = option?.Value;
         } /*
          {"areaId":"册别id:0baf00db-0768-4b62-a8f7-280f6bcebf71","scope":"school","abilityCode":"册别分区键"}
         */
@@ -56,5 +66,314 @@ namespace TEAMModelOS.Controllers.Research
             }
             return Ok(new { areas });
         }
+
+        /// <summary>
+        /// 区级统计接口
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-areastats")]
+#if !DEBUG
+        [Authorize(Roles = "IES")]
+#endif
+        [AuthToken(Roles = "area")]
+        public async Task<IActionResult> GetAreaStats(JsonElement jsonElement) 
+        {
+            try
+            {
+                if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var redisClinet = _azureRedis.GetRedisClient(8);
+                DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+                Area area = null;
+                AreaStats areaScStats = new();
+                List<string> scIds = new();
+                List<BISchoolInfo> schoolInfos = new();
+                List<ScStats> scStatss = new();
+                List<StatsInfo> statsInfos = new();
+                long useSize = 0;
+                Dictionary<string, double?> typeStics = new(); //所有类型
+                var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week");             //计算本周开始/结束时间
+                var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month");  //本月开始/结束时间
+
+
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BISchoolInfo>(queryText: $"select c.id,c.name,c.picture,c.areaId,c.areaName,c.size,c.scale,c.assists,c.sales,c.createDate,c.serial,c.service,c.hard from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
+                {
+                    schoolInfos.Add(item);
+                }
+                if (schoolInfos.Count > 0)
+                    scIds = schoolInfos.Select(s => s.id).ToList();
+                StringBuilder statsSql = new($"select value(c) from c where c.year={dateTime.Year}");
+                if (scIds.Count > 0)
+                    statsSql.Append($" and {BICommonWay.ManyScSql("c.id", scIds, $"{dateTime.Year}-")}");
+
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<StatsInfo>(queryText: statsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
+                {
+                    statsInfos.Add(item);
+                }
+
+                StringBuilder lastStsSql = new($"select c.lesson,c.activity from c where c.year={dateTime.Year - 1}");
+                if (scIds.Count > 0)
+                {
+                    lastStsSql.Append($" and {BICommonWay.ManyScSql("c.id", scIds, $"{dateTime.Year - 1}-")}");
+                }
+
+                List<LastYearLessAndAct> lastYear = new();
+
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<LastYearLessAndAct>(queryText: lastStsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
+                {
+                    lastYear.Add(item);
+                }
+
+                StatsInfo statsInfo = null;
+                statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _option, statsInfos, scIds, area);
+                if (statsInfo != null)
+                {
+                    areaScStats.id = statsInfo.id;
+                    areaScStats.name = statsInfo.name;
+                    areaScStats.weekSc = schoolInfos.Where(w => w.createDate >= weekS && w.createDate <= weekE).Count();
+                    areaScStats.monthSc = schoolInfos.Where(w => w.createDate >= mthS && w.createDate <= mthE).Count();
+                    areaScStats.tch = statsInfo.tch;
+                    areaScStats.dayTch = statsInfo.dayTch;
+                    areaScStats.weekTch = statsInfo.weekTch;
+                    areaScStats.monthTch = statsInfo.monthTch;
+                    areaScStats.stu = statsInfo.stu;
+                    areaScStats.dayStu = statsInfo.dayStu;
+                    areaScStats.weekStu = statsInfo.weekStu;
+                    areaScStats.monthStu = statsInfo.monthStu;
+                    areaScStats.room = statsInfo.room;
+                    areaScStats.witRoom = statsInfo.witRoom;
+                    areaScStats.resourceCnt = statsInfo.resourceCnt;
+                    areaScStats.size = statsInfo.size;
+                    //areaScStats.useSize = statsInfo.useSize;
+                    areaScStats.lessStats.open = statsInfo.lesson.all;
+                    areaScStats.lessStats.open = statsInfo.lesson.open;
+                    areaScStats.lessStats.less = statsInfo.lesson.less;
+                    areaScStats.lessStats.lastDay = statsInfo.lesson.lastDay;
+                    areaScStats.lessStats.day = statsInfo.lesson.day;
+                    areaScStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
+                    areaScStats.lessStats.week = statsInfo.lesson.week;
+                    areaScStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
+                    areaScStats.lessStats.term = statsInfo.lesson.term;
+                    areaScStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
+                    areaScStats.lessStats.dayInter = statsInfo.lesson.dayInter;
+                    areaScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
+                    areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
+                    areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
+                    areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
+                    areaScStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
+                    areaScStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
+                    areaScStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
+                    areaScStats.actStats.all = statsInfo.activity.all;
+                    areaScStats.actStats.exam = statsInfo.activity.exam;
+                    areaScStats.actStats.survey = statsInfo.activity.survey;
+                    areaScStats.actStats.vote = statsInfo.activity.vote;
+                    areaScStats.actStats.homework = statsInfo.activity.homework;
+                    areaScStats.actStats.lastDay = statsInfo.activity.lastDay;
+                    areaScStats.actStats.dayCnt = statsInfo.activity.dayCnt;
+                    areaScStats.actStats.lastWeek = statsInfo.activity.lastWeek;
+                    areaScStats.actStats.week = statsInfo.activity.week;
+                    areaScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
+                    areaScStats.actStats.term = statsInfo.activity.term;
+                    areaScStats.actStats.lastMonth = statsInfo.activity.lastMonth;
+                    areaScStats.actStats.month = statsInfo.activity.month;
+                    areaScStats.actStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum());
+                    areaScStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
+                    if (statsInfo.study != null)
+                    {
+                        areaScStats.srStats.learnTime = statsInfo.study.learnTime;
+                        areaScStats.srStats.online = statsInfo.study.online;
+                        areaScStats.srStats.offline = statsInfo.study.offline;
+                        areaScStats.srStats.classRoom = statsInfo.study.classRoom;
+                        areaScStats.srStats.submit = statsInfo.study.submit;
+                        areaScStats.srStats.notStarted = statsInfo.study.notStarted;
+                        areaScStats.srStats.ongoing = statsInfo.study.ongoing;
+                        areaScStats.srStats.finish = statsInfo.study.finish;
+                    }
+                }
+
+                List<double> weekLess = BICommonWay.weekDoubleMerge(statsInfos.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList(), dateTime);
+                schoolInfos.ForEach(fe =>
+                {
+                    var tempSts = statsInfos.Find(f => f.schoolId.Equals(fe.id));
+                    if (tempSts != null)
+                    {
+                        fe.less = tempSts.lesson.all;
+                        fe.lastWeekLess = tempSts.lesson.lastWeek;
+                        fe.monthLess = tempSts.lesson.month;
+                    }
+                });
+
+                List<IdInfo> assits = new();
+                schoolInfos.ForEach(fe => assits.AddRange(fe.assists));
+                List<IdInfo> saless = new();
+                schoolInfos.ForEach(fe => saless.AddRange(fe.sales));
+                foreach (var itemId in scIds)
+                {
+                    RedisValue value = redisClinet.HashGet($"Blob:Record", itemId);
+                    if (value != default && !value.IsNullOrEmpty)
+                    {
+                        JsonElement record = value.ToString().ToObject<JsonElement>();
+                        if (record.TryGetInt64(out long blobsize))
+                        {
+                            useSize += blobsize;
+                        }
+                    }
+
+                    SortedSetEntry[] Scores = redisClinet.SortedSetRangeByScoreWithScores($"Blob:Catalog:{itemId}");
+                    if (Scores.Length > 0)
+                    {
+                        Dictionary<string, double?> schoolStics = new(); //学校空间
+                        foreach (var score in Scores)
+                        {
+                            double val = score.Score;
+                            string key = score.Element.ToString();
+                            schoolStics.Add(key, val);
+                        }
+                        typeStics = typeStics.Concat(schoolStics).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value));  //lamebda表达式
+                    }
+                }
+
+                return Ok(new { state = RespondCode.Ok, areaScStats, schoolInfos, weekLess, assists = assits.Where((w, i) => assits.FindIndex(s => s.id.Equals(w.id)) == i).ToList(), saless = saless.Where((w, i) => saless.FindIndex(f => f.id.Equals(w.id)) == i).ToList(), useSize, typeStics = typeStics.ToList() });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},Area/GetAreaStats()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return BadRequest(new { ex.Message, ex.StackTrace });
+            }
+        }
+
+        /// <summary>
+        /// 学校统计接口
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-schoolstats")]
+#if !DEBUG
+        [Authorize(Roles = "IES")]
+#endif
+        [AuthToken(Roles = "area")]
+        public async Task<IActionResult> GetSchoolStats(JsonElement jsonElement) 
+        {
+            try
+            {
+                if (!jsonElement.TryGetProperty("schoolId", out JsonElement scId)) return BadRequest();
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+
+                School school = new();
+                ScStats scStats = new();
+
+                var respSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"Base"));
+                if (respSc.Status == 200)
+                {
+                    using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
+                    school = fileJson.ToObject<School>();
+                }
+                else
+                    return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{scId};相关的学校,请检查" });
+
+                bool isExist = true;
+                StatsInfo statsInfo = new();
+                var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{DateTimeOffset.UtcNow.Year}-{scId}", new PartitionKey("Statistics"));
+                if (scDataStats.Status == 200)
+                {
+                    using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
+                    statsInfo = fileJson.ToObject<StatsInfo>();
+                }
+                else
+                {
+                    scStats.id = school.id;
+                    isExist = false;
+                }
+
+                List<LastYearLessAndAct> lastYear = new();
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<LastYearLessAndAct>(queryText: $"select c.lesson,c.activity from c where c.id='{DateTimeOffset.UtcNow.Year - 1}-{scId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
+                {
+                    lastYear.Add(item);
+                }
+
+                DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+                long now = dateTime.ToUnixTimeMilliseconds();
+                if (!string.IsNullOrEmpty(statsInfo.id))
+                {
+                    scStats.id = statsInfo.id;
+                    scStats.schoolId = statsInfo.schoolId;
+                    scStats.name = statsInfo.name;
+                    scStats.picture = statsInfo.picture;
+                    scStats.areaId = statsInfo.areaId;
+                    scStats.tch = statsInfo.tch;
+                    scStats.dayTch = statsInfo.dayTch;
+                    scStats.weekTch = statsInfo.weekTch;
+                    scStats.monthTch = statsInfo.monthTch;
+                    scStats.stu = statsInfo.stu;
+                    scStats.dayStu = statsInfo.dayStu;
+                    scStats.weekStu = statsInfo.weekStu;
+                    scStats.monthStu = statsInfo.monthStu;
+                    scStats.room = statsInfo.room;
+                    scStats.witRoom = statsInfo.witRoom;
+                    scStats.resourceCnt = statsInfo.resourceCnt;
+                    scStats.size = statsInfo.size;
+                    scStats.scCreateTime = statsInfo.scCreateTime;
+                    scStats.upTime = statsInfo.upTime;
+                    scStats.lessStats.all = statsInfo.lesson.all;
+                    scStats.lessStats.open = statsInfo.lesson.open;
+                    scStats.lessStats.less = statsInfo.lesson.less;
+                    scStats.lessStats.lastDay = statsInfo.lesson.lastDay;
+                    scStats.lessStats.day = statsInfo.lesson.day;
+                    scStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
+                    scStats.lessStats.week = statsInfo.lesson.week;
+                    scStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
+                    scStats.lessStats.term = statsInfo.lesson.term;
+                    scStats.lessStats.month = statsInfo.lesson.month;
+                    scStats.lessStats.lastMonth = statsInfo.lesson.lastMonth;
+                    scStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
+                    scStats.lessStats.dayInter = statsInfo.lesson.dayInter;
+                    scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
+                    scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
+                    scStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
+                    scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
+                    scStats.lessStats.yearInter = statsInfo.lesson.yearInter;
+                    scStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
+                    scStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
+                    scStats.actStats.all = statsInfo.activity.all;
+                    scStats.actStats.exam = statsInfo.activity.exam;
+                    scStats.actStats.survey = statsInfo.activity.survey;
+                    scStats.actStats.vote = statsInfo.activity.vote;
+                    scStats.actStats.homework = statsInfo.activity.homework;
+                    scStats.actStats.lastDay = statsInfo.activity.lastDay;
+                    scStats.actStats.dayCnt = statsInfo.activity.dayCnt;
+                    scStats.actStats.lastWeek = statsInfo.activity.lastWeek;
+                    scStats.actStats.week = statsInfo.activity.week;
+                    scStats.actStats.lastTerm = statsInfo.activity.lastTerm;
+                    scStats.actStats.term = statsInfo.activity.term;
+                    scStats.actStats.lastMonth = statsInfo.activity.lastMonth;
+                    scStats.actStats.month = statsInfo.activity.month;
+                    scStats.actStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum());
+
+                    scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
+                    if (statsInfo.study != null)
+                    {
+                        scStats.srStats.learnTime = statsInfo.study.learnTime;
+                        scStats.srStats.online = statsInfo.study.online;
+                        scStats.srStats.offline = statsInfo.study.offline;
+                        scStats.srStats.classRoom = statsInfo.study.classRoom;
+                        scStats.srStats.submit = statsInfo.study.submit;
+                        scStats.srStats.notStarted = statsInfo.study.notStarted;
+                        scStats.srStats.ongoing = statsInfo.study.ongoing;
+                        scStats.srStats.finish = statsInfo.study.finish;
+                    }
+                }
+
+                return Ok(new { state = RespondCode.Ok, scStats, school.edition });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},Area/GetSchoolStats()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return BadRequest(new { ex.Message, ex.StackTrace });
+            }
+
+        }
     }
 }