|
@@ -1,4 +1,5 @@
|
|
using Azure.Cosmos;
|
|
using Azure.Cosmos;
|
|
|
|
+using DocumentFormat.OpenXml.Bibliography;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.Extensions.Options;
|
|
@@ -489,7 +490,8 @@ namespace TEAMModelBI.Controllers.Census
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 学校统计
|
|
|
|
|
|
+ /// 学校统计
|
|
|
|
+ /// 新的数据结构
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
@@ -578,18 +580,21 @@ namespace TEAMModelBI.Controllers.Census
|
|
scStats.actStats.term = statsInfo.activity.term;
|
|
scStats.actStats.term = statsInfo.activity.term;
|
|
scStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear ,dateTime.Year,dateTime.Month);
|
|
scStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear ,dateTime.Year,dateTime.Month);
|
|
scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
|
|
scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
|
|
- scStats.srStats.learnTime = statsInfo.study.learnTime;
|
|
|
|
- scStats.srStats.onlineTime = statsInfo.study.onlineTime;
|
|
|
|
- scStats.srStats.offlineTime = statsInfo.study.offlineTime;
|
|
|
|
- scStats.srStats.classTime = statsInfo.study.classTime;
|
|
|
|
- scStats.srStats.currency = statsInfo.study.currency;
|
|
|
|
- scStats.srStats.notStarted = statsInfo.study.notStarted;
|
|
|
|
- scStats.srStats.ongoing = statsInfo.study.ongoing;
|
|
|
|
- scStats.srStats.finish = statsInfo.study.finish;
|
|
|
|
|
|
+ if (statsInfo.study != null)
|
|
|
|
+ {
|
|
|
|
+ scStats.srStats.learnTime = statsInfo.study.learnTime;
|
|
|
|
+ scStats.srStats.online = statsInfo.study.online;
|
|
|
|
+ scStats.srStats.offline = statsInfo.study.offline;
|
|
|
|
+ scStats.srStats.classRoom = statsInfo.study.classRoom;
|
|
|
|
+ scStats.srStats.submit = statsInfo.study.submit;
|
|
|
|
+ scStats.srStats.notStarted = statsInfo.study.notStarted;
|
|
|
|
+ scStats.srStats.ongoing = statsInfo.study.ongoing;
|
|
|
|
+ scStats.srStats.finish = statsInfo.study.finish;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if(statsInfo.upTime > 0 && !isnew) {
|
|
if(statsInfo.upTime > 0 && !isnew) {
|
|
- long timedis = 15 * 60 * 1000;//15分钟
|
|
|
|
|
|
+ long timedis = 20 * 60 * 1000;//20分钟
|
|
if (now - statsInfo.upTime < timedis)
|
|
if (now - statsInfo.upTime < timedis)
|
|
isnew = true;
|
|
isnew = true;
|
|
}
|
|
}
|
|
@@ -599,10 +604,11 @@ namespace TEAMModelBI.Controllers.Census
|
|
statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
|
|
statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
|
|
if (!isnew)
|
|
if (!isnew)
|
|
{
|
|
{
|
|
- //Function 处理
|
|
|
|
|
|
+ //Function 处理Function 更新或者新增
|
|
//_ = _httpTrigger.RequestHttpTrigger(new { schoolId = $"{school.id}"}, _option.Location, "stats-sc-info");
|
|
//_ = _httpTrigger.RequestHttpTrigger(new { schoolId = $"{school.id}"}, _option.Location, "stats-sc-info");
|
|
- //异步方法处理
|
|
|
|
- statsInfo = await SchoolStatsWay.upSingleSc(cosmosClient, school.id);
|
|
|
|
|
|
+
|
|
|
|
+ //异步方法处理 同步更新
|
|
|
|
+ statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, school.id);
|
|
|
|
|
|
statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
if (isExist)
|
|
if (isExist)
|
|
@@ -620,6 +626,62 @@ namespace TEAMModelBI.Controllers.Census
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 区域统计
|
|
|
|
+ /// 新的数据结构
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-areastats")]
|
|
|
|
+ public async Task<IActionResult> GetAreaStats(JsonElement jsonElement)
|
|
|
|
+ {
|
|
|
|
+ if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
|
|
|
|
+
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+
|
|
|
|
+ Area area = new();
|
|
|
|
+ ScStats areaScStats = new();
|
|
|
|
+
|
|
|
|
+ var respSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{areaId}", new PartitionKey($"Base-Area"));
|
|
|
|
+ if (respSc.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
|
|
|
|
+ area = fileJson.ToObject<Area>();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{areaId};相关的学区,请检查!" });
|
|
|
|
+
|
|
|
|
+ List<string> scIds = new();
|
|
|
|
+ //scIds.Contains
|
|
|
|
+ string scSql = $"select value(c.id) from c where c.areaId='{areaId}'";
|
|
|
|
+
|
|
|
|
+ scIds = await CommonFind.FindScIds(cosmosClient, scSql, "Base");
|
|
|
|
+
|
|
|
|
+ //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<string>(queryText: scSql,requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")} ))
|
|
|
|
+ //{
|
|
|
|
+ // scIds.Add(item);
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ StringBuilder statsSql = new("select value(c) from c");
|
|
|
|
+ if (scIds.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ statsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds)}");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<ScStats> scStats = new();
|
|
|
|
+ List<StatsInfo> statsInfos = new();
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryIterator<StatsInfo>(queryText:statsSql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Stats") }))
|
|
|
|
+ {
|
|
|
|
+ statsInfos.Add(item);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StatsInfo statsInfo = new();
|
|
|
|
+ statsInfo = await SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds);
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = RespondCode.Ok ,area, statsInfo, scIds });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 依据Id查询School容器 数据管理工具——查询工具
|
|
/// 依据Id查询School容器 数据管理工具——查询工具
|
|
@@ -678,10 +740,10 @@ namespace TEAMModelBI.Controllers.Census
|
|
public int size { get; set; }
|
|
public int size { get; set; }
|
|
public long scCreateTime { get; set; }
|
|
public long scCreateTime { get; set; }
|
|
public long upTime { get; set; }
|
|
public long upTime { get; set; }
|
|
- public ScLessStats lessStats { get; set; }
|
|
|
|
- public ScActStats actStats { get; set; }
|
|
|
|
|
|
+ public ScLessStats lessStats { get; set; } = new ScLessStats();
|
|
|
|
+ public ScActStats actStats { get; set; } = new ScActStats();
|
|
|
|
|
|
- public ScSRStats srStats { get; set; }
|
|
|
|
|
|
+ public ScSRStats srStats { get; set; } = new ScSRStats();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -734,10 +796,10 @@ namespace TEAMModelBI.Controllers.Census
|
|
public record ScSRStats
|
|
public record ScSRStats
|
|
{
|
|
{
|
|
public int learnTime { get; set; }
|
|
public int learnTime { get; set; }
|
|
- public int onlineTime { get; set; }
|
|
|
|
- public int offlineTime { get; set; }
|
|
|
|
- public int classTime { get; set; }
|
|
|
|
- public int currency { get; set; }
|
|
|
|
|
|
+ public int online { get; set; }
|
|
|
|
+ public int offline { get; set; }
|
|
|
|
+ public int classRoom { get; set; }
|
|
|
|
+ public int submit { get; set; }
|
|
public int notStarted { get; set; }
|
|
public int notStarted { get; set; }
|
|
public int ongoing { get; set; }
|
|
public int ongoing { get; set; }
|
|
public int finish { get; set; }
|
|
public int finish { get; set; }
|