diff --git a/product/src/service/calc_server/CalcServerThread.cpp b/product/src/service/calc_server/CalcServerThread.cpp index a37ff790..7745cd94 100644 --- a/product/src/service/calc_server/CalcServerThread.cpp +++ b/product/src/service/calc_server/CalcServerThread.cpp @@ -6,18 +6,20 @@ */ #include "CalcServerThread.h" -#include "pub_lua_engine_api/LuaEngineInterface.h" +#include #include +#include +#include "pub_lua_engine_api/LuaEngineInterface.h" #include "common/Common.h" #include "boost/algorithm/string.hpp" #include "boost/lexical_cast.hpp" #include "net_msg_bus_api/CMbCommunicator.h" #include "CalcServerCommon.h" -#include "string" #include "common/MessageChannel.h" #include "pub_utility_api/TimeUtil.h" #include "service/common/CommonDefine.h" -#include "string" +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/CommonConfigParse.h" using namespace std; using namespace iot_public; @@ -37,6 +39,9 @@ SInPointInfoMap CalcServerThread::m_inPointInfoMAP; //输入 SOutPointInfoMap CalcServerThread::m_outPointInfoMap; //保存上次发送的点值和状态 SInOutVecMap CalcServerThread::m_inOutVecMap; +const int CN_Calc_Period = 1000; //计算周期,单位ms +const int CN_Send_Data_Period = 15 * 1000; //定时发送所有计算数据的周期,单位ms + iot_service::CalcServerThread::CalcServerThread(const iot_public::SRunAppInfo &stRunAppInfo) :iot_public::CTimerThreadBase("CalcServerThread",0), m_stRunAppInfo(stRunAppInfo), @@ -46,6 +51,8 @@ iot_service::CalcServerThread::CalcServerThread(const iot_public::SRunAppInfo &s clean(); m_lastCheckCfgTime = 0; //上次检查配置时间 m_lastCalcTime = 0; + m_nCalcPeriod = CN_Calc_Period; + m_nSendAllDataPeriod = CN_Send_Data_Period; } iot_service::CalcServerThread::~CalcServerThread() { @@ -63,6 +70,16 @@ iot_service::CalcServerThread::~CalcServerThread() //初始化 int iot_service::CalcServerThread::initialize() { + //加载配置文件 + if(!loadConfig()) + { + LOGERROR("加载配置文件proc_param_cfg.xml失败"); + return iotFailed; + } + + //初始化发送消息的结构体 + initDataMsgCache(); + //1.初始化内存表操作类 m_ptrCalcTableOpt=boost::make_shared (m_stRunAppInfo); if(m_ptrCalcTableOpt ==NULL) @@ -143,22 +160,9 @@ int iot_service::CalcServerThread::initialize() LOGERROR("CalcServerThread::initialize() 初始化lua失败!"); return iotFailed; } - luabridge::getGlobalNamespace(lua_state) - .beginNamespace ("kbd") - .addFunction ("getDataByIndex",&CalcServerThread::getDataByIndex) - .endNamespace (); - luabridge::getGlobalNamespace(lua_state) - .beginNamespace ("kbd") - .addFunction ("getInParamNum",&CalcServerThread::getInParamNum) - .endNamespace (); - luabridge::getGlobalNamespace(lua_state) - .beginNamespace ("kbd") - .addFunction ("getBitAnd",&CalcServerThread::getBitAnd) - .endNamespace (); - luabridge::getGlobalNamespace(lua_state) - .beginNamespace ("kbd") - .addFunction ("getBitOr",&CalcServerThread::getBitOr) - .endNamespace (); + + registFunctionToLua(); + return iotSuccess; } //设置为主 @@ -217,11 +221,13 @@ void iot_service::CalcServerThread::execute() } //3.计算结果并发送(变化+定时)给data_process - if(nCurTimeMSec - m_lastCalcTime > 1000) //一秒钟计算一次,没必要太频繁,提高效率 + if(nCurTimeMSec - m_lastCalcTime > m_nCalcPeriod) //一秒钟计算一次,没必要太频繁,提高效率 { - m_lastCalcTime = nCurTimeMSec ; calcAndSend(); //变化发送 timersendtoDp();//定时发送(默认5000ms发一次) + + hanleDataMsgCache(); //发送缓冲区数据 + m_lastCalcTime = nCurTimeMSec ; } return ; } @@ -908,15 +914,8 @@ void iot_service::CalcServerThread::sendToDp(const std::string strName,const std varValue.set_edatatype( CN_DATATYPE_DOUBLE ); varValue.set_dvalue(atof(outValue.c_str())); } - if(AddOptSetData(strTableName,strTagName,nAddStatus,nDelStatus,varValue) == iotSuccess) - { - sendCalcData(nPointType,false); - } - else - { - m_stOptDataMsg.clear_seq_set_data_info(); - m_stOptDataMsg.Clear(); - } + + AddOptSetData(nPointType,strTableName,strTagName,nAddStatus,nDelStatus,varValue); return; } @@ -945,10 +944,17 @@ int CalcServerThread::needSend(const string strName, const string outValue, cons } return iotSuccess; } -int iot_service::CalcServerThread::AddOptSetData(const string strTableName, const string strTagName, + +int iot_service::CalcServerThread::AddOptSetData(const int nPntType,const string strTableName, const string strTagName, const int nAddStatus, const int nDelStatus, const SVariable varValue) { - SOptSetDataMsg *OptSetData = m_stOptDataMsg.add_seq_set_data_info() ; + if(nPntType >= m_vecMsg.size()) + { + LOGERROR("添加计算结果到发送缓冲区失败.原因:无法识别的数据类型%d",nPntType); + return iotFailed; + } + + SOptSetDataMsg *OptSetData = m_vecMsg[nPntType].add_seq_set_data_info() ; if(OptSetData) { OptSetData->set_str_tag_name(strTagName); @@ -958,7 +964,7 @@ int iot_service::CalcServerThread::AddOptSetData(const string strTableName, cons } else { - m_stOptDataMsg.clear_seq_set_data_info(); + m_vecMsg[nPntType].clear_seq_set_data_info(); LOGERROR("AddOptSetData, key_id_tag = %s.%s, nAddStatus=%d,nDelStatus=%d Fail ",\ strTableName.c_str(), strTagName.c_str(), nAddStatus, nDelStatus); return iotFailed; @@ -966,38 +972,6 @@ int iot_service::CalcServerThread::AddOptSetData(const string strTableName, cons return iotSuccess; } -void iot_service::CalcServerThread::sendCalcData(const int nPointType, const bool bNotAlarm) -{ - int nNum = m_stOptDataMsg.seq_set_data_info_size() ; - //需要发送的数据为空 - if ( nNum <1 ) - { - //LOGDEBUG("CSrvDataPublish::SendOptData(): nNum =0, send return !") ; - return; - } - - SOptDataPkgHead stHead; - - stHead.set_str_src_tag("calc_server"); - stHead.set_b_not_alarm(bNotAlarm); //是否初始化 - stHead.set_n_point_type(nPointType); //点类型 - stHead.set_n_opt_time(getUTCTimeMsec()); - m_stOptDataMsg.mutable_package_head()->CopyFrom(stHead); - - string strSendBuff; - m_stOptDataMsg.SerializeToString(&strSendBuff) ; - - int nRetCode = m_ptrMsgbusMng->sendToHost(MT_OPT_SET_CAL_DATA_DOWN,CH_OPT_TO_SCADA_VALUE_SET,strSendBuff); - if (nRetCode == false) - { - LOGERROR("CalcServerThread::SendOptData(), nRetCode = %d, buf_size = %d, sendToHost Error", - nRetCode, (int)strSendBuff.size()); - } - m_stOptDataMsg.clear_package_head(); - m_stOptDataMsg.clear_seq_set_data_info(); - m_stOptDataMsg.Clear(); - return; -} void CalcServerThread::timersendtoDp() { @@ -1009,7 +983,7 @@ void CalcServerThread::timersendtoDp() if(it != m_outPointInfoMap.end()) { SOutPointInfo &sConstTimeOutDataInfo = it->second; - if(iot_public::getUTCTimeMsec() > (sConstTimeOutDataInfo.nTime + 5000)) + if(iot_public::getUTCTimeMsec() > static_cast(sConstTimeOutDataInfo.nTime + m_nSendAllDataPeriod)) { sConstTimeOutDataInfo.nTime = iot_public::getUTCTimeMsec(); sendToDp(it->first,sConstTimeOutDataInfo.value,sConstTimeOutDataInfo.nvalid); @@ -1150,3 +1124,92 @@ int CalcServerThread::dealLuaRef(luabridge::LuaRef ret, string &strValue, int &n } return iotSuccess; } + +bool CalcServerThread::loadConfig() +{ + iot_public::CCommonConfigParse configParse; + if (iotSuccess != configParse.load(iot_public::CFileUtil::getPathOfCfgFile("proc_param_cfg.xml"))) + { + LOGERROR("加载配置文件proc_param_cfg.xml失败"); + return false; + } + + m_nCalcPeriod = configParse.getIntWithDefault(CN_ProcName_CalcServer,"calc_period",CN_Calc_Period); + m_nSendAllDataPeriod = configParse.getIntWithDefault(CN_ProcName_CalcServer,"calc_period",CN_Calc_Period); + + return true; +} + +void CalcServerThread::initDataMsgCache() +{ + SOptSetDataPkg stMsg; + SOptDataPkgHead *pHead = stMsg.mutable_package_head(); + pHead->set_str_src_tag(CN_ProcName_CalcServer); + pHead->set_b_not_alarm(false); //产生告警,若为true,则测点不会生成告警 + pHead->set_n_opt_time(0); + + std::vector vecPntType = {POINT_TYPE_ANA,POINT_TYPE_DIG,POINT_TYPE_MIX,POINT_TYPE_ACC}; + int nMaxSize = *std::max_element(vecPntType.begin(),vecPntType.end()) + 1; + + m_vecMsg.resize(nMaxSize,stMsg); + + for(int i = 0; i < static_cast(m_vecMsg.size()); i++) + { + m_vecMsg[i].mutable_package_head()->set_n_point_type(i); + } +} + +void CalcServerThread::hanleDataMsgCache() +{ + for(size_t i = 0; i < m_vecMsg.size();i++) + { + sendMsgToDP(m_vecMsg[i]); + } +} + +void CalcServerThread::sendMsgToDP(iot_idl::SOptSetDataPkg &stMsg) +{ + if(stMsg.seq_set_data_info().empty()) + { + return; + } + + stMsg.mutable_package_head()->set_n_opt_time(getUTCTimeMsec()); + + string strSendBuff; + if(!stMsg.SerializeToString(&strSendBuff)) + { + stMsg.clear_seq_set_data_info(); + LOGERROR("序列化计算结果失败"); + return; + } + + bool nRetCode = m_ptrMsgbusMng->sendToHost(MT_OPT_SET_CAL_DATA_DOWN,CH_OPT_TO_SCADA_VALUE_SET,strSendBuff); + if (!nRetCode) + { + LOGERROR("CalcServerThread::SendOptData(), nRetCode = %d, buf_size = %d, sendToHost Error", + nRetCode, (int)strSendBuff.size()); + } + + stMsg.clear_seq_set_data_info(); +} + +void CalcServerThread::registFunctionToLua() +{ + luabridge::getGlobalNamespace(lua_state) + .beginNamespace ("kbd") + .addFunction ("getDataByIndex",&CalcServerThread::getDataByIndex) + .addFunction ("getInParamNum",&CalcServerThread::getInParamNum) + .addFunction ("getBitAnd",&CalcServerThread::getBitAnd) + .addFunction ("getBitOr",&CalcServerThread::getBitOr) + .endNamespace (); + + //< 更换为新命名空间,老的命名空间不再新增函数 + luabridge::getGlobalNamespace(lua_state) + .beginNamespace ("iot") + .addFunction ("getDataByIndex",&CalcServerThread::getDataByIndex) + .addFunction ("getInParamNum",&CalcServerThread::getInParamNum) + .addFunction ("getBitAnd",&CalcServerThread::getBitAnd) + .addFunction ("getBitOr",&CalcServerThread::getBitOr) + .endNamespace (); +} diff --git a/product/src/service/calc_server/CalcServerThread.h b/product/src/service/calc_server/CalcServerThread.h index 62d91a71..439a2e9d 100644 --- a/product/src/service/calc_server/CalcServerThread.h +++ b/product/src/service/calc_server/CalcServerThread.h @@ -34,6 +34,27 @@ namespace iot_service { public: CalcServerThread(const iot_public::SRunAppInfo &stRunAppInfo); virtual ~CalcServerThread(); + /** + * @brief execute 业务处理函数,必须继承实现自己的业务逻辑 + */ + virtual void execute(); + /** + * @brief initialize 初始化 + * @return 成功返回iotSuccess,失败返回失败码 + */ + int initialize(); + /** + * @brief setMaster 设置为主 + * @return 成功返回iotSuccess,失败返回失败码 + */ + int setMaster(); + /** + * @brief setSlave 设置为备 + * @return 成功返回iotSuccess,失败返回失败码 + */ + int setSlave(); + + private: /** * @brief getDataByIndex 脚本使用的接口 * @param index 根据参数序号获取值和状态 @@ -63,26 +84,6 @@ namespace iot_service { * @return */ static luabridge::LuaRef getBitOr(double first,double second,lua_State *LuaState); - /** - * @brief initialize 初始化 - * @return 成功返回iotSuccess,失败返回失败码 - */ - int initialize(); - - /** - * @brief setMaster 设置为主 - * @return 成功返回iotSuccess,失败返回失败码 - */ - int setMaster(); - /** - * @brief setSlave 设置为备 - * @return 成功返回iotSuccess,失败返回失败码 - */ - int setSlave(); - /** - * @brief execute 业务处理函数,必须继承实现自己的业务逻辑 - */ - virtual void execute(); /** * @brief TryReadConfig 读取配制表标识符,判断配置是否发生变化 * @return 无变化返回false,否则返回true @@ -250,15 +251,8 @@ namespace iot_service { * @param strValue 发送的数据 * @param bSendImme 是否发送 */ - int AddOptSetData(const std::string strTableName,const std::string strTagName,const int nAddStatus, - const int nDelStatus,const iot_idl::SVariable varValue); - /** - * @brief sendCalcData 发送计算量输出到dp - * @param nPointType 类型 - * @param bInit 是否初始化 - * @param nDstDomain 默认为本域 - */ - void sendCalcData(const int nPointType, const bool bNotAlarm = false); //-1为本域 + int AddOptSetData(const int nPntType,const std::string strTableName,const std::string strTagName, + const int nAddStatus,const int nDelStatus,const iot_idl::SVariable varValue); /** * @brief timersendtoDp 定时发送给dp 默认5秒 */ @@ -278,15 +272,45 @@ namespace iot_service { * @return */ int dealLuaRef(luabridge::LuaRef ret, std::string &strValue, int &nStatus, bool &isChange); + /** + * @brief 加载配置文件 + * @return + */ + bool loadConfig(); + /** + * @brief 初始化发送消息的结构体 + * @return + */ + void initDataMsgCache(); + /** + * @brief 发送缓冲区所有消息 + * @return + */ + void hanleDataMsgCache(); + + /** + * @brief 发送一条消息到数据处理服务 + * @param stMsg 要发送的消息 + * @return + */ + void sendMsgToDP(iot_idl::SOptSetDataPkg &stMsg); + + /** + * @brief 将C++函数注册到lua环境中 + * @return + */ + void registFunctionToLua(); + private: int64 m_lastCheckCfgTime; //上次检查配置时间 int64 m_lastCalcTime; //上次计算公式时间 + int m_nCalcPeriod; //计算周期,单位ms + int m_nSendAllDataPeriod; //定时发送所有计算数据的周期,单位ms iot_public::SRunAppInfo m_stRunAppInfo; //本应用运行参数 CalcRtdbTableOperatePtr m_ptrCalcTableOpt; //计算量相关内存表操作类 CalcMsgBusMngPtr m_ptrMsgbusMng; //消息总线管理类 iot_service::CDpcdaForAppPtr m_ptrCdpcda; //订阅点 - - iot_idl::SOptSetDataPkg m_stOptDataMsg; //操作数据 + std::vector m_vecMsg; //操作数据缓存,下标与数据类型对应 CDataProcessApiPtr m_ptrDataProcApi; iot_dbms::CRdbTableMngPtr m_ptrRdbTableMng; diff --git a/product/src/service/stat_server/stat_server/CComputeUnit.cpp b/product/src/service/stat_server/stat_server/CComputeUnit.cpp index 3dd59578..2bd68cd7 100644 --- a/product/src/service/stat_server/stat_server/CComputeUnit.cpp +++ b/product/src/service/stat_server/stat_server/CComputeUnit.cpp @@ -21,10 +21,12 @@ iot_service::CComputeUnit::CComputeUnit(QObject *parent, CComputeTaskPtr taskPtr m_iteration(0), m_iteration_cnt(0), m_luaState(luaL_newstate()), - m_objFunc(m_luaState), + //m_objFunc(m_luaState), m_taskPtr(taskPtr), m_parentWorker(parentWorker) // 计算完成发送信号, { + m_pLuaFunc = new luabridge::LuaRef(m_luaState); + //< 设置定时期类型 m_timer.setTimerType(Qt::PreciseTimer); @@ -60,6 +62,9 @@ iot_service::CComputeUnit::~CComputeUnit() } } + delete m_pLuaFunc; + m_pLuaFunc = NULL; + if (m_luaState != NULL) { lua_close(m_luaState); @@ -407,7 +412,7 @@ int iot_service::CComputeUnit::initLuaEnv() } //< 赋值函数 - m_objFunc = luabridge::getGlobal(m_luaState, m_taskPtr->statTemplate()->_template_tag.c_str()); + *m_pLuaFunc = luabridge::getGlobal(m_luaState, m_taskPtr->statTemplate()->_template_tag.c_str()); return iotSuccess; } @@ -536,31 +541,31 @@ int iot_service::CComputeUnit::callFunction(std::vector &vecA // LOGTRACE("当前计算统计实例%s,调用函数个数%d",m_taskPtr->tagName().c_str(),vecArgs.size()); switch (vecArgs.size()) { case 0: - ret = m_objFunc(); + ret = (*m_pLuaFunc)(); break; case 1: - ret = m_objFunc(vecArgs[0]); + ret = (*m_pLuaFunc)(vecArgs[0]); break; case 2: - ret = m_objFunc(vecArgs[0],vecArgs[1]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1]); break; case 3: - ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2]); break; case 4: - ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3]); break; case 5: - ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4]); break; case 6: - ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5]); break; case 7: - ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6]); break; case 8: - ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6],vecArgs[7]); + ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6],vecArgs[7]); break; default: break; diff --git a/product/src/service/stat_server/stat_server/CComputeUnit.h b/product/src/service/stat_server/stat_server/CComputeUnit.h index b3e21cb0..78e51e35 100644 --- a/product/src/service/stat_server/stat_server/CComputeUnit.h +++ b/product/src/service/stat_server/stat_server/CComputeUnit.h @@ -55,7 +55,8 @@ private: int m_state; //< 计算单元的状态 good 1 bad 0 lua_State* m_luaState; - luabridge::LuaRef m_objFunc; + //luabridge::LuaRef m_objFunc; + luabridge::LuaRef *m_pLuaFunc; CComputeTaskPtr m_taskPtr; CComputeWorker* m_parentWorker; qint64 m_nextComputeTimestamp; diff --git a/product/src/service/stat_server/stat_server/CMainThreadMng.cpp b/product/src/service/stat_server/stat_server/CMainThreadMng.cpp index c09a009b..bce70ecd 100644 --- a/product/src/service/stat_server/stat_server/CMainThreadMng.cpp +++ b/product/src/service/stat_server/stat_server/CMainThreadMng.cpp @@ -36,6 +36,8 @@ iot_service::CMainThreadMng::~CMainThreadMng() //< 清空数据结构 m_mapTagTemplate.reset(); m_mapTagTask.reset(); + //delete computeworker; + //computeworker = NULL; } int iot_service::CMainThreadMng::initialize() @@ -70,14 +72,14 @@ int iot_service::CMainThreadMng::initialize() connect(this,&CMainThreadMng::subDpCHgWorkerInit,subDpChgWorker,&CSubDpChgWorker::initialize,Qt::BlockingQueuedConnection); connect(this,&CMainThreadMng::start,computeworker,&CComputeWorker::startAll,Qt::QueuedConnection);//< 开始计算 - connect(this,&CMainThreadMng::stop,computeworker,&CComputeWorker::stopAll,Qt::QueuedConnection); //< 停止计算 + connect(this,&CMainThreadMng::stop,computeworker,&CComputeWorker::stopAll,Qt::DirectConnection); //< 停止计算 connect(this,&CMainThreadMng::restart,computeworker,&CComputeWorker::restartAll,Qt::QueuedConnection); //< 停止并重新开始计算 connect(computeworker,&CComputeWorker::computed,publishWorker,&CPublishWorker::publishResult,Qt::QueuedConnection); //<计算完发布 connect(subDpChgWorker,&CSubDpChgWorker::needCompute,computeworker,&CComputeWorker::compute,Qt::QueuedConnection); connect(this,&CMainThreadMng::start,subDpChgWorker,&CSubDpChgWorker::sub,Qt::QueuedConnection);//< 开始订阅变化点 - connect(this,&CMainThreadMng::stop,subDpChgWorker,&CSubDpChgWorker::unsub,Qt::QueuedConnection); //< 停止订阅变化点 + connect(this,&CMainThreadMng::stop,subDpChgWorker,&CSubDpChgWorker::unsub,Qt::DirectConnection); //< 停止订阅变化点 //< 清空缓存 removeCache(); @@ -109,6 +111,7 @@ void iot_service::CMainThreadMng::stopCompute() { LOGDEBUG("stopCompute()"); g_is_need_stopcompute = true; + // disconnect(computeworker,&CComputeWorker::computed,publishWorker,&CPublishWorker::publishResult); //<计算完发布 emit this->stop(); } diff --git a/product/src/service/stat_server/stat_server/CPublishWorker.cpp b/product/src/service/stat_server/stat_server/CPublishWorker.cpp index ba41cd4d..edd6937c 100644 --- a/product/src/service/stat_server/stat_server/CPublishWorker.cpp +++ b/product/src/service/stat_server/stat_server/CPublishWorker.cpp @@ -11,6 +11,7 @@ #include "pub_utility_api/TimeUtil.h" #include "boost/lexical_cast.hpp" #include "common/MessageChannel.h" +#include "../stat_server_function/global_var.h" iot_service::CPublishWorker::CPublishWorker(QObject *parent, const iot_public::SRunAppInfo &stRunAppInfo): QObject(parent),m_stRunAppInfo(stRunAppInfo) @@ -89,6 +90,10 @@ int iot_service::CPublishWorker::initialize() void iot_service::CPublishWorker::publishResult(QString instTag, double value, int status, bool isBind, QString pointTag) { + if(g_is_need_stopcompute) + { + return; + } // checkMainThread(); LOGTRACE("发布结果,返回值标签%s,值%f,状态%d(1有效,0无效),是否绑定测点%d(1绑定,0不绑定),绑定测点标签%s",instTag.toStdString().c_str(),value,status,(int)isBind,pointTag.toStdString().c_str()); diff --git a/product/src/service/stat_server/stat_server/CStatSrvApp.cpp b/product/src/service/stat_server/stat_server/CStatSrvApp.cpp index 5435ca88..33b7f4e2 100644 --- a/product/src/service/stat_server/stat_server/CStatSrvApp.cpp +++ b/product/src/service/stat_server/stat_server/CStatSrvApp.cpp @@ -37,12 +37,12 @@ bool iot_service::CStatSrvApp::start(int argc, char *argv[], int &nStatus) } //< 3.避免进程重复启动 - if(isAlreadyRunning()) - { - LOGERROR("进程已存在,不允许再次启动"); - nStatus = iotFailed; - return false; - } + // if(isAlreadyRunning()) + // { + // LOGERROR("进程已存在,不允许再次启动"); + // nStatus = iotFailed; + // return false; + // } //< 4.初始化消息总线和tsdb_api() if(!initMsgBusAndTsdb()) diff --git a/product/src/service/stat_server/stat_server_function/CLuaBuiltInFunc.cpp b/product/src/service/stat_server/stat_server_function/CLuaBuiltInFunc.cpp index a31804d4..628e0819 100644 --- a/product/src/service/stat_server/stat_server_function/CLuaBuiltInFunc.cpp +++ b/product/src/service/stat_server/stat_server_function/CLuaBuiltInFunc.cpp @@ -24,197 +24,76 @@ bool g_is_need_stopcompute = false; void iot_service::CLuaBuiltInFunc::loadKbdFunctions(lua_State *luaState) { - - //< 线程暂停测试 luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("threadStop", CLuaBuiltInFunc::threadStop) + .beginNamespace ("kbd") + .addFunction ("threadStop", CLuaBuiltInFunc::threadStop) //< 线程暂停测试 + .addFunction ("PcsIncomeAndPerPeriod", CLuaBuiltInFunc::PcsIncomeAndPerPeriod) //< 加载PCS收益与各时段统计 + .addFunction ("PvIncomeAndPerPeriod", CLuaBuiltInFunc::PvIncomeAndPerPeriod) //< 加载PV收益与各时段统计 + .addFunction ("getCurveChg", CLuaBuiltInFunc::getCurveChg) //< 加载尖峰平谷计算 + .addFunction ("getHourRatio", CLuaBuiltInFunc::getHourRatio) //< 加载时统计差量比 + .addFunction ("getDayRatio", CLuaBuiltInFunc::getDayRatio) //< 加载日统计差量比 + .addFunction ("getMonthRatio", CLuaBuiltInFunc::getMonthRatio) //< 加载月统计差量比 + .addFunction ("getYearRatio", CLuaBuiltInFunc::getYearRatio) //< 加载年统计差量比 + .addFunction ("getLatestHourDiff", CLuaBuiltInFunc::getLatestHourDiff) //< 加载最新时统计差量 + .addFunction ("getLatestDayDiff", CLuaBuiltInFunc::getLatestDayDiff) //< 加载最新日统计差量 + .addFunction ("getLatestMonthDiff", CLuaBuiltInFunc::getLatestMonthDiff) //< 加载最新月统计差量 + .addFunction ("getLatestYearDiff", CLuaBuiltInFunc::getLatestYearDiff) //< 加载最新年统计差量 + .addFunction ("getDayDiff", CLuaBuiltInFunc::getDayDiff) //< 加载日统计累计值(差值计算) + .addFunction ("getMonthDiff", CLuaBuiltInFunc::getMonthDiff) //< 加载月统计累计值(差值计算) + .addFunction ("getYearDiff", CLuaBuiltInFunc::getYearDiff) //< 加载年统计累计值(差值计算) + .addFunction ("monthPerYear", CLuaBuiltInFunc::MonthPerYear) //< 加载累计量统计输出(差值计算) + .addFunction ("hourPerDay", CLuaBuiltInFunc::hourPerDay) + .addFunction ("dayPerMonth", CLuaBuiltInFunc::DayPerMonth) + .addFunction ("genPrice", CLuaBuiltInFunc::genPrice) + .addFunction ("log", CLuaBuiltInFunc::log) + .addFunction ("getLastVal", CLuaBuiltInFunc::getLastVal) + .addFunction ("chargeCount", CLuaBuiltInFunc::chargeCount) //< 充放电次数和充放电时长计算 + .addFunction ("getAccFromDaily", CLuaBuiltInFunc::getAccFromDaily) //< 充放电次数和充放电时长计算 + .addFunction ("getHourChangeCnt", CLuaBuiltInFunc::getHourChangeCnt) //< 加载时统计变化次数 + .addFunction ("getDayChangeCnt", CLuaBuiltInFunc::getDayChangeCnt) //< 加载日统计变化次数 + .addFunction ("getMonthChangeCnt", CLuaBuiltInFunc::getMonthChangeCnt) //< 加载月统计变化次数 + .addFunction ("getYearChangeCnt", CLuaBuiltInFunc::getYearChangeCnt) //< 加载年统计变化次数 + .addFunction ("getHourRunningTime", CLuaBuiltInFunc::getHourRunningTime) //< 加载时统计变化次数 + .addFunction ("getDayRunningTime", CLuaBuiltInFunc::getDayRunningTime) //< 加载日统计变化次数 + .addFunction ("getMonthRunningTime", CLuaBuiltInFunc::getMonthRunningTime) //< 加载月统计变化次数 + .addFunction ("getYearRunningTime", CLuaBuiltInFunc::getYearRunningTime) //< 加载年统计变化次数 .endNamespace (); - //< 加载PCS收益与各时段统计 + //< 更换为新命名空间,老的命名空间不再新增函数 luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("PcsIncomeAndPerPeriod", CLuaBuiltInFunc::PcsIncomeAndPerPeriod) + .beginNamespace ("iot") + .addFunction ("threadStop", CLuaBuiltInFunc::threadStop) //< 线程暂停测试 + .addFunction ("PcsIncomeAndPerPeriod", CLuaBuiltInFunc::PcsIncomeAndPerPeriod) //< 加载PCS收益与各时段统计 + .addFunction ("PvIncomeAndPerPeriod", CLuaBuiltInFunc::PvIncomeAndPerPeriod) //< 加载PV收益与各时段统计 + .addFunction ("getCurveChg", CLuaBuiltInFunc::getCurveChg) //< 加载尖峰平谷计算 + .addFunction ("getHourRatio", CLuaBuiltInFunc::getHourRatio) //< 加载时统计差量比 + .addFunction ("getDayRatio", CLuaBuiltInFunc::getDayRatio) //< 加载日统计差量比 + .addFunction ("getMonthRatio", CLuaBuiltInFunc::getMonthRatio) //< 加载月统计差量比 + .addFunction ("getYearRatio", CLuaBuiltInFunc::getYearRatio) //< 加载年统计差量比 + .addFunction ("getLatestHourDiff", CLuaBuiltInFunc::getLatestHourDiff) //< 加载最新时统计差量 + .addFunction ("getLatestDayDiff", CLuaBuiltInFunc::getLatestDayDiff) //< 加载最新日统计差量 + .addFunction ("getLatestMonthDiff", CLuaBuiltInFunc::getLatestMonthDiff) //< 加载最新月统计差量 + .addFunction ("getLatestYearDiff", CLuaBuiltInFunc::getLatestYearDiff) //< 加载最新年统计差量 + .addFunction ("getDayDiff", CLuaBuiltInFunc::getDayDiff) //< 加载日统计累计值(差值计算) + .addFunction ("getMonthDiff", CLuaBuiltInFunc::getMonthDiff) //< 加载月统计累计值(差值计算) + .addFunction ("getYearDiff", CLuaBuiltInFunc::getYearDiff) //< 加载年统计累计值(差值计算) + .addFunction ("monthPerYear", CLuaBuiltInFunc::MonthPerYear) //< 加载累计量统计输出(差值计算) + .addFunction ("hourPerDay", CLuaBuiltInFunc::hourPerDay) + .addFunction ("dayPerMonth", CLuaBuiltInFunc::DayPerMonth) + .addFunction ("genPrice", CLuaBuiltInFunc::genPrice) + .addFunction ("log", CLuaBuiltInFunc::log) + .addFunction ("getLastVal", CLuaBuiltInFunc::getLastVal) + .addFunction ("chargeCount", CLuaBuiltInFunc::chargeCount) //< 充放电次数和充放电时长计算 + .addFunction ("getAccFromDaily", CLuaBuiltInFunc::getAccFromDaily) //< 充放电次数和充放电时长计算 + .addFunction ("getHourChangeCnt", CLuaBuiltInFunc::getHourChangeCnt) //< 加载时统计变化次数 + .addFunction ("getDayChangeCnt", CLuaBuiltInFunc::getDayChangeCnt) //< 加载日统计变化次数 + .addFunction ("getMonthChangeCnt", CLuaBuiltInFunc::getMonthChangeCnt) //< 加载月统计变化次数 + .addFunction ("getYearChangeCnt", CLuaBuiltInFunc::getYearChangeCnt) //< 加载年统计变化次数 + .addFunction ("getHourRunningTime", CLuaBuiltInFunc::getHourRunningTime) //< 加载时统计变化次数 + .addFunction ("getDayRunningTime", CLuaBuiltInFunc::getDayRunningTime) //< 加载日统计变化次数 + .addFunction ("getMonthRunningTime", CLuaBuiltInFunc::getMonthRunningTime) //< 加载月统计变化次数 + .addFunction ("getYearRunningTime", CLuaBuiltInFunc::getYearRunningTime) //< 加载年统计变化次数 .endNamespace (); - - //< 加载PV收益与各时段统计 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("PvIncomeAndPerPeriod", CLuaBuiltInFunc::PvIncomeAndPerPeriod) - .endNamespace (); - - - //< 加载尖峰平谷计算 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getCurveChg", CLuaBuiltInFunc::getCurveChg) - .endNamespace (); - - //< 加载时统计差量比 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getHourRatio", CLuaBuiltInFunc::getHourRatio) - .endNamespace (); - - - //< 加载日统计差量比 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getDayRatio", CLuaBuiltInFunc::getDayRatio) - .endNamespace (); - - //< 加载月统计差量比 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getMonthRatio", CLuaBuiltInFunc::getMonthRatio) - .endNamespace (); - - //< 加载年统计差量比 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getYearRatio", CLuaBuiltInFunc::getYearRatio) - .endNamespace (); - - - //< 加载最新时统计差量 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getLatestHourDiff", CLuaBuiltInFunc::getLatestHourDiff) - .endNamespace (); - - - //< 加载最新日统计差量 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getLatestDayDiff", CLuaBuiltInFunc::getLatestDayDiff) - .endNamespace (); - - //< 加载最新月统计差量 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getLatestMonthDiff", CLuaBuiltInFunc::getLatestMonthDiff) - .endNamespace (); - - //< 加载最新年统计差量 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getLatestYearDiff", CLuaBuiltInFunc::getLatestYearDiff) - .endNamespace (); - - - //< 加载日统计累计值(差值计算) - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getDayDiff", CLuaBuiltInFunc::getDayDiff) - .endNamespace (); - - //< 加载月统计累计值(差值计算) - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getMonthDiff", CLuaBuiltInFunc::getMonthDiff) - .endNamespace (); - - //< 加载年统计累计值(差值计算) - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getYearDiff", CLuaBuiltInFunc::getYearDiff) - .endNamespace (); - - - //< 加载累计量统计输出(差值计算) - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("monthPerYear", CLuaBuiltInFunc::MonthPerYear) - .endNamespace (); - - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("hourPerDay", CLuaBuiltInFunc::hourPerDay) - .endNamespace (); - - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("dayPerMonth", CLuaBuiltInFunc::DayPerMonth) - .endNamespace (); - - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("genPrice", CLuaBuiltInFunc::genPrice) - .endNamespace (); - - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("log", CLuaBuiltInFunc::log) - .endNamespace (); - - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getLastVal", CLuaBuiltInFunc::getLastVal) - .endNamespace (); - - //< 充放电次数和充放电时长计算 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("chargeCount", CLuaBuiltInFunc::chargeCount) - .endNamespace (); - - //< 充放电次数和充放电时长计算 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getAccFromDaily", CLuaBuiltInFunc::getAccFromDaily) - .endNamespace (); - - - //< 加载时统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getHourChangeCnt", CLuaBuiltInFunc::getHourChangeCnt) - .endNamespace (); - - - //< 加载日统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getDayChangeCnt", CLuaBuiltInFunc::getDayChangeCnt) - .endNamespace (); - - //< 加载月统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getMonthChangeCnt", CLuaBuiltInFunc::getMonthChangeCnt) - .endNamespace (); - - //< 加载年统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getYearChangeCnt", CLuaBuiltInFunc::getYearChangeCnt) - .endNamespace (); - - //< 加载时统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getHourRunningTime", CLuaBuiltInFunc::getHourRunningTime) - .endNamespace (); - - - //< 加载日统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getDayRunningTime", CLuaBuiltInFunc::getDayRunningTime) - .endNamespace (); - - //< 加载月统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getMonthRunningTime", CLuaBuiltInFunc::getMonthRunningTime) - .endNamespace (); - - //< 加载年统计变化次数 - luabridge::getGlobalNamespace(luaState) - .beginNamespace ("kbd") - .addFunction ("getYearRunningTime", CLuaBuiltInFunc::getYearRunningTime) - .endNamespace (); - } void iot_service::CLuaBuiltInFunc::threadStop(){ @@ -1085,7 +964,7 @@ double iot_service::CLuaBuiltInFunc::getPeriodDiff(const std::string keyIdTag, i { LOGERROR("influxdb连接异常"); //< 赋值给返回结果 - return 0; + return -INFINITY; } else{ } @@ -1105,18 +984,27 @@ double iot_service::CLuaBuiltInFunc::getPeriodDiff(const std::string keyIdTag, i //< 查询最后一个值 if(!findLastVal(*conn.get(),key,-1,endTime,&vecStatusNotHave,endVal)) { - LOGERROR("查询右边界值错误"); - return 0; + LOGERROR("tag[%s]查询右边界值错误key[%s],start[%lld],end[%lld]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime); + return -INFINITY; } //< 查询左边界值 - if(!findLastVal(*conn.get(),key,-1,startTime,&vecStatusNotHave,startVal)) + if(!findLastVal(*conn.get(),key,startTime-43200000,startTime,&vecStatusNotHave,startVal)) { - LOGERROR("查询左边界值错误"); + LOGERROR("tag[%s]查询左边界值错误key[%s],start[%lld],end[%lld]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime); return endVal; } - return endVal - startVal; + if (endVal - startVal >= 0) + { + LOGTRACE("tag[%s]计算值key[%s],start[%lld],end[%lld],startVal[%f],endVal[%f]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime, startVal, endVal); + return endVal - startVal; + } + else + { + LOGERROR("tag[%s]query-error-key[%s],start[%lld],end[%lld],startVal[%f],endVal[%f]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime, startVal, endVal); + return -INFINITY; + } } double iot_service::CLuaBuiltInFunc::getDayDiff(std::string keyIdTag) diff --git a/product/src/service/stat_server/stat_server_function/StatUtil.cpp b/product/src/service/stat_server/stat_server_function/StatUtil.cpp index c0bd3234..4aaa96a2 100644 --- a/product/src/service/stat_server/stat_server_function/StatUtil.cpp +++ b/product/src/service/stat_server/stat_server_function/StatUtil.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -222,7 +221,7 @@ bool iot_service::StatUtil::findYieldPoints(iot_dbms::CTsdbConn &objConn, const for(std::size_t i = 0 ; i < vecResult[0]->size();i++) { - double value = boost::lexical_cast(vecResult[0]->at(i).m_varValue); + double value = boost::get(vecResult[0]->at(i).m_varValue); if((int)(value) !=0) { outYieldPoints.push_back(vecResult[0]->at(i)); @@ -253,7 +252,7 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin } // ms级别是十三位 - firstCurveTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); + firstCurveTime = vecResult[0]->at(0).m_nTime; delete vecResult[0]; } else{ @@ -271,7 +270,7 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin return false; } - firstChargeVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); // ms级别是十三位 + firstChargeVal = boost::get(vecResult[0]->at(0).m_varValue); // ms级别是十三位 delete vecResult[0]; } @@ -294,9 +293,9 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin return false; } - firstChargeVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + firstChargeVal = boost::get(vecResult[0]->at(0).m_varValue); - firstChargeTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); + firstChargeTime = vecResult[0]->at(0).m_nTime; delete vecResult[0]; } @@ -315,8 +314,8 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin return false; } - firstCurveVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); - firstCurveTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime);// ms级别是十三位 + firstCurveVal = boost::get(vecResult[0]->at(0).m_varValue); + firstCurveTime = (vecResult[0]->at(0).m_nTime);// ms级别是十三位 delete vecResult[0]; } } @@ -340,8 +339,8 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin } - firstCurveVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); - firstCurveTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); + firstCurveVal = boost::get(vecResult[0]->at(0).m_varValue); + firstCurveTime = (vecResult[0]->at(0).m_nTime); delete vecResult[0]; } return true; @@ -373,7 +372,7 @@ bool iot_service::StatUtil::handleChgYieldPoints(iot_dbms::CTsdbConn &objConn, c return false; } - endChargeVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + endChargeVal = boost::get(vecResult[0]->at(0).m_varValue); diffChargeVal = endChargeVal - startChargeVal; //< 计算该区间放电差值 resultTmp[startCurveVal] += diffChargeVal; @@ -383,14 +382,14 @@ bool iot_service::StatUtil::handleChgYieldPoints(iot_dbms::CTsdbConn &objConn, c //< 为下一个区间计算作准备 startChargeVal = endChargeVal; - startCurveVal += (int)(boost::lexical_cast(yieldPoints.at(i).m_varValue)); + startCurveVal += boost::get(yieldPoints.at(i).m_varValue); if(startCurveVal < 1 || startCurveVal > 4 ) { LOGERROR("峰平谷尖值不正确,%d",startCurveVal); return false; } - startCurveTime = boost::lexical_cast(yieldPoints.at(i).m_nTime); + startCurveTime = (yieldPoints.at(i).m_nTime); LOGTRACE("处理区间%d完成",(int)i); } @@ -412,8 +411,8 @@ bool iot_service::StatUtil::handleChgYieldPoints(iot_dbms::CTsdbConn &objConn, c return false; } - lastChargeTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - lastChargeVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + lastChargeTime = (vecResult[0]->at(0).m_nTime); + lastChargeVal = boost::get(vecResult[0]->at(0).m_varValue); resultTmp[startCurveVal] += lastChargeVal - startChargeVal; // ms级别是十三位 @@ -460,7 +459,7 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co return false; } - endChargeVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + endChargeVal = boost::get(vecResult[0]->at(0).m_varValue); //< 检查当前区间是否跨天,如果跨天,当前时段的发电度量清零 if(!isSameDay(startCurveTime,currentTimeEpoch)) @@ -510,21 +509,21 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co return false; } - resultTmp[9] += diffChargeVal * boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTmp[9] += diffChargeVal * boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; } //< 为下一个区间计算作准备 startChargeVal = endChargeVal; - startCurveVal += (int)(boost::lexical_cast(yieldPoints.at(i).m_varValue)); + startCurveVal += boost::get(yieldPoints.at(i).m_varValue); if(startCurveVal < 1 || startCurveVal > 4 ) { LOGERROR("峰平谷尖值不正确,%d",startCurveVal); return false; } - startCurveTime = boost::lexical_cast(yieldPoints.at(i).m_nTime); + startCurveTime = (yieldPoints.at(i).m_nTime); LOGTRACE("处理区间%d完成",(int)i); } @@ -546,8 +545,8 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co return false; } - lastChargeTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - lastChargeVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + lastChargeTime = (vecResult[0]->at(0).m_nTime); + lastChargeVal = boost::get(vecResult[0]->at(0).m_varValue); //< 检查当前区间是否跨天,如果跨天,当前时段的发电度量清零 if(!isSameDay(startCurveTime,currentTimeEpoch)) @@ -583,7 +582,7 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co if(vecResult[0]->size() == 1) { - resultTmp[9] += (lastChargeVal - startChargeVal) * boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTmp[9] += (lastChargeVal - startChargeVal) * boost::get(vecResult[0]->at(0).m_varValue); } delete vecResult[0]; } @@ -608,7 +607,7 @@ bool iot_service::StatUtil::findFirstTime(iot_dbms::CTsdbConn &objConn, const st return false; } - result = boost::lexical_cast(vecResult[0]->at(0).m_nTime); + result = (vecResult[0]->at(0).m_nTime); delete vecResult[0]; return true; } @@ -629,8 +628,8 @@ bool iot_service::StatUtil::findFirstTimeAndVal(iot_dbms::CTsdbConn &objConn, co return false; } - resultTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - resultVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTime = (vecResult[0]->at(0).m_nTime); + resultVal = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -661,8 +660,8 @@ bool iot_service::StatUtil::findFirstLargerValAndTime(iot_dbms::CTsdbConn &objCo return false; } - resultTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - resultVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTime = (vecResult[0]->at(0).m_nTime); + resultVal = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; @@ -693,8 +692,8 @@ bool iot_service::StatUtil::findFirstLessOrEqualValAndTime(iot_dbms::CTsdbConn & return false; } - resultTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - resultVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTime = (vecResult[0]->at(0).m_nTime); + resultVal = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -716,7 +715,7 @@ bool iot_service::StatUtil::findLastTime(iot_dbms::CTsdbConn &objConn, const std return false; } - result = boost::lexical_cast(vecResult[0]->at(0).m_nTime); + result = (vecResult[0]->at(0).m_nTime); delete vecResult[0]; return true; } @@ -737,8 +736,8 @@ bool iot_service::StatUtil::findLastTimeAndVal(iot_dbms::CTsdbConn &objConn, con return false; } - resultTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - resultVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTime = (vecResult[0]->at(0).m_nTime); + resultVal = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -761,8 +760,8 @@ bool iot_service::StatUtil::findLastTimeAndVal(iot_dbms::CTsdbConn &objConn, con return false; } - resultTime = boost::lexical_cast(vecResult[0]->at(0).m_nTime); - resultVal = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + resultTime = (vecResult[0]->at(0).m_nTime); + resultVal = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -811,7 +810,7 @@ bool iot_service::StatUtil::findFirstVal(iot_dbms::CTsdbConn &objConn, const std return false; } - result = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + result = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -832,7 +831,7 @@ bool iot_service::StatUtil::findLastVal(iot_dbms::CTsdbConn &objConn, const std: return false; } - result = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + result = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -853,7 +852,7 @@ bool iot_service::StatUtil::findLastVal(iot_dbms::CTsdbConn &objConn, const std: return false; } - result = (int)boost::lexical_cast(vecResult[0]->at(0).m_varValue); + result = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -880,7 +879,7 @@ bool iot_service::StatUtil::findLastVal(iot_dbms::CTsdbConn &objConn, const std: if(vecResult[0]->size() == 1) { - result = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + result = boost::get(vecResult[0]->at(0).m_varValue); } else { @@ -906,7 +905,7 @@ bool iot_service::StatUtil::findMedianVal(iot_dbms::CTsdbConn &objConn, const st return false; } - result = boost::lexical_cast(vecResult[0]->at(0).m_varValue); + result = boost::get(vecResult[0]->at(0).m_varValue); delete vecResult[0]; return true; } @@ -1262,7 +1261,7 @@ bool iot_service::StatUtil::handlePcsYieldPoints(iot_dbms::CTsdbConn &objConn, startChargeVal = endChargeVal; startDischargeVal = endDischargeVal; startCurveTime = boost::int64_t(yieldPoints.at(i).m_nTime); - startCurveVal += (int)boost::lexical_cast(yieldPoints.at(i).m_varValue); + startCurveVal += boost::get(yieldPoints.at(i).m_varValue); if(startCurveVal < 1 || startCurveVal > 4 ) {