LogService
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using YhCore.Entity;
|
||||||
|
using YhCore.Model.Vo;
|
||||||
|
using YhCore.Repository;
|
||||||
|
using YhCore.Service.Interfaces;
|
||||||
|
|
||||||
|
namespace YhCore.Service.Impl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 日志查询服务(对应 Java 版 LogServiceImpl,替换框架期 LogServiceStub)。
|
||||||
|
/// 查询 sys_operation_log:按学校隔离;systemScope=false 排除查询类(GET=LogLevel 3);
|
||||||
|
/// keyword 模糊匹配用户名/URI/类方法/请求参数/异常/操作类型;按 CreateTime 倒序分页。
|
||||||
|
/// </summary>
|
||||||
|
public class LogService : ILogService
|
||||||
|
{
|
||||||
|
/// <summary>查询类日志级别(与 SysOperationLogFilter 推导一致:GET → 3/QUERY)</summary>
|
||||||
|
private const int QueryLogLevel = 3;
|
||||||
|
|
||||||
|
/// <summary>每页大小上限(审计日志量大,防一次拉全表)</summary>
|
||||||
|
private const int MaxPageSize = 200;
|
||||||
|
|
||||||
|
private readonly IRepository<SysOperationLog> _log;
|
||||||
|
|
||||||
|
public LogService(IRepository<SysOperationLog> log)
|
||||||
|
{
|
||||||
|
_log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<PageVO<SysOperationLog>> SearchAsync(int schId, string keyword, bool systemScope, int page, int size)
|
||||||
|
{
|
||||||
|
if (page < 0) page = 0;
|
||||||
|
if (size <= 0) size = 20;
|
||||||
|
if (size > MaxPageSize) size = MaxPageSize;
|
||||||
|
|
||||||
|
var kw = keyword?.Trim();
|
||||||
|
|
||||||
|
return _log.PageAsync(
|
||||||
|
a => a.SchId == schId
|
||||||
|
// 普通操作日志:只看增删改(排除查询类);系统操作日志全量
|
||||||
|
&& (systemScope || a.LogLevel != QueryLogLevel)
|
||||||
|
// 关键字模糊匹配(EF 翻译为 SQL LIKE,NULL 列不命中)
|
||||||
|
&& (string.IsNullOrEmpty(kw)
|
||||||
|
|| a.UserName.Contains(kw)
|
||||||
|
|| a.RequestUri.Contains(kw)
|
||||||
|
|| a.ClassMethod.Contains(kw)
|
||||||
|
|| a.RequestParams.Contains(kw)
|
||||||
|
|| a.ErrorMsg.Contains(kw)
|
||||||
|
|| a.OperationType.Contains(kw)),
|
||||||
|
page, size,
|
||||||
|
a => a.CreateTime, asc: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user