using Abp.Dependency; using Quartz; using Quartz.Impl; using ToolLibrary.LogHelper; using Yunda.ISAS.DataMonitoringServer.DataAnalysis; using Yunda.ISAS.DataMonitoringServer.DataAnalysis.DataCollection; using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Helper; using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model; using Yunda.ISAS.DataMonitoringServer.DataCenter; using Yunda.ISAS.DataMonitoringServer.WebSocket; namespace Yunda.ISAS.DataMonitoringServer { public class TimeWorkService : ISingletonDependency { public static RedisDataRepository _redisDataRepository; public static WebApiRequest _webApiRequest; public static RunningDataCache _runningDataCache; public static WebSocketServer _webSocketServer; public static CameraDataCenter _cameraDataCenter; public static ConfigurationHepler _configurationHepler; public static TeleCommandDataSendTask _teleCommandDataSendTask; public TimeWorkService( RedisDataRepository redisDataRepository, WebApiRequest webApiRequest, RunningDataCache runningDataCache, WebSocketServer webSocketController, CameraDataCenter cameraDataCenter, TeleCommandDataSendTask teleCommandDataSendTask, ConfigurationHepler configurationHepler ) { _redisDataRepository = redisDataRepository; _webApiRequest = webApiRequest; _runningDataCache = runningDataCache; _webSocketServer = webSocketController; _cameraDataCenter = cameraDataCenter; _configurationHepler = configurationHepler; _teleCommandDataSendTask = teleCommandDataSendTask; //FixedTimeTaskAsync(15); //布防撤防 //FixedTimeTaskAsync(10); // 摄像机权限释放 //FixedTimeTaskAsync(60 * 5);//联动录像下载 //FixedTimeTaskAsync(60);//报警队列主动推送 //FixedTimeTaskAsync(30);//遥控计划定时任务 //FixedTimeTaskAsync(120); } /// /// 定时任务开启 /// /// 执行内容 /// 执行间隔 private async void FixedTimeTaskAsync(int intval) where T : IJob { StdSchedulerFactory factory = new StdSchedulerFactory(); // get a scheduler IScheduler scheduler = await factory.GetScheduler(); await scheduler.Start(); Guid guid = Guid.NewGuid(); IJobDetail job = JobBuilder.Create() .WithIdentity(guid.ToString()) .Build(); guid = Guid.NewGuid(); //定义执行时间间隔 ITrigger trigger = TriggerBuilder.Create() .WithIdentity(guid.ToString()) .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(intval) .RepeatForever() ) .Build(); await scheduler.ScheduleJob(job, trigger); } /// /// 巡检灯光控制 /// [DisallowConcurrentExecution] public class LightingControlTimeJob : IJob { public async Task Execute(IJobExecutionContext context) { try { var telecomands = _webApiRequest.GetLightingControlTelecommand(_configurationHepler.SubstationId); if (telecomands == null) { return; } foreach (var telecomand in telecomands) { var telecom = new TelecommandModel(); ToolLibrary.MapValue.Map(telecomand, telecom); telecom.Value = telecomand.Value; _teleCommandDataSendTask.TelecommandTActionBlock.Post(new TelcommandDataModel() { Telecommand = telecom }); } } catch (Exception ex) { Log4Helper.Error(this.GetType(), "定时布防撤防数据更新发生错误", ex); } } } } }