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.

75 lines
2.6 KiB

7 months ago
using Entity.Base;
using Entity.DbModel.System;
7 months ago
using Entity.Dto;
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
7 months ago
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using Repository.System;
using SqlSugar;
namespace Service.System.SysLog
{
/// <summary>
/// 系统异常日志服务 🧩
/// </summary>
[Scope("SingleInstance")]
public class SysLogExService : BaseServices<SysLogEx>
{
private readonly SysLogExRepository _sysLogExRep;
public SysLogExService(SysLogExRepository sysLogExRep)
{
_sysLogExRep = sysLogExRep;
}
/// <summary>
/// 获取异常日志分页列表 🔖
/// </summary>
/// <returns></returns>
public async Task<PageResult<SysLogEx>> Page(PageLogReq input)
7 months ago
{
RefAsync<int> total = 0;
var items = await _sysLogExRep.SysLogExQueryPageAsync(
7 months ago
!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
7 months ago
);
return new PageResult<SysLogEx>()
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
Rows = items,
};
7 months ago
}
/// <summary>
/// 清空异常日志 🔖
/// </summary>
/// <returns></returns>
public async Task<bool> Clear()
{
return await _sysLogExRep.DeleteAsync(u => u.Id > 0);
}
/// <summary>
/// 导出异常日志 🔖
/// </summary>
/// <returns></returns>
public async Task<IActionResult> ExportLogEx(LogReq input)
{
var logExList = await _sysLogExRep.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(logExList);
return new FileStreamResult(new MemoryStream(res), "application/octet-stream") { FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "异常日志.xlsx" };
}
}
}