using Entity.Base;
using Entity.DbModel.System.SysBaseObject;
using Entity.Dto;
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using Repository.System;
using SqlSugar;
namespace Service.System.SysLog
{
///
/// 系统操作日志服务 🧩
///
[Scope("SingleInstance")]
public class SysLogOpService : BaseServices
{
private readonly SysLogOpRepository _sysLogOpRep;
public SysLogOpService(SysLogOpRepository sysLogOpRep)
{
_sysLogOpRep = sysLogOpRep;
}
///
/// 获取操作日志分页列表 🔖
///
///
public async Task> Page(PageLogReq input)
{
RefAsync total = 0;
var items = await _sysLogOpRep.SysLogOpQueryPageAsync(
!string.IsNullOrWhiteSpace(input.StartTime.ToString()), u => u.CreateTime >= input.StartTime,
!string.IsNullOrWhiteSpace(input.EndTime.ToString()), u => u.CreateTime <= input.EndTime,
input.Page, input.PageSize, total, input
);
return SqlSugarPagedExtensions.CreateSqlSugarPagedList(items, total, input.Page, input.PageSize);
}
///
/// 清空操作日志 🔖
///
///
public async Task Clear()
{
return await _sysLogOpRep.DeleteAsync(u => u.Id > 0);
}
///
/// 导出操作日志 🔖
///
///
public async Task ExportLogOp(LogReq input)
{
var logOpList = await _sysLogOpRep.QueryListByClauseAsync(
!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()),
u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime, u => u.CreateTime);
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" };
}
}
}