|
@@ -9,6 +9,7 @@ using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.Models;
|
|
|
using Azure.Cosmos;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
|
|
|
namespace TEAMModeBI.Controllers.BIHome
|
|
|
{
|
|
@@ -35,49 +36,225 @@ namespace TEAMModeBI.Controllers.BIHome
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("get-numberpeople")]
|
|
|
- public async Task<IActionResult> NumberPeople(JsonElement jsonElement)
|
|
|
+ public async Task<IActionResult> GetNumberPeople(JsonElement jsonElement)
|
|
|
{
|
|
|
- if (!jsonElement.TryGetProperty("schooolId", out JsonElement schoolId)) return BadRequest();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("schooolId", out JsonElement schoolId);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
+ //依据学校查询教师人数
|
|
|
+ List<string> teacherCount_list = new();
|
|
|
+ //依据学校查询学生信息
|
|
|
+ List<string> studentCount_List = new();
|
|
|
+ //学校人数
|
|
|
+ List<string> schoolCount_List = new();
|
|
|
+ //学校空间大小
|
|
|
+ int schoolsize = 0;
|
|
|
|
|
|
- //依据学校查询教师人数
|
|
|
- List<string> teacherCount_list = new();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join S1 in c.schools where S1.schoolId='{schoolId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ if (!string.IsNullOrEmpty($"{schoolId}"))
|
|
|
{
|
|
|
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
+ //查询学校教师人数
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join S1 in c.schools where S1.schoolId='{schoolId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ teacherCount_list.Add(account.GetProperty("id").GetString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询学校学生人数
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ studentCount_List.Add(account.GetProperty("id").GetString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { TeacherCount = teacherCount_list.Count, StudentCount = studentCount_List.Count });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //查询全部教师人数
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select * from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ teacherCount_list.Add(account.GetProperty("id").GetString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询全部学生人数
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.pk='Base'"))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ studentCount_List.Add(account.GetProperty("id").GetString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询已创建多少学校
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.size from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
{
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- teacherCount_list.Add(account.GetProperty("id").GetString());
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ schoolCount_List.Add(account.GetProperty("id").GetString());
|
|
|
+ schoolsize += int.Parse(account.GetProperty("size").ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return Ok(new { TeacherCount = teacherCount_list.Count, StudentCount = studentCount_List.Count, schoolCount = schoolCount_List.Count, schoolsize = schoolsize });
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-numberpeople \n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //
|
|
|
- List<string> studentCount_List = new();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
+ /// <summary>
|
|
|
+ /// 其它类型的统计
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-othertypes")]
|
|
|
+ public async Task<IActionResult> GetOtherTypes(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ if (!jsonElement.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
|
|
|
+
|
|
|
+ int surveyJoinCount = 0;
|
|
|
+ int surveyDoneCount = 0;
|
|
|
+ int surveyAreaJoinCount = 0;
|
|
|
+ int surveyAreaDoneCount = 0;
|
|
|
+ int examJoinCount = 0;
|
|
|
+ int examDoneCount = 0;
|
|
|
+ int examAreaJoinCount = 0;
|
|
|
+ int examAreaDoneCount = 0;
|
|
|
+ int voteJoinCount = 0;
|
|
|
+ int voteDoneCount = 0;
|
|
|
+ int voteAreaJoinCount = 0;
|
|
|
+ int voteAreaDoneCount = 0;
|
|
|
+
|
|
|
+ //问卷调查
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
|
|
|
+ .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Survey' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
|
|
|
{
|
|
|
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
+ if (!string.IsNullOrEmpty(item.owner))
|
|
|
{
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- studentCount_List.Add(account.GetProperty("id").GetString());
|
|
|
+ if (item.owner.Equals("school"))
|
|
|
+ {
|
|
|
+ surveyJoinCount += 1;
|
|
|
+ if (item.taskStatus > 0)
|
|
|
+ {
|
|
|
+ surveyDoneCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.owner.Equals("area"))
|
|
|
+ {
|
|
|
+ surveyAreaJoinCount += 1;
|
|
|
+ if (item.taskStatus > 0)
|
|
|
+ {
|
|
|
+ surveyAreaDoneCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
+ //评量检测
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
|
|
|
+ .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'ExamLite' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(item.owner))
|
|
|
+ {
|
|
|
+ if (item.owner.Equals("school"))
|
|
|
+ {
|
|
|
+ examJoinCount += 1;
|
|
|
+ if (item.taskStatus > 0)
|
|
|
+ {
|
|
|
+ examDoneCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.owner.Equals("area"))
|
|
|
+ {
|
|
|
+ examAreaJoinCount += 1;
|
|
|
+ if (item.taskStatus > 0)
|
|
|
+ {
|
|
|
+ examAreaDoneCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return Ok(new { SchoolTeacherCount = teacherCount_list.Count });
|
|
|
+ //投票活动
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
|
|
|
+ .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Vote' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(item.owner))
|
|
|
+ {
|
|
|
+ if (item.owner.Equals("school"))
|
|
|
+ {
|
|
|
+ voteJoinCount += 1;
|
|
|
+ if (item.taskStatus > 0)
|
|
|
+ {
|
|
|
+ voteDoneCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.owner.Equals("area"))
|
|
|
+ {
|
|
|
+ voteAreaJoinCount += 1;
|
|
|
+ if (item.taskStatus > 0)
|
|
|
+ {
|
|
|
+ voteAreaDoneCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ return Ok(new { surveyJoinCount, surveyDoneCount, surveyAreaJoinCount, surveyAreaDoneCount, examJoinCount, examDoneCount, examAreaJoinCount, examAreaDoneCount, voteJoinCount, voteDoneCount, voteAreaJoinCount, voteAreaDoneCount, });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-othertypes \n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|