diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterWindowRT.h b/CounterRealTime/CounterWindowRT.h index 9ed7190..86d7e4a 100644 --- a/CounterRealTime/CounterWindowRT.h +++ b/CounterRealTime/CounterWindowRT.h @@ -48,7 +48,6 @@ QVector channelValueList; // 通道测量值的QLabel集合 HttpRequestController * httpReq; - QKafkaConsumer * kafkaConsumer; int initHttpToken(); @@ -57,6 +56,9 @@ void initDevAndChannelForm(int count); void updateChannelDataForm(QJsonArray messageArray); + void updateDeviceAlarm(QJsonArray alarmList); + + CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId); private slots: void updateDateAndTime(); @@ -71,5 +73,8 @@ void drawCounterDataOnPage(QJsonArray messageArray); void onKafkaMessageReceived(QJsonObject message); + +// void queryClockAlarmOnTime(); +// void onAlarmChanged(); }; #endif // COUNTERWINDOWRT_H diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterWindowRT.h b/CounterRealTime/CounterWindowRT.h index 9ed7190..86d7e4a 100644 --- a/CounterRealTime/CounterWindowRT.h +++ b/CounterRealTime/CounterWindowRT.h @@ -48,7 +48,6 @@ QVector channelValueList; // 通道测量值的QLabel集合 HttpRequestController * httpReq; - QKafkaConsumer * kafkaConsumer; int initHttpToken(); @@ -57,6 +56,9 @@ void initDevAndChannelForm(int count); void updateChannelDataForm(QJsonArray messageArray); + void updateDeviceAlarm(QJsonArray alarmList); + + CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId); private slots: void updateDateAndTime(); @@ -71,5 +73,8 @@ void drawCounterDataOnPage(QJsonArray messageArray); void onKafkaMessageReceived(QJsonObject message); + +// void queryClockAlarmOnTime(); +// void onAlarmChanged(); }; #endif // COUNTERWINDOWRT_H diff --git a/CounterRealTime/common/HttpRequestController.cpp b/CounterRealTime/common/HttpRequestController.cpp index c90c8f0..2f8cf16 100644 --- a/CounterRealTime/common/HttpRequestController.cpp +++ b/CounterRealTime/common/HttpRequestController.cpp @@ -205,7 +205,7 @@ return resultObj; } -QJsonObject HttpRequestController::getSysClockAlarmCount() +int HttpRequestController::getSysClockAlarmCount() { QJsonObject resultObj; @@ -226,6 +226,46 @@ if(jsonDocument.isNull() == false) { resultObj = jsonDocument.object(); + if (resultObj.value("code").toInt() != 200) { + return 0; + } + } else + { + return 0; + } + + qDebug() << resultObj; + + return resultObj.value("data").toInt(); +} + +QJsonObject HttpRequestController::getSysClockAlarmList(int limit) +{ + QJsonObject resultObj; + + // 获取设备列表的接口地址 + QUrl url = baseUrl + "/alarm/recordsPage"; + + QNetworkRequest request; + request.setRawHeader("Content-type", "application/json"); + request.setRawHeader("token", token.toLocal8Bit()); + request.setRawHeader("system", SettingConfig::getInstance().SYSTEM.toLocal8Bit()); + + QUrlQuery query; + query.addQueryItem("offset", "1"); + query.addQueryItem("limit", QString::number(limit)); + url.setQuery(query); + + request.setUrl(url); + + qDebug() << url; + + QNetworkReply * reply = httpUtil->sendGetRequest(request); + const QByteArray reply_data = reply->readAll(); + QJsonDocument jsonDocument = QJsonDocument::fromJson(reply_data); + if(jsonDocument.isNull() == false) + { + resultObj = jsonDocument.object(); } else { resultObj.insert("code", -1); diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterWindowRT.h b/CounterRealTime/CounterWindowRT.h index 9ed7190..86d7e4a 100644 --- a/CounterRealTime/CounterWindowRT.h +++ b/CounterRealTime/CounterWindowRT.h @@ -48,7 +48,6 @@ QVector channelValueList; // 通道测量值的QLabel集合 HttpRequestController * httpReq; - QKafkaConsumer * kafkaConsumer; int initHttpToken(); @@ -57,6 +56,9 @@ void initDevAndChannelForm(int count); void updateChannelDataForm(QJsonArray messageArray); + void updateDeviceAlarm(QJsonArray alarmList); + + CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId); private slots: void updateDateAndTime(); @@ -71,5 +73,8 @@ void drawCounterDataOnPage(QJsonArray messageArray); void onKafkaMessageReceived(QJsonObject message); + +// void queryClockAlarmOnTime(); +// void onAlarmChanged(); }; #endif // COUNTERWINDOWRT_H diff --git a/CounterRealTime/common/HttpRequestController.cpp b/CounterRealTime/common/HttpRequestController.cpp index c90c8f0..2f8cf16 100644 --- a/CounterRealTime/common/HttpRequestController.cpp +++ b/CounterRealTime/common/HttpRequestController.cpp @@ -205,7 +205,7 @@ return resultObj; } -QJsonObject HttpRequestController::getSysClockAlarmCount() +int HttpRequestController::getSysClockAlarmCount() { QJsonObject resultObj; @@ -226,6 +226,46 @@ if(jsonDocument.isNull() == false) { resultObj = jsonDocument.object(); + if (resultObj.value("code").toInt() != 200) { + return 0; + } + } else + { + return 0; + } + + qDebug() << resultObj; + + return resultObj.value("data").toInt(); +} + +QJsonObject HttpRequestController::getSysClockAlarmList(int limit) +{ + QJsonObject resultObj; + + // 获取设备列表的接口地址 + QUrl url = baseUrl + "/alarm/recordsPage"; + + QNetworkRequest request; + request.setRawHeader("Content-type", "application/json"); + request.setRawHeader("token", token.toLocal8Bit()); + request.setRawHeader("system", SettingConfig::getInstance().SYSTEM.toLocal8Bit()); + + QUrlQuery query; + query.addQueryItem("offset", "1"); + query.addQueryItem("limit", QString::number(limit)); + url.setQuery(query); + + request.setUrl(url); + + qDebug() << url; + + QNetworkReply * reply = httpUtil->sendGetRequest(request); + const QByteArray reply_data = reply->readAll(); + QJsonDocument jsonDocument = QJsonDocument::fromJson(reply_data); + if(jsonDocument.isNull() == false) + { + resultObj = jsonDocument.object(); } else { resultObj.insert("code", -1); diff --git a/CounterRealTime/common/HttpRequestController.h b/CounterRealTime/common/HttpRequestController.h index db9d36a..a37122b 100644 --- a/CounterRealTime/common/HttpRequestController.h +++ b/CounterRealTime/common/HttpRequestController.h @@ -25,7 +25,8 @@ QJsonObject updateChannelInfo(QJsonArray channelInfos); - QJsonObject getSysClockAlarmCount(); + int getSysClockAlarmCount(); + QJsonObject getSysClockAlarmList(int limit); private: HttpRequestUtil * httpUtil; diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterWindowRT.h b/CounterRealTime/CounterWindowRT.h index 9ed7190..86d7e4a 100644 --- a/CounterRealTime/CounterWindowRT.h +++ b/CounterRealTime/CounterWindowRT.h @@ -48,7 +48,6 @@ QVector channelValueList; // 通道测量值的QLabel集合 HttpRequestController * httpReq; - QKafkaConsumer * kafkaConsumer; int initHttpToken(); @@ -57,6 +56,9 @@ void initDevAndChannelForm(int count); void updateChannelDataForm(QJsonArray messageArray); + void updateDeviceAlarm(QJsonArray alarmList); + + CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId); private slots: void updateDateAndTime(); @@ -71,5 +73,8 @@ void drawCounterDataOnPage(QJsonArray messageArray); void onKafkaMessageReceived(QJsonObject message); + +// void queryClockAlarmOnTime(); +// void onAlarmChanged(); }; #endif // COUNTERWINDOWRT_H diff --git a/CounterRealTime/common/HttpRequestController.cpp b/CounterRealTime/common/HttpRequestController.cpp index c90c8f0..2f8cf16 100644 --- a/CounterRealTime/common/HttpRequestController.cpp +++ b/CounterRealTime/common/HttpRequestController.cpp @@ -205,7 +205,7 @@ return resultObj; } -QJsonObject HttpRequestController::getSysClockAlarmCount() +int HttpRequestController::getSysClockAlarmCount() { QJsonObject resultObj; @@ -226,6 +226,46 @@ if(jsonDocument.isNull() == false) { resultObj = jsonDocument.object(); + if (resultObj.value("code").toInt() != 200) { + return 0; + } + } else + { + return 0; + } + + qDebug() << resultObj; + + return resultObj.value("data").toInt(); +} + +QJsonObject HttpRequestController::getSysClockAlarmList(int limit) +{ + QJsonObject resultObj; + + // 获取设备列表的接口地址 + QUrl url = baseUrl + "/alarm/recordsPage"; + + QNetworkRequest request; + request.setRawHeader("Content-type", "application/json"); + request.setRawHeader("token", token.toLocal8Bit()); + request.setRawHeader("system", SettingConfig::getInstance().SYSTEM.toLocal8Bit()); + + QUrlQuery query; + query.addQueryItem("offset", "1"); + query.addQueryItem("limit", QString::number(limit)); + url.setQuery(query); + + request.setUrl(url); + + qDebug() << url; + + QNetworkReply * reply = httpUtil->sendGetRequest(request); + const QByteArray reply_data = reply->readAll(); + QJsonDocument jsonDocument = QJsonDocument::fromJson(reply_data); + if(jsonDocument.isNull() == false) + { + resultObj = jsonDocument.object(); } else { resultObj.insert("code", -1); diff --git a/CounterRealTime/common/HttpRequestController.h b/CounterRealTime/common/HttpRequestController.h index db9d36a..a37122b 100644 --- a/CounterRealTime/common/HttpRequestController.h +++ b/CounterRealTime/common/HttpRequestController.h @@ -25,7 +25,8 @@ QJsonObject updateChannelInfo(QJsonArray channelInfos); - QJsonObject getSysClockAlarmCount(); + int getSysClockAlarmCount(); + QJsonObject getSysClockAlarmList(int limit); private: HttpRequestUtil * httpUtil; diff --git a/CounterRealTime/common/utils/TimerCounterUtil.h b/CounterRealTime/common/utils/TimerCounterUtil.h index 0f62573..2bdfd2f 100644 --- a/CounterRealTime/common/utils/TimerCounterUtil.h +++ b/CounterRealTime/common/utils/TimerCounterUtil.h @@ -17,7 +17,8 @@ return instance; } - QTimer * clockCounter; + QTimer * clockCounter; // 界面刷新时间定时器 + QTimer * alamrCounter; // 请求报警定时器 private: TimerCounterUtil() diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterWindowRT.h b/CounterRealTime/CounterWindowRT.h index 9ed7190..86d7e4a 100644 --- a/CounterRealTime/CounterWindowRT.h +++ b/CounterRealTime/CounterWindowRT.h @@ -48,7 +48,6 @@ QVector channelValueList; // 通道测量值的QLabel集合 HttpRequestController * httpReq; - QKafkaConsumer * kafkaConsumer; int initHttpToken(); @@ -57,6 +56,9 @@ void initDevAndChannelForm(int count); void updateChannelDataForm(QJsonArray messageArray); + void updateDeviceAlarm(QJsonArray alarmList); + + CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId); private slots: void updateDateAndTime(); @@ -71,5 +73,8 @@ void drawCounterDataOnPage(QJsonArray messageArray); void onKafkaMessageReceived(QJsonObject message); + +// void queryClockAlarmOnTime(); +// void onAlarmChanged(); }; #endif // COUNTERWINDOWRT_H diff --git a/CounterRealTime/common/HttpRequestController.cpp b/CounterRealTime/common/HttpRequestController.cpp index c90c8f0..2f8cf16 100644 --- a/CounterRealTime/common/HttpRequestController.cpp +++ b/CounterRealTime/common/HttpRequestController.cpp @@ -205,7 +205,7 @@ return resultObj; } -QJsonObject HttpRequestController::getSysClockAlarmCount() +int HttpRequestController::getSysClockAlarmCount() { QJsonObject resultObj; @@ -226,6 +226,46 @@ if(jsonDocument.isNull() == false) { resultObj = jsonDocument.object(); + if (resultObj.value("code").toInt() != 200) { + return 0; + } + } else + { + return 0; + } + + qDebug() << resultObj; + + return resultObj.value("data").toInt(); +} + +QJsonObject HttpRequestController::getSysClockAlarmList(int limit) +{ + QJsonObject resultObj; + + // 获取设备列表的接口地址 + QUrl url = baseUrl + "/alarm/recordsPage"; + + QNetworkRequest request; + request.setRawHeader("Content-type", "application/json"); + request.setRawHeader("token", token.toLocal8Bit()); + request.setRawHeader("system", SettingConfig::getInstance().SYSTEM.toLocal8Bit()); + + QUrlQuery query; + query.addQueryItem("offset", "1"); + query.addQueryItem("limit", QString::number(limit)); + url.setQuery(query); + + request.setUrl(url); + + qDebug() << url; + + QNetworkReply * reply = httpUtil->sendGetRequest(request); + const QByteArray reply_data = reply->readAll(); + QJsonDocument jsonDocument = QJsonDocument::fromJson(reply_data); + if(jsonDocument.isNull() == false) + { + resultObj = jsonDocument.object(); } else { resultObj.insert("code", -1); diff --git a/CounterRealTime/common/HttpRequestController.h b/CounterRealTime/common/HttpRequestController.h index db9d36a..a37122b 100644 --- a/CounterRealTime/common/HttpRequestController.h +++ b/CounterRealTime/common/HttpRequestController.h @@ -25,7 +25,8 @@ QJsonObject updateChannelInfo(QJsonArray channelInfos); - QJsonObject getSysClockAlarmCount(); + int getSysClockAlarmCount(); + QJsonObject getSysClockAlarmList(int limit); private: HttpRequestUtil * httpUtil; diff --git a/CounterRealTime/common/utils/TimerCounterUtil.h b/CounterRealTime/common/utils/TimerCounterUtil.h index 0f62573..2bdfd2f 100644 --- a/CounterRealTime/common/utils/TimerCounterUtil.h +++ b/CounterRealTime/common/utils/TimerCounterUtil.h @@ -17,7 +17,8 @@ return instance; } - QTimer * clockCounter; + QTimer * clockCounter; // 界面刷新时间定时器 + QTimer * alamrCounter; // 请求报警定时器 private: TimerCounterUtil() diff --git a/CounterRealTime/conf/config.ini b/CounterRealTime/conf/config.ini index c7ed463..d06d45b 100644 --- a/CounterRealTime/conf/config.ini +++ b/CounterRealTime/conf/config.ini @@ -11,6 +11,7 @@ dataTopic="clock-data" statusTopic="dev-status" msgTopic="clock-message" +alarmTopic="alarm-message" needSasl=1 saslUsername="admin" saslPassword="casicss" diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index 225ec88..da1d4eb 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -49,6 +49,11 @@ } } +int CounterSettingForm::getDisplayGroupFlag() +{ + return flagGroup->checkedId(); +} + void CounterSettingForm::initDefaultSettings() { ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL); diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 9c41362..c008aa3 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -22,6 +22,8 @@ ~CounterSettingForm(); void initCounterSelect(); + int getDisplayGroupFlag(); + private slots: void on_btnSettingClose_clicked(); diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 78a410e..e90c359 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -54,9 +54,25 @@ QTimer::singleShot(100, qApp, SLOT(quit())); } + ((QWidget *) ui->widgetContent->children().at(2))->setProperty("form", "devAlarm"); + channelNameList.at(14)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(14)->setProperty("labType", "channelValueAlarm"); + // 初始化设备和通道 getDeviceList(); + // 查询当前报警记录并显示 + int alarmCount = httpReq->getSysClockAlarmCount(); + if (alarmCount > 0) + { + QJsonObject alarmRecords = httpReq->getSysClockAlarmList(alarmCount); + if (alarmRecords.value("code") == 200) + { + this->updateDeviceAlarm(alarmRecords.value("data").toObject().value("rows").toArray()); + } + } + + // 暂停三秒后打开计数器的串口接收数据 QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { @@ -68,8 +84,6 @@ CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopB.at(i)); devicePtr->initSerialPort(); } - -// httpReq->getSysClockAlarmCount(); } CounterWindowRT::~CounterWindowRT() @@ -81,7 +95,7 @@ { switch (event->key()) { case Qt::Key_Escape: -// QTimer::singleShot(100, qApp, SLOT(quit())); + QTimer::singleShot(100, qApp, SLOT(quit())); default: QWidget::keyPressEvent(event); @@ -359,10 +373,74 @@ // 没有测量值的通道清空 channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); + + channelNameList.at(devIdx * 16 + i)->setProperty("labType", "channelNameAlarm"); + channelValueList.at(devIdx * 16 + i)->setProperty("labType", "channelValueAlarm"); } } } +void CounterWindowRT::updateDeviceAlarm(QJsonArray alarmList) +{ + QVector alarmDev; + QVector alarmChannel; + for (int i = 0; i < alarmList.size(); i++) + { + QJsonObject alarmData = alarmList.at(i).toObject(); + QString deviceId = alarmData.value("deviceId").toString(); + QString channelId = alarmData.value("channelId").toString(); + QString level = alarmData.value("level").toString(); + QString status = alarmData.value("status").toString(); + + if (alarmDev.contains(deviceId) == false) { + alarmDev.append(deviceId); + } +// CounterChannel * + } + + for (int i = 0; i < alarmDev.size(); i++) + { + CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(alarmDev.at(i)); + if (devicePtr != nullptr) + { + if (settingForm->getDisplayGroupFlag() == 1) + { + if (ConstCache::getInstance().deviceIdLoopA.contains(alarmDev.at(i))) + { + ((QWidget *)ui->widgetContent->children().at(devicePtr->getFormColIndex() + 1))->setProperty("form", "devAlarm"); + } + } else if (settingForm->getDisplayGroupFlag() == 0) + { + if (ConstCache::getInstance().deviceIdLoopB.contains(alarmDev.at(i))) + { + qDebug() << "B: " << devicePtr->getFormColIndex() << ui->widgetContent->children().size(); + + } + } + } + } +} + +CounterChannel * CounterWindowRT::getChannelByDevAndId(QString deviceId, QString channelId) +{ + if (deviceId.isEmpty() == true || channelId.isEmpty() == true) + return nullptr; + + for (int i = 1; i <= 16; i++) + { + QString key = QString("%1-%2").arg(deviceId).arg(i); + CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(key); + if (channelPtr != nullptr) { + if (channelPtr->getChannelId() == channelId) + { + return channelPtr; + } + } + } + + return nullptr; +} + void CounterWindowRT::updateDateAndTime() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); diff --git a/CounterRealTime/CounterWindowRT.h b/CounterRealTime/CounterWindowRT.h index 9ed7190..86d7e4a 100644 --- a/CounterRealTime/CounterWindowRT.h +++ b/CounterRealTime/CounterWindowRT.h @@ -48,7 +48,6 @@ QVector channelValueList; // 通道测量值的QLabel集合 HttpRequestController * httpReq; - QKafkaConsumer * kafkaConsumer; int initHttpToken(); @@ -57,6 +56,9 @@ void initDevAndChannelForm(int count); void updateChannelDataForm(QJsonArray messageArray); + void updateDeviceAlarm(QJsonArray alarmList); + + CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId); private slots: void updateDateAndTime(); @@ -71,5 +73,8 @@ void drawCounterDataOnPage(QJsonArray messageArray); void onKafkaMessageReceived(QJsonObject message); + +// void queryClockAlarmOnTime(); +// void onAlarmChanged(); }; #endif // COUNTERWINDOWRT_H diff --git a/CounterRealTime/common/HttpRequestController.cpp b/CounterRealTime/common/HttpRequestController.cpp index c90c8f0..2f8cf16 100644 --- a/CounterRealTime/common/HttpRequestController.cpp +++ b/CounterRealTime/common/HttpRequestController.cpp @@ -205,7 +205,7 @@ return resultObj; } -QJsonObject HttpRequestController::getSysClockAlarmCount() +int HttpRequestController::getSysClockAlarmCount() { QJsonObject resultObj; @@ -226,6 +226,46 @@ if(jsonDocument.isNull() == false) { resultObj = jsonDocument.object(); + if (resultObj.value("code").toInt() != 200) { + return 0; + } + } else + { + return 0; + } + + qDebug() << resultObj; + + return resultObj.value("data").toInt(); +} + +QJsonObject HttpRequestController::getSysClockAlarmList(int limit) +{ + QJsonObject resultObj; + + // 获取设备列表的接口地址 + QUrl url = baseUrl + "/alarm/recordsPage"; + + QNetworkRequest request; + request.setRawHeader("Content-type", "application/json"); + request.setRawHeader("token", token.toLocal8Bit()); + request.setRawHeader("system", SettingConfig::getInstance().SYSTEM.toLocal8Bit()); + + QUrlQuery query; + query.addQueryItem("offset", "1"); + query.addQueryItem("limit", QString::number(limit)); + url.setQuery(query); + + request.setUrl(url); + + qDebug() << url; + + QNetworkReply * reply = httpUtil->sendGetRequest(request); + const QByteArray reply_data = reply->readAll(); + QJsonDocument jsonDocument = QJsonDocument::fromJson(reply_data); + if(jsonDocument.isNull() == false) + { + resultObj = jsonDocument.object(); } else { resultObj.insert("code", -1); diff --git a/CounterRealTime/common/HttpRequestController.h b/CounterRealTime/common/HttpRequestController.h index db9d36a..a37122b 100644 --- a/CounterRealTime/common/HttpRequestController.h +++ b/CounterRealTime/common/HttpRequestController.h @@ -25,7 +25,8 @@ QJsonObject updateChannelInfo(QJsonArray channelInfos); - QJsonObject getSysClockAlarmCount(); + int getSysClockAlarmCount(); + QJsonObject getSysClockAlarmList(int limit); private: HttpRequestUtil * httpUtil; diff --git a/CounterRealTime/common/utils/TimerCounterUtil.h b/CounterRealTime/common/utils/TimerCounterUtil.h index 0f62573..2bdfd2f 100644 --- a/CounterRealTime/common/utils/TimerCounterUtil.h +++ b/CounterRealTime/common/utils/TimerCounterUtil.h @@ -17,7 +17,8 @@ return instance; } - QTimer * clockCounter; + QTimer * clockCounter; // 界面刷新时间定时器 + QTimer * alamrCounter; // 请求报警定时器 private: TimerCounterUtil() diff --git a/CounterRealTime/conf/config.ini b/CounterRealTime/conf/config.ini index c7ed463..d06d45b 100644 --- a/CounterRealTime/conf/config.ini +++ b/CounterRealTime/conf/config.ini @@ -11,6 +11,7 @@ dataTopic="clock-data" statusTopic="dev-status" msgTopic="clock-message" +alarmTopic="alarm-message" needSasl=1 saslUsername="admin" saslPassword="casicss" diff --git a/CounterRealTime/qss/mainClock.css b/CounterRealTime/qss/mainClock.css index 8d5c146..8bf2cbb 100644 --- a/CounterRealTime/qss/mainClock.css +++ b/CounterRealTime/qss/mainClock.css @@ -48,6 +48,7 @@ } QWidget[form="devAlarm"] { border: 3px solid #FF0000; + border-radius: 12px; } QWidget#widgetContent QLabel {