CrazyIter_Bin 1 rok temu
rodzic
commit
bf77a5cf2d

+ 8 - 7
TEAMModelBI/Filter/RequestAuditFilter.cs

@@ -150,16 +150,17 @@ namespace TEAMModelOS.Filter
                     p = "bi",
                     //idToken=XAuthIdToken
                 };
-
+                var httpclient = _httpClient.CreateClient();
+                httpclient.Timeout=  TimeSpan.FromSeconds(10);
 #if DEBUG
-                var response = await _httpClient.CreateClient().PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log", data);
-                if (response.StatusCode==HttpStatusCode.OK)
-                {
-                    string result = await response.Content.ReadAsStringAsync();
+                var response = await httpclient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log", data);
+                //if (response.StatusCode==HttpStatusCode.OK)
+                //{
+                //    string result = await response.Content.ReadAsStringAsync();
 
-                }
+                //}
 #else
-            _=  _httpClient.CreateClient().PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log",data);
+            _=  httpclient.CreateClient().PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log",data);
 #endif
                 //   _ = _httpTrigger.RequestHttpTrigger(data, "China", "http-log");
             }

+ 1 - 0
TEAMModelOS.FunctionV4/Program.cs

@@ -83,6 +83,7 @@ namespace TEAMModelOS.FunctionV4
                services.AddMultipleAzureStorage(storageConnects);
                services.AddHostedService<BlobRootServiceBusSub>();
                services.AddIPSearcher("");
+               services.TryAddSingleton(new Region2LongitudeLatitudeTranslator(""));
            })
            .Build();
             await host.RunAsync();

+ 6 - 0
TEAMModelOS.FunctionV4/TEAMModelOS.FunctionV4.csproj

@@ -24,6 +24,7 @@
 		<None Remove="Lang\en-us.json" />
 		<None Remove="Lang\zh-cn.json" />
 		<None Remove="Lang\zh-tw.json" />
+		<None Remove="latlng.json" />
 	</ItemGroup>
 	<ItemGroup>
 		<Content Include="Lang\en-us.json">
@@ -41,6 +42,11 @@
 			<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
 			<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
 		</Content>
+ 		<Content Include="latlng.json">
+ 		  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ 		  <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
+ 		  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
+ 		</Content>
 	</ItemGroup>
 
 	<ItemGroup>

+ 118 - 2
TEAMModelOS.FunctionV4/TimeTrigger/IESTimerTrigger.cs

@@ -1,5 +1,6 @@
 using Azure.Cosmos;
 using Azure.Storage.Blobs.Models;
+using Azure.Storage.Blobs.Specialized;
 using DinkToPdf;
 using DinkToPdf.Contracts;
 using HTEXLib.COMM.Helpers;
@@ -7,8 +8,10 @@ using Microsoft.Azure.Cosmos.Table;
 using Microsoft.Azure.Functions.Worker;
 using Microsoft.Azure.Functions.Worker.Http;
 using Microsoft.Extensions.Logging;
+using Microsoft.OData.Edm;
 using StackExchange.Redis;
 using System;
+using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -27,6 +30,7 @@ using TEAMModelOS.SDK.Models.Cosmos.Teacher;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Service.BI;
 using TEAMModelOS.SDK.Models.Table;
+using static TEAMModelOS.SDK.Models.Service.SystemService;
 using static TEAMModelOS.SDK.Models.Teacher;
 
 namespace TEAMModelOS.FunctionV4.TimeTrigger
@@ -45,7 +49,8 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
         private readonly SnowflakeId _snowflakeId;
         private readonly IHttpClientFactory _httpClient;
         private IPSearcher _ipSearcher;
