mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现系统管理表格操作接口、分页操作
This commit is contained in:
@@ -51,7 +51,7 @@ bool DaoEntity::execOnce(string sql)
|
||||
return db->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::execOnce(string sql, vector<DataFields>& result)
|
||||
bool DaoEntity::execOnce(string sql, vector<Fields>& result)
|
||||
{
|
||||
auto db = make_shared<MysqlClient>(DaoEntity::option_);
|
||||
return db->exec(sql, result);
|
||||
@@ -72,18 +72,18 @@ bool DaoEntity::exec(string sql)
|
||||
return db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::exec(string sql, vector<DataFields>& result)
|
||||
bool DaoEntity::exec(string sql, vector<Fields>& result)
|
||||
{
|
||||
return db_->exec(sql, result);
|
||||
}
|
||||
|
||||
bool DaoEntity::insertFields(DataFields& fields)
|
||||
bool DaoEntity::insertFields(Fields& fields)
|
||||
{
|
||||
string sql = fields.get_insert_sql(tableName_);
|
||||
return this->db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::insertFields(vector<DataFields>& vec_fields)
|
||||
bool DaoEntity::insertFields(vector<Fields>& vec_fields)
|
||||
{
|
||||
//"insert into TABLE () values ()";
|
||||
string sql = "insert into " + tableName_;
|
||||
@@ -128,7 +128,7 @@ bool DaoEntity::insertFields(vector<DataFields>& vec_fields)
|
||||
return this->db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::duplicateUpdate(DataFields& fields, vector<string>& keys)
|
||||
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;
|
||||
@@ -149,7 +149,7 @@ bool DaoEntity::duplicateUpdate(DataFields& fields, vector<string>& keys)
|
||||
{
|
||||
s_data += ",";
|
||||
}
|
||||
s_data += (k + "='" + fields.getStr(k) + "'");
|
||||
s_data += (k + "='" + fields.value(k) + "'");
|
||||
}
|
||||
string sql = "INSERT INTO " + tableName_ + "(" + s_key + ") VALUES (" + s_val + ") ON duplicate KEY UPDATE " + s_data;
|
||||
return this->db_->exec(sql);
|
||||
@@ -163,19 +163,19 @@ bool DaoEntity::duplicateUpdate(DataFields& fields, vector<string>& keys)
|
||||
//}
|
||||
|
||||
|
||||
bool DaoEntity::queryFields(string keys, const string& sql_c, vector<DataFields>& result)
|
||||
bool DaoEntity::queryFields(string keys, const string& sql_c, vector<Fields>& result)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "SELECT " + keys + " FROM " << tableName_ << (" " + sql_c) << "; ";
|
||||
return this->db_->exec(oss.str(), result);
|
||||
}
|
||||
|
||||
bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& pageinfo, vector<DataFields>& result)
|
||||
bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, vector<Fields>& result)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "SELECT count(1) total FROM `" << tableName_ << "` " << sql_c << ";";
|
||||
|
||||
vector<DataFields> res_total;
|
||||
vector<Fields> res_total;
|
||||
if (!this->db_->exec(oss.str().c_str(), res_total))
|
||||
{
|
||||
return false;
|
||||
@@ -183,27 +183,26 @@ bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& pageinfo
|
||||
|
||||
if (res_total.size() <= 0)
|
||||
{
|
||||
pageinfo.total = 0;
|
||||
page.total = 0;
|
||||
return true;
|
||||
}
|
||||
pageinfo.total = res_total[0].getInt("total");
|
||||
if (pageinfo.total <= 0)
|
||||
page.total = res_total[0].getInt("total");
|
||||
if (page.total <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
pageinfo.pageCount = pageinfo.total / pageinfo.pageSize + (pageinfo.total % pageinfo.pageSize > 0 ? 1 : 0);
|
||||
oss.str("");
|
||||
if (pageinfo.pageIndex <= 0)
|
||||
if (page.index <= 0)
|
||||
{
|
||||
pageinfo.pageIndex = 1;
|
||||
page.index = 1;
|
||||
}
|
||||
int start = (pageinfo.pageIndex - 1) * pageinfo.pageSize;
|
||||
oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << sql_c << " LIMIT " << start << "," << pageinfo.pageSize << ";";
|
||||
int start = (page.index - 1) * page.size;
|
||||
oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << sql_c << " LIMIT " << start << "," << page.size << ";";
|
||||
return this->db_->exec(oss.str().c_str(), result);
|
||||
}
|
||||
|
||||
bool DaoEntity::updateFields(DataFields& fields, const string& sql_c)
|
||||
bool DaoEntity::updateFields(Fields& fields, const string& sql_c)
|
||||
{
|
||||
string sql = fields.get_update_sql(tableName_, sql_c);
|
||||
std::cout << sql;
|
||||
@@ -215,7 +214,7 @@ bool DaoEntity::updateFields(DataFields& fields, const string& sql_c)
|
||||
return this->db_->exec(sql.c_str());
|
||||
}
|
||||
|
||||
bool DaoEntity::updateFields(DataFields& fields, vector<string> vec_keys, const string& sql_c)
|
||||
bool DaoEntity::updateFields(Fields& fields, vector<string> vec_keys, const string& sql_c)
|
||||
{
|
||||
string sql = fields.get_update_sql(tableName_, vec_keys, sql_c);
|
||||
if (sql_c.empty())
|
||||
|
||||
Reference in New Issue
Block a user