X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..f5776429a3145d59f5b131c25d0f9428ae947f4e:/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp index eaba5b53..325e7d7f 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp @@ -26,18 +26,20 @@ * */ +#include + #include "firebird_store.h" -#include "ibpp.h" +#include "stg/ibpp.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetTariffsList(vector * tariffsList) const +int FIREBIRD_STORE::GetTariffsList(std::vector * tariffsList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -string name; +std::string name; try { @@ -62,7 +64,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddTariff(const string & name) const +int FIREBIRD_STORE::AddTariff(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -90,7 +92,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelTariff(const string & name) const +int FIREBIRD_STORE::DelTariff(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -118,7 +120,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::SaveTariff(const TARIFF_DATA & td, - const string & tariffName) const + const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -144,17 +146,36 @@ try } st->Get(1, id); st->Close(); - st->Prepare("update tb_tariffs set \ - fee = ?, \ - free = ?, \ - passive_cost = ?, \ - traff_type = ? \ - where pk_tariff = ?"); - st->Set(1, td.tariffConf.fee); - st->Set(2, td.tariffConf.free); - st->Set(3, td.tariffConf.passiveCost); - st->Set(4, td.tariffConf.traffType); - st->Set(5, id); + if (schemaVersion > 0) + { + st->Prepare("update tb_tariffs set \ + fee = ?, \ + free = ?, \ + passive_cost = ?, \ + traff_type = ?, \ + period = ? \ + where pk_tariff = ?"); + st->Set(1, td.tariffConf.fee); + st->Set(2, td.tariffConf.free); + st->Set(3, td.tariffConf.passiveCost); + st->Set(4, td.tariffConf.traffType); + st->Set(5, TARIFF::PeriodToString(td.tariffConf.period)); + st->Set(6, id); + } + else + { + st->Prepare("update tb_tariffs set \ + fee = ?, \ + free = ?, \ + passive_cost = ?, \ + traff_type = ? \ + where pk_tariff = ?"); + st->Set(1, td.tariffConf.fee); + st->Set(2, td.tariffConf.free); + st->Set(3, td.tariffConf.passiveCost); + st->Set(4, td.tariffConf.traffType); + st->Set(5, id); + } st->Execute(); st->Close(); @@ -198,7 +219,7 @@ try threshold = ?, \ time_day_begins = ?, \ time_day_ends = ? \ - where fk_tariff = ? and dir_num = ?"); + where fk_tariff = ? and dir_num = ?"); st->Set(1, pda); st->Set(2, pdb); st->Set(3, pna); @@ -226,7 +247,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::RestoreTariff(TARIFF_DATA * td, - const string & tariffName) const + const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -244,7 +265,7 @@ td->tariffConf.name = tariffName; try { tr->Start(); - st->Prepare("select * from tb_tariffs where name = ?"); + st->Prepare("select * from tb_tariffs where name = ?"); // TODO: explicit field order! st->Set(1, tariffName); st->Execute(); if (!st->Fetch()) @@ -259,6 +280,12 @@ try st->Get(4, td->tariffConf.free); st->Get(5, td->tariffConf.passiveCost); st->Get(6, td->tariffConf.traffType); + if (schemaVersion > 0) + { + std::string period; + st->Get(7, period); + td->tariffConf.period = TARIFF::StringToPeriod(period); + } st->Close(); st->Prepare("select * from tb_tariffs_params where fk_tariff = ?"); st->Set(1, id); @@ -284,8 +311,8 @@ try st->Get(7, td->dirPrice[dir].priceNightB); td->dirPrice[dir].priceNightB /= 1024*1024; st->Get(8, td->dirPrice[dir].threshold); - if (td->dirPrice[dir].priceDayA == td->dirPrice[dir].priceNightA && - td->dirPrice[dir].priceDayB == td->dirPrice[dir].priceNightB) + if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 && + std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3) { td->dirPrice[dir].singlePrice = true; }