Browse Source

添加学校统计和学校课例趋势接口

Li 3 years ago
parent
commit
789f58ee3c

+ 105 - 1
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -22,6 +22,9 @@ using TEAMModelBI.Tool.Extension;
 using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.DI.BIAzureStorage;
+using Azure.Storage.Blobs.Models;
+using Azure;
+using Azure.Storage.Blobs.Specialized;
 
 namespace TEAMModelBI.Controllers.BISchool
 {
@@ -747,7 +750,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 batchCopyFile.codeKey = partitionCode;
                 batchCopyFile.tmdName = $"{_tmdName}";
                 var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
-                messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");   //Function暂时还未写
+                messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");  
                 try
                 {
                     //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制  单一
@@ -788,6 +791,107 @@ namespace TEAMModelBI.Controllers.BISchool
             }
         }
 
+        /// <summary>
+        /// 删除区域和区域的册别、能力点、区域文件、区域设置
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("del-area")]
+        public async Task<IActionResult> DelArea(JsonElement jsonElement) 
+        {
+            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos");
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos", BIConst.GlobalSite);
+            }
+
+            var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync("areaId", new PartitionKey("Base-Area"));
+            if (response.Status == 200)
+            {
+                using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                Area area = json.ToObject<Area>();
+                if (area.standard == $"{standard}") 
+                {
+                    //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<Area>(area.id, new PartitionKey("Base-Area")); //删除区
+
+                    List<string> abilityIds = new();  //册别的ID集合
+                    List<string> abilityTaskIds = new();  //章节ID集合
+
+                    //查询册别信息
+                    await foreach (var tempAbility in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
+                    {
+                        abilityIds.Add(tempAbility.id);  //查询出来册别ID添加册别ID集合
+                    }
+                    //删除册别
+                    if (abilityIds.IsNotEmpty())
+                    {
+                        //var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
+                    }
+
+                    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
+                    {
+                        abilityTaskIds.Add(item.id);   //查询出来的章节信息ID添加到战绩集合
+                    }
+                    //删除章节
+                    if (abilityTaskIds.IsNotEmpty())
+                    {
+                        //var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{_oldStandard}");
+                    }
+                    //区域政策文件
+                    StandardFile delFile = new();
+                    var responseFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("StandardFile"));
+                    if(responseFile.Status == 200)
+                    {
+                        using var fileJson = await JsonDocument.ParseAsync(responseFile.ContentStream);
+                        delFile = fileJson.ToObject<StandardFile>();
+                        //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(delFile.id, new PartitionKey("StandardFile"));
+                    }
+
+                    //区域设置
+                    AreaSetting delSet = new();
+                    var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("StandardFile"));
+                    if (responseFile.Status == 200)
+                    {
+                        using var fileJson = await JsonDocument.ParseAsync(responseFile.ContentStream);
+                        delSet = fileJson.ToObject<AreaSetting>();
+                        //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(delSet.id, new PartitionKey("AreaSetting"));
+                    }
+
+                    List<object> fileobj = new();
+                    //先删除原有的文件
+                    List<Task<Response<bool>>> DelList = new List<Task<Response<bool>>>();
+                    await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"yxpt/{area.standard}/"))
+                    {
+                        fileobj.Add(blobItem);
+                        //DelList.Add(blobClient.GetBlobBaseClient(blobItem.Name).DeleteIfExistsAsync());
+                    }
+
+                    //if (DelList.Count <= 256)
+                    //{
+                    //    await Task.WhenAll(DelList);
+                    //}
+                    //else
+                    //{
+                    //    int pages = (DelList.Count + 255) / 256;
+                    //    for (int i = 0; i < pages; i++)
+                    //    {
+                    //        List<Task<Response<bool>>> delList = DelList.Skip((i) * 256).Take(256).ToList();
+                    //        await Task.WhenAll(delList);
+                    //    }
+                    //}
+
+                    return Ok(new { state = 200,area, abilityIds, abilityTaskIds, });
+                }
+                else return Ok(new { state = 400, msg = "id和standard不匹配!" });
+            }
+            else return Ok(new { state = 404,msg="依据Id未找到该区!" });
+        }
+
         /// <summary>
         /// 区域列表
         /// </summary>

+ 252 - 11
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -1,5 +1,6 @@
 using Azure.Cosmos;
 using HTEXLib.COMM.Helpers;
