Browse Source

更新插入放一起.

git-svn-id: https://202.107.226.68:8443/svn/Services/ResistanceMonitor@86 a05970a1-87b9-9d4f-9ee5-fa77e2ec115b
shenchunzhong 1 năm trước cách đây
mục cha
commit
49931da83e
1 tập tin đã thay đổi với 12 bổ sung11 xóa
  1. 12 11
      4.Data/HttpPrcess.cpp

+ 12 - 11
4.Data/HttpPrcess.cpp

@@ -906,11 +906,6 @@ int DealPosttRetesionForce(const char* body_ptr, const size_t body_len, const st
 			str_conf = yyjson_mut_write(doc, 0, &len);
 			yyjson_mut_doc_free(doc);
 			CResistAlarmMng::Instance()->Insert(mo, mp, posi, (uint8_t)eZL_ALARMTYPE::RETENSION_FORCE, pInfo);
-
-			time_t tt;
-			time(&tt);
-			sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
-				mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE, str_conf, tt);
 		}
 		else
 		{
@@ -943,21 +938,27 @@ int DealPosttRetesionForce(const char* body_ptr, const size_t body_len, const st
 
 			str_conf = yyjson_mut_write(doc, 0, &len);
 			yyjson_mut_doc_free(doc);
-			sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
-				str_conf, mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE);
-		}
-
-		if (str_conf) free(str_conf);
 
+		}
+		time_t tt;
+		time(&tt);
+		sql.Format("IF EXISTS (SELECT 1 FROM rm_alarm_set WHERE mo = '%s' and mp = '%s' and no = %d and type = %d)\
+			update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = % d and type = % d\
+			ELSE\
+			INSERT INTO[rm_alarm_set]([mo], [mp], [no], [type], [conf], [time]) VALUES('%s', '%s', % d, % d, '%s', '%I64u')",
+			mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE,
+			str_conf, mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE,
+			mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE, str_conf, tt);
 		if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
 		{
 			ASSERT(FALSE);
 			msg = "Óï¾äÖ´ÐÐʧ°Ü" + sql;
 			CSimpleLog::Error(msg.c_str());
 			code = 500;
+			if (str_conf) free(str_conf);
 			break;
 		}
-
+		if (str_conf) free(str_conf);
 		code = 200;
 
 	} while (false);