using Quartz;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ToolLibrary.LogHelper;
using YunDa.ISAS.ExternalInteraction.DataTransferObject.InspectionEquipment;
using YunDa.ISAS.Redis.Entities.CameraAuthCategory;
namespace Yunda.ISAS.DataMonitoringServer.TimeWorkers
{
///
/// 摄像机权限
///
[DisallowConcurrentExecution]
public class CamAuthFixedTimeJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
CamAuthUpdate();
}
private async void CamAuthUpdate()
{
try
{
if (TimeWorkService._redisDataRepository.CameraAuthTimeRepository != null)
{
var videos =await TimeWorkService._redisDataRepository.CameraAuthTimeRepository.HashSetGetAllAsync(nameof(CameraAuthTimeRedis));
var listFreeVideo = new Dictionary>();
if (videos != null && videos.Count != 0)
{
videos.ForEach(t =>
{
if (!t.IsNotifyFreeAuth && (t.FreeAuthTime < DateTime.Now || t.FreeAuthTime < DateTime.Now - TimeSpan.FromSeconds(1)))
{
if (t.CameraAuthenticationEntity != null)
{
if (listFreeVideo.ContainsKey(t.CameraAuthenticationEntity.Code))
{
listFreeVideo[t.CameraAuthenticationEntity.Code].Add(t.VideoDevEntity.DevName);
}
else
{
listFreeVideo.Add(t.CameraAuthenticationEntity.Code, new List() { t.VideoDevEntity.DevName });
}
}
}
});
}
if (listFreeVideo.Count > 0)
{
foreach (var item in listFreeVideo)
{
var req = new ApplyControlToExternalInput()
{
Code = item.Key,
CamNames = item.Value
};
TimeWorkService._webApiRequest.SendFreeCamAuth(req);
}
}
}
}
catch (System.Exception ex)
{
Log4Helper.Error(this.GetType(), "定时摄像机鉴权数据更新发生错误", ex);
}
}
}
}