Преглед изворни кода

优化登录人数记录信息方法

Li пре 3 година
родитељ
комит
667b35177d
1 измењених фајлова са 265 додато и 270 уклоњено
  1. 265 270
      TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

+ 265 - 270
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -155,370 +155,365 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
         /// <param name="msg"></param>
         /// <returns></returns>
         [Function("onlin-record")]
-        public async Task OnlinRecord([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
+        public async Task<HttpResponseData> OnlinRecord([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
         {
-            try
+            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);   //一个月到期
+
+            switch (scope)
             {
-                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))
+                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}");
+            //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 });
+            //    }
+            //}
+
+            //保存当天每小时的峰值
+            List<HourLogin> hourLogins = await table.QueryWhereString<HourLogin>($"PartitionKey eq 'HourLogin' and RowKey eq '{dateHour}'");
+            if (hourLogins.Count > 0)
+            {
+                foreach (var hourLogin in hourLogins)
                 {
-                    school = _school.GetString();
+                    //hourLogin.Hour = currentHour;
+                    if (scope.Equals("teacher"))
+                        hourLogin.Teacher += 1;
+                    else if (scope.Equals("student"))
+                        hourLogin.Student += 1;
+                    else
+                        hourLogin.TmdUser += 1;
                 }
 
-                if (json.TryGetProperty("scope", out JsonElement _scope))
+                try
                 {
-                    scope = _scope.GetString();
+                    await table.SaveOrUpdateAll(hourLogins);
                 }
-
-                if (json.TryGetProperty("id", out JsonElement _id))
+                catch { }
+            }
+            else
+            {
+                HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = dateHour, Hour = currentHour };
+                if (scope.Equals("teacher"))
                 {
-                    id = _id.GetString();
+                    hourLogin.Teacher = 1;
+                    hourLogin.Student = 0;
+                    hourLogin.TmdUser = 0;
                 }
-
-                if (json.TryGetProperty("ip", out JsonElement _ip))
+                else if (scope.Equals("student"))
                 {
-                    ip = _ip.GetString();
+                    hourLogin.Teacher = 0;
+                    hourLogin.Student = 1;
+                    hourLogin.TmdUser = 0;
                 }
-
-                if (json.TryGetProperty("expire", out JsonElement _expire))
+                else
                 {
-                    expire = _expire.GetInt32();
+                    hourLogin.Teacher = 0;
+                    hourLogin.Student = 0;
+                    hourLogin.TmdUser = 1;
                 }
+                try
+                {
+                    await table.SaveOrUpdate<HourLogin>(hourLogin);//保存在线数据
+                }
+                catch { }
+            }
 
-                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);   //一个月到期
+            //保存当天的峰值
+            List<DayLogin> dayLogins = await table.QueryWhereString<DayLogin>($"PartitionKey eq 'DayLogin' and RowKey eq '{dateDay}'");
+            if (dayLogins.Count > 0)
+            {
+                foreach (var dayLogin in dayLogins)
+                {
+                    //dayLogin.Day = currentDay;
+                    if (scope.Equals("teacher"))
+                        dayLogin.Teacher += 1;
+                    else if (scope.Equals("student"))
+                        dayLogin.Student += 1;
+                    else
+                        dayLogin.TmdUser += 1;
+                }
 
-                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 table.SaveOrUpdateAll(dayLogins);
                 }
+                catch { }
+            }
+            else
+            {
+                //保存当月每天的峰值
+                DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = dateDay, Day = currentDay };
+                if (scope.Equals("teacher"))
+                {
+                    dayLogin.Teacher = 1;
+                    dayLogin.Student = 0;
+                    dayLogin.TmdUser = 0;
+                }
+                else if (scope.Equals("student"))
+                {
+                    dayLogin.Teacher = 0;
+                    dayLogin.Student = 1;
+                    dayLogin.TmdUser = 0;
+                }
+                else
+                {
+                    dayLogin.Teacher = 0;
+                    dayLogin.Student = 0;
+                    dayLogin.TmdUser = 1;
+                }
+                try
+                {
+                    await table.SaveOrUpdate<DayLogin>(dayLogin);//保存当月每天在线数据
+                }
+                catch { }
+            }
 
-                await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateDay}", $"{currentHour}", 1);//一天24小时
-                await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateMonth}", $"{currentDay}", 1); //当天的累计
+            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:IES:{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:IES:{scope}:{dateDay}", hour);  //设置到期时间
+                    await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateDay}", hour);  //设置到期时间
                 }
 
-                var rspMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{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:IES:{scope}:{dateMonth}", month);  //设置到期时间
+                    await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateMonth}", month);  //设置到期时间
                 }
 
                 ////查询Redis是否有值
-                //var dayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateDay}");
-                //List<dynamic> dayCounts = new();
-                //if (dayCnt != null && dayCnt.Length > 0)
+                //var scDayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateDay}");
+                //List<dynamic> scDayCounts = new();
+                //if (scDayCnt != null && scDayCnt.Length > 0)
                 //{
