]> git.stg.codes - stg.git/commitdiff
Merge remote-tracking branch 'origin/ticket'
authorMaxim Mamontov <faust.madf@gmail.com>
Thu, 22 Dec 2016 19:56:56 +0000 (21:56 +0200)
committerMaxim Mamontov <faust.madf@gmail.com>
Thu, 22 Dec 2016 19:56:56 +0000 (21:56 +0200)
projects/sgconf/tariffs.cpp
stglibs/srvconf.lib/parsers/chg_tariff.cpp
stglibs/srvconf.lib/parsers/get_tariff.cpp

index 3d63d2a8c6861f1b1fc0a666ef4af972ca9f3f69..6ab4e87107e69cbd19fad439e20fd74e62822b80 100644 (file)
@@ -28,6 +28,18 @@ if (level == 0)
 return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
 }
 
+std::string ChangePolicyToString(TARIFF::CHANGE_POLICY changePolicy)
+{
+switch (changePolicy)
+    {
+    case TARIFF::ALLOW: return "allow";
+    case TARIFF::TO_CHEAP: return "to_cheap";
+    case TARIFF::TO_EXPENSIVE: return "to_expensive";
+    case TARIFF::DENY: return "deny";
+    }
+return "unknown";
+}
+
 std::string PeriodToString(TARIFF::PERIOD period)
 {
 switch (period)
@@ -67,6 +79,29 @@ else
     throw SGCONF::ACTION::ERROR("Period should be 'daily' or 'monthly'. Got: '" + value + "'");
 }
 
+void ConvChangePolicy(const std::string & value, RESETABLE<TARIFF::CHANGE_POLICY> & res)
+{
+std::string lowered = ToLower(value);
+if (lowered == "allow")
+    res = TARIFF::ALLOW;
+else if (lowered == "to_cheap")
+    res = TARIFF::TO_CHEAP;
+else if (lowered == "to_expensive")
+    res = TARIFF::TO_EXPENSIVE;
+else if (lowered == "deny")
+    res = TARIFF::DENY;
+else
+    throw SGCONF::ACTION::ERROR("Change policy should be 'allow', 'to_cheap', 'to_expensive' or 'deny'. Got: '" + value + "'");
+}
+
+void ConvChangePolicyTimeout(const std::string & value, RESETABLE<time_t> & res)
+{
+struct tm brokenTime;
+if (stg_strptime(value.c_str(), "%Y-%m-%d %H:%M:%S", &brokenTime) == NULL)
+    throw SGCONF::ACTION::ERROR("Credit expiration should be in format 'YYYY-MM-DD HH:MM:SS'. Got: '" + value + "'");
+res = stg_timegm(&brokenTime);
+}
+
 void ConvTraffType(const std::string & value, RESETABLE<TARIFF::TRAFF_TYPE> & res)
 {
 std::string lowered = ToLower(value);
@@ -214,7 +249,9 @@ std::cout << Indent(level, true) << "name: " << conf.name << "\n"
           << Indent(level)       << "free mb: " << conf.free << "\n"
           << Indent(level)       << "passive cost: " << conf.passiveCost << "\n"
           << Indent(level)       << "traff type: " << TraffTypeToString(conf.traffType) << "\n"
-          << Indent(level)       << "period: " << PeriodToString(conf.period) << "\n";
+          << Indent(level)       << "period: " << PeriodToString(conf.period) << "\n"
+          << Indent(level)       << "change policy: " << ChangePolicyToString(conf.changePolicy) << "\n"
+          << Indent(level)       << "change policy timeout: " << formatTime(conf.changePolicyTimeout) << "\n";
 }
 
 void PrintTariff(const STG::GET_TARIFF::INFO & info, size_t level = 0)
