using FluentScheduler; using log4net; using POSV.WindowsService.Core.Utils; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using POSV.Service.Utils; namespace POSV.WindowsService.Core.Job { public class CleanDataJob: IJob { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private bool isRunning = false; public void Execute() { try { if (isRunning) { logger.Debug("执行中,请稍候..."); return; } logger.Info("执行清理历史数据"); isRunning = true; ConcurrentQueue lists = new ConcurrentQueue(); lists.Enqueue(string.Format("delete from [pos_order] where [saleDate] < '{0}'", DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd HH:mm:ss"))); lists.Enqueue(string.Format("delete from [pos_order_item] where [saleDate] < '{0}'", DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd HH:mm:ss"))); SQLiteUtils.ExecuteTransaction(lists); } catch (Exception ex) { logger.Error(ex,"执行清理历史数据异常"); } finally { isRunning = false; } } } }