using Admin.NET.Core; using Furion.DependencyInjection; using Furion.DynamicApiController; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Vistar.Application.Entity; using Vistar.Application.Service.Log.Dto; namespace Vistar.Application.Service.Log; /// /// 定时任务日志服务 🧩 /// [ApiDescriptionSettings(Order = 360, Description = "定时任务日志服务")] public class ScheduledTaskLogService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _scheduledTaskLogRep; public ScheduledTaskLogService(SqlSugarRepository scheduledTaskLogRep) { _scheduledTaskLogRep = scheduledTaskLogRep; } /// /// 获取操作日志分页列表 🔖 /// /// [SuppressMonitor] [DisplayName("获取操作日志分页列表")] public async Task> Page(PageTaskLogInput input) { return await _scheduledTaskLogRep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()), u => u.LogDateTime >= input.StartTime) .WhereIF(!string.IsNullOrWhiteSpace(input.EndTime.ToString()), u => u.LogDateTime <= input.EndTime) .WhereIF(!string.IsNullOrWhiteSpace(input.TaskName), u => u.TaskName.Contains(input.TaskName)) .WhereIF(input.presenceLog, u => u.ReturnResult != "未查询到符合条件的记录") .ToPagedListAsync(input.Page, input.PageSize); } /// /// 获取日志详情 🔖 /// /// [SuppressMonitor] [DisplayName("获取日志详情")] public async Task GetDetail(long id) { var data= await _scheduledTaskLogRep.AsQueryable().Where(x => x.Id == id).FirstAsync(); return data.ReturnResult; } /// /// 删除半年前定时任务日志 🔖 /// /// [SuppressMonitor] [DisplayName("删除半年前定时任务日志")] [HttpGet] public async Task DeleteHalfaYearTaskLog() { // 计算半年前的日期 var halfYearAgo = DateTime.Now.AddMonths(-6); // 执行删除操作并获取影响行数 var deletedCount = await _scheduledTaskLogRep.AsDeleteable() .Where(x => x.LogDateTime < halfYearAgo) .ExecuteCommandAsync(); if (deletedCount > 0) { return $"成功删除{deletedCount}条半年前定时任务日志"; } else { return "未查询到半年前定时任务日志"; } } }