|
@@ -6,10 +6,11 @@ using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Text.Json;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
-using TEAMModelOS.Models;
|
|
|
using Azure.Cosmos;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using System.Text;
|
|
|
|
|
|
namespace TEAMModeBI.Controllers.BIHome
|
|
|
{
|
|
@@ -29,18 +30,16 @@ namespace TEAMModeBI.Controllers.BIHome
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 依据学校编号,获取教师、学生数量
|
|
|
- /// 没有传入学校编号,获取全部教师数量、学生数量、已创校数量、全部学校总空间大小
|
|
|
+ /// 获取全部教师数量、学生数量、已创校数量、全部学校总空间大小
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("get-numberpeople")]
|
|
|
- public async Task<IActionResult> GetNumberPeople(JsonElement jsonElement)
|
|
|
+ [HttpPost("get-allnumber")]
|
|
|
+ public async Task<IActionResult> GetAllNumber()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- jsonElement.TryGetProperty("schooolid", out JsonElement schoolId);
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
|
|
|
//依据学校查询教师人数
|
|
@@ -51,146 +50,55 @@ namespace TEAMModeBI.Controllers.BIHome
|
|
|
List<string> schoolCount_List = new();
|
|
|
//学校空间大小
|
|
|
int schoolsize = 0;
|
|
|
- //方案数
|
|
|
- List<string> areaCount_List = new();
|
|
|
- //册别数量
|
|
|
- List<string> abilityCount = new List<string>();
|
|
|
- //章节数量
|
|
|
- List<string> abilityTaskCount = new List<string>();
|
|
|
-
|
|
|
- if (!string.IsNullOrEmpty($"{schoolId}"))
|
|
|
- {
|
|
|
- //查询学校教师人数
|
|
|
- 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") }))
|
|
|
{
|
|
|
- //查询全部教师人数
|
|
|
- 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)
|
|
|
{
|
|
|
- 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())
|
|
|
{
|
|
|
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
- {
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- teacherCount_list.Add(account.GetProperty("id").GetString());
|
|
|
- }
|
|
|
+ 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'"))
|
|
|
+ //查询全部学生人数
|
|
|
+ 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)
|
|
|
{
|
|
|
- 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())
|
|
|
{
|
|
|
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
- {
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- studentCount_List.Add(account.GetProperty("id").GetString());
|
|
|
- }
|
|
|
+ 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") }))
|
|
|
- {
|
|
|
- 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());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //查询微能力点方案
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryStreamIterator(queryText: $"select c.id,c.standard from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
|
|
|
+ //查询已创建多少学校
|
|
|
+ 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") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- 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())
|
|
|
{
|
|
|
- var area = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (area.MoveNext())
|
|
|
- {
|
|
|
- JsonElement areacount = area.Current;
|
|
|
- areaCount_List.Add(areacount.GetProperty("standard").GetString());
|
|
|
- }
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ schoolCount_List.Add(account.GetProperty("id").GetString());
|
|
|
+ schoolsize += int.Parse(account.GetProperty("size").ToString());
|
|
|
}
|
|
|
}
|
|
|
- if (areaCount_List.Count > 0)
|
|
|
- {
|
|
|
- foreach (var tempItem in areaCount_List)
|
|
|
- {
|
|
|
- //册别数量
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{tempItem}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- var tempAbility = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (tempAbility.MoveNext())
|
|
|
- {
|
|
|
- JsonElement jsonAbility = tempAbility.Current;
|
|
|
- abilityCount.Add(jsonAbility.GetProperty("id").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- //章节数量
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{tempItem}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- var tempAbilityTask = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (tempAbilityTask.MoveNext())
|
|
|
- {
|
|
|
- JsonElement jsonAbilityTask = tempAbilityTask.Current;
|
|
|
- abilityTaskCount.Add(jsonAbilityTask.GetProperty("id").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ return Ok(new { teacherCount = teacherCount_list.Count, studentCount = studentCount_List.Count, schoolCount = schoolCount_List.Count, schoolSize = schoolsize });
|
|
|
|
|
|
- return Ok(new { teacherCount = teacherCount_list.Count, studentCount = studentCount_List.Count, schoolCount = schoolCount_List.Count, schoolsize = schoolsize, areaCount = areaCount_List.Count, abilityCount = abilityCount.Count, abilityTaskCount = abilityTaskCount.Count });
|
|
|
- }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -310,37 +218,190 @@ namespace TEAMModeBI.Controllers.BIHome
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 查询地区信息
|
|
|
+ /// 查询所有区级信息统计数据
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("get-regionnumber")]
|
|
|
- public async Task<IActionResult> GetRegionNumber(JsonElement jsonElement)
|
|
|
+ [HttpPost("get-alldiststics")]
|
|
|
+ public async Task<IActionResult> GetAllDistStics(JsonElement jsonElement)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- jsonElement.TryGetProperty("country", out JsonElement _country); //
|
|
|
- jsonElement.TryGetProperty("province", out JsonElement _province);
|
|
|
- jsonElement.TryGetProperty("city", out JsonElement _city);
|
|
|
- jsonElement.TryGetProperty("county", out JsonElement _county);
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ List<SticsCity> standards = new List<SticsCity>();
|
|
|
+ StringBuilder stringBuder = new StringBuilder("select c.name,c.provName,c.cityName,c.standard from c");
|
|
|
+ //查询省份区域
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: stringBuder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
|
|
|
+ {
|
|
|
+ SticsCity sticsCity = new SticsCity
|
|
|
+ {
|
|
|
+ provName = item.provName,
|
|
|
+ cityName = item.cityName,
|
|
|
+ distName = item.name,
|
|
|
+ standard = item.standard
|
|
|
+ };
|
|
|
+ standards.Add(sticsCity);
|
|
|
+ }
|
|
|
+ List<SticsDist> sticsDists = new List<SticsDist>();
|
|
|
+
|
|
|
+ //查询所有下面的学校数量
|
|
|
+ foreach (var itemStandrds in standards)
|
|
|
+ {
|
|
|
+ SticsDist sticsDist = new SticsDist();
|
|
|
+
|
|
|
+ sticsDist.provName = itemStandrds.provName;
|
|
|
+ sticsDist.cityName = itemStandrds.cityName;
|
|
|
+ sticsDist.distName = itemStandrds.distName;
|
|
|
+ sticsDist.standard = itemStandrds.standard;
|
|
|
+
|
|
|
+ List<string> schoolIds = new List<string>();
|
|
|
+ int schoolCount = 0;
|
|
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrds.standard}'", 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;
|
|
|
+ schoolIds.Add(account.GetProperty("id").GetString());
|
|
|
+ schoolCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sticsDist.schoolCount = schoolCount;
|
|
|
|
|
|
+ int teacherCount = 0; //教师数量
|
|
|
+ int studentCount = 0; //学生数量
|
|
|
+ List<string> teacherIds = new List<string>();
|
|
|
|
|
|
+ List<string> studentIds = new List<string>();
|
|
|
+
|
|
|
+ //查询学校下面的教师人数
|
|
|
+ foreach (var itemSchool in schoolIds)
|
|
|
+ {
|
|
|
+ string sqlTeacherTxt = $"select distinct value(c) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
|
|
|
+ //查询全部教师人数
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: sqlTeacherTxt, 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;
|
|
|
+ //teacherIds.Add(account.GetProperty("id").GetString());
|
|
|
+ teacherCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //查询全部学生人数
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ //studentIds.Add(account.GetProperty("id").GetString());
|
|
|
+ studentCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ sticsDist.teacherCount = teacherCount;
|
|
|
+ sticsDist.studentCount = studentCount;
|
|
|
|
|
|
+ sticsDists.Add(sticsDist);
|
|
|
+ }
|
|
|
|
|
|
- return Ok(new { state = 200 });
|
|
|
+ return Ok(new { state = 200, sticsDists });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"BI,{_option.Location} homestatis/get-regionnumber \n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} homestatis/get-alldiststics \n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 区域
|
|
|
+ /// </summary>
|
|
|
+ public record SticsCity
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 省份
|
|
|
+ /// </summary>
|
|
|
+ public string provName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 市名称
|
|
|
+ /// </summary>
|
|
|
+ public string cityName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 区域名称
|
|
|
+ /// </summary>
|
|
|
+ public string distName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 区域标准
|
|
|
+ /// </summary>
|
|
|
+ public string standard { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 返回统计数据
|
|
|
+ /// </summary>
|
|
|
+ public record SticsDist
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 省份
|
|
|
+ /// </summary>
|
|
|
+ public string provName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 市名
|
|
|
+ /// </summary>
|
|
|
+ public string cityName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 区域标准名称
|
|
|
+ /// </summary>
|
|
|
+ public string distName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 区域标准
|
|
|
+ /// </summary>
|
|
|
+ public string standard { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 学校数量
|
|
|
+ /// </summary>
|
|
|
+ public int schoolCount { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 教师人数
|
|
|
+ /// </summary>
|
|
|
+ public int teacherCount { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 学生人数
|
|
|
+ /// </summary>
|
|
|
+ public int studentCount { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|