VistarStarDataIntegration/admin.net.pro/Admin.NET/Vistar.Application/Service/Log/ScheduledTaskLogService.cs

83 lines
2.8 KiB
C#

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;
/// <summary>
/// 定时任务日志服务 🧩
/// </summary>
[ApiDescriptionSettings(Order = 360, Description = "定时任务日志服务")]
public class ScheduledTaskLogService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<ScheduledTaskLog> _scheduledTaskLogRep;
public ScheduledTaskLogService(SqlSugarRepository<ScheduledTaskLog> scheduledTaskLogRep)
{
_scheduledTaskLogRep = scheduledTaskLogRep;
}
/// <summary>
/// 获取操作日志分页列表 🔖
/// </summary>
/// <returns></returns>
[SuppressMonitor]
[DisplayName("获取操作日志分页列表")]
public async Task<SqlSugarPagedList<ScheduledTaskLog>> 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);
}
/// <summary>
/// 获取日志详情 🔖
/// </summary>
/// <returns></returns>
[SuppressMonitor]
[DisplayName("获取日志详情")]
public async Task<string> GetDetail(long id)
{
var data= await _scheduledTaskLogRep.AsQueryable().Where(x => x.Id == id).FirstAsync();
return data.ReturnResult;
}
/// <summary>
/// 删除半年前定时任务日志 🔖
/// </summary>
/// <returns></returns>
[SuppressMonitor]
[DisplayName("删除半年前定时任务日志")]
[HttpGet]
public async Task<string> 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 "未查询到半年前定时任务日志";
}
}
}