Przeglądaj źródła

Z991239-4900 #comment 同步代码

Signed-Off-By: commit-hook
刘文涛80174520 2 lat temu
rodzic
commit
2eb2a61db0

+ 5 - 1
Module/mod_alarm/Alarm.h

@@ -35,7 +35,11 @@ struct alarmUpgraded_t
 
 struct alarm_state_t 
 {
-	unsigned long long SN;
+#ifdef RVC_OS_WIN
+	unsigned __int64 SN;
+#else
+    unsigned long long SN;
+#endif
 	unsigned long LifeID;
 	unsigned long Item;
 	char Level;

+ 74 - 61
Module/mod_alarm/AlarmFSM.cpp

@@ -1,8 +1,12 @@
 #include "stdafx.h"
 #include "AlarmFSM.h"
 #include "Event.h"
+#ifdef RVC_OS_WIN
+#include "json.h"
+#else
 #include "CommEntityRestful.hpp"
 #include "json/json.h"
+#endif
 
 namespace Task
 {
@@ -27,18 +31,26 @@ namespace Task
 					continue;
 				}
 				logSum=0;
-				
-				//IHttpFunc* client;
-				//client = create_http(m_fsm->HttpsLogCallBack);
+#ifdef RVC_OS_WIN
+				IHttpFunc* client;
+				client = create_http(m_fsm->HttpsLogCallBack);
 
 				bool isSendSucc=false;//查询是否成功标志
-				if(SendAlarmTaskImpl()){
+				if(SendAlarmTaskImpl(client)){
 					isSendSucc = true;
 				}else{
 					isSendSucc = false;
 				}
 
-				//client->Destory();
+				client->Destory();
+#else
+				bool isSendSucc=false;//查询是否成功标志
+				if(SendAlarmTaskImpl()){
+					isSendSucc = true;
+				}else{
+					isSendSucc = false;
+				}
+#endif
 
 				//m_fsm->PostEventFIFO(new SendAlarmEvent(isSendSucc));//返回处理结果
 				if(isSendSucc){
@@ -67,64 +79,64 @@ namespace Task
 				}
 			}
 		}
