ClearLogJob.cs 1.41 KB
using System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.WebEntity.bus;

namespace Quartz.Job.Jobs
{
    /// <summary>
    /// 日志清除Job
    /// 命名空间 Quartz.Job.Jobs 保持一致
    /// </summary>
    public class ClearLogJob : JobBase
    {
        public override void ExecuteJob(IJobExecutionContext context)
        {
            _dbContext.Deleteable<sys_job_log>().Where(x => x.createTime < DateTime.Now.AddDays(-3)).ExecuteCommand();

            //日志默认保留15天
            _dbContext.Deleteable<sys_interface_log>().Where(x => x.type != EnumLog.工序执行反馈.ToString() && x.createTime < DateTime.Now.AddDays(-15)).ExecuteCommand();
            //MES工序反馈只保留15天
            _dbContext.Deleteable<sys_interface_log>().Where(x => x.type == EnumLog.工序执行反馈.ToString() && x.createTime < DateTime.Now.AddDays(-15)).ExecuteCommand();
            _dbContext.Deleteable<sys_login_log>().Where(x => x.createTime < DateTime.Now.AddDays(-15)).ExecuteCommand();
            _dbContext.Deleteable<sys_oper_log>().Where(x => x.createTime < DateTime.Now.AddDays(-15)).ExecuteCommand();
            //_dbContext.Deleteable<bus_workOrder_detail_operation>().Where(x => x.createTime < DateTime.Now.AddMonths(-6)).ExecuteCommand();
            //_log.EnqueueJobLog(nameof(ClearLogJob), nameof(ClearLogJob), "", "定时器", "执行成功", "");
        }
    }
}