2014 lines
73 KiB
C++
2014 lines
73 KiB
C++
#include "CAlarmForm.h"
|
||
#include <QMenu>
|
||
#include <QPrinter>
|
||
#include <QMessageBox>
|
||
#include <QFileDialog>
|
||
#include <QSettings>
|
||
#include <QLineEdit>
|
||
#include <QPushButton>
|
||
#include <QTreeWidget>
|
||
#include <QContextMenuEvent>
|
||
#include <QSortFilterProxyModel>
|
||
#include "ui_CAlarmForm.h"
|
||
#include "CAlarmDelegate.h"
|
||
#include "CAiAlarmDelegate.h"
|
||
#include "CAlarmItemModel.h"
|
||
#include "CAlarmFilterDialog.h"
|
||
#include "CAlarmMsgManage.h"
|
||
#include "CTableViewPrinter.h"
|
||
#include "CAlarmDataCollect.h"
|
||
#include "CAiAlarmDataCollect.h"
|
||
#include "CAlarmInhibitDialog.h"
|
||
#include "CAlarmDeviceTreeModel.h"
|
||
#include "CAlarmDeviceTreeItem.h"
|
||
#include "CAiAlarmTreeItem.h"
|
||
#include "CAiAlarmTreeModel.h"
|
||
#include "perm_mng_api/PermMngApi.h"
|
||
#include "public/pub_sysinfo_api/SysInfoApi.h"
|
||
#include "dbms/db_sysinfo_api/CDbSysInfo.h"
|
||
#include <QDebug>
|
||
#include <QCheckBox>
|
||
#include "CMyListWidget.h"
|
||
#include "CMyCheckBox.h"
|
||
#include "CDisposalPlanDialog.h"
|
||
#include "CTreeViewPrinter.h"
|
||
#include "pub_logger_api/logger.h"
|
||
#include "pub_utility_api/FileUtil.h"
|
||
#include <QDomDocument>
|
||
CAlarmForm::CAlarmForm(QWidget *parent) :
|
||
QWidget(parent),
|
||
m_pModel(Q_NULLPTR),
|
||
m_treeModel(Q_NULLPTR),
|
||
m_delegate(Q_NULLPTR),
|
||
m_aiDelegate(Q_NULLPTR),
|
||
m_aiOptPerm(true),
|
||
m_enableAi(false),
|
||
ui(new Ui::CAlarmForm)
|
||
{
|
||
qRegisterMetaType<QItemSelection>("QItemSelection");
|
||
qRegisterMetaType< QList<QVector<QString> > >("QList<QVector<QString> >");
|
||
qRegisterMetaType<QVector<bool> >("QVector<bool>");
|
||
qRegisterMetaType<QVector<double> >("QVector<double>");
|
||
qRegisterMetaType<QVector<QString> >("QVector<QString>");
|
||
ui->setupUi(this);
|
||
ui->alarmView->setObjectName("alarmView");
|
||
ui->splitter->setStretchFactor(0,1);
|
||
ui->splitter->setStretchFactor(1,6);
|
||
|
||
QHBoxLayout * pHBoxLayout = new QHBoxLayout(ui->deviceView->header());
|
||
m_pSearchTextEdit = new QLineEdit(ui->deviceView->header());
|
||
m_pSearchTextEdit->setObjectName("searchTextEdit");
|
||
m_pSearchTextEdit->setTextMargins(0, 0, 21, 0);
|
||
pHBoxLayout->addWidget(m_pSearchTextEdit);
|
||
pHBoxLayout->setContentsMargins(2,0,2,0);
|
||
pHBoxLayout->setSpacing(0);
|
||
ui->deviceView->header()->setLayout(pHBoxLayout);
|
||
ui->deviceView->header()->setFixedHeight(36);
|
||
|
||
m_pSearchButton = new QPushButton(this);
|
||
m_pSearchButton->setObjectName("searchButton");
|
||
m_pSearchButton->setText("");
|
||
m_pSearchButton->setMaximumSize(21, 22);
|
||
m_pSearchButton->setCursor(QCursor(Qt::ArrowCursor));
|
||
|
||
QHBoxLayout * pSearchLayout = new QHBoxLayout();
|
||
pSearchLayout->setContentsMargins(1, 1, 1, 1);
|
||
pSearchLayout->addStretch();
|
||
pSearchLayout->addWidget(m_pSearchButton);
|
||
m_pSearchTextEdit->setLayout(pSearchLayout);
|
||
|
||
connect(m_pSearchTextEdit, &QLineEdit::returnPressed, this, &CAlarmForm::searchDeviceName);
|
||
connect(m_pSearchButton, &QPushButton::clicked, this, &CAlarmForm::searchDeviceName);
|
||
//initialize();
|
||
m_pListWidget1 = new CMyListWidget(this);
|
||
m_pListWidget2 = new CMyListWidget(this);
|
||
m_pListWidget3 = new CMyListWidget(this);
|
||
m_pLineEdit1 = new QLineEdit(this);
|
||
m_pLineEdit2 = new QLineEdit(this);
|
||
m_pLineEdit3 = new QLineEdit(this);
|
||
m_timeIcon = new QPushButton(this);
|
||
//时间过滤
|
||
m_myCalendar = new CMyCalendar(this);
|
||
QWidgetAction *widgetAction=new QWidgetAction(this);
|
||
m_timeMenu = new QMenu(this);
|
||
widgetAction->setDefaultWidget(m_myCalendar);
|
||
m_timeMenu->addAction(widgetAction);
|
||
m_timeIcon->setObjectName("iconButton");
|
||
m_timeIcon->setText("");
|
||
m_timeIcon->setMaximumSize(21, 22);
|
||
m_timeIcon->setCursor(QCursor(Qt::ArrowCursor));
|
||
QHBoxLayout * pTimeLayout = new QHBoxLayout();
|
||
pTimeLayout->setContentsMargins(1, 1, 1, 1);
|
||
pTimeLayout->addStretch();
|
||
pTimeLayout->addWidget(m_timeIcon);
|
||
ui->lineEdit->setLayout(pTimeLayout);
|
||
connect(m_timeIcon,&QPushButton::clicked,this,&CAlarmForm::myCalendarShow);
|
||
connect(m_myCalendar,&CMyCalendar::sig_endTimeClick,this,&CAlarmForm::myCalendarHide);
|
||
connect(m_myCalendar,&CMyCalendar::sig_cancle,this,&CAlarmForm::cancleTimeFilter);
|
||
ui->lineEdit->setText(tr("请选择时间"));
|
||
ui->lineEdit->setReadOnly(true);
|
||
ui->lineEdit->setObjectName("iconLineEdit");
|
||
|
||
m_pdfPrinter = new CPdfPrinter();
|
||
m_thread = new QThread();
|
||
m_pdfPrinter->moveToThread(m_thread);
|
||
connect(m_thread,&QThread::started,m_pdfPrinter,&CPdfPrinter::initialize);
|
||
connect(m_thread,&QThread::finished,m_pdfPrinter,&CPdfPrinter::deleteLater);
|
||
connect(this,&CAlarmForm::printExcel,m_pdfPrinter,&CPdfPrinter::printerByModel);
|
||
connect(this,&CAlarmForm::printExcelAlm,m_pdfPrinter,&CPdfPrinter::printerAlmByModel);
|
||
connect(m_pdfPrinter,&CPdfPrinter::printResult,this,&CAlarmForm::printMess);
|
||
m_thread->start();
|
||
}
|
||
|
||
CAlarmForm::~CAlarmForm()
|
||
{
|
||
removeInhibitAlarm(m_listInhibitAlarm);
|
||
if(m_delegate)
|
||
{
|
||
delete m_delegate;
|
||
}
|
||
m_delegate = Q_NULLPTR;
|
||
|
||
if(m_aiDelegate)
|
||
{
|
||
delete m_aiDelegate;
|
||
}
|
||
m_aiDelegate = Q_NULLPTR;
|
||
delete m_pdfPrinter;
|
||
m_thread->quit();
|
||
m_thread->wait();
|
||
delete ui;
|
||
LOGDEBUG("CAlarmForm::~CAlarmForm()");
|
||
qDebug() << "~CAlarmForm()";
|
||
}
|
||
|
||
void CAlarmForm::initialize()
|
||
{
|
||
m_pDeviceModel = new CAlarmDeviceTreeModel(this);
|
||
ui->deviceView->setModel(m_pDeviceModel);
|
||
connect(ui->checkBox,SIGNAL(stateChanged(int)),this,SLOT(slot_changePage(int)));
|
||
connect(ui->filter, SIGNAL(clicked()), this, SLOT(updateFilter()));
|
||
connect(ui->remove, SIGNAL(clicked()), this, SLOT(slot_removeAlarm()));
|
||
connect(ui->confirm, SIGNAL(clicked()), this, SLOT(slot_confirmAlarm()));
|
||
|
||
connect(ui->inhibit, SIGNAL(clicked()), this, SLOT(slot_showInhibitAlarm()));
|
||
|
||
connect(ui->print, SIGNAL(clicked()), this, SLOT(print()));
|
||
connect(ui->closeBtn, &QPushButton::clicked, this, &CAlarmForm::closeBtnClicked);
|
||
updateAlarmOperatePerm();
|
||
|
||
//< lingdaoyaoqiu
|
||
{
|
||
QSettings columFlags("IOT_HMI", "alarm config");
|
||
if(!columFlags.contains(QString("alarm/colum_0")))
|
||
{
|
||
columFlags.setValue(QString("alarm/colum_0"), false); //< 时间
|
||
columFlags.setValue(QString("alarm/colum_1"), false); //< 优先级
|
||
columFlags.setValue(QString("alarm/colum_2"), false); //< 位置
|
||
columFlags.setValue(QString("alarm/colum_3"), true); //< 责任区
|
||
columFlags.setValue(QString("alarm/colum_4"), true); //< 告警类型
|
||
columFlags.setValue(QString("alarm/colum_5"), false); //< 告警状态
|
||
columFlags.setValue(QString("alarm/colum_6"), false); //< 确认状态
|
||
columFlags.setValue(QString("alarm/colum_7"), false); //<
|
||
}
|
||
}
|
||
loadConfig();
|
||
ui->checkBox->setChecked(m_enableAi);
|
||
}
|
||
|
||
void CAlarmForm::loadConfig()
|
||
{
|
||
QFile file(iot_public::CFileUtil::getPathOfCfgFile("intelli_alm_cfg.xml",CN_DIR_PLATFORM).c_str());
|
||
if (!file.open(QFile::ReadWrite))
|
||
{
|
||
LOGERROR("打开智能告警配置文件失败,默认不启动");
|
||
return;
|
||
}
|
||
|
||
QDomDocument doc;
|
||
if (!doc.setContent(&file))
|
||
{
|
||
file.close();
|
||
LOGERROR("加载智能告警配置文件失败,默认不启动");
|
||
return;
|
||
}
|
||
file.close();
|
||
|
||
QDomElement root = doc.documentElement(); //返回根节点 root
|
||
QDomNode node = root.firstChild(); //获得第一个子节点
|
||
|
||
while (!node.isNull()) //如果节点不空
|
||
{
|
||
QDomElement element = node.toElement();
|
||
if(element.tagName() == "intelli_alm_srv")
|
||
{
|
||
if(element.attribute("enable") == "true")
|
||
{
|
||
m_enableAi =true;
|
||
}else
|
||
{
|
||
m_enableAi =false;
|
||
}
|
||
break;
|
||
}
|
||
node = node.nextSibling();
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::updateAlarmOperatePerm()
|
||
{
|
||
m_listRegionId.clear();
|
||
m_listLocationId.clear();
|
||
iot_public::SNodeInfo stNodeInfo;
|
||
iot_public::CSysInfoInterfacePtr spSysInfo;
|
||
if (!iot_public::createSysInfoInstance(spSysInfo))
|
||
{
|
||
LOGERROR("创建系统信息访问库实例失败!");
|
||
return;
|
||
}
|
||
spSysInfo->getLocalNodeInfo(stNodeInfo);
|
||
m_nodeName = stNodeInfo.strName;
|
||
|
||
iot_service::CPermMngApiPtr permMngPtr = iot_service::getPermMngInstance("base");
|
||
if(permMngPtr != NULL)
|
||
{
|
||
permMngPtr->PermDllInit();
|
||
int nUserGrpId;
|
||
int nLevel;
|
||
int nLoginSec;
|
||
std::string strInstanceName;
|
||
if(PERM_NORMAL != permMngPtr->CurUser(m_userId, nUserGrpId, nLevel, nLoginSec, strInstanceName))
|
||
{
|
||
m_userId = -1;
|
||
LOGERROR("用户ID获取失败!");
|
||
return;
|
||
}
|
||
std::vector <int> vecRegionId;
|
||
std::vector <int> vecLocationId;
|
||
if(PERM_NORMAL == permMngPtr->GetSpeFunc(FUNC_SPE_ALARM_OPERATE, vecRegionId, vecLocationId))
|
||
{
|
||
std::vector <int>::iterator region = vecRegionId.begin();
|
||
while (region != vecRegionId.end())
|
||
{
|
||
m_listRegionId.append(*region++);
|
||
}
|
||
|
||
std::vector <int>::iterator location = vecLocationId.begin();
|
||
while (location != vecLocationId.end())
|
||
{
|
||
m_listLocationId.append(*location++);
|
||
}
|
||
}
|
||
std::string str = "FUNC_NOM_IA_EDIT";
|
||
if(PERM_PERMIT != permMngPtr->PermCheck(PERM_NOM_FUNC_DEF,&str))
|
||
{
|
||
m_aiOptPerm = false;
|
||
LOGERROR("无智能告警编辑权限");
|
||
}else
|
||
{
|
||
m_aiOptPerm = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::setAlarmOperateEnable(const bool &bEnable)
|
||
{
|
||
ui->confirm->setEnabled(bEnable);
|
||
ui->remove->setEnabled(bEnable);
|
||
}
|
||
|
||
void CAlarmForm::setColumnWidth(const int &column, const int &width)
|
||
{
|
||
if(ui->alarmView != Q_NULLPTR)
|
||
{
|
||
ui->alarmView->setColumnWidth(column, width);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::initFilter()
|
||
{
|
||
QMap<int, QString> priority = m_pModel->priorityDescriptionMap();
|
||
QMap<int, QString> location = m_pModel->locationDescriptionMap();
|
||
QMap<int, QString> alarmType = m_pModel->alarmTypeDescriptionMap();
|
||
for(QMap<int, QString>::iterator it1 = priority.begin();it1 != priority.end();++it1)
|
||
{
|
||
QListWidgetItem *pItem = new QListWidgetItem(m_pListWidget1);
|
||
pItem->setData(Qt::UserRole, it1.key());
|
||
CMyCheckBox *pCheckBox = new CMyCheckBox(this);
|
||
pCheckBox->setText(it1.value());
|
||
m_pListWidget1->addItem(pItem);
|
||
m_pListWidget1->setItemWidget(pItem, pCheckBox);
|
||
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged1(int)));
|
||
}
|
||
ui->comboBox->setModel(m_pListWidget1->model());
|
||
ui->comboBox->setView(m_pListWidget1);
|
||
ui->comboBox->setLineEdit(m_pLineEdit1);
|
||
m_strText1 = tr("请选择优先级");
|
||
m_pLineEdit1->setText(tr("请选择优先级"));
|
||
m_pLineEdit1->setReadOnly(true);
|
||
connect(m_pLineEdit1, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged1(const QString &))); //为了解决点击下拉框白色部分导致lineedit无数据问题
|
||
for(QMap<int, QString>::iterator it2 = location.begin();it2 != location.end();++it2)
|
||
{
|
||
QListWidgetItem *pItem = new QListWidgetItem(m_pListWidget2);
|
||
pItem->setData(Qt::UserRole, it2.key());
|
||
CMyCheckBox *pCheckBox = new CMyCheckBox(this);
|
||
pCheckBox->setText(it2.value());
|
||
m_pListWidget2->addItem(pItem);
|
||
m_pListWidget2->setItemWidget(pItem, pCheckBox);
|
||
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged2(int)));
|
||
}
|
||
ui->comboBox_2->setModel(m_pListWidget2->model());
|
||
ui->comboBox_2->setView(m_pListWidget2);
|
||
ui->comboBox_2->setLineEdit(m_pLineEdit2);
|
||
m_strText2 = tr("请选择位置");
|
||
m_pLineEdit2->setText(tr("请选择位置"));
|
||
m_pLineEdit2->setReadOnly(true);
|
||
connect(m_pLineEdit2, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged2(const QString &)));
|
||
for(QMap<int, QString>::iterator it3 = alarmType.begin();it3 != alarmType.end();++it3)
|
||
{
|
||
QListWidgetItem *pItem = new QListWidgetItem(m_pListWidget3);
|
||
pItem->setData(Qt::UserRole, it3.key());
|
||
CMyCheckBox *pCheckBox = new CMyCheckBox(this);
|
||
pCheckBox->setText(it3.value());
|
||
m_pListWidget3->addItem(pItem);
|
||
m_pListWidget3->setItemWidget(pItem, pCheckBox);
|
||
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged3(int)));
|
||
}
|
||
ui->comboBox_3->setModel(m_pListWidget3->model());
|
||
ui->comboBox_3->setView(m_pListWidget3);
|
||
ui->comboBox_3->setLineEdit(m_pLineEdit3);
|
||
m_strText3 = tr("请选择告警类型");
|
||
m_pLineEdit3->setText(tr("请选择告警类型"));
|
||
m_pLineEdit3->setReadOnly(true);
|
||
connect(m_pLineEdit3, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged3(const QString &)));
|
||
}
|
||
|
||
void CAlarmForm::setLevelComboBox(bool &isLevelFilter, QList<int> &listLevel)
|
||
{
|
||
if(isLevelFilter == true && listLevel.size() > 0)
|
||
{
|
||
QString strText("");
|
||
for (int i = 0; i < m_pListWidget1->count(); ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget1->item(i);
|
||
QWidget *pWidget = m_pListWidget1->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
int nData = pItem->data(Qt::UserRole).toInt();
|
||
if(listLevel.contains(nData))
|
||
{
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(true);
|
||
strText.append(pCheckBox->text()).append(" ");
|
||
pCheckBox->blockSignals(false);
|
||
}else
|
||
{
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(false);
|
||
pCheckBox->blockSignals(false);
|
||
}
|
||
}
|
||
m_strText1 = strText;
|
||
m_pLineEdit1->setText(strText);
|
||
}else
|
||
{
|
||
for (int i = 0; i < m_pListWidget1->count(); ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget1->item(i);
|
||
QWidget *pWidget = m_pListWidget1->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(false);
|
||
pCheckBox->blockSignals(false);
|
||
}
|
||
m_strText1 = tr("请选择优先级");
|
||
m_pLineEdit1->setText(tr("请选择优先级"));
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::setLocationComboBox(bool &isLocationFilter,QList<int> &listLocation)
|
||
{
|
||
if(isLocationFilter == true && listLocation.size() > 0)
|
||
{
|
||
QString strText("");
|
||
for (int i = 0; i < m_pListWidget2->count(); ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget2->item(i);
|
||
QWidget *pWidget = m_pListWidget2->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
int nData = pItem->data(Qt::UserRole).toInt();
|
||
if(listLocation.contains(nData))
|
||
{
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(true);
|
||
strText.append(pCheckBox->text()).append(" ");
|
||
pCheckBox->blockSignals(false);
|
||
}else
|
||
{
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(false);
|
||
pCheckBox->blockSignals(false);
|
||
}
|
||
}
|
||
m_strText2 = strText;
|
||
m_pLineEdit2->setText(strText);
|
||
}else
|
||
{
|
||
for (int i = 0; i < m_pListWidget2->count(); ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget2->item(i);
|
||
QWidget *pWidget = m_pListWidget2->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(false);
|
||
pCheckBox->blockSignals(false);
|
||
}
|
||
m_strText2 = tr("请选择位置");
|
||
m_pLineEdit2->setText(tr("请选择位置"));
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::setAlarmTypeComboBox(bool &isAlarmTypeFilter, QList<int> &listAlarmType)
|
||
{
|
||
if(isAlarmTypeFilter == true && listAlarmType.size() > 0)
|
||
{
|
||
QString strText("");
|
||
for (int i = 0; i < m_pListWidget3->count(); ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget3->item(i);
|
||
QWidget *pWidget = m_pListWidget3->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
int nData = pItem->data(Qt::UserRole).toInt();
|
||
if(listAlarmType.contains(nData))
|
||
{
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(true);
|
||
strText.append(pCheckBox->text()).append(" ");
|
||
pCheckBox->blockSignals(false);
|
||
}else
|
||
{
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(false);
|
||
pCheckBox->blockSignals(false);
|
||
}
|
||
}
|
||
m_strText3 = strText;
|
||
m_pLineEdit3->setText(strText);
|
||
}else
|
||
{
|
||
for (int i = 0; i < m_pListWidget3->count(); ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget3->item(i);
|
||
QWidget *pWidget = m_pListWidget3->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
pCheckBox->blockSignals(true);
|
||
pCheckBox->setChecked(false);
|
||
pCheckBox->blockSignals(false);
|
||
}
|
||
m_strText3 = tr("请选择告警类型");
|
||
m_pLineEdit3->setText(tr("请选择告警类型"));
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::setAlarmTimeLineEdit(bool &isTimeFilter, QDateTime &startTime, QDateTime &endTime)
|
||
{
|
||
if(isTimeFilter == true)
|
||
{
|
||
ui->lineEdit->setText(startTime.date().toString("yyyy-MM-dd")+"~"+endTime.date().toString("yyyy-MM-dd"));
|
||
}else
|
||
{
|
||
ui->lineEdit->setText(tr("请选择时间"));
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::setAlarmModel(CAlarmItemModel *model)
|
||
{
|
||
m_pModel = model;
|
||
m_delegate = new CAlarmDelegate(m_pModel, ui->alarmView);
|
||
connect(m_delegate,&CAlarmDelegate::openVideo,CAlarmMsgManage::instance(),&CAlarmMsgManage::openVideoDialog,Qt::QueuedConnection);
|
||
ui->alarmView->initialize();
|
||
ui->alarmView->setItemDelegate(m_delegate);
|
||
ui->alarmView->setModel(m_pModel);
|
||
|
||
//< 性能损耗
|
||
//connect(ui->alarmView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(slot_selectionChanged()), Qt::QueuedConnection);
|
||
connect(ui->alarmView->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), m_pModel, SLOT(sortColumn(int,Qt::SortOrder)));
|
||
ui->confirm->setEnabled(true);
|
||
ui->remove->setEnabled(true);
|
||
|
||
|
||
//原始告警窗
|
||
|
||
ui->alarmView->setColumnWidth(0, 230);
|
||
ui->alarmView->setColumnWidth(1, 120);
|
||
ui->alarmView->setColumnWidth(2, 150);
|
||
ui->alarmView->setColumnWidth(5, 150);
|
||
ui->alarmView->setColumnWidth(6, 120);
|
||
|
||
ui->alarmView->horizontalHeader()->setSortIndicator(1, Qt::AscendingOrder);
|
||
QSettings columFlags("IOT_HMI", "alarm config");
|
||
for(int nColumnIndex(0); nColumnIndex < m_pModel->columnCount(); nColumnIndex++)
|
||
{
|
||
bool visible = columFlags.value(QString("alarm/colum_%1").arg(nColumnIndex)).toBool();
|
||
ui->alarmView->setColumnHidden(nColumnIndex, visible);
|
||
}
|
||
// ui->stackedWidget->setCurrentIndex(0);
|
||
ui->checkBox->setHidden(true);
|
||
//智能告警窗
|
||
if(m_enableAi)
|
||
{
|
||
ui->aiAlarmTreeView->initialize();
|
||
m_treeModel = new CAiAlarmTreeModel(this);
|
||
m_aiDelegate = new CAiAlarmDelegate(m_treeModel,ui->aiAlarmTreeView);
|
||
ui->aiAlarmTreeView->setItemDelegate(m_aiDelegate);
|
||
ui->aiAlarmTreeView->setModel(m_treeModel);
|
||
connect(m_aiDelegate,&CAiAlarmDelegate::openVideo,CAlarmMsgManage::instance(),&CAlarmMsgManage::openVideoDialog,Qt::QueuedConnection);
|
||
connect(ui->aiAlarmTreeView->header(),&QHeaderView::sortIndicatorChanged, m_treeModel,&CAiAlarmTreeModel::sortColumn);
|
||
connect(ui->aiAlarmTreeView,&CAiAlarmTreeView::doubleClicked, this,&CAlarmForm::aiAlmDoubleClicked);
|
||
|
||
ui->aiAlarmTreeView->setColumnWidth(0, 230);
|
||
ui->aiAlarmTreeView->setColumnWidth(1, 120);
|
||
ui->aiAlarmTreeView->setColumnWidth(2, 150);
|
||
ui->aiAlarmTreeView->setColumnWidth(5, 150);
|
||
ui->aiAlarmTreeView->setColumnWidth(6, 120);
|
||
|
||
|
||
ui->aiAlarmTreeView->header()->setSortIndicator(1, Qt::AscendingOrder);
|
||
for(int nColumnIndex(0); nColumnIndex < m_treeModel->columnCount(); nColumnIndex++)
|
||
{
|
||
bool visible = columFlags.value(QString("alarm/colum_%1").arg(nColumnIndex)).toBool();
|
||
ui->aiAlarmTreeView->setColumnHidden(nColumnIndex, visible);
|
||
}
|
||
// ui->stackedWidget->setCurrentIndex(1);
|
||
ui->checkBox->setHidden(false);
|
||
}
|
||
|
||
|
||
loadDeviceGroupFilterWidget();
|
||
if(m_pDeviceModel)
|
||
{
|
||
connect(m_pDeviceModel, &CAlarmDeviceTreeModel::itemCheckStateChanged, this, &CAlarmForm::deviceGroupFilterChanged);
|
||
}
|
||
initFilter();
|
||
}
|
||
|
||
void CAlarmForm::updateView()
|
||
{
|
||
m_pModel->updateAlternate();
|
||
updateDeviceGroupHiddenState();
|
||
ui->alarmView->viewport()->update();
|
||
if(m_enableAi)
|
||
{
|
||
ui->aiAlarmTreeView->viewport()->update();
|
||
}
|
||
updateRowTips();
|
||
}
|
||
|
||
void CAlarmForm::updateFilter()
|
||
{
|
||
bool isLevelFilter;
|
||
QList<int> levelFilter;
|
||
bool isLocationFilter;
|
||
QList<int> locationFilter;
|
||
bool isRegionFilter;
|
||
QList<int> regionFilter;
|
||
bool isAlarmTypeFilter; //告警状态过滤
|
||
QList<int> typeFilter;
|
||
bool deviceTypeFilter;
|
||
QString subSystem;
|
||
QString deviceType;
|
||
bool keywordFilter;
|
||
QString keyword;
|
||
bool isTimeFilterEnable;
|
||
QDateTime startTime;
|
||
QDateTime endTime;
|
||
bool isStateFilterEnable;
|
||
bool isConfirm;
|
||
|
||
CAlarmFilterDialog filterDlg;
|
||
filterDlg.setPriorityDescription(m_pModel->priorityDescriptionMap());
|
||
filterDlg.setLocationDescription(m_pModel->locationDescriptionMap());
|
||
filterDlg.setRegionDescription(m_pModel->regionDescriptionMap());
|
||
filterDlg.setAlarmTypeDescription(m_pModel->alarmTypeDescriptionMap());
|
||
m_pModel->getFilter(isLevelFilter, levelFilter,
|
||
isLocationFilter, locationFilter,
|
||
isRegionFilter, regionFilter,
|
||
isAlarmTypeFilter, typeFilter,
|
||
deviceTypeFilter, subSystem, deviceType,
|
||
keywordFilter, keyword,
|
||
isTimeFilterEnable, startTime, endTime,
|
||
isStateFilterEnable, isConfirm);
|
||
filterDlg.initialize();
|
||
filterDlg.setLevelFilterEnable(isLevelFilter);
|
||
filterDlg.setLevelFilter(levelFilter);
|
||
filterDlg.setLocationFilterEnable(isLocationFilter);
|
||
filterDlg.setLocationFilter(locationFilter);
|
||
filterDlg.setRegionFilterEnable(isRegionFilter);
|
||
filterDlg.setRegionFilter(regionFilter);
|
||
filterDlg.setAlarmTypeFilterEnable(isAlarmTypeFilter);
|
||
filterDlg.setAlarmTypeFilter(typeFilter);
|
||
filterDlg.setDeviceFilterEnable(deviceTypeFilter);
|
||
filterDlg.setSubSystem(subSystem);
|
||
filterDlg.setDeviceType(deviceType);
|
||
filterDlg.setkeyWordFilterEnable(keywordFilter);
|
||
filterDlg.setkeyWordFilteContent(keyword);
|
||
filterDlg.setTimeFilterEnable(isTimeFilterEnable);
|
||
filterDlg.setStartTimeFilter(startTime);
|
||
filterDlg.setEndTimeFilter(endTime);
|
||
filterDlg.setStateFilterEnable(isStateFilterEnable);
|
||
filterDlg.setStateFilter(isConfirm);
|
||
connect(&filterDlg, SIGNAL(sig_updateFilter(bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QString, QString, bool, QString, bool, QDateTime, QDateTime, bool, bool)),
|
||
this, SLOT(slot_updateFilter(bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QString, QString, bool, QString, bool, QDateTime, QDateTime, bool, bool)));
|
||
filterDlg.exec();
|
||
}
|
||
|
||
void CAlarmForm::deviceGroupFilterChanged(const QString &device, const bool &checked)
|
||
{
|
||
if(checked)
|
||
{
|
||
m_pModel->removeDeviceGroupFilter(device);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->removeDeviceGroupFilter(device);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_pModel->addDeviceGroupFilter(device);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->addDeviceGroupFilter(device);
|
||
}
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::slot_changePage(int i)
|
||
{
|
||
Q_UNUSED(i)
|
||
if(!ui->checkBox->isChecked())
|
||
{
|
||
ui->stackedWidget->setCurrentIndex(0);
|
||
}else
|
||
{
|
||
ui->stackedWidget->setCurrentIndex(1);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::slot_updateFilter(bool isLevelFilter, QList<int> listLevel, bool isLocationFilter, QList<int> listLocation, bool isRegionFilter, QList<int> listRegion, bool isAlarmTypeFilter, QList<int> listAlarmType,
|
||
bool isDeviceTypeFilter, QString subSystem, QString deviceType, bool isKeywordFilterEnable, QString keyword, bool isTimeFilter, QDateTime startTime, QDateTime endTime, bool isConfirmFilter, bool confirm)
|
||
{
|
||
m_pModel->setFilter(isLevelFilter, listLevel, isLocationFilter, listLocation, isRegionFilter, listRegion, isAlarmTypeFilter, listAlarmType, isDeviceTypeFilter, subSystem, deviceType, isKeywordFilterEnable, keyword, isTimeFilter, startTime, endTime, isConfirmFilter, confirm);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->setFilter(isLevelFilter, listLevel, isLocationFilter, listLocation, isRegionFilter, listRegion, isAlarmTypeFilter, listAlarmType, isDeviceTypeFilter, subSystem, deviceType, isKeywordFilterEnable, keyword, isTimeFilter, startTime, endTime, isConfirmFilter, confirm);
|
||
}
|
||
|
||
//设置下拉框的值
|
||
setLevelComboBox(isLevelFilter,listLevel);
|
||
setLocationComboBox(isLocationFilter,listLocation);
|
||
setAlarmTypeComboBox(isAlarmTypeFilter,listAlarmType);
|
||
setAlarmTimeLineEdit(isTimeFilter, startTime, endTime);
|
||
}
|
||
|
||
void CAlarmForm::slot_removeAlarm()
|
||
{
|
||
updateAlarmOperatePerm();
|
||
if(!ui->checkBox->isChecked())
|
||
{
|
||
removeAlarm0();
|
||
}else
|
||
{
|
||
removeAlarm1();
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::slot_confirmAlarm()
|
||
{
|
||
updateAlarmOperatePerm();
|
||
if(!ui->checkBox->isChecked())
|
||
{
|
||
confirmAlarm0();
|
||
}else
|
||
{
|
||
confirmAlarm1();
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::slot_showInhibitAlarm()
|
||
{
|
||
CAlarmInhibitDialog dlg;
|
||
dlg.setPriorityDescriptionMap(m_pModel->priorityDescriptionMap());
|
||
dlg.setLocationDescriptionMap(m_pModel->locationDescriptionMap());
|
||
dlg.setRegionDescriptionMap(m_pModel->regionDescriptionMap());
|
||
dlg.setAlarmTypeDescriptionMap(m_pModel->alarmTypeDescriptionMap());
|
||
dlg.setDeviceTypeDescriptionMap(m_pModel->deviceTypeDescriptionMap());
|
||
dlg.setInhibitAlarmList(m_listInhibitAlarm);
|
||
connect(&dlg, &CAlarmInhibitDialog::removeInhibitAlarmList, this, &CAlarmForm::removeInhibitAlarm);
|
||
dlg.exec();
|
||
|
||
}
|
||
|
||
void CAlarmForm::removeInhibitAlarm(QList<AlarmMsgPtr> alarmList)
|
||
{
|
||
foreach (AlarmMsgPtr alm, alarmList)
|
||
{
|
||
m_listInhibitAlarm.removeAll(alm);
|
||
CAlarmMsgManage::instance()->removeInhibitTag(alm->key_id_tag);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::searchDeviceName()
|
||
{
|
||
QItemSelection selection;
|
||
QString content = m_pSearchTextEdit->text();
|
||
ui->deviceView->selectionModel()->select(selection, QItemSelectionModel::Clear);
|
||
if(content.isEmpty())
|
||
{
|
||
return;
|
||
}
|
||
const QHash< QString, QModelIndex > &indexNameList = m_pDeviceModel->indexNameList();
|
||
QHash< QString, QModelIndex >::const_iterator iter = indexNameList.constBegin();
|
||
while (iter != indexNameList.constEnd())
|
||
{
|
||
qDebug()<<iter.key().section(".", 1);
|
||
if(iter.key().section(".", 1).contains(content, Qt::CaseInsensitive))
|
||
{
|
||
selection.append(QItemSelectionRange(iter.value(), iter.value()));
|
||
selection.append(QItemSelectionRange(iter.value().parent(), iter.value().parent()));
|
||
}
|
||
iter++;
|
||
}
|
||
ui->deviceView->selectionModel()->select(selection, QItemSelectionModel::Select);
|
||
}
|
||
|
||
void CAlarmForm::updateRowTips()
|
||
{
|
||
if(!ui->checkBox->isChecked())
|
||
{
|
||
if(m_pModel)
|
||
{
|
||
ui->showRow->setText(QString::number(m_pModel->rowCount()));
|
||
int nNumber = m_pModel->filterCount();
|
||
if(nNumber<0) nNumber = 0 ;
|
||
ui->filterRow->setText(QString::number(nNumber));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(m_treeModel)
|
||
{
|
||
int showNum = m_treeModel->getShowNum();
|
||
int showAiNum = m_treeModel->getShowAi();
|
||
int showTotal = CAlarmMsgManage::instance()->getAlmTotal();
|
||
ui->showRow->setText(QString("%1/%2").arg(showNum).arg(showAiNum));
|
||
int nNumber = showTotal - showNum;
|
||
if(nNumber<0) nNumber = 0 ;
|
||
ui->filterRow->setText(QString::number(nNumber));
|
||
}
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::print()
|
||
{
|
||
//QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("(*.pdf *)"));
|
||
QString fileName=QFileDialog::getSaveFileName(this,tr("Save File"),QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),"Excel 文件(*.xlsx)");//获取保存路径*.xls
|
||
if(!ui->checkBox->isChecked())
|
||
{
|
||
print0(fileName);
|
||
}else
|
||
{
|
||
print1(fileName);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::stateChanged1(int state)
|
||
{
|
||
Q_UNUSED(state)
|
||
QString strText("");
|
||
m_priorityList.clear();
|
||
int nCount = m_pListWidget1->count();
|
||
for (int i = 0; i < nCount; ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget1->item(i);
|
||
QWidget *pWidget = m_pListWidget1->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
if (pCheckBox->isChecked())
|
||
{
|
||
int nData = pItem->data(Qt::UserRole).toInt();
|
||
QString strtext = pCheckBox->text();
|
||
strText.append(strtext).append(" ");
|
||
m_priorityList.append(nData);
|
||
}
|
||
}
|
||
if (!strText.isEmpty())
|
||
{
|
||
m_strText1 = strText;
|
||
m_pLineEdit1->setText(strText);
|
||
}
|
||
else
|
||
{
|
||
m_pLineEdit1->clear();
|
||
m_strText1 = tr("请选择优先级");
|
||
m_pLineEdit1->setText(tr("请选择优先级"));
|
||
}
|
||
bool isCheck = false;
|
||
if(m_priorityList.size() > 0)
|
||
{
|
||
isCheck = true;
|
||
}
|
||
m_pModel->setPriorityFilter(isCheck,m_priorityList);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->setPriorityFilter(isCheck,m_priorityList);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::stateChanged2(int state)
|
||
{
|
||
Q_UNUSED(state)
|
||
QString strText("");
|
||
m_locationList.clear();
|
||
int nCount = m_pListWidget2->count();
|
||
for (int i = 0; i < nCount; ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget2->item(i);
|
||
QWidget *pWidget = m_pListWidget2->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
if (pCheckBox->isChecked())
|
||
{
|
||
int nData = pItem->data(Qt::UserRole).toInt();
|
||
QString strtext = pCheckBox->text();
|
||
strText.append(strtext).append(" ");
|
||
m_locationList.append(nData);
|
||
}
|
||
}
|
||
if (!strText.isEmpty())
|
||
{
|
||
m_strText2 = strText;
|
||
m_pLineEdit2->setText(strText);
|
||
}
|
||
else
|
||
{
|
||
m_pLineEdit2->clear();
|
||
m_strText2 = tr("请选择位置");
|
||
m_pLineEdit2->setText(tr("请选择位置"));
|
||
}
|
||
bool isCheck = false;
|
||
if(m_locationList.size() > 0)
|
||
{
|
||
isCheck = true;
|
||
}
|
||
m_pModel->setLocationFilter(isCheck,m_locationList);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->setLocationFilter(isCheck,m_locationList);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::stateChanged3(int state)
|
||
{
|
||
Q_UNUSED(state)
|
||
QString strText("");
|
||
m_alarmTypeList.clear();
|
||
bool other = false;
|
||
int nCount = m_pListWidget3->count();
|
||
for (int i = 0; i < nCount; ++i)
|
||
{
|
||
QListWidgetItem *pItem = m_pListWidget3->item(i);
|
||
QWidget *pWidget = m_pListWidget3->itemWidget(pItem);
|
||
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
|
||
if (pCheckBox->isChecked())
|
||
{
|
||
int nData = pItem->data(Qt::UserRole).toInt();
|
||
if(nData == 0)
|
||
{
|
||
other = true;
|
||
}
|
||
QString strtext = pCheckBox->text();
|
||
strText.append(strtext).append(" ");
|
||
m_alarmTypeList.append(nData);
|
||
}
|
||
}
|
||
if (!strText.isEmpty())
|
||
{
|
||
m_strText3 = strText;
|
||
m_pLineEdit3->setText(strText);
|
||
}
|
||
else
|
||
{
|
||
m_pLineEdit3->clear();
|
||
m_strText3 = tr("请选择告警类型");
|
||
m_pLineEdit3->setText(tr("请选择告警类型"));
|
||
}
|
||
bool isCheck = false;
|
||
if(m_alarmTypeList.size() > 0)
|
||
{
|
||
isCheck = true;
|
||
}
|
||
m_pModel->setAlarmTypeFilter(isCheck,m_alarmTypeList);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->setAlarmTypeFilter(isCheck,m_alarmTypeList);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::textChanged1(const QString &text)
|
||
{
|
||
Q_UNUSED(text)
|
||
m_pLineEdit1->setText(m_strText1);
|
||
}
|
||
|
||
void CAlarmForm::textChanged2(const QString &text)
|
||
{
|
||
Q_UNUSED(text)
|
||
m_pLineEdit2->setText(m_strText2);
|
||
}
|
||
|
||
void CAlarmForm::textChanged3(const QString &text)
|
||
{
|
||
Q_UNUSED(text)
|
||
m_pLineEdit3->setText(m_strText3);
|
||
}
|
||
|
||
void CAlarmForm::myCalendarHide(QDate startTime,QDate endTime)
|
||
{
|
||
ui->lineEdit->setText(startTime.toString("yyyy-MM-dd") +"~"+endTime.toString("yyyy-MM-dd"));
|
||
//开始过滤
|
||
bool isCheck = true;
|
||
m_pModel->setAlarmTimeFilter(isCheck,startTime,endTime);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->setAlarmTimeFilter(isCheck,startTime,endTime);
|
||
}
|
||
m_timeMenu->hide();
|
||
}
|
||
|
||
void CAlarmForm::myCalendarShow()
|
||
{
|
||
QPoint point(QCursor::pos().x()-500,QCursor::pos().y()+15);
|
||
m_timeMenu->move(point);
|
||
m_timeMenu->show();
|
||
}
|
||
|
||
void CAlarmForm::cancleTimeFilter()
|
||
{
|
||
ui->lineEdit->setText(tr("请选择时间"));
|
||
//取消过滤
|
||
bool isCheck = false;
|
||
m_pModel->setAlarmTimeFilter(isCheck);
|
||
if(m_enableAi)
|
||
{
|
||
m_treeModel->setAlarmTimeFilter(isCheck);
|
||
}
|
||
m_timeMenu->hide();
|
||
}
|
||
|
||
void CAlarmForm::aiAlmDoubleClicked(const QModelIndex &index)
|
||
{
|
||
if(m_treeModel == NULL)
|
||
{
|
||
return ;
|
||
}
|
||
if(!index.isValid())
|
||
{
|
||
return ;
|
||
}
|
||
CAiAlarmTreeItem *item =static_cast<CAiAlarmTreeItem*>(index.internalPointer());
|
||
if(item->isAi())
|
||
{
|
||
AiAlarmMsgPtr aiPtr;
|
||
if(item->getAiPtr(aiPtr))
|
||
{
|
||
CDisposalPlanDialog dialog(aiPtr);
|
||
dialog.exec();
|
||
}else
|
||
{
|
||
LOGERROR("aiAlmDoubleClicked():标识符错误!");
|
||
}
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::printMess(QString fileName)
|
||
{
|
||
QMessageBox::information( 0, tr("提示"), tr("导出成功"));
|
||
}
|
||
|
||
void CAlarmForm::contextMenuEvent(QContextMenuEvent *event)
|
||
{
|
||
updateAlarmOperatePerm();
|
||
if(ui->stackedWidget->currentIndex() == 0)
|
||
{
|
||
contextMenuStack0Event(event);
|
||
}else if(ui->stackedWidget->currentIndex() == 1)
|
||
{
|
||
contextMenuStack1Event(event);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::contextMenuStack0Event(QContextMenuEvent *event)
|
||
{
|
||
QWidget::contextMenuEvent(event);
|
||
if(!m_pModel)
|
||
{
|
||
return;
|
||
}
|
||
if(event->pos().x() < ui->alarmView->pos().x())
|
||
{
|
||
return;
|
||
}
|
||
QRect headerRect = ui->alarmView->horizontalHeader()->rect();
|
||
headerRect.moveTopLeft(ui->alarmView->mapTo(this, QPoint()));
|
||
if(headerRect.contains(event->pos()))
|
||
{
|
||
QMenu columnMenu(this);
|
||
|
||
for(int nColumnIndex(0); nColumnIndex < m_pModel->columnCount()-1; nColumnIndex++)
|
||
{
|
||
QAction * action = columnMenu.addAction(m_pModel->headerData(nColumnIndex, Qt::Horizontal, Qt::DisplayRole).toString());
|
||
action->setCheckable(true);
|
||
action->setChecked(!ui->alarmView->isColumnHidden(nColumnIndex));
|
||
connect(action, &QAction::triggered, [=](){
|
||
ui->alarmView->setColumnHidden(nColumnIndex, !action->isChecked());
|
||
ui->aiAlarmTreeView->setColumnHidden(nColumnIndex, !action->isChecked());
|
||
QSettings columFlags("IOT_HMI", "alarm config");
|
||
columFlags.setValue(QString("alarm/colum_%1").arg(nColumnIndex), !action->isChecked());
|
||
});
|
||
}
|
||
columnMenu.exec(QCursor::pos());
|
||
}
|
||
else
|
||
{
|
||
QModelIndex index = ui->alarmView->indexAt(ui->alarmView->mapFromGlobal(event->globalPos() - QPoint(0, headerRect.height())));
|
||
if(!index.isValid())
|
||
{
|
||
return;
|
||
}
|
||
AlarmMsgPtr alm = m_pModel->getAlarmInfo(index);
|
||
ui->alarmView->clearSelection();
|
||
ui->alarmView->selectRow(index.row());
|
||
QMenu menu(this);
|
||
QAction * selectAction = menu.addAction(tr("全选"));
|
||
connect(selectAction, &QAction::triggered, [=](){ui->alarmView->selectAll();});
|
||
|
||
QAction * InhibitAction = menu.addAction(tr("禁止告警"));
|
||
connect(InhibitAction, &QAction::triggered, [=](){
|
||
bool isContains = false;
|
||
foreach (AlarmMsgPtr alarm, m_listInhibitAlarm)
|
||
{
|
||
if(alarm->key_id_tag == alm->key_id_tag)
|
||
{
|
||
isContains = true;
|
||
break;
|
||
}
|
||
}
|
||
if(isContains)
|
||
{
|
||
QMessageBox::warning(this, tr("警告"), tr("当前测点告警已禁止,无需重复禁止!"), QMessageBox::Ok);
|
||
}
|
||
else
|
||
{
|
||
m_listInhibitAlarm.append(alm);
|
||
CAlarmMsgManage::instance()->addInhibitTag(alm->key_id_tag);
|
||
}
|
||
});
|
||
menu.exec(QCursor::pos());
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::contextMenuStack1Event(QContextMenuEvent *event)
|
||
{
|
||
QWidget::contextMenuEvent(event);
|
||
if(!m_treeModel)
|
||
{
|
||
return;
|
||
}
|
||
if(event->pos().x() < ui->aiAlarmTreeView->pos().x())
|
||
{
|
||
return;
|
||
}
|
||
QRect headerRect = ui->aiAlarmTreeView->header()->rect();
|
||
headerRect.moveTopLeft(ui->aiAlarmTreeView->mapTo(this, QPoint()));
|
||
if(headerRect.contains(event->pos()))
|
||
{
|
||
QMenu columnMenu(this);
|
||
|
||
for(int nColumnIndex(0); nColumnIndex < m_treeModel->columnCount()-1; nColumnIndex++)
|
||
{
|
||
QAction * action = columnMenu.addAction(m_treeModel->headerData(nColumnIndex, Qt::Horizontal, Qt::DisplayRole).toString());
|
||
action->setCheckable(true);
|
||
action->setChecked(!ui->aiAlarmTreeView->isColumnHidden(nColumnIndex));
|
||
connect(action, &QAction::triggered, [=](){
|
||
ui->alarmView->setColumnHidden(nColumnIndex, !action->isChecked());
|
||
ui->aiAlarmTreeView->setColumnHidden(nColumnIndex, !action->isChecked());
|
||
QSettings columFlags("IOT_HMI", "alarm config");
|
||
columFlags.setValue(QString("alarm/colum_%1").arg(nColumnIndex), !action->isChecked());
|
||
});
|
||
}
|
||
columnMenu.exec(QCursor::pos());
|
||
}else
|
||
{
|
||
QMenu menu(this);
|
||
QModelIndex index_ = ui->aiAlarmTreeView->indexAt(ui->aiAlarmTreeView->mapFromGlobal(event->globalPos() - QPoint(0, headerRect.height())));
|
||
if(!index_.isValid())
|
||
{
|
||
return;
|
||
}
|
||
QModelIndex index = ui->aiAlarmTreeView->currentIndex();
|
||
if(!index.isValid())
|
||
{
|
||
return ;
|
||
}
|
||
QModelIndexList indexList = ui->aiAlarmTreeView->selectionModel()->selectedRows(0);
|
||
QModelIndexList indexLists = ui->aiAlarmTreeView->selectionModel()->selectedIndexes();
|
||
QList<AiAlarmMsgPtr> aimsgList;
|
||
QList<AlarmMsgPtr> msgList;
|
||
|
||
foreach (QModelIndex modelIndex, indexList)
|
||
{
|
||
if(!modelIndex.isValid())
|
||
{
|
||
continue;
|
||
}
|
||
CAiAlarmTreeItem *item = static_cast<CAiAlarmTreeItem*>(modelIndex.internalPointer());
|
||
if(item->isAi())
|
||
{
|
||
AiAlarmMsgPtr ptr = NULL;
|
||
if(item->getAiPtr(ptr))
|
||
{
|
||
aimsgList.append(ptr);
|
||
}
|
||
}else
|
||
{
|
||
AlarmMsgPtr ptr = NULL;
|
||
if(item->getPtr(ptr))
|
||
{
|
||
msgList.append(ptr);
|
||
}
|
||
}
|
||
}
|
||
//判断右键位置是否在选中区
|
||
if(indexLists.contains(index))
|
||
{
|
||
QAction * mergeAction = menu.addAction(tr("合并"));
|
||
connect(mergeAction,&QAction::triggered,[=](){
|
||
QMap<int, iot_idl::SIntelliAlmMerge *> pkgMap;
|
||
QList<AlarmMsgPtr> listPtr;
|
||
listPtr.clear();
|
||
int permSkip = -1;
|
||
if(aimsgList.size() > 0)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含智能告警,无法合并!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
|
||
for(int alarmIndex(0);alarmIndex < msgList.size();alarmIndex++)
|
||
{
|
||
if(msgList.at(alarmIndex) != NULL)
|
||
{
|
||
//判断此原始告警是否已经被聚类
|
||
if(CAlarmMsgManage::instance()->isBelongAi(msgList.at(alarmIndex)->uuid_base64))
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含已经聚类的原始告警,无法合并!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
//判断权限
|
||
if(!m_aiOptPerm)
|
||
{
|
||
if(1 != permSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("当前用户无此条原始告警合并权限!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
permSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
permSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
}else
|
||
{
|
||
listPtr.append(msgList.at(alarmIndex));
|
||
}
|
||
}
|
||
}
|
||
//过滤后等于0直接返回
|
||
if(listPtr.size() <= 0)
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return ;
|
||
}
|
||
for(int x(0);x<listPtr.size();x++)
|
||
{
|
||
int32 domain_id = listPtr.at(x)->domain_id;
|
||
QMap<int, iot_idl::SIntelliAlmMerge *>::iterator it = pkgMap.find(domain_id);
|
||
if( it == pkgMap.end())
|
||
{
|
||
iot_idl::SIntelliAlmMerge *pkg =new iot_idl::SIntelliAlmMerge();
|
||
pkg->set_domain_id(domain_id);
|
||
pkgMap[domain_id] = pkg;
|
||
}
|
||
pkgMap.value(domain_id)->add_raw_alm_uuid(listPtr.at(x)->uuid_base64.toStdString());
|
||
}
|
||
if(pkgMap.size() != 1)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含不同域的原始告警,无法合并!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return ;
|
||
}
|
||
foreach (iot_idl::SIntelliAlmMerge * pkg, pkgMap)
|
||
{
|
||
CAiAlarmDataCollect::instance()->requestMergeAlm(*pkg);
|
||
}
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
ui->aiAlarmTreeView->setFocus();
|
||
});
|
||
QAction * seprAction = menu.addAction(tr("分离"));
|
||
connect(seprAction,&QAction::triggered,[=](){
|
||
if(aimsgList.size() != 0)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含智能告警,无法分离!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
if(msgList.size() <= 0)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("无原始告警,无法分离!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
QString aiuuid = "";
|
||
if(!CAlarmMsgManage::instance()->getAiuuid(msgList.at(0)->uuid_base64,aiuuid))
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含未聚类的原始告警,无法分离!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
//权限过滤
|
||
if(!m_aiOptPerm)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("无此条智能告警的编辑权限!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
//遍历所有原始告警
|
||
for(int index(1);index<msgList.size();index++)
|
||
{
|
||
QString uuid = "";
|
||
if(!CAlarmMsgManage::instance()->getAiuuid(msgList.at(index)->uuid_base64,uuid))
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含未聚类的原始告警,无法分离!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
if(uuid != aiuuid)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含不同智能告警下的原始告警,无法分离!"));
|
||
QPushButton *skip = msgBox->addButton(tr("确定"), QMessageBox::ActionRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
return ;
|
||
}
|
||
}
|
||
//拼包
|
||
int domain_id = msgList.at(0)->domain_id;
|
||
iot_idl::SIntelliAlmSepr *pkg = new iot_idl::SIntelliAlmSepr();
|
||
pkg->set_domain_id(domain_id);
|
||
for(int index(0);index<msgList.size();index++)
|
||
{
|
||
pkg->add_raw_alm_uuid(msgList.at(index)->uuid_base64.toStdString());
|
||
}
|
||
//发送
|
||
CAiAlarmDataCollect::instance()->requestSeprAlm(*pkg);
|
||
pkg = NULL;
|
||
delete pkg;
|
||
});
|
||
}else
|
||
{
|
||
ui->aiAlarmTreeView->clearSelection();
|
||
ui->aiAlarmTreeView->setCurrentIndex(index);
|
||
}
|
||
QAction * selectAction = menu.addAction(tr("全选"));
|
||
connect(selectAction,&QAction::triggered,[=](){ui->aiAlarmTreeView->selectAll();});
|
||
QAction * cancleAction = menu.addAction(tr("全不选"));
|
||
connect(cancleAction,&QAction::triggered,[=](){ui->aiAlarmTreeView->clearSelection();});
|
||
|
||
menu.exec(QCursor::pos());
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::loadDeviceGroupFilterWidget()
|
||
{
|
||
if(!m_pModel)
|
||
{
|
||
return;
|
||
}
|
||
QMap< int, QVector< QPair< QString, QString > > > locationInfos;
|
||
QMap<int, QString> locationMap = m_pModel->locationDescriptionMap();
|
||
iot_dbms::CDbApi *m_pReadDb = new iot_dbms::CDbApi(DB_CONN_MODEL_READ);
|
||
if(m_pReadDb->open())
|
||
{
|
||
QMap<int, QString>::const_iterator iter = locationMap.constBegin();
|
||
while (iter != locationMap.constEnd())
|
||
{
|
||
QVector< QPair< QString, QString > > dev;
|
||
|
||
QSqlQuery query;
|
||
QString sqlSequenceQuery = QString("select tag_name, description from dev_group where location_id = %1;").arg(iter.key());
|
||
if(false == m_pReadDb->execute(sqlSequenceQuery, query))
|
||
{
|
||
LOGINFO("load device info error, dbInterface execute failed!");
|
||
}
|
||
|
||
while(query.next())
|
||
{
|
||
dev.append(qMakePair<QString, QString>(query.value(0).toString(), query.value(1).toString()));
|
||
}
|
||
locationInfos.insert(iter.key(), dev);
|
||
iter++;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
LOGINFO("load deviceGroup info error, database open failed!");
|
||
}
|
||
m_pReadDb->close();
|
||
delete m_pReadDb;
|
||
m_pReadDb = NULL;
|
||
m_pDeviceModel->setupModelData(locationInfos,locationMap);
|
||
updateDeviceGroupHiddenState();
|
||
}
|
||
|
||
void CAlarmForm::updateDeviceGroupHiddenState()
|
||
{
|
||
QHash<QString, int> listDeviceStatisticalInfo = CAlarmMsgManage::instance()->getDeviceStatisticalInfo();
|
||
for(int nTopLevelRow(0); nTopLevelRow < m_pDeviceModel->rowCount(); nTopLevelRow++)
|
||
{
|
||
QModelIndex topLevelIndex = m_pDeviceModel->index(nTopLevelRow, 0);
|
||
for(int nChildRow(0); nChildRow < m_pDeviceModel->rowCount(topLevelIndex); nChildRow++)
|
||
{
|
||
CAlarmDeviceTreeItem *item = static_cast<CAlarmDeviceTreeItem*>(m_pDeviceModel->index(nChildRow, 0, topLevelIndex).internalPointer());
|
||
ui->deviceView->setRowHidden(nChildRow, topLevelIndex, !listDeviceStatisticalInfo.value(item->data(Qt::UserRole).toString(), 0));
|
||
}
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::print0(const QString &fileName)
|
||
{
|
||
if(!fileName.isEmpty())
|
||
{
|
||
// QVector<bool> columnHidden;
|
||
// QVector<double> columnWidth;
|
||
// QTableView view(ui->alarmView);
|
||
// view.setModel(m_pModel);
|
||
// for(int nIndex(0); nIndex < m_pModel->columnCount(); nIndex++)
|
||
// {
|
||
// if(ui->alarmView->isColumnHidden(nIndex))
|
||
// {
|
||
// columnHidden.append(true);
|
||
// }else
|
||
// {
|
||
// columnHidden.append(false);
|
||
// }
|
||
// columnWidth.append(ui->alarmView->columnWidth(nIndex));
|
||
// }
|
||
emit printExcelAlm(m_pModel,fileName);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::print1(const QString &fileName)
|
||
{
|
||
if(!fileName.isEmpty())
|
||
{
|
||
// QVector<bool> columnHidden;
|
||
// QVector<double> columnWidth;
|
||
// for(int nIndex(0); nIndex < m_treeModel->columnCount(); nIndex++)
|
||
// {
|
||
// if(ui->aiAlarmTreeView->isColumnHidden(nIndex))
|
||
// {
|
||
// columnHidden.append(true);
|
||
// }else
|
||
// {
|
||
// columnHidden.append(false);
|
||
// }
|
||
// columnWidth.append(ui->aiAlarmTreeView->columnWidth(nIndex));
|
||
// }
|
||
emit printExcel(m_treeModel,fileName);
|
||
}
|
||
}
|
||
|
||
void CAlarmForm::removeAlarm0()
|
||
{
|
||
QModelIndexList modelIndexList = ui->alarmView->selectionModel()->selectedRows(0);
|
||
if(modelIndexList.isEmpty())
|
||
{
|
||
QMessageBox::warning(this, tr("提示"), tr("当前未选中任何项!"), QMessageBox::Ok);
|
||
return;
|
||
}
|
||
QList<AlarmMsgPtr> listInfo = m_pModel->getListShowAlarmInfo();
|
||
//声明告警删除package
|
||
QMap<int, iot_idl::SAlmCltDelAlm *> pkgMap; //Domain-DelPkg;
|
||
int permSkip = -1; //< 不具备确认权限时是否跳过: 0-单步跳过、1-全部跳过
|
||
int unConfirmSkip = -1; //< 未确认告警是否跳过: 0-单步跳过、1-全部跳过
|
||
foreach (QModelIndex index, modelIndexList)
|
||
{
|
||
AlarmMsgPtr info = listInfo.at(index.row());
|
||
//< 权限过滤
|
||
|
||
if(!m_listLocationId.contains(info->location_id) || (!m_listRegionId.contains(info->region_id) && info->region_id != -1))
|
||
{
|
||
if(1 != permSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("当前用户不具备该告警删除操作权限!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
permSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
permSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
//删除条件
|
||
if(info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN)
|
||
{
|
||
if(1 != unConfirmSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含未确认告警!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
unConfirmSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
unConfirmSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
//构建告警删除package
|
||
QMap<int, iot_idl::SAlmCltDelAlm *>::iterator it = pkgMap.find(info->domain_id);
|
||
if(it == pkgMap.end())
|
||
{
|
||
iot_idl::SAlmCltDelAlm * pkg = new iot_idl::SAlmCltDelAlm();
|
||
pkg->set_domain_id(info->domain_id);
|
||
pkgMap[info->domain_id] = pkg;
|
||
LOGINFO("Bulid Alarm Remove MSG: %s", info->key_id_tag.toStdString().c_str());
|
||
}
|
||
pkgMap.value(info->domain_id)->add_uuid_base64(info->uuid_base64.toStdString());
|
||
}
|
||
|
||
//请求删除
|
||
foreach (iot_idl::SAlmCltDelAlm * pkg, pkgMap)
|
||
{
|
||
if(CAlarmDataCollect::instance()->requestDelAlm(*pkg)!= true)
|
||
{
|
||
LOGDEBUG("请求删除原始告警失败!");
|
||
}
|
||
}
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
ui->alarmView->setFocus();
|
||
}
|
||
|
||
void CAlarmForm::removeAlarm1()
|
||
{
|
||
QModelIndexList modelIndexList = ui->aiAlarmTreeView->selectionModel()->selectedRows(0);
|
||
if(modelIndexList.isEmpty())
|
||
{
|
||
QMessageBox::warning(this, tr("提示"), tr("当前未选中任何项!"), QMessageBox::Ok);
|
||
return;
|
||
}
|
||
QList<AiAlarmMsgPtr> aimsgList; //选中的智能告警
|
||
QList<AlarmMsgPtr> msgList; //选中的原始告警
|
||
//声明智能告警删除package
|
||
QMap<int, iot_idl::SIntelliAlmDel *> aipkgMap; //Domain-DelPkg; ai
|
||
QMap<int, iot_idl::SAlmCltDelAlm *> pkgMap; //Domain-DelPkg; alarm
|
||
int permSkip = -1; //< 不具备确认权限时是否跳过: 0-单步跳过、1-全部跳过
|
||
int unConfirmSkip = -1; //< 未确认告警是否跳过: 0-单步跳过、1-全部跳过
|
||
foreach (QModelIndex index, modelIndexList)
|
||
{
|
||
if(!index.isValid())
|
||
{
|
||
continue;
|
||
}
|
||
CAiAlarmTreeItem *item = static_cast<CAiAlarmTreeItem*>(index.internalPointer());
|
||
if(item->isAi())
|
||
{
|
||
AiAlarmMsgPtr ptr = NULL;
|
||
if(item->getAiPtr(ptr))
|
||
{
|
||
aimsgList.append(ptr);
|
||
}
|
||
}else
|
||
{
|
||
//忽略选中的原始告警
|
||
if(item->parent() == m_treeModel->getItem())
|
||
{
|
||
AlarmMsgPtr ptr = NULL;
|
||
if(item->getPtr(ptr))
|
||
{
|
||
msgList.append(ptr);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if(aimsgList.size() <= 0 && msgList.size() <= 0)
|
||
{
|
||
QMessageBox::warning(this, tr("提示"), tr("当前未选中任何智能告警和未聚类的原始告警!"), QMessageBox::Ok);
|
||
return;
|
||
}
|
||
//处理原始告警
|
||
for(int alarm(0);alarm<msgList.size();alarm++)
|
||
{
|
||
AlarmMsgPtr info = msgList.at(alarm);
|
||
if(!m_listLocationId.contains(info->location_id) || (!m_listRegionId.contains(info->region_id) && info->region_id != -1))
|
||
{
|
||
if(1 != permSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("当前用户不具备该告警删除操作权限!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
permSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
permSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
//删除条件
|
||
if(info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN)
|
||
{
|
||
if(1 != unConfirmSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含未确认告警!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
unConfirmSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
unConfirmSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
//构建告警删除package
|
||
QMap<int, iot_idl::SAlmCltDelAlm *>::iterator it = pkgMap.find(info->domain_id);
|
||
if(it == pkgMap.end())
|
||
{
|
||
iot_idl::SAlmCltDelAlm * pkg = new iot_idl::SAlmCltDelAlm();
|
||
pkg->set_domain_id(info->domain_id);
|
||
pkgMap[info->domain_id] = pkg;
|
||
LOGINFO("Bulid Alarm Remove MSG: %s", info->key_id_tag.toStdString().c_str());
|
||
}
|
||
pkgMap.value(info->domain_id)->add_uuid_base64(info->uuid_base64.toStdString());
|
||
}
|
||
//处理智能告警
|
||
for(int aialarm(0);aialarm<aimsgList.size();aialarm++)
|
||
{
|
||
if(!m_aiOptPerm)
|
||
{
|
||
if(1 != permSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("当前用户不具备该告警删除操作权限!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
permSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
permSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(aipkgMap);
|
||
aipkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
if(CAlarmMsgManage::instance()->ifhaveNotConfirmAlmByuuid(aimsgList.at(aialarm)->uuid_base64))
|
||
{
|
||
if(1 != unConfirmSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("包含未确认原始告警告警!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
unConfirmSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
unConfirmSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(aipkgMap);
|
||
aipkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
int domain_id = aimsgList.at(aialarm)->domain_id;
|
||
QString aiuuid = aimsgList.at(aialarm)->uuid_base64;
|
||
QMap<int, iot_idl::SIntelliAlmDel *>::iterator it = aipkgMap.find(domain_id);
|
||
if(it == aipkgMap.end())
|
||
{
|
||
iot_idl::SIntelliAlmDel * pkg = new iot_idl::SIntelliAlmDel();
|
||
pkg->set_domain_id(domain_id);
|
||
aipkgMap[domain_id] = pkg;
|
||
}
|
||
aipkgMap.value(domain_id)->add_uuid_base64(aiuuid.toStdString());
|
||
}
|
||
//请求删除
|
||
foreach (iot_idl::SAlmCltDelAlm * pkg, pkgMap)
|
||
{
|
||
if(CAlarmDataCollect::instance()->requestDelAlm(*pkg)!= true)
|
||
{
|
||
LOGDEBUG("请求删除原始告警失败!");
|
||
}
|
||
}
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
//请求删除
|
||
foreach (iot_idl::SIntelliAlmDel * pkg, aipkgMap)
|
||
{
|
||
CAiAlarmDataCollect::instance()->requestDelAlm(*pkg);
|
||
}
|
||
qDeleteAll(aipkgMap);
|
||
aipkgMap.clear();
|
||
ui->aiAlarmTreeView->setFocus();
|
||
}
|
||
|
||
void CAlarmForm::confirmAlarm0()
|
||
{
|
||
QModelIndexList modelIndexList = ui->alarmView->selectionModel()->selectedRows(0);
|
||
if(modelIndexList.isEmpty())
|
||
{
|
||
QMessageBox::warning(this, tr("提示"), tr("当前未选中任何项!"), QMessageBox::Ok);
|
||
return;
|
||
}
|
||
QList<AlarmMsgPtr> listInfo = m_pModel->getListShowAlarmInfo();
|
||
if(listInfo.isEmpty())
|
||
{
|
||
return;
|
||
}
|
||
|
||
//构建告警确认package
|
||
QMap<QString, iot_idl::SAlmCltCfmAlm *> pkgMap; //Domain-DelPkg;
|
||
|
||
int permSkip = -1; //< 不具备确认权限时是否跳过: 0-单步跳过、1-全部跳过
|
||
foreach (QModelIndex index, modelIndexList)
|
||
{
|
||
AlarmMsgPtr info = listInfo.at(index.row());
|
||
|
||
//< 权限过滤
|
||
if(!m_listLocationId.contains(info->location_id) || (!m_listRegionId.contains(info->region_id) && info->region_id != -1))
|
||
{
|
||
if(1 != permSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("当前用户不具备该告警确认操作权限!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
permSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
permSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
//告警状态
|
||
if(E_ALS_ALARM == info->logic_state || E_ALS_RETURN == info->logic_state)
|
||
{
|
||
QString key = QString::number(info->domain_id);
|
||
QMap<QString, iot_idl::SAlmCltCfmAlm *>::iterator it = pkgMap.find(key);
|
||
if(it == pkgMap.end())
|
||
{
|
||
iot_idl::SAlmCltCfmAlm * pkg = new iot_idl::SAlmCltCfmAlm();
|
||
pkg->set_node_name(m_nodeName);
|
||
pkg->set_user_id(m_userId);
|
||
pkg->set_confirm_time(QDateTime::currentMSecsSinceEpoch());
|
||
pkg->set_domain_id(info->domain_id);
|
||
pkg->set_app_id(info->app_id);
|
||
pkg->set_alm_type(info->alm_type);
|
||
pkgMap[key] = pkg;
|
||
LOGINFO("Bulid Alarm Confirm MSG: %s", key.toStdString().c_str());
|
||
}
|
||
|
||
pkgMap.value(key)->add_key_id_tag(info->key_id_tag.toStdString());
|
||
pkgMap.value(key)->add_time_stamp(info->time_stamp);
|
||
pkgMap.value(key)->add_uuid_base64(info->uuid_base64.toStdString());
|
||
}
|
||
}
|
||
|
||
//请求确认
|
||
foreach (iot_idl::SAlmCltCfmAlm * pkg, pkgMap)
|
||
{
|
||
CAlarmDataCollect::instance()->requestCfmAlm(*pkg);
|
||
}
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
ui->alarmView->setFocus();
|
||
}
|
||
|
||
void CAlarmForm::confirmAlarm1()
|
||
{
|
||
QModelIndexList modelIndexList = ui->aiAlarmTreeView->selectionModel()->selectedRows(0);
|
||
if(modelIndexList.isEmpty())
|
||
{
|
||
QMessageBox::warning(this, tr("提示"), tr("当前未选中任何项!"), QMessageBox::Ok);
|
||
return;
|
||
}
|
||
QList<AiAlarmMsgPtr> aimsgList; //选中的智能告警
|
||
QList<AlarmMsgPtr> msgList; //选中的原始告警
|
||
QList<QString> uuidList;
|
||
//构建告警确认package
|
||
QMap<QString, iot_idl::SAlmCltCfmAlm *> pkgMap; //Domain-DelPkg;
|
||
int permSkip = -1; //< 不具备确认权限时是否跳过: 0-单步跳过、1-全部跳过
|
||
foreach (QModelIndex index, modelIndexList)
|
||
{
|
||
if(!index.isValid())
|
||
{
|
||
continue;
|
||
}
|
||
CAiAlarmTreeItem *item = static_cast<CAiAlarmTreeItem*>(index.internalPointer());
|
||
if(item->isAi())
|
||
{
|
||
AiAlarmMsgPtr ptr = NULL;
|
||
if(item->getAiPtr(ptr))
|
||
{
|
||
aimsgList.append(ptr);
|
||
QList<AlarmMsgPtr> listPtr = item->getChildAlarmPtr();
|
||
for(int x(0);x<listPtr.size();x++)
|
||
{
|
||
if(!uuidList.contains(listPtr.at(x)->uuid_base64))
|
||
{
|
||
msgList.append(listPtr.at(x));
|
||
uuidList.append(listPtr.at(x)->uuid_base64);
|
||
}
|
||
}
|
||
}
|
||
}else
|
||
{
|
||
AlarmMsgPtr ptr = NULL;
|
||
if(item->getPtr(ptr))
|
||
{
|
||
msgList.append(ptr);
|
||
uuidList.append(ptr->uuid_base64);
|
||
}
|
||
}
|
||
}
|
||
for(int alarmNum(0);alarmNum<msgList.size();alarmNum++)
|
||
{
|
||
if(!m_listLocationId.contains(msgList.at(alarmNum)->location_id) || (!m_listRegionId.contains(msgList.at(alarmNum)->region_id) && msgList.at(alarmNum)->region_id != -1))
|
||
{
|
||
if(1 != permSkip)
|
||
{
|
||
QMessageBox *msgBox = new QMessageBox(this);
|
||
msgBox->setObjectName("msgbox");
|
||
msgBox->setText(tr("当前用户不具备该告警确认操作权限!"));
|
||
msgBox->setInformativeText(tr("是否跳过该项?"));
|
||
QPushButton *skip = msgBox->addButton(tr("跳过"), QMessageBox::ActionRole);
|
||
QPushButton *skipAll = msgBox->addButton(tr("全部跳过"), QMessageBox::AcceptRole);
|
||
msgBox->addButton(tr("取消"), QMessageBox::RejectRole);
|
||
msgBox->setDefaultButton(skip);
|
||
msgBox->exec();
|
||
if (msgBox->clickedButton() == skip)
|
||
{
|
||
permSkip = 0;
|
||
continue;
|
||
}
|
||
else if (msgBox->clickedButton() == skipAll)
|
||
{
|
||
permSkip = 1;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
if(E_ALS_ALARM == msgList.at(alarmNum)->logic_state || E_ALS_RETURN == msgList.at(alarmNum)->logic_state ||
|
||
E_ALS_ALARM_DEL == msgList.at(alarmNum)->logic_state || E_ALS_RETURN_DEL == msgList.at(alarmNum)->logic_state)
|
||
{
|
||
QString key = QString(msgList.at(alarmNum)->domain_id);
|
||
QMap<QString, iot_idl::SAlmCltCfmAlm *>::iterator it= pkgMap.find(key);
|
||
if(it == pkgMap.end())
|
||
{
|
||
iot_idl::SAlmCltCfmAlm * pkg = new iot_idl::SAlmCltCfmAlm();
|
||
pkg->set_node_name(m_nodeName);
|
||
pkg->set_user_id(m_userId);
|
||
pkg->set_confirm_time(QDateTime::currentMSecsSinceEpoch());
|
||
pkg->set_domain_id(msgList.at(alarmNum)->domain_id);
|
||
pkg->set_app_id(msgList.at(alarmNum)->app_id);
|
||
pkg->set_alm_type(msgList.at(alarmNum)->alm_type);
|
||
pkgMap[key] = pkg;
|
||
}
|
||
pkgMap.value(key)->add_key_id_tag(msgList.at(alarmNum)->key_id_tag.toStdString());
|
||
pkgMap.value(key)->add_time_stamp(msgList.at(alarmNum)->time_stamp);
|
||
pkgMap.value(key)->add_uuid_base64(msgList.at(alarmNum)->uuid_base64.toStdString());
|
||
}
|
||
}
|
||
foreach (iot_idl::SAlmCltCfmAlm * pkg, pkgMap)
|
||
{
|
||
CAlarmDataCollect::instance()->requestCfmAlm(*pkg);
|
||
}
|
||
qDeleteAll(pkgMap);
|
||
pkgMap.clear();
|
||
ui->aiAlarmTreeView->setFocus();
|
||
}
|