|
@@ -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>
|