FemaLocalSoftware/alarm_r.h

74 lines
2.4 KiB
C
Raw Normal View History

2024-12-28 17:15:48 +00:00
#ifndef ALARM_R_H
#define ALARM_R_H
#include <QJsonDocument>
2025-01-07 22:13:48 +00:00
#include <QJsonObject>
#include <QString>
2024-12-28 17:15:48 +00:00
2025-01-07 22:13:48 +00:00
class AlarmR
{
2024-12-28 17:15:48 +00:00
public:
AlarmR() = default;
2025-01-07 22:13:48 +00:00
AlarmR(const QString &endTime,
const QString &mark,
const QString &sensorGroup,
const QString &sensorId,
const QString &serial,
const QString &startTime)
: end_time(endTime)
, mark(mark)
, sensor_group(sensorGroup)
, sensor_id(sensorId)
, serial(serial)
, start_time(startTime)
{}
2024-12-28 17:15:48 +00:00
2025-01-07 22:13:48 +00:00
void parseResponse(const QJsonObject &json)
{
if (json["start_time"].isDouble()) {
start_time = QString::number(static_cast<qint64>(json["start_time"].toDouble()));
qint64 unixTime = static_cast<qint64>(json["start_time"].toDouble());
QDateTime dateTime = QDateTime::fromSecsSinceEpoch(unixTime);
start_time = dateTime.toString("dd.MM.yyyy HH:mm");
}
if (json.contains("end_time") && json["end_time"].isDouble()) {
end_time = QString::number(static_cast<qint64>(json["end_time"].toDouble()));
qint64 unixTime = static_cast<qint64>(json["end_time"].toDouble());
QDateTime dateTime = QDateTime::fromSecsSinceEpoch(unixTime);
end_time = dateTime.toString("dd.MM.yyyy HH:mm");
} else {
end_time.clear();
2024-12-28 17:15:48 +00:00
}
if (json.contains("mark") && json["mark"].isString()) {
mark = json["mark"].toString();
}
if (json.contains("sensor_group") && json["sensor_group"].isString()) {
sensor_group = json["sensor_group"].toString();
}
if (json.contains("sensor_id") && json["sensor_id"].isString()) {
sensor_id = json["sensor_id"].toString();
}
if (json.contains("serial") && json["serial"].isString()) {
serial = json["serial"].toString();
}
}
QString getEndTime() const { return end_time; }
QString getMark() const { return mark; }
QString getSensorGroup() const { return sensor_group; }
QString getSensorId() const { return sensor_id; }
QString getSerial() const { return serial; }
QString getStartTime() const { return start_time; }
private:
QString end_time;
QString mark;
QString sensor_group;
QString sensor_id;
QString serial;
QString start_time;
};
#endif // ALARM_R_H