HM-SPMS/product/src/gui/plugin/AlarmWidget/CAiAlarmDataCollect.cpp

240 lines
7.4 KiB
C++
Raw Normal View History

#include "CAiAlarmDataCollect.h"
#include "pub_logger_api/logger.h"
#include "CAlarmMsgManage.h"
#include <QDebug>
#include "CAlarmDataCollect.h"
using namespace kbd_service;
CAiAlarmDataCollect * CAiAlarmDataCollect::m_pInstance = NULL;
CAiAlarmDataCollect::CAiAlarmDataCollect()
: CIntelliAlmApi4Clt(),
m_referenceCount(0),
m_bFaultRecallState(false),
m_pAlternateTimer(Q_NULLPTR)
{
m_rtdbMutex = new QMutex();
m_rtdbPriorityOrderAccess = new kbd_dbms::CRdbAccess();
m_rtdbPriorityOrderAccess->open("base", "alarm_level_define");
}
CAiAlarmDataCollect::~CAiAlarmDataCollect()
{
LOGDEBUG("CAiAlarmDataCollect::~CAiAlarmDataCollect()");
qDebug() << "~CAiAlarmDataCollect()";
}
void CAiAlarmDataCollect::refrence()
{
m_referenceCount++;
}
int CAiAlarmDataCollect::getRefrenceCount()
{
return m_referenceCount;
}
CAiAlarmDataCollect *CAiAlarmDataCollect::instance()
{
if(NULL == m_pInstance)
{
m_pInstance = new CAiAlarmDataCollect();
}
return m_pInstance;
}
void CAiAlarmDataCollect::initialize()
{
resumeThread();
if(!m_pAlternateTimer)
{
m_pAlternateTimer = new QTimer();
m_pAlternateTimer->setInterval(1000);
connect(m_pAlternateTimer, &QTimer::timeout, this, &CAiAlarmDataCollect::slotAiAlarmStateChanged);
connect(this, &CAiAlarmDataCollect::sigTimerShot, this, &CAiAlarmDataCollect::slotTimerShot, Qt::QueuedConnection);
}
if(!m_bFaultRecallState)
{
emit sigTimerShot(true);
}
}
void CAiAlarmDataCollect::release()
{
emit sigTimerShot(false);
suspendThread(true);
}
bool CAiAlarmDataCollect::isFaultRecallState()
{
return m_bFaultRecallState;
}
bool CAiAlarmDataCollect::requestDelAlm(kbd_idlfile::SIntelliAlmDel &objDelAlm)
{
LOGDEBUG("请求删除!");
return kbd_service::CIntelliAlmApi4Clt::requestDelAlm(objDelAlm);
}
bool CAiAlarmDataCollect::requestSeprAlm(kbd_idlfile::SIntelliAlmSepr &objSeprAlm)
{
LOGDEBUG("请求分离!");
return kbd_service::CIntelliAlmApi4Clt::requestSeprAlm(objSeprAlm);
}
bool CAiAlarmDataCollect::requestMergeAlm(kbd_idlfile::SIntelliAlmMerge &objMergeAlm)
{
LOGDEBUG("请求合并!");
return kbd_service::CIntelliAlmApi4Clt::requestMergeAlm(objMergeAlm);
}
void CAiAlarmDataCollect::handleAllAlmMsg(int nDomainId, kbd_idlfile::SIntelliAlmAdd &objAllAlm)
{
LOGINFO("========== AiAlarmDataCollect handleAllAlmMsg ==========");
//< 清空该域缓存
QMutexLocker locker(m_rtdbMutex);
CAlarmMsgManage::instance()->removeAiAlarmMsgByDomainID(nDomainId);
//构建告警
int nAlarmCount = objAllAlm.alm_info_size();
QList<AiAlarmMsgPtr> almList;
for(int nAddMsgIndex(0); nAddMsgIndex < nAlarmCount; nAddMsgIndex++)
{
kbd_idlfile::SIntelliAlmInfo msg = objAllAlm.alm_info(nAddMsgIndex);
AiAlarmMsgPtr alm(new CAiAlarmMsgInfo());
alm->initialize(msg);
alm->priorityOrder = queryPriorityOrder(alm->priority);
almList.append(alm);
}
CAlarmMsgManage::instance()->addAiAllAlarmMsg(almList);//添加全部完成后通知model重新拉取数据
LOGDEBUG("AiAlarmDataCollect handleAllAlmMsg():count[%d]",nAlarmCount);
emit sigMsgRefresh();
}
void CAiAlarmDataCollect::handleAddAlmMsg(kbd_idlfile::SIntelliAlmAdd &objAddAlm)
{
LOGINFO("========== AiAlarmDataCollect handleAddAlmMsg ==========");
QMutexLocker locker(m_rtdbMutex);
//构建告警
int nAlarmCount = objAddAlm.alm_info_size();
QList<AiAlarmMsgPtr> almList;
for(int nAddMsgIndex(0); nAddMsgIndex < nAlarmCount; nAddMsgIndex++)
{
kbd_idlfile::SIntelliAlmInfo msg = objAddAlm.alm_info(nAddMsgIndex);
AiAlarmMsgPtr alm(new CAiAlarmMsgInfo());
alm->initialize(msg);
alm->priorityOrder = queryPriorityOrder(alm->priority);
almList.append(alm);
}
CAlarmMsgManage::instance()->addAiAlarmMsg(almList); //单独添加的时候来一条通知一次model添加
LOGDEBUG("AiAlarmDataCollect handleAddAlmMsg():count[%d]",nAlarmCount);
}
void CAiAlarmDataCollect::handleDelAlmMsg(kbd_idlfile::SIntelliAlmDel &objDelAlm)
{
LOGINFO("========== AiAlarmDataCollect handleDelAlmMsg ==========");
QMutexLocker locker(m_rtdbMutex);
//构建告警
int nAlarmCount = objDelAlm.uuid_base64_size();
QList<QString> uuidList;
for(int nDelMsgIndex(0); nDelMsgIndex < nAlarmCount; nDelMsgIndex++)
{
QString uuid = QString::fromStdString(objDelAlm.uuid_base64(nDelMsgIndex));
uuidList.append(uuid);
}
CAlarmMsgManage::instance()->delAiAlarmMsg(uuidList);
LOGDEBUG("AiAlarmDataCollect handleDelAlmMsg():count[%d]",nAlarmCount);
}
void CAiAlarmDataCollect::handleBrokenAlmMsg(kbd_idlfile::SIntelliAlmBroken &objBrokenAlm)
{
//先保证能够编译通过
LOGINFO("========== AiAlarmDataCollect handleBrokenAlmMsg ==========");
QMutexLocker locker(m_rtdbMutex);
int nAlarmCount = objBrokenAlm.uuid_base64_size();
QList<QString> uuidList;
for(int nBrokenMsgIndex(0); nBrokenMsgIndex < nAlarmCount; nBrokenMsgIndex++)
{
QString uuid = QString::fromStdString(objBrokenAlm.uuid_base64(nBrokenMsgIndex));
uuidList.append(uuid);
}
CAlarmMsgManage::instance()->brokenAiAlarmMsg(uuidList);
LOGDEBUG("AiAlarmDataCollect handleBrokenAlmMsg():count[%d]",nAlarmCount);
}
void CAiAlarmDataCollect::handleReleaseAlmMsg(kbd_idlfile::SIntelliAlmRelease &objReleaseAlm)
{
//先保证能够编译通过
LOGINFO("========== AiAlarmDataCollect handleReleaseAlmMsg ==========");
QMutexLocker locker(m_rtdbMutex);
int nAlarmCount = objReleaseAlm.uuid_base64_size();
QList<QString> uuidList;
for(int nReleaseMsgIndex(0); nReleaseMsgIndex < nAlarmCount; nReleaseMsgIndex++)
{
QString uuid = QString::fromStdString(objReleaseAlm.uuid_base64(nReleaseMsgIndex));
uuidList.append(uuid);
}
CAlarmMsgManage::instance()->releaseAiAlarmMsg(uuidList);
LOGDEBUG("AiAlarmDataCollect handleReleaseAlmMsg():count[%d]",nAlarmCount);
}
void CAiAlarmDataCollect::destory()
{
LOGINFO("退出时:CAiAlarmDataCollect::destory()打开窗口的个数m_referenceCount:[%d]",m_referenceCount);
if(--m_referenceCount > 0)
{
return;
}
slotTimerShot(false);
suspendThread();
{
QMutexLocker locker(m_rtdbMutex);
if(Q_NULLPTR != m_pAlternateTimer)
{
m_pAlternateTimer->stop();
m_pAlternateTimer->deleteLater();
}
m_pAlternateTimer = Q_NULLPTR;
}
delete m_rtdbMutex;
delete m_rtdbPriorityOrderAccess;
m_pInstance = NULL;
delete this;
}
void CAiAlarmDataCollect::slotTimerShot(const bool start)
{
if(m_pAlternateTimer)
{
if(start)
{
m_pAlternateTimer->start();
}
else
{
m_pAlternateTimer->stop();
}
}
}
void CAiAlarmDataCollect::slotSwitchFaultRecallState(bool bFaultRecallState)
{
m_bFaultRecallState = bFaultRecallState;
release();
m_pInstance->reinit(m_bFaultRecallState);
CAlarmMsgManage::instance()->release();
//initialize();
}
int CAiAlarmDataCollect::queryPriorityOrder(int &id)
{
kbd_dbms::CTableLockGuard locker(*m_rtdbPriorityOrderAccess);
kbd_dbms::CVarType value = -1000;
m_rtdbPriorityOrderAccess->getColumnValueByKey((void*)&id, "priority_order", value);
return value.toInt();
}
void CAiAlarmDataCollect::slotAiAlarmStateChanged()
{
QMutexLocker locker(m_rtdbMutex);
CAlarmMsgManage::instance()->dealDelayAi();
}