Sfoglia il codice sorgente

将所有的数据查询放到了 DealWithCacheCommand的类下面

jochu 5 anni fa
parent
commit
fac42c8b5a

+ 26 - 4
NB_IOT_UDP_HP_SCOKET/WWKJUtil/DealWithCacheCommand.cs

@@ -26,7 +26,7 @@ namespace NB_IOT_UDP_HP_SCOKET.WWKJUtil
             SqlDataReader dr;
             //SqlConnection conn;
 
-            sql = "SELECT TOP 1 SendCmdRecordID,MeterId,SendText,ParentId,SendStatic FROM WWKJ_RMRS_SendCmdRecord WHERE sendStatic in(0,3) AND (MeterId != -1 AND MeterId = " + info.meterId + ") AND (MeterId = -1 AND CmdID = '"+info.Address+"') ORDER BY SendCmdRecordID";//0 未发送  3 发送过单未全部发送成功 
+            sql = "SELECT TOP 1 SendCmdRecordID,MeterId,SendText,ParentId,SendStatic FROM RMRS_SendCmdRecord WHERE sendStatic in(0,3) AND (MeterId != -1 AND MeterId = " + info.meterId + ") AND (MeterId = -1 AND CmdID = '"+info.Address+"') ORDER BY SendCmdRecordID";//0 未发送  3 发送过单未全部发送成功 
             arr = null;
             try
             {
@@ -86,7 +86,7 @@ namespace NB_IOT_UDP_HP_SCOKET.WWKJUtil
         {
             StringBuilder sb = new StringBuilder(220);
             
-            sb.Append("UPDATE WWKJ_RMRS_SendCmdRecord set sendStatic = '");
+            sb.Append("UPDATE RMRS_SendCmdRecord set sendStatic = '");
             sb.Append(sendState.ToString());
             sb.Append("',SendTime=GETDATE() ");
             if (!string.IsNullOrEmpty(returnCode)) {
@@ -97,12 +97,12 @@ namespace NB_IOT_UDP_HP_SCOKET.WWKJUtil
 
             if (sendState == 3)
             {
-                sb.Append(" UPDATE WWKJ_RMRS_SendCmdRecord set sendStatic = 3, RecvTime = GETDATE() WHERE ParentId = ").Append(parentId);
+                sb.Append(" UPDATE RMRS_SendCmdRecord set sendStatic = 3, RecvTime = GETDATE() WHERE ParentId = ").Append(parentId);
             }
 
             if (sendState == 1)
             {
-                sb.Append(" UPDATE WWKJ_RMRS_SendCmdRecord set sendStatic = 1, RecvTime = GETDATE() WHERE ParentId = ").Append(parentId.ToString());
+                sb.Append(" UPDATE RMRS_SendCmdRecord set sendStatic = 1, RecvTime = GETDATE() WHERE ParentId = ").Append(parentId.ToString());
             }
 
             try
@@ -124,5 +124,27 @@ namespace NB_IOT_UDP_HP_SCOKET.WWKJUtil
             }
             
         }
+
+        /// <summary>
+        /// 通过表地址获取水表的id
+        /// </summary>
+        /// <param name="meterAddr"></param>
+        /// <returns></returns>
+        public static int GetMeterIdByAddress(string meterAddr)
+        {
+            int num = 0;
+            try
+            {
+                string sql = "SELECT MeterID FROM RMRS_MeterInfo WHERE right('00000000000000' +[ElecAddress],14) = '" + meterAddr + "' ";
+                num = DBHelper.ScalarToInt(sql);
+            }
+            catch (Exception ex)
+            {
+                LogUtil.WriteLog("GetMeterIdByAddress():" + ex.Message);
+                num = 0;
+            }
+
+            return num;
+        }
     }
 }

+ 4 - 3
NB_IOT_UDP_HP_SCOKET/WWKJUtil/ProtocolAnalysisTools.cs

@@ -167,9 +167,10 @@ namespace NB_IOT_UDP_HP_SCOKET.WWKJUtil
                 #region 判断是否有水表id
                 if (info.meterId == 0) //判断是否有水表id
                 {
-                    sb.Append(" SELECT MeterID FROM WWKJ_RMRS_MeterInfo WHERE right('00000000000000'+[ElecAddress],14) = '").Append(info.Address).Append("' ");
-                    info.meterId = DBHelper.ScalarToInt(sb.ToString());
-                    sb.Clear();
+                    //sb.Append(" SELECT MeterID FROM RMRS_MeterInfo WHERE right('00000000000000'+[ElecAddress],14) = '").Append(info.Address).Append("' ");
+                    //info.meterId = DBHelper.ScalarToInt(sb.ToString());
+                    //sb.Clear();
+                    info.meterId = DealWithCacheCommand.GetMeterIdByAddress(info.Address);
                     if (info.meterId == 0)
                     {
                         //sb.Append("SELECT ID FROM WWKJ_RMRS_NBBatchRegister where right('00000000000000' + MeterAddr, 14) = '").Append(info.Address).Append("' AND DeleteMark = 0");