|
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
@@ -34,7 +35,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 统计所有学校
|
|
|
+ /// 统计所有分析:基础、课例、活动、资源
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
@@ -43,43 +44,183 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
{
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
|
|
+ long schoolCount = 0; //学校数量
|
|
|
+ int tecCount = 0; //教师数量
|
|
|
+ int stuCount = 0; //学生数量
|
|
|
+ long roomCount = 0; //教室数量
|
|
|
+ long wisdomRoomCount = 0; //智慧教室数量
|
|
|
+ long allClassCount = 0; //所有班级
|
|
|
+
|
|
|
long allLessCount = 0; //所有课例
|
|
|
long lastYearLessCount = 0; //去年课例
|
|
|
long yearLessCount = 0;//今年课例
|
|
|
+ long lastWeekLessCount = 0; //上周课例
|
|
|
+ long weekLessCount = 0; //本周课例
|
|
|
+ long lastTermLessCount = 0; //上学期课例
|
|
|
+ long termLessCount = 0; //本学期课例
|
|
|
+
|
|
|
long allActivityCount = 0; //所有活动
|
|
|
long lastActivityCount = 0; //去年活动
|
|
|
long activityCount = 0; //今年活动
|
|
|
- int tecCount = 0; //教师数量
|
|
|
- int stuCount = 0; //学生数量
|
|
|
- long roomCount = 0; //教师数量
|
|
|
-
|
|
|
+ long lastWeekActivitCount = 0; //上周活动
|
|
|
+ long weekActivitCount = 0; //本周活动
|
|
|
+ long lastTermActivitCount =0; //上学期活动
|
|
|
+ long TermActivitCount = 0; //本学期学期活动
|
|
|
+
|
|
|
+ long rercCount = 0; //所有资源数量
|
|
|
+ long weekRercCount = 0; //本周资源数量
|
|
|
+ long lastWeekRercCount = 0; //上周资源数量
|
|
|
+ long lastTermRercCount = 0; //上学期资源
|
|
|
+ long termRercCount = 0; //本学期资源
|
|
|
+ long lastYearRercCount = 0; //去年资源
|
|
|
+ long yearRercCount = 0; //去年资源
|
|
|
|
|
|
+ var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
|
|
|
+ var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year"); //计算今年开始/结束时间
|
|
|
+ var (lastWeekStart, lastWeekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastweek"); //计算上周开始/结束时间
|
|
|
+ var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week"); //计算本周开始/结束时间
|
|
|
+ var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm"); //计算上学期开始/结束时间
|
|
|
+ var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term"); //计算本学期开始/结束时间
|
|
|
|
|
|
- var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year");
|
|
|
- var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year");
|
|
|
+ schoolCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "School", "Base"); //所有学校数量
|
|
|
+ tecCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Teacher", "Base"); //所有教师数量
|
|
|
+ stuCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Student", "Base"); //所有学生数量
|
|
|
+ allClassCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Class'", new List<string>() { "School" }); //所有班级数量
|
|
|
+ roomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room'", new List<string>() { "School" }); //所有教室数量
|
|
|
+ wisdomRoomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room' and c.serial != null", new List<string>() { "School" }); //智慧教室数量
|
|
|
|
|
|
- List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, "select c.id from c", "Base");
|
|
|
- tecCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Teacher", "Base");
|
|
|
- stuCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Student", "Base");
|
|
|
- roomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room' and c.serial != null", new List<string>() { "School" });
|
|
|
+ List<string> containers = new() { "School", "Teacher" };
|
|
|
+ string lessSqlTxt = "select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={0} and c.startTime<={1}";
|
|
|
|
|
|
+ allLessCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord'", containers);//所有课例
|
|
|
+ lastYearLessCount = await CommonFind.FindTotals(cosmosClient, string.Format(lessSqlTxt, lastYearStart, lastYearEnd), containers); //去年课例
|
|
|
+ yearLessCount = await CommonFind.FindTotals(cosmosClient, string.Format(lessSqlTxt, yearStart, yearEnd), containers); //今年课例
|
|
|
+ lastWeekLessCount = await CommonFind.FindTotals(cosmosClient, string.Format(lessSqlTxt, lastWeekStart, lastWeekEnd), containers); //上周课例
|
|
|
+ weekLessCount = await CommonFind.FindTotals(cosmosClient, string.Format(lessSqlTxt, weekStart, weekEnd), containers); //本周课例
|
|
|
+ lastTermLessCount = await CommonFind.FindTotals(cosmosClient, string.Format(lessSqlTxt, lastTermStart, lastTermEnd), containers); //上学期课例
|
|
|
+ termLessCount = await CommonFind.FindTotals(cosmosClient, string.Format(lessSqlTxt, termStart, termEnd), containers); //上学期课例
|
|
|
|
|
|
- //所有课例
|
|
|
- allLessCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord'", new List<string>() { "School", "Teacher" });
|
|
|
- //去年课例
|
|
|
- lastYearLessCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={lastYearStart} and c.startTime<={lastYearEnd}", new List<string>() { "School", "Teacher" });
|
|
|
- //今年课例
|
|
|
- yearLessCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={yearStart} and c.startTime<={yearEnd}", new List<string>() { "School", "Teacher" });
|
|
|
+ List<string> containerTypes = new() { "Common" };
|
|
|
+ string typeSqlTxt = "select count(c.id) as totals from c where c.pk='{0}' and c.createTime >={1} and c.createTime<= {2}";
|
|
|
|
|
|
- //活动
|
|
|
foreach (var type in StaticValue.activityTypes)
|
|
|
{
|
|
|
- allActivityCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='{type}' ", new List<string>() { "Common" });
|
|
|
- lastActivityCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='{type}' and c.createTime >={lastYearStart} and c.createTime<= {lastYearEnd}", new List<string>() { "Common" });
|
|
|
- activityCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='{type}' and c.createTime >={yearStart} and c.createTime<= {yearEnd}", new List<string>() { "Common" });
|
|
|
+ allActivityCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='{type}' ", containerTypes);//所有活动
|
|
|
+ lastActivityCount += await CommonFind.FindTotals(cosmosClient, string.Format(typeSqlTxt, type, lastYearStart, lastYearEnd), containerTypes); //去年活动
|
|
|
+ activityCount += await CommonFind.FindTotals(cosmosClient, string.Format(typeSqlTxt, type, yearStart, yearEnd), containerTypes); //今年活动
|
|
|
+ lastWeekActivitCount += await CommonFind.FindTotals(cosmosClient, string.Format(typeSqlTxt, type, lastWeekStart, lastWeekEnd), containerTypes); //上周活动
|
|
|
+ weekActivitCount += await CommonFind.FindTotals(cosmosClient, string.Format(typeSqlTxt, type, weekStart, weekEnd), containerTypes); //本周活动
|
|
|
+ lastTermActivitCount += await CommonFind.FindTotals(cosmosClient, string.Format(typeSqlTxt, type, lastTermStart, lastTermEnd), containerTypes); //上学期活动
|
|
|
+ TermActivitCount += await CommonFind.FindTotals(cosmosClient, string.Format(typeSqlTxt, type, termStart, termEnd), containerTypes); //本学期学期活动
|
|
|
+ }
|
|
|
+
|
|
|
+ string bloblSqlTxt = "select count(c.id) as totals from c where c.pk='Bloblog' and c.time>={0} and c.time<={1}";
|
|
|
+
|
|
|
+ rercCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.pk='Bloblog'", containers); //所有资源
|
|
|
+ lastWeekRercCount = await CommonFind.FindTotals(cosmosClient, string.Format(bloblSqlTxt, lastWeekStart, lastWeekEnd), containers); //上周资源
|
|
|
+ weekRercCount = await CommonFind.FindTotals(cosmosClient, string.Format(bloblSqlTxt, weekStart, weekEnd), containers); //本周资源
|
|
|
+ lastTermRercCount = await CommonFind.FindTotals(cosmosClient, string.Format(bloblSqlTxt, lastTermStart, lastTermEnd), containers); //上学期资源
|
|
|
+ termRercCount = await CommonFind.FindTotals(cosmosClient, string.Format(bloblSqlTxt, termStart, termEnd), containers); //这学期资源
|
|
|
+ lastYearRercCount = await CommonFind.FindTotals(cosmosClient, string.Format(bloblSqlTxt, lastYearStart, lastYearEnd), containers); //去年资源
|
|
|
+ yearRercCount = await CommonFind.FindTotals(cosmosClient, string.Format(bloblSqlTxt, yearStart, yearEnd), containers); //今年资源
|
|
|
+
|
|
|
+ return Ok(new { state = 200, schoolCount, tecCount, stuCount, allClassCount, roomCount, wisdomRoomCount, allLessCount, lastYearLessCount, yearLessCount, lastWeekLessCount, weekLessCount, lastTermLessCount, termLessCount, allActivityCount, lastActivityCount, activityCount, lastWeekActivitCount, weekActivitCount, lastTermActivitCount, TermActivitCount, rercCount, lastWeekRercCount, weekRercCount, lastTermRercCount, termRercCount, lastYearRercCount, yearRercCount });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询顾问相关的学校统计数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("get-assist")]
|
|
|
+ public async Task<IActionResult> GetAssistStatis(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
+
|
|
|
+ int tecCount = 0; //教师数量
|
|
|
+ int stuCount = 0; //学校数量
|
|
|
+ int classCount = 0; //班级数量
|
|
|
+ int roomCount = 0; //智慧教师数量
|
|
|
+ int allLessonCount = 0; //课例数量
|
|
|
+ int lastWeekLessCount = 0;// 上周课例数
|
|
|
+ int weekLessCount = 0; //本周课例
|
|
|
+ int lastTermLessCount = 0;// 上学期课例数
|
|
|
+ int termLessCount = 0; //本学期课例
|
|
|
+ int lastYearLessCount = 0; //去年课例
|
|
|
+ int yearLessCount = 0; //今年课例
|
|
|
+
|
|
|
+ int allBloblog = 0; //学校资源
|
|
|
+ int lastYearBloblog = 0; //去年学校资源
|
|
|
+ int yearBloblog = 0; //今年学校资源
|
|
|
+
|
|
|
+ long allActivity = 0; //学校所有活动
|
|
|
+ long lastYearActivity = 0; //去年学校所有活动
|
|
|
+ long yearActivity = 0; //今年学校所有活动
|
|
|
+ long lastWeekActivity = 0; //上周学校所有活动
|
|
|
+ long weekActivity = 0; //本周学校所有活动
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
+
|
|
|
+ var (lastWeekStart, lastWeekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastweek"); //计算上周开始/结束时间
|
|
|
+ var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week"); //计算本周开始/结束时间
|
|
|
+ var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm"); //计算上学期开始/结束时间
|
|
|
+ var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term"); //计算本学期开始/结束时间
|
|
|
+ var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
|
|
|
+ var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year"); //计算今年开始/结束时间
|
|
|
+
|
|
|
+ string unifySqlTxt = "select count(c.id) as totals from c";
|
|
|
+ string unifyTimeSql = "select count(c.id) as totals from c where c.startTime>={0} and c.startTime<={1}";
|
|
|
+ string blobTimeSql = "select count(c.id) as totals from c where c.time>={0} and c.time<={1}";
|
|
|
+ List<RecSchoolDate> recSchoolDates = new();
|
|
|
+
|
|
|
+ foreach (var itemId in schoolIds)
|
|
|
+ {
|
|
|
+ School school = new();
|
|
|
+ var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ school = json.ToObject<School>();
|
|
|
+ }
|
|
|
+ tecCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'", "School", $"Teacher-{itemId}");
|
|
|
+ stuCount += await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "Student", $"Base-{itemId}");
|
|
|
+ classCount += await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"Class-{itemId}");
|
|
|
+ roomCount += await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"Room-{itemId}");
|
|
|
+ //学校所有课例
|
|
|
+ int tempLessCount = await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"LessonRecord-{itemId}");
|
|
|
+ lastWeekLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql,lastWeekStart,lastWeekEnd), "School", $"LessonRecord-{itemId}");
|
|
|
+ weekLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, weekStart, weekEnd), "School", $"LessonRecord-{itemId}");
|
|
|
+ lastTermLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, lastTermStart, lastTermEnd), "School", $"LessonRecord-{itemId}");
|
|
|
+ termLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, termStart, termEnd), "School", $"LessonRecord-{itemId}");
|
|
|
+ lastYearLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, lastYearStart, lastYearEnd), "School", $"LessonRecord-{itemId}");
|
|
|
+ yearLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, yearStart, yearEnd), "School", $"LessonRecord-{itemId}");
|
|
|
+
|
|
|
+ //学校资源
|
|
|
+ int tempBloblog = await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"Bloblog-{itemId}");
|
|
|
+ lastYearBloblog += await CommonFind.FindTotals(cosmosClient, string.Format(blobTimeSql,lastYearStart,lastYearEnd), "School", $"Bloblog-{itemId}");
|
|
|
+ yearBloblog += await CommonFind.FindTotals(cosmosClient, string.Format(blobTimeSql, yearStart, yearEnd), "School", $"Bloblog-{itemId}");
|
|
|
+
|
|
|
+ //学校活动
|
|
|
+ long tempallActivity = 0;
|
|
|
+ //统计活动
|
|
|
+ foreach (var type in StaticValue.activityTypes)
|
|
|
+ {
|
|
|
+ string sqlTime = "SELECT count(c.id) as totals FROM c where c.pk = '{0}' and c.school = '{1}' and c.createTime>={2} and c.createTime<={3}";
|
|
|
+ tempallActivity += await CommonFind.FindTotals(cosmosClient, $"SELECT count(c.id) as totals FROM c where c.pk = '{type}' and c.school = '{itemId}'", new List<string> { "Common" });
|
|
|
+ lastYearActivity += await CommonFind.FindTotals(cosmosClient, string.Format(sqlTime,type,itemId, lastYearStart, lastYearEnd), new List<string> { "Common" });
|
|
|
+ yearActivity += await CommonFind.FindTotals(cosmosClient, string.Format(sqlTime, type, itemId, yearStart, yearEnd), new List<string> { "Common" });
|
|
|
+ lastWeekActivity += await CommonFind.FindTotals(cosmosClient, string.Format(sqlTime, type, itemId, lastWeekStart, lastWeekEnd), new List<string> { "Common" });
|
|
|
+ weekActivity += await CommonFind.FindTotals(cosmosClient, string.Format(sqlTime, type, itemId, weekStart, weekEnd), new List<string> { "Common" });
|
|
|
+ }
|
|
|
+ allLessonCount += tempLessCount;
|
|
|
+ allActivity += tempallActivity;
|
|
|
+ allBloblog += tempBloblog;
|
|
|
+
|
|
|
+ recSchoolDates.Add(new RecSchoolDate() { id = school.id, name = school.name, dataCount = (tempLessCount + tempallActivity + tempBloblog) });
|
|
|
}
|
|
|
|
|
|
- return Ok(new { state = 200, scCount = schoolIds.Count, tecCount, stuCount, roomCount, allLessCount, lastYearLessCount, yearLessCount, allActivityCount, lastActivityCount, activityCount });
|
|
|
+ return Ok(new { state = 200, schoolCount = schoolIds.Count, tecCount, stuCount, classCount, roomCount, allLessonCount, lastWeekLessCount, weekLessCount, lastTermLessCount, termLessCount, lastYearLessCount, yearLessCount,allBloblog , lastYearBloblog, yearBloblog , allActivity , lastYearActivity ,yearActivity , lastWeekActivity, weekActivity, recSchoolDates });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -107,6 +248,12 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
return Ok(new { state = 200, infos });
|
|
|
}
|
|
|
|
|
|
+ public record RecSchoolDate
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public long dataCount { get; set; }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|