60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#ifndef PLOTSERVICE_H
|
|
#define PLOTSERVICE_H
|
|
|
|
#include "HttpClient.h"
|
|
#include "utils.h"
|
|
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QList>
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
|
|
class PlotService : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit PlotService(HttpClient *client, QObject *parent = nullptr)
|
|
: QObject(parent)
|
|
, httpClient(client)
|
|
{}
|
|
|
|
int getDeviceSensorData(const QMap<QString, QList<QString>> &groupsWithSensors,
|
|
qint64 start,
|
|
qint64 end)
|
|
{
|
|
QJsonObject rootObj;
|
|
rootObj["start_time"] = start;
|
|
rootObj["end_time"] = end;
|
|
QJsonObject sensorsObj;
|
|
for (auto it = groupsWithSensors.constBegin(); it != groupsWithSensors.constEnd(); ++it) {
|
|
QJsonArray sensorArray;
|
|
for (QString sensorId : it.value()) {
|
|
sensorArray.append(sensorId);
|
|
}
|
|
sensorsObj[it.key()] = sensorArray;
|
|
}
|
|
rootObj["sensors"] = sensorsObj;
|
|
QJsonDocument doc(rootObj);
|
|
QByteArray requestData = doc.toJson();
|
|
|
|
QJsonObject responseJson = httpClient->post(utils::API_URL + "/alarms/getAlarmsAmount",
|
|
QJsonDocument::fromJson(requestData).object());
|
|
|
|
if (responseJson.contains("amount")) {
|
|
return responseJson["amount"].toInt();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
private:
|
|
HttpClient *httpClient;
|
|
};
|
|
|
|
#endif // PLOTSERVICE_H
|