mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现系统管理表格操作接口、分页操作
This commit is contained in:
@@ -10,12 +10,12 @@ enum class EnDatabaseErr
|
||||
SUCCESS = 0,
|
||||
};
|
||||
|
||||
std::shared_ptr<DaoEntity> DAO::get(std::string tableName)
|
||||
std::shared_ptr<DaoEntity> DAO1::get(std::string tableName)
|
||||
{
|
||||
return std::make_shared<DaoEntity>(tableName);
|
||||
}
|
||||
|
||||
Errcode DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string passwd, std::string& err)
|
||||
Errcode DAO1::login(std::shared_ptr<DaoEntity> dao, std::string account, std::string passwd, std::string& err)
|
||||
{
|
||||
std::string t = Utils::timeStr();
|
||||
if (!dao)
|
||||
@@ -25,35 +25,35 @@ Errcode DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::str
|
||||
if (!dao->isConnected())
|
||||
{
|
||||
err = "数据库连接错误";
|
||||
DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return Errcode::ERR_DB_CONN;
|
||||
}
|
||||
|
||||
std::string sql = "SELECT * FROM user WHERE account='" + account + "';";
|
||||
|
||||
std::vector<DataFields> res;
|
||||
std::vector<Fields> res;
|
||||
bool ret = dao->exec(sql, res);
|
||||
if (!ret)
|
||||
{
|
||||
err = "数据库操作错误";
|
||||
DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return Errcode::ERR_DB_CONN;
|
||||
}
|
||||
if (res.size() <=0)
|
||||
{
|
||||
err = "用户不存在";
|
||||
DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err);
|
||||
return Errcode::ERR_LOGIN_USER_NOTEXIST;
|
||||
}
|
||||
DataFields& fields = res[0];
|
||||
std::string userId = fields.getStr("user_id");
|
||||
Fields& fields = res[0];
|
||||
std::string userId = fields.value("user_id");
|
||||
int loginCount = fields.getInt("login_count");
|
||||
|
||||
// 判断密码
|
||||
if (passwd != fields.getStr("passwd"))
|
||||
if (passwd != fields.value("passwd"))
|
||||
{
|
||||
err = "密码错误";
|
||||
DAO::writeSystemLog(dao, 2, userId, account, "用户登录失败:" + err);
|
||||
DAO1::writeSystemLog(dao, 2, userId, account, "用户登录失败:" + err);
|
||||
return Errcode::ERR_LOGIN_PASSWD;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,11 @@ Errcode DAO::login(std::shared_ptr<DaoEntity> dao, std::string account, std::str
|
||||
XLOGE() << "更新用户登录信息失败:sql=" << sql;
|
||||
}
|
||||
|
||||
DAO::writeSystemLog(dao, 2, userId, account, "用户登录成功");
|
||||
DAO1::writeSystemLog(dao, 2, userId, account, "用户登录成功");
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
bool DAO::writeSystemLog(std::shared_ptr<DaoEntity> dao, int type, std::string userId, std::string account, std::string text)
|
||||
bool DAO1::writeSystemLog(std::shared_ptr<DaoEntity> dao, int type, std::string userId, std::string account, std::string text)
|
||||
{
|
||||
if (!dao)
|
||||
{
|
||||
@@ -84,7 +84,7 @@ bool DAO::writeSystemLog(std::shared_ptr<DaoEntity> dao, int type, std::string u
|
||||
|
||||
// 数据库写入登录日志
|
||||
dao->setTableName("system_log");
|
||||
DataFields fieldsLog;
|
||||
Fields fieldsLog;
|
||||
fieldsLog.set("log_id", Snowflake::instance().getIdStr());
|
||||
fieldsLog.set("type", 2);
|
||||
fieldsLog.set("user_id", userId);
|
||||
@@ -96,7 +96,7 @@ bool DAO::writeSystemLog(std::shared_ptr<DaoEntity> dao, int type, std::string u
|
||||
}
|
||||
|
||||
|
||||
bool DAO::queryUser(std::vector<DataFields>& res)
|
||||
bool DAO1::queryUser(std::vector<Fields>& res)
|
||||
{
|
||||
std::shared_ptr<DaoEntity> dao = std::make_shared<DaoEntity>("");
|
||||
if (!dao->isConnected())
|
||||
@@ -108,7 +108,7 @@ bool DAO::queryUser(std::vector<DataFields>& res)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DAO::insertUser(DataFields& fields)
|
||||
int DAO1::insertUser(Fields& fields)
|
||||
{
|
||||
std::shared_ptr<DaoEntity> dao = std::make_shared<DaoEntity>("user");
|
||||
if (!dao->isConnected())
|
||||
@@ -116,10 +116,10 @@ int DAO::insertUser(DataFields& fields)
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string account = fields.getStr("account");
|
||||
std::string account = fields.value("account");
|
||||
|
||||
// step1: 查询
|
||||
std::vector<DataFields> res;
|
||||
std::vector<Fields> res;
|
||||
bool ret = dao->exec("SELECT * from user WHERE account='" + account + "';", res);
|
||||
if (!ret)
|
||||
{
|
||||
@@ -136,7 +136,7 @@ int DAO::insertUser(DataFields& fields)
|
||||
return (ret) ? 0 : 1;
|
||||
}
|
||||
|
||||
int DAO::updateUserById(std::string id, DataFields& fields)
|
||||
int DAO1::updateUserById(std::string id, Fields& fields)
|
||||
{
|
||||
std::shared_ptr<DaoEntity> dao = std::make_shared<DaoEntity>("user");
|
||||
if (!dao->isConnected())
|
||||
|
||||
Reference in New Issue
Block a user