using HKCardOUT.Logic;
using HKCardOUT.Logic.Model;
using Quartz;
using System.Threading.Tasks;

namespace HKCardOUT.QuartzUtil.Job
{
    public class QuartzJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            switch (context.JobDetail.Key.Group)
            {
                default:
                    {
                        var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false).ToList();
                        if (WaitSync.Count > 0)
                        {
                            foreach (var input in WaitSync)
                            {
                                var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
                                if (res)
                                   await DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == input.Id).ExecuteCommandAsync();
                            }
                        }
                    }
                    break;
            }
        }
    }
}