-        public IESTimerTrigger(IPSearcher ipSearcher, IHttpClientFactory httpClient,SnowflakeId snowflakeId,IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
+        private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
+        public IESTimerTrigger(Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator, IPSearcher ipSearcher, IHttpClientFactory httpClient,SnowflakeId snowflakeId,IConverter converter, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
         {
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
@@ -55,8 +60,119 @@ namespace TEAMModelOS.FunctionV4.TimeTrigger
             _snowflakeId=snowflakeId;
             _httpClient = httpClient;
             _ipSearcher = ipSearcher;
+            _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
+        }
+        /// <summary>
+        /// 防火墙日志记录文件
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [Function("HttpLogCount")]
+        //https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
+        //0 1 * * * * 一天中每小时的第 1 分钟
+        //0 */10 * * * *  每五分钟一次
+        public async Task HttpLogCount([TimerTrigger("0 1 * * * *")] TimerInfo myTimer, ILogger log) {
+            try {
+                string location = Environment.GetEnvironmentVariable("Option:Location");
+                //获取上一个小时的数据
+                var gmt8Time = DateTimeOffset.UtcNow.GetGMTTime(8).AddHours(-1);
+                var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
+                if (await appendBlob.ExistsAsync())
+                {
+                    BlobDownloadResult result = await appendBlob.DownloadContentAsync();
+                    var content = result.Content.ToString();
+                    content= content.Substring(0, content.Length-2);
+                    if (content.EndsWith("}"))
+                    {
+                        content=$"[{content}]";
+                    }
+                    else
+                    {
+                        content=$"[{content}}}]";
+                    }
+                    var httpLogs = content.ToObject<ConcurrentBag<HttpLog>>();
+                    Parallel.ForEach(httpLogs, item =>
+                    {
+                        item.year = $"{gmt8Time:yyyy}";
+                        item.month = $"{gmt8Time:MM}";
+                        item.day = $"{gmt8Time:dd}";
+                        item.hour =$"{gmt8Time:HH}";
+                    });
+
+                    //  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())
+                    {
+                        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;
+                            }
+                        }
+                    }
+                }
+            } catch (Exception ex) 
+            {
+               await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
         }
-      
 
         /// <summary>
         /// 防火墙日志记录文件

Plik diff jest za duży
+ 42708 - 0
TEAMModelOS.FunctionV4/latlng.json


+ 9 - 7
TEAMModelOS/Filter/Region2LongitudeLatitudeTranslator.cs

@@ -1,18 +1,21 @@
 using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 using System.Text;
-using System.Text.Json;
-using TEAMModelOS.SDK.Extension;
-using Top.Api;
+using System.Threading.Tasks;
 
-namespace TEAMModelOS.Filter
+namespace TEAMModelOS.SDK.DI
 {
     public class Region2LongitudeLatitudeTranslator
     {
 
         public readonly JArray regionJson;
-        public Region2LongitudeLatitudeTranslator(string configPath) {
-            StreamReader streamReader = new StreamReader(new FileStream(configPath + "/latlng.json", FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
+        public Region2LongitudeLatitudeTranslator(string configPath)
+        {
+            if (configPath == null) throw new ArgumentNullException(nameof(configPath));
+            StreamReader streamReader = new StreamReader(new FileStream(Path.Combine(configPath , "latlng.json"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
             StringBuilder stringBuilder = new StringBuilder();
             string text;
             while ((text = streamReader.ReadLine()) != null)
@@ -22,7 +25,6 @@ namespace TEAMModelOS.Filter
             streamReader.Close();
             string input = stringBuilder.ToString();
             regionJson=  JArray.Parse(input);
-           
         }
     }
 }

+ 562 - 1
TEAMModelOS.SDK/Models/Service/SystemService.cs

@@ -1,7 +1,12 @@
-using System;
+using HTEXLib.COMM.Helpers;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Concurrent;
 using System.Collections.Generic;
+using System.IdentityModel.Tokens.Jwt;
 using System.Linq;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
@@ -55,5 +60,561 @@ 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)
+        {
+            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)>();
+            object lockObj = new object();
+            Parallel.ForEach(logs, async log => {
+                string uuid = Guid.NewGuid().ToString();
+                List<string> schoolMatch = new List<string>();
+                List<string> useridMatch = new List<string>();
+                var vist = new ApiVist()
+                {
+                    id=uuid,
+                    ip=log.ip,
+                    tid=log.tid,
+                    time= log.time,
+                    userId= log.id,
+                    school= log.school,
+                    tname= log.name,
+                    path = log.path,
+                    year=log.year,
+                    month=log.month,
+                    day=log.day,
+                    hour=log.hour
+                };
+                if (string.IsNullOrWhiteSpace(vist.userId))
+                {
+
+                    //var jsonPathContext = new JsonPathContext();
+                    //jsonPathContext.ValueSystem= new JsonTextValueSystem();
+                    string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','code','studentId','student','studentid']";
+
+                    JObject jsonObject = JObject.Parse(log.param.GetRawText());
+                    //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
+
+                    var nodes_path = jsonObject.SelectTokens(path);
+                    foreach (var node in nodes_path)
+                    {
+                        // 只获取是字符串的 
+                        if (node.Type.Equals(JTokenType.String))
+                        {
+                            switch (true)
+                            {
+                                case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
+                                    {
+                                        try
+                                        {
+                                            var jwt = new JwtSecurityToken($"{node}");
+                                            string id = jwt.Payload.Sub;
+                                            var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
+                                            if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
+                                            {
+                                                useridMatch.Add(id);
+                                            }
+                                        }
+                                        catch (Exception ex) { }
+                                        break;
+                                    }
+                                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("userId")||node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
+                                    {
+                                        if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
+                                        {
+                                            useridMatch.Add($"{node}");
+                                        }
+                                        break;
+                                    }
+                                case bool when node.Path.Contains("code"):
+                                    {
+                                        if (!string.IsNullOrWhiteSpace($"{node}"))
+                                        {
+                                            if (long.TryParse($"{node}", out long _id))
+                                            {
+                                                useridMatch.Add($"{node}");
+                                            }
+                                            else
+                                            {
+                                                string[] codes = $"{node}".Split("-");
+                                                foreach (var _code in codes)
+                                                {
+                                                    if (long.TryParse(_code, out long _codeid))
+                                                    {
+                                                        useridMatch.Add($"{_code}");
+                                                        break;
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    }
+                            }
+                        }
+                    }
+                }
+                if (string.IsNullOrWhiteSpace(vist.school))
+                {
+                    string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
+                    JObject jsonObject = JObject.Parse(log.param.GetRawText());
+                    var nodes_path = jsonObject.SelectTokens(path);
+                    foreach (var node in nodes_path)
+                    {
+                        // 只获取是字符串的 
+                        if (node.Type.Equals(JTokenType.String))
+                        {
+                            switch (true)
+                            {
+                                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"):
+                                    {
+                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
+                                        {
+                                            schoolMatch.Add($"{node}");
+                                        }
+                                        break;
+                                    }
+                                case bool when node.Path.Contains("code"):
+                                    {
+                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
+                                        {
+                                            schoolMatch.Add($"{node}");
+                                        }
+                                        else
+                                        {
+                                            string[] codes = $"{node}".Split("-");
+                                            foreach (var _code in codes)
+                                            {
+                                                if ($"{node}".Length<=8)
+                                                {
+                                                    schoolMatch.Add($"{_code}");
+                                                    break;
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    }
+                            }
+                        }
+
+                    }
+                }
+
+
+
+                //处理 client
+                {
+                    if (!string.IsNullOrWhiteSpace(log.client))
+                    {
+                        if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="ies5";
+                        }
+                        if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="aclassone";
+                        }
+                        if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="habb";
+                        }
+                        if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="hiscan";
+                        }
+                        if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="hita";
+                        }
+                        if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="hiteachcc";
+                        }
+                        if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="hiteach";
+                        }
+                        if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
+                        {
+                            vist.client="open";
+                        }
+                    }
+                }
+                //补全站点
+                {
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                        &&(log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
+                        ||log.host.Equals("yx.teammodel.cn")))
+                    {
+                        log.host="IES-正式站";
+                        log.host="www.teammodel.cn";
+                        vist.client="ies5";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                       &&(log.host.Equals("scyx.teammodel.cn")  ||log.host.Equals("jinniu.teammodel.cn")))
+                    {
+                        log.host="研修2.0-正式站";
+                        log.host="scyx.teammodel.cn";
+                        vist.client="ability";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                       &&(log.host.Equals("open.teammodel.cn")))
+                    {
+                        log.host="开放平台-正式站";
+                        log.host="open.teammodel.cn";
+                        vist.client="open";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                       &&(log.host.Equals("open-test.teammodel.cn")  ||log.host.Equals("zhiyin-test.teammodel.cn")))
+                    {
+                        log.host="开放平台-测试站";
+                        log.host="open-test.teammodel.cn";
+                        vist.client="open";
+                    }
+
+                    //
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                        &&(log.host.Equals("teammodelos-rc.chinacloudsites.cn")))
+                    {
+                        log.host="IES-RC站";
+                        log.host="rc.teammodel.cn";
+                        vist.client="ies5";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                        &&(log.host.Equals("teammodelos-test.chinacloudsites.cn")))
+                    {
+                        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.client="bi";
+                    }
+                    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")))
+                    {
+                        log.host="赛课-正式站";
+                        log.host="contest.teammodel.cn";
+                        vist.client="contest";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                        &&(log.host.Equals("contest-test.chinacloudsites.cn")))
+                    {
+                        log.host="赛课-测试站";
+                        log.host="contest-test.teammodel.cn";
+                        vist.client="contest";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                        &&(log.host.Equals("hiteachcc.chinacloudsites.cn")))
+                    {
+                        log.host="CC-正式站";
+                        log.host="hiteachcc.teammodel.cn";
+                        vist.client="hiteachcc";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host) &&(log.host.Equals("appraisal.chinacloudsites.cn")))
+                    {
+                        log.host="评价-正式站";
+                        log.host="appraisal.teammodel.cn";
+                        vist.client="appraisal";
+                    }
+                    if (!string.IsNullOrWhiteSpace(log.host)
+                        &&(log.host.Equals("appraisal-test.chinacloudsites.cn")))
+                    {
+                        log.host="评价-测试站";
+                        log.host="appraisal-test.teammodel.cn";
+                        vist.client="appraisal";
+                    }
+                    if (log.host.Equals("localhost")  &&  log.p.Equals("appraisal"))
+                    {
+                        log.host="评价-测试站";
+                        log.host="appraisal-test.teammodel.cn";
+                        vist.client="appraisal";
+                    }
+                    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";
+                    }
+                }
+
+                //补全产品端
+                {
+                    //研修2.0
+                    if (log.path.Contains("research")  || log.path.Contains("study")  || log.path.Contains("standard-file"))
+                    {
+                        vist.client="ability";
+                    }
+
+                    if (log.path.StartsWith("/activity"))
+                    {
+                        vist.client="contest";
+                    }
+                    //小程序
+                    if (log.path.Contains("aclassone"))
+                    {
+                        vist.client="aclassone";
+                    }
+                    //  /// <summary>
+                    /// ExamInfo  qamode   書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
+                    /// </summary>
+                    //艺术评测
+                    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";
+
+                    }
+
+                    if (log.path.Contains("habb"))
+                    {
+                        vist.client="habb";
+                    }
+                    //阅卷客户端
+                    if (log.path.Contains("hiscan"))
+                    {
+                        vist.client="hiscan";
+                    }
+                    if (log.path.Contains("hita"))
+                    {
+                        vist.client="hita";
+                    }
+                    if (log.path.Contains("hiteachcc"))
+                    {
+                        vist.client="hiteachcc";
+                    }
+                    if (log.path.Contains("sokrate"))
+                    {
+                        vist.client="sokrate";
+                    }
+                    if (log.path.Contains("sokrate") || log.path.Contains("score"))
+                    {
+                        vist.client="sokrate";
+                    }
+
+                    if (log.path.Contains("hiteach"))
+                    {
+                        vist.client="hiteach";
+                    }
+                    ///IES开放平台
+                    if (log.path.Contains("business")  || log.path.Contains("biz") || log.path.Contains("openapi-config")  || log.path.Contains("open-api"))
+                    {
+                        vist.client="open";
+                    }
+                    //从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")
+                        || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding")  || log.path.Contains("wechat")
+                        )
+                    {
+                        vist.client="sso-third";
+                    }
+                }
+
+                //处理IP转地区
+                vist.region=await _ipSearcher.SearchIpAsync(vist.ip);
+                if (!string.IsNullOrWhiteSpace(vist.region))
+                {
+                    vist.region= vist.region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
+                    var regions = vist.region.Split("·");
+                    if (regions.Length==4)
+                    {
+                        vist.area=  regions[0];
+                        vist.province   = regions[1];
+                        vist.city = regions[2];
+                    }
+                    if (regions.Length==3)
+                    {
+                        vist.area=  regions[0];
+                        vist.province   = regions[1];
+                    }
+                    if (regions.Length==2)
+                    {
+                        vist.area=  regions[0];
+                        vist.province   = regions[1];
+                    }
+                    if (regions.Length==1)
+                    {
+                        vist.area=  regions[0];
+                    }
+                }
+                //处理地区转经纬度
+                {
+                    IEnumerable<JToken> tokens = default;
+                    if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province)  && !string.IsNullOrWhiteSpace(vist.area))
+                    {
+                        tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
+                        if (!(tokens.Any() && tokens.Count()>0))
+                        {
+                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
+                            if (!(tokens.Any() && tokens.Count()>0))
+                            {
+                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
+                            }
+                            if (!(tokens.Any() && tokens.Count()>0))
+                            {
+                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
+                            }
+                        }
+
+                    }
+                    else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
+                    {
+                        if (vist.area.Equals("中国"))
+                        {
+                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
+                            if (!(tokens.Any() && tokens.Count()>0))
+                            {
+                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
+                            }
+                        }
+                        else
+                        {
+                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
+                        }
+                    }
+                    else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
+                    {
+                        if (vist.area.Equals("中国"))
+                        {
+                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
+                            if (!(tokens.Any() && tokens.Count()>0))
+                            {
+                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
+                            }
+                        }
+                        else
+                        {
+                            tokens=  _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
+                        }
+                    }
+                    else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
+                    {
+                        tokens=  _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
+                    }
+                    if (tokens!= null && tokens!=default  &&  tokens.Any() && tokens.Count()>0)
+                    {
+                        List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
+                        foreach (JToken token in tokens)
+                        {
+                            regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
+                        }
+                        var region = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
+                        if (!region.IsNotEmpty())
+                        {
+                            region= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
+                        }
+                        vist.point= region?.FirstOrDefault();
+                    }
+                }
+                vist.host= log.host;
+                vist.hostName=log.hostName;
+                uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
+                vists.Add(vist);
+            });
+            return (vists, uuidInfo);
+        }
+
+        public class ApiVist
+        {
+            public string id { get; set; }
+            public string path { get; set; }
+            /// <summary>
+            /// 细分
+            /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
+            /// 产品端
+            /// </summary>
+            public string client { get; set; }
+            /// <summary>
+            /// 具体功能
+            /// </summary>
+            public string func { get; set; }
+
+            public string userId { get; set; }
+            public string scope { get; set; }
+            public string tname { get; set; }
+            public string school { get; set; }
+            public string ip { get; set; }
+            public string region { get; set; }
+            public string area { get; set; }
+            public string province { get; set; }
+            public string city { get; set; }
+            public long time { get; set; }
+            /// <summary>
+            /// 
+            /// </summary>
+            public string host { get; set; }
+            public string hostName = "其他";
+            /// <summary>
+            /// tokenid
+            /// </summary>
+            public string tid { get; set; }
+            public string year { get; set; }
+            public string month { get; set; }
+            public string day { get; set; }
+            public string hour { get; set; }
+            public RegionLngLat point { get; set; }
+        }
+
+        public class HttpLog
+        {
+            public string ip { get; set; }
+            public long time { get; set; }
+            public string host { get; set; }
+            public string hostName = "其他";
+            public string tid { get; set; }
+            public string path { get; set; }
+            public string client { get; set; }
+            public JsonElement param { get; set; }
+            public string id { get; set; }
+            public string name { get; set; }
+            public string school { get; set; }
+            public string p { get; set; }
+            // public string ua { get; set; }
+            // public string referer { get; set;  }
+            public string scope { get; set; }
+            public string year { get; set; }
+            public string month { get; set; }
+            public string day { get; set; }
+            public string hour { get; set; }
+
+        }
+        public record RegionLngLat
+        {
+            public string country { get; set; }
+            public string province { get; set; }
+            public string city { get; set; }
+            public string lat { get; set; }
+            public string lng { get; set; }
+            public string area { get; set; }
+            public string m { get; set; } = "0";
+        }
     }
 }

