Files
energy_storage/src/pv/pages/PageSysmgrPop.cpp

518 lines
19 KiB
C++
Raw Normal View History

#include "PageSysmgrPop.h"
#include "app/Application.h"
#include "database/Dao.h"
#include "database/DataModelDef.h"
#include "common/Snowflake.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageTable ===
PageTable::PageTable(PARAM* p) : PvMask(p)
{
table = std::make_shared<PvTable>(p, 0, 20, 210, 1880, pageSize, option);
table->setOperateCallback([=](int row, int col, std::string text) { this->onOperate(row, col, text); });
pagination = std::make_shared<PvPagination>(p, 0, 20, 780, 20);
pagination->setCallback([=](int index)
{
pageIndex = index;
this->updateDataFromDB();
});
}
std::shared_ptr<PvPopWidget> PageTable::addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys)
{
std::shared_ptr<PvPopWidget> pop = std::make_shared<PvPopWidget>(p, w, h, name);
pop->lineValWidth = w0;
pop->setPrimaryKeys(primaryKeys);
pop->setCallbackConfirm([=]()
{
auto fields = pop->getData();
std::string err = this->onValidation(pop, fields);
pop->setMsg(err);
if (err.empty())
{
XLOGD() << "POP get: data=" << fields.toStr();
if (pop->status == POP_OPER_EDIT) { pop->checkChangedData(fields); }
XLOGD() << "POP get: data=" << fields.toStr();
table->mappingData(fields);
XLOGD() << "POP get: data=" << fields.toStr();
err = this->onPopConfirm(pop, fields);
pop->setMsg(err);
if (err.empty())
{
this->hidePop(0);
this->updateDataFromDB();
};
}
});
pop->show(0);
vecPop.push_back(pop);
return pop;
}
void PageTable::showPop(int index, std::string oper, Fields& fields)
{
XLOGD() << "POP set: data=" << fields.toStr();
table->mappingData(fields);
XLOGD() << "POP set: data=" << fields.toStr();
if (index < vecPop.size())
{
auto& pop = vecPop[index];
pop->show(true);
pop->setStatus(oper);
pop->setData(fields);
pop->setMsg("");
}
}
void PageTable::hidePop(int index)
{
if (index < vecPop.size())
{
vecPop[index]->show(false);
}
}
void PageTable::updateDataFromDB()
{
std::vector<Fields> result;
PageInfo pageInfo;
pageInfo.size = pageSize;
pageInfo.index = pageIndex;
this->onQueryTable(pageInfo, result);
for (int i = 0; i<table->rows(); ++i)
{
if (i<result.size())
{
auto& fields = result[i];
table->setRowData(i, result[i]);
}
else
{
table->setRowVisible(i, false);
}
}
pagination->setPage(pageInfo.index, pageInfo.total/pageInfo.size + int(pageInfo.total%pageInfo.size != 0));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageUser ===
PageUser::PageUser(PARAM* p, EPvCode pvcode) :PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMUser::USER_ID, "用户编号", 180, {});
table->addHead(DMUser::ACCOUNT, "用户名", 180, {});
table->addHead(DMUser::NAME, "姓名", 180, {});
table->addHead(DMUser::GENDER, "性别", 180, appdata.mapping.gender);
table->addHead(DMUser::AGE, "年龄", 180, {});
table->addHead(DMUser::PHONE, "手机号", 180, {});
table->addHead(DMUser::EMAIL, "邮箱", 180, {});
table->addHead(DMRole::ROLE_ID, "角色", 180, appdata.mapping.role);
table->addHead(DMUser::LOGINTIME, "上次登录时间", 200, {});
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 50, y = 80, w = 350, h = 60;
auto pop = this->addPop(700, 500, 180, "用户信息", {DMUser::USER_ID});
pop->addParamLineEdit(DMUser::USER_ID, "编号", x, y, false);
pop->addParamCombox(DMRole::ROLE_ID, "角色", x+w, y, appdata.getRoleNames());
pop->addParamLineEdit(DMUser::ACCOUNT, "用户名", x, y += h);
pop->addParamLineEdit(DMUser::NAME, "姓名", x+w, y);
pop->addParamCombox(DMUser::GENDER, "性别", x, y += h, {"", ""});
pop->addParamLineEdit(DMUser::AGE, "年龄", x+w, y);
pop->addParamLineEdit(DMUser::PHONE, "手机号", x, y += h);
pop->addParamLineEdit(DMUser::EMAIL, "邮箱", x+w, y);
}
void PageUser::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryUserList(pageInfo, result);
}
void PageUser::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
};
std::string PageUser::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (fields.value(DMUser::ACCOUNT).empty()) { return "请输入用户名"; }
return "";
};
std::string PageUser::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (pop->status == POP_OPER_NEW)
{
Errcode err = DAO::insertUser(fields);
if (err == Errcode::OK) { return ""; }
else if (err == Errcode::ERR_DB_DUPLICATE) { return "用户名已经存在"; }
else { return "系统错误"; }
}
else if (pop->status == POP_OPER_EDIT)
{
Errcode err = DAO::updateUserById(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
return "";
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageRole ===
PageRole::PageRole(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMRole::ROLE_ID, "角色编号", 200, {});
table->addHead(DMRole::NAME, "角色名称", 200, {});
table->addHead(DMRole::DESCRIBE, "角色描述", 900, {});
table->addHead(DMRole::IS_OPEN, "是否启用", 200, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 180, "角色信息", {DMUser::USER_ID});
pop->addParamLineEdit(DMRole::ROLE_ID, "编号", x, y, false);
pop->addParamLineEdit(DMRole::NAME, "名称", x, y += h);
pop->addParamCombox(DMUser::IS_OPEN, "是否启用", x, y += h, {"启用", "禁用"});
pop->addParamTextEdit(DMRole::DESCRIBE, "描述", x, y += h);
}
void PageRole::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryRoleList(pageInfo, result);
}
void PageRole::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageRole::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageRole::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePermission ===
PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMPermission::PERMISSION_ID, "权限编号", 200, {});
table->addHead(DMPermission::NAME, "权限名称", 200, {});
table->addHead(DMPermission::DESCRIBE, "权限描述", 900, {});
table->addHead(DMPermission::IS_OPEN, "是否启用", 200, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 180, "角色信息", {DMPermission::PERMISSION_ID});
pop->addParamLineEdit(DMPermission::PERMISSION_ID, "编号", x, y, false);
pop->addParamLineEdit(DMPermission::NAME, "名称", x, y += h);
pop->addParamCombox(DMPermission::IS_OPEN, "是否启用", x, y += h, {"启用", "禁用"});
pop->addParamTextEdit(DMPermission::DESCRIBE, "描述", x, y += h);
}
void PagePermission::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryPermissionList(pageInfo, result);
}
void PagePermission::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PagePermission::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PagePermission::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageStation ===
PageStation::PageStation(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMStation::STATION_ID, "场站编号", 200, {});
table->addHead(DMStation::NAME, "场站名称", 200, {});
table->addHead(DMStation::ADDRESS, "地址", 200, {});
table->addHead(DMStation::LONGITUDE, "经度", 200, {});
table->addHead(DMStation::LATITUDE, "维度", 200, {});
table->addHead(DMStation::TEL, "电话", 200, {});
table->addHead(DMStation::STATUS, "状态", 200, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 240, "场站信息", {DMStation::STATION_ID});
pop->addParamLineEdit(DMStation::STATION_ID, "编号", x, y, false);
pop->addParamLineEdit(DMStation::NAME, "名称", x, y += h);
pop->addParamLineEdit(DMStation::ADDRESS, "地址", x, y += h);
pop->addParamLineEdit(DMStation::LONGITUDE, "经度", x, y += h);
pop->addParamLineEdit(DMStation::LATITUDE, "维度", x, y += h);
pop->addParamLineEdit(DMStation::TEL, "电话", x, y += h);
pop->addParamCombox(DMStation::STATUS, "状态", x, y += h, {"启用", "禁用"});
}
void PageStation::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryStationList(pageInfo, result);
}
void PageStation::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageStation::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageStation::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (pop->status == POP_OPER_NEW)
{
Errcode err = DAO::insertStation(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
else if (pop->status == POP_OPER_EDIT)
{
Errcode err = DAO::updateStationById(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageDevice ===
PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {});
table->addHead(DMDevice::TYPE_ID, "设备类型", 120, appdata.mapping.deviceType);
table->addHead(DMDevice::NAME, "设备名称", 180, {});
table->addHead(DMDevice::CODE, "设备编码", 160, {});
table->addHead(DMDevice::MODEL, "设备型号", 160, {});
table->addHead(DMDevice::FACTORY, "厂家", 160, {});
table->addHead(DMDevice::TEL, "厂家电话", 160, {});
table->addHead(DMDevice::ATTRS, "设备参数", 460, {});
table->addHead(DMDevice::IS_OPEN, "是否启用", 120, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 50, y = 80, w = 350, h = 60;
auto pop = this->addPop(700, 520, 180, "设备信息", {DMDevice::DEVICE_ID});
pop->addParamLineEdit(DMDevice::DEVICE_ID, "设备编号", x, y, false);
pop->addParamCombox(DMDevice::TYPE_ID, "类型", x+w, y, appdata.getDeviceTypes());
pop->addParamLineEdit(DMDevice::NAME, "设备名称", x, y += h);
pop->addParamLineEdit(DMDevice::CODE, "设备编码", x+w, y);
pop->addParamLineEdit(DMDevice::MODEL, "设备型号", x, y += h);
pop->addParamLineEdit(DMDevice::FACTORY, "厂家", x+w, y);
pop->addParamLineEdit(DMDevice::TEL, "厂家电话", x, y += h);
pop->addParamCombox(DMDevice::IS_OPEN, "是否启用", x+w, y, {"启用", "禁用"});
pop->addParamLineEdit(DMDevice::ATTRS, "设备参数", x, y += h);
}
void PageDevice::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryDeviceList(pageInfo, result);
}
void PageDevice::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageDevice::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageDevice::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (pop->status == POP_OPER_NEW)
{
Errcode err = DAO::insertDevice(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
else if (pop->status == POP_OPER_EDIT)
{
Errcode err = DAO::updateDeviceById(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePolicy ===
PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMPolicy::POLICY_ID, "策略编号", 200, {});
table->addHead(DMPolicy::TYPE, "策略类型", 200, {});
table->addHead(DMPolicy::NAME, "策略名称", 200, {});
table->addHead(DMPolicy::DESCRIBE, "策略描述", 400, {});
table->addHead(DMPolicy::VALUE, "策略参数", 400, {});
table->addHead(DMPolicy::IS_OPEN, "是否启用", 200, appdata.mapping.isopen);
table->addOperate({ "编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 180, "策略信息", {DMPolicy::POLICY_ID});
pop->addParamLineEdit(DMPolicy::POLICY_ID, "编号", x, y, false);
}
void PagePolicy::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryPolicyList(pageInfo, result);
}
void PagePolicy::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PagePolicy::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PagePolicy::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageSyslog ===
PageSyslog::PageSyslog(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMSystemLog::LOG_ID, "日志编号", 160, {});
table->addHead(DMSystemLog::TYPE, "日志类型", 160, {});
table->addHead(DMSystemLog::USER_ACCOUNT, "用户", 160, {});
table->addHead(DMSystemLog::CONTENT, "日志详情", 800, {});
table->addHead(DMSystemLog::STATUS, "状态", 160, {});
table->addHead(DMSystemLog::CREATE_TIME, "记录时间", 200, {});
table->addOperate({"查看"});
}
void PageSyslog::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::querySystemLogList(pageInfo, result);
}
void PageSyslog::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageSyslog::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageSyslog::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageAlertlog ===
PageAlertlog::PageAlertlog(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMAlertLog::LOG_ID, "日志编号", 160, {});
table->addHead(DMAlertLog::TYPE, "日志类型", 160, {});
table->addHead(DMAlertLog::DEVICE_ID, "设备ID", 160, {});
table->addHead(DMAlertLog::CONTENT, "日志详情", 800, {});
table->addHead(DMAlertLog::STATUS, "状态", 160, {});
table->addHead(DMAlertLog::CREATE_TIME, "记录时间", 200, {});
table->addOperate({"查看"});
}
void PageAlertlog::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
//DAO::queryAlertLogList(pageInfo, result);
}
void PageAlertlog::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageAlertlog::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageAlertlog::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}