CrazyIter_Bin 1 年之前
父节点
当前提交
6395b9a9d5

+ 4 - 4
TEAMModelOS.SDK/Helper/Network/IP2Region/IPSearcher.cs

@@ -386,10 +386,10 @@ namespace TEAMModelOS.SDK
                 if (block != null)
                 {
                     string region = block.Region.Replace("0|0|0|0|", "").Replace("0|0|0|", "").Replace("|0|0|0|0", "").Replace("|0|0|0|", "").Replace("|0|0|0", "").Replace("|0|0|", "").Replace("|0|0", "").Replace("|0|", "·").Replace("|0", "").Replace("|", "·");
-                    if (!string.IsNullOrWhiteSpace(region))
-                    {
-                        region = region.Replace("中国·", "").Replace("中国", "").Replace("台湾省", "台湾");
-                    }
+                    //if (!string.IsNullOrWhiteSpace(region))
+                   // {
+                       // region = region.Replace("中国·", "").Replace("中国", "").Replace("台湾省", "台湾");
+                   // }
                     return region;
                 }
                 else { return null; }

+ 125 - 362
TEAMModelOS/Controllers/System/BillController.cs

@@ -21,6 +21,7 @@ using OpenXmlPowerTools;
 using StackExchange.Redis;
 using System;
 using System.Collections;
+using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.IdentityModel.Tokens.Jwt;
@@ -32,6 +33,7 @@ using System.Text;
 using System.Text.Json;
 using System.Text.Json.Nodes;
 using System.Text.RegularExpressions;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Web;
 using TEAMModelOS.Filter;
@@ -57,10 +59,10 @@ namespace TEAMModelOS.Controllers
         private readonly IConfiguration _configuration;
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
-        private readonly ISearcher _ipSearcher;
+        private readonly IPSearcher _ipSearcher;
         private readonly Option _option;
         private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
-        public BillController(Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator,IHttpClientFactory httpClient, IConfiguration configuration, AzureStorageFactory azureStorage, ISearcher searcher, DingDing dingDing, IOptionsSnapshot<Option> option)
+        public BillController(AzureRedisFactory azureRedis, Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator, IHttpClientFactory httpClient, IConfiguration configuration, AzureStorageFactory azureStorage, IPSearcher searcher, DingDing dingDing, IOptionsSnapshot<Option> option)
         {
             _httpClient = httpClient;
             _configuration = configuration;
@@ -68,6 +70,7 @@ namespace TEAMModelOS.Controllers
             _ipSearcher = searcher;
             _dingDing = dingDing;
             _option = option.Value;
+            _azureRedis=azureRedis;
             _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
         }
         /// <summary>
@@ -81,70 +84,18 @@ namespace TEAMModelOS.Controllers
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<IActionResult> ReportApi(JsonElement json)
         {
-            {
-                var vist=  json.GetProperty("vist").ToObject<ApiVist>();
-                IEnumerable<JToken> tokens;
-                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)]");
-                }
-                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)]");
-                    }
-                    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)]");
-                    }
-                    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)]");
-                }
-            }
+
+
             var jobject = JObject.Parse(json.GetRawText());
-            var tks= jobject.SelectTokens(json.GetProperty("path").GetString());
+            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);
             }
 