BIN
TEAMModelOS/ClientApp/public/login_bg.jpg


+ 4 - 553
TEAMModelOS/Controllers/System/BillController.cs

@@ -43,7 +43,9 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.IP2Region;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
+using TEAMModelOS.SDK.Models.Service;
 using Top.Api;
+using static TEAMModelOS.SDK.Models.Service.SystemService;
 
 namespace TEAMModelOS.Controllers
 {
@@ -152,7 +154,7 @@ namespace TEAMModelOS.Controllers
                                 });
                             }
                         });
-                        (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   =   Convert(logs);
+                        (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"));
@@ -229,484 +231,7 @@ namespace TEAMModelOS.Controllers
 
 
 
-        public (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) Convert(ConcurrentBag<HttpLog> logs)
-        {
-            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)>();
-            object lockObj = new object();
-            Parallel.ForEach(logs, async log => {
-                string uuid = Guid.NewGuid().ToString();
-                List<string> schoolMatch = new List<string>();
-                List<string> useridMatch = new List<string>();
-                var vist = new ApiVist() {
-                    id=uuid,
-                    ip=log.ip,
-                    tid=log.tid,
-                    time= log.time,
-                    userId= log.id,
-                    school= log.school,
-                    tname= log.name,
-                    path = log.path,
-                    year=log.year,
-                    month=log.month,
-                    day=log.day,
-                    hour=log.hour
-                };
-                if (string.IsNullOrWhiteSpace(vist.userId))
-                {
-
-                    //var jsonPathContext = new JsonPathContext();
-                    //jsonPathContext.ValueSystem= new JsonTextValueSystem();
-                    string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','code','studentId','student','studentid']";
-
-                    JObject jsonObject = JObject.Parse(log.param.GetRawText());
-                    //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
-
-                    var nodes_path = jsonObject.SelectTokens(path);
-                    foreach (var node in nodes_path)
-                    {
-                        // 只获取是字符串的 
-                        if (node.Type.Equals(JTokenType.String))
-                        {
-                            switch (true)
-                            {
-                                case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
-                                    {
-                                        try
-                                        {
-                                            var jwt = new JwtSecurityToken($"{node}");
-                                            string id = jwt.Payload.Sub;
-                                            var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
-                                            if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
-                                            {
-                                                useridMatch.Add(id);
-                                            }
-                                        }
-                                        catch (Exception ex) { }
-                                        break;
-                                    }
-                                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("userId")||node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
-                                    {
-                                        if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
-                                        {
-                                            useridMatch.Add($"{node}");
-                                        }
-                                        break;
-                                    }
-                                case bool when node.Path.Contains("code"):
-                                    {
-                                        if (!string.IsNullOrWhiteSpace($"{node}"))
-                                        {
-                                            if (long.TryParse($"{node}", out long _id))
-                                            {
-                                                useridMatch.Add($"{node}");
-                                            }
-                                            else
-                                            {
-                                                string[] codes = $"{node}".Split("-");
-                                                foreach (var _code in codes)
-                                                {
-                                                    if (long.TryParse(_code, out long _codeid))
-                                                    {
-                                                        useridMatch.Add($"{_code}");
-                                                        break;
-                                                    }
-                                                }
-                                            }
-                                        }
-                                        break;
-                                    }
-                            }
-                        }
-                    }
-                }
-                if (string.IsNullOrWhiteSpace(vist.school))
-                {
-                    string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
-                    JObject jsonObject = JObject.Parse(log.param.GetRawText());
-                    var nodes_path = jsonObject.SelectTokens(path);
-                    foreach (var node in nodes_path)
-                    {
-                        // 只获取是字符串的 
-                        if (node.Type.Equals(JTokenType.String))
-                        {
-                            switch (true)
-                            {
-                                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"):
-                                    {
-                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
-                                        {
-                                            schoolMatch.Add($"{node}");
-                                        }
-                                        break;
-                                    }
-                                case bool when node.Path.Contains("code"):
-                                    {
-                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
-                                        {
-                                            schoolMatch.Add($"{node}");
-                                        }
-                                        else
-                                        {
-                                            string[] codes = $"{node}".Split("-");
-                                            foreach (var _code in codes)
-                                            {
-                                                if ($"{node}".Length<=8)
-                                                {
-                                                    schoolMatch.Add($"{_code}");
-                                                    break;
-                                                }
-                                            }
-                                        }
-                                        break;
-                                    }
-                            }
-                        }
-
-                    }
-                }
-
-
-              
-                //处理 client
-                {
-                    if (!string.IsNullOrWhiteSpace(log.client))
-                    {
-                        if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="ies5";
-                        }
-                        if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="aclassone";
-                        }
-                        if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="habb";
-                        }
-                        if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="hiscan";
-                        }
-                        if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="hita";
-                        }
-                        if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="hiteachcc";
-                        }
-                        if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="hiteach";
-                        }
-                        if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
-                        {
-                            vist.client="open";
-                        }
-                    }
-                }
-                //补全站点
-                {
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
-                        ||log.host.Equals("yx.teammodel.cn")))
-                    {
-                        log.host="IES-正式站";
-                        log.host="www.teammodel.cn";
-                        vist.client="ies5";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                       &&(log.host.Equals("scyx.teammodel.cn")  ||log.host.Equals("jinniu.teammodel.cn")))
-                    {
-                        log.host="研修2.0-正式站";
-                        log.host="scyx.teammodel.cn";
-                        vist.client="ability";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                       &&(log.host.Equals("open.teammodel.cn")))
-                    {
-                        log.host="开放平台-正式站";
-                        log.host="open.teammodel.cn";
-                        vist.client="open";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                       &&(log.host.Equals("open-test.teammodel.cn")  ||log.host.Equals("zhiyin-test.teammodel.cn")))
-                    {
-                        log.host="开放平台-测试站";
-                        log.host="open-test.teammodel.cn";
-                        vist.client="open";
-                    }
-
-                    //
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelos-rc.chinacloudsites.cn")))
-                    {
-                        log.host="IES-RC站";
-                        log.host="rc.teammodel.cn";
-                        vist.client="ies5";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("teammodelos-test.chinacloudsites.cn")))
-                    {
-                        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.client="bi";
-                    }
-                    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")))
-                    {
-                        log.host="赛课-正式站";
-                        log.host="contest.teammodel.cn";
-                        vist.client="contest";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("contest-test.chinacloudsites.cn")))
-                    {
-                        log.host="赛课-测试站";
-                        log.host="contest-test.teammodel.cn";
-                        vist.client="contest";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("hiteachcc.chinacloudsites.cn")))
-                    {
-                        log.host="CC-正式站";
-                        log.host="hiteachcc.teammodel.cn";
-                        vist.client="hiteachcc";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host) &&(log.host.Equals("appraisal.chinacloudsites.cn")))
-                    {
-                        log.host="评价-正式站";
-                        log.host="appraisal.teammodel.cn";
-                        vist.client="appraisal";
-                    }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("appraisal-test.chinacloudsites.cn")))
-                    {
-                        log.host="评价-测试站";
-                        log.host="appraisal-test.teammodel.cn";
-                        vist.client="appraisal";
-                    }
-                    if (log.host.Equals("localhost")  &&  log.p.Equals("appraisal"))
-                    {
-                        log.host="评价-测试站";
-                        log.host="appraisal-test.teammodel.cn";
-                        vist.client="appraisal";
-                    }
-                    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";
-                    }
-                }
-
-                //补全产品端
-                {
-                    //研修2.0
-                    if (log.path.Contains("research")  || log.path.Contains("study")  || log.path.Contains("standard-file"))
-                    {
-                        vist.client="ability";
-                    }
-
-                    if (log.path.StartsWith("/activity"))
-                    {
-                        vist.client="contest";
-                    }
-                    //小程序
-                    if (log.path.Contains("aclassone"))
-                    {
-                        vist.client="aclassone";
-                    }
-                    //  /// <summary>
-                    /// ExamInfo  qamode   書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
-                    /// </summary>
-                    //艺术评测
-                    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";
-
-                    }
-
-                    if (log.path.Contains("habb"))
-                    {
-                        vist.client="habb";
-                    }
-                    //阅卷客户端
-                    if (log.path.Contains("hiscan"))
-                    {
-                        vist.client="hiscan";
-                    }
-                    if (log.path.Contains("hita"))
-                    {
-                        vist.client="hita";
-                    }
-                    if (log.path.Contains("hiteachcc"))
-                    {
-                        vist.client="hiteachcc";
-                    }
-                    if (log.path.Contains("sokrate"))
-                    {
-                        vist.client="sokrate";
-                    }
-                    if (log.path.Contains("sokrate") || log.path.Contains("score"))
-                    {
-                        vist.client="sokrate";
-                    }
-
-                    if (log.path.Contains("hiteach"))
-                    {
-                        vist.client="hiteach";
-                    }
-                    ///IES开放平台
-                    if (log.path.Contains("business")  || log.path.Contains("biz") || log.path.Contains("openapi-config")  || log.path.Contains("open-api"))
-                    {
-                        vist.client="open";
-                    }
-                    //从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")
-                        || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding")  || log.path.Contains("wechat")
-                        )
-                    {
-                        vist.client="sso-third";
-                    }
-                }
-
-                //处理IP转地区
-                vist.region=await _ipSearcher.SearchIpAsync(vist.ip);
-                if (!string.IsNullOrWhiteSpace(vist.region))
-                {
-                    vist.region= vist.region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
-                    var regions = vist.region.Split("·");
-                    if (regions.Length==4)
-                    {
-                        vist.area=  regions[0];
-                        vist.province   = regions[1];
-                        vist.city = regions[2];
-                    }
-                    if (regions.Length==3)
-                    {
-                        vist.area=  regions[0];
-                        vist.province   = regions[1];
-                    }
-                    if (regions.Length==2)
-                    {
-                        vist.area=  regions[0];
-                        vist.province   = regions[1];
-                    }
-                    if (regions.Length==1)
-                    {
-                        vist.area=  regions[0];
-                    }
-                }
-                //处理地区转经纬度
-                {
-                    IEnumerable<JToken> tokens = default;
-                    if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province)  && !string.IsNullOrWhiteSpace(vist.area))
-                    {
-                        tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
-                        if (!(tokens.Any() && tokens.Count()>0))
-                        {
-                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
-                            if (!(tokens.Any() && tokens.Count()>0))
-                            {
-                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
-                            }
-                            if (!(tokens.Any() && tokens.Count()>0))
-                            {
-                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
-                            }
-                        }
-
-                    }
-                    else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
-                    {
-                        if (vist.area.Equals("中国"))
-                        {
-                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
-                            if (!(tokens.Any() && tokens.Count()>0))
-                            {
-                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
-                            }
-                        }
-                        else
-                        {
-                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
-                        }
-                    }
-                    else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
-                    {
-                        if (vist.area.Equals("中国"))
-                        {
-                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
-                            if (!(tokens.Any() && tokens.Count()>0))
-                            {
-                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
-                            }
-                        }
-                        else
-                        {
-                            tokens=  _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
-                        }
-                    }
-                    else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
-                    {
-                        tokens=  _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
-                    }
-                    if (tokens!= null && tokens!=default  &&  tokens.Any() && tokens.Count()>0)
-                    {
-                        List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
-                        foreach (JToken token in tokens)
-                        {
-                            regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
-                        }
-                        var region = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
-                        if (!region.IsNotEmpty())
-                        {
-                            region= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
-                        }
-                        vist.point= region?.FirstOrDefault();
-                    }
-                }
-                vist.host= log.host;
-                vist.hostName=log.hostName;
-                uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
-                vists.Add(vist);
-            });
-            return (vists, uuidInfo);
-        }
+      
 
         [HttpPost("report")]
         [EnableCors("AllowSpecificOrigin")]
