// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Core.Service;
///
/// 系统操作日志服务
///
[ApiDescriptionSettings(Order = 360)]
public class SysLogOpService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _sysLogOpRep;
public SysLogOpService(SqlSugarRepository sysLogOpRep)
{
_sysLogOpRep = sysLogOpRep;
}
///
/// 获取操作日志分页列表
///
///
[SuppressMonitor]
[DisplayName("获取操作日志分页列表")]
public async Task> Page(PageLogInput input)
{
return await _sysLogOpRep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()), u => u.CreateTime >= input.StartTime)
.WhereIF(!string.IsNullOrWhiteSpace(input.EndTime.ToString()), u => u.CreateTime <= input.EndTime)
//.OrderBy(u => u.CreateTime, OrderByType.Desc)
.OrderBuilder(input)
.ToPagedListAsync(input.Page, input.PageSize);
}
///
/// 清空操作日志
///
///
[ApiDescriptionSettings(Name = "Clear"), HttpPost]
[DisplayName("清空操作日志")]
public async Task Clear()
{
return await _sysLogOpRep.DeleteAsync(u => u.Id > 0);
}
///
/// 导出操作日志
///
///
[ApiDescriptionSettings(Name = "Export"), NonUnify]
[DisplayName("导出操作日志")]
public async Task ExportLogOp(LogInput input)
{
var logOpList = await _sysLogOpRep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()),
u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime)
.OrderBy(u => u.CreateTime, OrderByType.Desc)
.Select().ToListAsync();
IExcelExporter excelExporter = new ExcelExporter();
var res = await excelExporter.ExportAsByteArray(logOpList);
return new FileStreamResult(new MemoryStream(res), "application/octet-stream") { FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "操作日志.xlsx" };
}
}