2025-11-06 18:54:50 +08:00
|
|
|
|
#ifndef ALARMEVENTDATASERVICE_H
|
|
|
|
|
|
#define ALARMEVENTDATASERVICE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "alarmEventGlobal.h"
|
|
|
|
|
|
#include "alarmEventUtils.h"
|
|
|
|
|
|
#include "qamqpclient.h"
|
|
|
|
|
|
#include "qamqpexchange.h"
|
|
|
|
|
|
#include "qamqpqueue.h"
|
2025-11-11 10:51:01 +08:00
|
|
|
|
//#include <QNetworkRequest>
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
class QAmqpClient;
|
|
|
|
|
|
class QAmqpQueue;
|
|
|
|
|
|
class QAmqpExchange;
|
2025-11-11 10:51:01 +08:00
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
|
|
class QNetworkReply;
|
2025-11-07 17:33:04 +08:00
|
|
|
|
class QTimer;
|
2025-11-12 14:48:47 +08:00
|
|
|
|
class QSettings;
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
class AlarmEventDataService : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
2025-11-12 10:06:10 +08:00
|
|
|
|
Q_DISABLE_COPY(AlarmEventDataService) //禁止拷贝,等价于:AlarmEventDataService(const AlarmEventDataService&) = delete; AlarmEventDataService& operator=(const AlarmEventDataService&) = delete;
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
static AlarmEventDataService* instance();
|
|
|
|
|
|
void start();
|
|
|
|
|
|
void stop();
|
2025-11-25 11:54:16 +08:00
|
|
|
|
void queryHistoricalEvents(const QDateTime& startTime, const QDateTime& endTime, int confirmStatus = -1);
|
2025-12-04 18:05:44 +08:00
|
|
|
|
void confirmEvents(const QStringList& uuids);
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
void realTimeEventReceived(const EventData& event);
|
2025-11-11 10:51:01 +08:00
|
|
|
|
void historicalQueryError(const QString& msg);
|
2025-11-12 10:06:10 +08:00
|
|
|
|
void historicalQueryData(const QList<EventData>& events);
|
2025-12-04 18:05:44 +08:00
|
|
|
|
void confirmEventsResult(bool success, const QString& mesg);
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
void onRabbitMQConnected();
|
|
|
|
|
|
void onRabbitMQDisconnected();
|
|
|
|
|
|
void onRabbitMQError(QAMQP::Error error);
|
2025-11-18 14:26:29 +08:00
|
|
|
|
void onRabbitMQSocketError(QAbstractSocket::SocketError error);
|
2025-12-04 18:05:44 +08:00
|
|
|
|
void onAmqpQueueOpened();
|
2025-11-06 18:54:50 +08:00
|
|
|
|
void onMessageReceived();
|
2025-11-07 17:33:04 +08:00
|
|
|
|
void onReconnectTimeout();
|
2025-11-11 10:51:01 +08:00
|
|
|
|
void onHistoricalRequestFinished(QNetworkReply* reply);
|
2025-12-04 18:05:44 +08:00
|
|
|
|
void onConfirmEventsRequestFinished(QNetworkReply* reply);
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
explicit AlarmEventDataService();
|
|
|
|
|
|
~AlarmEventDataService();
|
|
|
|
|
|
|
2025-11-12 14:48:47 +08:00
|
|
|
|
void initialize();
|
|
|
|
|
|
|
2025-11-06 18:54:50 +08:00
|
|
|
|
//连接管理
|
|
|
|
|
|
void startRealTimeDataService();
|
|
|
|
|
|
void cleanupRabbitMQConnection();
|
2025-11-07 17:33:04 +08:00
|
|
|
|
void scheduleReconnect();
|
|
|
|
|
|
void cancelReconnect();
|
2025-11-06 18:54:50 +08:00
|
|
|
|
//实时信息处理
|
|
|
|
|
|
MessageHandleResult processMessage(const QAmqpMessage& message);
|
|
|
|
|
|
EventData parseEventFromMessage(const QByteArray& data, QString& errorString);
|
|
|
|
|
|
bool validateEvent(const EventData& event);
|
2025-11-11 10:51:01 +08:00
|
|
|
|
//历史数据处理
|
2025-11-25 11:54:16 +08:00
|
|
|
|
QUrl bulidHistoricalQueryUrl(const QDateTime& startTime, const QDateTime& endTime, int confirmStatus);
|
2025-11-11 10:51:01 +08:00
|
|
|
|
void processHistoricalResponse(const QByteArray& data);
|
|
|
|
|
|
//QNetworkRequest createHistoricalRequest(const QUrl& url);
|
2025-12-04 18:05:44 +08:00
|
|
|
|
//事件确认
|
|
|
|
|
|
QUrl buildConfirmEventsUrl();
|
2025-11-06 18:54:50 +08:00
|
|
|
|
|
|
|
|
|
|
ServiceConfig m_config;
|
|
|
|
|
|
ServiceStatus m_serviceStatus;
|
|
|
|
|
|
//ConnectionStatus m_realTimeConnectionStatus;
|
|
|
|
|
|
//ConnectionStatus m_historicalConnectionStatus;
|
|
|
|
|
|
|
|
|
|
|
|
//RabbitMQ通信相关组件
|
|
|
|
|
|
QAmqpClient* m_amqpClient;
|
|
|
|
|
|
QAmqpQueue* m_amqpQueue;
|
|
|
|
|
|
QAmqpExchange* m_amqpExchange;
|
|
|
|
|
|
|
2025-11-07 17:33:04 +08:00
|
|
|
|
//重连相关
|
|
|
|
|
|
QTimer* m_reconnectTimer;
|
|
|
|
|
|
int m_reconnectAttempts;
|
|
|
|
|
|
int m_maxReconnectAttempts;
|
2025-11-11 10:51:01 +08:00
|
|
|
|
|
|
|
|
|
|
//历史数据相关
|
|
|
|
|
|
QNetworkAccessManager* m_networkManager;
|
2025-11-12 14:48:47 +08:00
|
|
|
|
|
|
|
|
|
|
//配置相关
|
|
|
|
|
|
QSettings* m_settings;
|
|
|
|
|
|
QString m_settingsFile;
|
|
|
|
|
|
bool m_isVaildSettingsFile;
|
2025-11-06 18:54:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|