123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- using Quartz;
- using System;
- using log4net;
- using RDIFramework.Utilities;
- using System.Collections.Generic;
- using RabbitMQ.Client;
- using System.Text;
- using Newtonsoft.Json;
- using System.Data;
- 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");
- String sql = "";
- DataTable dt = dbHelper.Fill(sql);
- if (dt != null)
- {
- // 数据 获取 以及 赋值 知道表结构了在去写查询和赋值
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- 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; }
- }
- }
|