@@ -1373,78 +898,4 @@ namespace TEAMModelOS.Controllers
         }
     }
 
-    public class ApiVist
-    {
-        public string id { get; set; }
-        public string path { get; set; }
-        /// <summary>
-        /// 细分
-        /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
-        /// 产品端
-        /// </summary>
-        public string client { get; set; }
-        /// <summary>
-        /// 具体功能
-        /// </summary>
-        public string func {  get; set; }
-
-        public string userId { get; set; }
-        public string scope { get; set; }
-        public string tname { get; set; }
-        public string school { get; set; }
-        public string ip { get; set; }
-        public string region { get; set; }
-        public string area { get; set; }
-        public string province { get; set; }
-        public string city { get; set; }
-        public long time { get; set; }
-        /// <summary>
-        /// 
-        /// </summary>
-        public string host { get; set; }
-        public string hostName = "其他";
-        /// <summary>
-        /// tokenid
-        /// </summary>
-        public string tid { get; set; }
-        public string year { get; set; }
-        public string month { get; set; }
-        public string day { get; set; }
-        public string hour { get; set; }
-        public RegionLngLat point { get; set; }
-    }
-
-    public class HttpLog
-    {
-        public string ip { get; set; }
-        public long time { get; set; }
-        public string host { get; set; }
-        public string hostName = "其他";
-        public string tid { get; set; }
-        public string path { get; set; }
-        public string client { get; set; }
-        public JsonElement param { get; set; }
-        public string id { get; set; }
-        public string name { get; set; }
-        public string school { get; set; }
-        public string p { get; set; }
-        // public string ua { get; set; }
-        // public string referer { get; set;  }
-        public string scope { get; set; }
-        public string year { get; set; }
-        public string month { get; set; }
-        public string day { get; set; }
-        public string hour { get; set; }
-
-    }
-    public record RegionLngLat
-    {
-        public string country { get; set; }
-        public string province { get; set; }
-        public string city { get; set; }
-        public string lat { get; set; }
-        public string lng { get; set; }
-        public string area { get; set; }
-        public string m { get; set; } = "0";
-    }
 }

+ 8 - 7
TEAMModelOS/Filter/RequestAuditFilter.cs

@@ -189,16 +189,17 @@ namespace TEAMModelOS.Filter
                     p = "os",
                     //idToken=XAuthIdToken
                 };
-
+                var httpclient=    _httpClient.CreateClient();
+                httpclient.Timeout=  TimeSpan.FromSeconds(10); 
 #if DEBUG
-                var  response = await   _httpClient.CreateClient().PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log", data);
-                if (response.StatusCode==HttpStatusCode.OK) 
-                {
-                    string result =   await response.Content.ReadAsStringAsync();
+                var  response = await httpclient.PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log", data);
+                //if (response.StatusCode==HttpStatusCode.OK) 
+                //{
+                //    string result =   await response.Content.ReadAsStringAsync();
                     
-                }
+                //}
 #else
-            _=  _httpClient.CreateClient().PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log",data);
+            _=  httpclient.CreateClient().PostAsJsonAsync("http://cdhabook.teammodel.cn:8805/api/http-log",data);
 #endif
                 //   _ = _httpTrigger.RequestHttpTrigger(data, "China", "http-log");
             }