using Furion.DatabaseAccessor;
|
using Furion.DependencyInjection;
|
using Furion.DynamicApiController;
|
using iWare.Wms.Core;
|
using Microsoft.AspNetCore.Mvc;
|
using Newtonsoft.Json.Linq;
|
using StackExchange.Redis;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Text.Json;
|
using System.Threading.Tasks;
|
using System.Xml.Linq;
|
|
namespace iWare.Wms.Application
|
{
|
/// <summary>
|
/// 外部访问接口日志
|
/// </summary>
|
//[ApiDescriptionSettings("外部访问接口日志", Name = "AccessInterfaceLog", Order = 100)]
|
//[Route("api/[Controller]")]
|
public class AccessInterfaceLogService : IAccessInterfaceLogService, IDynamicApiController, ITransient
|
{
|
private readonly IRepository<AccessInterfaceLog, MasterDbContextLocator> _accessInterfaceLogRep;
|
|
/// <summary>
|
/// 外部访问接口日志构造
|
/// </summary>
|
/// <param name="accessInterfaceLogRep"></param>
|
public AccessInterfaceLogService(IRepository<AccessInterfaceLog, MasterDbContextLocator> accessInterfaceLogRep)
|
{
|
_accessInterfaceLogRep = accessInterfaceLogRep;
|
}
|
|
/// <summary>
|
/// 添加日志
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
//[HttpPost("Add")]
|
public async Task AddInterfaceLogAsync(AddAccessInterfaceLogInput input)
|
{
|
AccessInterfaceLog log = new();
|
log.Id=input.Id;
|
log.ParaJSON = input.JsonString;
|
log.Action = input.Action;
|
log.IPAddress = input.IpAddress;
|
log.OperateAddress = input.OperateAddress;
|
log.OperateUserId = input.OperateUserId;
|
log.OperateUserName = input.OperateUserName;
|
|
try
|
{
|
// 处理请求参数
|
JObject jsonObject = JObject.Parse(input.JsonString);
|
int count = 0;
|
foreach (JProperty property in jsonObject.Properties())
|
{
|
switch (count)
|
{
|
case 0:
|
log.Param1 = property.Value.ToString();
|
count++;
|
break;
|
case 1:
|
log.Param2 = property.Value.ToString();
|
count++;
|
break;
|
case 2:
|
log.Param3 = property.Value.ToString();
|
count++;
|
break;
|
default:
|
break;
|
}
|
}
|
}
|
catch
|
{
|
log.Param1 = "解析失败";
|
}
|
|
// 处理返回结果
|
var keys = new List<string>();
|
try
|
{
|
//if (input.Result!=null&&input.Result.GetType().IsGenericType && input.Result.GetType().GetGenericTypeDefinition() == typeof(List<>) )
|
//{
|
// PropertyInfo property = input.Result.GetType().GetProperty("Item");
|
// if (property != null)
|
// {
|
// IEnumerable collection = input.Result as IEnumerable;
|
// foreach (var item in collection)
|
// {
|
// PropertyInfo idProperty = item.GetType().GetProperty($"{input.Key}");
|
// if (idProperty == null) continue;
|
// var idValue = idProperty.GetValue(item);
|
// keys.Add(idValue.ToString());
|
// }
|
// }
|
//}
|
//else if(input.Result != null)
|
//{
|
// PropertyInfo idProperty = input.Result.GetType().GetProperty($"{input.Key}");
|
// if (idProperty == null)
|
// {
|
// var idValue = idProperty.GetValue(input.Result);
|
// keys.Add(idValue.ToString());
|
// }
|
//}
|
//log.Keys = string.Join(", ", keys);
|
if(input.Result.GetType().Name.Equals("String"))
|
{
|
log.ResultJson = input.Result.ToString();
|
|
}
|
else
|
{
|
|
log.ResultJson = JsonSerializer.Serialize(input.Result);
|
}
|
|
}
|
catch
|
{
|
log.ResultJson = "日志异常";
|
}
|
//return log;
|
await _accessInterfaceLogRep.InsertNowAsync(log);
|
}
|
}
|
}
|