mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
完成系统管理web端功能,实现系统管理服务端接口,实现登录功能
This commit is contained in:
@@ -7,6 +7,21 @@
|
||||
#include "common/Logger.h"
|
||||
#include "Snowflake.h"
|
||||
#include "app/Dao.h"
|
||||
#include "app/Admin.h"
|
||||
#include "app/Device.h"
|
||||
|
||||
static void VariantListRes(std::vector<DataFields>& data, QVariantList& listRes)
|
||||
{
|
||||
for (auto& fields: data)
|
||||
{
|
||||
QVariantMap row;
|
||||
for (auto& field: fields.fields())
|
||||
{
|
||||
row[field.first.c_str()] = field.second.c_str();
|
||||
}
|
||||
listRes << row;
|
||||
}
|
||||
}
|
||||
|
||||
static void JSsetResPaginaion(QVariantMap& result, std::vector<DataFields>& data, int page, int pageSize, int count, int code, string err)
|
||||
{
|
||||
@@ -47,16 +62,16 @@ void MyWebHandler::log(const QString& text)
|
||||
|
||||
QString MyWebHandler::readFile(const QString& filename)
|
||||
{
|
||||
//std::string filePath = "assets/html/系统管理/index.html"; //filename.toStdString();
|
||||
std::filesystem::path filePath = std::filesystem::u8path(filename.toStdString());
|
||||
XLOGD() << "[cppNative] readFile: " << filePath;
|
||||
std::string fileName = filename.toStdString();
|
||||
XLOGD() << "[cppNative] readFile: " << fileName;
|
||||
std::filesystem::path filePath = std::filesystem::u8path(fileName);
|
||||
std::ifstream ifs(filePath);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
// 获取文件大小
|
||||
ifs.seekg(0, std::ios::end);
|
||||
std::streamsize size = ifs.tellg();
|
||||
XLOGD() << "[cppNative] readFile [" << filePath << "] success, data size=" << size;
|
||||
XLOGD() << "[cppNative] readFile [" << fileName << "] success, data size=" << size;
|
||||
|
||||
// 定位回文件开始,读取文件内容到缓冲区
|
||||
ifs.seekg(0, std::ios::beg);
|
||||
@@ -67,11 +82,23 @@ QString MyWebHandler::readFile(const QString& filename)
|
||||
}
|
||||
else
|
||||
{
|
||||
XLOGD() << "[cppNative] readFile [" << filePath << "] failed.";
|
||||
XLOGD() << "[cppNative] readFile [" << fileName << "] failed.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void MyWebHandler::login(const QString& username, const QString& passwd)
|
||||
{
|
||||
XLOGI() << "login request: " << username.toStdString();
|
||||
Errcode ecode = Admin::instance().longin(username.toStdString(), passwd.toStdString());
|
||||
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
emit signalLongin(username, int(ecode));
|
||||
}
|
||||
|
||||
void MyWebHandler::loginOut(const QString& username)
|
||||
{
|
||||
}
|
||||
|
||||
QVariantMap MyWebHandler::queryUserList(int page, int pageSize)
|
||||
{
|
||||
@@ -102,7 +129,7 @@ int MyWebHandler::insertUser(QVariantMap params)
|
||||
|
||||
|
||||
// 设置用户角色
|
||||
std::string user_id = fields.get_str("user_id");
|
||||
std::string user_id = fields.getStr("user_id");
|
||||
if (params.contains("role_id")) {
|
||||
|
||||
int role_id = params["role_id"].toInt();
|
||||
@@ -161,16 +188,24 @@ int MyWebHandler::updateUser(const QString& userId, QVariantMap params)
|
||||
// 角色管理接口
|
||||
QVariantMap MyWebHandler::queryRoleList(int page, int pageSize)
|
||||
{
|
||||
QVariantMap result;
|
||||
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("role");
|
||||
bool ret = dao->exec("SELECT * FROM role;", res);
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
|
||||
XLOGD() << "[cppNative] queryRoleList " << (ret ? "success." : "failed.");
|
||||
|
||||
//QtConcurrent::run([this]()
|
||||
// {
|
||||
// XLOGD() << "[cppNative] lxy ========== queryRoleList 1111111111111111111111 ";
|
||||
// QThread::msleep(2000);
|
||||
// XLOGD() << "[cppNative] lxy ========== queryRoleList 2222222222222222222222 ";
|
||||
// });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertRole(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
@@ -313,6 +348,66 @@ QVariantMap MyWebHandler::queryDeviceList(int page, int pageSize)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void JSgetReqParamSql(QString key, QVariantMap& params, std::string& sql)
|
||||
{
|
||||
if (params.contains(key))
|
||||
{
|
||||
auto& v = params[key];
|
||||
std::string typeName = v.typeName();
|
||||
|
||||
|
||||
XLOGD() << key.toStdString() << " : " << typeName;
|
||||
if (!sql.empty()) sql += ",";
|
||||
|
||||
if ("QVariantList" == typeName)
|
||||
{
|
||||
std::string str = "";
|
||||
for (auto& item : v.toList())
|
||||
{
|
||||
if (!str.empty()) str += ",";
|
||||
str += ("'" + item.toString().toStdString() + "'");
|
||||
}
|
||||
sql += ("`" + key.toStdString() + "` IN (" + str + ")");
|
||||
XLOGD() << "QVariantList";
|
||||
}
|
||||
else if ("QString" == typeName)
|
||||
{
|
||||
// 如果是数组, 需要处理数组格式: ["","",""]
|
||||
sql += ("`" + key.toStdString() + "`='" + v.toString().toStdString() + "'");
|
||||
XLOGD() << "QString";
|
||||
}
|
||||
else {
|
||||
XLOGD() << "???";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVariantList MyWebHandler::queryDevice(QVariantMap params)
|
||||
{
|
||||
XLOGD() << "MyWebHandler::queryDevice -- params.size=" << params.size();
|
||||
|
||||
QVariantList result;
|
||||
|
||||
std::string sqlc = "";
|
||||
JSgetReqParamSql("type", params, sqlc);
|
||||
|
||||
if (sqlc.empty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string sql = "SELECT * FROM device WHERE " + sqlc + ";";
|
||||
auto dao = DAO::get("device");
|
||||
std::vector<DataFields> res;
|
||||
bool ret = dao->exec(sql, res);
|
||||
XLOGD() << "sql=" << sql;
|
||||
XLOGD() << "queryDevice: size=" << res.size();
|
||||
|
||||
VariantListRes(res, result);
|
||||
|
||||
XLOGD() << "queryDevice: result size=" << result.size();
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertDevice(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
@@ -600,5 +695,31 @@ QVariantMap MyWebHandler::querySecRecordList(int page, int pageSize)
|
||||
return result;
|
||||
};
|
||||
|
||||
int MyWebHandler::insertSecRecord(QVariantMap params) {};
|
||||
int MyWebHandler::updateSecRecord(const QString& policyId, QVariantMap params) {};
|
||||
int MyWebHandler::insertSecRecord(QVariantMap params) { return 0; };
|
||||
int MyWebHandler::updateSecRecord(const QString& policyId, QVariantMap params) { return 0; };
|
||||
|
||||
|
||||
QVariantList MyWebHandler::getDeviceInfo(const QVariantList& types)
|
||||
{
|
||||
std::vector<std::shared_ptr<DeviceEntity>> vecDevice;
|
||||
for (auto item: types)
|
||||
{
|
||||
int deviceType = item.toInt();
|
||||
auto vecRes = Device::getDeviceByType(deviceType);
|
||||
vecDevice.insert(vecDevice.end(), vecRes.begin(), vecRes.end());
|
||||
}
|
||||
|
||||
QVariantList result;
|
||||
for (auto& device: vecDevice)
|
||||
{
|
||||
QVariantMap row;
|
||||
row["device_id"] = device->deviceId;
|
||||
row["name"] = device->name.c_str();
|
||||
row["type"] = device->type;
|
||||
row["status"] = device->status;
|
||||
row["online"] = device->online;
|
||||
row["err"] = device->err;
|
||||
result << row;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user