|
@@ -7,6 +7,10 @@ using System.Threading.Tasks;
|
|
|
using System.Collections.Generic;
|
|
|
using Azure.Cosmos;
|
|
|
using System.Text.Json;
|
|
|
+using TEAMModelBI.Tool;
|
|
|
+using System;
|
|
|
+using System.Text;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.Census
|
|
|
{
|
|
@@ -32,46 +36,124 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("get-type")]
|
|
|
- public async Task<IActionResult> GetTypeCount()
|
|
|
+ public async Task<IActionResult> GetTypeCount(JsonElement jsonElement)
|
|
|
{
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ jsonElement.TryGetProperty("term", out JsonElement term);
|
|
|
+
|
|
|
+ var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
+
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
List<string> itemType = new List<string> { "single", "multiple", "judge", "complete", "subjective", "connector", "correct", "compose" };
|
|
|
- List<KeyValuePair<string, long>> typeCount = new List<KeyValuePair<string, long>>();
|
|
|
- foreach (var type in itemType)
|
|
|
+ List<object> typeCount = new List<object>();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
- long total = 0;
|
|
|
+ List<string> schoolIds = new List<string>();
|
|
|
|
|
|
- //string sqlText = $"select c.id from c where c.pk='Item' and c.type='{type}'";
|
|
|
- string sqlText = $"select COUNT(c.id) AS totals from c where c.pk='Item' and c.type='{type}'";
|
|
|
+ string schoolSql = $"SELECT DISTINCT REPLACE(c.code,'Teacher-','') AS schoolId,c.code,c.roles,c.id,c.name From c where ARRAY_CONTAINS(c.roles,'assist',true) AND c.pk = 'Teacher' AND c.status = 'join' AND c.id='{tmdId}'";
|
|
|
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS","School").GetItemQueryStreamIterator(queryText:sqlText,requestOptions:new QueryRequestOptions() {}))
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- //total += count.GetInt64();
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- total += obj.GetProperty("totals").GetInt32();
|
|
|
- }
|
|
|
+ schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlText, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ foreach (var schoolId in schoolIds)
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
|
|
|
+ School school = new();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
{
|
|
|
- //total += count.GetInt64();
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ }
|
|
|
+
|
|
|
+ Census tempCensus = new Census() { id = schoolId, name = school.name != null ? school.name : schoolId };
|
|
|
+
|
|
|
+ foreach (var type in itemType)
|
|
|
+ {
|
|
|
+ StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.code='Item-{schoolId}' and c.type='{type}'");
|
|
|
+
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
{
|
|
|
- total += obj.GetProperty("totals").GetInt32();
|
|
|
+ sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
|
|
|
}
|
|
|
+
|
|
|
+ long totals = 0;
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ totals += obj.GetProperty("totals").GetInt32();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{schoolId}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ totals += obj.GetProperty("totals").GetInt32();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempCensus.census.Add(new KeyValuePair<object, long>(type, totals));
|
|
|
}
|
|
|
+ typeCount.Add(tempCensus);
|
|
|
}
|
|
|
- typeCount.Add(new KeyValuePair<string, long>(type, total));
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var type in itemType)
|
|
|
+ {
|
|
|
+ long total = 0;
|
|
|
+ StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.pk='Item' and c.type='{type}'");
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
+ {
|
|
|
+ sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
|
|
|
+ }
|
|
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ total += obj.GetProperty("totals").GetInt32();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ total += obj.GetProperty("totals").GetInt32();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ typeCount.Add(new KeyValuePair<string, object>(type, total));
|
|
|
+ }
|
|
|
+ }
|
|
|
return Ok(new { state = 200, typeCount });
|
|
|
}
|
|
|
|
|
@@ -79,46 +161,126 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
/// 依据难度统计
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("get-leve")]
|
|
|
- public async Task<IActionResult> GetLeveCount()
|
|
|
+ [HttpPost("get-level")]
|
|
|
+ public async Task<IActionResult> GetLevelCount(JsonElement jsonElement)
|
|
|
{
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ jsonElement.TryGetProperty("term", out JsonElement term);
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
- List<KeyValuePair<int, long>> leveCount = new List<KeyValuePair<int, long>>();
|
|
|
- for (int i = 1; i < 6; i++)
|
|
|
+ var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
+
|
|
|
+ List<object> levelCount = new List<object>();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
- long total = 0;
|
|
|
- //string sqlText = $"select c.id from c where c.pk='Item' and c.level={i}";
|
|
|
- string sqlText = $"select COUNT(c.id) AS totals from c where c.pk='Item' and c.level={i}";
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlText, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ List<string> schoolIds = new List<string>();
|
|
|
+
|
|
|
+ string schoolSql = $"SELECT DISTINCT REPLACE(c.code,'Teacher-','') AS schoolId,c.code,c.roles,c.id,c.name From c where ARRAY_CONTAINS(c.roles,'assist',true) AND c.pk = 'Teacher' AND c.status = 'join' AND c.id='{tmdId}'";
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- //total += count.GetInt64();
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- total += obj.GetProperty("totals").GetInt64();
|
|
|
- }
|
|
|
+ schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlText, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ foreach (var schoolId in schoolIds)
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ School school = new();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ Census tempCensus = new Census() { id = schoolId, name = school.name != null ? school.name : schoolId };
|
|
|
+
|
|
|
+ for (int i = 1; i < 6; i++)
|
|
|
{
|
|
|
- //total += count.GetInt64();
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ StringBuilder sqlTxt = new StringBuilder($"SELECT COUNT(c.id) AS totals FROM c WHERE c.code='Item-{schoolId}' and c.level={i}");
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
+ {
|
|
|
+ sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
|
|
|
+ }
|
|
|
+
|
|
|
+ long totals = 0;
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ totals += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
{
|
|
|
- total += obj.GetProperty("totals").GetInt64();
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ totals += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ tempCensus.census.Add(new KeyValuePair<object, long>(i, totals));
|
|
|
}
|
|
|
+ levelCount.Add(tempCensus);
|
|
|
}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //List<KeyValuePair<int, long>> leveCount = new List<KeyValuePair<int, long>>();
|
|
|
+ for (int i = 1; i < 6; i++)
|
|
|
+ {
|
|
|
+ long total = 0;
|
|
|
+ StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.pk='Item' and c.level={i}");
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
+ {
|
|
|
+ sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ total += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ total += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- leveCount.Add(new KeyValuePair<int, long>(i, total));
|
|
|
+ levelCount.Add(new KeyValuePair<int, long>(i, total));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return Ok(new { state = 200, leveCount });
|
|
|
+ return Ok(new { state = 200, levelCount });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -127,48 +289,142 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("get-layer")]
|
|
|
- public async Task<IActionResult> GetLayerCount()
|
|
|
+ public async Task<IActionResult> GetLayerCount(JsonElement jsonElement)
|
|
|
{
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ jsonElement.TryGetProperty("term", out JsonElement term);
|
|
|
+
|
|
|
+ var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
- List<KeyValuePair<int, long>> layerCount = new List<KeyValuePair<int, long>>();
|
|
|
- for (int i = 1; i <= 6; i++)
|
|
|
+ List<object> layerCount = new List<object>();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
- long total = 0;
|
|
|
+ List<string> schoolIds = new List<string>();
|
|
|
+ string schoolSql = $"SELECT DISTINCT REPLACE(c.code,'Teacher-','') AS schoolId,c.code,c.roles,c.id,c.name From c where ARRAY_CONTAINS(c.roles,'assist',true) AND c.pk = 'Teacher' AND c.status = 'join' AND c.id='{tmdId}'";
|
|
|
|
|
|
- //string sqlText = $"select c.id from c where c.pk='Item' and c.field={i}";
|
|
|
- string sqlText = $"select COUNT(c.id) AS totals from c where c.pk='Item' and c.field={i}";
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlText, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt64() > 0)
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- //total += count.GetInt64();
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- total += obj.GetProperty("totals").GetInt64();
|
|
|
- }
|
|
|
+ schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlText, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ foreach (var schoolId in schoolIds)
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ School school = new();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ Census tempCensus = new Census() { id = schoolId, name = school.name != null ? school.name : schoolId };
|
|
|
+
|
|
|
+ for (int i = 1; i <= 6; i++)
|
|
|
{
|
|
|
- //total += count.GetInt64();
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ long total = 0;
|
|
|
+ StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.code='Item-{schoolId}' and c.field={i}");
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
{
|
|
|
- total += obj.GetProperty("totals").GetInt64();
|
|
|
+ sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
|
|
|
}
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ total += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ total += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempCensus.census.Add(new KeyValuePair<object, long>(i, total));
|
|
|
}
|
|
|
+
|
|
|
+ layerCount.Add(tempCensus);
|
|
|
}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (int i = 1; i <= 6; i++)
|
|
|
+ {
|
|
|
+ long totals = 0;
|
|
|
+ StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.pk='Item' and c.field={i}");
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
+ {
|
|
|
+ sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ totals += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- layerCount.Add(new KeyValuePair<int, long>(i, total));
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ {
|
|
|
+ //total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ totals += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ layerCount.Add(new KeyValuePair<object, long>(i, totals));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return Ok(new { state = 200, layerCount });
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 统计实体
|
|
|
+ /// </summary>
|
|
|
+ public record Census
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 学校ID
|
|
|
+ /// </summary>
|
|
|
+ public string id { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 学校名称
|
|
|
+ /// </summary>
|
|
|
+ public string name { get; set; }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 统计信息
|
|
|
+ /// </summary>
|
|
|
+ public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
|
|
|
+ }
|
|
|
}
|
|
|
}
|