+using MathNet.Numerics.LinearAlgebra.Double;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Configuration;
@@ -14,6 +15,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
+using TEAMModelBI.Models;
 using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.CosmosBank;
@@ -24,6 +26,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Service;
 
 namespace TEAMModelBI.Controllers.BISchool
@@ -144,7 +147,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 //if (!string.IsNullOrEmpty($"{areaId}"))                    
                 //    notAreaSchools = notAreaSchools.Select(na => new NotAreaSchool { id = na.id, name = na.name, schoolCode = na.schoolCode, picture = na.picture, period = na.period, province = na.province, city = na.city = na.city, dist = na.dist,  manyAreas =  new List<ManyArea> { na.manyAreas.Find(m => m.areaId != $"{areaId}") } }).ToList();
 
-                return Ok(new { state = 200, continuationToken,cont= notAreaSchools.Count, notAreaSchools });
+                return Ok(new { state = 200, continuationToken, cont = notAreaSchools.Count, notAreaSchools });
             }
             catch (Exception ex)
             {
@@ -214,7 +217,7 @@ namespace TEAMModelBI.Controllers.BISchool
 
                             }
 
-                            if (school.manyAreas == null) 
+                            if (school.manyAreas == null)
                             {
                                 //ManyArea manyArea = new ManyArea() { areaId = $"{_areaId}", standard = $"{standard}" };
                                 school.manyAreas = new List<ManyArea>() { new ManyArea() { areaId = $"{_areaId}", standard = $"{standard}" } };
@@ -311,16 +314,41 @@ namespace TEAMModelBI.Controllers.BISchool
                 if ($"{site}".Equals(BIConst.GlobalSite))
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
 
-                var rsponse = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{schoolId}", new PartitionKey("Base"));
-                if (rsponse.Status == 200)
+                AssistSchool schoolAssists = new(); //返回学校列表集合
+                string sqlTxt = $"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c where c.id='{schoolId}'";
+                await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
                 {
-                    using var json = await JsonDocument.ParseAsync(rsponse.ContentStream);
-                    School school = json.ToObject<School>();
+                    //schoolAssists.Add(itemSchool);
+                    schoolAssists = itemSchool;
+                }
+
+                if (schoolAssists != null)
+                {
+                    var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolAssists.id, new PartitionKey("ProductSum"));
+                    if (response.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
+                        {
+                            schoolAssists.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
+                        }
+                        if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
+                        {
+                            schoolAssists.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
+                        }
+                        if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
+                        {
+                            schoolAssists.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
+                        }
+                    }
 
-                    return Ok(new { state = 200, school });
+                    schoolAssists.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolAssists.id, "assist");
+                    schoolAssists.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{schoolAssists.id}");
+
+
+                    return Ok(new { state = 200, schoolAssists });
                 }
-                else
-                    return Ok(new { state = 404, msg = $"未找到ID是({schoolId})的学校" });
+                else return Ok(new { state = 404, msg = "未找到该学校!" });
 
             }
             catch (Exception ex)