-            var regions=  _longitudeLatitudeTranslator.regionJson.SelectTokens(json.GetProperty("region").GetString());
-            foreach(var region in regions)
-            {
-                Console.WriteLine(region);
-
-            }
-            var jsonPathContext = new JsonPathContext() { ValueSystem= new JsonNetValueSystem()};
-            {
-                var nodes_id_token = jsonPathContext.SelectNodes(json, json.GetProperty("path").GetString());
-                foreach (var node in nodes_id_token)
-                {
-                    if (node is string)
-                    {
-                        Console.WriteLine(node);
-                    }
-                    else
-                    {
-                        return Ok(node);
-                    }
-                }
-                //return Ok(nodes_id_token);
-            }
-            var reg = _ipSearcher.SearchIp(json.GetProperty("ip").GetString());
+            List<ApiVist> apiVists = new List<ApiVist>();
             List<string> times = json.GetProperty("times").ToObject<List<string>>();
             foreach (var time in times)
             {
@@ -161,28 +112,40 @@ namespace TEAMModelOS.Controllers
                     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/{time}");
-                    foreach (var file in files)
-                    {
+                    //List<HttpLog> logs = new List<HttpLog>();
+                    ConcurrentBag<HttpLog> logs = new ConcurrentBag<HttpLog>();
+                   // object lockObj = new object();
+                    await Parallel.ForEachAsync(files, async (file, _) => {
                         if (!file.Contains("index.json"))
                         {
-                            string hour = DateTimeOffset.Now.GetGMTTime(8).ToString("HH");
-                            //当前小时的不保存
-                            if (!file.EndsWith($"{hour}.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}]";
                             }
-                            BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{time}/{hour}.json").DownloadContentAsync();
-                            var httpLogs = result.Content.ToObjectFromJson<List<HttpLog>>();
-                            (List<ApiVist> vists, List<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   = await Convert(httpLogs);
-                            vistsDay.AddRange(vists);
-                            uuidInfos.AddRange(uuidInfo);
-
-
+                            else
+                            {
+                                content=$"[{content}}}]";
+                            }
+                            var httpLogs = content.ToObject<List<HttpLog>>();
+                            Parallel.ForEach(httpLogs, item =>
+                            {
+                                logs.Add( item);
+                            });
                         }
-                    }
-
+                    });
+                    (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)   =   Convert(logs);
+                    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();
@@ -245,35 +208,36 @@ namespace TEAMModelOS.Controllers
                             }
                         }
                     }
+                    apiVists.AddRange(vistsDay);
                 }
             }
-            return Ok(reg);
+            return Ok(new { apiVists });
         }
 
 
 
 
-        public async Task<(List<ApiVist> vists, List<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)> Convert(List<HttpLog> logs)
+        public (ConcurrentBag<ApiVist> vists, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) Convert(ConcurrentBag<HttpLog> logs)
         {
-            List<ApiVist> vists = new List<ApiVist>();
-            List<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new List<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
-            foreach (HttpLog log in 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 };
                 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]";
+                    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);
+                    var nodes_path = jsonObject.SelectTokens(path);
                     foreach (var node in nodes_path)
                     {
                         // 只获取是字符串的 
@@ -332,204 +296,28 @@ namespace TEAMModelOS.Controllers
                             }
                         }
                     }
