117 lines
4.5 KiB
C#
117 lines
4.5 KiB
C#
![]() |
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<SafetyStateFixedTimeJob>(15); //布防撤防
|
|||
|
//FixedTimeTaskAsync<CamAuthFixedTimeJob>(10); // 摄像机权限释放
|
|||
|
//FixedTimeTaskAsync<DownloadAndTranscodeLinkResult>(60 * 5);//联动录像下载
|
|||
|
//FixedTimeTaskAsync<AlarmQueueTimeJob>(60);//报警队列主动推送
|
|||
|
//FixedTimeTaskAsync<TelecommandPlanJob>(30);//遥控计划定时任务
|
|||
|
//FixedTimeTaskAsync<LightingControlTimeJob>(120);
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 定时任务开启
|
|||
|
/// </summary>
|
|||
|
/// <typeparam name="T">执行内容</typeparam>
|
|||
|
/// <param name="intval">执行间隔</param>
|
|||
|
private async void FixedTimeTaskAsync<T>(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<T>()
|
|||
|
.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);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 巡检灯光控制
|
|||
|
/// </summary>
|
|||
|
[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);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|