|
@@ -1,5 +1,6 @@
|
|
using Azure.Cosmos;
|
|
using Azure.Cosmos;
|
|
using HTEXLib.COMM.Helpers;
|
|
using HTEXLib.COMM.Helpers;
|
|
|
|
+using MathNet.Numerics.LinearAlgebra;
|
|
using MathNet.Numerics.LinearAlgebra.Double;
|
|
using MathNet.Numerics.LinearAlgebra.Double;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
@@ -29,6 +30,7 @@ using TEAMModelOS.SDK.Models;
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
|
|
+using TEAMModelOS.SDK.Models.Service.BI;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BISchool
|
|
namespace TEAMModelBI.Controllers.BISchool
|
|
{
|
|
{
|
|
@@ -1516,6 +1518,220 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
return Ok(new { state = 200, gradeCnt, subCnt, weekTrend });
|
|
return Ok(new { state = 200, gradeCnt, subCnt, weekTrend });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 顾问学校基础统计、以及排行
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-assisscbase")]
|
|
|
|
+ public async Task<IActionResult> GetAssistSchoolCnt(JsonElement jsonElement)
|
|
|
|
+ {
|
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
|
+ jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+ if ($"{site}".Equals(BIConst.Global))
|
|
|
|
+ cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow ;
|
|
|
|
+
|
|
|
|
+ int scAllCnt = 0; //学校
|
|
|
|
+ int tchAllCnt = 0; //教师数量
|
|
|
|
+ int tchMonthCnt = 0; //教师本月新增
|
|
|
|
+
|
|
|
|
+ int stuAllCnt = 0; //所有学校学生
|
|
|
|
+
|
|
|
|
+ int lessAllCnt = 0; //课例总数
|
|
|
|
+ int lessMthCnt = 0; //本月新增
|
|
|
|
+
|
|
|
|
+ List<ScRankCnt> scRankCnts = new(); //学校开课、上传, 课例排名
|
|
|
|
+
|
|
|
|
+ var (start, end) = TimeHelper.GetStartOrEnd(dateTime, "month");
|
|
|
|
+
|
|
|
|
+ List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
|
+
|
|
|
|
+ string scIdSql = BICommonWay.ManyScSql("schoolId", schoolIds);
|
|
|
|
+ string stuSql = $"select value(count(c.id)) from c where {scIdSql}";
|
|
|
|
+ stuAllCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", stuSql);
|
|
|
|
+
|
|
|
|
+ string scSql = BICommonWay.ManyScSql("school", schoolIds);
|
|
|
|
+ string lessMoSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {scSql} and c.startTime >= {start} and c.startTime <= {end}";
|
|
|
|
+ lessMthCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessMoSql);
|
|
|
|
+
|
|
|
|
+ List<SchoolBase> scInfos = new();
|
|
|
|
+ string scInfoSql = $"select c.id,c.name,c.code,c.picture from c ";
|
|
|
|
+ scInfos = await CommonFind.GetObject<SchoolBase>(cosmosClient, "School", scInfoSql, "Base",schoolIds);
|
|
|
|
+
|
|
|
|
+ List<string> tchMonIds = new();
|
|
|
|
+ foreach (var item in scInfos)
|
|
|
|
+ {
|
|
|
|
+ ScRankCnt lessRankCnt = new() { id = item.id, name = item.name, code = item.code, picture = item.picture };
|
|
|
|
+ string tchSql = $"select value(count(c.id)) from c where array_contains(c.roles,'teacher',true) and c.createTime >= {start} and c.createTime <= {end}";
|
|
|
|
+ tchMonthCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", tchSql, $"Teacher-{item.id}");
|
|
|
|
+
|
|
|
|
+ string tchAllSql = $"select value(count(c.id)) from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'";
|
|
|
|
+ tchAllCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", tchAllSql, $"Teacher-{item.id}");
|
|
|
|
+
|
|
|
|
+ string lessALLSql = "select value(count(c.id)) from c where c.pk='LessonRecord'";
|
|
|
|
+ lessAllCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessALLSql, $"LessonRecord-{item.id}");
|
|
|
|
+
|
|
|
|
+ string lessUpSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.upload = 0";
|
|
|
|
+ lessRankCnt.openCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessMoSql, $"LessonRecord-{item.id}");
|
|
|
|
+
|
|
|
|
+ string lessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.upload = 1";
|
|
|
|
+ lessRankCnt.lessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessSql, $"LessonRecord-{item.id}");
|
|
|
|
+
|
|
|
|
+ string interactSql = $"select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
|
|
|
|
+ lessRankCnt.interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", interactSql, $"LessonRecord-{item.id}");
|
|
|
|
+
|
|
|
|
+ string actSql = $" and c.school='{item.id}'";
|
|
|
|
+ lessRankCnt.actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
|
|
|
|
+
|
|
|
|
+ scRankCnts.Add(lessRankCnt);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ scAllCnt = schoolIds.Count();
|
|
|
|
+ tchMonthCnt = tchMonIds.Distinct().Count();
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = RespondCode.Ok, scAllCnt, tchAllCnt, tchMonthCnt, stuAllCnt, lessAllCnt, lessMthCnt, scRankCnts });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 顾问所有学校一年的统计
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-assissc")]
|
|
|
|
+ public async Task<IActionResult> GetAssisSc(JsonElement jsonElement)
|
|
|
|
+ {
|
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
|
+ jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+ if ($"{site}".Equals(BIConst.Global))
|
|
|
|
+ cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
|
+
|
|
|
|
+ List <YearCnt> yearCnts = new(); //当前的课例,活动,互动统计
|
|
|
|
+
|
|
|
|
+ List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
|
+
|
|
|
|
+ string strSql = "SELECT value(count(c.id)) FROM c where c.pk='LessonRecord'";
|
|
|
|
+ string scSql = BICommonWay.ManyScSql("school", schoolIds);
|
|
|
|
+
|
|
|
|
+ List<MonthStartEnd> mthStartEnds = await TimeHelper.GetYearSataMthCtMth(DateTimeOffset.UtcNow);
|
|
|
|
+ if (mthStartEnds.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in mthStartEnds)
|
|
|
|
+ {
|
|
|
|
+ YearCnt yearCnt = new() { name = item.yearMonth };
|
|
|
|
+ string selessSql = $"{strSql} and {scSql.ToString()} and c.startTime >= { item.start} and c.startTime <= {item.end}";
|
|
|
|
+ yearCnt.lessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", selessSql);
|
|
|
|
+
|
|
|
|
+ string interactSql = $"select value(sum(c.clientInteractionAverge)) from c where c.pk='LessonRecord' and {scSql} and c.startTime >= { item.start} and c.startTime <= {item.end}";
|
|
|
|
+ yearCnt.interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", interactSql);
|
|
|
|
+
|
|
|
|
+ string mthActSql = $" and {scSql} and c.createTime >= {item.start} and c.createTime <= {item.end}";
|
|
|
|
+ yearCnt.actCnt = await ActivityWay.GetCnt(cosmosClient, mthActSql);
|
|
|
|
+
|
|
|
|
+ yearCnts.Add(yearCnt);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = RespondCode.Ok, yearCnts, });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 顾问学校统计
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-assissccnt")]
|
|
|
|
+ public async Task<IActionResult> GetAssisScCnt(JsonElement jsonElement)
|
|
|
|
+ {
|
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
|
+ jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+ if ($"{site}".Equals(BIConst.Global))
|
|
|
|
+ cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
|
+ var (days, daye) = TimeHelper.GetStartOrEnd(dateTime);
|
|
|
|
+ var (lastDays, lastDaye) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));
|
|
|
|
+ var (years, yeare) = TimeHelper.GetStartOrEnd(dateTime, "year");
|
|
|
|
+ var (lastYears, lastYeare) = TimeHelper.GetStartOrEnd(dateTime, "lastYear");
|
|
|
|
+
|
|
|
|
+ int lessAll = 0; //所以课例
|
|
|
|
+ int lessLastdayCnt = 0; //昨天的课例
|
|
|
|
+ int lessDayCnt = 0; //今天的课例
|
|
|
|
+ int lessLastYarCnt = 0; //去年的课例
|
|
|
|
+ int lessYearCnt = 0; //去年的课例
|
|
|
|
+
|
|
|
|
+ int interAll = 0; //所有互动总数
|
|
|
|
+ int lastDayInterCnt = 0; // 昨天课例互动
|
|
|
|
+ int interCnt = 0; // 今天课例互动
|
|
|
|
+ int lastYarInterCnt = 0; // 去年课例互动
|
|
|
|
+ int yearInterCnt = 0; // 今年课例互动
|
|
|
|
+
|
|
|
|
+ int actAllCnt = 0; //所有活动
|
|
|
|
+ int lastActCnt = 0; //昨天活动
|
|
|
|
+ int actCnt = 0; //今天活动
|
|
|
|
+ int lastYearActCn = 0; //去年活动
|
|
|
|
+ int yearActCn = 0; //今年活动
|
|
|
|
+
|
|
|
|
+ List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
|
+ string scSql = BICommonWay.ManyScSql("school", schoolIds);
|
|
|
|
+
|
|
|
|
+ string strSql = "SELECT value(count(c.id)) FROM c where c.pk='LessonRecord'";
|
|
|
|
+
|
|
|
|
+ //课例
|
|
|
|
+ lessAll = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{strSql} and {scSql}");
|
|
|
|
+
|
|
|
|
+ string lessLastdaySql = $"{strSql} and {scSql} and c.startTime >= { lastDays} and c.startTime <= {lastDays} ";
|
|
|
|
+ lessLastdayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastdaySql);
|
|
|
|
+
|
|
|
|
+ string lessDaySql = $"{strSql} and {scSql} and c.startTime >= { days} and c.startTime <= {daye} ";
|
|
|
|
+ lessDayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessDaySql);
|
|
|
|
+
|
|
|
|
+ string lessLastYarSql = $"{strSql} and {scSql} and c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
|
|
|
|
+ lessLastYarCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastYarSql);
|
|
|
|
+
|
|
|
|
+ string lessYearSql = $"{strSql} and {scSql} and c.startTime >= { years} and c.startTime <= {yeare} ";
|
|
|
|
+ lessYearCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessYearSql);
|
|
|
|
+
|
|
|
|
+ //课例互动
|
|
|
|
+ string strInterSql = $"select value(sum(c.clientInteractionAverge)) from c where c.pk='LessonRecord' and {scSql}";
|
|
|
|
+ interAll = await CommonFind.GetSqlValueCount(cosmosClient, "School", strInterSql);
|
|
|
|
+
|
|
|
|
+ string lastdayInterSql = $"{strInterSql} and c.startTime >= { lastDays} and c.startTime <= {lastDays} ";
|
|
|
|
+ lastDayInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastdayInterSql);
|
|
|
|
+
|
|
|
|
+ string dayInterSql = $"{strInterSql} and c.startTime >= { days} and c.startTime <= {daye} ";
|
|
|
|
+ interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", dayInterSql);
|
|
|
|
+
|
|
|
|
+ string lastYarInterSql = $"{strInterSql} and c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
|
|
|
|
+ lastYarInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastYarInterSql);
|
|
|
|
+
|
|
|
|
+ string yearInterSql = $"{strInterSql} and c.startTime >= { years} and c.startTime <= {yeare} ";
|
|
|
|
+ yearInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", yearInterSql);
|
|
|
|
+
|
|
|
|
+ //活动
|
|
|
|
+ string actAllSql = $" and {scSql} ";
|
|
|
|
+ actAllCnt = await ActivityWay.GetCnt(cosmosClient, actAllSql);
|
|
|
|
+
|
|
|
|
+ string lastActSql = $" and {scSql} and c.createTime >= {lastDays} and c.createTime <= {lastDays}";
|
|
|
|
+ lastActCnt = await ActivityWay.GetCnt(cosmosClient, lastActSql);
|
|
|
|
+
|
|
|
|
+ string actSql = $" and {scSql} and c.createTime >= {days} and c.createTime <= {daye}";
|
|
|
|
+ actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
|
|
|
|
+
|
|
|
|
+ string lastYearActSql = $" and {scSql} and c.createTime >= {lastYears} and c.createTime <= {lastYeare}";
|
|
|
|
+ lastYearActCn = await ActivityWay.GetCnt(cosmosClient, lastYearActSql);
|
|
|
|
+
|
|
|
|
+ string yearActSql = $" and {scSql} and c.createTime >= {years} and c.createTime <= {yeare}";
|
|
|
|
+ yearActCn = await ActivityWay.GetCnt(cosmosClient, yearActSql);
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = RespondCode.Ok, lessAll, lessLastdayCnt, lessDayCnt, lessLastYarCnt, lessYearCnt, interAll, lastDayInterCnt, interCnt, lastYarInterCnt, yearInterCnt, actAllCnt, lastActCnt, actCnt, lastYearActCn, yearActCn });
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 依据年级统计
|
|
/// 依据年级统计
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -1544,6 +1760,34 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
return gCount;
|
|
return gCount;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #region 顾问学校统计返回值
|
|
|
|
+
|
|
|
|
+ public record ScRankCnt : SchoolBase
|
|
|
|
+ {
|
|
|
|
+ public int openCnt { get; set; }
|
|
|
|
+ public int lessCnt { get; set; }
|
|
|
|
+ public int interCnt { get; set; }
|
|
|
|
+ public int actCnt { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public record YearCnt
|
|
|
|
+ {
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+ public int lessCnt { get; set; }
|
|
|
|
+ public int interCnt { get; set; }
|
|
|
|
+ public int actCnt { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public record SchoolBase
|
|
|
|
+ {
|
|
|
|
+ public string id { get; set; }
|
|
|
|
+ public string code { get; set; }
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+ public string picture { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
|
|
public record ApplySchool
|
|
public record ApplySchool
|
|
{
|
|
{
|