|
@@ -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;
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public string deviceCode { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DateTime readTime { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public string videoUrl { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public string weather { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int isLeakPoint { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int csq { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int psrp { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int snr { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int ecl { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int pcl { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int isBatteryUnusual { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int isHitch { get; set; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int singnalType { get; set; }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|