From: Maxim Mamontov Date: Mon, 6 Jan 2014 15:51:09 +0000 (+0200) Subject: Merge branch 'new-daily-fee' X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/8569ecdc2c9368dc0fe650b901cce7b37337ffec?ds=inline;hp=--cc Merge branch 'new-daily-fee' Conflicts: include/stg/tariff_conf.h projects/stargazer/plugins/store/firebird/Makefile projects/stargazer/plugins/store/firebird/firebird_store.cpp projects/stargazer/plugins/store/firebird/firebird_store.h projects/stargazer/plugins/store/mysql/Makefile projects/stargazer/plugins/store/mysql/mysql_store.cpp projects/stargazer/plugins/store/mysql/mysql_store.h projects/stargazer/plugins/store/postgresql/Makefile projects/stargazer/plugins/store/postgresql/postgresql_store.cpp projects/stargazer/plugins/store/postgresql/postgresql_store.h projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp --- 8569ecdc2c9368dc0fe650b901cce7b37337ffec diff --cc include/stg/tariff_conf.h index b554e14a,376ed378..6a296230 --- a/include/stg/tariff_conf.h +++ b/include/stg/tariff_conf.h @@@ -178,14 -184,15 +184,15 @@@ struct TARIFF_CONF_RE return *this; } - TARIFF_CONF GetData() + TARIFF_CONF GetData() const { TARIFF_CONF tc; - tc.fee = fee; - tc.free = free; - tc.name = name; - tc.passiveCost = passiveCost; - tc.traffType = traffType; - tc.period = period; + tc.fee = fee.data(); + tc.free = free.data(); + tc.name = name.data(); + tc.passiveCost = passiveCost.data(); + tc.traffType = traffType.data(); ++ tc.period = period.data(); return tc; } diff --cc projects/stargazer/plugins/store/firebird/firebird_store.h index 638067f2,a5905fef..688f0e88 --- a/projects/stargazer/plugins/store/firebird/firebird_store.h +++ b/projects/stargazer/plugins/store/firebird/firebird_store.h @@@ -123,11 -127,13 +123,13 @@@ private MODULE_SETTINGS settings; mutable IBPP::Database db; mutable pthread_mutex_t mutex; - mutable IBPP::TIL til; - mutable IBPP::TLR tlr; + IBPP::TIL til; + IBPP::TLR tlr; + int schemaVersion; - STG_LOGGER & WriteServLog; + PLUGIN_LOGGER logger; int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const; + int CheckVersion(); }; time_t ts2time_t(const IBPP::Timestamp & ts); diff --cc projects/stargazer/plugins/store/mysql/mysql_store.cpp index b4ac8715,95ac298d..11c2def3 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@@ -525,10 -578,33 +581,33 @@@ if(!IsTablePresent("stat",sock) return 0; } //----------------------------------------------------------------------------- + int MYSQL_STORE::MakeUpdates(MYSQL * sock) + { + if (schemaVersion < 1) + { + if (MysqlQuery("ALTER TABLE tariffs ADD period VARCHAR(32) NOT NULL DEFAULT 'month'", sock)) + { + errorStr = "Couldn't update tariffs table to version 1. With error:\n"; + errorStr += mysql_error(sock); + mysql_close(sock); + return -1; + } + if (MysqlQuery("UPDATE info SET version = 1", sock)) + { + errorStr = "Couldn't update DB schema version to 1. With error:\n"; + errorStr += mysql_error(sock); + mysql_close(sock); + return -1; + } + schemaVersion = 1; + WriteServLog("MYSQL_STORE: Updated DB schema to version %d", schemaVersion); + } + return 0; + } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetAllParams(vector * ParamList, - const string & table, const string & name) const +int MYSQL_STORE::GetAllParams(std::vector * ParamList, + const std::string & table, const std::string & name) const { MYSQL_RES *res; MYSQL_ROW row; diff --cc projects/stargazer/plugins/store/mysql/mysql_store.h index af747c14,8818f590..4a492b38 --- a/projects/stargazer/plugins/store/mysql/mysql_store.h +++ b/projects/stargazer/plugins/store/mysql/mysql_store.h @@@ -129,20 -130,21 +129,22 @@@ private MYSQL_STORE(const MYSQL_STORE & rvalue); MYSQL_STORE & operator=(const MYSQL_STORE & rvalue); - virtual int WriteLogString(const string & str, const string & login) const; - int GetAllParams(vector * ParamList, const string & table, const string & name) const; + virtual int WriteLogString(const std::string & str, const std::string & login) const; + int GetAllParams(std::vector * ParamList, const std::string & table, const std::string & name) const; int CheckAllTables(MYSQL * sock); + int MakeUpdates(MYSQL * sock); - bool IsTablePresent(const string & str,MYSQL * sock); - mutable string errorStr; - int MysqlQuery(const char* sQuery,MYSQL * sock) const; + bool IsTablePresent(const std::string & str,MYSQL * sock); + mutable std::string errorStr; + int MysqlQuery(const char* sQuery,MYSQL * sock) const; int MysqlGetQuery(const char * Query,MYSQL * & sock) const; int MysqlSetQuery(const char * Query) const; MYSQL * MysqlConnect() const ; - string version; + std::string version; MYSQL_STORE_SETTINGS storeSettings; MODULE_SETTINGS settings; + int schemaVersion; - STG_LOGGER & WriteServLog; + + PLUGIN_LOGGER logger; }; //----------------------------------------------------------------------------- diff --cc projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp index fb8caf9d,ffce2846..c9cb7ccf --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp @@@ -292,26 -289,26 +292,30 @@@ if (tuples != 1 return -1; } -std::stringstream tuple; -tuple << PQgetvalue(result, 0, 0); + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0); -PQclear(result); + PQclear(result); -tuple >> id; + tuple >> id; + } -query.str(""); -query << "UPDATE tb_tariffs SET \ - fee = " << td.tariffConf.fee << ", \ - free = " << td.tariffConf.free << ", \ - passive_cost = " << td.tariffConf.passiveCost << ", \ - traff_type = " << td.tariffConf.traffType; + { + std::ostringstream query; + query << "UPDATE tb_tariffs SET \ + fee = " << td.tariffConf.fee << ", \ + free = " << td.tariffConf.free << ", \ + passive_cost = " << td.tariffConf.passiveCost << ", \ - traff_type = " << td.tariffConf.traffType << " \ - WHERE pk_tariff = " << id; ++ traff_type = " << td.tariffConf.traffType; + -if (version > 6) - query << ", period = '" << TARIFF::PeriodToString(td.tariffConf.period) << "'"; ++ if (version > 6) ++ query << ", period = '" << TARIFF::PeriodToString(td.tariffConf.period) << "'"; + -query << " WHERE pk_tariff = " << id; ++ query << " WHERE pk_tariff = " << id; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_COMMAND_OK) { @@@ -434,13 -429,17 +438,17 @@@ if (EscapeString(ename) td->tariffConf.name = tariffName; -std::stringstream query; +std::ostringstream query; query << "SELECT pk_tariff, \ fee, \ - free, \ - passive_cost, \ - traff_type \ - FROM tb_tariffs WHERE name = '" << ename << "'"; + free, \ + passive_cost, \ + traff_type"; + + if (version > 6) + query << ", period"; + + query << " FROM tb_tariffs WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); @@@ -470,23 -469,23 +478,26 @@@ if (tuples != 1 return -1; } -std::stringstream tuple; -tuple << PQgetvalue(result, 0, 0) << " "; -tuple << PQgetvalue(result, 0, 1) << " "; -tuple << PQgetvalue(result, 0, 2) << " "; -tuple << PQgetvalue(result, 0, 3) << " "; -tuple << PQgetvalue(result, 0, 4) << " "; - int id; -tuple >> id; -tuple >> td->tariffConf.fee; -tuple >> td->tariffConf.free; -tuple >> td->tariffConf.passiveCost; -tuple >> td->tariffConf.traffType; + + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0) << " "; + tuple << PQgetvalue(result, 0, 1) << " "; + tuple << PQgetvalue(result, 0, 2) << " "; + tuple << PQgetvalue(result, 0, 3) << " "; + tuple << PQgetvalue(result, 0, 4) << " "; + + tuple >> id; + tuple >> td->tariffConf.fee; + tuple >> td->tariffConf.free; + tuple >> td->tariffConf.passiveCost; + tuple >> td->tariffConf.traffType; + } + if (version > 6) + td->tariffConf.period = TARIFF::StringToPeriod(PQgetvalue(result, 0, 5)); + PQclear(result); query.str(""); diff --cc projects/stargazer/user_impl.cpp index 7b0348bc,42650eff..3b2489ad --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@@ -1253,9 -1231,12 +1253,12 @@@ STG_LOCKER lock(&mutex, __FILE__, __LIN if (passive.ConstData() || tariff == NULL) return; + if (tariff->GetPeriod() != TARIFF::MONTH) + return; + double fee = tariff->GetFee() / DaysInCurrentMonth(); -if (fee == 0.0) +if (std::fabs(fee) < 1.0e-3) return; double c = cash;