using Model;
using Model.Dto.System;
using Model.Entity.System;
using Model.Mapper;
using ORM;
using Service.Interface;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Service.Implement
{
///
/// 审计日志 服务实现(查询端;写入端在各业务服务中直接插 AuditLogEntity,或经 AuditHelper)
///
public class AuditLogService : IAuditLogService
{
public async Task>> GetPagedAsync(int pageIndex, int pageSize, RefAsync total,
string? keyword = null, string? operationType = null, string? operationTarget = null,
DateTime? startTime = null, DateTime? endTime = null)
{
try
{
var list = await SqlSugarContext.DbContext.Queryable()
.Where(x => x.IsDel == 0)
.WhereIF(!string.IsNullOrWhiteSpace(keyword),
x => (x.UserName != null && x.UserName.Contains(keyword!))
|| (x.Description != null && x.Description.Contains(keyword!))
|| (x.RoleName != null && x.RoleName.Contains(keyword!)))
.WhereIF(!string.IsNullOrWhiteSpace(operationType), x => x.OperationType == operationType)
.WhereIF(!string.IsNullOrWhiteSpace(operationTarget), x => x.OperationTarget == operationTarget)
.WhereIF(startTime.HasValue, x => x.OperateTime >= startTime!.Value)
.WhereIF(endTime.HasValue, x => x.OperateTime <= endTime!.Value)
.OrderBy(x => x.OperateTime, OrderByType.Desc)
.ToPageListAsync(pageIndex, pageSize, total);
return Result>.Success(list.ToDtoList());
}
catch (Exception ex)
{
return Result>.Error("查询审计日志失败", ex);
}
}
}
}