+#ifdef RVC_OS_WIN
+		bool SendAlarmTaskImpl(IHttpFunc* client){
 
-		//bool SendAlarmTaskImpl(IHttpFunc* client){
-
-		//	HttpStruct::SendAlarmTaskReq qTempReq;
-		//	HttpStruct::SendAlarmTaskRet qTempRet;
-		//	if(m_fsm->m_unSendAlarm.IsNullOrEmpty()){
-		//		//组装新的json告警信息
-		//		string strJson = m_fsm->alarmJson();
-		//		if(strJson.empty()){
-		//			return true;
-		//		}else{
-		//			qTempReq.m_reqStr = strJson.c_str();//请求参数
-		//			m_fsm->m_unSendAlarm = strJson.c_str();
-		//			m_fsm->m_sendBeginTime = CSmallDateTime::GetNow();
-		//		}
-		//	}else{
-		//		//重发新的告警信息
-		//		qTempReq.m_reqStr = m_fsm->m_unSendAlarm.GetData();//请求参数
-		//		Dbg("alarm retry send");
-		//	}
-		//	qTempReq.m_url=m_fsm->m_sendUrl.GetData();//访问地址
-		//	//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("alarm send =%s",qTempReq.m_reqStr.c_str());
-		//	
-		//	if(!client->Post(qTempReq, qTempRet)){
-		//		Dbg("SendAlarmTask http req fail,url=%s",qTempReq.m_url.c_str());
-		//		return false;//失败
-		//	}
-		//	Json::Reader reader;
-		//	Json::Value rootRet;
-		//	if (!reader.parse(qTempRet.m_retStr, rootRet, false))
-		//	{
-		//		Dbg("SendAlarmTask parse resp is fail");
-		//		return false;//失败
-		//	}
-
-		//	bool isSucc = rootRet["success"].asBool();
-		//	if(isSucc){
-		//		Dbg("SendAlarmTask [success] is succ,m_eachSum=%d",m_fsm->m_eachSum);
-		//		m_fsm->m_unSendAlarm="";//置为空
-		//		m_fsm->m_iSucc = m_fsm->m_iSucc+ m_fsm->m_eachSum ;//发送成功
-		//		m_fsm->m_eachSum = 0;//清空批次数量
-		//		return true;//写入成功
-		//	}else{
-		//		CSimpleStringA errCode = rootRet["code"].asString().c_str();
-		//		if(!errCode.IsNullOrEmpty()||errCode == "10101"){
-		//			//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask [success] is false,code = 10101");
-		//			m_fsm->m_unSendAlarm="";//置为空
-		//			m_fsm->m_iFail = m_fsm->m_iFail+ m_fsm->m_eachSum ;//发送失败
-		//			LogWarn(Severity_Low,Error_Exception,WARN_ALARM_PARSE_FAIL,CSimpleStringA::Format("SendAlarmTask [success] is false,code = 10101,throw away alarm num= %d,m_iFail=%d",m_fsm->m_eachSum,m_fsm->m_iFail));
-		//			m_fsm->m_eachSum = 0;//清空批次数量
-		//			return true;//中文乱码解析失败,默认成功
-		//		}else{
-		//			Dbg("SendAlarmTask [success] is false,code =%s",errCode);
-		//			return false;//写入失败
-		//		}
-		//	}
-		//}
+			HttpStruct::SendAlarmTaskReq qTempReq;
+			HttpStruct::SendAlarmTaskRet qTempRet;
+			if(m_fsm->m_unSendAlarm.IsNullOrEmpty()){
+				//组装新的json告警信息
+				string strJson = m_fsm->alarmJson();
+				if(strJson.empty()){
+					return true;
+				}else{
+					qTempReq.m_reqStr = strJson.c_str();//请求参数
+					m_fsm->m_unSendAlarm = strJson.c_str();
+					m_fsm->m_sendBeginTime = CSmallDateTime::GetNow();
+				}
+			}else{
+				//重发新的告警信息
+				qTempReq.m_reqStr = m_fsm->m_unSendAlarm.GetData();//请求参数
+				DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("alarm retry send");
+			}
+			qTempReq.m_url=m_fsm->m_sendUrl.GetData();//访问地址
+			//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("alarm send =%s",qTempReq.m_reqStr.c_str());
+
+			if(!client->Post(qTempReq, qTempRet)){
+				DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask http req fail,url=%s",qTempReq.m_url.c_str());
+				return false;//失败
+			}
+			Json::Reader reader;
+			Json::Value rootRet;
+			if (!reader.parse(qTempRet.m_retStr, rootRet, false))
+			{
+				DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask parse resp is fail");
+				return false;//失败
+			}
 
+			bool isSucc = rootRet["success"].asBool();
+			if(isSucc){
+				DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask [success] is succ,m_eachSum=%d",m_fsm->m_eachSum);
+				m_fsm->m_unSendAlarm="";//置为空
+				m_fsm->m_iSucc = m_fsm->m_iSucc+ m_fsm->m_eachSum ;//发送成功
+				m_fsm->m_eachSum = 0;//清空批次数量
+				return true;//写入成功
+			}else{
+				CSimpleStringA errCode = rootRet["code"].asString().c_str();
+				if(!errCode.IsNullOrEmpty()||errCode == "10101"){
+					//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask [success] is false,code = 10101");
+					m_fsm->m_unSendAlarm="";//置为空
+					m_fsm->m_iFail = m_fsm->m_iFail+ m_fsm->m_eachSum ;//发送失败
+					LogWarn(Severity_Low,Error_Exception,WARN_ALARM_PARSE_FAIL,CSimpleStringA::Format("SendAlarmTask [success] is false,code = 10101,throw away alarm num= %d,m_iFail=%d",m_fsm->m_eachSum,m_fsm->m_iFail));
+					m_fsm->m_eachSum = 0;//清空批次数量
+					return true;//中文乱码解析失败,默认成功
+				}else{
+					DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask [success] is false,code =%s",errCode);
+					return false;//写入失败
+				}
+			}
+		}
+#else
 		bool SendAlarmTaskImpl() {
 			HttpClientResponseResult result;
 			HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->m_sendUrl.GetData());
@@ -189,6 +201,7 @@ namespace Task
 			}
 			return true;
 		}
+#endif
 	};
 }
 

+ 7 - 0
Module/mod_alarm/AlarmFSM.h

@@ -55,7 +55,11 @@ struct AlarmReply
 struct AlarmStateUpload
 {
 	char TerminalNo[16];
+#ifdef RVC_OS_WIN
+	unsigned __int64 SN;
+#else
 	unsigned long long SN;
+#endif
 	unsigned long  LifeID;
 	unsigned long Item;
 	char Level;
@@ -218,7 +222,10 @@ public:
 
 	static void HttpsLogCallBack(const char* logtxt);
 	string alarmJson();
+#ifdef RVC_OS_WIN
+#else
 	int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len);
