diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs index 5890bc4a..c9ccd77c 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs @@ -80,16 +80,5 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Error(); } } - - //[HttpGet] - //public async Task ExportFile() - //{ - // var userdata = await _userService.GetAllEntitiesTrueAsync(); - // var userList = userdata.ToList(); - // List header = new() { "用户", "密码", "头像", "昵称", "邮箱", "ip", "年龄", "个人介绍", "地址", "手机", "角色" }; - // var filename = Common.Helper.ExcelHelper.CreateExcelFromList(userList, header, _env.ContentRootPath.ToString()); - // var MimeType = Common.Helper.MimeHelper.GetMimeMapping(filename); - // return new FileStreamResult(new FileStream(Path.Combine(_env.ContentRootPath+@"/wwwroot/excel", filename), FileMode.Open),MimeType); - //} } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs index dc68771a..b797f44a 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs @@ -40,7 +40,6 @@ builder.Host.ConfigureLogging(loggingBuilder => loggingBuilder.AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning); loggingBuilder.AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning); loggingBuilder.AddLog4Net("./Config/Log4net.config"); - }); #region // @@ -71,12 +70,16 @@ builder.Services.AddAutoMapperService(); //+ #endregion builder.Services.AddControllers(optios => { - //optios.Filters.Add(); + //עȫ + optios.Filters.Add(); }).AddJsonFileService(); #region //Ȩ޹ #endregion +//Ȩ builder.Services.AddSingleton(); +//־ +builder.Services.AddSingleton(); #region //Swagger #endregion diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Enum/OperationEnum.cs b/Yi.Framework.Net6/Yi.Framework.Common/Enum/OperationEnum.cs new file mode 100644 index 00000000..6b9c76fc --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Common/Enum/OperationEnum.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Common.Enum +{ + public enum OperationEnum + { + Query, + Insert, + Update, + Delete + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/GlobalLogAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/GlobalLogAttribute.cs new file mode 100644 index 00000000..78687593 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/GlobalLogAttribute.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.WebCore.AttributeExtend +{ + public class GlobalLogAttribute : ActionFilterAttribute + { + private ILogger _logger; + //注入一个日志服务 + public GlobalLogAttribute(ILogger logger) + { + _logger = logger; + } + public override void OnResultExecuted(ResultExecutedContext context) + { + try + { + //查找标签,获取标签对象 + if (context.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor) return; + LogAttribute logAttribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true) + .FirstOrDefault(a => a.GetType().Equals(typeof(LogAttribute))) as LogAttribute; + if (logAttribute == null) return; + + string controller = context.RouteData.Values["Controller"].ToString(); + string action = context.RouteData.Values["Action"].ToString(); + string ip = "127.0.0.1"; + string ipData = "深圳"; + //日志服务插入一条操作记录即可 + } + catch (Exception ex) + { + _logger.LogError(ex, $"操作日志错误:{ex.Message}"); + } + + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/LogAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/LogAttribute.cs new file mode 100644 index 00000000..ea594683 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/LogAttribute.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.IdentityModel.JsonWebTokens; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Yi.Framework.Common.Const; +using Yi.Framework.Common.Enum; + +namespace Yi.Framework.WebCore.AttributeExtend +{ + [AttributeUsage(AttributeTargets.Method)] + public class LogAttribute : Attribute + { + private OperationEnum OperationType { get; set; } + + public LogAttribute(OperationEnum operationType) + { + this.OperationType = operationType; + } + } +} \ No newline at end of file diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs index 65ccb4cd..bd44f95c 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs @@ -26,8 +26,6 @@ namespace Yi.Framework.WebCore.AttributeExtend /// public override void OnActionExecuting(ActionExecutingContext context) { - - if (string.IsNullOrEmpty(permission)) { throw new Exception("权限不能为空!");