using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Hangfire;

namespace DigitalSchoolApi.Controllers
{
    public class YKTController : BaseController
    {

        /// <summary>
        /// 开始推送
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Begin()
        {
            //YKTTrabs.BeginTrans();
            //RecurringJob.AddOrUpdate("YKT",
            //    () => YKTTrabs.BeginTrans(),
            //    Cron.Daily(13), TimeZoneInfo.Local);
            //RecurringJob.AddOrUpdate("YKT2",
            //    () => YKTTrabs.BeginTrans(),
            //    Cron.Daily(22), TimeZoneInfo.Local);
            RecurringJob.AddOrUpdate("JINYUYKT",
                () => YKTTrabs.GetConsumeInfo(),
                Cron.Daily(0), TimeZoneInfo.Local);
            RecurringJob.AddOrUpdate("JINYUYKT2",
                () => YKTTrabs.GetConsumeInfo(),
                Cron.Daily(14), TimeZoneInfo.Local);
            RecurringJob.AddOrUpdate("JINYUYKTSAVER",
                () => YKTTrabs.GetSaveRecordInfo(),
                Cron.Daily(14), TimeZoneInfo.Local);
            RecurringJob.AddOrUpdate("PUSHWEIXIN",
                () => YKTTrabs.PushWeixin(),
                Cron.Daily(0), TimeZoneInfo.Local);
            return Ok();
        }

        /// <summary>
        /// 河南新安定时获取部门用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult HeNanXinAnBegin()
        {
            //YKTTrabs.BgeinHeNanXinAn();
            RecurringJob.AddOrUpdate("HNXA",
            () => YKTTrabs.BgeinHeNanXinAn(),
                Cron.Daily(13), TimeZoneInfo.Local);
            return Ok();
        }

        /// <summary>
        /// 消费信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult Balance()
        {
            RecurringJob.Trigger("JINYUYKT");
            //YKTTrabs.GetConsumeInfo();
            return Ok();
        }

        [HttpGet]
        public IHttpActionResult PushWeixinTest()
        {
            RecurringJob.Trigger("PUSHWEIXIN");
            //YKTTrabs.PushWeixin();
            return Ok();
        }
        [HttpGet]
        public IHttpActionResult GetSaveRecord()
        {
            RecurringJob.Trigger("PUSHWEIXIN");
            //YKTTrabs.PushWeixin();
            return Ok();
        }
        
        /// <summary>
        /// 停止推送
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Terminate()
        {
            //RecurringJob.RemoveIfExists("YKT");
            //RecurringJob.RemoveIfExists("YKT2");
            RecurringJob.RemoveIfExists("JINYUYKT");
            RecurringJob.RemoveIfExists("JINYUYKT2");
            return Ok();
        }
    }
}
