优化文章管理、日志记录

This commit is contained in:
不做码农 2023-05-27 18:31:48 +08:00
parent 5c0564c7c1
commit 13758b31b8
6 changed files with 26 additions and 48 deletions

View File

@ -1,15 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Infrastructure.Model namespace Infrastructure.Model
{ {
public class SendEmailDto public class SendEmailDto
{ {
/// <summary>
/// 文件地址
/// </summary>
public string FileUrl { get; set; } = ""; public string FileUrl { get; set; } = "";
/// <summary>
/// 主题
/// </summary>
[Required(ErrorMessage = "主题不能为空")]
public string Subject { get; set; } public string Subject { get; set; }
[Required(ErrorMessage = "发送人不能为空")]
public string ToUser { get; set; } public string ToUser { get; set; }
public string Content { get; set; } = ""; public string Content { get; set; } = "";
public string HtmlContent { get; set; } public string HtmlContent { get; set; }

View File

@ -16,7 +16,6 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary> /// <summary>
/// 文章目录Controller /// 文章目录Controller
/// </summary> /// </summary>
[Verify]
[Route("article/ArticleCategory")] [Route("article/ArticleCategory")]
public class ArticleCategoryController : BaseController public class ArticleCategoryController : BaseController
{ {
@ -36,7 +35,7 @@ namespace ZR.Admin.WebApi.Controllers
/// <param name="parm"></param> /// <param name="parm"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("list")] [HttpGet("list")]
[ActionPermissionFilter(Permission = "articlecategory:list")] //[ActionPermissionFilter(Permission = "articlecategory:list")]
public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm) public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
{ {
var response = _ArticleCategoryService.GetList(parm); var response = _ArticleCategoryService.GetList(parm);
@ -49,7 +48,7 @@ namespace ZR.Admin.WebApi.Controllers
/// <param name="parm"></param> /// <param name="parm"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("treeList")] [HttpGet("treeList")]
[ActionPermissionFilter(Permission = "articlecategory:list")] //[ActionPermissionFilter(Permission = "articlecategory:list")]
public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm) public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
{ {
var response = _ArticleCategoryService.GetTreeList(parm); var response = _ArticleCategoryService.GetTreeList(parm);
@ -62,7 +61,7 @@ namespace ZR.Admin.WebApi.Controllers
/// <param name="CategoryId"></param> /// <param name="CategoryId"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("{CategoryId}")] [HttpGet("{CategoryId}")]
[ActionPermissionFilter(Permission = "articlecategory:query")] //[ActionPermissionFilter(Permission = "articlecategory:query")]
public IActionResult GetArticleCategory(int CategoryId) public IActionResult GetArticleCategory(int CategoryId)
{ {
var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId); var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);
@ -75,17 +74,12 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Verify]
[ActionPermissionFilter(Permission = "articlecategory:add")] [ActionPermissionFilter(Permission = "articlecategory:add")]
[Log(Title = "文章目录", BusinessType = BusinessType.INSERT)] [Log(Title = "文章目录", BusinessType = BusinessType.INSERT)]
public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm) public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
{ {
if (parm == null)
{
throw new CustomException("请求参数错误");
}
//从 Dto 映射到 实体
var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext); var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext);
var response = _ArticleCategoryService.AddArticleCategory(modal); var response = _ArticleCategoryService.AddArticleCategory(modal);
return ToResponse(response); return ToResponse(response);
@ -96,16 +90,12 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPut] [HttpPut]
[Verify]
[ActionPermissionFilter(Permission = "articlecategory:edit")] [ActionPermissionFilter(Permission = "articlecategory:edit")]
[Log(Title = "文章目录", BusinessType = BusinessType.UPDATE)] [Log(Title = "文章目录", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm) public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm)
{ {
if (parm == null)
{
throw new CustomException("请求实体不能为空");
}
var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext); var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext);
var response = _ArticleCategoryService.Update(w => w.CategoryId == modal.CategoryId, it => new ArticleCategory() var response = _ArticleCategoryService.Update(w => w.CategoryId == modal.CategoryId, it => new ArticleCategory()
{ {
Name = modal.Name, Name = modal.Name,

View File

@ -1,7 +1,5 @@
using Infrastructure; using Infrastructure.Attribute;
using Infrastructure.Attribute;
using Infrastructure.Enums; using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster; using Mapster;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -79,7 +77,7 @@ namespace ZR.Admin.WebApi.Controllers
if (model != null) if (model != null)
{ {
model.ArticleCategoryNav = _ArticleCategoryService.GetById(model.CategoryId); model.ArticleCategoryNav = _ArticleCategoryService.GetById(model.CategoryId);
model.TagList = model.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries); model.TagList = model.Tags?.Split(',', StringSplitOptions.RemoveEmptyEntries);
} }
return SUCCESS(model); return SUCCESS(model);
} }
@ -90,13 +88,9 @@ namespace ZR.Admin.WebApi.Controllers
/// <returns></returns> /// <returns></returns>
[HttpPost("add")] [HttpPost("add")]
[ActionPermissionFilter(Permission = "system:article:add")] [ActionPermissionFilter(Permission = "system:article:add")]
[Log(Title = "文章添加", BusinessType = BusinessType.INSERT)] [Log(Title = "添加文章", BusinessType = BusinessType.INSERT)]
public IActionResult Create([FromBody] ArticleDto parm) public IActionResult Create([FromBody] ArticleDto parm)
{ {
if (parm == null)
{
throw new CustomException("请求参数错误");
}
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext); var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
addModel.AuthorName = HttpContext.GetName(); addModel.AuthorName = HttpContext.GetName();
@ -112,13 +106,8 @@ namespace ZR.Admin.WebApi.Controllers
[Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)] [Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)]
public IActionResult Update([FromBody] ArticleDto parm) public IActionResult Update([FromBody] ArticleDto parm)
{ {
if (parm == null)
{
throw new CustomException("请求参数错误");
}
parm.AuthorName = HttpContext.GetName(); parm.AuthorName = HttpContext.GetName();
var modal = parm.Adapt<Article>().ToUpdate(HttpContext); var modal = parm.Adapt<Article>().ToUpdate(HttpContext);
var response = _ArticleService.UpdateArticle(modal); var response = _ArticleService.UpdateArticle(modal);
return SUCCESS(response); return SUCCESS(response);
@ -133,16 +122,8 @@ namespace ZR.Admin.WebApi.Controllers
[Log(Title = "文章删除", BusinessType = BusinessType.DELETE)] [Log(Title = "文章删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(int id = 0) public IActionResult Delete(int id = 0)
{ {
if (id <= 0)
{
return ToResponse(ApiResult.Error($"删除失败Id 不能为空"));
}
// 删除文章
var response = _ArticleService.Delete(id); var response = _ArticleService.Delete(id);
return SUCCESS(response); return SUCCESS(response);
} }
} }
} }

View File

@ -82,7 +82,7 @@
<logger name="Quartz*" minlevel="Trace" maxlevel="Info" final="true" /> <logger name="Quartz*" minlevel="Trace" maxlevel="Info" final="true" />
<logger name="ZR.Admin.WebApi.Middleware.GlobalExceptionMiddleware" final="true" writeTo="console,errorfile"/> <logger name="ZR.Admin.WebApi.Middleware.GlobalExceptionMiddleware" final="true" writeTo="console,errorfile"/>
<logger name="ZR.Admin.WebApi.Extensions.DbExtension" final="true" writeTo="consoleSql,sqlfile"/> <logger name="ZR.Admin.WebApi.Extensions.DbExtension" final="true" writeTo="consoleSql,sqlfile"/>
<logger name="*" final="true" writeTo="console"/> <logger name="*" writeTo="console"/>
<logger name="*" minLevel="Trace" writeTo="allfile" /> <logger name="*" minLevel="Trace" writeTo="allfile" />
<!--Skip non-critical Microsoft logs and so log only own logs--> <!--Skip non-critical Microsoft logs and so log only own logs-->

View File

@ -19,9 +19,9 @@ namespace ZR.Model.System.Dto
{ {
[Required(ErrorMessage = "Cid不能为空")] [Required(ErrorMessage = "Cid不能为空")]
public int Cid { get; set; } public int Cid { get; set; }
[Required(ErrorMessage = "文章标题不能为空")]
public string Title { get; set; } public string Title { get; set; }
[Required(ErrorMessage = "文章内容不能为空")]
public string Content { get; set; } public string Content { get; set; }
public long? UserId { get; set; } public long? UserId { get; set; }

View File

@ -69,16 +69,18 @@ namespace ZR.Service.System
/// <returns></returns> /// <returns></returns>
public PagedInfo<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager) public PagedInfo<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager)
{ {
logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1); //logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1);
logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1); //logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1);
var exp = Expressionable.Create<SysLogininfor>(); var exp = Expressionable.Create<SysLogininfor>();
exp.And(it => it.LoginTime >= logininfoDto.BeginTime && it.LoginTime <= logininfoDto.EndTime);
exp.AndIF(logininfoDto.BeginTime == null, it => it.LoginTime >= DateTime.Now.ToShortDateString().ParseToDateTime());
exp.AndIF(logininfoDto.BeginTime != null, it => it.LoginTime >= logininfoDto.BeginTime && it.LoginTime <= logininfoDto.EndTime);
exp.AndIF(logininfoDto.Ipaddr.IfNotEmpty(), f => f.Ipaddr == logininfoDto.Ipaddr); exp.AndIF(logininfoDto.Ipaddr.IfNotEmpty(), f => f.Ipaddr == logininfoDto.Ipaddr);
exp.AndIF(logininfoDto.UserName.IfNotEmpty(), f => f.UserName.Contains(logininfoDto.UserName)); exp.AndIF(logininfoDto.UserName.IfNotEmpty(), f => f.UserName.Contains(logininfoDto.UserName));
exp.AndIF(logininfoDto.Status.IfNotEmpty(), f => f.Status == logininfoDto.Status); exp.AndIF(logininfoDto.Status.IfNotEmpty(), f => f.Status == logininfoDto.Status);
var query = Queryable().Where(exp.ToExpression()) var query = Queryable().Where(exp.ToExpression())
.OrderBy(it => it.InfoId, OrderByType.Desc); .OrderBy(it => it.InfoId, OrderByType.Desc);
return query.ToPage(pager); return query.ToPage(pager);
} }