实现削峰套利策略的编辑页面

This commit is contained in:
lixiaoyuan
2025-08-26 18:36:25 +08:00
parent 7fe51ea362
commit 8f6c83147b
37 changed files with 1506 additions and 729 deletions

View File

@@ -41,8 +41,7 @@ void DaoEntity::setOption(std::string host, int port, std::string user, std::str
std::shared_ptr<DaoEntity> DaoEntity::create(string tb_name)
{
std::shared_ptr<DaoEntity> dao = std::make_shared<DaoEntity>(tb_name);
return (dao->isConnected() ? dao : nullptr);
return std::make_shared<DaoEntity>(tb_name);
}
bool DaoEntity::execOnce(string sql)
@@ -79,7 +78,7 @@ bool DaoEntity::exec(string sql, vector<Fields>& result)
bool DaoEntity::insertFields(Fields& fields)
{
string sql = fields.get_insert_sql(tableName_);
string sql = fields.toSqlInsert(tableName_);
return this->db_->exec(sql);
}
@@ -95,7 +94,7 @@ bool DaoEntity::insertFields(vector<Fields>& vec_fields)
{
keys = "";
values = "";
for (auto& item : field.fields())
for (auto& item : field.map())
{
const string& k = item.first;
const string& v = item.second;
@@ -133,7 +132,7 @@ 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;
for (auto& item : fields.fields())
for (auto& item : fields.map())
{
if (!s_key.empty())
{
@@ -162,18 +161,17 @@ bool DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
// });
//}
bool DaoEntity::queryFields(string keys, const string& sql_c, vector<Fields>& result)
bool DaoEntity::queryFields(string keys, const string& condition, vector<Fields>& result)
{
ostringstream oss;
oss << "SELECT " + keys + " FROM " << tableName_ << (" " + sql_c) << "; ";
oss << "SELECT " + keys + " FROM " << tableName_ << (" " + condition) << "; ";
return this->db_->exec(oss.str(), result);
}
bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, vector<Fields>& result)
bool DaoEntity::queryFields(string keys, const string& condition, PageInfo& page, vector<Fields>& result)
{
ostringstream oss;
oss << "SELECT count(1) total FROM `" << tableName_ << "` " << sql_c << ";";
oss << "SELECT count(1) total FROM `" << tableName_ << "` " << condition << ";";
vector<Fields> res_total;
if (!this->db_->exec(oss.str().c_str(), res_total))
@@ -186,7 +184,7 @@ bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, ve
page.total = 0;
return true;
}
page.total = res_total[0].getInt("total");
page.total = res_total[0].get<int>("total");
if (page.total <= 0)
{
return true;
@@ -198,29 +196,18 @@ bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, ve
page.index = 1;
}
int start = (page.index - 1) * page.size;
oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << sql_c << " LIMIT " << start << "," << page.size << ";";
oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << condition << " LIMIT " << start << "," << page.size << ";";
return this->db_->exec(oss.str().c_str(), result);
}
bool DaoEntity::updateFields(Fields& fields, const string& sql_c)
bool DaoEntity::updateFields(Fields& fields, const string& condition)
{
string sql = fields.get_update_sql(tableName_, sql_c);
std::cout << sql;
if (sql_c.empty())
{
//Spdlogger::error("[DB] update condition is empty, not exec, sql={}", sql);
return false;
}
return this->db_->exec(sql.c_str());
string sql = fields.toSqlUpdate(tableName_, condition);
return this->db_->exec(sql);
}
bool DaoEntity::updateFields(Fields& fields, vector<string> vec_keys, const string& sql_c)
bool DaoEntity::updateFields(Fields& fields, vector<string> vecKeys, const string& condition)
{
string sql = fields.get_update_sql(tableName_, vec_keys, sql_c);
if (sql_c.empty())
{
//Spdlogger::error("[DB] update condition is empty, not exec, sql={}", sql);
return false;
}
return this->db_->exec(sql.c_str());
string sql = fields.toSqlUpdate(tableName_, vecKeys, condition);
return this->db_->exec(sql);
}