CrazyIter_Bin 1 anno fa
parent
commit
58bd406184

+ 73 - 27
TEAMModelBI/Filter/RequestAuditFilter.cs

@@ -16,28 +16,30 @@ using System.Net.Http;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Channels;
 using System.Net;
 using System.Net;
 using System.Net.Http.Json;
 using System.Net.Http.Json;
+using Microsoft.Extensions.Options;
+using TEAMModelOS.Models;
+using OpenXmlPowerTools;
 
 
 namespace TEAMModelOS.Filter
 namespace TEAMModelOS.Filter
 {
 {
     public class RequestAuditFilter : IAsyncActionFilter
     public class RequestAuditFilter : IAsyncActionFilter
     {
     {
         //private readonly ILogger _logger;
         //private readonly ILogger _logger;
-       // private readonly HttpTrigger _httpTrigger;
         private readonly IHttpClientFactory _httpClient;
         private readonly IHttpClientFactory _httpClient;
         private readonly DingDing _dingding;
         private readonly DingDing _dingding;
-        public RequestAuditFilter(/*ILoggerFactory loggerFactory*/IHttpClientFactory httpClient, DingDing dingding)
+        private readonly Option _option; private string p = "bi";
+        public RequestAuditFilter(/*ILoggerFactory loggerFactory*/IHttpClientFactory httpClient, DingDing dingding, IOptionsSnapshot<Option> option)
         {
         {
             //  _logger = loggerFactory.CreateLogger<RequestAuditFilter>();
             //  _logger = loggerFactory.CreateLogger<RequestAuditFilter>();
-            // _httpTrigger = httpTrigger;
             _httpClient = httpClient;
             _httpClient = httpClient;
             _dingding=dingding;
             _dingding=dingding;
+            _option = option?.Value;
         }
         }
         public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
         public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
         {
         {
-
-            try {
+            try
+            {
                 string id = string.Empty, name = string.Empty, picture = string.Empty, school = string.Empty, scope = string.Empty, roles = string.Empty;
                 string id = string.Empty, name = string.Empty, picture = string.Empty, school = string.Empty, scope = string.Empty, roles = string.Empty;
-
                 //============== 这里是执行方法之前获取数据 ====================
                 //============== 这里是执行方法之前获取数据 ====================
 
 
                 // 获取控制器、路由信息
                 // 获取控制器、路由信息
@@ -68,23 +70,39 @@ namespace TEAMModelOS.Filter
                 //var userId = httpContext.User?.FindFirstValue("userId");
                 //var userId = httpContext.User?.FindFirstValue("userId");
                 var authtoken = context.HttpContext.GetXAuth("AuthToken");
                 var authtoken = context.HttpContext.GetXAuth("AuthToken");
                 string tokenSha = string.Empty, client = string.Empty;
                 string tokenSha = string.Empty, client = string.Empty;
-                if (context.HttpContext.Request.Headers.TryGetValue("Authorization", out StringValues Authorization))
+                if (context.HttpContext.Request.Headers.TryGetValue("Authorization", out StringValues Authorization) && Authorization.Any())
                 {
                 {
-                    var jwt = new JwtSecurityTokenHandler().ReadJwtToken(Authorization.ToString().Replace("Bearer ", ""));
-                    client= roles = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("roles"))?.Value;
-                    tokenSha= ShaHashHelper.GetSHA1(Authorization.ToString());
+                    try
+                    {
+                        var jwt = new JwtSecurityTokenHandler().ReadJwtToken(Authorization.ToString().Replace("Bearer ", ""));
+                        client= roles = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("roles"))?.Value;
+                        tokenSha= ShaHashHelper.GetSHA1(Authorization.ToString());
+                    }
+                    catch (Exception ex)
+                    {
+                        // await _dingding.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n{Authorization}\n{httpRequest.PathBase}{httpRequest.Path}", GroupNames.成都开发測試群組);
+                    }
                 }
                 }
-                if (context.HttpContext.Request.Headers.TryGetValue("X-Auth-IdToken", out StringValues XAuthIdToken))
+                if (context.HttpContext.Request.Headers.TryGetValue("X-Auth-IdToken", out StringValues XAuthIdToken)  && XAuthIdToken.Any())
                 {
                 {
-                    var jwt = new JwtSecurityTokenHandler().ReadJwtToken(XAuthIdToken);
-                    id = jwt.Payload.Sub;
-                    name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
-                    if (string.IsNullOrEmpty(tokenSha))
+                    try
                     {
                     {
-                        tokenSha= ShaHashHelper.GetSHA1(XAuthIdToken.ToString());
+                        var jwt = new JwtSecurityTokenHandler().ReadJwtToken(XAuthIdToken.ToString());
+                        id = jwt.Payload.Sub;
+                        name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
+                        if (string.IsNullOrEmpty(tokenSha))
+                        {
+                            tokenSha= ShaHashHelper.GetSHA1(XAuthIdToken.ToString());
+                        }
+                        scope="teacher";
+                    }
+                    catch (Exception ex)
+                    {
+                        await _dingding.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n{XAuthIdToken}\n{httpRequest.PathBase}{httpRequest.Path}", GroupNames.成都开发測試群組);
                     }
                     }
                 }
                 }
-                if (context.HttpContext.Request.Headers.TryGetValue("X-Auth-School", out StringValues XAuthSchool))
+
+                if (context.HttpContext.Request.Headers.TryGetValue("X-Auth-School", out StringValues XAuthSchool) && XAuthSchool.Any())
                 {
                 {
                     try
                     try
                     {
                     {
@@ -92,17 +110,42 @@ namespace TEAMModelOS.Filter
                     }
                     }
                     catch (Exception ex) { }
                     catch (Exception ex) { }
                 }
                 }
+                if (context.HttpContext.Request.Headers.TryGetValue("X-Auth-ApiToken", out StringValues XAutApiToken) && XAutApiToken.Any())
+                {
+                    try
+                    {
+                        var jwt = new JwtSecurityTokenHandler().ReadJwtToken(XAutApiToken);
+                        id = jwt.Payload.Sub;
+
+                        if (string.IsNullOrEmpty(tokenSha))
+                        {
+                            tokenSha= jwt.Payload.Jti;
+                        }
+                        client="Open";
+                    }
+                    catch (Exception ex)
+                    {
 
 
+                        await _dingding.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n{XAutApiToken}\n{httpRequest.PathBase}{httpRequest.Path}", GroupNames.成都开发測試群組);
+                    }
+                }
                 if (!string.IsNullOrWhiteSpace(authtoken))
                 if (!string.IsNullOrWhiteSpace(authtoken))
                 {
                 {
-                    var jwt = new JwtSecurityTokenHandler().ReadJwtToken(authtoken);
-                    id = jwt.Payload.Sub;
-                    school = jwt.Payload.Azp;
-                    name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
-                    scope = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("scope"))?.Value;
-                    if (string.IsNullOrEmpty(tokenSha))
+                    try
+                    {
+                        var jwt = new JwtSecurityTokenHandler().ReadJwtToken(authtoken);
+                        id = jwt.Payload.Sub;
+                        school = $"{jwt.Payload.Azp}".Equals("true")|| $"{jwt.Payload.Azp}".Equals("false") ? "" : $"{jwt.Payload.Azp}";
+                        name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
+                        scope = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("scope"))?.Value;
+                        if (string.IsNullOrEmpty(tokenSha))
+                        {
+                            tokenSha= ShaHashHelper.GetSHA1(authtoken);
+                        }
+                    }
+                    catch (Exception ex)
                     {
                     {
-                        tokenSha= ShaHashHelper.GetSHA1(authtoken);
+                        await _dingding.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n{authtoken}\n{httpRequest.PathBase}{httpRequest.Path}", GroupNames.成都开发測試群組);
                     }
                     }
                 }
                 }
                 string secChUaPlatform = string.Empty;
                 string secChUaPlatform = string.Empty;
@@ -147,16 +190,17 @@ namespace TEAMModelOS.Filter
                     scope = scope,
                     scope = scope,
                     // referer = refererUrl,
                     // referer = refererUrl,
                     //platform = secChUaPlatform,
                     //platform = secChUaPlatform,
-                    p = "bi",
+                    p = p,
+                    l = _option.Location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "China" : "Global"
                     //idToken=XAuthIdToken
                     //idToken=XAuthIdToken
                 };
                 };
                 var httpclient = _httpClient.CreateClient();
                 var httpclient = _httpClient.CreateClient();
                 httpclient.Timeout=  TimeSpan.FromSeconds(10);
                 httpclient.Timeout=  TimeSpan.FromSeconds(10);
 #if DEBUG
 #if DEBUG
                 var response = await httpclient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log", data);
                 var response = await httpclient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log", data);
-                //if (response.StatusCode==HttpStatusCode.OK)
+                //if (response.StatusCode==HttpStatusCode.OK) 
                 //{
                 //{
-                //    string result = await response.Content.ReadAsStringAsync();
+                //    string result =   await response.Content.ReadAsStringAsync();
 
 
                 //}
                 //}
 #else
 #else
@@ -171,5 +215,7 @@ namespace TEAMModelOS.Filter
             }
             }
 
 
         }
         }