-                //    foreach (var hourCnt in dayCnt)
+                //    foreach (var itemHour in scDayCnt)
                 //    {
-                //        dayCounts.Add(new { code = hourCnt.Element.ToString(), count = (int)hourCnt.Score });
+                //        scDayCounts.Add(new { code = itemHour.Element.ToString(), count = (int)itemHour.Score });
                 //    }
                 //}
-
-                //var monthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateMonth}");
-                //List<dynamic> monthCounts = new();
-                //if (monthCnt != null && monthCnt.Length > 0)
+                //var ScMonth = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateMonth}");
+                //List<dynamic> scMonthCount = new();
+                //if (ScMonth != null && ScMonth.Length > 0)
                 //{
-                //    foreach (var mCnt in monthCnt)
+                //    foreach (var count in ScMonth)
                 //    {
-                //        monthCounts.Add(new { code = mCnt.Element.ToString(), count = (int)mCnt.Score });
+                //        scMonthCount.Add(new { code = count.Element.ToString(), count = (int)count.Score });
                 //    }
                 //}
 
-                //保存当天每小时的峰值
-                List<HourLogin> hourLogins = await table.QueryWhereString<HourLogin>($"PartitionKey eq 'HourLogin' and RowKey eq '{dateHour}'");
-                if (hourLogins.Count > 0)
+                //保存学校当天每小时的
+                List<HourLoginSchool> hourLoginSchools = await table.QueryWhereString<HourLoginSchool>($"PartitionKey eq 'HourLogin-{school}' and RowKey eq '{dateHour}'");
+                if (hourLoginSchools.Count > 0)
                 {
-                    foreach (var hourLogin in hourLogins)
+                    foreach (var hLoginSc in hourLoginSchools)
                     {
-                        //hourLogin.Hour = currentHour;
+                        //hLoginSc.Hour = currentHour;
                         if (scope.Equals("teacher"))
-                            hourLogin.Teacher += 1;
+                            hLoginSc.Teacher += 1;
                         else if (scope.Equals("student"))
-                            hourLogin.Student += 1;
+                            hLoginSc.Student += 1;
                         else
-                            hourLogin.TmdUser += 1;
+                            hLoginSc.TmdUser += 1;
                     }
 
                     try
                     {
-                        await table.SaveOrUpdateAll(hourLogins);
+                        await table.SaveOrUpdateAll(hourLoginSchools);
                     }
                     catch { }
                 }
                 else
                 {
-                    HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = dateHour, Hour = currentHour };
+                    //学校小时峰值
+                    HourLoginSchool hourLoginSc = new() { PartitionKey = $"HourLogin-{school}", RowKey = dateHour, Hour = currentHour, School = school };
                     if (scope.Equals("teacher"))
                     {
-                        hourLogin.Teacher = 1;
-                        hourLogin.Student = 0;
-                        hourLogin.TmdUser = 0;
+                        hourLoginSc.Teacher = 1;
+                        hourLoginSc.Student = 0;
+                        hourLoginSc.TmdUser = 0;
                     }
                     else if (scope.Equals("student"))
                     {
-                        hourLogin.Teacher = 0;
-                        hourLogin.Student = 1;
-                        hourLogin.TmdUser = 0;
+                        hourLoginSc.Teacher = 0;
+                        hourLoginSc.Student = 1;
+                        hourLoginSc.TmdUser = 0;
                     }
                     else
                     {
-                        hourLogin.Teacher = 0;
-                        hourLogin.Student = 0;
-                        hourLogin.TmdUser = 1;
+                        hourLoginSc.Teacher = 0;
+                        hourLoginSc.Student = 0;
+                        hourLoginSc.TmdUser = 1;
                     }
+
                     try
                     {
-                        await table.SaveOrUpdate<HourLogin>(hourLogin);//保存在线数据
+                        await table.SaveOrUpdate<HourLoginSchool>(hourLoginSc);//保存在线数据
                     }
                     catch { }
                 }
 
