Implement parsing of "Product" and adding into TariffProduct.

This commit is contained in:
Gerhard Hoffmann 2024-02-22 16:33:19 +01:00
parent 39ab08a5b7
commit afb0e20dd2

View File

@ -2,6 +2,7 @@
#include "tariff_timebase.h" #include "tariff_timebase.h"
#include "time_range_header.h" #include "time_range_header.h"
#include "tariff_timestep_config.h" #include "tariff_timestep_config.h"
#include "tariff_permit_type.h"
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
@ -24,6 +25,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
if (strcmp(member_name, "Customer") == 0) return MemberType::CustomerType; if (strcmp(member_name, "Customer") == 0) return MemberType::CustomerType;
if (strcmp(member_name, "TimeRange") == 0) return MemberType::TimeRangeType; if (strcmp(member_name, "TimeRange") == 0) return MemberType::TimeRangeType;
if (strcmp(member_name, "TimeStepConfig") == 0) return MemberType::TimeStepConfigType; if (strcmp(member_name, "TimeStepConfig") == 0) return MemberType::TimeStepConfigType;
if (strcmp(member_name, "Product") == 0) return MemberType::ProductType;
else return MemberType::UnknownType; else return MemberType::UnknownType;
} }
@ -93,6 +95,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
ATBCustomer Customer; ATBCustomer Customer;
ATBTimeRange TimeRange; ATBTimeRange TimeRange;
ATBTimeStepConfig TimeStepConfig; ATBTimeStepConfig TimeStepConfig;
ATBTariffProduct TariffProduct;
MemberType mb_type = MemberType::UnknownType; MemberType mb_type = MemberType::UnknownType;
this->currentPaymentOptions.clear(); this->currentPaymentOptions.clear();
@ -157,6 +160,50 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
{ {
case MemberType::UnknownType: case MemberType::UnknownType:
break; break;
case MemberType::ProductType: {
if (QString(inner_obj_name) == QString("tariff_product_id")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffProduct.m_tariff_product_id = PermitType(x);
}
} else
if (QString(inner_obj_name) == QString("tariff_product_price")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffProduct.m_tariff_product_price = x;
}
} else
if (QString(inner_obj_name) == QString("tariff_product_name")) {
if (k->value.IsString()) {
std::string const &s = k->value.GetString();
TariffProduct.m_tariff_product_name = QString::fromStdString(s);
}
} else
if (QString(inner_obj_name) == QString("tariff_product_start")) {
if (k->value.IsString()) {
std::string const &s = k->value.GetString();
TariffProduct.m_tariff_product_start = QTime::fromString(QString::fromStdString(s), Qt::ISODate);
}
} else
if (QString(inner_obj_name) == QString("tariff_product_end")) {
if (k->value.IsString()) {
std::string const &s = k->value.GetString();
TariffProduct.m_tariff_product_end = QTime::fromString(QString::fromStdString(s), Qt::ISODate);
}
} else
if (QString(inner_obj_name) == QString("tariff_product_from_in_minutes_from_start")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffProduct.m_tariff_product_from_in_minutes_from_start = x;
}
} else
if (QString(inner_obj_name) == QString("tariff_product_to_in_minutes_from_start")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffProduct.m_tariff_product_to_in_minutes_from_start = x;
}
}
} break;
case MemberType::TimeRangeType: case MemberType::TimeRangeType:
if (QString(inner_obj_name) == QString("time_range_id")) { if (QString(inner_obj_name) == QString("time_range_id")) {
if (k->value.IsInt()) { if (k->value.IsInt()) {
@ -479,6 +526,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
cfg->TimeStepConfig.insert(pair<int, ATBTimeStepConfig>(TimeStepConfig.tsconfig_id, TimeStepConfig)); cfg->TimeStepConfig.insert(pair<int, ATBTimeStepConfig>(TimeStepConfig.tsconfig_id, TimeStepConfig));
// qCritical() << TimeStepConfig; // qCritical() << TimeStepConfig;
break; break;
case MemberType::ProductType:
cfg->TariffProduct.insert(pair<int, ATBTariffProduct>(TariffProduct.m_tariff_product_id, TariffProduct));
qCritical() << TariffProduct;
default: default:
break; break;
} }
@ -492,6 +542,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} }
} }
ATBPaymentOption const &Configuration::getPaymentOptions() const { ATBPaymentOption const &Configuration::getPaymentOptions() const {
Q_ASSERT(!this->currentPaymentOptions.isEmpty()); Q_ASSERT(!this->currentPaymentOptions.isEmpty());
return this->currentPaymentOptions.at(0); return this->currentPaymentOptions.at(0);