136 lines
6.4 KiB
C#
136 lines
6.4 KiB
C#
![]() |
using Quartz;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using ToolLibrary.LogHelper;
|
|||
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.DataCollection;
|
|||
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model;
|
|||
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelecommandPlanDto.TelecommandPlanItemDto;
|
|||
|
using YunDa.ISAS.Entities.DataMonitoring;
|
|||
|
|
|||
|
namespace Yunda.ISAS.DataMonitoringServer.TimeWorkers
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 遥控计划控制定时任务
|
|||
|
/// </summary>
|
|||
|
[DisallowConcurrentExecution]
|
|||
|
public class TelecommandPlanJob : IJob
|
|||
|
{
|
|||
|
public async Task Execute(IJobExecutionContext context)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var telecomandPlanDatas = TimeWorkService._webApiRequest
|
|||
|
.GetTelecommandPlanDatas(TimeWorkService._configurationHepler.SubstationId);
|
|||
|
|
|||
|
if (telecomandPlanDatas == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Action<IEnumerable<TelecommandPlanItemProperty>> sendTelecommandMsg = items =>
|
|||
|
{
|
|||
|
foreach (var item in items)
|
|||
|
{
|
|||
|
TimeWorkService._teleCommandDataSendTask.TelecommandTActionBlock.Post(new TelcommandDataModel()
|
|||
|
{
|
|||
|
Telecommand = new TelecommandModel()
|
|||
|
{
|
|||
|
Id = (Guid)item.TelecommandConfigurationId,
|
|||
|
CommandValue = item.TeleCommandValue,
|
|||
|
CPUSector = item.TelecommandConfiguration.CPUSector,
|
|||
|
DeviceAddress = item.TelecommandConfiguration.DeviceAddress,
|
|||
|
DispatcherAddress = item.TelecommandConfiguration.DispatcherAddress,
|
|||
|
InfoAddress = item.TelecommandConfiguration.InfoAddress,
|
|||
|
Sender = "遥控计划后台",
|
|||
|
Source = "Web后台"
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
bool isSameMinTime(DateTime dateTime1, DateTime dateTime2)
|
|||
|
{
|
|||
|
return dateTime1.Year == dateTime2.Year &&
|
|||
|
dateTime1.Month == dateTime2.Month &&
|
|||
|
dateTime1.Day == dateTime2.Day &&
|
|||
|
dateTime1.Hour == dateTime2.Hour &&
|
|||
|
dateTime1.Minute == dateTime2.Minute;
|
|||
|
}
|
|||
|
foreach (var telecomandPlanData in telecomandPlanDatas)
|
|||
|
{
|
|||
|
if (telecomandPlanData.Freq == FreqEnum.DAILY)
|
|||
|
{
|
|||
|
if (!isSameMinTime(DateTime.Now, telecomandPlanData.SendTelecommandTime))
|
|||
|
{
|
|||
|
if (DateTime.Now.Hour == telecomandPlanData.StartTime.Hour &&
|
|||
|
DateTime.Now.Minute == telecomandPlanData.StartTime.Minute)
|
|||
|
{
|
|||
|
sendTelecommandMsg(telecomandPlanData.TeleCommandPlanSetting.TeleCommandSettingItems);
|
|||
|
TimeWorkService._webApiRequest
|
|||
|
.UpdateTelecommandSendTime(telecomandPlanData.Id, DateTime.Now);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (telecomandPlanData.Freq == FreqEnum.WEEKLY)
|
|||
|
{
|
|||
|
if (!isSameMinTime(DateTime.Now, telecomandPlanData.SendTelecommandTime))
|
|||
|
{
|
|||
|
if (DateTime.Now.DayOfWeek == telecomandPlanData.StartTime.DayOfWeek &&
|
|||
|
DateTime.Now.Hour == telecomandPlanData.StartTime.Hour &&
|
|||
|
DateTime.Now.Minute == telecomandPlanData.StartTime.Minute
|
|||
|
)
|
|||
|
{
|
|||
|
sendTelecommandMsg(telecomandPlanData.TeleCommandPlanSetting.TeleCommandSettingItems);
|
|||
|
TimeWorkService._webApiRequest
|
|||
|
.UpdateTelecommandSendTime(telecomandPlanData.Id, DateTime.Now);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (telecomandPlanData.Freq == FreqEnum.MONTHLY)
|
|||
|
{
|
|||
|
if (!isSameMinTime(DateTime.Now, telecomandPlanData.SendTelecommandTime))
|
|||
|
{
|
|||
|
if (DateTime.Now.Day == telecomandPlanData.StartTime.Day &&
|
|||
|
DateTime.Now.Hour == telecomandPlanData.StartTime.Hour &&
|
|||
|
DateTime.Now.Minute == telecomandPlanData.StartTime.Minute)
|
|||
|
{
|
|||
|
sendTelecommandMsg(telecomandPlanData.TeleCommandPlanSetting.TeleCommandSettingItems);
|
|||
|
TimeWorkService._webApiRequest
|
|||
|
.UpdateTelecommandSendTime(telecomandPlanData.Id, DateTime.Now);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (telecomandPlanData.Freq == FreqEnum.YEARLY)
|
|||
|
{
|
|||
|
if (!isSameMinTime(DateTime.Now, telecomandPlanData.SendTelecommandTime))
|
|||
|
{
|
|||
|
if (DateTime.Now.Day == telecomandPlanData.StartTime.Day &&
|
|||
|
DateTime.Now.Month == telecomandPlanData.StartTime.Month &&
|
|||
|
DateTime.Now.Hour == telecomandPlanData.StartTime.Hour &&
|
|||
|
DateTime.Now.Minute == telecomandPlanData.StartTime.Minute
|
|||
|
|
|||
|
)
|
|||
|
{
|
|||
|
sendTelecommandMsg(telecomandPlanData.TeleCommandPlanSetting.TeleCommandSettingItems);
|
|||
|
TimeWorkService._webApiRequest
|
|||
|
.UpdateTelecommandSendTime(telecomandPlanData.Id, DateTime.Now);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Log4Helper.Error(this.GetType(), "遥控计划控制定时任务", ex);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|