|
@@ -78,16 +78,18 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
{
|
|
|
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 表达式查询
|
|
|
|
|
|
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 表达式查询
|
|
|
+ }
|
|
|
+
|
|
|
+ //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 表达式查询 教师查询人数
|
|
|
|
|
|
return Ok(new { state = 200, areaCnt, scCnt, tchCnt, stuCnt, todayScCnt, todayTchCnt, todayStuCnt, onStuCnt, onTchCnt});
|
|
|
}
|
|
@@ -239,30 +241,81 @@ 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 = scRecLesn.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() });
|
|
|
}
|
|
|
|
|
@@ -297,6 +350,9 @@ namespace TEAMModelBI.Controllers.BIHome
|
|
|
return Ok(new { state = 200, scEdCnt });
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 记录在线人数
|
|
|
+ /// </summary>
|
|
|
public record RecOnLine
|
|
|
{
|
|
|
public string id { get; set; }
|
|
@@ -305,7 +361,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 +375,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; }
|
|
|
+ }
|
|
|
}
|
|
|
}
|