-
-                    /*
-                     
-                    {
-                        var nodes_id_token = selection.SelectNodes("$.request.id_token");
-                        if (nodes_id_token.Count()>0)
-                        {
-                            try
-                            {
-                                var jwt = new JwtSecurityToken($"{nodes_id_token[0].Value}");
-                                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))
-                                {
-                                    //vist.userId=id;
-                                    //vist.tname=name;
-                                    useridMatch.Add(id);
-                                }
-                            }
-                            catch (Exception ex) { }
-                        }
-                    }
-
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    // {
-                    var nodes_idToken = selection.SelectNodes("$.request.idToken");
-                    if (nodes_idToken.Count()>0)
-                    {
-                        try
-                        {
-                            var jwt = new JwtSecurityToken($"{nodes_idToken[0].Value}");
-                            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))
-                            {
-                                //vist.userId=id;
-                                //vist.tname=name;
-                                useridMatch.Add(id);
-                            }
-                        }
-                        catch (Exception ex) { }
-                    }
-                    // }
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    //{
-                    var nodes_tmdid = selection.SelectNodes("$.request.tmdid");
-                    if (nodes_tmdid.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_tmdid[0].Value}") && long.TryParse($"{nodes_tmdid[0].Value}", out long _id))
-                        {
-                            //  vist.userId=$"{nodes_tmdid[0].Value}";
-                            useridMatch.Add($"{nodes_tmdid[0].Value}");
-                        }
-                    }
-                    // }
-                    //if (string.IsNullOrWhiteSpace(vist.userId))
-                    // {
-                    var nodes_id = selection.SelectNodes("$.request.id");
-                    if (nodes_id.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_id[0].Value}") && long.TryParse($"{nodes_id[0].Value}", out long _id))
-                        {
-                            //  vist.userId=$"{nodes_id[0].Value}";
-                            useridMatch.Add($"{nodes_id[0].Value}");
-                        }
-                    }
-                    // }
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    // {
-                    var nodes_teacherId = selection.SelectNodes("$.request.teacherId");
-                    if (nodes_teacherId.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_teacherId[0].Value}") && long.TryParse($"{nodes_teacherId[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_teacherId[0].Value}");
-                            //vist.userId=$"{nodes_teacherId[0].Value}";
-                        }
-                    }
-                    // }
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    //  {
-                    var nodes_teacher = selection.SelectNodes("$.request.teacher");
-                    if (nodes_teacher.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_teacher[0].Value}") && long.TryParse($"{nodes_teacher[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_teacher[0].Value}");
-                            // vist.userId=$"{nodes_teacher[0].Value}";
-                        }
-                    }
-                    //}
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    // {
-                    var nodes_tid = selection.SelectNodes("$.request.tid");
-                    if (nodes_tid.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_tid[0].Value}") && long.TryParse($"{nodes_tid[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_tid[0].Value}");
-                            // vist.userId=$"{nodes_tid[0].Value}";
-                        }
-                    }
-                    var nodes_userid = selection.SelectNodes("$.request.userid");
-                    if (nodes_userid.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_userid[0].Value}") && long.TryParse($"{nodes_userid[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_userid[0].Value}");
-                            // vist.userId=$"{nodes_tid[0].Value}";
-                        }
-                    }
-                    var nodes_userId = selection.SelectNodes("$.request.userId");
-                    if (nodes_userId.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_userId[0].Value}") && long.TryParse($"{nodes_userId[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_userId[0].Value}");
-                            // vist.userId=$"{nodes_tid[0].Value}";
-                        }
-                    }
-                    //  }
-                    //  if (string.IsNullOrWhiteSpace(vist.userId))
-                    // {
-                    var nodes_code = selection.SelectNodes("$.request.code");
-                    if (nodes_code.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_code[0].Value}"))
-                        {
-                            if (long.TryParse($"{nodes_code[0].Value}", out long _id))
-                            {
-                                //vist.userId=$"{nodes_code[0].Value}";
-                                useridMatch.Add($"{nodes_code[0].Value}");
-                            }
-                            else
-                            {
-                                string[] codes = $"{nodes_code[0].Value}".Split("-");
-                                foreach (var _code in codes)
-                                {
-                                    if (long.TryParse(_code, out long _codeid))
-                                    {
-                                        useridMatch.Add(vist.userId=$"{_code}");
-                                        // vist.userId=$"{_code}";
-                                        break;
-                                    }
-                                }
-                            }
-
-                        }
-                    }
-                    // }
-                    //学生
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    // {
-                    var nodes_studentId = selection.SelectNodes("$.request.studentId");
-                    if (nodes_studentId.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_studentId[0].Value}") && long.TryParse($"{nodes_studentId[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_studentId[0].Value}");
-                            // vist.userId=$"{nodes_studentId[0].Value}";
-                        }
-                    }
-
-                    //  }
-                    // if (string.IsNullOrWhiteSpace(vist.userId))
-                    //  {
-                    var nodes_student = selection.SelectNodes("$.request.student");
-                    if (nodes_student.Count()>0)
-                    {
-                        if (!string.IsNullOrWhiteSpace($"{nodes_student[0].Value}") && long.TryParse($"{nodes_student[0].Value}", out long _id))
-                        {
-                            useridMatch.Add($"{nodes_student[0].Value}");
-                            //  vist.userId=$"{nodes_student[0].Value}";
-                        }
-                    }
-                    // }
-                     */
                 }
                 if (string.IsNullOrWhiteSpace(vist.school))
                 {
-                    string path = "$..[school,id,schoolId,schoolid,schoolCode,school_code,schoolcode,code]";
-                    //var jsonPathContext = new JsonPathContext();
-                    //jsonPathContext.ValueSystem= new JsonTextValueSystem();
-                    //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
+                    string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
                     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) )
+                        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"):
-                                    { break; }
+                                    {
+                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
+                                        {
+                                            schoolMatch.Add($"{node}");
+                                        }
+                                        break;
+                                    }
                                 case bool when node.Path.Contains("code"):
                                     {
                                         if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
@@ -550,94 +338,14 @@ namespace TEAMModelOS.Controllers
                                         }
                                         break;
                                     }
-
                             }
                         }
 
                     }
-
-                    /*
-                      {
-                         var nodes_school = selection.SelectNodes("$.request.school");
-                         if (nodes_school.Count()>0)
-                         {
-                             if (!string.IsNullOrWhiteSpace($"{nodes_school[0].Value}")  && $"{nodes_school[0].Value}".Length<=8)
-                             {
-                                 schoolMatch.Add($"{nodes_school[0].Value}");
-                             }
-                         }
-                     }
-                     var nodes_id = selection.SelectNodes("$.request.id");
-                     if (nodes_id.Count()>0)
-                     {
-                         if (!string.IsNullOrWhiteSpace($"{nodes_id[0].Value}")  && $"{nodes_id[0].Value}".Length<=8)
-                         {
-                             schoolMatch.Add($"{nodes_id[0].Value}");
-                         }
-                     }
-                     var nodes_schoolId = selection.SelectNodes("$.request.schoolId");
-                     if (nodes_schoolId.Count()>0)
-                     {
-                         if (!string.IsNullOrWhiteSpace($"{nodes_schoolId[0].Value}")  && $"{nodes_schoolId[0].Value}".Length<=8)
-                         {
-                             schoolMatch.Add($"{nodes_schoolId[0].Value}");
-                         }
-                     }
-                     var nodes_schoolid = selection.SelectNodes("$.request.schoolid");
-                     if (nodes_schoolid.Count()>0)
-                     {
-                         if (!string.IsNullOrWhiteSpace($"{nodes_schoolid[0].Value}")  && $"{nodes_schoolid[0].Value}".Length<=8)
-                         {
-                             schoolMatch.Add($"{nodes_schoolid[0].Value}");
-                         }
-                     }
-                     var nodes_schoolCode = selection.SelectNodes("$.request.schoolCode");
-                     if (nodes_schoolCode.Count()>0)
-                     {
-                         if (!string.IsNullOrWhiteSpace($"{nodes_schoolCode[0].Value}")  && $"{nodes_schoolCode[0].Value}".Length<=8)
-                         {
-                             schoolMatch.Add($"{nodes_schoolCode[0].Value}");
-                         }
-                     }
-                     var nodes_school_code = selection.SelectNodes("$.request.school_code");
-                     if (!string.IsNullOrWhiteSpace($"{nodes_school_code[0].Value}")  && $"{nodes_school_code[0].Value}".Length<=8)
-                     {
-                         schoolMatch.Add($"{nodes_school_code[0].Value}");
-                     }
-                     var nodes_schoolcode = selection.SelectNodes("$.request.schoolcode");
-                     if (!string.IsNullOrWhiteSpace($"{nodes_schoolcode[0].Value}")  && $"{nodes_schoolcode[0].Value}".Length<=8)
-                     {
-                         schoolMatch.Add($"{nodes_schoolcode[0].Value}");
-                     }
-                     var nodes_code = selection.SelectNodes("$.request.code");
-                     if (!string.IsNullOrWhiteSpace($"{nodes_code[0].Value}"))
-                     {
-                         if (!$"{nodes_code[0].Value}".Contains("-")&&  $"{nodes_code[0].Value}".Length<=8)
-                         {
-                             //vist.userId=$"{nodes_code[0].Value}";
-                             schoolMatch.Add($"{nodes_code[0].Value}");
-                         }
-                         else
-                         {
-                             string[] codes = $"{nodes_code[0].Value}".Split("-");
-                             foreach (var _code in codes)
-                             {
-                                 if ($"{nodes_code[0].Value}".Length<=8)
-                                 {
-                                     schoolMatch.Add(vist.userId=$"{_code}");
-                                     // vist.userId=$"{_code}";
-                                     break;
-                                 }
-                             }
-                         }
-
-                     }
-                     */
                 }
 
 