+
     }
     }
+
 }
 }

+ 49 - 81
TEAMModelOS.FunctionV4/TimeTrigger/IESTimerTrigger.cs

@@ -50,7 +50,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         private readonly IHttpClientFactory _httpClient;
         private readonly IHttpClientFactory _httpClient;
         private IPSearcher _ipSearcher;
         private IPSearcher _ipSearcher;
         private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
         private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
-        public IESTimerTrigger(Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator, IPSearcher ipSearcher, IHttpClientFactory httpClient,SnowflakeId snowflakeId,IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
+        public IESTimerTrigger(Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator, IPSearcher ipSearcher, IHttpClientFactory httpClient, SnowflakeId snowflakeId, IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
         {
         {
             _azureCosmos = azureCosmos;
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
             _dingDing = dingDing;
@@ -72,11 +72,14 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         //https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
         //https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
         //0 1 * * * * 一天中每小时的第 1 分钟
         //0 1 * * * * 一天中每小时的第 1 分钟
         //0 */10 * * * *  每五分钟一次
         //0 */10 * * * *  每五分钟一次
-        public async Task HttpLogCount([TimerTrigger("0 1 * * * *")] TimerInfo myTimer, ILogger log) {
-            try {
+        public async Task HttpLogCount([TimerTrigger("0 5 * * * *")] TimerInfo myTimer, ILogger log)
+        {
+            try
+            {
                 string location = Environment.GetEnvironmentVariable("Option:Location");
                 string location = Environment.GetEnvironmentVariable("Option:Location");
                 //获取上一个小时的数据
                 //获取上一个小时的数据
-                var gmt8Time = DateTimeOffset.UtcNow.GetGMTTime(8).AddHours(-1);
+                //获取上一个小时的数据
+                var gmt8Time = DateTimeOffset.Now.GetGMTTime(8).AddHours(-1);
                 var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
                 var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
                 if (await appendBlob.ExistsAsync())
                 if (await appendBlob.ExistsAsync())
                 {
                 {
@@ -91,8 +94,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                     {
                     {
                         content=$"[{content}}}]";
                         content=$"[{content}}}]";
                     }
                     }
-                    var httpLogs = content.ToObject<ConcurrentBag<HttpLog>>();
-                    Parallel.ForEach(httpLogs, item =>
+                    var httpLogList = content.ToObject<List<HttpLog>>();
+                    Parallel.ForEach(httpLogList, item =>
                     {
                     {
                         item.year = $"{gmt8Time:yyyy}";
                         item.year = $"{gmt8Time:yyyy}";
                         item.month = $"{gmt8Time:MM}";
                         item.month = $"{gmt8Time:MM}";
@@ -103,74 +106,29 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                     //  vistsDay.FindAll(x => x.path.Contains("common/exam/upsert-record"))
                     //  vistsDay.FindAll(x => x.path.Contains("common/exam/upsert-record"))
 
 
 
 
-                    (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   = SystemService.ConvertHttpLog(httpLogs, _ipSearcher, _longitudeLatitudeTranslator);
-                    List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
-                    List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
-                    var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
-                    if (tmds.Any())
+                    (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   = await SystemService.ConvertHttpLog(httpLogList, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator);
+                    if (vists!=null  && vists.Count>0)
                     {
                     {
-                        foreach (var tmd in tmds)
+                        var appendDayBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/index.log");
+                        if (!await appendDayBlob.ExistsAsync())
                         {
                         {
-                            var exists = await _azureRedis.GetRedisClient().KeyExistsAsync($"Blob:Catalog:{tmd}");
-                            if (exists)
-                            {
-                                tmdexists.Add((tmd, exists, "teacher"));
-                            }
-                            else
-                            {
-                                exists = await _azureRedis.GetRedisClient().KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
-                                tmdexists.Add((tmd, exists, "student"));
-                            }
-                        }
-                    }
-                    var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
-                    if (schs.Any())
-                    {
-                        foreach (var sch in schs)
-                        {
-                            var exists = await _azureRedis.GetRedisClient().KeyExistsAsync(sch);
-                            schexists.Add((sch, exists));
-                        }
-                    }
-                    foreach (var item in uuidInfo)
-                    {
-                        foreach (var tmd in item.tmdid)
-                        {
-                            var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
-                            if (tmdext.tmd!= null  && tmdext.exists)
-                            {
-                                var vist = vists.Where(x => x.id.Equals(item.uuid));
-                                foreach (var vi in vist)
-                                {
-                                    vi.userId=tmd;
-                                    if (string.IsNullOrWhiteSpace(vi.scope))
-                                    {
-                                        vi.scope=tmdext.scope;
-                                    }
-                                }
-                                break;
-                            }
+                            await appendDayBlob.CreateAsync();
                         }
                         }
-
-                        foreach (var sch in item.school)
+                        await Parallel.ForEachAsync(vists, async (item, _) =>
                         {
                         {
-                            var schext = schexists.Find(x => x.sch.Equals(sch));
-                            if (schext.sch!= null  && schext.exists)
+                             
+                            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes($"{item.ToJsonString()},\n")))
                             {
                             {
-                                var vist = vists.Where(x => x.id.Equals(item.uuid));
-                                foreach (var vi in vist)
-                                {
-                                    vi.school=sch;
-                                }
-                                
-                                break;
+                                await appendDayBlob.AppendBlockAsync(stream);
                             }
                             }
-                        }
+                             
+                        });
                     }
                     }
                 }
                 }
-            } catch (Exception ex) 
+            }
+            catch (Exception ex)
             {
             {
-               await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
             }
         }
         }
 
 
@@ -296,7 +254,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-               // await _dingDing.SendBotMsg($"FireWallFileLog 防火墙日志记录: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                // await _dingDing.SendBotMsg($"FireWallFileLog 防火墙日志记录: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
             }
         }
         }
 
 
@@ -311,7 +269,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         //0 1 0 * * * 一天中00的第 1 分钟
         //0 1 0 * * * 一天中00的第 1 分钟
         //0 1 * * * * 一天中每小时的第 1 分钟
         //0 1 * * * * 一天中每小时的第 1 分钟
         //0 */10 * * * *  每五分钟一次
         //0 */10 * * * *  每五分钟一次
-        public async Task BIStatsDayDefault([TimerTrigger("0 1 0 * * *")] TimerInfo myTimer, ILogger log) 
+        public async Task BIStatsDayDefault([TimerTrigger("0 1 0 * * *")] TimerInfo myTimer, ILogger log)
         {
         {
             try
             try
             {
             {
@@ -319,7 +277,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                 await _dingDing.SendBotMsg($"BIStatsDayDefault 定时清理每天的数据: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"BIStatsDayDefault 定时清理每天的数据: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
             }
         }
         }
 
 
@@ -334,9 +292,11 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         //5分钟一次
         //5分钟一次
         public async Task CleanUnusedLessonRecord(
         public async Task CleanUnusedLessonRecord(
             //[TimerTrigger("0 */10 15-23 * * *")] TimerInfo myTimer, ILogger log
             //[TimerTrigger("0 */10 15-23 * * *")] TimerInfo myTimer, ILogger log
-            ) {
+            )
+        {
             string location = Environment.GetEnvironmentVariable("Option:Location");
             string location = Environment.GetEnvironmentVariable("Option:Location");
-            try {
+            try
+            {
                 if (location.Equals("China") || location.Equals("Global"))
                 if (location.Equals("China") || location.Equals("Global"))
                 {
                 {
                     bool lockKey = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"LessonRecord:Unused:Lock:{location}");
                     bool lockKey = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"LessonRecord:Unused:Lock:{location}");
@@ -396,7 +356,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                                                               //100-200
                                                               //100-200
                         var count100_200 = schoolKeys.Where(x => x.count >= 100 && x.count <= 200);//至少500条-1000条
                         var count100_200 = schoolKeys.Where(x => x.count >= 100 && x.count <= 200);//至少500条-1000条
                         counts.AddRange(count100_200.Page(10));//5个学校或个人
                         counts.AddRange(count100_200.Page(10));//5个学校或个人
-                                                              //51-99
+                                                               //51-99
                         var count51_99 = schoolKeys.Where(x => x.count >= 51 && x.count <= 99);//至少500条-990条
                         var count51_99 = schoolKeys.Where(x => x.count >= 51 && x.count <= 99);//至少500条-990条
                         counts.AddRange(count51_99.Page(10));//10个学校或个人
                         counts.AddRange(count51_99.Page(10));//10个学校或个人
                                                              //21-50
                                                              //21-50
@@ -460,7 +420,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                                 if (items.IsNotEmpty())
                                 if (items.IsNotEmpty())
                                 {
                                 {
                                     HashSet<string> set = new HashSet<string>();
                                     HashSet<string> set = new HashSet<string>();
-                                    items.ForEach(z => {
+                                    items.ForEach(z =>
+                                    {
                                         var uri = z.Split("/");
                                         var uri = z.Split("/");
                                         if (uri.Length > 1)
                                         if (uri.Length > 1)
                                         {
                                         {
@@ -484,7 +445,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                                         {
                                         {
                                             foreach (var not in notin)
                                             foreach (var not in notin)
                                             {
                                             {
-                                                if (!string.IsNullOrWhiteSpace(not)) {
+                                                if (!string.IsNullOrWhiteSpace(not))
+                                                {
                                                     string url = $"records/{not}";
                                                     string url = $"records/{not}";
                                                     long id = -1;
                                                     long id = -1;
                                                     long.TryParse(not, out id);
                                                     long.TryParse(not, out id);
@@ -507,7 +469,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
-                                if (urls.IsNotEmpty()) {
+                                if (urls.IsNotEmpty())
+                                {
                                     deleteUrls.Add(new KeyValuePair<string, List<string>>($"{idCode.name}-{idCode.id}", urls));
                                     deleteUrls.Add(new KeyValuePair<string, List<string>>($"{idCode.name}-{idCode.id}", urls));
                                 }
                                 }
                             }
                             }
@@ -530,7 +493,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                         List<string> content = new List<string>();
                         List<string> content = new List<string>();
                         foreach (var url in deleteUrls)
                         foreach (var url in deleteUrls)
                         {
                         {
-                            if (url.Value.IsNotEmpty()) {
+                            if (url.Value.IsNotEmpty())
+                            {
                                 content.Add($"{url.Key}\n   {string.Join("  \t\n", url.Value)}");
                                 content.Add($"{url.Key}\n   {string.Join("  \t\n", url.Value)}");
                             }
                             }
                         }
                         }
@@ -538,7 +502,7 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                         {
                         {
                             //锁定15至少小时。
                             //锁定15至少小时。
                             await _azureRedis.GetRedisClient(8).StringSetAsync($"LessonRecord:Unused:Lock:Lock", "用于在清理完所有Blob容器后,锁定不再进行多次清理。");
                             await _azureRedis.GetRedisClient(8).StringSetAsync($"LessonRecord:Unused:Lock:Lock", "用于在清理完所有Blob容器后,锁定不再进行多次清理。");
-                            await _azureRedis.GetRedisClient(8).KeyExpireAsync($"LessonRecord:Unused:Lock:Lock",  DateTime.UtcNow.AddHours(15)   );
+                            await _azureRedis.GetRedisClient(8).KeyExpireAsync($"LessonRecord:Unused:Lock:Lock", DateTime.UtcNow.AddHours(15));
                         }
                         }
 
 
                         if (content.IsNotEmpty())
                         if (content.IsNotEmpty())
@@ -546,12 +510,15 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
                             string str = string.Join("\n", content);
                             string str = string.Join("\n", content);
                             await _dingDing.SendBotMsg($"{location}-结束第{unusedLock.field}轮清理冗余的课例记录文件...\n结束时间:{edata}\n耗时:{timeStr}\n清理内容:\n{str}", GroupNames.醍摩豆服務運維群組);
                             await _dingDing.SendBotMsg($"{location}-结束第{unusedLock.field}轮清理冗余的课例记录文件...\n结束时间:{edata}\n耗时:{timeStr}\n清理内容:\n{str}", GroupNames.醍摩豆服務運維群組);
                         }
                         }
-                        else {
-                          //  await _dingDing.SendBotMsg($"{location}-结束第{unusedLock.field}轮清理冗余的课例记录文件...\n结束时间:{edata}\n耗时:{timeStr}\n清理内容:暂无", GroupNames.醍摩豆服務運維群組);
+                        else
+                        {
+                            //  await _dingDing.SendBotMsg($"{location}-结束第{unusedLock.field}轮清理冗余的课例记录文件...\n结束时间:{edata}\n耗时:{timeStr}\n清理内容:暂无", GroupNames.醍摩豆服務運維群組);
                         }
                         }
                     }
                     }
                 }
                 }
-            } catch (Exception ex) {
+            }
+            catch (Exception ex)
+            {
                 await _dingDing.SendBotMsg($"{location} 清理时容器出现异常。\n异常信息:{ex.Message},{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"{location} 清理时容器出现异常。\n异常信息:{ex.Message},{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
             }
             }
         }
         }
@@ -588,7 +555,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         //    await ErrorItemsService.cntStuErrorItemsAsync(_azureRedis, _azureCosmosClient, _dingDing);
         //    await ErrorItemsService.cntStuErrorItemsAsync(_azureRedis, _azureCosmosClient, _dingDing);
         //}
         //}
 
 
-        public class UnusedLock { 
+        public class UnusedLock
+        {
             public int field { get; set; }
             public int field { get; set; }
             /// <summary>
             /// <summary>
             /// 0默认未被执行,1 正在执行中
             /// 0默认未被执行,1 正在执行中
@@ -596,6 +564,6 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
             public int status { get; set; }
             public int status { get; set; }
             public IEnumerable<IdCodeCount> item { get; set; } = new List<IdCodeCount>();
             public IEnumerable<IdCodeCount> item { get; set; } = new List<IdCodeCount>();
         }
         }
-       
+
     }
     }
 }
 }

+ 340 - 124
TEAMModelOS.SDK/Models/Service/SystemService.cs

@@ -1,5 +1,9 @@
-using HTEXLib.COMM.Helpers;
+using DocumentFormat.OpenXml.Bibliography;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Wordprocessing;
+using HTEXLib.COMM.Helpers;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json.Linq;
+using OpenXmlPowerTools;
 using System;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -7,6 +11,7 @@ using System.IdentityModel.Tokens.Jwt;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Text.Json;
 using System.Text.Json;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Extension;
@@ -62,7 +67,7 @@ namespace TEAMModelOS.SDK.Models.Service
         }
         }
 
 
 
 
-        public  static (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) ConvertHttpLog(ConcurrentBag<HttpLog> logs, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator)
+        public  static async Task<(ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)> ConvertHttpLog(List<HttpLog> logs,AzureRedisFactory _azureRedis, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator)
         {
         {
             ConcurrentBag<ApiVist> vists = new ConcurrentBag<ApiVist>();
             ConcurrentBag<ApiVist> vists = new ConcurrentBag<ApiVist>();
             ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
             ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
@@ -81,11 +86,27 @@ namespace TEAMModelOS.SDK.Models.Service
                     school= log.school,
                     school= log.school,
                     tname= log.name,
                     tname= log.name,
                     path = log.path,
                     path = log.path,
-                    year=log.year,
-                    month=log.month,
-                    day=log.day,
-                    hour=log.hour
+                    client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p,
+                    scope=log.scope,
+                    host= log.host,
+                    hostName=log.hostName,
+                    l=log.l,
                 };
                 };
+                if (!string.IsNullOrWhiteSpace(log.year)  && !string.IsNullOrWhiteSpace(log.month)  && !string.IsNullOrWhiteSpace(log.day)  && !string.IsNullOrWhiteSpace(log.hour)   )
+                {
+                    vist.year =log.year;
+                    vist.month=log.month;
+                    vist.day=log.day;
+                    vist.hour=log.hour;
+                }
+                else {
+                    var time = DateTimeOffset.FromUnixTimeMilliseconds(log.time);
+                    vist.year = $"{time:yyyy}";
+                    vist.month = $"{time:MM}";
+                    vist.day = $"{time:dd}";
+                    vist.hour =$"{time:HH}";
+                }
+
                 if (string.IsNullOrWhiteSpace(vist.userId))
                 if (string.IsNullOrWhiteSpace(vist.userId))
                 {
                 {
 
 
@@ -113,6 +134,9 @@ namespace TEAMModelOS.SDK.Models.Service
                                             var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
                                             var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
                                             if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
                                             if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
                                             {
                                             {
+                                                vist.userId=id;
+                                                vist.scope="teahcer";
+                                                vist.tname=name;
                                                 useridMatch.Add(id);
                                                 useridMatch.Add(id);
                                             }
                                             }
                                         }
                                         }
@@ -121,11 +145,25 @@ namespace TEAMModelOS.SDK.Models.Service
                                     }
                                     }
                                 case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
                                 case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
                                 ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
                                 ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
-                                ||node.Path.Contains("userId")||node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
+                                ||node.Path.Contains("userId"):
                                     {
                                     {
                                         if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
                                         if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
                                         {
                                         {
+                                            vist.userId=$"{node}";
+                                            vist.scope="teahcer";
                                             useridMatch.Add($"{node}");
                                             useridMatch.Add($"{node}");
+
+                                        }
+                                        break;
+                                    }
+                                case bool when node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
+                                    {
+                                        if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
+                                        {
+                                            vist.userId=$"{node}";
+                                            vist.scope="student";
+                                            useridMatch.Add($"{node}");
+
                                         }
                                         }
                                         break;
                                         break;
                                     }
                                     }
@@ -135,6 +173,7 @@ namespace TEAMModelOS.SDK.Models.Service
                                         {
                                         {
                                             if (long.TryParse($"{node}", out long _id))
                                             if (long.TryParse($"{node}", out long _id))
                                             {
                                             {
+                                                vist.userId=$"{node}";
                                                 useridMatch.Add($"{node}");
                                                 useridMatch.Add($"{node}");
                                             }
                                             }
                                             else
                                             else
@@ -144,6 +183,7 @@ namespace TEAMModelOS.SDK.Models.Service
                                                 {
                                                 {
                                                     if (long.TryParse(_code, out long _codeid))
                                                     if (long.TryParse(_code, out long _codeid))
                                                     {
                                                     {
+                                                        vist.userId=$"{node}";
                                                         useridMatch.Add($"{_code}");
                                                         useridMatch.Add($"{_code}");
                                                         break;
                                                         break;
                                                     }
                                                     }
@@ -155,9 +195,43 @@ namespace TEAMModelOS.SDK.Models.Service
                             }
                             }
                         }
                         }
                     }
                     }
+
+                    if (log.path.Contains("process-notify",StringComparison.OrdinalIgnoreCase)) {
+                        string s=  log.param.ToJsonString().Replace("\\","");
+                        Regex regextmdid = new Regex("\"tmdid\":\"(\\d+)\"");
+                        Match matchtmdid = regextmdid.Match(s);
+                        if (matchtmdid.Success)
+                        {
+                            var t= matchtmdid.Groups[1].Value;
+                          
+                            if (!string.IsNullOrWhiteSpace(t)) {
+                                vist.userId=t;
+                                vist.scope="teahcer";
+                                useridMatch.Add(t);
+                            }
+                        }
+                        Regex regexname  = new Regex("\"tmdname\":\"(.+?)\"");
+                        Match matchname  = regexname.Match(s);
+                        if (matchname.Success)
+                        {
+                            var t = matchname.Groups[1].Value;
+                            if (!string.IsNullOrWhiteSpace(t))
+                            {
+                                vist.tname=t;
+                            }
+                        }
+                    }
                 }
                 }
-                if (string.IsNullOrWhiteSpace(vist.school))
+                else {
+                    if (string.IsNullOrWhiteSpace($"{vist.scope}")) 
+                    {
+                        vist.scope="teacher";
+                        uuidInfo.Add((uuid, log, new List<string>() { vist.userId }, new List<string>()));
+                    }
+                }
+                if (string.IsNullOrWhiteSpace(vist.school) || vist.school.Equals("true") || vist.school.Equals("false")  )
                 {
                 {
+                    vist.school="";
                     string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
                     string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
                     JObject jsonObject = JObject.Parse(log.param.GetRawText());
                     JObject jsonObject = JObject.Parse(log.param.GetRawText());
                     var nodes_path = jsonObject.SelectTokens(path);
                     var nodes_path = jsonObject.SelectTokens(path);
@@ -171,16 +245,18 @@ namespace TEAMModelOS.SDK.Models.Service
                                 case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
                                 case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
                                 ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
                                 ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
                                     {
                                     {
-                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
+                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8 && $"{node}".Length>=1)
                                         {
                                         {
+                                            vist.school=$"{node}";
                                             schoolMatch.Add($"{node}");
                                             schoolMatch.Add($"{node}");
                                         }
                                         }
                                         break;
                                         break;
                                     }
                                     }
                                 case bool when node.Path.Contains("code"):
                                 case bool when node.Path.Contains("code"):
                                     {
                                     {
-                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
+                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8&& $"{node}".Length>=1)
                                         {
                                         {
+                                            vist.school=$"{node}";
                                             schoolMatch.Add($"{node}");
                                             schoolMatch.Add($"{node}");
                                         }
                                         }
                                         else
                                         else
@@ -188,8 +264,9 @@ namespace TEAMModelOS.SDK.Models.Service
                                             string[] codes = $"{node}".Split("-");
                                             string[] codes = $"{node}".Split("-");
                                             foreach (var _code in codes)
                                             foreach (var _code in codes)
                                             {
                                             {
-                                                if ($"{node}".Length<=8)
+                                                if ($"{_code}".Length<=8  && $"{_code}".Length>=1)
                                                 {
                                                 {
+                                                    vist.school=$"{_code}";
                                                     schoolMatch.Add($"{_code}");
                                                     schoolMatch.Add($"{_code}");
                                                     break;
                                                     break;
                                                 }
                                                 }
@@ -201,9 +278,22 @@ namespace TEAMModelOS.SDK.Models.Service
                         }
                         }
 
 
                     }
                     }
-                }
-
+                    if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
+                    {
+                        string s = log.param.ToJsonString().Replace("\\", "");
+                        Regex regexname = new Regex("\"schoolId\":\"(.+?)\"");
+                        Match matchname = regexname.Match(s);
+                        if (matchname.Success)
+                        {
+                            var t = matchname.Groups[1].Value;
+                            if (!string.IsNullOrWhiteSpace(t))
+                            {
+                                vist.school=t;
+                            }
+                        }
+                    }
 
 
+                }
 
 
                 //处理 client
                 //处理 client
                 {
                 {
@@ -228,6 +318,7 @@ namespace TEAMModelOS.SDK.Models.Service
                         if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
                         if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
                         {
                         {
                             vist.client="hita";
                             vist.client="hita";
+                            vist.scope="teacher";
                         }
                         }
                         if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
                         if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
                         {
                         {
@@ -235,6 +326,7 @@ namespace TEAMModelOS.SDK.Models.Service
                         }
                         }
                         if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
                         if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
                         {
                         {
+                            vist.scope="teacher";
                             vist.client="hiteach";
                             vist.client="hiteach";
                         }
                         }
                         if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
                         if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
@@ -245,124 +337,129 @@ namespace TEAMModelOS.SDK.Models.Service
                 }
                 }
                 //补全站点
                 //补全站点
                 {
                 {
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
-                        ||log.host.Equals("yx.teammodel.cn")))
+                    if (
+                        (log.host.Equals("wwww.teammodel.net")||log.host.Equals("ies5-rc.teammodel.net")))
                     {
                     {
-                        log.host="IES-正式站";
-                        log.host="www.teammodel.cn";
+                        vist.hostName="国际站";
+                        vist.host="www.teammodel.net";
                         vist.client="ies5";
                         vist.client="ies5";
+                        vist.l="Global";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                       &&(log.host.Equals("scyx.teammodel.cn")  ||log.host.Equals("jinniu.teammodel.cn")))
+                    else if (
+                         log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
+                         ||log.host.Equals("yx.teammodel.cn")||log.host.Equals("teammodelos-rc.chinacloudsites.cn")||log.host.Equals("rc.teammodel.cn")|| log.host.Equals("www.teammodel.cn"))
                     {
                     {
-                        log.host="研修2.0-正式站";
-                        log.host="scyx.teammodel.cn";
-                        vist.client="ability";
+                        vist.hostName="大陆站";
+                        vist.host="www.teammodel.cn";
+                        vist.client="ies5"; vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                       &&(log.host.Equals("open.teammodel.cn")))
+                    else if ((log.host.Contains("localhost")  &&  log.p.Equals("os"))|| log.host.Equals("teammodelos-test.chinacloudsites.cn") ||log.host.Equals("test.teammodel.cn"))
                     {
                     {
-                        log.host="开放平台-正式站";
-                        log.host="open.teammodel.cn";
-                        vist.client="open";
+                        vist.hostName="测试站";
+                        vist.host="test.teammodel.cn";
+                        vist.client="ies5"; vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                       &&(log.host.Equals("open-test.teammodel.cn")  ||log.host.Equals("zhiyin-test.teammodel.cn")))
+                    else if (
+                       (log.host.Equals("scyx.teammodel.cn")  ||log.host.Equals("jinniu.teammodel.cn")))
                     {
                     {
-                        log.host="开放平台-测试站";
-                        log.host="open-test.teammodel.cn";
-                        vist.client="open";
+                        vist.hostName="研修2.0";
+                        vist.host="scyx.teammodel.cn";
+                        vist.client="ability"; vist.l="China";
                     }
                     }
-
-                    //
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelos-rc.chinacloudsites.cn")))
+                    else if (
+                        log.host.Equals("open.teammodel.cn")||log.host.Equals("open-test.teammodel.cn")  ||log.host.Equals("zhiyin-test.teammodel.cn"))
                     {
                     {
-                        log.host="IES-RC站";
-                        log.host="rc.teammodel.cn";
-                        vist.client="ies5";
+                        vist.hostName="开放平台";
+                        vist.host="open.teammodel.cn";
+                        vist.client="open"; vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelos-test.chinacloudsites.cn")))
+                    else if ((log.host.Equals("bi-rc.teammodel.net") || log.host.Equals("bi.teammodel.net")))
                     {
                     {
-                        log.host="IES-测试站";
-                        log.host="test.teammodel.cn";
-                        vist.client="ies5";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelbi-test.chinacloudsites.cn")))
-                    {
-                        log.host="BI-测试站";
-                        log.host="bitest.teammodel.cn";
-                        vist.client="bi";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelbi.chinacloudsites.cn")))
-                    {
-                        log.host="BI-正式站";
-                        log.host="bi.teammodel.cn";
+                        vist.hostName="国际站";
+                        vist.host="bi.teammodel.net";
                         vist.client="bi";
                         vist.client="bi";
+                        if (string.IsNullOrWhiteSpace(vist.scope))
+                        {
+                            vist.scope="admin";
+                        }
+                        vist.l="Global";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teamcontest.chinacloudsites.cn")))
-                    {
-                        log.host="赛课-正式站";
-                        log.host="contest.teammodel.cn";
-                        vist.client="contest";
 
 
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("contest.chinacloudsites.cn")))
+                    else if (log.host.Equals("teammodelbi.chinacloudsites.cn") ||log.host.Equals("bi.teammodel.cn"))
                     {
                     {
-                        log.host="赛课-正式站";
-                        log.host="contest.teammodel.cn";
-                        vist.client="contest";
+                        vist.hostName="大陆站";
+                        vist.host="bi.teammodel.cn";
+                        vist.client="bi";
+                        if (string.IsNullOrWhiteSpace(vist.scope))
+                        {
+                            vist.scope="admin";
+                        }
+                        vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("contest-test.chinacloudsites.cn")))
+                    else if (log.host.Equals("bitest.teammodel.cn")||log.host.Equals("teammodelbi-test.chinacloudsites.cn")||(log.host.Contains("localhost")  && (log.p.Equals("bi"))))
                     {
                     {
-                        log.host="赛课-测试站";
-                        log.host="contest-test.teammodel.cn";
-                        vist.client="contest";
+                        vist.hostName="测试站";
+                        vist.host="testbi.teammodel.cn";
+                        vist.client="bi";
+                        if (string.IsNullOrWhiteSpace(vist.scope)) {
+                            vist.scope="admin";
+                        }
+                        vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("hiteachcc.chinacloudsites.cn")))
+                    else if (
+                        log.host.Equals("teamcontest.chinacloudsites.cn")||log.host.Equals("contest.chinacloudsites.cn")||log.host.Equals("contest-test.chinacloudsites.cn"))
                     {
                     {
-                        log.host="CC-正式站";
-                        log.host="hiteachcc.teammodel.cn";
-                        vist.client="hiteachcc";
+                        vist.hostName="大陆站";
+                        vist.host="contest.teammodel.cn";
+                        vist.client="contest"; vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host) &&(log.host.Equals("appraisal.chinacloudsites.cn")))
+                    else if (
+                         log.host.Equals("hiteachcc.chinacloudsites.cn"))
                     {
                     {
-                        log.host="评价-正式站";
-                        log.host="appraisal.teammodel.cn";
-                        vist.client="appraisal";
+                        vist.hostName="正式站";
+                        vist.host="hiteachcc.teammodel.cn";
+                        vist.client="hiteachcc"; 
+                        vist.l="China";
                     }
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("appraisal-test.chinacloudsites.cn")))
+                    else if (log.host.Equals("appraisal.chinacloudsites.cn"))
                     {
                     {
-                        log.host="评价-测试站";
-                        log.host="appraisal-test.teammodel.cn";
-                        vist.client="appraisal";
+                        vist.hostName="大陆站";
+                        vist.host="appraisal.teammodel.cn";
+                        vist.client="appraisal"; 
+                        vist.l="China";
                     }
                     }
-                    if (log.host.Equals("localhost")  &&  log.p.Equals("appraisal"))
+                    else if ((log.host.Contains("localhost")  &&  log.p.Equals("appraisal"))||log.host.Equals("appraisal-test.teammodel.cn")  ||log.host.Equals("appraisal-test.chinacloudsites.cn"))
                     {
                     {
-                        log.host="评价-测试站";
-                        log.host="appraisal-test.teammodel.cn";
+                        vist.hostName="测试站";
+                        vist.host="appraisal-test.teammodel.cn";
                         vist.client="appraisal";
                         vist.client="appraisal";
+                        vist.l="China";
                     }
                     }
-                    if (log.host.Equals("localhost")  &&  log.p.Equals("os"))
-                    {
-                        log.host="IES-测试站";
-                        log.host="test.teammodel.cn";
-                        vist.client="ies5";
-                    }
-                    else if (log.host.Equals("localhost")  && (log.p.Equals("bi")))
-                    {
-                        log.host="BI-测试站";
-                        log.host="bitest.teammodel.cn";
-                        vist.client="bi";
+                    else {
+                        if (!string.IsNullOrWhiteSpace(log.p))
+                        {
+                            vist.client=log.p.Equals("os",StringComparison.OrdinalIgnoreCase)?"ies5": log.p;
+                        }
+                        else
+                        {
+                            vist.client="other";
+                        }
+                        if (log.host.EndsWith(".cn"))
+                        {
+                            vist.hostName="大陆站";
+                            vist.l="China";  
+                        }
+                        else if (log.host.EndsWith(".net"))
+                        {
+                            vist.hostName="国际站";
+                            vist.l="Global"; 
+                        }
+                        else {
+                            vist.hostName="其他"; 
+                            vist.l="其他";
+
+                        }
+                      
                     }
                     }
                 }
                 }
 
 
@@ -373,7 +470,14 @@ namespace TEAMModelOS.SDK.Models.Service
                     {
                     {
                         vist.client="ability";
                         vist.client="ability";
                     }
                     }
-
+                    if (log.path.Contains("teahcer")  )
+                    {
+                        vist.scope="teahcer";
+                    }
+                    if (log.path.Contains("tmduer"))
+                    {
+                        vist.scope=Constant.ScopeTmdUser;
+                    }
                     if (log.path.StartsWith("/activity"))
                     if (log.path.StartsWith("/activity"))
                     {
                     {
                         vist.client="contest";
                         vist.client="contest";
@@ -390,9 +494,16 @@ namespace TEAMModelOS.SDK.Models.Service
                     if (log.path.Contains("art") ||log.path.Contains("aclassone/find-children-activity")  ||log.path.Contains("aclassone/find-teacher-activity") ||log.path.Contains("aclassone/find-summary-activity") ||log.path.Contains("aclassone/upload-all") ||log.path.Contains("aclassone/delete"))
                     if (log.path.Contains("art") ||log.path.Contains("aclassone/find-children-activity")  ||log.path.Contains("aclassone/find-teacher-activity") ||log.path.Contains("aclassone/find-summary-activity") ||log.path.Contains("aclassone/upload-all") ||log.path.Contains("aclassone/delete"))
                     {
                     {
                         vist.client="art";
                         vist.client="art";
-
                     }
                     }
-
+                    if (log.path.Contains("common/exam/upsert-record"))
+                    {
+                        JObject jobject = JObject.Parse(log.param.GetRawText());
+                        var jtokens =  jobject.SelectTokens("$..artId");
+                        if (jtokens!=null && jtokens.Count()>0) {
+                            vist.client="art";
+                            vist.scope=Constant.ScopeStudent;
+                        }
+                    }
                     if (log.path.Contains("habb"))
                     if (log.path.Contains("habb"))
                     {
                     {
                         vist.client="habb";
                         vist.client="habb";
@@ -418,7 +529,6 @@ namespace TEAMModelOS.SDK.Models.Service
                     {
                     {
                         vist.client="sokrate";
                         vist.client="sokrate";
                     }
                     }
-
                     if (log.path.Contains("hiteach"))
                     if (log.path.Contains("hiteach"))
                     {
                     {
                         vist.client="hiteach";
                         vist.client="hiteach";
@@ -430,7 +540,7 @@ namespace TEAMModelOS.SDK.Models.Service
                     }
                     }
                     //从token的role 能否获取 开放平台
                     //从token的role 能否获取 开放平台
                     //单点登录及第三方接口
                     //单点登录及第三方接口
-                    if (log.path.Contains("lepei") || log.path.Contains("sc/")  || log.path.Contains("/sso") || log.path.Contains("sc-init") || log.path.Contains("data-push") || log.path.Contains("xkw")|| log.path.Contains("tianbo")
+                    if (log.path.Contains("lepei") || log.path.Contains("sc/")  || log.path.Contains("/sso") || log.path.Contains("sc-init")|| log.path.Contains("moofen") || log.path.Contains("data-push") || log.path.Contains("xkw")|| log.path.Contains("tianbo")
                         || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding")  || log.path.Contains("wechat")
                         || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding")  || log.path.Contains("wechat")
                         )
                         )
                     {
                     {
@@ -439,11 +549,14 @@ namespace TEAMModelOS.SDK.Models.Service
                 }
                 }
 
 
                 //处理IP转地区
                 //处理IP转地区
-                vist.region=await _ipSearcher.SearchIpAsync(vist.ip);
-                if (!string.IsNullOrWhiteSpace(vist.region))
+                var  region=await _ipSearcher.SearchIpAsync(vist.ip);
+                if (string.IsNullOrWhiteSpace(region)) {
+                    region="未知IP·未知IP·未知IP";
+                }
+                if (!string.IsNullOrWhiteSpace(region))
                 {
                 {
-                    vist.region= vist.region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
-                    var regions = vist.region.Split("·");
+                    region=   region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
+                    var regions = region.Split("·");
                     if (regions.Length==4)
                     if (regions.Length==4)
                     {
                     {
                         vist.area=  regions[0];
                         vist.area=  regions[0];
@@ -465,6 +578,7 @@ namespace TEAMModelOS.SDK.Models.Service
                         vist.area=  regions[0];
                         vist.area=  regions[0];
                     }
                     }
                 }
                 }
+               
                 //处理地区转经纬度
                 //处理地区转经纬度
                 {
                 {
                     IEnumerable<JToken> tokens = default;
                     IEnumerable<JToken> tokens = default;
@@ -519,26 +633,124 @@ namespace TEAMModelOS.SDK.Models.Service
                     {
                     {
                         tokens=  _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
                         tokens=  _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
                     }
                     }
-                    if (tokens!= null && tokens!=default  &&  tokens.Any() && tokens.Count()>0)
+                    if (  tokens!=null &&   tokens.Any()  )
                     {
                     {
                         List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
                         List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
                         foreach (JToken token in tokens)
                         foreach (JToken token in tokens)
                         {
                         {
                             regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
                             regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
                         }
                         }
-                        var region = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
-                        if (!region.IsNotEmpty())
+                        var points = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
+                        if (!points.IsNotEmpty())
+                        {
+                            points= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
+                        }
+
+
+                        vist.lat=points?.FirstOrDefault()?.lat;
+                        vist.lng=points?.FirstOrDefault()?.lng;
+
+                    }
+                    else {
+                        if (vist.area.Equals("内网IP"))
+                        {
+                            if (vist.host.Contains(".cn") || vist.host.Contains("localhost"))
+                            {
+                                vist.lat="30.655821878416408";
+                                vist.lng="104.08153351042463";
+                                vist.area="中国";
+                                vist.province="四川";
+                                vist.city="成都";
+                            }
+                            else
+                            {
+                                vist.lat="25.044332";
+                                vist.lng="121.509062";
+                                vist.area="中国";
+                                vist.province="台湾";
+                                vist.city="台湾";
+                            }
+
+                        }
+                        else
                         {
                         {
-                            region= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
+                            vist.lat="30.655821878416408";
+                            vist.lng="104.08153351042463";
+                            vist.area="中国";
+                            vist.province="四川";
+                            vist.city="成都";
                         }
                         }
-                        vist.point= region?.FirstOrDefault();
                     }
                     }
+                    
                 }
                 }
-                vist.host= log.host;
-                vist.hostName=log.hostName;
+              
                 uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
                 uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
                 vists.Add(vist);
                 vists.Add(vist);
             });
             });
+
+            List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
+            List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
+            var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
+            if (tmds.Any())
+            {
+                foreach (var tmd in tmds)
+                {
+                    var exists = await _azureRedis.GetRedisClient().KeyExistsAsync($"Blob:Catalog:{tmd}");
+                    if (exists)
+                    {
+                        tmdexists.Add((tmd, exists, "teacher"));
+                    }
+                    else
+                    {
+                        exists = await _azureRedis.GetRedisClient().KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
+                        tmdexists.Add((tmd, exists, "student"));
+                    }
+                }
+            }
+            var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
+            if (schs.Any())
+            {
+                foreach (var sch in schs)
+                {
+                    var exists = await _azureRedis.GetRedisClient().KeyExistsAsync(sch);
+                    schexists.Add((sch, exists));
+                }
+            }
+            foreach (var item in uuidInfo)
+            {
+                foreach (var tmd in item.tmdid)
+                {
+                    var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
+                    if (tmdext.tmd!= null  && tmdext.exists)
+                    {
+                        var vist = vists.Where(x => x.id.Equals(item.uuid));
+                        foreach (var vi in vist)
+                        {
+                            vi.userId=tmd;
+                            if (string.IsNullOrWhiteSpace(vi.scope))
+                            {
+                                vi.scope=tmdext.scope;
+                            }
+                        }
+                        break;
+                    }
+                }
+
+                foreach (var sch in item.school)
+                {
+                    var schext = schexists.Find(x => x.sch.Equals(sch));
+                    if (schext.sch!= null  && schext.exists)
+                    {
+                        var vist = vists.Where(x => x.id.Equals(item.uuid));
+                        foreach (var vi in vist)
+                        {
+                            vi.school=sch;
+                        }
+                        break;
+                    }
+                }
+            }
+           
             return (vists, uuidInfo);
             return (vists, uuidInfo);
         }
         }
 
 
@@ -555,23 +767,23 @@ namespace TEAMModelOS.SDK.Models.Service
             /// <summary>
             /// <summary>
             /// 具体功能
             /// 具体功能
             /// </summary>
             /// </summary>
-            public string func { get; set; }
+           // public string func { get; set; }
 
 
             public string userId { get; set; }
             public string userId { get; set; }
             public string scope { get; set; }
             public string scope { get; set; }
             public string tname { get; set; }
             public string tname { get; set; }
             public string school { get; set; }
             public string school { get; set; }
             public string ip { get; set; }
             public string ip { get; set; }
-            public string region { get; set; }
+            //public string region { get; set; }
             public string area { get; set; }
             public string area { get; set; }
             public string province { get; set; }
             public string province { get; set; }
-            public string city { get; set; }
+            public string city { get; set; } = "";
             public long time { get; set; }
             public long time { get; set; }
             /// <summary>
             /// <summary>
             /// 
             /// 
             /// </summary>
             /// </summary>
             public string host { get; set; }
             public string host { get; set; }
-            public string hostName = "其他";
+            public string hostName { get; set; } = "其他";
             /// <summary>
             /// <summary>
             /// tokenid
             /// tokenid
             /// </summary>
             /// </summary>
@@ -580,7 +792,10 @@ namespace TEAMModelOS.SDK.Models.Service
             public string month { get; set; }
             public string month { get; set; }
             public string day { get; set; }
             public string day { get; set; }
             public string hour { get; set; }
             public string hour { get; set; }
-            public RegionLngLat point { get; set; }
+            //public RegionLngLat point { get; set; }
+            public string lat { get; set; }
+            public string lng { get; set; }
+            public string l { get; set; }
         }
         }
 
 
         public class HttpLog
         public class HttpLog
@@ -604,6 +819,7 @@ namespace TEAMModelOS.SDK.Models.Service
             public string month { get; set; }
             public string month { get; set; }
             public string day { get; set; }
             public string day { get; set; }
             public string hour { get; set; }
             public string hour { get; set; }
+            public string l { get; set; }
 
 
         }
         }
         public record RegionLngLat
         public record RegionLngLat

+ 24 - 124
TEAMModelOS/Controllers/System/BillController.cs

@@ -1,4 +1,5 @@
 using Azure.Storage.Blobs.Models;
 using Azure.Storage.Blobs.Models;
+using Azure.Storage.Blobs.Specialized;
 using DocumentFormat.OpenXml.Bibliography;
 using DocumentFormat.OpenXml.Bibliography;
 using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Spreadsheet;
 using DocumentFormat.OpenXml.Spreadsheet;
@@ -75,6 +76,26 @@ namespace TEAMModelOS.Controllers
             _azureRedis=azureRedis;
             _azureRedis=azureRedis;
             _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
             _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
         }
         }
