CrazyIter_Bin 1 năm trước cách đây
mục cha
commit
44489a154f

+ 0 - 1
TEAMModelOS.SDK/DI/AzureCosmos/AzureCosmosExtensions.cs

@@ -16,7 +16,6 @@ using System.Text.Json;
 using System.Net;
 using System.Linq.Expressions;
 using TEAMModelOS.SDK;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;

+ 1 - 2
TEAMModelOS.SDK/Helper/Common/JsonHelper/JsonParser.cs

@@ -22,7 +22,7 @@ namespace TEAMModelOS.SDK.Helper.Common.JsonHelper
         public static T[] As<T>(this JsonPathNode[] nodes, T prototype) { return nodes.Select(node => node.As<T>()).ToArray(); }
     }
 
-    public delegate object JsonPathScriptEvaluator(string script, object value,IJsonPathContext context);
+    public delegate object JsonPathScriptEvaluator(string script, object value, IJsonPathContext context);
 
     public sealed class JsonPathSelection
     {
@@ -1788,4 +1788,3 @@ namespace TEAMModelOS.SDK.Helper.Common.JsonHelper
 // THE SOFTWARE.
 //
 #endregion
- 

+ 1 - 1
TEAMModelOS.SDK/Helper/Common/JsonHelper/JsonPath/IJsonPathValueSystem.cs

@@ -4,7 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 
-namespace TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath
+namespace TEAMModelOS.SDK
 {
     public interface IJsonPathValueSystem
     {

+ 70 - 0
TEAMModelOS.SDK/Helper/Common/JsonHelper/JsonPath/JsonNetValueSystem.cs

@@ -0,0 +1,70 @@
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK
+{
+   public sealed class JsonNetValueSystem : IJsonPathValueSystem
+    {
+        public bool HasMember(object value, string member)
+        {
+            if (value is JObject)
+                return (value as JObject).Properties().Any(property => property.Name == member);
+            if (value is JArray)
+            {
+                int index = ParseInt(member, -1);
+                return index >= 0 && index < (value as JArray).Count;
+            }
+            return false;
+        }
+
+        public object GetMemberValue(object value, string member)
+        {
+            if (value is JObject)
+            {
+                var memberValue = (value as JObject)[member];
+                return memberValue;
+            }
+            if (value is JArray)
+            {
+                int index = ParseInt(member, -1);
+                return (value as JArray)[index];
+            }
+            return null;
+        }
+
+        public IEnumerable GetMembers(object value)
+        {
+            var jobject = value as JObject;
+            return jobject.Properties().Select(property => property.Name);
+        }
+
+        public bool IsObject(object value)
+        {
+            return value is JObject;
+        }
+
+        public bool IsArray(object value)
+        {
+            return value is JArray;
+        }
+
+        public bool IsPrimitive(object value)
+        {
+            if (value == null)
+                throw new ArgumentNullException("value");
+
+            return value is JObject || value is JArray ? false : true;
+        }
+
+        private int ParseInt(string s, int defaultValue)
+        {
+            int result;
+            return int.TryParse(s, out result) ? result : defaultValue;
+        }
+    }
+}

+ 1 - 1
TEAMModelOS.SDK/Helper/Common/JsonHelper/JsonPath/JsonPathContext.cs

@@ -9,7 +9,7 @@ using System.Text.Json;
 using System.Text.RegularExpressions;
 using TEAMModelOS.SDK;
 
-namespace TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath
+namespace TEAMModelOS.SDK
 {
     /// <summary>
     /// 语法文档  https://www.cnblogs.com/aoyihuashao/p/8665873.html

+ 2 - 3
TEAMModelOS.SDK/Helper/Common/JsonHelper/JsonPath/JsonApiValueSystem.cs

@@ -5,9 +5,8 @@ using System.Linq;
 using System.Text.Json;
 using System.Threading.Tasks;
 
-namespace TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath
-{
-    public class JsonApiValueSystem : IJsonPathValueSystem
+namespace TEAMModelOS.SDK { 
+    public class JsonTextValueSystem : IJsonPathValueSystem
     {
         public bool HasMember(object value, string member)
         {

+ 0 - 1
TEAMModelOS.SDK/Helper/Security/RSACrypt/RsaHelper.cs

@@ -4,7 +4,6 @@ using System.Collections.Generic;
 using System.IO;
 using System.Security.Cryptography;
 using System.Text;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 
 namespace TEAMModelOS.SDK.Helper.Security.RSACrypt
 {

+ 0 - 2
TEAMModelOS/Controllers/Analysis/ChangeController.cs

@@ -11,8 +11,6 @@ using System.Threading.Tasks;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
 using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Module.AzureBlob.Container;
 using TEAMModelOS.SDK.Models;

+ 0 - 1
TEAMModelOS/Controllers/Both/SyllabusController.cs

@@ -6,7 +6,6 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK;
 using System;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using System.Linq;
 using TEAMModelOS.Models;
 using System.Text.Json;

+ 115 - 31
TEAMModelOS/Controllers/System/BillController.cs

@@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.Azure.Amqp.Framing;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Options;
+using Newtonsoft.Json.Linq;
 using NUnit.Framework;
 using OfficeOpenXml;
 using OpenXmlPowerTools;
@@ -29,6 +30,7 @@ using System.Net.Http;
 using System.Runtime.Intrinsics.Arm;
 using System.Text;
 using System.Text.Json;
+using System.Text.Json.Nodes;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Web;
@@ -37,8 +39,6 @@ using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
 using TEAMModelOS.SDK.IP2Region;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 using Top.Api;
@@ -59,7 +59,8 @@ namespace TEAMModelOS.Controllers
         private readonly AzureRedisFactory _azureRedis;
         private readonly ISearcher _ipSearcher;
         private readonly Option _option;
-        public BillController(IHttpClientFactory httpClient, IConfiguration configuration, AzureStorageFactory azureStorage, ISearcher searcher, DingDing dingDing, IOptionsSnapshot<Option> option)
+        private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
+        public BillController(Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator,IHttpClientFactory httpClient, IConfiguration configuration, AzureStorageFactory azureStorage, ISearcher searcher, DingDing dingDing, IOptionsSnapshot<Option> option)
         {
             _httpClient = httpClient;
             _configuration = configuration;
@@ -67,6 +68,7 @@ namespace TEAMModelOS.Controllers
             _ipSearcher = searcher;
             _dingDing = dingDing;
             _option = option.Value;
+            _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
         }
         /// <summary>
         /// 使用时长,一天内累计
@@ -79,16 +81,61 @@ namespace TEAMModelOS.Controllers
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<IActionResult> ReportApi(JsonElement json)
         {
-            var reg = _ipSearcher.SearchIp(json.GetProperty("ip").GetString());
-            var untyped = new JsonParser().Parse(json.GetRawText());
-            var selection = new JsonPathSelection(untyped);
             {
-                var nodes_id_token = selection.SelectNodes(json.GetProperty("path").GetString());
+                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());
+            foreach (var t in tks)
+            {
+                var s = $"{t}";
+            }
+
+            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.Value is string)
+                    if (node is string)
                     {
-                        Console.WriteLine(node.Value);
+                        Console.WriteLine(node);
                     }
                     else
                     {
@@ -97,6 +144,7 @@ namespace TEAMModelOS.Controllers
                 }
                 //return Ok(nodes_id_token);
             }
+            var reg = _ipSearcher.SearchIp(json.GetProperty("ip").GetString());
             List<string> times = json.GetProperty("times").ToObject<List<string>>();
             foreach (var time in times)
             {
@@ -217,15 +265,19 @@ namespace TEAMModelOS.Controllers
                 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 untyped = new JsonParser().Parse(log.param.GetRawText());
-                    var selection = new JsonPathSelection(untyped);
+                   
+                    //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]";
 
-                    var nodes_path = selection.SelectNodes(path);
+                    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.Value is string)
+                        if (node.Type.Equals(JTokenType.String))
                         {
                             switch (true)
                             {
@@ -233,7 +285,7 @@ namespace TEAMModelOS.Controllers
                                     {
                                         try
                                         {
-                                            var jwt = new JwtSecurityToken($"{node.Value}");
+                                            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))
@@ -248,23 +300,23 @@ namespace TEAMModelOS.Controllers
                                 ||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.Value}") && long.TryParse($"{node.Value}", out long _id))
+                                        if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
                                         {
-                                            useridMatch.Add($"{node.Value}");
+                                            useridMatch.Add($"{node}");
                                         }
                                         break;
                                     }
                                 case bool when node.Path.Contains("code"):
                                     {
-                                        if (!string.IsNullOrWhiteSpace($"{node.Value}"))
+                                        if (!string.IsNullOrWhiteSpace($"{node}"))
                                         {
-                                            if (long.TryParse($"{node.Value}", out long _id))
+                                            if (long.TryParse($"{node}", out long _id))
                                             {
-                                                useridMatch.Add($"{node.Value}");
+                                                useridMatch.Add($"{node}");
                                             }
                                             else
                                             {
-                                                string[] codes = $"{node.Value}".Split("-");
+                                                string[] codes = $"{node}".Split("-");
                                                 foreach (var _code in codes)
                                                 {
                                                     if (long.TryParse(_code, out long _codeid))
@@ -460,15 +512,18 @@ namespace TEAMModelOS.Controllers
                 }
                 if (string.IsNullOrWhiteSpace(vist.school))
                 {
-                    var untyped = new JsonParser().Parse(log.param.GetRawText());
-                    var selection = new JsonPathSelection(untyped);
-
                     string path = "$..[school,id,schoolId,schoolid,schoolCode,school_code,schoolcode,code]";
-                    var nodes_path = selection.SelectNodes(path);
+                    //var jsonPathContext = new JsonPathContext();
+                    //jsonPathContext.ValueSystem= new JsonTextValueSystem();
+                    //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
+                    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.Value is string)
+                        if (node.Type.Equals(JTokenType.String) )
                         {
                             switch (true)
                             {
@@ -477,16 +532,16 @@ namespace TEAMModelOS.Controllers
                                     { break; }
                                 case bool when node.Path.Contains("code"):
                                     {
-                                        if (!$"{node.Value}".Contains("-")&&  $"{node.Value}".Length<=8)
+                                        if (!$"{node}".Contains("-")&&  $"{node}".Length<=8)
                                         {
-                                            schoolMatch.Add($"{node.Value}");
+                                            schoolMatch.Add($"{node}");
                                         }
                                         else
                                         {
-                                            string[] codes = $"{node.Value}".Split("-");
+                                            string[] codes = $"{node}".Split("-");
                                             foreach (var _code in codes)
                                             {
-                                                if ($"{node.Value}".Length<=8)
+                                                if ($"{node}".Length<=8)
                                                 {
                                                     schoolMatch.Add($"{_code}");
                                                     break;
@@ -838,8 +893,37 @@ namespace TEAMModelOS.Controllers
                     }
                 }
                 //处理地区转经纬度
-                { 
-                   
+                {
+                    if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province)  && !string.IsNullOrWhiteSpace(vist.area))
+                    {
+                        _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("中国"))
+                        {
+                            _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
+                        }
+                        else
+                        {
+                            _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)]");
+                        }
+                        else
+                        {
+                            _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)]");
+                    }
                 }
                 vist.host= log.host;
                 vist.hostName=log.hostName;

+ 0 - 1
TEAMModelOS/Controllers/System/BlobController.cs

@@ -6,7 +6,6 @@ using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 using TEAMModelOS.SDK.DI;
 using System.Net.Http;

+ 0 - 1
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -54,7 +54,6 @@ using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;

+ 4 - 1
TEAMModelOS/Filter/IpToRegion.cs

@@ -12,6 +12,10 @@ namespace TEAMModelOS
             {
                 ip = "127.0.0.1";
             }
+            if (ip.Equals("0:0:0:0:0:0:0:1"))
+            {
+                ip = "127.0.0.1";
+            }
             try
             {
                 string region = _ipSearcher.Search(ip);
@@ -25,7 +29,6 @@ namespace TEAMModelOS
                     return region;
                 }
                 else { return null; }
-
             }
             catch (Exception)
             {

+ 7 - 3
TEAMModelOS/Filter/Region2LongitudeLatitudeTranslator.cs

@@ -1,13 +1,16 @@
-using System.IO;
+using Newtonsoft.Json.Linq;
+using System.IO;
 using System.Text;
 using System.Text.Json;
 using TEAMModelOS.SDK.Extension;
+using Top.Api;
 
 namespace TEAMModelOS.Filter
 {
     public class Region2LongitudeLatitudeTranslator
     {
-        public readonly JsonElement regionJson;
+
+        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);
             StringBuilder stringBuilder = new StringBuilder();
@@ -18,7 +21,8 @@ namespace TEAMModelOS.Filter
             }
             streamReader.Close();
             string input = stringBuilder.ToString();
-            input.ToObject<JsonElement>();
+            regionJson=  JArray.Parse(input);
+           
         }
     }
 }

BIN
TEAMModelOS/JsonFile/Core/ip2region.xdb


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 3990 - 0
TEAMModelOS/JsonFile/Core/latlng.json


+ 1 - 1
TEAMModelOS/TEAMModelOS.csproj

@@ -8,7 +8,7 @@
 	<PackageReference Include="DinkToPdf" Version="1.0.8" />
 	<PackageReference Include="EPPlus" Version="6.2.6" />
 	<PackageReference Include="IP2Region.Net" Version="2.0.2" />
-	<PackageReference Include="JsonPath.Net" Version="0.7.1" />
+	<PackageReference Include="JsonPath.Net" Version="1.0.0" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
 	<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="2.20.0" />
 	<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />