mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现策略配置功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "Fields.h"
|
||||
#include "common/Utils.h"
|
||||
|
||||
#include "common/JsonN.h"
|
||||
|
||||
std::string& Fields::value(std::string key)
|
||||
{
|
||||
@@ -14,14 +14,16 @@ bool Fields::contains(std::string key)
|
||||
return (mapFields.find(key) != mapFields.end());
|
||||
}
|
||||
|
||||
std::unordered_map<string, string>::iterator Fields::remove(string key)
|
||||
std::string Fields::remove(string key)
|
||||
{
|
||||
std::string val;
|
||||
auto it = mapFields.find(key);
|
||||
if (it != mapFields.end())
|
||||
{
|
||||
it = mapFields.erase(it);
|
||||
val = it->second;
|
||||
mapFields.erase(it);
|
||||
}
|
||||
return it;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Fields::append(Fields& datafield)
|
||||
@@ -177,6 +179,13 @@ string Fields::toSqlUpdate(string tableName, std::vector<std::string> vecKeys, s
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void Fields::parseJson(std::string jsonstr)
|
||||
{
|
||||
NJsonNode jsonroot;
|
||||
NJson::parse(jsonstr, jsonroot);
|
||||
|
||||
|
||||
|
||||
for (auto& item : jsonroot.items())
|
||||
{
|
||||
this->set(item.key(), item.value());
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ struct PageInfo
|
||||
class Fields
|
||||
{
|
||||
public:
|
||||
Fields() {};
|
||||
|
||||
template <typename T>
|
||||
void set(string key, T val, int precision=6)
|
||||
{
|
||||
@@ -42,7 +44,6 @@ public:
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
* @param: [string key] 索引名称
|
||||
@@ -60,7 +61,7 @@ public:
|
||||
* 删除指定索引的值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
std::unordered_map<string, string>::iterator remove(string key);
|
||||
std::string remove(string key);
|
||||
|
||||
/**
|
||||
* 追加合并
|
||||
@@ -136,6 +137,8 @@ public:
|
||||
*/
|
||||
string toSqlUpdate(string tableName, std::vector<std::string> vecKeys, string condition);
|
||||
|
||||
void parseJson(std::string jsonstr);
|
||||
|
||||
private:
|
||||
std::unordered_map<string, string> mapFields;
|
||||
};
|
||||
|
||||
@@ -91,6 +91,15 @@ public:
|
||||
std::cout << "JSON read error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void parse(std::string jsonstr, std::vector<std::string>& vd)
|
||||
{
|
||||
NJsonNode jsonroot;
|
||||
if (NJson::parse(jsonstr, jsonroot))
|
||||
{
|
||||
vd = jsonroot.get<std::vector<std::string>>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
std::mutex g_mutex;
|
||||
|
||||
Logger::Logger(Logger::ELogType logtype, std::string filename, int lineEdit) : line_(lineEdit)
|
||||
Logger::Logger(Logger::ELogType logtype, std::string filename, int edit) : line_(edit)
|
||||
{
|
||||
auto index = filename.find_last_of('\\');
|
||||
if (index != std::string::npos)
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
Logger(Logger::ELogType logType, std::string filename, int lineEdit);
|
||||
Logger(Logger::ELogType logType, std::string filename, int edit);
|
||||
~Logger();
|
||||
std::stringstream& Stream() { return oss_; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user