优化操作日志查询

This commit is contained in:
不做码农 2023-12-07 22:02:50 +08:00
parent 9a93282ce7
commit f2a58057d1
2 changed files with 5 additions and 6 deletions

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model.System.Dto; using ZR.Model.System.Dto;
@ -15,12 +14,10 @@ namespace ZR.Admin.WebApi.Controllers.monitor
public class SysOperlogController : BaseController public class SysOperlogController : BaseController
{ {
private ISysOperLogService sysOperLogService; private ISysOperLogService sysOperLogService;
private IWebHostEnvironment WebHostEnvironment;
public SysOperlogController(ISysOperLogService sysOperLogService, IWebHostEnvironment hostEnvironment) public SysOperlogController(ISysOperLogService sysOperLogService)
{ {
this.sysOperLogService = sysOperLogService; this.sysOperLogService = sysOperLogService;
WebHostEnvironment = hostEnvironment;
} }
/// <summary> /// <summary>

View File

@ -34,14 +34,16 @@ namespace ZR.ServiceCore.Services
public PagedInfo<SysOperLog> SelectOperLogList(SysOperLogQueryDto sysOper) public PagedInfo<SysOperLog> SelectOperLogList(SysOperLogQueryDto sysOper)
{ {
var exp = Expressionable.Create<SysOperLog>(); var exp = Expressionable.Create<SysOperLog>();
exp.And(it => it.OperTime >= sysOper.BeginTime && it.OperTime <= sysOper.EndTime); exp.AndIF(sysOper.BeginTime == null, it => it.OperTime >= DateTime.Now.ToShortDateString().ParseToDateTime());
exp.AndIF(sysOper.BeginTime != null, it => it.OperTime >= sysOper.BeginTime && it.OperTime <= sysOper.EndTime);
exp.AndIF(sysOper.Title.IfNotEmpty(), it => it.Title.Contains(sysOper.Title)); exp.AndIF(sysOper.Title.IfNotEmpty(), it => it.Title.Contains(sysOper.Title));
exp.AndIF(sysOper.OperName.IfNotEmpty(), it => it.OperName.Contains(sysOper.OperName)); exp.AndIF(sysOper.OperName.IfNotEmpty(), it => it.OperName.Contains(sysOper.OperName));
exp.AndIF(sysOper.BusinessType != -1, it => it.BusinessType == sysOper.BusinessType); exp.AndIF(sysOper.BusinessType != -1, it => it.BusinessType == sysOper.BusinessType);
exp.AndIF(sysOper.Status != -1, it => it.Status == sysOper.Status); exp.AndIF(sysOper.Status != -1, it => it.Status == sysOper.Status);
exp.AndIF(sysOper.OperParam != null, it => it.OperParam.Contains(sysOper.OperParam)); exp.AndIF(sysOper.OperParam != null, it => it.OperParam.Contains(sysOper.OperParam));
return Queryable().Where(exp.ToExpression()) return Queryable()
.Where(exp.ToExpression())
.OrderBy(x => x.OperId, OrderByType.Desc) .OrderBy(x => x.OperId, OrderByType.Desc)
.ToPage(sysOper); .ToPage(sysOper);
} }