Add parsing of

ATBDailyTicket DailyTicket;
        ATBTimeBase TimeBase;
        ATBCustomer Customer;
        ATBTimeRange TimeRange;
This commit is contained in:
Gerhard Hoffmann 2023-12-15 13:24:29 +01:00
parent ad534eef09
commit c598014dd0

View File

@ -77,16 +77,21 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} }
printf("%s", "Valid JSON configuration identified\n"); printf("%s", "Valid JSON configuration identified\n");
ATBCurrency Currency; ATBCurrency Currency;
ATBDuration Duration; ATBDuration Duration;
ATBPaymentMethod PaymentMethod; ATBPaymentMethod PaymentMethod;
ATBPaymentRate PaymentRate; ATBPaymentRate PaymentRate;
ATBSpecialDaysWorktime SpecialDaysWorktime; ATBSpecialDaysWorktime SpecialDaysWorktime;
ATBSpecialDays SpecialDays; ATBSpecialDays SpecialDays;
ATBWeekDays WeekDays; ATBWeekDays WeekDays;
ATBWeekDaysWorktime WeekDaysWorktime; ATBWeekDaysWorktime WeekDaysWorktime;
ATBPaymentOption PaymentOption; ATBPaymentOption PaymentOption;
ATBPeriodYear YearPeriod; ATBPeriodYear YearPeriod;
ATBDailyTicket DailyTicket;
ATBTimeBase TimeBase;
ATBCustomer Customer;
ATBTimeRange TimeRange;
MemberType mb_type = MemberType::UnknownType; MemberType mb_type = MemberType::UnknownType;
// Get all JSON object members // Get all JSON object members
@ -118,14 +123,14 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
continue; continue;
} }
//printf(" -%s\n", mb_name); printf(" -%s\n", mb_name);
// Get array for each JSON object member // Get array for each JSON object member
auto mb_array = document[mb_name].GetArray(); auto mb_array = document[mb_name].GetArray();
if (mb_array.Size() <= 0) break; if (mb_array.Size() <= 0) break;
//Iterate over provided array //Iterate over provided array
for (auto j = 0; j < mb_array.Size(); j++) for (rapidjson::SizeType j = 0; j < mb_array.Size(); j++)
{ {
// Get all inner objects, don't print name if NULL // Get all inner objects, don't print name if NULL
auto inner_obj = mb_array[j].GetObject(); auto inner_obj = mb_array[j].GetObject();
@ -145,12 +150,133 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
// Identify member type // Identify member type
mb_type = IdentifyJsonMember(mb_name); mb_type = IdentifyJsonMember(mb_name);
//#pragma region Get_values
switch (mb_type) switch (mb_type)
{ {
case MemberType::UnknownType: case MemberType::UnknownType:
break; break;
case MemberType::CurrencyType: case MemberType::TimeRangeType:
if (QString(inner_obj_name) == QString("time_range_id")) {
if (k->value.IsInt()) {
TimeRange.time_range_id = k->value.GetInt();
}
} else
if (QString(inner_obj_name) == QString("time_range_from")) {
if (k->value.IsString()) {
QTime timeRangeFrom = QTime::fromString(QString::fromStdString(k->value.GetString()), Qt::ISODate);
TimeRange.time_range_from = timeRangeFrom;
}
} else
if (QString(inner_obj_name) == QString("time_range_to")) {
if (k->value.IsString()) {
QTime timeRangeTo = QTime::fromString(QString::fromStdString(k->value.GetString()), Qt::ISODate);
TimeRange.time_range_to = timeRangeTo;
}
}
break;
case MemberType::TimeBaseType:
if (QString(inner_obj_name) == QString("tbase_type")) {
if (k->value.IsInt()) {
int timeBase = k->value.GetInt();
switch (timeBase) {
case (int)ATBTimeBase::TimeBaseType::ABSOLUTE:
TimeBase.tbase_type = ATBTimeBase::TimeBaseType::ABSOLUTE;
break;
case (int)ATBTimeBase::TimeBaseType::RELATIVE:
TimeBase.tbase_type = ATBTimeBase::TimeBaseType::RELATIVE;
break;
}
}
}
break;
case MemberType::DailyTicketType:
if (QString(inner_obj_name) == QString("daily_ticket_payment_option_id")) {
if (k->value.IsInt()) {
DailyTicket.daily_ticket_payment_option_id = k->value.GetInt();
}
} else
if (QString(inner_obj_name) == QString("daily_ticket_unit_id")) {
if (k->value.IsInt()) {
DailyTicket.daily_ticket_unit_id = k->value.GetInt();
}
} else
if (QString(inner_obj_name) == QString("daily_ticket_price")) {
if (k->value.IsInt()) {
DailyTicket.daily_ticket_price = k->value.GetInt();
}
} else
if (QString(inner_obj_name) == QString("daily_ticket_tbase_type")) {
if (k->value.IsInt()) {
int baseType = k->value.GetInt();
switch(baseType) {
case (int)ATBTimeBase::TimeBaseType::ABSOLUTE:
DailyTicket.daily_ticket_tbase_type = ATBTimeBase::TimeBaseType::ABSOLUTE;
break;
case (int)ATBTimeBase::TimeBaseType::RELATIVE:
DailyTicket.daily_ticket_tbase_type = ATBTimeBase::TimeBaseType::RELATIVE;
break;
}
}
} else
if (QString(inner_obj_name) == QString("daily_ticket_clearance_customer_type")) {
if (k->value.IsInt()) {
int CustomerType = k->value.GetInt();
switch (CustomerType) {
case (int)ATBCustomer::CustomerType::ADULT:
DailyTicket.daily_ticket_clearance_customer_type = ATBCustomer::CustomerType::ADULT;
break;
case (int)ATBCustomer::CustomerType::CHILD:
DailyTicket.daily_ticket_clearance_customer_type = ATBCustomer::CustomerType::CHILD;
break;
case (int)ATBCustomer::CustomerType::TEEN:
DailyTicket.daily_ticket_clearance_customer_type = ATBCustomer::CustomerType::TEEN;
break;
}
}
} else
if (QString(inner_obj_name) == QString("daily_ticket_weekday_range")) {
if (k->value.IsInt()) {
DailyTicket.daily_ticket_weekday_range = k->value.GetInt();
}
} else
if (QString(inner_obj_name) == QString("daily_ticket_special_day_range")) {
if (k->value.IsInt()) {
DailyTicket.daily_ticket_special_day_range = k->value.GetInt();
}
}
break;
case MemberType::CustomerType:
if (QString(inner_obj_name) == QString("cust_type")) {
if (k->value.IsInt()) {
int cust_type = k->value.GetInt();
switch (cust_type) {
case (int)ATBCustomer::CustomerType::ADULT:
Customer.cust_type = ATBCustomer::CustomerType::ADULT;
break;
case (int)ATBCustomer::CustomerType::CHILD:
Customer.cust_type = ATBCustomer::CustomerType::CHILD;
break;
case (int)ATBCustomer::CustomerType::TEEN:
Customer.cust_type = ATBCustomer::CustomerType::TEEN;
break;
}
}
} else
if (QString(inner_obj_name) == QString("cust_label")) {
if (k->value.IsString()) {
QString label(QString::fromStdString(k->value.GetString()));
if (label.contains("ADULT", Qt::CaseInsensitive)) {
Customer.cust_label = label;
} else
if (label.contains("CHILD", Qt::CaseInsensitive)) {
Customer.cust_label = label;
} else
if (label.contains("TEEN", Qt::CaseInsensitive)) {
Customer.cust_label = label;
}
}
}
break;
case MemberType::CurrencyType:
if (strcmp(inner_obj_name, "pcu_id") == 0) Currency.pcu_id = k->value.GetInt(); if (strcmp(inner_obj_name, "pcu_id") == 0) Currency.pcu_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pcu_sign") == 0) Currency.pcu_sign = k->value.GetString(); else if (strcmp(inner_obj_name, "pcu_sign") == 0) Currency.pcu_sign = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_major") == 0) Currency.pcu_major = k->value.GetString(); else if (strcmp(inner_obj_name, "pcu_major") == 0) Currency.pcu_major = k->value.GetString();
@ -258,7 +384,19 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
case MemberType::PeriodYearType: case MemberType::PeriodYearType:
cfg->YearPeriod.insert(pair<int, ATBPeriodYear>(YearPeriod.pye_id, YearPeriod)); cfg->YearPeriod.insert(pair<int, ATBPeriodYear>(YearPeriod.pye_id, YearPeriod));
break; break;
default: case MemberType::DailyTicketType:
qCritical() << DailyTicket;
break;
case MemberType::CustomerType:
qCritical() << Customer;
break;
case MemberType::TimeBaseType:
qCritical() << TimeBase;
break;
case MemberType::TimeRangeType:
qCritical() << TimeRange;
break;
default:
break; break;
} }
} }