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 { /// /// 系统异常日志服务 🧩 /// [Scope("SingleInstance")] public class SysLogExService : BaseServices { private readonly SysLogExRepository _sysLogExRep; public SysLogExService(SysLogExRepository sysLogExRep) { _sysLogExRep = sysLogExRep; } /// /// 获取异常日志分页列表 🔖 /// /// public async Task> Page(PageLogReq input) { RefAsync 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() { PageNum = input.PageNum, PageSize = input.PageSize, ToTal = total, Rows = items, }; } /// /// 清空异常日志 🔖 /// /// public async Task Clear() { return await _sysLogExRep.DeleteAsync(u => u.Id > 0); } /// /// 导出异常日志 🔖 /// /// public async Task ExportLogEx(LogReq input) { var logExList = await _sysLogExRep.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(logExList); return new FileStreamResult(new MemoryStream(res), "application/octet-stream") { FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "异常日志.xlsx" }; } } }