You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.5 KiB

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