From d7eb906a7260de90d7532800c1c7d1d76604069b Mon Sep 17 00:00:00 2001 From: wtp <1813748440@qq.com> Date: Sat, 17 Dec 2022 15:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=BF=BD=E7=95=A5=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- Magic.Core/Service/Log/Dto/ExLogInput.cs | 46 +++++++++++ Magic.Core/Service/Log/Dto/ExLogOutput.cs | 9 +++ Magic.Core/Service/Log/Dto/OpLogInput.cs | 89 +++++++++++++++++++++ Magic.Core/Service/Log/Dto/OpLogOutput.cs | 9 +++ Magic.Core/Service/Log/Dto/VisLogInput.cs | 59 ++++++++++++++ Magic.Core/Service/Log/Dto/VisLogOutput.cs | 9 +++ Magic.Core/Service/Log/ISysExLogService.cs | 10 +++ Magic.Core/Service/Log/ISysOpLogService.cs | 10 +++ Magic.Core/Service/Log/ISysVisLogService.cs | 10 +++ Magic.Core/Service/Log/SysExLogService.cs | 56 +++++++++++++ Magic.Core/Service/Log/SysOpLogService.cs | 55 +++++++++++++ Magic.Core/Service/Log/SysVisLogService.cs | 55 +++++++++++++ 13 files changed, 418 insertions(+), 2 deletions(-) create mode 100644 Magic.Core/Service/Log/Dto/ExLogInput.cs create mode 100644 Magic.Core/Service/Log/Dto/ExLogOutput.cs create mode 100644 Magic.Core/Service/Log/Dto/OpLogInput.cs create mode 100644 Magic.Core/Service/Log/Dto/OpLogOutput.cs create mode 100644 Magic.Core/Service/Log/Dto/VisLogInput.cs create mode 100644 Magic.Core/Service/Log/Dto/VisLogOutput.cs create mode 100644 Magic.Core/Service/Log/ISysExLogService.cs create mode 100644 Magic.Core/Service/Log/ISysOpLogService.cs create mode 100644 Magic.Core/Service/Log/ISysVisLogService.cs create mode 100644 Magic.Core/Service/Log/SysExLogService.cs create mode 100644 Magic.Core/Service/Log/SysOpLogService.cs create mode 100644 Magic.Core/Service/Log/SysVisLogService.cs diff --git a/.gitignore b/.gitignore index 9491a2f..11b826c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,8 +30,7 @@ bld/ [Bb]in/ [Oo]bj/ [Oo]ut/ -[Ll]og/ -[Ll]ogs/ + # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/Magic.Core/Service/Log/Dto/ExLogInput.cs b/Magic.Core/Service/Log/Dto/ExLogInput.cs new file mode 100644 index 0000000..1579780 --- /dev/null +++ b/Magic.Core/Service/Log/Dto/ExLogInput.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace Magic.Core.Service; + +/// +/// 异常日志参数 +/// +public class ExLogInput : PageInputBase +{ + /// + /// 操作人 + /// + public string Account { get; set; } + + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 类名 + /// + public string ClassName { get; set; } + + /// + /// 方法名 + /// + public string MethodName { get; set; } + + /// + /// 异常名称 + /// + public string ExceptionName { get; set; } + + /// + /// 异常信息 + /// + [MaxLength(2000)] + public string ExceptionMsg { get; set; } + + /// + /// 异常时间 + /// + public DateTime ExceptionTime { get; set; } +} diff --git a/Magic.Core/Service/Log/Dto/ExLogOutput.cs b/Magic.Core/Service/Log/Dto/ExLogOutput.cs new file mode 100644 index 0000000..c2a9dd3 --- /dev/null +++ b/Magic.Core/Service/Log/Dto/ExLogOutput.cs @@ -0,0 +1,9 @@ +namespace Magic.Core.Service; + +/// +/// 异常日志参数 +/// +public class ExLogOutput : ExLogInput +{ + +} diff --git a/Magic.Core/Service/Log/Dto/OpLogInput.cs b/Magic.Core/Service/Log/Dto/OpLogInput.cs new file mode 100644 index 0000000..bce4be1 --- /dev/null +++ b/Magic.Core/Service/Log/Dto/OpLogInput.cs @@ -0,0 +1,89 @@ +using System; + +namespace Magic.Core.Service; + +/// +/// 请求日志参数 +/// +public class OpLogInput : PageInputBase +{ + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 是否执行成功(Y-是,N-否) + /// + public YesOrNot Success { get; set; } + + /// + /// 具体消息 + /// + public string Message { get; set; } + + /// + /// ip + /// + public string Ip { get; set; } + + /// + /// 地址 + /// + public string Location { get; set; } + + /// + /// 浏览器 + /// + public string Browser { get; set; } + + /// + /// 操作系统 + /// + public string Os { get; set; } + + /// + /// 请求地址 + /// + public string Url { get; set; } + + /// + /// 类名称 + /// + public string ClassName { get; set; } + + /// + /// 方法名称 + /// + public string MethodName { get; set; } + + /// + /// 请求方式(GET POST PUT DELETE) + /// + public string ReqMethod { get; set; } + + /// + /// 请求参数 + /// + public string Param { get; set; } + + /// + /// 返回结果 + /// + public string Result { get; set; } + + /// + /// 耗时(毫秒) + /// + public long ElapsedTime { get; set; } + + /// + /// 操作时间 + /// + public DateTime OpTime { get; set; } + + /// + /// 操作人 + /// + public string Account { get; set; } +} diff --git a/Magic.Core/Service/Log/Dto/OpLogOutput.cs b/Magic.Core/Service/Log/Dto/OpLogOutput.cs new file mode 100644 index 0000000..b395ee3 --- /dev/null +++ b/Magic.Core/Service/Log/Dto/OpLogOutput.cs @@ -0,0 +1,9 @@ +namespace Magic.Core.Service; + +/// +/// 请求日志参数 +/// +public class OpLogOutput : OpLogInput +{ + +} diff --git a/Magic.Core/Service/Log/Dto/VisLogInput.cs b/Magic.Core/Service/Log/Dto/VisLogInput.cs new file mode 100644 index 0000000..5cc57e9 --- /dev/null +++ b/Magic.Core/Service/Log/Dto/VisLogInput.cs @@ -0,0 +1,59 @@ +using System; + +namespace Magic.Core.Service; + +/// +/// 访问日志参数 +/// +public class VisLogInput : PageInputBase +{ + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 是否执行成功(Y-是,N-否) + /// + public YesOrNot? Success { get; set; } + + /// + /// 具体消息 + /// + public string Message { get; set; } + + /// + /// IP + /// + public string Ip { get; set; } + + /// + /// 地址 + /// + public string Location { get; set; } + + /// + /// 浏览器 + /// + public string Browser { get; set; } + + /// + /// 操作系统 + /// + public string Os { get; set; } + + /// + /// 访问类型 + /// + public LoginType VisType { get; set; } + + /// + /// 访问时间 + /// + public DateTime VisTime { get; set; } + + /// + /// 访问人 + /// + public string Account { get; set; } +} diff --git a/Magic.Core/Service/Log/Dto/VisLogOutput.cs b/Magic.Core/Service/Log/Dto/VisLogOutput.cs new file mode 100644 index 0000000..173201c --- /dev/null +++ b/Magic.Core/Service/Log/Dto/VisLogOutput.cs @@ -0,0 +1,9 @@ +namespace Magic.Core.Service; + +/// +/// 访问日志参数 +/// +public class VisLogOutput : VisLogInput +{ + +} diff --git a/Magic.Core/Service/Log/ISysExLogService.cs b/Magic.Core/Service/Log/ISysExLogService.cs new file mode 100644 index 0000000..9ebb15d --- /dev/null +++ b/Magic.Core/Service/Log/ISysExLogService.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; + +namespace Magic.Core.Service; + +public interface ISysExLogService +{ + Task ClearExLog(); + Task QueryExLogPageList([FromQuery] ExLogInput input); +} diff --git a/Magic.Core/Service/Log/ISysOpLogService.cs b/Magic.Core/Service/Log/ISysOpLogService.cs new file mode 100644 index 0000000..f43406a --- /dev/null +++ b/Magic.Core/Service/Log/ISysOpLogService.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; + +namespace Magic.Core.Service; + +public interface ISysOpLogService +{ + Task ClearOpLog(); + Task QueryOpLogPageList([FromQuery] OpLogInput input); +} diff --git a/Magic.Core/Service/Log/ISysVisLogService.cs b/Magic.Core/Service/Log/ISysVisLogService.cs new file mode 100644 index 0000000..06c87e5 --- /dev/null +++ b/Magic.Core/Service/Log/ISysVisLogService.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; + +namespace Magic.Core.Service; + +public interface ISysVisLogService +{ + Task ClearVisLog(); + Task QueryVisLogPageList([FromQuery] VisLogInput input); +} diff --git a/Magic.Core/Service/Log/SysExLogService.cs b/Magic.Core/Service/Log/SysExLogService.cs new file mode 100644 index 0000000..986d4a3 --- /dev/null +++ b/Magic.Core/Service/Log/SysExLogService.cs @@ -0,0 +1,56 @@ + + +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Magic.Core.Entity; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using System; +using System.Threading.Tasks; + +namespace Magic.Core.Service; + +/// +/// 异常日志服务 +/// +[ApiDescriptionSettings(Name = "ExLog", Order = 100)] +public class SysExLogService : ISysExLogService, IDynamicApiController, ITransient +{ + private readonly SqlSugarRepository _sysExLogRep; // 操作日志表仓储 + + public SysExLogService(SqlSugarRepository sysExLogRep) + { + _sysExLogRep = sysExLogRep; + } + + /// + /// 分页查询异常日志 + /// + /// + /// + [HttpGet("/sysExLog/page")] + public async Task QueryExLogPageList([FromQuery] ExLogInput input) + { + var exLogs = await _sysExLogRep.AsQueryable() + .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim())) + .WhereIF(!string.IsNullOrWhiteSpace(input.ClassName), u => u.ClassName == input.ClassName) + .WhereIF(!string.IsNullOrWhiteSpace(input.MethodName), u => u.MethodName == input.MethodName) + .WhereIF(!string.IsNullOrWhiteSpace(input.ExceptionMsg), u => u.ExceptionMsg.Contains(input.ExceptionMsg.Trim())) + .WhereIF(!string.IsNullOrWhiteSpace(input.SearchBeginTime), u => u.ExceptionTime >= DateTime.Parse(input.SearchBeginTime.Trim()) && + u.ExceptionTime <= DateTime.Parse(input.SearchEndTime.Trim())) + .OrderBy(u => u.Id, OrderByType.Desc) + .Select() + .ToPagedListAsync(input.PageNo, input.PageSize); + return exLogs.XnPagedResult(); + } + + /// + /// 清空异常日志 + /// + /// + [HttpPost("/sysExLog/delete")] + public async Task ClearExLog() + { + await _sysExLogRep.DeleteAsync(m => true); + } +} diff --git a/Magic.Core/Service/Log/SysOpLogService.cs b/Magic.Core/Service/Log/SysOpLogService.cs new file mode 100644 index 0000000..bfd5fd2 --- /dev/null +++ b/Magic.Core/Service/Log/SysOpLogService.cs @@ -0,0 +1,55 @@ + + +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Magic.Core.Entity; +using Microsoft.AspNetCore.Mvc; + +using SqlSugar; +using System; +using System.Threading.Tasks; + +namespace Magic.Core.Service; + +/// +/// 操作日志服务 +/// +[ApiDescriptionSettings(Name = "OpLog", Order = 100)] +public class SysOpLogService : ISysOpLogService, IDynamicApiController, ITransient +{ + private readonly SqlSugarRepository _sysOpLogRep; // 操作日志表仓储 + + public SysOpLogService(SqlSugarRepository sysOpLogRep) + { + _sysOpLogRep = sysOpLogRep; + } + + /// + /// 分页查询操作日志 + /// + /// + /// + [HttpGet("/sysOpLog/page")] + public async Task QueryOpLogPageList([FromQuery] OpLogInput input) + { + var opLogs = await _sysOpLogRep.AsQueryable() + .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim())) + .WhereIF(Enum.IsDefined(typeof(YesOrNot),input.Success), u => u.Success == input.Success) + .WhereIF(!string.IsNullOrWhiteSpace(input.SearchBeginTime), u => u.OpTime >= DateTime.Parse(input.SearchBeginTime.Trim()) && u.OpTime <= DateTime.Parse(input.SearchEndTime.Trim())) + .OrderBy(u => u.Id, OrderByType.Desc) + .Select() + .ToPagedListAsync(input.PageNo, input.PageSize); + + return opLogs.XnPagedResult(); + } + + /// + /// 清空操作日志 + /// + /// + [HttpPost("/sysOpLog/delete")] + public async Task ClearOpLog() + { + await _sysOpLogRep.DeleteAsync(m => true); + } +} diff --git a/Magic.Core/Service/Log/SysVisLogService.cs b/Magic.Core/Service/Log/SysVisLogService.cs new file mode 100644 index 0000000..6d78d31 --- /dev/null +++ b/Magic.Core/Service/Log/SysVisLogService.cs @@ -0,0 +1,55 @@ + + +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Magic.Core.Entity; +using Microsoft.AspNetCore.Mvc; + +using SqlSugar; +using System; +using System.Threading.Tasks; + +namespace Magic.Core.Service; + +/// +/// 访问日志服务 +/// +[ApiDescriptionSettings(Name = "VisLog", Order = 100)] +public class SysVisLogService : ISysVisLogService, IDynamicApiController, ITransient +{ + private readonly SqlSugarRepository _sysVisLogRep; // 访问日志表仓储 + + public SysVisLogService(SqlSugarRepository sysVisLogRep) + { + _sysVisLogRep = sysVisLogRep; + } + + /// + /// 分页查询访问日志 + /// + /// + /// + [HttpGet("/sysVisLog/page")] + public async Task QueryVisLogPageList([FromQuery] VisLogInput input) + { + var visLogs = await _sysVisLogRep.AsQueryable() + .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) + .WhereIF(input.VisType > 0, u => u.VisType == input.VisType) + .WhereIF(input.Success != null && Enum.IsDefined(typeof(YesOrNot), input.Success), u => u.Success == input.Success) + .WhereIF(!string.IsNullOrWhiteSpace(input.SearchBeginTime), u => u.VisTime >= DateTime.Parse(input.SearchBeginTime.Trim()) && u.VisTime <= DateTime.Parse(input.SearchEndTime.Trim())) + .OrderBy(u => u.Id, OrderByType.Desc) + .Select() + .ToPagedListAsync(input.PageNo, input.PageSize); + return visLogs.XnPagedResult(); + } + + /// + /// 清空访问日志 + /// + /// + [HttpPost("/sysVisLog/delete")] + public async Task ClearVisLog() + { + await _sysVisLogRep.DeleteAsync(m => true); + } +}