⚡优化代码
This commit is contained in:
parent
5d9d1e2f38
commit
c54c306a9d
@ -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;
|
||||
|
||||
@ -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<SysNotice>();
|
||||
|
||||
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<SysNotice> response = _SysNoticeService.GetPageList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
@ -74,7 +69,6 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
/// <param name="NoticeId"></param>
|
||||
/// <returns></returns>
|
||||
[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<SysNotice>().ToCreate(HttpContext);
|
||||
modal.Create_by = HttpContext.GetName();
|
||||
modal.Create_time = DateTime.Now;
|
||||
|
||||
|
||||
int result = _SysNoticeService.Insert(modal, it => new
|
||||
{
|
||||
it.NoticeTitle,
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
/// </summary>
|
||||
public interface ISysNoticeService: IBaseService<SysNotice>
|
||||
public interface ISysNoticeService : IBaseService<SysNotice>
|
||||
{
|
||||
List<SysNotice> GetSysNotices();
|
||||
|
||||
PagedInfo<SysNotice> GetPageList(SysNoticeQueryDto parm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
/// <returns></returns>
|
||||
public List<SysNotice> GetSysNotices()
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<SysNotice>();
|
||||
|
||||
//搜索条件查询语法参考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<SysNotice> GetPageList(SysNoticeQueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<SysNotice>();
|
||||
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user