|
@@ -9,6 +9,8 @@ using OASystem.Infrastructure.Repositories.CRM;
|
|
|
using OASystem.RedisRepository;
|
|
|
using System.Collections;
|
|
|
using System.Data;
|
|
|
+using System.Net;
|
|
|
+using UAParser;
|
|
|
|
|
|
namespace OASystem.API.Controllers
|
|
|
{
|
|
@@ -65,7 +67,7 @@ namespace OASystem.API.Controllers
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost]
|
|
|
- [ApiLog("Crm_NewClientData", OperationEnum.List)]
|
|
|
+ //[ApiLog("Crm_NewClientData", OperationEnum.List)]
|
|
|
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
|
|
|
{
|
|
@@ -78,6 +80,8 @@ namespace OASystem.API.Controllers
|
|
|
#endregion
|
|
|
|
|
|
JsonView jw = new JsonView();
|
|
|
+ var startTime = DateTime.UtcNow;
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
Result resultData = await _clientDataRepository.QueryNewClientData(dto);
|
|
@@ -98,6 +102,94 @@ namespace OASystem.API.Controllers
|
|
|
{
|
|
|
jw = JsonView(false, "程序错误!");
|
|
|
}
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ using var ssg = _sqlSugar.CopyNew();
|
|
|
+ var status = HttpContext.Response.StatusCode.ToString();
|
|
|
+ _ = Task.Run(async () =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string remoteIp = string.Empty,
|
|
|
+ location = string.Empty;
|
|
|
+
|
|
|
+ // 检查请求头中的X-Forwarded-For,以获取真实的客户端IP地址
|
|
|
+ if (HttpContext.Request.Headers.ContainsKey("X-Forwarded-For"))
|
|
|
+ {
|
|
|
+ remoteIp = HttpContext.Request.Headers["X-Forwarded-For"].ToString().Split(',', StringSplitOptions.RemoveEmptyEntries)[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ remoteIp = HttpContext.Connection.RemoteIpAddress?.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ var task = GetIpInfo(remoteIp);
|
|
|
+
|
|
|
+ string deviceType = string.Empty, browser = string.Empty, os = string.Empty;
|
|
|
+ var userAgent = HttpContext.Request.Headers["User-Agent"].FirstOrDefault();
|
|
|
+ if (!string.IsNullOrEmpty(userAgent))
|
|
|
+ {
|
|
|
+ // 解析User-Agent头
|
|
|
+ var parser = Parser.GetDefault();
|
|
|
+ var client = parser.Parse(userAgent);
|
|
|
+
|
|
|
+ // 提取浏览器信息
|
|
|
+ browser = client.UA.Family; // 浏览器名称
|
|
|
+ var browserVersion = client.UA.Major + "." + client.UA.Minor + "." + client.UA.Patch; // 浏览器版本
|
|
|
+ browser += $"({browserVersion})";
|
|
|
+
|
|
|
+ // 提取操作系统信息
|
|
|
+ os = client.OS.Family; // 操作系统名称
|
|
|
+
|
|
|
+ var osVersion = string.Empty; // 操作系统版本
|
|
|
+ if (!string.IsNullOrEmpty(client.OS.Major)) osVersion += client.OS.Major;
|
|
|
+ if (!string.IsNullOrEmpty(client.OS.Minor)) osVersion += "." + client.OS.Minor;
|
|
|
+ if (!string.IsNullOrEmpty(client.OS.Patch)) osVersion += "." + client.OS.Patch;
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(osVersion)) os += $"({osVersion})";
|
|
|
+
|
|
|
+ // 提取设备信息
|
|
|
+ deviceType = client.Device.Family; // 设备类型,如 'mobile', 'tablet', 'desktop' 等
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 记录请求结束时间
|
|
|
+ var endTime = DateTime.UtcNow;
|
|
|
+ // 计算耗时
|
|
|
+ var duration = (long)(endTime - startTime).TotalMilliseconds;
|
|
|
+
|
|
|
+ //等待任务进行
|
|
|
+ (remoteIp, location) = await task;
|
|
|
+
|
|
|
+ //单独记录操作
|
|
|
+ var logInfo = new Crm_TableOperationRecord()
|
|
|
+ {
|
|
|
+ TableName = "Crm_NewClientData",
|
|
|
+ PortType = dto.PortType,
|
|
|
+ OperationItem = OperationEnum.List,
|
|
|
+ DataId = 0,
|
|
|
+ RequestUrl = "/api/MarketCustomerResources/QueryNewClientData",
|
|
|
+ RemoteIp = remoteIp,
|
|
|
+ Location = location,
|
|
|
+ RequestParam = JsonConvert.SerializeObject(dto),
|
|
|
+ ReturnResult = JsonConvert.SerializeObject(jw),
|
|
|
+ Elapsed = duration,
|
|
|
+ Status = status,
|
|
|
+ CreateUserId = dto.OperationUserId,
|
|
|
+ UpdatePreData = "",
|
|
|
+ UpdateBefData = "",
|
|
|
+ Browser = browser,
|
|
|
+ Os = os,
|
|
|
+ DeviceType = deviceType,
|
|
|
+ };
|
|
|
+ // 存储到数据库
|
|
|
+ await ssg.Insertable(logInfo).ExecuteCommandAsync();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
return Ok(jw);
|
|
|
}
|
|
@@ -1466,6 +1558,32 @@ namespace OASystem.API.Controllers
|
|
|
return count > 0 ? Ok(JsonView(true, "分配成功!", count)) : Ok(JsonView(false, "分配失败!"));
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取IP信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="ip">ipv4 or ipv6</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<(string ip, string local)> GetIpInfo(string ip)
|
|
|
+ {
|
|
|
+ string local = string.Empty;
|
|
|
+
|
|
|
+ if (IPAddress.TryParse(ip, out _))
|
|
|
+ {
|
|
|
+ using HttpClient _httpClient = new HttpClient();
|
|
|
+ var response = await _httpClient.GetAsync($"https://api.vore.top/api/IPdata?ip={ip}");
|
|
|
+ response.EnsureSuccessStatusCode();
|
|
|
+ var json = await response.Content.ReadAsStringAsync();
|
|
|
+ var ipInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
|
|
|
+ if (ipInfo.code == 200)
|
|
|
+ {
|
|
|
+ ip = ipInfo.ipinfo.text;
|
|
|
+ local = $"{ipInfo.adcode.o}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return (ip, local);
|
|
|
+ }
|
|
|
+
|
|
|
#region 回滚数据记录
|
|
|
|
|
|
|