Преглед изворни кода

添加 噪声设备的数据同步

jochu_liu пре 2 година
родитељ
комит
332bb382c7
2 измењених фајлова са 204 додато и 0 уклоњено
  1. 203 0
      TimedUpload/QuartzJobs/NoiseDataUploadJob.cs
  2. 1 0
      TimedUpload/TimedUpload.csproj

+ 203 - 0
TimedUpload/QuartzJobs/NoiseDataUploadJob.cs

@@ -0,0 +1,203 @@
+using Quartz;
+using System;
+using log4net;
+using RDIFramework.Utilities;
+using System.Collections.Generic;
+using RabbitMQ.Client;
+using System.Text;
+using Newtonsoft.Json;
+
+namespace TimedUpload.QuartzJobs
+{
+    [DisallowConcurrentExecution]
+    public class NoiseDataUploadJob : IJob
+    {
+        private readonly ILog log = LogManager.GetLogger(typeof(NoiseDataUploadJob));
+
+        private const String NOISECHANNELNAME = "noiseMonitor.deviceHis";
+
+        public void Execute(IJobExecutionContext context)
+        {
+            string[] uploadUrls = Constants.UploadUrl.Split('|');
+            Dictionary<string, IConnection> connections = new Dictionary<string, IConnection>();
+            Dictionary<string, IModel> channels = new Dictionary<string, IModel>();
+            Dictionary<string, IBasicProperties> properties = new Dictionary<string, IBasicProperties>();
+
+            foreach (string uploadUrl in uploadUrls)
+            {
+                ConnectionFactory factory = new ConnectionFactory();
+                factory.HostName = uploadUrl;//主机名,Rabbit会拿这个IP生成一个endpoint,这个很熟悉吧,就是socket绑定的那个终结点。
+                factory.UserName = Constants.UploadUserName;//默认用户名,用户可以在服务端自定义创建,有相关命令行
+                factory.Password = Constants.UploadPassword;//默认密码
+
+                factory.AutomaticRecoveryEnabled = true; // 链接断开会自动重连
+
+                IConnection connection = factory.CreateConnection();
+                IModel channel = connection.CreateModel();
+                channel.QueueDeclare(NOISECHANNELNAME, true, false, false, null);//创建一个名称为kibaqueue的消息队列
+
+                IBasicProperties property = channel.CreateBasicProperties();
+                property.ContentType = "text/plain";
+                property.DeliveryMode = 2; //持久化
+                connections.Add(uploadUrl, connection);
+                properties.Add(uploadUrl, property);
+                channels.Add(uploadUrl, channel);
+            }
+            if (channels.Count > 0)
+            {
+                SendNoiseDataUploadHistory(channels, properties);
+            }
+
+            foreach (KeyValuePair<string, IConnection> item in connections)
+            {
+                IConnection connection = item.Value;
+                connection.Close();
+            }
+        }
+
+        /// <summary>
+        /// 同步噪声设备的数据
+        /// </summary>
+        /// <param name="channels"></param>
+        /// <param name="properties"></param>
+        private void SendNoiseDataUploadHistory(Dictionary<string, IModel> channels, Dictionary<string, IBasicProperties> properties) {
+
+            try
+            {
+                NoiseModel model = new NoiseModel();
+                log.Info("同步噪声声设备数据...............start\r\n");
+
+                // 数据 获取 以及 赋值 等着以后有设备了再说 
+
+                model.deviceCode = "";
+                model.readTime = DateTime.Now;
+                model.videoUrl = "";
+                model.weather = "";
+                model.isLeakPoint = 0;
+                model.csq = 0;
+                model.psrp = 0;
+                model.snr = 0;
+                model.ecl = 0;
+                model.pcl = 0;
+                model.isBatteryUnusual = 0;
+                model.isHitch = 0;
+                model.singnalType = 1;
+
+                string message = JsonConvert.SerializeObject(model);
+
+                foreach (var item in channels)
+                {
+                    string key = item.Key;
+                    IModel channel = item.Value;
+                    IBasicProperties property = properties[key];
+                    channel.BasicPublish(NOISECHANNELNAME, "", property, Encoding.UTF8.GetBytes(message)); //生产消息
+                }
+
+                log.Info("同步噪声声设备数据...............end\r\n");
+            }
+            catch (Exception ex)
+            {
+                log.Error("步噪声声设备数据错误:" + ex.Message+ "====" + ex.StackTrace + "\r\n");
+            }
+        }
+
+
+
+        static IDbProvider dbHelper
+        {
+            get
+            {
+                var DbDefine = DbFactoryProvider.GetProvider(CurrentDbType.SqlServer, Constants.WaterFactoryDbConncetion);
+                return DbDefine;
+            }
+        }
+    }
+
+    class NoiseModel
+    {
+        /// <summary>
+        /// 设备编号
+        /// </summary>
+        public string deviceCode { get; set; }
+
+        /// <summary>
+        /// 上报时间
+        /// </summary>
+        public DateTime readTime { get; set; }
+
+        /// <summary>
+        /// 音频路径
+        /// </summary>
+        public string videoUrl { get; set; }
+
+        /// <summary>
+        /// 天气
+        /// </summary>
+        public string weather { get; set; }
+
+        /// <summary>
+        /// 是否漏点  0 不是 1 是
+        /// </summary>
+        public int isLeakPoint { get; set; }
+
+        /// <summary>
+        /// csq 信号强度
+        /// CSQ指示RSSI强度,取值范围为0-31,数值越大信号越好。
+        /// CSQ值大于5,终端即可正常工作。若CSQ值小于5即不能正常工作。如果出现99表示信道无效。
+        /// CSQ=(RSSI<接收信号强度dBm>+113)/2
+        /// </summary>
+        public int csq { get; set; }
+
+        /// <summary>
+        /// psrp 无线信号强度的关键参数 RSRP  前期写错了 不好改了
+        /// RSRP是代表无线信号强度的关键参数,反映当前信道的路径损耗强度,用于小区覆盖的测量和小区选择/重选。
+        /// 测量频率带宽上承载参考信号的资源元素(RE)上的接收功率(以瓦为单位)的线性平均值
+        /// RSRP的取值范围:
+        /// -44~-140dBm,值越大越好。
+        /// Rx≤-105,覆盖强度等级6,表示覆盖较差。业务基本无法连接。
+        /// -105<Rx≤-95,覆盖强度等级5,表示覆盖差。室外业务能够连接,但连接成功率低,室内业务基本无法连接。
+        /// -95<Rx≤-85,覆盖强度等级4,表示覆盖一般,室外能够连接,室内连接成功率低。
+        /// -85<Rx≤-75,覆盖强度等级3,表示覆盖较好,室内外都能够连接。
+        /// -75<Rx≤-65,覆盖强度等级2,表示覆盖好,室内外都能够很好的连接。
+        /// Rx>-65,覆盖强度等级1,表示覆盖非常好。
+        /// </summary>
+        public int psrp { get; set; }
+
+        /// <summary>
+        /// snr 信噪比
+        /// 信号功率与噪声功率的比值,比值越大越好
+        /// </summary>
+        public int snr { get; set; }
+
+        /// <summary>
+        /// ecl 覆盖等级
+        /// ECL共分三个等级,数值从0到2,分别对应可对抗144dB、154dB、164dB的信号衰减
+        /// 基站和UE之间会根据其所在的CEL来选择相对应的信息重发次数。
+        /// 0表示常规覆盖,MCL<144dB,与现有GPRS覆盖一致。
+        /// 1表示扩展覆盖,144dB<MCL<154dB,在现有GPRS覆盖的基础上提升了10dB
+        /// 2表示极端覆盖,154dB<MCL<164dB,在现有GPRS覆盖的基础上提升了20dB。
+        /// </summary>
+        public int ecl { get; set; }
+
+        /// <summary>
+        /// pcl
+        /// </summary>
+        public int pcl { get; set; }
+
+        /// <summary>
+        /// 电池是否异常 0 正常 1 异常
+        /// </summary>
+        public int isBatteryUnusual { get; set; }
+
+        /// <summary>
+        /// 是否故障 0 正常 1 故障
+        /// </summary>
+        public int isHitch { get; set; }
+
+        /// <summary>
+        /// 信号状态  1 在线 2 离线
+        /// </summary>
+        public int singnalType { get; set; }
+
+    }
+}

+ 1 - 0
TimedUpload/TimedUpload.csproj

@@ -95,6 +95,7 @@
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="QuartzJobs\DABusinessDataJob.cs" />
+    <Compile Include="QuartzJobs\NoiseDataUploadJob.cs" />
     <Compile Include="QuartzJobs\TestJob.cs" />
     <Compile Include="QuartzJobs\WaterFactoryAreaDataJob.cs" />
     <Compile Include="QuartzJobs\WorkmanshipDataUploadJob.cs" />