-                uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
-                vists.Add(vist);
+              
                 //处理 client
                 {
                     if (!string.IsNullOrWhiteSpace(log.client))
@@ -766,8 +474,7 @@ namespace TEAMModelOS.Controllers
                         log.host="hiteachcc.teammodel.cn";
                         vist.client="hiteachcc";
                     }
-                    if (!string.IsNullOrWhiteSpace(log.host)
-                        &&(log.host.Equals("appraisal.chinacloudsites.cn")))
+                    if (!string.IsNullOrWhiteSpace(log.host) &&(log.host.Equals("appraisal.chinacloudsites.cn")))
                     {
                         log.host="评价-正式站";
                         log.host="appraisal.teammodel.cn";
@@ -780,6 +487,12 @@ namespace TEAMModelOS.Controllers
                         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-测试站";
@@ -867,11 +580,12 @@ namespace TEAMModelOS.Controllers
                 }
 
                 //处理IP转地区
-                vist.region=_ipSearcher.SearchIp(vist.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) 
+                    if (regions.Length==4)
                     {
                         vist.area=  regions[0];
                         vist.province   = regions[1];
@@ -894,40 +608,78 @@ namespace TEAMModelOS.Controllers
                 }
                 //处理地区转经纬度
                 {
+                    IEnumerable<JToken> tokens = default;
                     if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province)  && !string.IsNullOrWhiteSpace(vist.area))
                     {
-                        _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
+                        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("中国"))
                         {
-                            _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
+                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
+                            if (!(tokens.Any() && tokens.Count()>0))
+                            {
+                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
+                            }
                         }
                         else
                         {
-                            _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
+                            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("中国"))
                         {
-                            _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
+                            tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
+                            if (!(tokens.Any() && tokens.Count()>0))
+                            {
+                                tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
+                            }
                         }
                         else
                         {
-                            _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
+                            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))
                     {
-                        _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)
+                    {
+                        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);
         }
 
@@ -1624,6 +1376,7 @@ namespace TEAMModelOS.Controllers
         /// tokenid
         /// </summary>
         public string tid { get; set; }
+        public RegionLngLat point { get; set; }
     }
 
     public class HttpLog
@@ -1644,4 +1397,14 @@ namespace TEAMModelOS.Controllers
         // public string referer { get; set;  }
         public string scope { 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";
+    }
 }

+ 22 - 21
TEAMModelOS/JsonFile/Core/latlng.json

@@ -3,6 +3,7 @@
     "area": "",
     "city": "市辖区",
     "country": "中国",
+    "m": "1",
     "lat": "39.910924547299565",
     "lng": "116.4133836971231",
     "province": "北京市"
@@ -27075,7 +27076,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "油尖旺区",
+    "city": "油尖旺区",
     "lng": "114.173332",
     "lat": "22.311704"
   },
@@ -27083,7 +27084,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "湾仔区",
+    "city": "湾仔区",
     "lng": "114.182915",
     "lat": "22.276389"
   },
@@ -27091,7 +27092,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "北区",
+    "city": "北区",
     "lng": "114.147364",
     "lat": "22.496104"
   },
