|
@@ -26,6 +26,7 @@ using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
|
|
|
using TEAMModelOS.SDK.Models.Service.BI;
|
|
|
using TEAMModelOS.SDK.Models.Service.BIStatsWay;
|
|
|
using static TEAMModelBI.Controllers.Census.SchoolController;
|
|
|
+using LessonStats = TEAMModelOS.SDK.Models.Cosmos.BI.LessonStats;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.Census
|
|
|
{
|
|
@@ -538,6 +539,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
if (!string.IsNullOrEmpty(statsInfo.id))
|
|
|
{
|
|
|
scStats.id = statsInfo.id;
|
|
|
+ scStats.schoolId = statsInfo.schoolId;
|
|
|
scStats.name = statsInfo.name;
|
|
|
scStats.picture = statsInfo.picture;
|
|
|
scStats.areaId = statsInfo.areaId;
|
|
@@ -569,7 +571,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
|
|
|
scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
|
|
|
scStats.lessStats.yearInter = statsInfo.lesson.yearInter;
|
|
|
- //scStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
|
|
|
+ scStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
|
|
|
scStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
|
|
|
scStats.actStats.all = statsInfo.activity.all;
|
|
|
scStats.actStats.exam = statsInfo.activity.exam;
|
|
@@ -640,25 +642,52 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
[HttpPost("get-areastats")]
|
|
|
public async Task<IActionResult> GetAreaStats(JsonElement jsonElement)
|
|
|
{
|
|
|
- if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("areaId", out JsonElement areaId);
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ jsonElement.TryGetProperty("role", out JsonElement role);
|
|
|
|
|
|
- var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ if (string.IsNullOrEmpty($"{areaId}") && string.IsNullOrEmpty($"{tmdId}"))
|
|
|
+ return Ok(new { stats = RespondCode.ParamsError, msg = "areaId/tmdId两者参数不能都为空!" });
|
|
|
|
|
|
- Area area = new();
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ Area area = null;
|
|
|
ScStats areaScStats = new();
|
|
|
+ List<string> scIds = new();
|
|
|
|
|
|
- var respSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{areaId}", new PartitionKey($"Base-Area"));
|
|
|
- if (respSc.Status == 200)
|
|
|
+ StringBuilder scSql = new("select value(c.id) from c");
|
|
|
+ StringBuilder lastScSql = new("select value(c.id) from c");
|
|
|
+ if (!string.IsNullOrEmpty($"{areaId}"))
|
|
|
{
|
|
|
- using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
|
|
|
- area = fileJson.ToObject<Area>();
|
|
|
+ scSql.Append($" where c.areaId='{areaId}'");
|
|
|
+ lastScSql.Append($" where c.areaId='{areaId}'");
|
|
|
+ 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};相关的学区,请检查!" });
|
|
|
}
|
|
|
- else
|
|
|
- return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{areaId};相关的学区,请检查!" });
|
|
|
|
|
|
- List<string> scIds = new();
|
|
|
- string scSql = $"select value(c.id) from c where c.areaId='{areaId}'";
|
|
|
- scIds = await CommonFind.FindScIds(cosmosClient, scSql, "Base");
|
|
|
+ if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
+ {
|
|
|
+ switch ($"{role}")
|
|
|
+ {
|
|
|
+ case "assists":
|
|
|
+ scSql.Append($" join a in c.assists where a.id='{tmdId}'");
|
|
|
+ lastScSql.Append($" join a in c.assists where a.id='{tmdId}'");
|
|
|
+ break;
|
|
|
+ case "sales":
|
|
|
+ scSql.Append($" join a in c.sales where a.id='{tmdId}'");
|
|
|
+ lastScSql.Append($" join a in c.sales where a.id='{tmdId}'");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return Ok(new { state = RespondCode.ParamsError, msg = "role参数错误" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ scIds = await CommonFind.FindScIds(cosmosClient, scSql.ToString(), "BIRel");
|
|
|
StringBuilder statsSql = new("select value(c) from c");
|
|
|
if (scIds.Count > 0)
|
|
|
{
|
|
@@ -673,11 +702,24 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
statsInfos.Add(item);
|
|
|
}
|
|
|
|
|
|
- StatsInfo statsInfo = new();
|
|
|
+ StringBuilder lastStsSql = new("select c.lesson,c.activity from c");
|
|
|
+ if (scIds.Count > 0)
|
|
|
+ {
|
|
|
+ lastStsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds, $"{DateTimeOffset.UtcNow.Year - 1}-")}");
|
|
|
+ }
|
|
|
+ List<LastYearLessAndAct> lastYear = new();
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LastYearLessAndAct>(queryText: lastStsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
|
|
|
+ {
|
|
|
+ lastYear.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ StatsInfo statsInfo = null;
|
|
|
statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds, area);
|
|
|
- if (!string.IsNullOrEmpty(statsInfo.id))
|
|
|
+ if (statsInfo != null)
|
|
|
{
|
|
|
areaScStats.id = statsInfo.id;
|
|
|
+ areaScStats.schoolId = statsInfo.schoolId;
|
|
|
areaScStats.name = statsInfo.name;
|
|
|
areaScStats.picture = statsInfo.picture;
|
|
|
areaScStats.areaId = statsInfo.areaId;
|
|
@@ -709,7 +751,8 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
|
|
|
areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
|
|
|
areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
|
|
|
- //areaScStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
|
|
|
+ areaScStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
|
|
|
+ areaScStats.lessStats.LastYear = TimeHelper.GetYearMonth(BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()), dateTime.Year, dateTime.Month);
|
|
|
areaScStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
|
|
|
areaScStats.actStats.all = statsInfo.activity.all;
|
|
|
areaScStats.actStats.exam = statsInfo.activity.exam;
|
|
@@ -722,7 +765,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
areaScStats.actStats.week = statsInfo.activity.week;
|
|
|
areaScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
|
|
|
areaScStats.actStats.term = statsInfo.activity.term;
|
|
|
- //areaScStats.actStats.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear, dateTime.Year, dateTime.Month);
|
|
|
+ areaScStats.actStats.LastYear = TimeHelper.GetYearMonth(BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()), dateTime.Year, dateTime.Month);
|
|
|
areaScStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
|
|
|
if (statsInfo.study != null)
|
|
|
{
|
|
@@ -828,6 +871,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public record ScStats
|
|
|
{
|
|
|
public string id { get; set; }
|
|
|
+ public string schoolId { get; set; }
|
|
|
public string name { get; set; }
|
|
|
public string picture { get; set; }
|
|
|
public string areaId { get; set; }
|
|
@@ -871,7 +915,7 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public int monthInter { get; set; }
|
|
|
public int lastYearInter { get; set; }
|
|
|
public int yearInter { get; set; }
|
|
|
- //public List<YearMonth> yearInter { get; set; } = new List<YearMonth>();//12个月
|
|
|
+ public List<YearMonth> yearInters { get; set; } = new List<YearMonth>();//12个月
|
|
|
public List<YearMonth> LastYear { get; set; } = new List<YearMonth>();//12个月
|
|
|
public List<YearMonth> year { get; set; } = new List<YearMonth>(); //12个月
|
|
|
}
|
|
@@ -911,5 +955,20 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public int finish { get; set; }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 查询去年的统计
|
|
|
+ /// </summary>
|
|
|
+ public record LastYearLessAndAct
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 课例活动
|
|
|
+ /// </summary>
|
|
|
+ public LessonStats lesson { get; set; } = new LessonStats();
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 活动
|
|
|
+ /// </summary>
|
|
|
+ public ActivityStats activity { get; set; } = new ActivityStats();
|
|
|
+ }
|
|
|
}
|
|
|
}
|