@@ -338,7 +366,7 @@ namespace TEAMModelBI.Controllers.BISchool
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("upd-school")]
-        public async Task<IActionResult> UpdSchool(School school, [FromHeader] string site) 
+        public async Task<IActionResult> UpdSchool(School school, [FromHeader] string site)
         {
             try
             {
@@ -881,7 +909,7 @@ namespace TEAMModelBI.Controllers.BISchool
                     else
                         delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{schoolId}", type = 2, status = response.Status });
                 }
-                
+
                 foreach (var item in scStuIds)
                 {
                     var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{schoolId}"));
@@ -1101,6 +1129,219 @@ namespace TEAMModelBI.Controllers.BISchool
             return Ok(new { state = 200, allSize, useSize, teacherSpace, useSpaceInfo });
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("get-schoolcnt")]
+        public async Task<IActionResult> GetSchoolCnt(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.GlobalSite))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+
+            DateTimeOffset dtime = DateTimeOffset.UtcNow;
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(dtime, "week");
+            var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dtime, "lastweek");
+            var (termS, termE) = TimeHelper.GetStartOrEnd(dtime, "term");
+            var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dtime, "lastterm");
+            var (yearS, yearE) = TimeHelper.GetStartOrEnd(dtime, "year");
+            var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(dtime, "lastYear");
+
+            int tecCnt = 0;// 教师数量
+            int classCnt = 0; //班级
+            int stuCnt = 0; //学生
+            int roomCnt = 0;  //智慧教室
+            int lesCnt = 0;  //课例总数
+
+            int weekLesCnt = 0;  //本周课例
+            int lastWeekLesCnt = 0;  //上周课例
+            int weekACTCnt = 0;  //本周活动
+            int lastWeekACTCnt = 0;  //上周活动
+
+            int termLesCnt = 0;  //本学期课例
+            int lastTermLesCnt = 0;  //上学学期课例
+            int termACTCnt = 0;  //本学期活动
+            int lastTermActCnt = 0;  //上学学期活动
+
+            int yearLesCnt = 0;  //今年课例
+            int lastYearLesCnt = 0;  //去年课例
+            int yearACTCnt = 0;  //今年课例
+            int lastYearACTCnt = 0;  //去年课例
+
+            SchoolInfo schoolInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolInfo>($"{schoolId}", new PartitionKey("Base"));
+            if (schoolInfo != null)
+            {
+                var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolInfo.id, new PartitionKey("ProductSum"));
+                if (response.Status == 200)
+                {
+                    using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                    if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
+                    {
+                        schoolInfo.serial = serial.ToObject<List<ProductSumInfos>>();
+                    }
+                    if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
+                    {
+                        schoolInfo.service = service.ToObject<List<ProductSumInfos>>();
+                    }
+                    if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
+                    {
+                        schoolInfo.hard = hard.ToObject<List<SchoolProductSumDataHard>>();
+                    }
+                }
+
+
+
+                schoolInfo.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolInfo.id, "assist");
+
+                string currencySql = "select value(count(c.id)) from c";
+
+                //schoolInfo.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql,  $"LessonRecord-{schoolInfo.id}");
+
+                tecCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"Teacher-{schoolInfo.id}"); // 教师数量
+                classCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"Class-{schoolInfo.id}"); //班级
+                stuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", currencySql, $"Base-{schoolInfo.id}"); //学生
+                roomCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"Room-{schoolInfo.id}");  //智慧教室
+                lesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"LessonRecord-{schoolInfo.id}");  //课例总数
+
+                weekLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {weekS} and  c.startTime<= {weekE}", $"LessonRecord-{schoolInfo.id}");  //本周课例
+                lastWeekLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {lastWeekS} and  c.startTime<= {lastWeekE}", $"LessonRecord-{schoolInfo.id}");  //上周课例
+
+                termLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {termS} and c.startTime <= {termE}", $"LessonRecord-{schoolInfo.id}");  //本学期课例
+                lastTermLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {lastTermS} and c.startTime <= {lastTermE}", $"LessonRecord-{schoolInfo.id}"); //上学学期课例
+
+                yearLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {yearS} and c.startTime <= {yearE}", $"LessonRecord-{schoolInfo.id}");  //今年课例
+                lastYearLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {lastYearS} and c.startTime <= {lastYearE}", $"LessonRecord-{schoolInfo.id}"); //去年课例
+                int ACTCnt = 0; //活动
+
+                foreach (var type in StaticValue.activityTypes)
+                {
+                    ACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql}  where c.pk='{type}' and c.school='{schoolInfo.id}'");
+
+                    weekACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql}  where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {weekS} and c.createTime <= {weekE} ");  //本周活动
+
+                    lastWeekACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql}  where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE} ");  //上周活动
+
+                    termACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {termS} and c.createTime <= {termE}", $"LessonRecord-{schoolInfo.id}");  //本学期活动
+                    lastTermActCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {lastTermS} and c.createTime <= {lastTermE}", $"LessonRecord-{schoolInfo.id}");  //上学学期活动
+
+                    yearACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {yearS} and c.createTime <= {yearE}", $"LessonRecord-{schoolInfo.id}");  //今年活动
+                    lastYearACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {lastYearS} and c.createTime <= {lastYearE}", $"LessonRecord-{schoolInfo.id}");  //去年活动
+
+                }
+
+                return Ok(new { state = 200, tecCnt, classCnt, stuCnt, roomCnt, lesCnt, weekLesCnt, lastWeekLesCnt, weekACTCnt, lastWeekACTCnt, termLesCnt, lastTermLesCnt, termACTCnt, lastTermActCnt, yearLesCnt, lastYearLesCnt, yearACTCnt, lastYearACTCnt, schoolInfo });
+            }
+            else
+                return Ok(new { state = 404, msg = "未找到该学校信息!" });
+        }
+
+        /// <summary>
+        /// 学校每周课例趋势
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+       [HttpPost("get-schooldate")]
+        public async Task<IActionResult> GetSchoolDate(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.GlobalSite))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+
+            List<double> weekTrend = new();
+            int year = DateTimeOffset.UtcNow.Year;
+            int dayOfweek = (int)DateTimeOffset.Parse($"{year}-1-1").DayOfWeek;
+            int currentTime = DateTimeOffset.UtcNow.DayOfYear / 7 + 1;
+            int currentTime1 = DateTimeOffset.UtcNow.DayOfYear / 7;
+
+            List<LessonCount> scount = new();
+            List<LessonCount> tcount = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{schoolId}-{year}") }))
+            {
+                scount.Add(item);
+            }
+
+            List<string> teacIds = await CommonFind.FindRolesId(cosmosClient, new List<string>() { $"{schoolId}" });
+            foreach (var tId in teacIds)
+            {
+                var sqlTxtt = $"select value(c) from c where c.id='{tId}'";
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<LessonCount>(queryText: sqlTxtt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{year}") }))
+                {
+                    tcount.Add(item);
+                }
+            }
+
+            int days = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 366 : days = 365;
+
+            List<List<double>> lessons = new();
+            if (scount.Count > 0)
+            {
+                foreach (LessonCount item in scount)
+                {
+                    lessons.Add(item.beginCount);
+                }
+            }
+            if (tcount.Count > 0)
+            {
+                foreach (LessonCount item in tcount)
+                {
+                    lessons.Add(item.beginCount);
+                }
+            }
+
+            if (lessons.Count > 0)
+            {
+                var bmatrix = DenseMatrix.OfColumns(lessons);
+
+                //开学第一周周内开课                   
+                if (dayOfweek == 0)
+                {
+                    dayOfweek = 7;
+                }
+                //第一周多少天
+                var dd = 7 - dayOfweek + 1;
+                //一年有几周
+                int sweeks = days / 7;
+                //查询天数
+                int dayYear = 0;
+                if (currentTime > 0)
+                {
+                    for (int i = 0; i <= currentTime; i++)
+                    {
+                        if (i == 0)
+                        {
+                            var bsum = bmatrix.SubMatrix(dayYear, dd, 0, bmatrix.ColumnCount).ColumnSums().Sum();
+                            dayYear += dd;
+                            //weeks.Add(i, bsum);
+                            weekTrend.Add(bsum);
+                        }
+                        else
+                        {
+                            var bsum = bmatrix.SubMatrix(dayYear, 7, 0, bmatrix.ColumnCount).ColumnSums().Sum();
+                            dayYear += 7;
+                            //weeks.Add(i, bsum);
+                            weekTrend.Add(bsum);
+                        }
+                    }
+                }
+                //最后一周是否有余
+                int stary = days - dayYear;
+                if (stary > 0 && stary < 7)
+                {
+                    var bsum = bmatrix.SubMatrix(dayYear, stary - 1, 0, bmatrix.ColumnCount).ColumnSums().Sum();
+                    //weeks.Add((sweeks + 1), bsum);
+                    weekTrend.Add(bsum);
+                }
+            }
+
+            return Ok(new { state = 200, weekTrend });
+        }
+
         /// <summary>
         /// 未加入区域的学校
         /// </summary>

