feat:增加报警事件服务的配置文件及信息读取
This commit is contained in:
parent
faa0ad8af4
commit
a37988428c
|
|
@ -211,6 +211,45 @@ install(TARGETS PowerMaster
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 定义配置文件和目标目录
|
||||||
|
set(CONFIG_FILES
|
||||||
|
alarmEventService_config.ini
|
||||||
|
realTimeDataService_config.ini
|
||||||
|
)
|
||||||
|
set(CONFIG_FILE_DIR "${CMAKE_BINARY_DIR}/config")
|
||||||
|
# 确保配置文件目录存在
|
||||||
|
if(NOT EXISTS "${CONFIG_FILE_DIR}")
|
||||||
|
message(STATUS "Creating confiuration directory: ${CONFIG_FILE_DIR}")
|
||||||
|
file(MAKE_DIRECTORY "${CONFIG_FILE_DIR}")
|
||||||
|
endif()
|
||||||
|
# 复制所有配置文件到目标目录
|
||||||
|
foreach(CONFIG_FILE ${CONFIG_FILES})
|
||||||
|
set(SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${CONFIG_FILE}")
|
||||||
|
set(TARGET_FILE "${CONFIG_FILE_DIR}/${CONFIG_FILE}")
|
||||||
|
# 检查源文件是否存在
|
||||||
|
if(NOT EXISTS "${SOURCE_FILE}")
|
||||||
|
message(WARNING "Config file not found: ${CONFIG_FILE}")
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
# 拷贝
|
||||||
|
if(NOT EXISTS "${TARGET_FILE}")
|
||||||
|
message(STATUS "Copied ${CONFIG_FILE} to ${CONFIG_FILE_DIR}")
|
||||||
|
file(COPY "${SOURCE_FILE}" DESTINATION "${CONFIG_FILE_DIR}")
|
||||||
|
else()
|
||||||
|
# 可选:检查是否需要更新(基于时间戳并采用统一格式)
|
||||||
|
file(TIMESTAMP "${SOURCE_FILE}" SOURCE_TIME "%s")
|
||||||
|
file(TIMESTAMP "${TARGET_FILE}" TARGET_TIME "%s")
|
||||||
|
# message(STATUS "${SOURCE_FILE} timestamp: ${SOURCE_TIME}")
|
||||||
|
# message(STATUS "${TARGET_FILE} timestamp: ${TARGET_TIME}")
|
||||||
|
if(SOURCE_TIME GREATER TARGET_TIME)
|
||||||
|
message(STATUS "Updating ${CONFIG_FILE} (source is newer)")
|
||||||
|
file(COPY "${SOURCE_FILE}" DESTINATION "${CONFIG_FILE_DIR}")
|
||||||
|
else()
|
||||||
|
message(STATUS "${TARGET_FILE} already exists, skipping copy")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
if(QT_VERSION_MAJOR EQUAL 6)
|
if(QT_VERSION_MAJOR EQUAL 6)
|
||||||
qt_finalize_executable(PowerMaster)
|
qt_finalize_executable(PowerMaster)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
[RabbitMQConfig]
|
||||||
|
host=127.0.0.1
|
||||||
|
port=5672
|
||||||
|
username=alarm_service
|
||||||
|
password=123456
|
||||||
|
virtualHost=/alarm
|
||||||
|
exchangeName=event_notify_fanout
|
||||||
|
queueName=event_nofify_queue
|
||||||
|
routingKey=key
|
||||||
|
reconnectInterval=3000
|
||||||
|
heartbeat=60
|
||||||
|
autoAck=1
|
||||||
|
|
||||||
|
[HistoricalDataConfig]
|
||||||
|
baseUrl=http://127.0.0.1:8888/api/events
|
||||||
|
timeout=3000
|
||||||
|
maxRetries=3
|
||||||
|
retryInterval=2000
|
||||||
|
|
@ -14,6 +14,7 @@ class QAmqpExchange;
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
class QSettings;
|
||||||
|
|
||||||
class AlarmEventDataService : public QObject
|
class AlarmEventDataService : public QObject
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +23,6 @@ class AlarmEventDataService : public QObject
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static AlarmEventDataService* instance();
|
static AlarmEventDataService* instance();
|
||||||
bool initialize(const ServiceConfig& config);
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
void queryHistoricalEvents(const QDateTime& startTime, const QDateTime& endTime);
|
void queryHistoricalEvents(const QDateTime& startTime, const QDateTime& endTime);
|
||||||
|
|
@ -44,6 +44,8 @@ private:
|
||||||
explicit AlarmEventDataService();
|
explicit AlarmEventDataService();
|
||||||
~AlarmEventDataService();
|
~AlarmEventDataService();
|
||||||
|
|
||||||
|
void initialize();
|
||||||
|
|
||||||
//连接管理
|
//连接管理
|
||||||
void startRealTimeDataService();
|
void startRealTimeDataService();
|
||||||
void cleanupRabbitMQConnection();
|
void cleanupRabbitMQConnection();
|
||||||
|
|
@ -75,6 +77,11 @@ private:
|
||||||
|
|
||||||
//历史数据相关
|
//历史数据相关
|
||||||
QNetworkAccessManager* m_networkManager;
|
QNetworkAccessManager* m_networkManager;
|
||||||
|
|
||||||
|
//配置相关
|
||||||
|
QSettings* m_settings;
|
||||||
|
QString m_settingsFile;
|
||||||
|
bool m_isVaildSettingsFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,13 @@
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QSettings>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
AlarmEventDataService* AlarmEventDataService::instance()
|
AlarmEventDataService* AlarmEventDataService::instance()
|
||||||
{
|
{
|
||||||
|
|
@ -30,22 +33,46 @@ AlarmEventDataService::AlarmEventDataService()
|
||||||
connect(m_reconnectTimer, &QTimer::timeout, this, &AlarmEventDataService::onReconnectTimeout);
|
connect(m_reconnectTimer, &QTimer::timeout, this, &AlarmEventDataService::onReconnectTimeout);
|
||||||
|
|
||||||
m_networkManager = new QNetworkAccessManager(this);
|
m_networkManager = new QNetworkAccessManager(this);
|
||||||
|
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlarmEventDataService::~AlarmEventDataService()
|
AlarmEventDataService::~AlarmEventDataService()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool AlarmEventDataService::initialize(const ServiceConfig& config)
|
void AlarmEventDataService::initialize()
|
||||||
{
|
{
|
||||||
if(m_serviceStatus != ServiceStatus::Uninitialized)
|
//读取配置文件
|
||||||
return false;
|
QString cofigDir = QCoreApplication::applicationDirPath();
|
||||||
|
m_settingsFile = cofigDir + "/config/alarmEventService_config.ini";
|
||||||
|
QFile file(m_settingsFile);
|
||||||
|
if(file.open(QIODevice::ReadWrite))
|
||||||
|
{
|
||||||
|
m_isVaildSettingsFile = true;
|
||||||
|
m_settings = new QSettings(m_settingsFile, QSettings::IniFormat);
|
||||||
|
|
||||||
if(!config.isValid())
|
//RabbitMQConfig
|
||||||
return false;
|
m_config.rabbitMQConfig.host = m_settings->value("RabbitMQConfig/host").toString();
|
||||||
|
m_config.rabbitMQConfig.port = m_settings->value("RabbitMQConfig/port").toInt();
|
||||||
|
m_config.rabbitMQConfig.username = m_settings->value("RabbitMQConfig/username").toString();
|
||||||
|
m_config.rabbitMQConfig.password = m_settings->value("RabbitMQConfig/password").toString();
|
||||||
|
m_config.rabbitMQConfig.virtualHost = m_settings->value("RabbitMQConfig/virtualHost").toString();
|
||||||
|
m_config.rabbitMQConfig.exchangeName = m_settings->value("RabbitMQConfig/exchangeName").toString();
|
||||||
|
m_config.rabbitMQConfig.queueName = m_settings->value("RabbitMQConfig/queueName").toString();
|
||||||
|
m_config.rabbitMQConfig.routingKey = m_settings->value("RabbitMQConfig/routingKey").toString();
|
||||||
|
m_config.rabbitMQConfig.reconnectInterval = m_settings->value("RabbitMQConfig/reconnectInterval").toInt();
|
||||||
|
m_config.rabbitMQConfig.heartbeat = m_settings->value("RabbitMQConfig/heartbeat").toInt();
|
||||||
|
m_config.rabbitMQConfig.autoAck = m_settings->value("RabbitMQConfig/autoAck").toBool();
|
||||||
|
//HistoricalDataConfig
|
||||||
|
m_config.historicalConfig.baseUrl = m_settings->value("HistoricalDataConfig/baseUrl").toString();
|
||||||
|
m_config.historicalConfig.timeout = m_settings->value("HistoricalDataConfig/timeout").toInt();
|
||||||
|
m_config.historicalConfig.maxRetries = m_settings->value("HistoricalDataConfig/maxRetries").toInt();
|
||||||
|
m_config.historicalConfig.retryInterval = m_settings->value("HistoricalDataConfig/retryInterval").toInt();
|
||||||
|
|
||||||
m_config = config;
|
m_serviceStatus = ServiceStatus::Disconnected;
|
||||||
m_serviceStatus = ServiceStatus::Disconnected;
|
}
|
||||||
return true;
|
else
|
||||||
|
m_isVaildSettingsFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlarmEventDataService::start()
|
void AlarmEventDataService::start()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue