RunningDataCache.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Abp.Dependency;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Concurrent;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using ToolLibrary.LogHelper;
  9. using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model;
  10. using YunDa.ISAS.DataTransferObject.DataMonitoring.LinkageExecuteActivityDto;
  11. using YunDa.ISAS.DataTransferObject.EquipmentLiveData;
  12. using YunDa.ISAS.DataTransferObject.GeneralInformation.TransformerSubstationDto;
  13. using YunDa.ISAS.Redis.Repositories;
  14. using ConstantModel = YunDa.ISAS.DataTransferObject.EquipmentLiveData.ConstantModel;
  15. namespace Yunda.ISAS.DataMonitoringServer.DataCenter
  16. {
  17. public class RunningDataCache : ISingletonDependency
  18. {
  19. private readonly RedisDataRepository _redisDataRepository;
  20. public TransformerSubstationOutput _transformerSubstation;
  21. public bool IsRunning { get; set; }
  22. public RunningDataCache(RedisDataRepository redisDataRepository)
  23. {
  24. _redisDataRepository= redisDataRepository;
  25. Task.Factory.StartNew( () => {
  26. while (true)
  27. {
  28. UpdateEquipmentDataModelDicRedis();
  29. Task.Delay(TimeSpan.FromSeconds(10*60)).Wait();
  30. }
  31. },TaskCreationOptions.LongRunning);
  32. }
  33. public async void UpdateEquipmentDataModelDicRedis()
  34. {
  35. try
  36. {
  37. await _redisDataRepository.EquipmentDataModelDicRedis.DeleteKeyAsync(ConstantModel.EquipmentDataModelDicRedisKey);
  38. await _redisDataRepository.EquipmentDataModelDicRedis.HashSetUpdateManyAsync(ConstantModel.EquipmentDataModelDicRedisKey, EquipmentDataDic.Keys.ToList(), EquipmentDataDic.Values.ToList());
  39. }
  40. catch (Exception e)
  41. {
  42. Log4Helper.Error(this.GetType(), "内存数据库插入", e);
  43. }
  44. }
  45. public ConcurrentDictionary<Guid, EquipmentDataModel> EquipmentDataDic { get; set; }
  46. = new ConcurrentDictionary<Guid, EquipmentDataModel>();
  47. public TelemeteringModel GetTelemeteringModel(Guid? guid =null,string name ="")
  48. {
  49. foreach (var item in EquipmentDataDic.Values)
  50. {
  51. if (!string.IsNullOrWhiteSpace(name))
  52. {
  53. var relemeteringModel = item.Telemeterings.FirstOrDefault(t => t.Name.Contains(name));
  54. if (relemeteringModel != null)
  55. {
  56. return relemeteringModel;
  57. }
  58. }
  59. else
  60. {
  61. var relemeteringModel = item.Telemeterings.FirstOrDefault(t => t.Id == guid);
  62. if (relemeteringModel != null)
  63. {
  64. return relemeteringModel;
  65. }
  66. }
  67. }
  68. return null;
  69. }
  70. public TelesignalisationModel GetTelesignalisationModel(Guid? guid = null, string name = "")
  71. {
  72. foreach (var item in EquipmentDataDic.Values)
  73. {
  74. if (!string.IsNullOrWhiteSpace(name))
  75. {
  76. var telesignalisationModel = item.Telesignalisations.FirstOrDefault(t => t.Name.Contains( name));
  77. if (telesignalisationModel != null)
  78. {
  79. return telesignalisationModel;
  80. }
  81. }
  82. else
  83. {
  84. var telesignalisationModel = item.Telesignalisations.FirstOrDefault(t => t.Id == guid);
  85. if (telesignalisationModel != null)
  86. {
  87. return telesignalisationModel;
  88. }
  89. }
  90. }
  91. return null;
  92. }
  93. //public ConcurrentDictionary<Guid, TelemeteringModel> TelemeteringDic { get; set; } =
  94. // new ConcurrentDictionary<Guid, TelemeteringModel>();
  95. //public ConcurrentDictionary<Guid, TelesignalisationModel> TelesignalisationDic { get; set; } =
  96. // new ConcurrentDictionary<Guid, TelesignalisationModel>();
  97. /// <summary>
  98. /// 遥控策略数据缓存
  99. /// </summary>
  100. public ConcurrentBag<LinkageExecuteActivityOutput> LinkageExecuteActivities { get; set; }
  101. = new ConcurrentBag<LinkageExecuteActivityOutput>();
  102. /// <summary>
  103. /// 摄像头数据缓存
  104. /// </summary>
  105. public ConcurrentBag<VideoDev> VideoDevs { get; set; }
  106. = new ConcurrentBag<VideoDev>();
  107. /// <summary>
  108. /// 遥控数据缓存
  109. /// </summary>
  110. public ConcurrentBag<TelecommandModel> TelecommandModels { get; set; }
  111. = new ConcurrentBag<TelecommandModel>();
  112. /// <summary>
  113. /// 遥测小时统计列表
  114. /// </summary>
  115. public Dictionary<Guid, TelemeteringHourStatisticsModel> TelemeteringHourStatisticsDic { get; set; }
  116. = new Dictionary<Guid, TelemeteringHourStatisticsModel>();
  117. /// <summary>
  118. /// 联动策略缓存
  119. /// </summary>
  120. public ConcurrentBag<LinkageStrategyModel> LinkageStrategys { get; set; }
  121. = new ConcurrentBag<LinkageStrategyModel>();
  122. }
  123. }