|
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelBI.Models;
|
|
@@ -26,7 +27,6 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly Option _option;
|
|
|
|
|
|
-
|
|
|
public PaperController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
@@ -44,8 +44,12 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
public async Task<IActionResult> GetCount(JsonElement jsonElement)
|
|
|
{
|
|
|
jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ if(!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
|
|
|
+ var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
- object total = new object();
|
|
|
+ object paperCount = new object();
|
|
|
+
|
|
|
+ StringBuilder sqlTxt = new StringBuilder("select count(c.id) AS totals from c");
|
|
|
|
|
|
if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
@@ -62,6 +66,10 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
schoolIds.Add(obj.GetProperty("schoolId").GetString());
|
|
|
}
|
|
|
}
|
|
|
+ if (bool.Parse($"{term}") == true)
|
|
|
+ {
|
|
|
+ sqlTxt.Append($" where c.createTime >={start} and c.createTime <={end}");
|
|
|
+ }
|
|
|
|
|
|
foreach (var schoolId in schoolIds)
|
|
|
{
|
|
@@ -76,35 +84,46 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
}
|
|
|
schoolPaper.name = school != null ? school.name : schoolId;
|
|
|
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator($"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}") }))
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText:sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt64() > 0)
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
|
|
|
{
|
|
|
- schoolPaper.total += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ schoolPaper.total += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
schoolPapers.Add(schoolPaper);
|
|
|
}
|
|
|
|
|
|
- total = schoolPapers;
|
|
|
+ paperCount = schoolPapers;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
long tempTotal = 0;
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.pk='Paper'", requestOptions: new QueryRequestOptions() { }))
|
|
|
+ sqlTxt.Append(" where c.pk='Paper' ");
|
|
|
+ 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)
|
|
|
{
|
|
|
- tempTotal += count.GetInt64();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ tempTotal += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- total = tempTotal;
|
|
|
+ paperCount = tempTotal;
|
|
|
}
|
|
|
|
|
|
- return Ok(new { state = 200 , total });
|
|
|
+ return Ok(new { state = 200 , paperCount });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -200,7 +219,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
List<MonthStartEnd> endList1 = DateTimeHeloer.GetYearMonthlyStartEnd13(DateTimeOffset.UtcNow.Year);
|
|
|
if (string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
- Dictionary<string, long> yearCount = new Dictionary<string, long>();
|
|
|
+ Dictionary<string, long> schoolYears = new Dictionary<string, long>();
|
|
|
foreach (var temp in endList1)
|
|
|
{
|
|
|
long total = 0;
|
|
@@ -229,10 +248,10 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- yearCount.Add(temp.yearMonth, total);
|
|
|
+ schoolYears.Add(temp.yearMonth, total);
|
|
|
}
|
|
|
|
|
|
- return Ok(new { state = 200, yearCount });
|
|
|
+ return Ok(new { state = 200, schoolYears });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -295,14 +314,93 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
}
|
|
|
schoolYear.yearPaper = yearCount;
|
|
|
schoolYears.Add(schoolYear);
|
|
|
-
|
|
|
}
|
|
|
return Ok(new { state = 200, schoolYears });
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 统计当前学期的数量,传醍摩豆则统计该账户相关的学校试题统计,不传则统计当前学期的试卷
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("get-termpaper")]
|
|
|
+ public async Task<IActionResult> GetTermPaper(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var (start, end) = DateTimeHeloer.GetTermStartOrEnd(DateTime.Now);
|
|
|
+
|
|
|
+ var total = new object();
|
|
|
+ if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
+ {
|
|
|
+ List<string> schoolIds = new List<string>();
|
|
|
+ List<SchoolPaper> schoolPapers = new List<SchoolPaper>();
|
|
|
+
|
|
|
+ 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: 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var schoolId in schoolIds)
|
|
|
+ {
|
|
|
+ SchoolPaper schoolPaper = new SchoolPaper() { id = schoolId };
|
|
|
+ School school = new();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ schoolPaper.name = school != null ? school.name : schoolId;
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator($"select count(c.id) AS totals from c where c.createTime >={start} and c.createTime <={end}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}") }))
|
|
|
+ {
|
|
|
+ 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())
|
|
|
+ {
|
|
|
+ schoolPaper.total += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ //schoolPaper.total += count.GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ schoolPapers.Add(schoolPaper);
|
|
|
+ }
|
|
|
+
|
|
|
+ total = schoolPapers;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long tempTotal = 0;
|
|
|
+ string sqlTxt = $"SELECT COUNT(c.id) AS totals FROM c where c.pk='Paper' and c.createTime >= {start} and c.createTime <= {end}";
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, 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 += obj.GetProperty("totals").GetInt64();
|
|
|
+ tempTotal += obj.GetProperty("totals").GetInt64();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ total = tempTotal;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = 200, total });
|
|
|
+ }
|
|
|
|
|
|
public record SchoolPaper
|
|
|
{
|