|
@@ -73,22 +73,28 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
todayTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", addSql, "Base");
|
|
|
todayStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", addSql, "Base");
|
|
|
|
|
|
- List<RecOnLine> recStuOnLines = new();
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where c.pk='Base' and array_length(c.loginInfos) > 0 ", requestOptions:new QueryRequestOptions() { }))
|
|
|
- {
|
|
|
- recStuOnLines.Add(item);
|
|
|
- }
|
|
|
- onStuCnt = (from rs in recStuOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count(); //linq查询
|
|
|
- //onStuCnt = recStuOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count(); //lambda 表达式查询
|
|
|
+ string onStuSql = $"select value(count(c.id)) from c join t in c.loginInfos where array_length(c.loginInfos) > 0 and t.expire > {hour1}";
|
|
|
+ onTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", onStuSql, "Base");
|
|
|
+ onStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", onStuSql, "Base");
|
|
|
+
|
|
|
+ //List<RecOnLine> recStuOnLines = new();
|
|
|
+ //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where c.pk='Base' and array_length(c.loginInfos) > 0 ", requestOptions:new QueryRequestOptions() { }))
|
|
|
+ //{
|
|
|
+ // recStuOnLines.Add(item);
|
|
|
+ //}
|
|
|
+
|
|
|
+ //List<RecOnLine> recTecOnLines = new();
|
|
|
+ //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where array_length(c.loginInfos) > 0 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ //{
|
|
|
+ // recTecOnLines.Add(item);
|
|
|
+ //}
|
|
|
+
|
|
|
+ ////onStuCnt = (from rs in recStuOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count(); //linq查询 学生在线人数
|
|
|
+ //onStuCnt = recStuOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count(); //lambda 表达式查询 教师查询人数
|
|
|
+
|
|
|
+ ////onTchCnt = (from rs in recTecOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count(); //linq查询 教师查询人数
|
|
|
+ //onTchCnt = recTecOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count(); //lambda 表达式查询 教师查询人数
|
|
|
|
|
|
- List<RecOnLine> recTecOnLines = new();
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where array_length(c.loginInfos) > 0 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
- {
|
|
|
- recTecOnLines.Add(item);
|
|
|
- }
|
|
|
- onTchCnt = (from rs in recTecOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count(); //linq查询
|
|
|
- //onStuCnt = recTecOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count(); //lambda 表达式查询
|
|
|
-
|
|
|
return Ok(new { state = 200, areaCnt, scCnt, tchCnt, stuCnt, todayScCnt, todayTchCnt, todayStuCnt, onStuCnt, onTchCnt});
|
|
|
}
|
|
|
|
|
@@ -239,30 +245,80 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
Dictionary<int, int> tchLessCnt = new(); //教师课例
|
|
|
Dictionary<int, int> yesterdayCnt = new(); //昨天24小时课例
|
|
|
|
|
|
+ var (daySt, dayEt) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间 13位
|
|
|
+ var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{dateTime.Day - 1}")); //昨天开始时间
|
|
|
+
|
|
|
+ List<RecLesn> scRecLesn = new(); //学校课例
|
|
|
+ List<RecLesn> tchRecLesn = new(); //个人课例
|
|
|
+ List<RecLesn> allRecLesn = new(); //昨天所有课例
|
|
|
+ string lesnSql = $"select c.id,c.name,c.code,c.school,c.scope,c.startTime from c where c.pk='LessonRecord' and c.startTime >={daySt} and c.startTime <= {dayEt}";
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ scRecLesn.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
|
|
|
+ {
|
|
|
+ tchRecLesn.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ string allLesnSql = $"select c.id,c.name,c.code,c.school,c.scope,c.startTime from c where c.pk='LessonRecord' and c.startTime >={lastDayS} and c.startTime <= {lastdayE}";
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: allLesnSql, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ allRecLesn.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: allLesnSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
|
|
|
+ {
|
|
|
+ allRecLesn.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
for (int i = 0; i < 24; i++)
|
|
|
{
|
|
|
if (hour >= i)
|
|
|
{
|
|
|
DateTimeOffset timeHour = new DateTime(year, month, day, i, 0, 0);
|
|
|
var (hourS, hourE) = TimeHelper.GetStartOrEnd(timeHour, type: "hour");
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { }))
|
|
|
- {
|
|
|
- scLessCnt.Add(i, item);
|
|
|
- }
|
|
|
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
|
|
|
- {
|
|
|
- tchLessCnt.Add(i, item);
|
|
|
- }
|
|
|
+ var scLesn = scRecLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE).ToList();
|
|
|
+ scLessCnt.Add(i, scLesn.Count());
|
|
|
+
|
|
|
+ var tchLesn = tchRecLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE).ToList();
|
|
|
+ tchLessCnt.Add(i, tchLesn.Count());
|
|
|
}
|
|
|
|
|
|
DateTimeOffset yesterday = new DateTime(year, month, day - 1, i, 0, 0);
|
|
|
var (yHourS, yHourE) = TimeHelper.GetStartOrEnd(yesterday, type: "hour");
|
|
|
- string sql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >= {yHourS} and c.startTime <= {yHourE}";
|
|
|
- int hourLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string> { "School", "Teacher" }, sql);
|
|
|
- yesterdayCnt.Add(i, hourLessCnt);
|
|
|
+
|
|
|
+ var allLesn = allRecLesn.Where(item => item.startTime >= yHourS && item.startTime <= yHourE).ToList();
|
|
|
+ yesterdayCnt.Add(i, allLesn.Count());
|
|
|
}
|
|
|
|
|
|
+ ////通过循环实时查询课例统计
|
|
|
+ //for (int i = 0; i < 24; i++)
|
|
|
+ //{
|
|
|
+ // if (hour >= i)
|
|
|
+ // {
|
|
|
+ // DateTimeOffset timeHour = new DateTime(year, month, day, i, 0, 0);
|
|
|
+ // var (hourS, hourE) = TimeHelper.GetStartOrEnd(timeHour, type: "hour");
|
|
|
+ // await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { }))
|
|
|
+ // {
|
|
|
+ // scLessCnt.Add(i, item);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(queryText: $"select value(count(c.id)) from c where c.startTime >={hourS} and c.startTime <= {hourE}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
|
|
|
+ // {
|
|
|
+ // tchLessCnt.Add(i, item);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // DateTimeOffset yesterday = new DateTime(year, month, day - 1, i, 0, 0);
|
|
|
+ // var (yHourS, yHourE) = TimeHelper.GetStartOrEnd(yesterday, type: "hour");
|
|
|
+ // string sql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime >= {yHourS} and c.startTime <= {yHourE}";
|
|
|
+ // int hourLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string> { "School", "Teacher" }, sql);
|
|
|
+ // yesterdayCnt.Add(i, hourLessCnt);
|
|
|
+ //}
|
|
|
+
|
|
|
return Ok(new { state = 200, scLessCnt = scLessCnt.ToList(), tchLessCnt = tchLessCnt.ToList(), yesterdayCnt = yesterdayCnt.ToList() });
|
|
|
}
|
|
|
|
|
@@ -274,6 +330,10 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
public async Task<IActionResult> GetEdition()
|
|
|
{
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ int beCnt = 0; //基础班
|
|
|
+ int seCnt = 0; //标准版
|
|
|
+ int peCnt = 0; //专业版
|
|
|
+
|
|
|
List<RecScEd> scEdCnt = new();
|
|
|
var ScSql = $"select c.id,c.name,c.size,c.scale from c";
|
|
|
await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecScEd>(queryText: ScSql, requestOptions:new QueryRequestOptions() { PartitionKey= new PartitionKey("Base")}))
|
|
@@ -281,22 +341,37 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
scEdCnt.Add(item);
|
|
|
}
|
|
|
|
|
|
- scEdCnt.ForEach(async scProductCnt =>
|
|
|
+ scEdCnt.ForEach(async scProCnt =>
|
|
|
{
|
|
|
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scProductCnt.id, new PartitionKey("ProductSum"));
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scProCnt.id, new PartitionKey("ProductSum"));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
SchoolProductSum ScProductSum = json.ToObject<SchoolProductSum>();
|
|
|
- scProductCnt.serial = ScProductSum.serial.Count();
|
|
|
- scProductCnt.service = ScProductSum.service.Count();
|
|
|
- scProductCnt.hard = ScProductSum.hard.Count();
|
|
|
+ //scProCnt.serial = ScProductSum.serial.Count();
|
|
|
+ //scProCnt.service = ScProductSum.service.Count();
|
|
|
+ //scProCnt.hard = ScProductSum.hard.Count();
|
|
|
+ int pSeriCnt = ScProductSum.serial.Count();
|
|
|
+ int pServCnt = ScProductSum.service.Count();
|
|
|
+ int pHardCnt = ScProductSum.hard.Count();
|
|
|
+ scProCnt.serial = pSeriCnt;
|
|
|
+ scProCnt.service = pServCnt;
|
|
|
+ scProCnt.hard = pHardCnt;
|
|
|
+ if (scProCnt.scale >= 500 && (pSeriCnt > 0 || pServCnt > 0 || pHardCnt > 0)) peCnt += 1;
|
|
|
}
|
|
|
+
|
|
|
+ if (scProCnt.scale >= 500 && scProCnt.serial == 0 && scProCnt.service == 0 && scProCnt.hard == 0) seCnt += 1;
|
|
|
+ if (scProCnt.scale == 0) beCnt += 1;
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
|
|
|
- return Ok(new { state = 200, scEdCnt });
|
|
|
+ return Ok(new { state = 200, beCnt, seCnt, peCnt, scEdCnt });
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 记录在线人数
|
|
|
+ /// </summary>
|
|
|
public record RecOnLine
|
|
|
{
|
|
|
public string id { get; set; }
|
|
@@ -305,7 +380,10 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
public List<Teacher.LoginInfo> loginInfos { get; set; }
|
|
|
}
|
|
|
|
|
|
- public class RecScEd
|
|
|
+ /// <summary>
|
|
|
+ /// 记录学校版本信息
|
|
|
+ /// </summary>
|
|
|
+ public record RecScEd
|
|
|
{
|
|
|
public string id { get; set; }
|
|
|
public string name { get; set; }
|
|
@@ -316,6 +394,17 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
public int hard { get; set; } = 0; //硬体
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 记录课例
|
|
|
+ /// </summary>
|
|
|
+ public record RecLesn
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public string code { get; set; }
|
|
|
+ public string school { get; set; }
|
|
|
+ public string scope{get;set;}
|
|
|
+ public long startTime { get; set; }
|
|
|
+ }
|
|
|
}
|
|
|
}
|