using System;
using System.Threading;
using System.Threading.Tasks;
using Hangfire;
using JiShe.CollectBus.ScheduledMeterReading;
using Microsoft.Extensions.Logging;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;

namespace JiShe.CollectBus.Workers
{
    /// <summary>
    /// 15分钟采集数据
    /// </summary>
    public class SubscriberFifteenMinuteWorker : HangfireBackgroundWorkerBase, ITransientDependency, ICollectWorker
    {
        private readonly ILogger<SubscriberFifteenMinuteWorker> _logger;
        private readonly IScheduledMeterReadingService _scheduledMeterReadingService;

        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriberFifteenMinuteWorker"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="scheduledMeterReadingService">定时任务</param>
        public SubscriberFifteenMinuteWorker(ILogger<SubscriberFifteenMinuteWorker> logger, IScheduledMeterReadingService scheduledMeterReadingService)
        {
            _logger = logger;
            RecurringJobId = nameof(SubscriberFifteenMinuteWorker);
            CronExpression = "0 0/15 * * * *";
            TimeZone = TimeZoneInfo.Local;
            this._scheduledMeterReadingService = scheduledMeterReadingService;
        }


        public override async Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            //await _scheduledMeterReadingService.AmmeterScheduledMeterFifteenMinuteReading();
            //await _scheduledMeterReadingService.WatermeterScheduledMeterFifteenMinuteReading();

            //using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin())
            //{
            //    Logger.LogInformation("Executed MyLogWorker..!");
            //    return Task.CompletedTask;
            //}
        }
    }
}
