using PushPlatform.Common.Enumerate;
using PushPlatform.Common.Util;
using Newtonsoft.Json.Linq;
using PushInfo.Core.BLL;
using PushInfo.Core.Models.QueryResults;
using PushInfo.Core.Models.Tables;
using Quartz;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using PushInfo.Core.Common;
using PushPlatform.Common.Model;

namespace PushInfo.Core.Quartz.Jobs
{
    public class PushJob: IJob
    {
        private MapProjectPushBLL mProPushBll = new MapProjectPushBLL();
        private ProcessTaskBLL proTaskBll = new ProcessTaskBLL();
        /// <summary>
        /// 推送数据体
        /// </summary>
        public void Execute(IJobExecutionContext context)
        {
            LogHelper.Debug("开始执行定时任务");
            var jobDetail = context.JobDetail;
            if (jobDetail != null)
            {
                var jobKey = jobDetail.Key;
                Map_Project_Push task = mProPushBll.Query_Sys_Task_By_Id(jobKey.Name);
                if(task == null)
                {
                    LogHelper.Info("执行任务时查询结果为NULL，不正常-" + task.Name_Des);
                    return;
                }
                if (task != null && (task.Exec_Status == (int)ExecuteStatus.已安排触发器 || task.Exec_Status == (int)ExecuteStatus.循环执行中))
                {
                    LogHelper.Debug("执行任务" + task.Name_Des);
                    if (!proTaskBll.StartTask(task))
                    {
                        LogHelper.Info("执行任务" + task.Name_Des+"。失败！");
                    }
                }
            }
        }
    }
}