@@ -233,6 +270,8 @@ params.push_back(SGCONF::API_ACTION::PARAM("free", "<free mb>", "\tprepaid traff
 params.push_back(SGCONF::API_ACTION::PARAM("passive-cost", "<cost>", "\tpassive cost"));
 params.push_back(SGCONF::API_ACTION::PARAM("traff-type", "<type>", "\ttraffic type (up, down, up+down, max)"));
 params.push_back(SGCONF::API_ACTION::PARAM("period", "<period>", "\ttarification period (daily, monthly)"));
+params.push_back(SGCONF::API_ACTION::PARAM("change-policy", "<policy>", "tariff change policy (allow, to_cheap, to_expensive, deny)"));
+params.push_back(SGCONF::API_ACTION::PARAM("change-policy-timeout", "<yyyy-mm-dd hh:mm:ss>", "tariff change policy timeout"));
 params.push_back(SGCONF::API_ACTION::PARAM("times", "<hh:mm-hh:mm, ...>", "coma-separated day time-spans for each direction"));
 params.push_back(SGCONF::API_ACTION::PARAM("day-prices", "<price/price, ...>", "coma-separated day prices for each direction"));
 params.push_back(SGCONF::API_ACTION::PARAM("night-prices", "<price/price, ...>", "coma-separated night prices for each direction"));
@@ -337,6 +376,8 @@ SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
 SGCONF::MaybeSet(options, "passive-cost", conf.tariffConf.passiveCost);
 SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
 SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
+SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
+SGCONF::MaybeSet(options, "change-policy-timeout", conf.tariffConf.changePolicyTimeout, ConvChangePolicyTimeout);
 SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
 SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
 SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
@@ -370,6 +411,8 @@ SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
 SGCONF::MaybeSet(options, "passive-cost", conf.tariffConf.passiveCost);
 SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
 SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
+SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
+SGCONF::MaybeSet(options, "change-policy-timeout", conf.tariffConf.changePolicyTimeout, ConvChangePolicyTimeout);
 SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
 SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
 SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
index 158e6f890642af0a744525691ea825774e429901..16c4b198dbf1d4e605de0a51d22c39f46abf8d4e 100644 (file)
@@ -69,6 +69,16 @@ if (!data.tariffConf.period.empty())
         case TARIFF::MONTH: stream << "<period value=\"month\"/>"; break;
         }
 
+if (!data.tariffConf.changePolicy.empty())
+    switch (data.tariffConf.changePolicy.data())
+        {
+        case TARIFF::ALLOW: stream << "<changePolicy value=\"allow\"/>"; break;
+        case TARIFF::TO_CHEAP: stream << "<changePolicy value=\"to_cheap\"/>"; break;
+        case TARIFF::TO_EXPENSIVE: stream << "<changePolicy value=\"to_expensive\"/>"; break;
+        case TARIFF::DENY: stream << "<changePolicy value=\"deny\"/>"; break;
+        }
+
+appendResetableTag(stream, "changePolicyTimeout", data.tariffConf.changePolicyTimeout);
 for (size_t i = 0; i < DIR_NUM; ++i)
     if (!data.dirPrice[i].hDay.empty() &&
         !data.dirPrice[i].mDay.empty() &&
index 0804b269ac3d8980ae20b33b84c6d0375e3750d8..e2066363b6eef02925a5b0433e8ca45a1cc2af73 100644 (file)
@@ -97,6 +97,34 @@ else
 return true;
 }
 
+template <typename T>
+bool GetChangePolicy(const char ** attr, T & value, const std::string & attrName)
+{
+if (!CheckValue(attr, attrName))
+    return false;
+std::string type(attr[1]);
+if (type == "allow")
+        value = TARIFF::ALLOW;
+else if (type == "to_cheap")
+        value = TARIFF::TO_CHEAP;
+else if (type == "to_expensive")
+        value = TARIFF::TO_EXPENSIVE;
+else if (type == "deny")
+        value = TARIFF::DENY;
+else
+    return false;
+return true;
+}
+
+template <typename T>
+bool GetChangePolicyTimeout(const char ** attr, T & value, const std::string & attrName)
+{
+if (!CheckValue(attr, attrName))
+    return false;
+value = readTime(attr[1]);
+return true;
+}
+
 template <typename A, typename T>
 bool GetSlashedValue(const char ** attr, A & array, T A::value_type:: * field)
 {
@@ -131,6 +159,8 @@ GET_TARIFF::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
     AddParser(propertyParsers, "free", info.tariffConf.free);
     AddParser(propertyParsers, "traffType", info.tariffConf.traffType, GetTraffType);
     AddParser(propertyParsers, "period", info.tariffConf.period, GetPeriod);
+    AddParser(propertyParsers, "changePolicy", info.tariffConf.changePolicy, GetChangePolicy);
+    AddParser(propertyParsers, "changePolicyTimeout", info.tariffConf.changePolicyTimeout, GetChangePolicyTimeout);
     for (size_t i = 0; i < DIR_NUM; ++i)
         AddParser(propertyParsers, "time" + unsigned2str(i), info.dirPrice[i], GetTimeSpan);
     AddAOSParser(propertyParsers, "priceDayA", info.dirPrice, &DIRPRICE_DATA::priceDayA, GetSlashedValue);