实现策略配置功能

This commit is contained in:
lixiaoyuan
2025-08-28 18:42:37 +08:00
parent 8f6c83147b
commit dda905cda0
47 changed files with 1311 additions and 863 deletions

View File

@@ -2,7 +2,7 @@
//#include "PvInstance.h"
//#include "spdlogger.h"
MysqlOption DaoEntity::option_;
MysqlOption DaoEntity::option;
DaoEntity::DaoEntity(string tb_name)
{
@@ -12,7 +12,7 @@ DaoEntity::DaoEntity(string tb_name)
//opts.password = "123456";
//opts.port = 3306;
//opts.dbname = "pvb";
db_ = make_shared<MysqlClient>(DaoEntity::option_);
db_ = make_shared<MysqlClient>(DaoEntity::option);
if (!db_->isConnected())
{
//Global::data().status_msg = "数据库连接异常!";
@@ -28,15 +28,15 @@ DaoEntity::~DaoEntity()
MysqlOption& DaoEntity::mysqlOption()
{
return DaoEntity::option_;
return DaoEntity::option;
}
void DaoEntity::setOption(std::string host, int port, std::string user, std::string pwd, std::string dbname)
{
option_.host = host;
option_.port = port;
option_.user = user;
option_.password = pwd;
option_.dbname = dbname;
option.host = host;
option.port = port;
option.user = user;
option.password = pwd;
option.dbname = dbname;
}
std::shared_ptr<DaoEntity> DaoEntity::create(string tb_name)
@@ -46,13 +46,13 @@ std::shared_ptr<DaoEntity> DaoEntity::create(string tb_name)
bool DaoEntity::execOnce(string sql)
{
auto db = make_shared<MysqlClient>(DaoEntity::option_);
auto db = make_shared<MysqlClient>(DaoEntity::option);
return db->exec(sql);
}
bool DaoEntity::execOnce(string sql, vector<Fields>& result)
{
auto db = make_shared<MysqlClient>(DaoEntity::option_);
auto db = make_shared<MysqlClient>(DaoEntity::option);
return db->exec(sql, result);
}
@@ -130,27 +130,27 @@ bool DaoEntity::insertFields(vector<Fields>& vec_fields)
bool DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
{
//insert into device_attr(device_id, attr_id, attr_val) values('26', 'model', '型号1') on duplicate key update attr_val='型号1';
string s_key;
string s_val;
string key;
string val;
for (auto& item : fields.map())
{
if (!s_key.empty())
if (!key.empty())
{
s_key += ","; s_val += ",";
key += ","; val += ",";
}
s_key += (item.first);
s_val += ("'" + item.second + "'");
key += (item.first);
val += ("'" + item.second + "'");
}
string s_data;
string str;
for (auto& k : keys)
{
if (!s_data.empty())
if (!str.empty())
{
s_data += ",";
str += ",";
}
s_data += (k + "='" + fields.value(k) + "'");
str += (k + "='" + fields.value(k) + "'");
}
string sql = "INSERT INTO " + tableName_ + "(" + s_key + ") VALUES (" + s_val + ") ON duplicate KEY UPDATE " + s_data;
string sql = "INSERT INTO " + tableName_ + "(" + key + ") VALUES (" + val + ") ON duplicate KEY UPDATE " + str;
return this->db_->exec(sql);
}