Selaa lähdekoodia

Merge remote-tracking branch 'origin/master'

jochu_liu 1 vuosi sitten
vanhempi
commit
c8958bbc47

+ 41 - 78
TimedUpload/QuartzJobs/ChangleWaterQualityDataJob.cs

@@ -47,8 +47,8 @@ namespace TimedUpload.QuartzJobs
 
             if (channels.Count > 0)
             {
-                SendZoneMeterUser(channels, properties);
-                SendZoneMeterUserHis(channels, properties);
+                SendQualityMeterUser(channels, properties);
+                SendQualityMeterUserHis(channels, properties);
             }
 
             foreach (KeyValuePair<string, IConnection> item in connections)
@@ -63,7 +63,7 @@ namespace TimedUpload.QuartzJobs
         /// 水质设备添加
         /// </summary>
         /// <param name="channel"></param>
-        private void SendZoneMeterUser(Dictionary<string, IModel> channels, Dictionary<string, IBasicProperties> properties)
+        private void SendQualityMeterUser(Dictionary<string, IModel> channels, Dictionary<string, IBasicProperties> properties)
         {
             string changLeWaterQualityId = Constants.changLeWaterQualityId;
             log.Info("水质设备基础数据同步任务开始执行.................\r\n");
@@ -152,87 +152,50 @@ namespace TimedUpload.QuartzJobs
         /// 水质设备历史数据
         /// </summary>
         /// <param name="channel"></param>
-        private void SendZoneMeterUserHis(Dictionary<string, IModel> channels, Dictionary<string, IBasicProperties> properties)
+        private void SendQualityMeterUserHis(Dictionary<string, IModel> channels, Dictionary<string, IBasicProperties> properties)
         {
             string changLeWaterQualityHisId = Constants.changLeWaterQualityHisId;
             log.Info("水质设备抄表数据同步任务开始执行.................\r\n");
-            String sqlMeter = "SELECT * FROM [设备信息] ORDER BY ID";
-            DataTable dtMeter = dbHelper.Fill(sqlMeter);
+            String sqlMeter = "SELECT top 100 * FROM [历史记录_zhsw] WHERE HistoryRecordID > " + changLeWaterQualityHisId + " ORDER BY HistoryRecordID";
+            DataTable dtMeterHis = dbHelper.Fill(sqlMeter);
 
-            for (int i = 0; i < dtMeter.Rows.Count; i++)
+            StringBuilder message = new StringBuilder();
+            for (int j = 0; j < dtMeterHis.Rows.Count; j++)
             {
-                DataRow drMeter = dtMeter.Rows[i];
-                String meterId = drMeter["ID"].ToString();
-                String meterCode = drMeter["考核表编码"].ToString();
-                String lastTime = "";
-
-                int nowYear = DateTime.Now.Year;
-
-                //for (int k = lastYear; k <= nowYear; k++)
-                //{
-                //    string tablename = "历史记录_" + ("000000" + meterId).Substring(meterId.Length, 6) + "_" + k;
-
-                    
-                //    DataTable dtMeterHis = dbHelper.Fill("");
-
-                //    StringBuilder message = new StringBuilder();
-                //    for (int j = 0; j < dtMeterHis.Rows.Count; j++)
-                //    {
-                //        message.Clear();
-                //        try
-                //        {
-                //            DataRow drMeterHis = dtMeterHis.Rows[j];
-                //            String getDateTime = Convert.ToDateTime(drMeterHis["采集时间"]).ToString("yyyy-MM-dd HH:mm:ss");
-                //            message.Append("{");
-                //            message.Append("\"meterAssessmentCode\": \"").Append(meterCode).Append("\",");
-                //            message.Append("\"manufacturerCode\": ").Append(Constants.ManufacturerCode).Append(",");
-                //            message.Append("\"getDateTime\": \"").Append(getDateTime).Append("\",");
-                //            if (Convert.DBNull != drMeterHis["净累计流量"])
-                //            {
-                //                message.Append("\"netCumulativeFlow\": ").Append(Convert.ToDecimal(drMeterHis["净累计流量"])).Append(",");
-                //            }
-                //            if (Convert.DBNull != drMeterHis["正累计流量"])
-                //            {
-                //                message.Append("\"positiveCumulativeFlow\": ").Append(Convert.ToDecimal(drMeterHis["正累计流量"])).Append(",");
-                //            }
-                //            if (Convert.DBNull != drMeterHis["负累计流量"])
-                //            {
-                //                message.Append("\"negativeCumulativeFlow\": ").Append(Convert.ToDecimal(drMeterHis["负累计流量"])).Append(",");
-                //            }
-                //            if (Convert.DBNull != drMeterHis["瞬时流量"])
-                //            {
-                //                message.Append("\"instantaneousFlow\": ").Append(Convert.ToDecimal(drMeterHis["瞬时流量"])).Append(",");
-                //            }
-                //            if (Convert.DBNull != drMeterHis["压力"])
-                //            {
-                //                message.Append("\"pressure\": ").Append(Convert.ToDecimal(drMeterHis["压力"])).Append(",");
-                //            }
-                //            if (Convert.DBNull != drMeterHis["电池电压"])
-                //            {
-                //                message.Append("\"batteryVoltageValue\": ").Append(Convert.ToDecimal(drMeterHis["电池电压"])).Append(",");
-                //            }
-                //            message.Append("}");
+                message.Clear();
+                try
+                {
+                    DataRow drMeterHis = dtMeterHis.Rows[j];
+                    String getDateTime = Convert.ToDateTime(drMeterHis["GetDateTime"]).ToString("yyyy-MM-dd HH:mm:ss");
+                    String meterCode = "wwkjsz" + drMeterHis["DevId"].ToString();
+                    message.Append("{");
+                    message.Append("\"meterAssessmentCode\": \"").Append(meterCode).Append("\",");
+                    message.Append("\"manufacturerCode\": ").Append(Constants.ManufacturerCode).Append(",");
+                    message.Append("\"getDateTime\": \"").Append(getDateTime).Append("\",");
+                    if (Convert.DBNull != drMeterHis["Chlorine"])
+                    {
+                        message.Append("\"chlorine\": ").Append(Convert.ToDecimal(drMeterHis["Chlorine"])).Append(",");
+                    }
+                    if (Convert.DBNull != drMeterHis["Turbidity"])
+                    {
+                        message.Append("\"turbidity\": ").Append(Convert.ToDecimal(drMeterHis["Turbidity"])).Append(",");
+                    }
+                    message.Append("}");
 
-                //            foreach (KeyValuePair<string, IModel> item in channels)
-                //            {
-                //                string key = item.Key;
-                //                IModel channel = item.Value;
-                //                IBasicProperties property = properties[key];
-                //                channel.BasicPublish("zone.deviceHis", "", property, Encoding.UTF8.GetBytes(message.ToString())); //生产消息
-                //            }
-                //            lastTime = getDateTime;
-                //        }
-                //        catch (Exception ex)
-                //        {
-                //            log.Info("水质设备历史记录同步任务数据推送失败:" + message.ToString() + "\r\n");
-                //            log.Error(ex.Message + "===========" + ex.StackTrace + "\r\n");
-                //        }
-                //    }
-                //}
-                //if (!"".Equals(lastTime))
-                //{
-                //    uploadHis[meterCode] = lastTime;
-                //}
+                    foreach (KeyValuePair<string, IModel> item in channels)
+                    {
+                        string key = item.Key;
+                        IModel channel = item.Value;
+                        IBasicProperties property = properties[key];
+                        channel.BasicPublish("zone.deviceHis", "", property, Encoding.UTF8.GetBytes(message.ToString())); //生产消息
+                    }
+                    changLeWaterQualityHisId = drMeterHis["HistoryRecordID"].ToString();
+                }
+                catch (Exception ex)
+                {
+                    log.Info("水质设备历史记录同步任务数据推送失败:" + message.ToString() + "\r\n");
+                    log.Error(ex.Message + "===========" + ex.StackTrace + "\r\n");
+                }
             }
 
             UpdateAppConfig("ChangLeWaterQualityHisId", changLeWaterQualityHisId);

+ 1 - 1
TimedUpload/app.config

@@ -8,7 +8,7 @@
     <add key="changleWaterFactoryDb" value=""/>
     <add key="ChangLeWaterQualityDb" value="Data Source=47.105.90.108;Initial Catalog=舜水水质;uid=sa;password=wwkj@2136807" />
     <!-- 智慧水务系统RabbitMQ信息 start -->
-    <add key="UploadUrl" value="127.0.0.1" />
+    <add key="UploadUrl" value="182.92.149.41" />
     <add key="UploadPort" value="5678" />
     <add key="UploadUserName" value="wwkj" />
     <add key="UploadPassword" value="wwkj123!" />

+ 24 - 5
TimedUpload/quartz_jobs.xml

@@ -168,7 +168,7 @@
       </cron>
     </trigger>-->
     <!--昌乐泵房数据定时上传数据-->
-    <job>
+    <!--<job>
       <name>ChangleSecondPumpDataJob</name>
       <group>ChangleSecondPumpData</group>
       <description>昌乐泵房数据定时上传服务</description>
@@ -185,9 +185,9 @@
         <start-time>2017-08-08T00:00:00+08:00</start-time>
         <cron-expression>0 0/1 * * * ? *</cron-expression>
       </cron>
-    </trigger>
+    </trigger>-->
     <!--昌乐水厂数据定时上传数据-->
-    <job>
+    <!--<job>
       <name>ChangleWaterFactoryDataJob</name>
       <group>ChangleWaterFactoryData</group>
       <description>昌乐泵房数据定时上传服务</description>
@@ -204,9 +204,9 @@
         <start-time>2017-08-08T00:00:00+08:00</start-time>
         <cron-expression>0 0 1 * * ? *</cron-expression>
       </cron>
-    </trigger>
+    </trigger>-->
     <!--昌乐营收数据定时上传数据-->
-    <job>
+    <!--<job>
       <name>ChangleBusinessDataJob</name>
       <group>ChangleBusinessData</group>
       <description>数据定时上传服务</description>
@@ -223,6 +223,25 @@
         <start-time>2017-08-08T00:00:00+08:00</start-time>
         <cron-expression>0 0 1 * * ? *</cron-expression>
       </cron>
+    </trigger>-->
+    <!--昌乐水质数据定时上传数据-->
+    <job>
+      <name>ChangleWaterQualityDataJob</name>
+      <group>ChangleWaterQualityData</group>
+      <description>昌乐水质数据定时上传服务</description>
+      <job-type>TimedUpload.QuartzJobs.ChangleWaterQualityDataJob,TimedUpload</job-type>
+      <durable>true</durable>
+      <recover>false</recover>
+    </job>
+    <trigger>
+      <cron>
+        <name>ChangleWaterQualityDataJobTrigger</name>
+        <group>ChangleWaterQualityData</group>
+        <job-name>ChangleWaterQualityDataJob</job-name>
+        <job-group>ChangleWaterQualityData</job-group>
+        <start-time>2017-08-08T00:00:00+08:00</start-time>
+        <cron-expression>0 0 1 * * ? *</cron-expression>
+      </cron>
     </trigger>
   </schedule>
 </job-scheduling-data>