TelecomDataCenter.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using Abp.Dependency;
  2. using DotNetty.Common;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Concurrent;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
  10. using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Helper;
  11. using YunDa.ISAS.DataTransferObject.DataMonitoring.TelemeteringConfigurationDto;
  12. using YunDa.ISAS.DataTransferObject.DataMonitoring.TelemeteringConfigurationDto.SearchCondition;
  13. using YunDa.ISAS.DataTransferObject.DataMonitoring.TelesignalisationConfigurationDto;
  14. using YunDa.ISAS.DataTransferObject.EquipmentLiveData;
  15. using YunDa.ISAS.DataTransferObject.Iec104;
  16. using YunDa.ISAS.Entities.DataMonitoring;
  17. using ConstantModel = Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model.ConstantModel;
  18. namespace Yunda.ISAS.DataMonitoringServer.DataCenter
  19. {
  20. public class TelecomDataCenter : ISingletonDependency
  21. {
  22. private List<TelemeteringConfigurationOutput> _telemeteringConfigurationRepo = new List<TelemeteringConfigurationOutput>();
  23. private List<TelesignalisationConfigurationOutput> _telesignalisationConfigurationRepo = new List<TelesignalisationConfigurationOutput>();
  24. private ConfigurationHepler _configurationHepler;
  25. private DataRepository _dataRepository;
  26. private readonly RedisDataRepository _redisDataRepository;
  27. private readonly RunningDataCache _runningDataCache;
  28. /// <summary>
  29. /// 已经发送的104数据,使用地址判断
  30. /// </summary>
  31. private readonly List<IecServerData> _sendediecServerDatas = new List<IecServerData>();
  32. public TelecomDataCenter(ConfigurationHepler configurationHepler,
  33. DataRepository dataRepository,
  34. RunningDataCache runningDataCache,
  35. RedisDataRepository redisDataRepository)
  36. {
  37. _configurationHepler = configurationHepler;
  38. _dataRepository = dataRepository;
  39. _redisDataRepository = redisDataRepository;
  40. _runningDataCache = runningDataCache;
  41. }
  42. /// <summary>
  43. /// 自检判定
  44. /// </summary>
  45. public void ExcuteSelfChecking()
  46. {
  47. Task.Factory.StartNew(async () =>
  48. {
  49. while (true)
  50. {
  51. try
  52. {
  53. ResetTimeoutHandle(_runningDataCache.EquipmentDataDic.ToDictionary(kv => kv.Key, kv => kv.Value));
  54. }
  55. catch (Exception ex)
  56. {
  57. MonitoringEventBus.LogHandler(ex.Message, "异常信息");
  58. }
  59. Task.Delay(2000).Wait();
  60. }
  61. }, TaskCreationOptions.LongRunning);
  62. }
  63. private void ResetTimeoutHandle(Dictionary<Guid, EquipmentDataModel> dic)
  64. {
  65. foreach (EquipmentDataModel item in dic.Values)
  66. {
  67. var selfChecking = item.Telesignalisations.FirstOrDefault(t => t.IsSelfCheckingValue && t.SelfCheckingConfigurationId.HasValue);
  68. if (selfChecking != null)
  69. {
  70. var virtualDevice = item.Telesignalisations.FirstOrDefault(t => t.IsVirtualDevice);
  71. if (virtualDevice != null)
  72. {
  73. var teleData = _sendediecServerDatas.FirstOrDefault(t =>
  74. t.devAddr == (byte)virtualDevice.InfoDeviceAddress
  75. && t.devCpu == (byte)virtualDevice.InfoCPUSector
  76. && t.inf == virtualDevice.InfoAddress);
  77. if (teleData.inf == 0)
  78. {
  79. var iecdata = new IecServerData();
  80. iecdata.devAddr = (byte)virtualDevice.InfoDeviceAddress;
  81. iecdata.dateTime = DateTime.Now;
  82. iecdata.devCpu = (byte)virtualDevice.InfoCPUSector;
  83. iecdata.inf = virtualDevice.InfoAddress;
  84. iecdata.dataType = 2;
  85. iecdata.devName = "visual";
  86. iecdata.yxValue = selfChecking.SelfCheckingConfiguration.SendTelesignalisationValue - 1;
  87. _sendediecServerDatas.Add(iecdata);
  88. var res = ToolLibrary.HttpHelper.HttpPostRequest<bool>(_runningDataCache._transformerSubstation.Iec104ServerUrl + "SendData", iecdata);
  89. MonitoringEventBus.LogHandler($"发送遥信:装置地址:{iecdata.devAddr} 扇区号:{iecdata.devCpu} 信息地址:{iecdata.inf} 值:{iecdata.yxValue}", "虚拟点位信息");
  90. }
  91. if (selfChecking.SelfCheckingConfiguration.DataType == DataTypeEnum.Telesignalisation
  92. && selfChecking.SelfCheckingConfiguration.JudgmentMode == JudgmentModeEnum.ResetTimeout)
  93. {
  94. //是否发送自检信息
  95. bool isSendErrorData = false;
  96. if (DateTime.Now - selfChecking.ResultTime > TimeSpan.FromSeconds(selfChecking.SelfCheckingConfiguration.TimeOfJudgment))
  97. {
  98. isSendErrorData = true;
  99. }
  100. else
  101. {
  102. selfChecking.IsSendSelfCheck = false;
  103. }
  104. if (selfChecking.RemoteType == RemoteTypeEnum.SinglePoint ? selfChecking.ResultValue == 1 : selfChecking.ResultValue == 2)
  105. {
  106. isSendErrorData = true;
  107. }
  108. else
  109. {
  110. isSendErrorData = false;
  111. }
  112. if (!selfChecking.IsSendSelfCheck)
  113. {
  114. if (teleData.inf != 0)
  115. {
  116. var iecdata = new IecServerData();
  117. iecdata.devAddr = (byte)virtualDevice.InfoDeviceAddress;
  118. iecdata.dateTime = DateTime.Now;
  119. iecdata.devCpu = (byte)virtualDevice.InfoCPUSector;
  120. iecdata.inf = virtualDevice.InfoAddress;
  121. iecdata.dataType = 2;
  122. iecdata.devName = "visual";
  123. iecdata.yxValue = isSendErrorData ? selfChecking.SelfCheckingConfiguration.SendTelesignalisationValue : selfChecking.SelfCheckingConfiguration.SendTelesignalisationValue - 1;
  124. _sendediecServerDatas.Add(iecdata);
  125. var res = ToolLibrary.HttpHelper.HttpPostRequest<bool>(_runningDataCache._transformerSubstation.Iec104ServerUrl + "SendData", iecdata);
  126. MonitoringEventBus.LogHandler($"发送遥信:装置地址:{iecdata.devAddr} 扇区号:{iecdata.devCpu} 信息地址:{iecdata.inf} 值:{iecdata.yxValue}", "虚拟点位信息");
  127. selfChecking.IsSendSelfCheck = true;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }