修改运行监控场站及设备信息查询接口

This commit is contained in:
lixiaoyuan
2025-09-06 15:23:07 +08:00
parent aca9a8f0ae
commit 566a3b050c
17 changed files with 468 additions and 302 deletions

View File

@@ -12,18 +12,18 @@ DaoEntity::DaoEntity(string tb_name)
//opts.password = "123456";
//opts.port = 3306;
//opts.dbname = "pvb";
db_ = make_shared<MysqlClient>(DaoEntity::option);
if (!db_->isConnected())
db = make_shared<MysqlClient>(DaoEntity::option);
if (!db->isConnected())
{
//Global::data().status_msg = "数据库连接异常!";
//PvInstance::send_user_event(nullptr, EUserEvent::ALARM_DB, "数据库连接异常!");
}
tableName_ = tb_name;
tableName = tb_name;
}
DaoEntity::~DaoEntity()
{
db_ = nullptr;
db = nullptr;
}
MysqlOption& DaoEntity::mysqlOption()
@@ -58,34 +58,34 @@ bool DaoEntity::execOnce(string sql, vector<Fields>& result)
void DaoEntity::setTableName(string tb_name)
{
tableName_ = tb_name;
tableName = tb_name;
}
bool DaoEntity::isConnected()
{
return db_->isConnected();
return db->isConnected();
}
int DaoEntity::exec(string sql)
{
return db_->exec(sql);
return db->exec(sql);
}
int DaoEntity::exec(string sql, vector<Fields>& result)
{
return db_->exec(sql, result);
return db->exec(sql, result);
}
int DaoEntity::insertFields(Fields& fields)
{
string sql = fields.toSqlInsert(tableName_);
return this->db_->exec(sql);
string sql = fields.toSqlInsert(tableName);
return this->db->exec(sql);
}
int DaoEntity::insertFields(vector<Fields>& vec_fields)
{
//"insert into TABLE () values ()";
string sql = "insert into " + tableName_;
string sql = "insert into " + tableName;
bool first = true;
string keys;
string values;
@@ -100,16 +100,10 @@ int DaoEntity::insertFields(vector<Fields>& vec_fields)
const string& v = item.second;
if (first)
{
if (!keys.empty())
{
keys += ",";
}
if (!keys.empty()) { keys += ","; }
keys += k;
}
if (!values.empty())
{
values += ",";
}
if (!values.empty()) { values += ","; }
values += ("'" + v + "'");
}
if (first)
@@ -124,7 +118,7 @@ int DaoEntity::insertFields(vector<Fields>& vec_fields)
}
}
sql += ";";
return this->db_->exec(sql);
return this->db->exec(sql);
}
int DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
@@ -150,8 +144,8 @@ int DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
}
str += (k + "='" + fields.value(k) + "'");
}
string sql = "INSERT INTO " + tableName_ + "(" + key + ") VALUES (" + val + ") ON duplicate KEY UPDATE " + str;
return this->db_->exec(sql);
string sql = "INSERT INTO " + tableName + "(" + key + ") VALUES (" + val + ") ON duplicate KEY UPDATE " + str;
return this->db->exec(sql);
}
//void DaoEntity::queryFields(const string& condition, DaoPageinfo& pageinfo, vector<map<string, string>>& result)
@@ -164,18 +158,18 @@ int DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
int DaoEntity::queryFields(string keys, const string& condition, vector<Fields>& result)
{
ostringstream oss;
oss << "SELECT " + keys + " FROM " << tableName_ << (" " + condition) << "; ";
return this->db_->exec(oss.str(), result);
oss << "SELECT " + keys + " FROM " << tableName << (" " + condition) << "; ";
return this->db->exec(oss.str(), result);
}
int DaoEntity::queryFields(string keys, const string& condition, PageInfo& page, vector<Fields>& result)
{
int err = 0;
ostringstream oss;
oss << "SELECT count(1) total FROM `" << tableName_ << "` " << condition << ";";
oss << "SELECT count(1) total FROM `" << tableName << "` " << condition << ";";
vector<Fields> res_total;
if (err = this->db_->exec(oss.str().c_str(), res_total))
if (err = this->db->exec(oss.str().c_str(), res_total))
{
return err;
}
@@ -192,23 +186,20 @@ int DaoEntity::queryFields(string keys, const string& condition, PageInfo& page,
}
oss.str("");
if (page.index <= 0)
{
page.index = 1;
}
if (page.index <= 0) { page.index = 1; }
int start = (page.index - 1) * page.size;
oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << condition << " LIMIT " << start << "," << page.size << ";";
return this->db_->exec(oss.str().c_str(), result);
oss << "SELECT " << keys << " FROM `" << tableName << "` " << condition << " LIMIT " << start << "," << page.size << ";";
return this->db->exec(oss.str().c_str(), result);
}
int DaoEntity::updateFields(Fields& fields, const string& condition)
{
string sql = fields.toSqlUpdate(tableName_, condition);
return this->db_->exec(sql);
string sql = fields.toSqlUpdate(tableName, condition);
return this->db->exec(sql);
}
int DaoEntity::updateFields(Fields& fields, vector<string> vecKeys, const string& condition)
{
string sql = fields.toSqlUpdate(tableName_, vecKeys, condition);
return this->db_->exec(sql);
string sql = fields.toSqlUpdate(tableName, vecKeys, condition);
return this->db->exec(sql);
}