+
+        [HttpPost("report-api-test")]
+        [EnableCors("AllowSpecificOrigin")]
+        [AllowAnonymous]
+        [RequestSizeLimit(102_400_000_00)] //最大10000m左右
+        public async Task<IActionResult> ReportApiTest(JsonElement json)
+        {
+            try
+            {
+                var httpLogs = json.ToObject<List<HttpLog>>();
+                (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   = await SystemService.ConvertHttpLog(httpLogs, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator);
+                return Ok(new { vists });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+            return Ok();
+        }
+
         /// <summary>
         /// <summary>
         /// 使用时长,一天内累计
         /// 使用时长,一天内累计
         /// </summary>
         /// </summary>
@@ -86,142 +107,21 @@ namespace TEAMModelOS.Controllers
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<IActionResult> ReportApi(JsonElement json)
         public async Task<IActionResult> ReportApi(JsonElement json)
         {
         {
-
-
-            var jobject = JObject.Parse(json.GetRawText());
-            string path = "$..[school,id,schoolId,schoolid,schoolCode,school_code,schoolcode,code]";
-            var tks = jobject.SelectTokens(json.GetProperty("path").GetString());
-            foreach (var t in tks)
-            {
-                var s = $"{t}";
-                return Ok(tks);
-            }
-
+            
             List<ApiVist> apiVists = new List<ApiVist>();
             List<ApiVist> apiVists = new List<ApiVist>();
             List<string> times = json.GetProperty("times").ToObject<List<string>>();
             List<string> times = json.GetProperty("times").ToObject<List<string>>();
             foreach (var timeDate in times)
             foreach (var timeDate in times)
             {
             {
 
 
                 if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date)) {
                 if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date)) {
-                    var BlobClient = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.json");
+                    var BlobClient = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log");
                     string nowMonth = DateTimeOffset.Now.GetGMTTime(8).ToString("yyyy-MM-dd");
                     string nowMonth = DateTimeOffset.Now.GetGMTTime(8).ToString("yyyy-MM-dd");
                     string force = json.GetProperty("force").GetString();
                     string force = json.GetProperty("force").GetString();
                     if (BlobClient.Exists() && !force.Equals("1") && !nowMonth.Equals(date.ToString("yyyy-MM-dd")))
                     if (BlobClient.Exists() && !force.Equals("1") && !nowMonth.Equals(date.ToString("yyyy-MM-dd")))
                     {
                     {
-                        BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.json").DownloadContentAsync();
+                        BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log").DownloadContentAsync();
                         var vist = result.Content.ToObjectFromJson<List<ApiVist>>();
                         var vist = result.Content.ToObjectFromJson<List<ApiVist>>();
                     }
                     }
-                    else
-                    {
-                        List<ApiVist> vistsDay = new List<ApiVist>();
-                        List<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfos = new List<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
-                        List<string> files = await _azureStorage.GetBlobContainerClient("0-service-log").List($"http-log/{date:yyyy}/{date:MM}/{date:dd}");
-                        //List<HttpLog> logs = new List<HttpLog>();
-                        ConcurrentBag<HttpLog> logs = new ConcurrentBag<HttpLog>();
-                        // object lockObj = new object();
-
-                        files.Find(x => x.Contains("index.json"));
-                        await Parallel.ForEachAsync(files, async (file, _) => {
-                            if (!file.Contains("index.json"))
-                            {
-                                //string hour = DateTimeOffset.Now.GetGMTTime(8).ToString("HH");
-                                ////当前小时的不保存
-                                //if (!file.EndsWith($"{hour}.json"))
-                                //{
-
-                                //}
-                                BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient(file).DownloadContentAsync();
-                                var content = result.Content.ToString();
-                                content= content.Substring(0, content.Length-2);
-                                if (content.EndsWith("}"))
-                                {
-                                    content=$"[{content}]";
-                                }
-                                else
-                                {
-                                    content=$"[{content}}}]";
-                                }
-                                var paths = file.Split("/");
-                                var hour = paths[paths.Length-1].Replace(".log", "");
-                                var httpLogs = content.ToObject<List<HttpLog>>();
-                                Parallel.ForEach(httpLogs, item =>
-                                {
-                                    item.year = $"{date:yyyy}";
-                                    item.month = $"{date:MM}";
-                                    item.day = $"{date:dd}";
-                                    item.hour = hour;
-                                    logs.Add(item);
-                                });
-                            }
-                        });
-                        (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   = SystemService.ConvertHttpLog(logs,_ipSearcher,_longitudeLatitudeTranslator);
-                        vistsDay.AddRange(vists);
-                        uuidInfos.AddRange(uuidInfo);
-                        vistsDay.FindAll(x => x.path.Contains("common/exam/upsert-record"));
-                        List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
-                        List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
-                        var tmds = uuidInfos.SelectMany(x => x.tmdid).ToHashSet();
-                        if (tmds.Any())
-                        {
-                            foreach (var tmd in tmds)
-                            {
-                                var exists = await _azureRedis.GetRedisClient().KeyExistsAsync($"Blob:Catalog:{tmd}");
-                                if (exists)
-                                {
-                                    tmdexists.Add((tmd, exists, "teacher"));
-                                }
-                                else
-                                {
-                                    exists = await _azureRedis.GetRedisClient().KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
-                                    tmdexists.Add((tmd, exists, "student"));
-                                }
-                            }
-                        }
-                        var schs = uuidInfos.SelectMany(x => x.school).ToHashSet();
-                        if (schs.Any())
-                        {
-                            foreach (var sch in schs)
-                            {
-                                var exists = await _azureRedis.GetRedisClient().KeyExistsAsync(sch);
-                                schexists.Add((sch, exists));
-                            }
-                        }
-                        foreach (var item in uuidInfos)
-                        {
-                            foreach (var tmd in item.tmdid)
-                            {
-                                var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
-                                if (tmdext.tmd!= null  && tmdext.exists)
-                                {
-                                    var vist = vistsDay.Find(x => x.id.Equals(item.uuid));
-                                    if (vist!= null)
-                                    {
-                                        vist.userId=tmd;
-                                        if (string.IsNullOrWhiteSpace(vist.scope))
-                                        {
-                                            vist.scope=tmdext.scope;
-                                        }
-                                    }
-                                    break;
-                                }
-                            }
-
-                            foreach (var sch in item.school)
-                            {
-                                var schext = schexists.Find(x => x.sch.Equals(sch));
-                                if (schext.sch!= null  && schext.exists)
-                                {
-                                    var vist = vistsDay.Find(x => x.id.Equals(item.uuid));
-                                    if (vist!= null)
-                                    {
-                                        vist.school=sch;
-                                    }
-                                    break;
-                                }
-                            }
-                        }
-                        apiVists.AddRange(vistsDay);
-                    }
                 }
                 }
                
                
             }
             }

+ 42 - 0
TEAMModelOS/Controllers/Third/Moofen/MoofenController.cs

@@ -0,0 +1,42 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.IdentityModel.Tokens;
+using System;
+using System.IdentityModel.Tokens.Jwt;
+using System.Security.Claims;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using TEAMModelOS.SDK.Models;
+
+namespace TEAMModelOS.Controllers.Third.Moofen
+{
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    public class MoofenController : ControllerBase
+    {
+        [HttpGet("moofen/sso")]
+        [AllowAnonymous]
+        public async Task<IActionResult> Sso([FromQuery] OAuthCode authCode)
+        {
+            string key = "U@vY42qlgq9ASXLXNqfze%Jj-NQ!ZKrX$iKonXy1u^8F021c7bzo@t5$ANwWCor#";
+            string code = "15283771540"; //手机号码
+            var claims = new[]
+            {
+                new Claim("code",code)
+            };
+            var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
+            var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);
+            var jwt = new JwtSecurityToken(
+                claims: claims,
+                expires: DateTime.Now.AddMinutes(5),
+                signingCredentials: signinCredentials
+            );
+
+            var tokenString = new JwtSecurityTokenHandler().WriteToken(jwt);
+            string url = $"http://www.moofen.net/sso/tmodel/login?a={HttpUtility.UrlEncode(tokenString)}&c=doofen&t={DateTimeOffset.Now.ToUnixTimeSeconds()}";
+            return Redirect(url);
+        }
+    }
+}

