diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 7fb5dc8..8789282 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -1,19 +1,14 @@ using Infrastructure; using Infrastructure.Attribute; -using Infrastructure.Model; using IPTools.Core; using Lazy.Captcha.Core; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -using System; -using System.Collections.Generic; using UAParser; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Framework; -using ZR.Common; using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Service.System; diff --git a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs index 1027660..e5a7ec1 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs @@ -11,6 +11,7 @@ using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Hubs; using ZR.Common; +using ZR.Model; using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Service.System.IService; @@ -58,13 +59,7 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:notice:list")] public IActionResult QuerySysNotice([FromQuery] SysNoticeQueryDto parm) { - var predicate = Expressionable.Create(); - - predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.NoticeTitle), m => m.NoticeTitle.Contains(parm.NoticeTitle)); - predicate = predicate.AndIF(parm.NoticeType != null, m => m.NoticeType == parm.NoticeType); - predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CreateBy), m => m.Create_by.Contains(parm.CreateBy) || m.Update_by.Contains(parm.CreateBy)); - predicate = predicate.AndIF(parm.Status != null, m => m.Status == parm.Status); - var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm); + PagedInfo response = _SysNoticeService.GetPageList(parm); return SUCCESS(response); } @@ -74,7 +69,6 @@ namespace ZR.Admin.WebApi.Controllers.System /// /// [HttpGet("{NoticeId}")] - [ActionPermissionFilter(Permission = "system:notice:query")] public IActionResult GetSysNotice(int NoticeId) { var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId); @@ -92,9 +86,7 @@ namespace ZR.Admin.WebApi.Controllers.System public IActionResult AddSysNotice([FromBody] SysNoticeDto parm) { var modal = parm.Adapt().ToCreate(HttpContext); - modal.Create_by = HttpContext.GetName(); - modal.Create_time = DateTime.Now; - + int result = _SysNoticeService.Insert(modal, it => new { it.NoticeTitle, diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index f9820fd..b1e9c91 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -1,7 +1,9 @@ -using Infrastructure; +using Aliyun.OSS; +using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Extensions; +using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using ZR.Admin.WebApi.Extensions; @@ -71,8 +73,8 @@ namespace ZR.Admin.WebApi.Controllers.System { throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } - - post.Create_by = HttpContext.GetName(); + post.ToCreate(HttpContext); + return ToResponse(PostService.Add(post)); } @@ -94,7 +96,7 @@ namespace ZR.Admin.WebApi.Controllers.System { throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } - post.Update_by = HttpContext.GetName(); + post.ToUpdate(HttpContext); return ToResponse(PostService.Update(post)); } diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index 20d7023..1a96758 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -1,4 +1,6 @@  +using System.Reflection; + namespace ZR.Admin.WebApi.Extensions { public static class EntityExtension @@ -7,26 +9,14 @@ namespace ZR.Admin.WebApi.Extensions { var types = source?.GetType(); if (types == null) return source; + BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance; + + types.GetProperty("CreateTime", flag)?.SetValue(source, DateTime.Now, null); + types.GetProperty("AddTime", flag)?.SetValue(source, DateTime.Now, null); + types.GetProperty("CreateBy", flag)?.SetValue(source, context.GetName(), null); + types.GetProperty("Create_by", flag)?.SetValue(source, context.GetName(), null); + types.GetProperty("UserId", flag)?.SetValue(source, context.GetUId(), null); - types.GetProperty("CreateTime")?.SetValue(source, DateTime.Now, null); - types.GetProperty("AddTime")?.SetValue(source, DateTime.Now, null); - types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); - if (types.GetProperty("Create_by") != null && context != null) - { - types.GetProperty("Create_by")?.SetValue(source, context.GetName(), null); - } - if (types.GetProperty("Create_By") != null && context != null) - { - types.GetProperty("Create_By")?.SetValue(source, context.GetName(), null); - } - if (types.GetProperty("CreateBy") != null && context != null) - { - types.GetProperty("CreateBy")?.SetValue(source, context.GetName(), null); - } - if (types.GetProperty("UserId") != null && context != null) - { - types.GetProperty("UserId")?.SetValue(source, context.GetUId(), null); - } return source; } @@ -34,12 +24,12 @@ namespace ZR.Admin.WebApi.Extensions { var types = source?.GetType(); if (types == null) return source; + BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance; - types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); - types.GetProperty("Update_time")?.SetValue(source, DateTime.Now, null); - - types.GetProperty("UpdateBy")?.SetValue(source,context.GetName(), null); - types.GetProperty("Update_by")?.SetValue(source, context.GetName(), null); + types.GetProperty("UpdateTime", flag)?.SetValue(source, DateTime.Now, null); + types.GetProperty("Update_time", flag)?.SetValue(source, DateTime.Now, null); + types.GetProperty("UpdateBy", flag)?.SetValue(source, context.GetName(), null); + types.GetProperty("Update_by", flag)?.SetValue(source, context.GetName(), null); return source; } diff --git a/ZR.Service/System/IService/ISysNoticeService.cs b/ZR.Service/System/IService/ISysNoticeService.cs index 8c8a53b..2544aa8 100644 --- a/ZR.Service/System/IService/ISysNoticeService.cs +++ b/ZR.Service/System/IService/ISysNoticeService.cs @@ -1,6 +1,7 @@ -using System; using System.Collections.Generic; +using ZR.Model; using ZR.Model.System; +using ZR.Model.System.Dto; namespace ZR.Service.System.IService { @@ -10,8 +11,10 @@ namespace ZR.Service.System.IService /// @author zr /// @date 2021-12-15 /// - public interface ISysNoticeService: IBaseService + public interface ISysNoticeService : IBaseService { List GetSysNotices(); + + PagedInfo GetPageList(SysNoticeQueryDto parm); } } diff --git a/ZR.Service/System/SysNoticeService.cs b/ZR.Service/System/SysNoticeService.cs index 168297a..7c938a0 100644 --- a/ZR.Service/System/SysNoticeService.cs +++ b/ZR.Service/System/SysNoticeService.cs @@ -1,8 +1,9 @@ using Infrastructure.Attribute; using SqlSugar; using System.Collections.Generic; -using ZR.Model.Models; +using ZR.Model; using ZR.Model.System; +using ZR.Model.System.Dto; using ZR.Service.System.IService; namespace ZR.Service.System @@ -24,12 +25,25 @@ namespace ZR.Service.System /// public List GetSysNotices() { - //开始拼装查询条件 var predicate = Expressionable.Create(); - //搜索条件查询语法参考Sqlsugar predicate = predicate.And(m => m.Status == 0); - return GetList(predicate.ToExpression()); + return Queryable() + .Where(predicate.ToExpression()) + .OrderByDescending(f => f.Create_time) + .ToList(); + } + + public PagedInfo GetPageList(SysNoticeQueryDto parm) + { + var predicate = Expressionable.Create(); + + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.NoticeTitle), m => m.NoticeTitle.Contains(parm.NoticeTitle)); + predicate = predicate.AndIF(parm.NoticeType != null, m => m.NoticeType == parm.NoticeType); + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CreateBy), m => m.Create_by.Contains(parm.CreateBy) || m.Update_by.Contains(parm.CreateBy)); + predicate = predicate.AndIF(parm.Status != null, m => m.Status == parm.Status); + var response = GetPages(predicate.ToExpression(), parm); + return response; } #endregion