update 操作日志完善
This commit is contained in:
@@ -8,6 +8,8 @@ using System.Diagnostics;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using UAParser;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -34,12 +36,29 @@ namespace Ewide.Core
|
||||
var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
|
||||
var descAtt = Attribute.GetCustomAttribute(actionDescriptor.MethodInfo, typeof(DescriptionAttribute)) as DescriptionAttribute;
|
||||
|
||||
var message = "请求成功";
|
||||
if (isRequestSucceed)
|
||||
{
|
||||
var result = actionContext.Result;
|
||||
var resultType = result.GetType();
|
||||
if (resultType.Name == "ContentResult")
|
||||
{
|
||||
var resultContent = ((Microsoft.AspNetCore.Mvc.ContentResult)actionContext.Result)?.Content;
|
||||
var resultJson = JsonConvert.DeserializeObject<JObject>(resultContent);
|
||||
message = resultJson["message"]?.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message = actionContext.Exception.Message;
|
||||
}
|
||||
|
||||
var sysOpLog = new SysLogOp
|
||||
{
|
||||
Name = descAtt != null ? descAtt.Description : actionDescriptor.ActionName,
|
||||
OpType = 1,
|
||||
Success = isRequestSucceed,
|
||||
//Message = isRequestSucceed ? "成功" : "失败",
|
||||
Message = message,
|
||||
Ip = httpContext.GetRemoteIpAddressToIPv4(),
|
||||
Location = httpRequest.GetRequestUrlAddress(),
|
||||
Browser = clent.UA.Family + clent.UA.Major,
|
||||
@@ -48,13 +67,13 @@ namespace Ewide.Core
|
||||
ClassName = context.Controller.ToString(),
|
||||
MethodName = actionDescriptor.ActionName,
|
||||
ReqMethod = httpRequest.Method,
|
||||
//Param = JsonSerializerUtility.Serialize(context.ActionArguments),
|
||||
//Result = JsonSerializerUtility.Serialize(actionContext.Result),
|
||||
Param = JsonConvert.SerializeObject(context.ActionArguments),
|
||||
// Result = resultContent,
|
||||
ElapsedTime = sw.ElapsedMilliseconds,
|
||||
OpTime = DateTime.Now,
|
||||
Account = httpContext.User?.FindFirstValue(ClaimConst.CLAINM_ACCOUNT)
|
||||
};
|
||||
await sysOpLog.InsertAsync();
|
||||
await sysOpLog.();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,24 @@ namespace Ewide.Core.Service
|
||||
// 设置刷新Token令牌
|
||||
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
|
||||
|
||||
// 增加登录日志
|
||||
var loginOutput = user.Adapt<LoginOutput>();
|
||||
var clent = Parser.GetDefault().Parse(App.GetService<IHttpContextAccessor>().HttpContext.Request.Headers["User-Agent"]);
|
||||
loginOutput.LastLoginBrowser = clent.UA.Family + clent.UA.Major;
|
||||
loginOutput.LastLoginOs = clent.OS.Family + clent.OS.Major;
|
||||
await new SysLogVis
|
||||
{
|
||||
Name = "登录",
|
||||
Success = true,
|
||||
Message = "登录成功",
|
||||
Ip = loginOutput.LastLoginIp,
|
||||
Browser = loginOutput.LastLoginBrowser,
|
||||
Os = loginOutput.LastLoginOs,
|
||||
VisType = 1,
|
||||
VisTime = loginOutput.LastLoginTime,
|
||||
Account = loginOutput.Account
|
||||
}.InsertAsync();
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@@ -163,20 +181,6 @@ namespace Ewide.Core.Service
|
||||
loginOutput.Menus = await _sysMenuService.GetLoginMenusAntDesign(userId, defaultActiveAppCode);
|
||||
}
|
||||
|
||||
// 增加登录日志
|
||||
//await new SysLogVis
|
||||
//{
|
||||
// Name = "登录",
|
||||
// Success = true,
|
||||
// Message = "登录成功",
|
||||
// Ip = loginOutput.LastLoginIp,
|
||||
// Browser = loginOutput.LastLoginBrowser,
|
||||
// Os = loginOutput.LastLoginOs,
|
||||
// VisType = 1,
|
||||
// VisTime = loginOutput.LastLoginTime,
|
||||
// Account = loginOutput.Account
|
||||
//}.InsertAsync();
|
||||
|
||||
return loginOutput;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Ewide.Core.Extension;
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
@@ -20,10 +21,12 @@ namespace Ewide.Core.Service
|
||||
public class SysOpLogService : ISysOpLogService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysLogOp> _sysOpLogRep; // 操作日志表仓储
|
||||
private readonly IDapperRepository<SysLogOp> _dapperRepository;
|
||||
|
||||
public SysOpLogService(IRepository<SysLogOp> sysOpLogRep)
|
||||
public SysOpLogService(IRepository<SysLogOp> sysOpLogRep, IDapperRepository<SysLogOp> dapperRepository)
|
||||
{
|
||||
_sysOpLogRep = sysOpLogRep;
|
||||
_dapperRepository = dapperRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,11 +57,7 @@ namespace Ewide.Core.Service
|
||||
[HttpPost("/sysOpLog/delete")]
|
||||
public async Task ClearOpLog()
|
||||
{
|
||||
var opLogs = await _sysOpLogRep.Entities.ToListAsync();
|
||||
opLogs.ForEach(u =>
|
||||
{
|
||||
u.Delete();
|
||||
});
|
||||
await _dapperRepository.ExecuteAsync("DELETE FROM sys_log_op");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Ewide.Core.Service
|
||||
.Where(u => u.Status == (int)CommonStatus.ENABLE)
|
||||
.Where(u => u.Application == appCode)
|
||||
.Where(u => u.Type != (int)MenuType.BTN)
|
||||
//.Where(u => u.Weight != (int)MenuWeight.DEFAULT_WEIGHT)
|
||||
.Where(u => u.Weight != (int)MenuWeight.DEFAULT_WEIGHT)
|
||||
.OrderBy(u => u.Sort).ToListAsync();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user