⚡ 优化文章管理、日志记录
This commit is contained in:
parent
5c0564c7c1
commit
13758b31b8
@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Infrastructure.Model
|
||||
{
|
||||
public class SendEmailDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件地址
|
||||
/// </summary>
|
||||
public string FileUrl { get; set; } = "";
|
||||
/// <summary>
|
||||
/// 主题
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "主题不能为空")]
|
||||
public string Subject { get; set; }
|
||||
[Required(ErrorMessage = "发送人不能为空")]
|
||||
public string ToUser { get; set; }
|
||||
public string Content { get; set; } = "";
|
||||
public string HtmlContent { get; set; }
|
||||
|
||||
@ -16,7 +16,6 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <summary>
|
||||
/// 文章目录Controller
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("article/ArticleCategory")]
|
||||
public class ArticleCategoryController : BaseController
|
||||
{
|
||||
@ -36,7 +35,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:list")]
|
||||
//[ActionPermissionFilter(Permission = "articlecategory:list")]
|
||||
public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetList(parm);
|
||||
@ -49,7 +48,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("treeList")]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:list")]
|
||||
//[ActionPermissionFilter(Permission = "articlecategory:list")]
|
||||
public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetTreeList(parm);
|
||||
@ -62,7 +61,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="CategoryId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{CategoryId}")]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:query")]
|
||||
//[ActionPermissionFilter(Permission = "articlecategory:query")]
|
||||
public IActionResult GetArticleCategory(int CategoryId)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);
|
||||
@ -75,17 +74,12 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:add")]
|
||||
[Log(Title = "文章目录", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext);
|
||||
|
||||
var response = _ArticleCategoryService.AddArticleCategory(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
@ -96,16 +90,12 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:edit")]
|
||||
[Log(Title = "文章目录", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext);
|
||||
|
||||
var response = _ArticleCategoryService.Update(w => w.CategoryId == modal.CategoryId, it => new ArticleCategory()
|
||||
{
|
||||
Name = modal.Name,
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -79,7 +77,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
if (model != null)
|
||||
{
|
||||
model.ArticleCategoryNav = _ArticleCategoryService.GetById(model.CategoryId);
|
||||
model.TagList = model.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
model.TagList = model.Tags?.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
return SUCCESS(model);
|
||||
}
|
||||
@ -90,13 +88,9 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpPost("add")]
|
||||
[ActionPermissionFilter(Permission = "system:article:add")]
|
||||
[Log(Title = "文章添加", BusinessType = BusinessType.INSERT)]
|
||||
[Log(Title = "添加文章", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] ArticleDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
||||
addModel.AuthorName = HttpContext.GetName();
|
||||
|
||||
@ -112,13 +106,8 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
[Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] ArticleDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
parm.AuthorName = HttpContext.GetName();
|
||||
var modal = parm.Adapt<Article>().ToUpdate(HttpContext);
|
||||
|
||||
var response = _ArticleService.UpdateArticle(modal);
|
||||
|
||||
return SUCCESS(response);
|
||||
@ -133,16 +122,8 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
[Log(Title = "文章删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int id = 0)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"删除失败Id 不能为空"));
|
||||
}
|
||||
|
||||
// 删除文章
|
||||
var response = _ArticleService.Delete(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@
|
||||
<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.Extensions.DbExtension" final="true" writeTo="consoleSql,sqlfile"/>
|
||||
<logger name="*" final="true" writeTo="console"/>
|
||||
<logger name="*" writeTo="console"/>
|
||||
|
||||
<logger name="*" minLevel="Trace" writeTo="allfile" />
|
||||
<!--Skip non-critical Microsoft logs and so log only own logs-->
|
||||
|
||||
@ -19,9 +19,9 @@ namespace ZR.Model.System.Dto
|
||||
{
|
||||
[Required(ErrorMessage = "Cid不能为空")]
|
||||
public int Cid { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "文章标题不能为空")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "文章内容不能为空")]
|
||||
public string Content { get; set; }
|
||||
|
||||
public long? UserId { get; set; }
|
||||
|
||||
@ -69,11 +69,13 @@ namespace ZR.Service.System
|
||||
/// <returns></returns>
|
||||
public PagedInfo<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager)
|
||||
{
|
||||
logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1);
|
||||
logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1);
|
||||
//logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1);
|
||||
//logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1);
|
||||
|
||||
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.UserName.IfNotEmpty(), f => f.UserName.Contains(logininfoDto.UserName));
|
||||
exp.AndIF(logininfoDto.Status.IfNotEmpty(), f => f.Status == logininfoDto.Status);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user