|
@@ -11,6 +11,8 @@ using TEAMModelBI.Tool;
|
|
|
using System;
|
|
|
using System.Text;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelBI.Models;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.Census
|
|
|
{
|
|
@@ -39,7 +41,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public async Task<IActionResult> GetTypeCount(JsonElement jsonElement)
|
|
|
{
|
|
|
jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
- jsonElement.TryGetProperty("term", out JsonElement term);
|
|
|
+ if (!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
|
|
|
|
|
|
var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
|
|
@@ -49,28 +51,16 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
|
|
|
if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
- 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);
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
+ List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
|
|
|
foreach (var schoolId in schoolIds)
|
|
|
{
|
|
|
School school = new();
|
|
|
- try
|
|
|
- {
|
|
|
- school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch
|
|
|
+ var rsponse = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
|
|
|
+ if (rsponse.Status == 200)
|
|
|
{
|
|
|
+ using var json = await JsonDocument.ParseAsync(rsponse.ContentStream);
|
|
|
+ school = json.ToObject<School>();
|
|
|
}
|
|
|
|
|
|
Census tempCensus = new Census() { id = schoolId, name = school.name != null ? school.name : schoolId };
|
|
@@ -84,32 +74,8 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School", "Teacher" });
|
|
|
|
|
|
- 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);
|
|
@@ -119,39 +85,15 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
{
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School", "Teacher" });
|
|
|
|
|
|
- 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));
|
|
|
+ typeCount.Add(new KeyValuePair<string, object>(type, totals));
|
|
|
}
|
|
|
}
|
|
|
return Ok(new { state = 200, typeCount });
|
|
@@ -165,7 +107,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public async Task<IActionResult> GetLevelCount(JsonElement jsonElement)
|
|
|
{
|
|
|
jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
- jsonElement.TryGetProperty("term", out JsonElement term);
|
|
|
+ if(!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
|
|
@@ -174,27 +116,17 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
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);
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
+ schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
|
|
|
foreach (var schoolId in schoolIds)
|
|
|
{
|
|
|
School school = new();
|
|
|
- try
|
|
|
- {
|
|
|
- school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch
|
|
|
+
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
|
|
|
+ if (response.Status == 200)
|
|
|
{
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ school = json.ToObject<School>();
|
|
|
}
|
|
|
|
|
|
Census tempCensus = new Census() { id = schoolId, name = school.name != null ? school.name : schoolId };
|
|
@@ -207,32 +139,8 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School", "Teacher" });
|
|
|
|
|
|
- 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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
tempCensus.census.Add(new KeyValuePair<object, long>(i, totals));
|
|
|
}
|
|
|
levelCount.Add(tempCensus);
|
|
@@ -240,41 +148,15 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
}
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ long total = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School", "Teacher" });
|
|
|
|
|
|
levelCount.Add(new KeyValuePair<int, long>(i, total));
|
|
|
}
|
|
@@ -292,7 +174,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public async Task<IActionResult> GetLayerCount(JsonElement jsonElement)
|
|
|
{
|
|
|
jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
- jsonElement.TryGetProperty("term", out JsonElement term);
|
|
|
+ if (!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
|
|
|
|
|
|
var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
@@ -301,63 +183,31 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
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);
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
+ schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
|
|
|
foreach (var schoolId in schoolIds)
|
|
|
{
|
|
|
School school = new();
|
|
|
- try
|
|
|
- {
|
|
|
- school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
|
|
|
+ if (response.Status == 200)
|
|
|
{
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ school = json.ToObject<School>();
|
|
|
}
|
|
|
+
|
|
|
Census tempCensus = new Census() { id = schoolId, name = school.name != null ? school.name : schoolId };
|
|
|
|
|
|
for (int i = 1; i <= 6; i++)
|
|
|
{
|
|
|
- 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)
|
|
|
{
|
|
|
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));
|
|
|
+ long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School", "Teacher" });
|
|
|
+
|
|
|
+ tempCensus.census.Add(new KeyValuePair<object, long>(i, totals));
|
|
|
}
|
|
|
|
|
|
layerCount.Add(tempCensus);
|
|
@@ -367,38 +217,13 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
{
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School", "Teacher" });
|
|
|
|
|
|
layerCount.Add(new KeyValuePair<object, long>(i, totals));
|
|
|
}
|