|
@@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
+using Newtonsoft.Json.Linq;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework;
|
|
using OfficeOpenXml;
|
|
using OfficeOpenXml;
|
|
using OpenXmlPowerTools;
|
|
using OpenXmlPowerTools;
|
|
@@ -29,6 +30,7 @@ using System.Net.Http;
|
|
using System.Runtime.Intrinsics.Arm;
|
|
using System.Runtime.Intrinsics.Arm;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
|
|
+using System.Text.Json.Nodes;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web;
|
|
@@ -37,8 +39,6 @@ using TEAMModelOS.Models;
|
|
using TEAMModelOS.SDK;
|
|
using TEAMModelOS.SDK;
|
|
using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Extension;
|
|
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
|
|
|
|
-using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
|
|
|
|
using TEAMModelOS.SDK.IP2Region;
|
|
using TEAMModelOS.SDK.IP2Region;
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
|
|
using Top.Api;
|
|
using Top.Api;
|
|
@@ -59,7 +59,8 @@ namespace TEAMModelOS.Controllers
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private readonly ISearcher _ipSearcher;
|
|
private readonly ISearcher _ipSearcher;
|
|
private readonly Option _option;
|
|
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;
|
|
_httpClient = httpClient;
|
|
_configuration = configuration;
|
|
_configuration = configuration;
|
|
@@ -67,6 +68,7 @@ namespace TEAMModelOS.Controllers
|
|
_ipSearcher = searcher;
|
|
_ipSearcher = searcher;
|
|
_dingDing = dingDing;
|
|
_dingDing = dingDing;
|
|
_option = option.Value;
|
|
_option = option.Value;
|
|
|
|
+ _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 使用时长,一天内累计
|
|
/// 使用时长,一天内累计
|
|
@@ -79,16 +81,61 @@ namespace TEAMModelOS.Controllers
|
|
[RequestSizeLimit(102_400_000_00)] //最大10000m左右
|
|
[RequestSizeLimit(102_400_000_00)] //最大10000m左右
|
|
public async Task<IActionResult> ReportApi(JsonElement json)
|
|
public async Task<IActionResult> ReportApi(JsonElement json)
|
|
{
|
|
{
|
|
- var 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)
|
|
foreach (var node in nodes_id_token)
|
|
{
|
|
{
|
|
- if (node.Value is string)
|
|
|
|
|
|
+ if (node is string)
|
|
{
|
|
{
|
|
- Console.WriteLine(node.Value);
|
|
|
|
|
|
+ Console.WriteLine(node);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -97,6 +144,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
//return Ok(nodes_id_token);
|
|
//return Ok(nodes_id_token);
|
|
}
|
|
}
|
|
|
|
+ var reg = _ipSearcher.SearchIp(json.GetProperty("ip").GetString());
|
|
List<string> times = json.GetProperty("times").ToObject<List<string>>();
|
|
List<string> times = json.GetProperty("times").ToObject<List<string>>();
|
|
foreach (var time in times)
|
|
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 };
|
|
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))
|
|
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]";
|
|
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)
|
|
foreach (var node in nodes_path)
|
|
{
|
|
{
|
|
// 只获取是字符串的
|
|
// 只获取是字符串的
|
|
- if (node.Value is string)
|
|
|
|
|
|
+ if (node.Type.Equals(JTokenType.String))
|
|
{
|
|
{
|
|
switch (true)
|
|
switch (true)
|
|
{
|
|
{
|
|
@@ -233,7 +285,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- var jwt = new JwtSecurityToken($"{node.Value}");
|
|
|
|
|
|
+ var jwt = new JwtSecurityToken($"{node}");
|
|
string id = jwt.Payload.Sub;
|
|
string id = jwt.Payload.Sub;
|
|
var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
|
|
var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
|
|
if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
|
|
if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
|
|
@@ -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("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
|
|
||node.Path.Contains("userId")||node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
|
|
||node.Path.Contains("userId")||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;
|
|
break;
|
|
}
|
|
}
|
|
case bool when node.Path.Contains("code"):
|
|
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
|
|
else
|
|
{
|
|
{
|
|
- string[] codes = $"{node.Value}".Split("-");
|
|
|
|
|
|
+ string[] codes = $"{node}".Split("-");
|
|
foreach (var _code in codes)
|
|
foreach (var _code in codes)
|
|
{
|
|
{
|
|
if (long.TryParse(_code, out long _codeid))
|
|
if (long.TryParse(_code, out long _codeid))
|
|
@@ -460,15 +512,18 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
if (string.IsNullOrWhiteSpace(vist.school))
|
|
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]";
|
|
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)
|
|
foreach (var node in nodes_path)
|
|
{
|
|
{
|
|
// 只获取是字符串的
|
|
// 只获取是字符串的
|
|
- if (node.Value is string)
|
|
|
|
|
|
+ if (node.Type.Equals(JTokenType.String) )
|
|
{
|
|
{
|
|
switch (true)
|
|
switch (true)
|
|
{
|
|
{
|
|
@@ -477,16 +532,16 @@ namespace TEAMModelOS.Controllers
|
|
{ break; }
|
|
{ break; }
|
|
case bool when node.Path.Contains("code"):
|
|
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
|
|
else
|
|
{
|
|
{
|
|
- string[] codes = $"{node.Value}".Split("-");
|
|
|
|
|
|
+ string[] codes = $"{node}".Split("-");
|
|
foreach (var _code in codes)
|
|
foreach (var _code in codes)
|
|
{
|
|
{
|
|
- if ($"{node.Value}".Length<=8)
|
|
|
|
|
|
+ if ($"{node}".Length<=8)
|
|
{
|
|
{
|
|
schoolMatch.Add($"{_code}");
|
|
schoolMatch.Add($"{_code}");
|
|
break;
|
|
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.host= log.host;
|
|
vist.hostName=log.hostName;
|
|
vist.hostName=log.hostName;
|