+ 44 - 1
TEAMModelBI/Models/AssistSchool.cs

@@ -3,7 +3,7 @@ using TEAMModelOS.SDK.Models;
 
 namespace TEAMModelBI.Models
 {
-    public class AssistSchool
+    public class SchoolBase
     {
         public string id { get; set; }
         public string code { get; set; }
@@ -20,6 +20,13 @@ namespace TEAMModelBI.Models
         public int scale { get; set; }
         public string standard { get; set; }
         public string areaId { get; set; }
+    }
+
+    /// <summary>
+    /// 学校校展示基础信息购买模组ID
+    /// </summary>
+    public class AssistSchool : SchoolBase
+    {
         public List<SchoolTeacherRoles> assists { get; set; } = new List<SchoolTeacherRoles>();
         //public int serial { get; set; } //软体
         //public int service { get; set; } //服务
@@ -29,4 +36,40 @@ namespace TEAMModelBI.Models
         public List<string> service { get; set; } = new List<string>(); //服务
         public List<string> hard { get; set; } = new List<string>(); //硬体
     }
+
+    public class SchoolPeriod
+    {
+        public string name { get; set; }
+        public string id { get; set; }
+        public List<string> grades { get; set; }
+        public List<Subject> subjects { get; set; }
+    }
+
+    /// <summary>
+    /// 学校展示基础信息购买模组详细信息
+    /// </summary>
+    public class SchoolInfo : SchoolBase
+    {
+        public List<SchoolPeriod> period { get; set; }
+        public List<SchoolTeacherRoles> assists { get; set; } = new List<SchoolTeacherRoles>();
+        public List<ProductSumInfos> serial { get; set; } = new List<ProductSumInfos>(); //软体
+        public List<ProductSumInfos> service { get; set; } = new List<ProductSumInfos>(); //服务
+        public List<SchoolProductSumDataHard> hard { get; set; } = new List<SchoolProductSumDataHard>(); //硬体
+    }
+
+    /// <summary>
+    /// 软体和服务信息
+    /// </summary>
+    public class ProductSumInfos
+    {
+        /// <summary>
+        /// 商品标识
+        /// </summary>
+        public string prodCode { get; set; }
+
+        public int avaliable { get; set; }        
+        public long startDate { get; set; }
+        public long endDate { get; set; }
+    }
+
 }

+ 13 - 1
TEAMModelBI/Tool/TimeHelper.cs

@@ -195,11 +195,17 @@ namespace TEAMModelBI.Tool
                 DateTimeOffset tempEnd = new();
                 switch (type)
                 {
+                    //今年开始、结束
                     case "year":
                         tempStrart = new DateTime(year, 1, 1);
                         tempEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59);
                         break;
-
+                    //去年开始、结束
+                    case "lastYear":
+                        tempStrart = new DateTime(year - 1, 1, 1);
+                        tempEnd = new DateTime(year - 1, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59);
+                        break;
+                    //本学期
                     case "term":
                         if (month <= 8 && month >= 3)
                         {
@@ -223,6 +229,7 @@ namespace TEAMModelBI.Tool
                         }
 
                         break;
+                    //上学期
                     case "lastterm":
                         DateTimeOffset tempDate = new();
                         if (dateTime.Month > 9)
@@ -255,11 +262,13 @@ namespace TEAMModelBI.Tool
                         }
 
                         break;
+                    //本月
                     case "month":
                         tempStrart = new DateTime(year, month, 1);
                         tempEnd = new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59);
 
                         break;
+                    //上周
                     case "week":
                         DateTimeOffset weekStrart = dateTime.AddDays(-(int)(dateTime.DayOfWeek) + 1);
                         DateTimeOffset weekEnd = dateTime.AddDays(7 - (int)(dateTime.DayOfWeek));
@@ -267,6 +276,7 @@ namespace TEAMModelBI.Tool
                         tempEnd = new DateTime(weekEnd.Year, weekEnd.Month, weekEnd.Day, 23, 59, 59);
 
                         break;
+                    //上周
                     case "lastweek":
                         var m = (dateTime.DayOfWeek == DayOfWeek.Sunday ? (DayOfWeek)7 : dateTime.DayOfWeek) - DayOfWeek.Monday;
                         var s = (dateTime.DayOfWeek == DayOfWeek.Sunday ? (DayOfWeek)7 : dateTime.DayOfWeek) - (DayOfWeek)7;
@@ -276,11 +286,13 @@ namespace TEAMModelBI.Tool
                         tempEnd = new DateTime(Sun.Year, Sun.Month, Sun.Day, 23, 59, 59);
 
                         break;
+                    //当前小时
                     case "hour":
                         tempStrart = new DateTime(year, month, day, hour, 0, 0);
                         tempEnd = new DateTime(year, month, day, hour, 59, 59);
 
                         break;
+                    //当天
                     default:
                         tempStrart = new DateTime(year, month, day);
                         tempEnd = new DateTime(year, month, day, 23, 59, 59);