CamAuthFixedTimeJob.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using ToolLibrary.LogHelper;
  6. using YunDa.ISAS.ExternalInteraction.DataTransferObject.InspectionEquipment;
  7. using YunDa.ISAS.Redis.Entities.CameraAuthCategory;
  8. namespace Yunda.ISAS.DataMonitoringServer.TimeWorkers
  9. {
  10. /// <summary>
  11. /// 摄像机权限
  12. /// </summary>
  13. [DisallowConcurrentExecution]
  14. public class CamAuthFixedTimeJob : IJob
  15. {
  16. public async Task Execute(IJobExecutionContext context)
  17. {
  18. CamAuthUpdate();
  19. }
  20. private async void CamAuthUpdate()
  21. {
  22. try
  23. {
  24. if (TimeWorkService._redisDataRepository.CameraAuthTimeRepository != null)
  25. {
  26. var videos =await TimeWorkService._redisDataRepository.CameraAuthTimeRepository.HashSetGetAllAsync(nameof(CameraAuthTimeRedis));
  27. var listFreeVideo = new Dictionary<string, List<string>>();
  28. if (videos != null && videos.Count != 0)
  29. {
  30. videos.ForEach(t =>
  31. {
  32. if (!t.IsNotifyFreeAuth && (t.FreeAuthTime < DateTime.Now || t.FreeAuthTime < DateTime.Now - TimeSpan.FromSeconds(1)))
  33. {
  34. if (t.CameraAuthenticationEntity != null)
  35. {
  36. if (listFreeVideo.ContainsKey(t.CameraAuthenticationEntity.Code))
  37. {
  38. listFreeVideo[t.CameraAuthenticationEntity.Code].Add(t.VideoDevEntity.DevName);
  39. }
  40. else
  41. {
  42. listFreeVideo.Add(t.CameraAuthenticationEntity.Code, new List<string>() { t.VideoDevEntity.DevName });
  43. }
  44. }
  45. }
  46. });
  47. }
  48. if (listFreeVideo.Count > 0)
  49. {
  50. foreach (var item in listFreeVideo)
  51. {
  52. var req = new ApplyControlToExternalInput()
  53. {
  54. Code = item.Key,
  55. CamNames = item.Value
  56. };
  57. TimeWorkService._webApiRequest.SendFreeCamAuth(req);
  58. }
  59. }
  60. }
  61. }
  62. catch (System.Exception ex)
  63. {
  64. Log4Helper.Error(this.GetType(), "定时摄像机鉴权数据更新发生错误", ex);
  65. }
  66. }
  67. }
  68. }