using BLW_Log.Models;
using DAL.PGModels;
using Microsoft.EntityFrameworkCore;
using Quartz;

namespace BLW_Log.services
{
    public class DelLogJob : IJob
    {
        public readonly PostgresContext DbContext;
        public DelLogJob(PostgresContext db) { this.DbContext = db; }


        public async Task Execute(IJobExecutionContext context)
        {
            //using (var a = new LowmachinelogContext())
            //{
                string ti = DateTime.Now.AddDays(-90).ToString("yyyy-MM-dd HH:mm:ss");
                string sql = string.Format(@"delete from dev_monitorlog where CreateTime<='{0}';
                                             DELETE from iot_monitorlog where TriggerTime<='{0}';
                                             delete from webapi_monitorlog where InvokStart_Time<='{0}';", ti);
               await DbContext.Database.ExecuteSqlRawAsync(sql);
            //}
        }
    }
}