@@ -27099,7 +27100,7 @@
     "country": "中国",
     "province": "香港特别行政区",
     "area": "龙跃头乡",
-    "name": "北区",
+    "city": "北区",
     "lng": "114.154061",
     "lat": "22.500422"
   },
@@ -27107,7 +27108,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "大埔区",
+    "city": "大埔区",
     "lng": "114.171743",
     "lat": "22.445653"
   },
@@ -27115,7 +27116,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "东区",
+    "city": "东区",
     "lng": "114.226003",
     "lat": "22.279693"
   },
@@ -27123,7 +27124,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "观塘区",
+    "city": "观塘区",
     "lng": "114.214054",
     "lat": "22.320838"
   },
@@ -27131,7 +27132,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "黄大仙区",
+    "city": "黄大仙区",
     "lng": "114.203886",
     "lat": "22.336321"
   },
@@ -27139,7 +27140,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "九龙城区",
+    "city": "九龙城区",
     "lng": "114.192847",
     "lat": "22.31251"
   },
@@ -27147,7 +27148,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "葵青区",
+    "city": "葵青区",
     "lng": "114.139319",
     "lat": "22.363877"
   },
@@ -27155,7 +27156,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "离岛区",
+    "city": "离岛区",
     "lng": "113.94612",
     "lat": "22.286408"
   },
@@ -27163,7 +27164,7 @@
     "country": "中国",
     "province": "香港特别行政区",
     "area": "梅窝乡",
-    "name": "离岛区",
+    "city": "离岛区",
     "lng": "114.000813",
     "lat": "22.264829"
   },
@@ -27171,7 +27172,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "南区",
+    "city": "南区",
     "lng": "114.160012",
     "lat": "22.245897"
   },
@@ -27179,7 +27180,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "荃湾区",
+    "city": "荃湾区",
     "lng": "114.121079",
     "lat": "22.368306"
   },
@@ -27187,7 +27188,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "沙田区",
+    "city": "沙田区",
     "lng": "114.195365",
     "lat": "22.379532"
   },
@@ -27195,7 +27196,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "深水埗区",
+    "city": "深水埗区",
     "lng": "114.163242",
     "lat": "22.333854"
   },
@@ -27203,7 +27204,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "屯门区",
+    "city": "屯门区",
     "lng": "113.976574",
     "lat": "22.393844"
   },
@@ -27211,7 +27212,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "西贡区",
+    "city": "西贡区",
     "lng": "114.264645",
     "lat": "22.314213"
   },
@@ -27219,7 +27220,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "元朗区",
+    "city": "元朗区",
     "lng": "114.032438",
     "lat": "22.441428"
   },
@@ -27227,7 +27228,7 @@
     "country": "中国",
     "province": "香港特别行政区",
     "area": "逢吉乡",
-    "name": "元朗区",
+    "city": "元朗区",
     "lng": "114.063044",
     "lat": "22.45481"
   },
@@ -27235,7 +27236,7 @@
     "area": "",
     "country": "中国",
     "province": "香港特别行政区",
-    "name": "中西区",
+    "city": "中西区",
     "lng": "114.154373",
     "lat": "22.281981"
   },

+ 1 - 1
TEAMModelOS/Startup.cs

@@ -164,7 +164,7 @@ namespace TEAMModelOS
             services.AddHtexTranslator(path);
             services.TryAddSingleton(new Region2LongitudeLatitudeTranslator(path));
             services.AddIPSearcher(path);
-            services.AddSingleton<ISearcher>(new Searcher(CachePolicy.File, Path.Combine(path, "ip2region.xdb")));
+            services.AddSingleton<ISearcher>(new Searcher(CachePolicy.VectorIndex, Path.Combine(path, "ip2region.xdb")));
             services.AddServerSentEvents(o =>
             {
                 o.KeepaliveMode = ServerSentEventsKeepaliveMode.Always;