|
@@ -29,7 +29,7 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
/// <param name="expire">到期时间</param>
|
|
|
/// <param name="region">上次登录地址</param>
|
|
|
/// <returns></returns>
|
|
|
- public static async Task<List<LoginInfo>> DoLoginInfo(List<LoginInfo> loginInfos, string school, string scope, string id, string ip, AzureRedisFactory _azureRedis, AzureStorageFactory _azureStorage, CosmosClient client ,int expire =1, string region = null)
|
|
|
+ public static async Task<List<LoginInfo>> DoLoginInfo(List<LoginInfo> loginInfos, string school, string scope, string id, string ip, AzureRedisFactory _azureRedis, AzureStorageFactory _azureStorage, int expire = 1, string region = null)
|
|
|
{
|
|
|
var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
|
|
|
DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
@@ -55,35 +55,130 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
}
|
|
|
else
|
|
|
loginInfos = new List<LoginInfo> { new LoginInfo { expire = Expire, ip = ip, time = now } };
|
|
|
-
|
|
|
+
|
|
|
+ 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}");
|
|
|
+ //List<dynamic> dayCounts = new();
|
|
|
+ //if (dayCnt != null && dayCnt.Length > 0)
|
|
|
+ //{
|
|
|
+ // foreach (var hourCnt in dayCnt)
|
|
|
+ // {
|
|
|
+ // dayCounts.Add(new { code = hourCnt.Element.ToString(), count = (int)hourCnt.Score });
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //var monthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateMonth}");
|
|
|
+ //List<dynamic> monthCounts = new();
|
|
|
+ //if (monthCnt != null && monthCnt.Length > 0)
|
|
|
+ //{
|
|
|
+ // foreach (var mCnt in monthCnt)
|
|
|
+ // {
|
|
|
+ // monthCounts.Add(new { code = mCnt.Element.ToString(), count = (int)mCnt.Score });
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //保存当天没小时的峰值
|
|
|
+ HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = now.ToString(), Hour = int.Parse(dateHour) };
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ {
|
|
|
+ hourLogin.Teacher = int.Parse(id);
|
|
|
+ hourLogin.Student = 0;
|
|
|
+ hourLogin.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ {
|
|
|
+ hourLogin.Teacher = 0;
|
|
|
+ hourLogin.Student = int.Parse(id);
|
|
|
+ hourLogin.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hourLogin.Teacher = 0;
|
|
|
+ hourLogin.Student = 0;
|
|
|
+ hourLogin.TmdUser = int.Parse(id);
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await table.SaveOrUpdate<HourLogin>(hourLogin);//保存在线数据
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存当月每天的峰值
|
|
|
+ DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = now.ToString(), Day = int.Parse(dateDay) };
|
|
|
+ if (scope.Equals("teacher"))
|
|
|
+ {
|
|
|
+ dayLogin.Teacher = int.Parse(id);
|
|
|
+ dayLogin.Student = 0;
|
|
|
+ dayLogin.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else if (scope.Equals("student"))
|
|
|
+ {
|
|
|
+ dayLogin.Teacher = 0;
|
|
|
+ dayLogin.Student = int.Parse(id);
|
|
|
+ dayLogin.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dayLogin.Teacher = 0;
|
|
|
+ dayLogin.Student = 0;
|
|
|
+ dayLogin.TmdUser = int.Parse(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ await table.SaveOrUpdate<DayLogin>(dayLogin);//保存在线数据
|
|
|
+
|
|
|
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 resDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
- if (resDay == null)
|
|
|
+ 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 rspMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
- if (rspMonth != null)
|
|
|
+ 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 scDay = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
- List<dynamic> scDayCount = new();
|
|
|
- if (scDay != null && scDay.Length > 0)
|
|
|
- {
|
|
|
- foreach (var count in scDay)
|
|
|
- {
|
|
|
- scDayCount.Add(new { code = count.Element.ToString(), count = (int)count.Score });
|
|
|
- }
|
|
|
- }
|
|
|
+ ////查询Redis是否有值
|
|
|
+ //var scDayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateDay}");
|
|
|
+ //List<dynamic> scDayCounts = new();
|
|
|
+ //if (scDayCnt != null && scDayCnt.Length > 0)
|
|
|
+ //{
|
|
|
+ // foreach (var itemHour in scDayCnt)
|
|
|
+ // {
|
|
|
+ // scDayCounts.Add(new { code = itemHour.Element.ToString(), count = (int)itemHour.Score });
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //var ScMonth = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
+ //List<dynamic> scMonthCount = new();
|
|
|
+ //if (ScMonth != null && ScMonth.Length > 0)
|
|
|
+ //{
|
|
|
+ // foreach (var count in ScMonth)
|
|
|
+ // {
|
|
|
+ // scMonthCount.Add(new { code = count.Element.ToString(), count = (int)count.Score });
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
//学校小时峰值
|
|
|
HourLoginSchool hourLoginSc = new() { PartitionKey = $"HourLogin-{school}", RowKey = now.ToString(), Hour = int.Parse(dateHour), School = school };
|
|
@@ -91,11 +186,19 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
hourLoginSc.Teacher = int.Parse(id);
|
|
|
hourLoginSc.Student = 0;
|
|
|
+ hourLoginSc.TmdUser = 0;
|
|
|
}
|
|
|
else if (scope.Equals("student"))
|
|
|
{
|
|
|
hourLoginSc.Teacher = 0;
|
|
|
hourLoginSc.Student = int.Parse(id);
|
|
|
+ hourLoginSc.TmdUser = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hourLoginSc.Teacher = 0;
|
|
|
+ hourLoginSc.Student = 0;
|
|
|
+ hourLoginSc.TmdUser = int.Parse(id);
|
|
|
}
|
|
|
|
|
|
try
|
|
@@ -106,126 +209,34 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- var ScMonth = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateMonth}");
|
|
|
- List<dynamic> scMonthCount = new();
|
|
|
- if (ScMonth != null && ScMonth.Length > 0)
|
|
|
- {
|
|
|
- foreach (var count in ScMonth)
|
|
|
- {
|
|
|
- scMonthCount.Add(new { code = count.Element.ToString(), count = (int)count.Score });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
//学校天峰值
|
|
|
DayLoginSchool dayLoginSc = new() { PartitionKey = $"DayLogin-{school}", RowKey = now.ToString(), Day = int.Parse(dateDay), School = school };
|
|
|
if (scope.Equals("teacher"))
|
|
|
{
|
|
|
dayLoginSc.Teacher = int.Parse(id);
|
|
|
dayLoginSc.Student = 0;
|
|
|
+ dayLoginSc.TmdUser = 0;
|
|
|
}
|
|
|
else if (scope.Equals("student"))
|
|
|
{
|
|
|
dayLoginSc.Teacher = 0;
|
|
|
dayLoginSc.Student = int.Parse(id);
|
|
|
- }
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- await table.SaveOrUpdate<DayLoginSchool>(dayLoginSc);//保存在线数据
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- 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); //设置到期时间
|
|
|
- }
|
|
|
-
|
|
|
- var scDay = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateDay}");
|
|
|
- List<dynamic> scDayCount = new();
|
|
|
- if (scDay != null && scDay.Length > 0)
|
|
|
- {
|
|
|
- foreach (var count in scDay)
|
|
|
- {
|
|
|
- scDayCount.Add(new { code = count.Element.ToString(), count = (int)count.Score });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var ScMonth = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateMonth}");
|
|
|
- List<dynamic> scMonthCount = new();
|
|
|
- if (ScMonth != null && ScMonth.Length > 0)
|
|
|
- {
|
|
|
- foreach (var count in ScMonth)
|
|
|
- {
|
|
|
- scMonthCount.Add(new { code = count.Element.ToString(), count = (int)count.Score });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //个人或者TMDuser小时峰值
|
|
|
- HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = now.ToString(), Hour = int.Parse(dateHour) };
|
|
|
- if (scope.Equals("teacher"))
|
|
|
- {
|
|
|
- hourLogin.Teacher = int.Parse(id);
|
|
|
- hourLogin.Student = 0;
|
|
|
- hourLogin.TmdUser = 0;
|
|
|
- }
|
|
|
- else if (scope.Equals("student"))
|
|
|
- {
|
|
|
- hourLogin.Teacher = 0;
|
|
|
- hourLogin.Student = int.Parse(id);
|
|
|
- hourLogin.TmdUser = 0;
|
|
|
+ dayLoginSc.TmdUser = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- hourLogin.Teacher = 0;
|
|
|
- hourLogin.Student = 0;
|
|
|
- hourLogin.TmdUser = int.Parse(id);
|
|
|
+ dayLoginSc.Teacher = 0;
|
|
|
+ dayLoginSc.Student = 0;
|
|
|
+ dayLoginSc.TmdUser = int.Parse(id);
|
|
|
}
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
- await table.SaveOrUpdate<HourLogin>(hourLogin);//保存在线数据
|
|
|
-
|
|
|
+ await table.SaveOrUpdate<DayLoginSchool>(dayLoginSc);//保存在线数据
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
- //个人或者TMDuser天峰值
|
|
|
- DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = now.ToString(), Day = int.Parse(dateDay) };
|
|
|
- if (scope.Equals("teacher"))
|
|
|
- {
|
|
|
- dayLogin.Teacher = int.Parse(id);
|
|
|
- dayLogin.Student = 0;
|
|
|
- dayLogin.TmdUser = 0;
|
|
|
- }
|
|
|
- else if (scope.Equals("student"))
|
|
|
- {
|
|
|
- dayLogin.Teacher = 0;
|
|
|
- dayLogin.Student = int.Parse(id);
|
|
|
- dayLogin.TmdUser = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dayLogin.Teacher = 0;
|
|
|
- dayLogin.Student = 0;
|
|
|
- dayLogin.TmdUser = int.Parse(id);
|
|
|
- }
|
|
|
-
|
|
|
- await table.SaveOrUpdate<DayLogin>(dayLogin);//保存在线数据
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return loginInfos;
|