+ 10 - 3
TEAMModelOS/Filter/RequestAuditFilter.cs

@@ -19,6 +19,8 @@ using TEAMModelOS.Controllers;
 using System.Net;
 using System.Net;
 using System.Net.Http;
 using System.Net.Http;
 using System.Net.Http.Json;
 using System.Net.Http.Json;
+using TEAMModelOS.Models;
+using Microsoft.Extensions.Options;
 
 
 namespace TEAMModelOS.Filter
 namespace TEAMModelOS.Filter
 {
 {
@@ -27,11 +29,14 @@ namespace TEAMModelOS.Filter
         //private readonly ILogger _logger;
         //private readonly ILogger _logger;
         private readonly IHttpClientFactory _httpClient;
         private readonly IHttpClientFactory _httpClient;
         private readonly DingDing _dingding;
         private readonly DingDing _dingding;
-        public RequestAuditFilter(/*ILoggerFactory loggerFactory*/IHttpClientFactory httpClient, DingDing dingding)
+        private readonly Option _option;
+        private string p = "os";
+        public RequestAuditFilter(/*ILoggerFactory loggerFactory*/IHttpClientFactory httpClient, DingDing dingding, IOptionsSnapshot<Option> option)
         {
         {
             //  _logger = loggerFactory.CreateLogger<RequestAuditFilter>();
             //  _logger = loggerFactory.CreateLogger<RequestAuditFilter>();
             _httpClient = httpClient;
             _httpClient = httpClient;
             _dingding=dingding;
             _dingding=dingding;
+            _option = option?.Value;
         }
         }
         public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
         public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
         {
         {
@@ -92,6 +97,7 @@ namespace TEAMModelOS.Filter
                         {
                         {
                             tokenSha= ShaHashHelper.GetSHA1(XAuthIdToken.ToString());
                             tokenSha= ShaHashHelper.GetSHA1(XAuthIdToken.ToString());
                         }
                         }
+                        scope="teacher";
                     }
                     }
                     catch (Exception ex)
                     catch (Exception ex)
                     {
                     {
@@ -131,7 +137,7 @@ namespace TEAMModelOS.Filter
                     {
                     {
                         var jwt = new JwtSecurityTokenHandler().ReadJwtToken(authtoken);
                         var jwt = new JwtSecurityTokenHandler().ReadJwtToken(authtoken);
                         id = jwt.Payload.Sub;
                         id = jwt.Payload.Sub;
-                        school = jwt.Payload.Azp;
+                        school = $"{jwt.Payload.Azp}".Equals("true")|| $"{jwt.Payload.Azp}".Equals("false") ? "": $"{jwt.Payload.Azp}";
                         name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
                         name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
                         scope = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("scope"))?.Value;
                         scope = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("scope"))?.Value;
                         if (string.IsNullOrEmpty(tokenSha))
                         if (string.IsNullOrEmpty(tokenSha))
@@ -186,7 +192,8 @@ namespace TEAMModelOS.Filter
                     scope = scope,
                     scope = scope,
                     // referer = refererUrl,
                     // referer = refererUrl,
                     //platform = secChUaPlatform,
                     //platform = secChUaPlatform,
-                    p = "os",
+                    p =p,
+                    l = _option.Location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "China" : "Global"
                     //idToken=XAuthIdToken
                     //idToken=XAuthIdToken
                 };
                 };
                 var httpclient=    _httpClient.CreateClient();
                 var httpclient=    _httpClient.CreateClient();