|
@@ -155,330 +155,332 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
|
|
|
/// </summary>
|
|
|
/// <param name="msg"></param>
|
|
|
/// <returns></returns>
|
|
|
- [Function("onlin-record")]
|
|
|
- public async Task<HttpResponseData> OnlinRecord([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
|
|
|
+ [Function("online-record")]
|
|
|
+ public async Task<HttpResponseData> OnlineRecord([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
|
|
|
{
|
|
|
var response = req.CreateResponse(HttpStatusCode.OK);
|
|
|
string data = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
var json = JsonDocument.Parse(data).RootElement;
|
|
|
-
|
|
|
- string school = null;
|
|
|
- string scope = null;
|
|
|
- string id = null;
|
|
|
- string ip = null;
|
|
|
- int expire = 1;
|
|
|
- if (json.TryGetProperty("school", out JsonElement _school))
|
|
|
- school = _school.GetString();
|
|
|
-
|
|
|
- if (json.TryGetProperty("scope", out JsonElement _scope))
|
|
|
- scope = _scope.GetString();
|
|
|
-
|
|
|
- if (json.TryGetProperty("id", out JsonElement _id))
|
|
|
- id = _id.GetString();
|
|
|
-
|
|
|
- if (json.TryGetProperty("ip", out JsonElement _ip))
|
|
|
- ip = _ip.GetString();
|
|
|
- if (json.TryGetProperty("expire", out JsonElement _expire))
|
|
|
- expire = _expire.GetInt32();
|
|
|
-
|
|
|
- var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
|
|
|
- var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
- DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
- var dateHour = dateTime.ToString("yyyyMMddHH"); //获取当天的小时
|
|
|
- var dateDay = dateTime.ToString("yyyyMMdd"); //获取当天的日期
|
|
|
- var dateMonth = dateTime.ToString("yyyyMM");//获取当月的日期
|
|
|
- var currentHour = dateTime.Hour; //当前小时
|
|
|
- var currentDay = dateTime.Day; //当前天
|
|
|
- long Expire = dateTime.AddHours(expire).ToUnixTimeMilliseconds(); //token到期时间
|
|
|
- long now = dateTime.ToUnixTimeMilliseconds(); //当前时间戳
|
|
|
- DateTime hour = DateTime.UtcNow.AddHours(25); //25小时到期
|
|
|
- DateTime month = DateTime.UtcNow.AddDays(32); //一个月到期
|
|
|
- var delTbHour = dateTime.AddHours(-168).ToString("yyyyMMddHH"); //168小时前
|
|
|
- var delTbDay = dateTime.AddDays(-180).ToString("yyyyMMdd"); //180天前
|
|
|
-
|
|
|
- switch (scope)
|
|
|
+ try
|
|
|
{
|
|
|
- case "teacher":
|
|
|
- try
|
|
|
- {
|
|
|
- Teacher teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
- teacher.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
- await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch { }
|
|
|
- break;
|
|
|
- case "student":
|
|
|
- try
|
|
|
- {
|
|
|
- Student student = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Student>(id, new PartitionKey($"Base-{school}"));
|
|
|
- student.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
- await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Student>(student, student.id, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch { }
|
|
|
- break;
|
|
|
- case "tmduser":
|
|
|
- try
|
|
|
- {
|
|
|
- TmdUser tmdUser = await cosmosClient.GetContainer("TEAMModelOS", "Student").ReadItemAsync<TmdUser>(id, new PartitionKey("Base"));
|
|
|
- tmdUser.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
- await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<TmdUser>(tmdUser, tmdUser.id, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch { }
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateDay}", $"{currentHour}", 1);//一天24小时
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateMonth}", $"{currentDay}", 1); //当天的累计
|
|
|
-
|
|
|
- var resDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{scope}:{dateDay}");
|
|
|
- if (resDay == null)
|
|
|
- await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:IES:{scope}:{dateDay}", hour); //设置到期时间
|
|
|
- var rspMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{scope}:{dateMonth}");
|
|
|
- if (rspMonth == null)
|
|
|
- await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:IES:{scope}:{dateMonth}", month); //设置到期时间
|
|
|
-
|
|
|
- //查询Redis是否有值
|
|
|
- var dayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateDay}");
|
|
|
- if (dayCnt != null && dayCnt.Length > 0)
|
|
|
- {
|
|
|
- List<HourLogin> hourLogins = new();
|
|
|
- foreach (var hourCnt in dayCnt)
|
|
|
+ string school = null;
|
|
|
+ string scope = null;
|
|
|
+ string id = null;
|
|
|
+ string ip = null;
|
|
|
+ int expire = 1;
|
|
|
+
|
|
|
+ if (json.TryGetProperty("school", out JsonElement _school))
|
|
|
+ school = _school.GetString();
|
|
|
+
|
|
|
+ if (json.TryGetProperty("scope", out JsonElement _scope))
|
|
|
+ scope = _scope.GetString();
|
|
|
+
|
|
|
+ if (json.TryGetProperty("id", out JsonElement _id))
|
|
|
+ id = _id.GetString();
|
|
|
+
|
|
|
+ if (json.TryGetProperty("ip", out JsonElement _ip))
|
|
|
+ ip = _ip.GetString();
|
|
|
+ if (json.TryGetProperty("expire", out JsonElement _expire))
|
|
|
+ expire = _expire.GetInt32();
|
|
|
+
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
+ var dateHour = dateTime.ToString("yyyyMMddHH"); //获取当天的小时
|
|
|
+ var dateDay = dateTime.ToString("yyyyMMdd"); //获取当天的日期
|
|
|
+ var dateMonth = dateTime.ToString("yyyyMM");//获取当月的日期
|
|
|
+ var currentHour = dateTime.Hour; //当前小时
|
|
|
+ var currentDay = dateTime.Day; //当前天
|
|
|
+ long Expire = dateTime.AddHours(expire).ToUnixTimeMilliseconds(); //token到期时间
|
|
|
+ long now = dateTime.ToUnixTimeMilliseconds(); //当前时间戳
|
|
|
+ DateTime hour = DateTime.UtcNow.AddHours(25); //25小时到期
|
|
|
+ DateTime month = DateTime.UtcNow.AddDays(32); //一个月到期
|
|
|
+ var delTbHour = dateTime.AddHours(-168).ToString("yyyyMMddHH"); //168小时前
|
|
|
+ var delTbDay = dateTime.AddDays(-180).ToString("yyyyMMdd"); //180天前
|
|
|
+
|
|
|
+ switch (scope)
|
|
|
{
|
|
|
- if (((int)hourCnt.Element) == currentHour)
|
|
|
- {
|
|
|
- var tphourLogins = await table.QueryWhereString<HourLogin>($"PartitionKey eq 'HourLogin' and RowKey eq '{dateHour}'");
|
|
|
- if (tphourLogins.Count > 0)
|
|
|
+ case "teacher":
|
|
|
+ try
|
|
|
{
|
|
|
- foreach (var hourLogin in tphourLogins)
|
|
|
- {
|
|
|
- if (scope.Equals("teacher"))
|
|
|
- hourLogin.Teacher = (int)hourCnt.Score;
|
|
|
- else if (scope.Equals("student"))
|
|
|
- hourLogin.Student = (int)hourCnt.Score;
|
|
|
- else
|
|
|
- hourLogin.TmdUser = (int)hourCnt.Score;
|
|
|
- hourLogins.Add(hourLogin);
|
|
|
- }
|
|
|
+ Teacher teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
+ teacher.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
+ await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
}
|
|
|
- else
|
|
|
+ catch { }
|
|
|
+ break;
|
|
|
+ case "student":
|
|
|
+ try
|
|
|
{
|
|
|
- HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = dateHour, Hour = currentHour };
|
|
|
- if (scope.Equals("teacher"))
|
|
|
- {
|
|
|
- hourLogin.Teacher = 1;
|
|
|
- hourLogin.Student = 0;
|
|
|
- hourLogin.TmdUser = 0;
|
|
|
- }
|
|
|
- else if (scope.Equals("student"))
|
|
|
- {
|
|
|
- hourLogin.Teacher = 0;
|
|
|
- hourLogin.Student = 1;
|
|
|
- hourLogin.TmdUser = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- hourLogin.Teacher = 0;
|
|
|
- hourLogin.Student = 0;
|
|
|
- hourLogin.TmdUser = 1;
|
|
|
- }
|
|
|
- hourLogins.Add(hourLogin);
|
|
|
+ Student student = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Student>(id, new PartitionKey($"Base-{school}"));
|
|
|
+ student.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
+ await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Student>(student, student.id, new PartitionKey("Base"));
|
|
|
}
|
|
|
- }
|
|
|
+ catch { }
|
|
|
+ break;
|
|
|
+ case "tmduser":
|
|
|
+ try
|
|
|
+ {
|
|
|
+ TmdUser tmdUser = await cosmosClient.GetContainer("TEAMModelOS", "Student").ReadItemAsync<TmdUser>(id, new PartitionKey("Base"));
|
|
|
+ tmdUser.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
+ await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<TmdUser>(tmdUser, tmdUser.id, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
- await table.SaveOrUpdateAll(hourLogins); //保存和更新保存当前小时登录次数
|
|
|
- }
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateDay}", $"{currentHour}", 1);//一天24小时 小时为单位
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateMonth}", $"{currentDay}", 1); //一天的累计 天为单位
|
|
|
|
|
|
- var monthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateMonth}");
|
|
|
- if (monthCnt != null && monthCnt.Length > 0)
|
|
|
- {
|
|
|
- List<DayLogin> dayLogins = new();
|
|
|
- foreach (var mCnt in monthCnt)
|
|
|
+ var resDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{scope}:{dateDay}");
|
|
|
+ if (resDay == null)
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:IES:{scope}:{dateDay}", hour); //设置到期时间
|
|
|
+ var rspMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{scope}:{dateMonth}");
|
|
|
+ if (rspMonth == null)
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:IES:{scope}:{dateMonth}", month); //设置到期时间
|
|
|
+
|
|
|
+ //保存当前小时统计
|
|
|
+ var dayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateDay}");
|
|
|
+ if (dayCnt != null && dayCnt.Length > 0)
|
|
|
{
|
|
|
- if (((int)mCnt.Element) == currentDay)
|
|
|
+ List<HourLogin> hourLogins = new();
|
|
|
+ foreach (var dCnt in dayCnt)
|
|
|
{
|
|
|
- //保存当天的峰值
|
|
|
- var tbDays = await table.QueryWhereString<DayLogin>($"PartitionKey eq 'DayLogin' and RowKey eq '{dateDay}'");
|
|
|
- if (tbDays.Count > 0)
|
|
|
- {
|
|
|
- foreach (var dayLogin in tbDays)
|
|
|
- {
|
|
|
- if (scope.Equals("teacher"))
|
|
|
- dayLogin.Teacher = (int)mCnt.Score;
|
|
|
- else if (scope.Equals("student"))
|
|
|
- dayLogin.Student = (int)mCnt.Score;
|
|
|
- else
|
|
|
- dayLogin.TmdUser = (int)mCnt.Score;
|
|
|
- dayLogins.Add(dayLogin);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ if (((int)dCnt.Element) == currentHour)
|
|
|
{
|
|
|
- //保存当月每天的峰值
|
|
|
- DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = dateDay, Day = currentDay };
|
|
|
- if (scope.Equals("teacher"))
|
|
|
+ var tphourLogins = await table.QueryWhereString<HourLogin>($"PartitionKey eq 'HourLogin' and RowKey eq '{dateHour}'");
|
|
|
+ if (tphourLogins.Count > 0)
|
|
|
{
|
|
|
- dayLogin.Teacher = 1;
|
|
|
- dayLogin.Student = 0;
|
|
|
- dayLogin.TmdUser = 0;
|
|
|
- }
|
|
|
- else if (scope.Equals("student"))
|
|
|
- {
|
|
|
- dayLogin.Teacher = 0;
|
|
|
- dayLogin.Student = 1;
|
|
|
- dayLogin.TmdUser = 0;
|
|
|
+ foreach (var hourLogin in tphourLogins)
|
|
|
+ {
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ hourLogin.Teacher = (int)dCnt.Score;
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ hourLogin.Student = (int)dCnt.Score;
|
|
|
+ else
|
|
|
+ hourLogin.TmdUser = (int)dCnt.Score;
|
|
|
+ hourLogins.Add(hourLogin);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dayLogin.Teacher = 0;
|
|
|
- dayLogin.Student = 0;
|
|
|
- dayLogin.TmdUser = 1;
|
|
|
+ HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = dateHour, Hour = currentHour };
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ {
|
|
|
+ hourLogin.Teacher = 1;
|
|
|
+ hourLogin.Student = 0;
|
|
|
+ hourLogin.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ {
|
|
|
+ hourLogin.Teacher = 0;
|
|
|
+ hourLogin.Student = 1;
|
|
|
+ hourLogin.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hourLogin.Teacher = 0;
|
|
|
+ hourLogin.Student = 0;
|
|
|
+ hourLogin.TmdUser = 1;
|
|
|
+ }
|
|
|
+ hourLogins.Add(hourLogin);
|
|
|
}
|
|
|
- dayLogins.Add(dayLogin);
|
|
|
}
|
|
|
}
|
|
|
+ await table.SaveOrUpdateAll(hourLogins); //保存和更新保存当前小时登录次数
|
|
|
}
|
|
|
-
|
|
|
- await table.SaveOrUpdateAll(dayLogins);// 保存当月每天在线数据
|
|
|
- }
|
|
|
-
|
|
|
- string tbHourSql = $"PartitionKey eq 'HourLogin' and RowKey le '{delTbHour}'";
|
|
|
- await table.DeleteStringWhere<BIOptLog>(rowKey: tbHourSql); //删除168小时前的数据
|
|
|
-
|
|
|
- string tbDaySql = $"PartitionKey eq 'DayLogin' and RowKey le '{delTbDay}'";
|
|
|
- await table.DeleteStringWhere<BIOptLog>(rowKey: tbDaySql); //删除180天前的数据
|
|
|
-
|
|
|
- if (!string.IsNullOrWhiteSpace(school))
|
|
|
- {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:School:{school}:{scope}:{dateDay}", $"{currentHour}", 1);//当天当前小时在线人加1
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:School:{school}:{scope}:{dateMonth}", $"{currentDay}", 1); //当天的在线加1
|
|
|
-
|
|
|
- var reScDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
- if (reScDay == null)
|
|
|
- await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateDay}", hour); //设置到期时间
|
|
|
- var reScMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
- if (reScMonth == null)
|
|
|
- await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateMonth}", month); //设置到期时间
|
|
|
-
|
|
|
- //查询Redis是否有值
|
|
|
- var scDayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
- List<dynamic> scDayCounts = new();
|
|
|
- if (scDayCnt != null && scDayCnt.Length > 0)
|
|
|
+ //保存当前的统计数据
|
|
|
+ var monthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateMonth}");
|
|
|
+ if (monthCnt != null && monthCnt.Length > 0)
|
|
|
{
|
|
|
- //保存学校当天每小时的
|
|
|
- List<HourLoginSchool> hourLoginSchools = new();
|
|
|
- foreach (var itemHour in scDayCnt)
|
|
|
+ List<DayLogin> dayLogins = new();
|
|
|
+ foreach (var mCnt in monthCnt)
|
|
|
{
|
|
|
- if (((int)itemHour.Element) == currentHour)
|
|
|
+ if (((int)mCnt.Element) == currentDay)
|
|
|
{
|
|
|
- var tmpHour = await table.QueryWhereString<HourLoginSchool>($"PartitionKey eq 'HourLogin-{school}' and RowKey eq '{dateHour}'");
|
|
|
- if (tmpHour.Count > 0)
|
|
|
+ //保存当天的峰值
|
|
|
+ var tbDays = await table.QueryWhereString<DayLogin>($"PartitionKey eq 'DayLogin' and RowKey eq '{dateDay}'");
|
|
|
+ if (tbDays.Count > 0)
|
|
|
{
|
|
|
- foreach (var hLoginSc in tmpHour)
|
|
|
+ foreach (var dayLogin in tbDays)
|
|
|
{
|
|
|
if (scope.Equals("teacher"))
|
|
|
- hLoginSc.Teacher = (int)itemHour.Score;
|
|
|
+ dayLogin.Teacher = (int)mCnt.Score;
|
|
|
else if (scope.Equals("student"))
|
|
|
- hLoginSc.Student = (int)itemHour.Score;
|
|
|
+ dayLogin.Student = (int)mCnt.Score;
|
|
|
else
|
|
|
- hLoginSc.TmdUser = (int)itemHour.Score;
|
|
|
- hourLoginSchools.Add(hLoginSc);
|
|
|
+ dayLogin.TmdUser = (int)mCnt.Score;
|
|
|
+ dayLogins.Add(dayLogin);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //学校小时峰值
|
|
|
- HourLoginSchool hourLoginSc = new() { PartitionKey = $"HourLogin-{school}", RowKey = dateHour, Hour = currentHour, School = school };
|
|
|
+ //保存当月每天的峰值
|
|
|
+ DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = dateDay, Day = currentDay };
|
|
|
if (scope.Equals("teacher"))
|
|
|
{
|
|
|
- hourLoginSc.Teacher = 1;
|
|
|
- hourLoginSc.Student = 0;
|
|
|
- hourLoginSc.TmdUser = 0;
|
|
|
+ dayLogin.Teacher = 1;
|
|
|
+ dayLogin.Student = 0;
|
|
|
+ dayLogin.TmdUser = 0;
|
|
|
}
|
|
|
else if (scope.Equals("student"))
|
|
|
{
|
|
|
- hourLoginSc.Teacher = 0;
|
|
|
- hourLoginSc.Student = 1;
|
|
|
- hourLoginSc.TmdUser = 0;
|
|
|
+ dayLogin.Teacher = 0;
|
|
|
+ dayLogin.Student = 1;
|
|
|
+ dayLogin.TmdUser = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- hourLoginSc.Teacher = 0;
|
|
|
- hourLoginSc.Student = 0;
|
|
|
- hourLoginSc.TmdUser = 1;
|
|
|
+ dayLogin.Teacher = 0;
|
|
|
+ dayLogin.Student = 0;
|
|
|
+ dayLogin.TmdUser = 1;
|
|
|
}
|
|
|
- hourLoginSchools.Add(hourLoginSc);
|
|
|
+ dayLogins.Add(dayLogin);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- await table.SaveOrUpdateAll(hourLoginSchools);
|
|
|
+ await table.SaveOrUpdateAll(dayLogins);// 保存当月每天在线数据
|
|
|
}
|
|
|
|
|
|
- var ScMonth = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
- if (ScMonth != null && ScMonth.Length > 0)
|
|
|
+ string tbHourSql = $"PartitionKey eq 'HourLogin' and RowKey le '{delTbHour}'";
|
|
|
+ await table.DeleteStringWhere<BIOptLog>(rowKey: tbHourSql); //删除168小时前的数据
|
|
|
+
|
|
|
+ string tbDaySql = $"PartitionKey eq 'DayLogin' and RowKey le '{delTbDay}'";
|
|
|
+ await table.DeleteStringWhere<BIOptLog>(rowKey: tbDaySql); //删除180天前的数据
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(school))
|
|
|
{
|
|
|
- //学校天峰值
|
|
|
- List<DayLoginSchool> DayLoginSchools = new();
|
|
|
- foreach (var count in ScMonth)
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:School:{school}:{scope}:{dateDay}", $"{currentHour}", 1);//当天当前小时在线人加1
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:School:{school}:{scope}:{dateMonth}", $"{currentDay}", 1); //当天的在线加1
|
|
|
+
|
|
|
+ var reScDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
+ if (reScDay == null)
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateDay}", hour); //设置到期时间
|
|
|
+ var reScMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
+ if (reScMonth == null)
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateMonth}", month); //设置到期时间
|
|
|
+
|
|
|
+ //保存学校当天每小时的
|
|
|
+ var scDayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
+ if (scDayCnt != null && scDayCnt.Length > 0)
|
|
|
{
|
|
|
- if (((int)count.Element) == currentDay)
|
|
|
+ List<HourLoginSchool> hourLoginSchools = new();
|
|
|
+ foreach (var scDCnt in scDayCnt)
|
|
|
{
|
|
|
- var tempDays = await table.QueryWhereString<DayLoginSchool>($"PartitionKey eq 'DayLogin-{school}' and RowKey eq '{dateDay}'");
|
|
|
- if (tempDays.Count > 0)
|
|
|
+ if (((int)scDCnt.Element) == currentHour)
|
|
|
{
|
|
|
- foreach (var dLoginSc in tempDays)
|
|
|
+ var tmpHour = await table.QueryWhereString<HourLoginSchool>($"PartitionKey eq 'HourLogin-{school}' and RowKey eq '{dateHour}'");
|
|
|
+ if (tmpHour.Count > 0)
|
|
|
{
|
|
|
+ foreach (var hLoginSc in tmpHour)
|
|
|
+ {
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ hLoginSc.Teacher = (int)scDCnt.Score;
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ hLoginSc.Student = (int)scDCnt.Score;
|
|
|
+ else
|
|
|
+ hLoginSc.TmdUser = (int)scDCnt.Score;
|
|
|
+ hourLoginSchools.Add(hLoginSc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //学校小时峰值
|
|
|
+ HourLoginSchool hourLoginSc = new() { PartitionKey = $"HourLogin-{school}", RowKey = dateHour, Hour = currentHour, School = school };
|
|
|
if (scope.Equals("teacher"))
|
|
|
- dLoginSc.Teacher = (int)count.Score;
|
|
|
+ {
|
|
|
+ hourLoginSc.Teacher = 1;
|
|
|
+ hourLoginSc.Student = 0;
|
|
|
+ hourLoginSc.TmdUser = 0;
|
|
|
+ }
|
|
|
else if (scope.Equals("student"))
|
|
|
- dLoginSc.Student = (int)count.Score;
|
|
|
+ {
|
|
|
+ hourLoginSc.Teacher = 0;
|
|
|
+ hourLoginSc.Student = 1;
|
|
|
+ hourLoginSc.TmdUser = 0;
|
|
|
+ }
|
|
|
else
|
|
|
- dLoginSc.TmdUser = (int)count.Score;
|
|
|
- DayLoginSchools.Add(dLoginSc);
|
|
|
+ {
|
|
|
+ hourLoginSc.Teacher = 0;
|
|
|
+ hourLoginSc.Student = 0;
|
|
|
+ hourLoginSc.TmdUser = 1;
|
|
|
+ }
|
|
|
+ hourLoginSchools.Add(hourLoginSc);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ await table.SaveOrUpdateAll(hourLoginSchools);
|
|
|
+ }
|
|
|
+ //学校天峰值
|
|
|
+ var scMonthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
+ if (scMonthCnt != null && scMonthCnt.Length > 0)
|
|
|
+ {
|
|
|
+ List<DayLoginSchool> DayLoginSchools = new();
|
|
|
+ foreach (var scMCnt in scMonthCnt)
|
|
|
+ {
|
|
|
+ if (((int)scMCnt.Element) == currentDay)
|
|
|
{
|
|
|
- //学校天峰值
|
|
|
- DayLoginSchool dayLoginSc = new() { PartitionKey = $"DayLogin-{school}", RowKey = dateDay, Day = currentDay, School = school };
|
|
|
- if (scope.Equals("teacher"))
|
|
|
- {
|
|
|
- dayLoginSc.Teacher = 1;
|
|
|
- dayLoginSc.Student = 0;
|
|
|
- dayLoginSc.TmdUser = 0;
|
|
|
- }
|
|
|
- else if (scope.Equals("student"))
|
|
|
+ var tempDays = await table.QueryWhereString<DayLoginSchool>($"PartitionKey eq 'DayLogin-{school}' and RowKey eq '{dateDay}'");
|
|
|
+ if (tempDays.Count > 0)
|
|
|
{
|
|
|
- dayLoginSc.Teacher = 0;
|
|
|
- dayLoginSc.Student = 1;
|
|
|
- dayLoginSc.TmdUser = 0;
|
|
|
+ foreach (var dLoginSc in tempDays)
|
|
|
+ {
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ dLoginSc.Teacher = (int)scMCnt.Score;
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ dLoginSc.Student = (int)scMCnt.Score;
|
|
|
+ else
|
|
|
+ dLoginSc.TmdUser = (int)scMCnt.Score;
|
|
|
+ DayLoginSchools.Add(dLoginSc);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dayLoginSc.Teacher = 0;
|
|
|
- dayLoginSc.Student = 0;
|
|
|
- dayLoginSc.TmdUser = 1;
|
|
|
- }
|
|
|
+ //学校天峰值
|
|
|
+ DayLoginSchool dayLoginSc = new() { PartitionKey = $"DayLogin-{school}", RowKey = dateDay, Day = currentDay, School = school };
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ {
|
|
|
+ dayLoginSc.Teacher = 1;
|
|
|
+ dayLoginSc.Student = 0;
|
|
|
+ dayLoginSc.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ {
|
|
|
+ dayLoginSc.Teacher = 0;
|
|
|
+ dayLoginSc.Student = 1;
|
|
|
+ dayLoginSc.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dayLoginSc.Teacher = 0;
|
|
|
+ dayLoginSc.Student = 0;
|
|
|
+ dayLoginSc.TmdUser = 1;
|
|
|
+ }
|
|
|
|
|
|
- DayLoginSchools.Add(dayLoginSc);
|
|
|
+ DayLoginSchools.Add(dayLoginSc);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ await table.SaveOrUpdateAll(DayLoginSchools);//保存学校当月在线数据
|
|
|
}
|
|
|
|
|
|
- await table.SaveOrUpdateAll(DayLoginSchools);//保存学校当月在线数据
|
|
|
- }
|
|
|
+ string tbScHourSql = $"PartitionKey eq 'HourLogin-{school}' and RowKey le '{delTbHour}'";
|
|
|
+ await table.DeleteStringWhere<BIOptLog>(rowKey: tbHourSql); //删除学校168小时前的数据
|
|
|
|
|
|
- string tbScHourSql = $"PartitionKey eq 'HourLogin-{school}' and RowKey le '{delTbHour}'";
|
|
|
- await table.DeleteStringWhere<BIOptLog>(rowKey: tbHourSql); //删除学校168小时前的数据
|
|
|
+ string tbScDaySql = $"PartitionKey eq 'DayLogin-{school}' and RowKey le '{delTbDay}'";
|
|
|
+ await table.DeleteStringWhere<BIOptLog>(rowKey: tbDaySql); //删除学校180天前的数据
|
|
|
+ }
|
|
|
|
|
|
- string tbScDaySql = $"PartitionKey eq 'DayLogin-{school}' and RowKey le '{delTbDay}'";
|
|
|
- await table.DeleteStringWhere<BIOptLog>(rowKey: tbDaySql); //删除学校180天前的数据
|
|
|
+ await response.WriteAsJsonAsync(new { data = json });
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-online-record 人数记录异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ await response.WriteAsJsonAsync(new { data = json });
|
|
|
+ return response;
|
|
|
}
|
|
|
-
|
|
|
- await response.WriteAsJsonAsync(new { data = json });
|
|
|
- return response;
|
|
|
}
|
|
|
}
|
|
|
}
|