3 changed files with 310 additions and 0 deletions
@ -0,0 +1,55 @@ |
|||||||
|
using ATS.NonCustodial.Application.Base; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.AuditLog; |
||||||
|
using ATS.NonCustodial.AuditLogging.AuditLoggings.Services; |
||||||
|
using ATS.NonCustodial.AuditLogging.Dtos.Input; |
||||||
|
using ATS.NonCustodial.AuditLogging.Dtos.Output; |
||||||
|
using ATS.NonCustodial.AuditLogging.EntityFrameworkCore.Entities; |
||||||
|
using ATS.NonCustodial.AuditLogging.Mappers; |
||||||
|
using ATS.NonCustodial.DynamicApi; |
||||||
|
using ATS.NonCustodial.DynamicApi.Attributes; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
|
||||||
|
namespace ATS.NonCustodial.Application.Impl.Logs |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// 审计日志服务 |
||||||
|
/// </summary> |
||||||
|
/// Author:mxg |
||||||
|
/// CreatedTimed:2022-04-25 16:31 |
||||||
|
[DynamicApi(Area = "admin")] |
||||||
|
public class AuditLogService : AdminAppServiceBase, IAuditLogService, IDynamicApi |
||||||
|
{ |
||||||
|
#region Identity |
||||||
|
|
||||||
|
protected readonly IAuditLogRepository<AuditLog> AuditLogRepository; |
||||||
|
|
||||||
|
public AuditLogService(IAuditLogRepository<AuditLog> auditLogRepository) |
||||||
|
{ |
||||||
|
AuditLogRepository = auditLogRepository; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion Identity |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 查询 |
||||||
|
/// </summary> |
||||||
|
/// <param name="filters"></param> |
||||||
|
/// <returns></returns> |
||||||
|
[HttpPost] |
||||||
|
public async Task<AuditLogsDto> GetAsync(AuditLogFilterDto filters) |
||||||
|
{ |
||||||
|
var pagedList = await AuditLogRepository.GetAsync(filters.Event, filters.Source, filters.Category, filters.Created, filters.SubjectIdentifier, filters.SubjectName, filters.Page, filters.PageSize); |
||||||
|
var auditLogsDto = pagedList.ToAuditLogModel(); |
||||||
|
|
||||||
|
return auditLogsDto; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 删除 |
||||||
|
/// </summary> |
||||||
|
/// <param name="deleteOlderThan"></param> |
||||||
|
/// <returns></returns> |
||||||
|
[HttpDelete] |
||||||
|
public virtual async Task DeleteLogsOlderThanAsync(DateTime deleteOlderThan) => await AuditLogRepository.DeleteLogsOlderThanAsync(deleteOlderThan); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,102 @@ |
|||||||
|
using ATS.NonCustodial.Application.Base; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.LoginLog; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.LoginLog.Input; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.LoginLog.Output; |
||||||
|
using ATS.NonCustodial.Domain.Entities.Logs; |
||||||
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore; |
||||||
|
using ATS.NonCustodial.DynamicApi; |
||||||
|
using ATS.NonCustodial.DynamicApi.Attributes; |
||||||
|
using ATS.NonCustodial.Shared.Common.UnifiedResults; |
||||||
|
using ATS.NonCustodial.Shared.Extensions; |
||||||
|
using ATS.NonCustodial.Shared.Helpers; |
||||||
|
using Microsoft.AspNetCore.Http; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
|
||||||
|
namespace ATS.NonCustodial.Application.Impl.Logs |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// 登录日志服务 |
||||||
|
/// </summary> |
||||||
|
/// Author:mxg |
||||||
|
/// CreatedTimed:2022-05-17 10:15 PM |
||||||
|
[DynamicApi(Area = "admin")] |
||||||
|
public class LoginLogService : AdminAppServiceBase, ILoginLogService, IDynamicApi |
||||||
|
{ |
||||||
|
#region Identity |
||||||
|
|
||||||
|
private readonly IHttpContextAccessor _context; |
||||||
|
private readonly IEfRepository<AppLoginLog?, long> _loginLogRepository; |
||||||
|
|
||||||
|
public LoginLogService( |
||||||
|
IHttpContextAccessor context, |
||||||
|
IEfRepository<AppLoginLog?, long> loginLogRepository |
||||||
|
) |
||||||
|
{ |
||||||
|
_context = context; |
||||||
|
_loginLogRepository = loginLogRepository; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion Identity |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 查询登录日志列表 |
||||||
|
/// </summary> |
||||||
|
/// <param name="input"></param> |
||||||
|
/// <returns></returns> |
||||||
|
[HttpPost] |
||||||
|
public async Task<IResultOutput> GetPageAsync(LogGetPageDto input) |
||||||
|
{ |
||||||
|
var express = GetExpression(input, _loginLogRepository.AsQueryable(false, true)); |
||||||
|
var rtn = await base.GetPageAsync<AppLoginLog, LogGetPageDto, LoginLogListOutput>(input, express); |
||||||
|
return ResultOutput.Ok(rtn); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 新增 |
||||||
|
/// </summary> |
||||||
|
/// <param name="input"></param> |
||||||
|
/// <returns></returns> |
||||||
|
public async Task<IResultOutput<long>> AddAsync(LoginLogAddInput input) |
||||||
|
{ |
||||||
|
var res = new ResultOutput<long>(); |
||||||
|
|
||||||
|
input.IP = IPHelper.GetIP(_context?.HttpContext?.Request); |
||||||
|
|
||||||
|
string ua = _context.HttpContext.Request.Headers["User-Agent"]; |
||||||
|
if (ua.NotNull()) |
||||||
|
{ |
||||||
|
var client = UAParser.Parser.GetDefault().Parse(ua); |
||||||
|
var device = client.Device.Family; |
||||||
|
device = device.ToLower() == "other" ? "" : device; |
||||||
|
input.Browser = client.UA.Family; |
||||||
|
input.Os = client.OS.Family; |
||||||
|
input.Device = device; |
||||||
|
input.BrowserInfo = ua; |
||||||
|
} |
||||||
|
var entity = Mapper.Map<AppLoginLog>(input); |
||||||
|
var id = (await _loginLogRepository.InsertAsync(entity)).Id; |
||||||
|
|
||||||
|
return id > 0 ? res.Ok(id) : res; |
||||||
|
} |
||||||
|
|
||||||
|
#region Private |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 查询条件 |
||||||
|
/// </summary> |
||||||
|
/// <param name="pageInput"></param> |
||||||
|
/// <param name="query"></param> |
||||||
|
/// <returns></returns> |
||||||
|
private IQueryable<AppLoginLog> GetExpression(LogGetPageDto pageInput, IQueryable<AppLoginLog?> query) |
||||||
|
{ |
||||||
|
query = query |
||||||
|
.WhereIf(pageInput.OperatorName.NotNull(), w => pageInput.OperatorName.Contains(w.CreatedUserName)); |
||||||
|
|
||||||
|
var express = base.GetEntityAddExpression<AppLoginLog, LogGetPageDto, long>(pageInput, query); |
||||||
|
|
||||||
|
return express; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion Private |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,153 @@ |
|||||||
|
using ATS.NonCustodial.Application.Base; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.LoginLog.Input; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.OprationLog; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.OprationLog.Input; |
||||||
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Logs.OprationLog.Output; |
||||||
|
using ATS.NonCustodial.Domain.Entities.Logs; |
||||||
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos; |
||||||
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore; |
||||||
|
using ATS.NonCustodial.DynamicApi; |
||||||
|
using ATS.NonCustodial.DynamicApi.Attributes; |
||||||
|
using ATS.NonCustodial.Shared.Common.UnifiedResults; |
||||||
|
using ATS.NonCustodial.Shared.Extensions; |
||||||
|
using AutoMapper.QueryableExtensions; |
||||||
|
using Microsoft.AspNetCore.Http; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
using Microsoft.EntityFrameworkCore; |
||||||
|
|
||||||
|
namespace ATS.NonCustodial.Application.Impl.Logs |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// 操作日志服务 |
||||||
|
/// </summary> |
||||||
|
/// Author:mxg |
||||||
|
/// CreatedTimed:2022-05-17 10:11 PM |
||||||
|
[DynamicApi(Area = "admin")] |
||||||
|
public class OperationLogService : AdminAppServiceBase, IOperationLogService, IDynamicApi |
||||||
|
{ |
||||||
|
#region Identity |
||||||
|
|
||||||
|
private readonly IHttpContextAccessor _context; |
||||||
|
private readonly IEfRepository<AppOperationLog?, long> _oprationLogRepository; |
||||||
|
private readonly IAppCaseManagementService _appCaseManagementService; |
||||||
|
|
||||||
|
public OperationLogService( |
||||||
|
IHttpContextAccessor context, |
||||||
|
IEfRepository<AppOperationLog?, long> oprationLogRepository, |
||||||
|
IAppCaseManagementService appCaseManagementService |
||||||
|
) |
||||||
|
{ |
||||||
|
_context = context; |
||||||
|
_oprationLogRepository = oprationLogRepository; |
||||||
|
_appCaseManagementService = appCaseManagementService; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion Identity |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 查询操作日志列表 |
||||||
|
/// </summary> |
||||||
|
/// <param name="input"></param> |
||||||
|
/// <returns></returns> |
||||||
|
[HttpPost] |
||||||
|
public async Task<IResultOutput> GetPageAsync(LogGetPageDto input) |
||||||
|
{ |
||||||
|
var express = await GetExpression(input, _oprationLogRepository.AsQueryable(false, true).Take(3000)); |
||||||
|
var rtn = await base.GetPageAsync<AppOperationLog, LogGetPageDto, OprationLogListOutput>(input, express); |
||||||
|
|
||||||
|
return ResultOutput.Ok(rtn); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 查询操作日志明细 |
||||||
|
/// </summary> |
||||||
|
/// <param name="id"></param> |
||||||
|
/// <returns></returns> |
||||||
|
public async Task<IResultOutput> Get(long id) |
||||||
|
{ |
||||||
|
var rtn = await base.GetAsync<AppOperationLog, OprationLogListOutput, long>(_oprationLogRepository, id); |
||||||
|
return ResultOutput.Ok(rtn); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 新增 |
||||||
|
/// </summary> |
||||||
|
/// <param name="input"></param> |
||||||
|
/// <returns></returns> |
||||||
|
public async Task<IResultOutput> AddAsync(OprationLogAddInput input) |
||||||
|
{ |
||||||
|
string ua = _context.HttpContext!.Request.Headers["User-Agent"]; |
||||||
|
var client = UAParser.Parser.GetDefault().Parse(ua); |
||||||
|
var device = client.Device.Family; |
||||||
|
device = device.ToLower() == "other" ? "" : device; |
||||||
|
input.Browser = client.UA.Family; |
||||||
|
input.Os = client.OS.Family; |
||||||
|
input.Device = device; |
||||||
|
input.BrowserInfo = ua; |
||||||
|
|
||||||
|
input.NickName = User.NickName; |
||||||
|
input.IpAddress = _context.HttpContext.Connection.RemoteIpAddress?.ToString().Replace("::ffff:", "")/*IPHelper.GetIP(_context?.HttpContext?.Request)*/; |
||||||
|
|
||||||
|
var entity = Mapper.Map<AppOperationLog>(input); |
||||||
|
var id = ((await _oprationLogRepository.InsertAsync(entity))!).Id; |
||||||
|
|
||||||
|
return ResultOutput.Result(id > 0); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 业务工作台==>最新5条操作日志 |
||||||
|
/// </summary> |
||||||
|
/// <returns></returns> |
||||||
|
public async Task<IResultOutput> OperationBusinessWorkbench() |
||||||
|
{ |
||||||
|
var userIds = await _appCaseManagementService.GetUserIdListByCurrentUser(); |
||||||
|
|
||||||
|
var dataList = await _oprationLogRepository.AsQueryable(false, true) |
||||||
|
.Where(w => w.CreatedUserId != null && userIds.Contains(w.CreatedUserId.Value)) |
||||||
|
.OrderByDescending(w => w.CreatedTime) |
||||||
|
.Skip(0) |
||||||
|
.Take(5) |
||||||
|
.ProjectTo<OprationLogListOutput>(Mapper.ConfigurationProvider) |
||||||
|
.ToListAsync(); |
||||||
|
return ResultOutput.Ok(dataList); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 批量删除操作日志 |
||||||
|
/// </summary> |
||||||
|
/// <param name="input"></param> |
||||||
|
/// <returns></returns> |
||||||
|
public async Task<IResultOutput> BatchDeleteAsync(BatchIdsInput input) |
||||||
|
{ |
||||||
|
var rtn = await _oprationLogRepository.DeleteAsync(w => input.Ids.Contains(w.Id)); |
||||||
|
|
||||||
|
return ResultOutput.Ok(rtn > 0); |
||||||
|
} |
||||||
|
|
||||||
|
#region Private |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// 查询条件 |
||||||
|
/// </summary> |
||||||
|
/// <param name="pageInput"></param> |
||||||
|
/// <param name="query"></param> |
||||||
|
/// <returns></returns> |
||||||
|
private async Task<IQueryable<AppOperationLog>> GetExpression(LogGetPageDto pageInput, IQueryable<AppOperationLog?> query) |
||||||
|
{ |
||||||
|
var userIds = await _appCaseManagementService.GetUserIdListByCurrentUser(); |
||||||
|
|
||||||
|
query = query |
||||||
|
.Where(w => w.CreatedUserId != null && userIds.Contains(w.CreatedUserId.Value)) |
||||||
|
.WhereIf(pageInput.OperatorName.NotNull(), w => w.CreatedUserName.Contains(pageInput.OperatorName)) |
||||||
|
.WhereIf(pageInput.Device.NotNull(), w => w.Device==pageInput.Device) |
||||||
|
.WhereIf(pageInput.NickName.NotNull(), w => w.NickName==pageInput.NickName); |
||||||
|
|
||||||
|
var express = base.GetEntityAddExpression<AppOperationLog, LogGetPageDto, long>(pageInput, query); |
||||||
|
|
||||||
|
return express; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion Private |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue