|
|
|
|
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 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)
|
|
|
|
|
{
|
|
|
|
|
RefAsync<int> total = 0;
|
|
|
|
|
var items = await _sysLogExRep.SysLogExQueryPageAsync(
|
|
|
|
|
!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<SysLogEx>()
|
|
|
|
|
{
|
|
|
|
|
PageNum = input.PageNum,
|
|
|
|
|
PageSize = input.PageSize,
|
|
|
|
|
ToTal = total,
|
|
|
|
|
Rows = items,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|