+#endif
 private:
 	//获取告警数量
 	bool is_alarm_empty();

+ 23 - 18
Module/mod_alarm/mod_alarm.cpp

@@ -1,6 +1,8 @@
 #include "stdafx.h"
 #include "mod_alarm.h"
-#ifdef RVC_OS_LINUX
+#ifdef RVC_OS_WIN
+
+#else
 #include <sys/timeb.h>
 #include "SpUtility.h"
 #endif
@@ -8,9 +10,12 @@
 
 void CAlarmEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
 	const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
-	const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
+	const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
 {
 		//Dbg("receive log,pszEntityName=%s,eLogType=%d,pszMessage=%s",pszEntityName,(int)eLogType,pszMessage);
+#ifdef RVC_OS_WIN
+
+#else
 		CSimpleStringA strMessage(true);
 		if (!(pszMessage == NULL || strlen(pszMessage) == 0))
 			strMessage = pszMessage;
@@ -22,7 +27,7 @@ void CAlarmEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,con
 					strMessage = tmpStr.c_str();
 			}
  		}
-
+#endif
 
 		alarm_t*Alarm = new alarm_t();
 		char cEntityName[32]={0};
@@ -42,14 +47,16 @@ void CAlarmEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,con
 
 		Alarm->UserCode	= dwUserCode;
 
-        if (eLogType == Log_Warning && eLevel == Severity_Low) {
-            Alarm->Level = '1';
-        } else {
-            _itoa((int)eLogType, &Alarm->Level, 16);//把level替换成logtype
-        }
+		//_itoa((int)eLevel,&Alarm->Level,16);
+		//新加逻辑,对于eLogType=2 并且level=Severity_Low的低告警数据,level设置为1
+		if(eLogType==Log_Warning&&eLevel==Severity_Low){
+			Alarm->Level='1';
+		}else{
+			_itoa((int)eLogType,&Alarm->Level,16);//把level替换成logtype,
+		}
 
-		char cDescription[512] = { 0 };
-		char clogTime[32] = { 0 };//2020-20-20 12:12:12.100 日志时间
+		char cDescription[512]={0};
+		char clogTime[32]={0};//2020-20-20 12:12:12.100 日志时间,记得释放
 		char warnTime[20]={0};//2020-20-20 12:12:12 告警时间,记得释放
 #ifdef RVC_OS_WIN
 		SYSTEMTIME st;
@@ -65,19 +72,17 @@ void CAlarmEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,con
 		sprintf(warnTime, "%04d-%02d-%02d %02d:%02d:%02d", nowTm.tm_year + 1900, nowTm.tm_mon + 1, nowTm.tm_mday, nowTm.tm_hour, nowTm.tm_min, nowTm.tm_sec);
 #endif
 		strncpy(cDescription, clogTime, 32);
+#ifdef RVC_OS_WIN
+		strncat(cDescription, pszMessage, 512 - 32 - 1);
+#else
 		strncat(cDescription, strMessage.GetData(), 512 - 32 - 1);
+#endif
+		
 		Alarm->Description = _strdup(cDescription);
 		Alarm->warnTime = _strdup(warnTime);
 
 
-		//modify by lwt 20200528 去除去重功能,
-		//去重
-		//if (m_fsm.find_UploadedAlarm(Alarm))
-		//{
-		//	return;
-		//}
-		//Dbg("rece,Entity=%s,Type=%c",Alarm->EntityName,Alarm->Level);
-		//m_fsm.add_alarm(Alarm);
+
 		m_fsm.add_NewAlarm(Alarm);
 		m_fsm.m_iRec++;
 		if(m_fsm.m_iRec%50==0){

+ 7 - 1
Module/mod_alarm/mod_alarm.h

@@ -6,9 +6,13 @@
 #include "SpIni.h"
 #include "AlarmFSM.h"
 #include "EventCode.h"
+#ifdef RVC_OS_WIN
 
+#else
 #include "SpTest.h"
 #include "modVer.h"
+#endif
+
 
 class CAlarmEntity : public CEntityBase,public ILogListener
 {
@@ -16,13 +20,15 @@ public:
 	CAlarmEntity(){}
 	virtual ~CAlarmEntity() {}
 	virtual const char *GetEntityName() const { return "Alarm"; }
+#ifdef RVC_OS_WIN
 
+#else
 	const char* GetEntityVersion() const override
 	{
 		return MODULE_VERSION_FULL;
 	}
-
 	ON_ENTITYT_TEST()
+#endif
 
 	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
 	{