|
|
@@ -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
|
|
|
};
|
|
|
}
|
|
|
|