102 lines
3.0 KiB
C++
102 lines
3.0 KiB
C++
#include "CHisEventManage.h"
|
||
#include "CDataInfoManage.h"
|
||
#include "public/pub_logger_api/logger.h"
|
||
#include <QTime>
|
||
|
||
CHisEventManage::CHisEventManage(QObject *parent)
|
||
: QObject(parent)
|
||
{
|
||
}
|
||
|
||
void CHisEventManage::release()
|
||
{
|
||
delete this;
|
||
}
|
||
|
||
void CHisEventManage::queryHisEventStatis(int location, int devType, qint64 startTime, qint64 endTime, EN_STATIS_MODE mode)
|
||
{
|
||
QTime time;
|
||
time.start();
|
||
kbd_dbms::CTsdbConnPtr tsdbConnPtr;
|
||
if(!getValidTsdbConnPtr(tsdbConnPtr))
|
||
{
|
||
LOGERROR("CTsdbQuery: 未获取到有效的TSDB连接!");
|
||
emit updateHisEventStatis(QMap<qint64, QMap<int, int> >());
|
||
return;
|
||
}
|
||
|
||
QMap<qint64, QMap<int, int> > record;
|
||
QStringList devList = CDataInfoManage::instance()->getDevice(location, devType);
|
||
for(int nIndex=0; nIndex<devList.length(); nIndex++)
|
||
{
|
||
CTsdbQuery tsdbQuery(devList[nIndex], tsdbConnPtr);
|
||
tsdbQuery.queryEventByPeriod(startTime, endTime, mode, record);
|
||
}
|
||
LOGINFO("CHisEventManage::queryHisEventStatis() time:%I64u", time.elapsed());
|
||
emit updateHisEventStatis(record);
|
||
}
|
||
|
||
void CHisEventManage::queryHisEventContrast(QList<int> selectedList, qint64 startTime, qint64 endTime, EN_STATIS_STYLE style)
|
||
{
|
||
QTime time;
|
||
time.start();
|
||
kbd_dbms::CTsdbConnPtr tsdbConnPtr;
|
||
if(!getValidTsdbConnPtr(tsdbConnPtr))
|
||
{
|
||
LOGERROR("CTsdbQuery: 未获取到有效的TSDB连接!");
|
||
emit updateHisEventContrast(QMap<QString, QMap<int, int> >());
|
||
return;
|
||
}
|
||
|
||
QMap<QString, QMap<int, int> > record;
|
||
foreach (int select, selectedList) {
|
||
QStringList devList;
|
||
if(STYLE_LOCATION == style)
|
||
{
|
||
devList = CDataInfoManage::instance()->getDevice(select, -1);
|
||
}
|
||
else if(STYLE_DEVTYPE == style)
|
||
{
|
||
devList = CDataInfoManage::instance()->getDevice(-1, select);
|
||
}
|
||
for(int nIndex=0; nIndex<devList.length(); nIndex++)
|
||
{
|
||
CTsdbQuery tsdbQuery(devList[nIndex], tsdbConnPtr);
|
||
tsdbQuery.queryEventByUnit(startTime, endTime, record);
|
||
}
|
||
}
|
||
LOGINFO("CHisEventManage::queryHisEventContrast() time:%I64u", time.elapsed());
|
||
emit updateHisEventContrast(record);
|
||
}
|
||
|
||
bool CHisEventManage::getValidTsdbConnPtr(kbd_dbms::CTsdbConnPtr &ptr)
|
||
{
|
||
if(m_tsdbConnPtr != NULL)
|
||
{
|
||
if(m_tsdbConnPtr->pingServer())
|
||
{
|
||
ptr = m_tsdbConnPtr;
|
||
return true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_tsdbConnPtr = getOneUseableConn(true);
|
||
if(m_tsdbConnPtr != NULL && m_tsdbConnPtr->pingServer())
|
||
{
|
||
ptr = m_tsdbConnPtr;
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
m_tsdbConnPtr = getOneUseableConn(false);
|
||
if(m_tsdbConnPtr != NULL && m_tsdbConnPtr->pingServer())
|
||
{
|
||
ptr = m_tsdbConnPtr;
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|