#ifndef PLOTSERVICE_H #define PLOTSERVICE_H #include "HttpClient.h" #include "utils.h" #include #include #include #include #include #include #include class PlotService : public QObject { Q_OBJECT public: explicit PlotService(HttpClient *client, QObject *parent = nullptr) : QObject(parent) , httpClient(client) {} int getDeviceSensorData(const QMap> &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