|
@@ -1,4 +1,5 @@
|
|
|
-using Azure.Cosmos;
|
|
|
+using Azure.Core;
|
|
|
+using Azure.Cosmos;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
@@ -1305,6 +1306,74 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
|
|
|
#endregion 新的统计接口
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 学校课例
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-leseoncnt")]
|
|
|
+ public async Task<IActionResult> GetLessonCnt(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ List<LessonRecord> records = new();
|
|
|
+
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
+ var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间
|
|
|
+ var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week"); //计算本周开始/结束时间
|
|
|
+ var (monthS, monthE) = TimeHelper.GetStartOrEnd(dateTime, "month"); //本月开始/结束时间
|
|
|
+
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: "select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{code}") }))
|
|
|
+ {
|
|
|
+ records.Add(item);
|
|
|
+ }
|
|
|
+ double itemCount = 0;
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT count(1) as items FROM c where c.scope = 'school' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ if (obj.TryGetProperty("items", out JsonElement items))
|
|
|
+ {
|
|
|
+ itemCount = items.GetDouble();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ double paperCount = 0;
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT count(1) as papers FROM c where c.scope = 'school' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ if (obj.TryGetProperty("papers", out JsonElement papers))
|
|
|
+ {
|
|
|
+ paperCount = papers.GetDouble();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ double resourcesCount = itemCount + paperCount; //线上资源
|
|
|
+ double attendCount = records.Select(c => c.attendCount).Sum(); //学生参加人数
|
|
|
+ double clientInteractionCount = records.Select(c => c.clientInteractionCount).Sum(); //互动总次数
|
|
|
+ double workCount = records.Select(c => c.collateCount).Sum();//课堂任务总次数
|
|
|
+ double interactionCount = records.Select(c => c.interactionCount).Sum(); //课堂提问中题数
|
|
|
+ double duration = records.Select(c => c.duration).Sum(); //课堂总时长
|
|
|
+ double dayCnt = records.Where(c => c.startTime >= dayS && c.startTime <= dayE).Count(); //今天课例数
|
|
|
+ double weekCnt = records.Where(c => c.startTime >= weekS && c.startTime <= weekE).Count(); //本周课例数
|
|
|
+ double monthCnt = records.Where(c => c.startTime >= monthS && c.startTime <= monthE).Count(); //本月课例数
|
|
|
+
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, cnt = records.Count, dayCnt, weekCnt, monthCnt, resourcesCount, attendCount, clientInteractionCount, workCount, interactionCount, duration });
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 学校信息中间件查询接口
|
|
|
/// </summary>
|