-                //保存当天的峰值
-                List<DayLogin> dayLogins = await table.QueryWhereString<DayLogin>($"PartitionKey eq 'DayLogin' and RowKey eq '{dateDay}'");
-                if (dayLogins.Count > 0)
+                //学校天峰值
+                List<DayLoginSchool> DayLoginSchools = await table.QueryWhereString<DayLoginSchool>($"PartitionKey eq 'DayLogin-{school}' and RowKey eq '{dateDay}'");
+                if (DayLoginSchools.Count > 0)
                 {
-                    foreach (var dayLogin in dayLogins)
+                    foreach (var dLoginSc in DayLoginSchools)
                     {
-                        //dayLogin.Day = currentDay;
+                        //dLoginSc.Day = currentDay;
                         if (scope.Equals("teacher"))
-                            dayLogin.Teacher += 1;
+                            dLoginSc.Teacher += 1;
                         else if (scope.Equals("student"))
-                            dayLogin.Student += 1;
+                            dLoginSc.Student += 1;
                         else
-                            dayLogin.TmdUser += 1;
+                            dLoginSc.TmdUser += 1;
                     }
 
                     try
                     {
-                        await table.SaveOrUpdateAll(dayLogins);
+                        await table.SaveOrUpdateAll(DayLoginSchools);
                     }
                     catch { }
                 }
                 else
                 {
-                    //保存当月每天的峰值
-                    DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = dateDay, Day = currentDay };
+                    //学校天峰值
+                    DayLoginSchool dayLoginSc = new() { PartitionKey = $"DayLogin-{school}", RowKey = dateDay, Day = currentDay, School = school };
                     if (scope.Equals("teacher"))
                     {
-                        dayLogin.Teacher = 1;
-                        dayLogin.Student = 0;
-                        dayLogin.TmdUser = 0;
+                        dayLoginSc.Teacher = 1;
+                        dayLoginSc.Student = 0;
+                        dayLoginSc.TmdUser = 0;
                     }
                     else if (scope.Equals("student"))
                     {
-                        dayLogin.Teacher = 0;
-                        dayLogin.Student = 1;
-                        dayLogin.TmdUser = 0;
+                        dayLoginSc.Teacher = 0;
+                        dayLoginSc.Student = 1;
+                        dayLoginSc.TmdUser = 0;
                     }
                     else
                     {
-                        dayLogin.Teacher = 0;
-                        dayLogin.Student = 0;
-                        dayLogin.TmdUser = 1;
+                        dayLoginSc.Teacher = 0;
+                        dayLoginSc.Student = 0;
+                        dayLoginSc.TmdUser = 1;
                     }
+
                     try
                     {
-                        await table.SaveOrUpdate<DayLogin>(dayLogin);//保存当月每天在线数据
+                        await table.SaveOrUpdate<DayLoginSchool>(dayLoginSc);//保存在线数据
                     }
                     catch { }
                 }
-
-                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)
-                    //{
-                    //    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 });
-                    //    }
-                    //}
-
-                    //保存学校当天每小时的
-                    List<HourLoginSchool> hourLoginSchools = await table.QueryWhereString<HourLoginSchool>($"PartitionKey eq 'HourLogin-{school}' and RowKey eq '{dateHour}'");
-                    if (hourLoginSchools.Count > 0)
-                    {
-                        foreach (var hLoginSc in hourLoginSchools)
-                        {
-                            //hLoginSc.Hour = currentHour;
-                            if (scope.Equals("teacher"))
-                                hLoginSc.Teacher += 1;
-                            else if (scope.Equals("student"))
-                                hLoginSc.Student += 1;
-                            else
-                                hLoginSc.TmdUser += 1;
-                        }
-
-                        try
-                        {
-                            await table.SaveOrUpdateAll(hourLoginSchools);
-                        }
-                        catch { }
-                    }
-                    else
-                    {
-                        //学校小时峰值
-                        HourLoginSchool hourLoginSc = new() { PartitionKey = $"HourLogin-{school}", RowKey = dateHour, Hour = currentHour, School = school };
-                        if (scope.Equals("teacher"))
-                        {
-                            hourLoginSc.Teacher = 1;
-                            hourLoginSc.Student = 0;
-                            hourLoginSc.TmdUser = 0;
-                        }
-                        else if (scope.Equals("student"))
-                        {
-                            hourLoginSc.Teacher = 0;
-                            hourLoginSc.Student = 1;
-                            hourLoginSc.TmdUser = 0;
-                        }
-                        else
-                        {
-                            hourLoginSc.Teacher = 0;
-                            hourLoginSc.Student = 0;
-                            hourLoginSc.TmdUser = 1;
-                        }
-
-                        try
-                        {
-                            await table.SaveOrUpdate<HourLoginSchool>(hourLoginSc);//保存在线数据
-                        }
-                        catch { }
-                    }
-
-                    //学校天峰值
-                    List<DayLoginSchool> DayLoginSchools = await table.QueryWhereString<DayLoginSchool>($"PartitionKey eq 'DayLogin-{school}' and RowKey eq '{dateDay}'");
-                    if (DayLoginSchools.Count > 0)
-                    {
-                        foreach (var dLoginSc in DayLoginSchools)
-                        {
-                            //dLoginSc.Day = currentDay;
-                            if (scope.Equals("teacher"))
-                                dLoginSc.Teacher += 1;
-                            else if (scope.Equals("student"))
-                                dLoginSc.Student += 1;
-                            else
-                                dLoginSc.TmdUser += 1;
-                        }
-
-                        try
-                        {
-                            await table.SaveOrUpdateAll(DayLoginSchools);
-                        }
-                        catch { }
-                    }
-                    else
-                    {
-                        //学校天峰值
-                        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;
-                        }
-
-                        try
-                        {
-                            await table.SaveOrUpdate<DayLoginSchool>(dayLoginSc);//保存在线数据
-                        }
-                        catch { }
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"OS:在线记录{Environment.GetEnvironmentVariable("Option:Location")}  onlin-record \n{ex.Message}\n{ex.StackTrace}\n\n{req}", GroupNames.成都开发測試群組);
             }
 
+            await response.WriteAsJsonAsync(new { data = json });
+            return response;
         }
     }
 }