mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
[WEB]1.修改首页场站图标显示颜色不正确的问题,2.修改运行监控页面储能系统的运行模式和预制舱参数在页面切换时数据不显示问题
This commit is contained in:
@@ -26,7 +26,7 @@ enum class EDeviceType
|
||||
//12 水浸传感器 0
|
||||
//13 视频监控 4
|
||||
//14 冷机 0
|
||||
//15 网关 0
|
||||
GATEWAY = 15, // 网关 0
|
||||
//100 储能预制舱 1
|
||||
EMS = 101,//101 EMS 1
|
||||
PCS = 102, //102 PCS 1
|
||||
|
||||
@@ -453,8 +453,14 @@ static void JSONReadArrayItem(njson& json, int i, int& v)
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayMode(int mode, string p1, string p2, string p3)
|
||||
void Station::readGatewayMode(int deviceNo, int mode, string p1, string p2, string p3)
|
||||
{
|
||||
auto device = this->getDeviceByType(int(EDeviceType::GATEWAY), Utils::toStr(deviceNo));
|
||||
if (device)
|
||||
{
|
||||
device->online = true;
|
||||
device->ts = Utils::time();
|
||||
}
|
||||
this->gatewayParam.mode = mode;
|
||||
this->gatewayParam.param1 = p1;
|
||||
this->gatewayParam.param2 = p2;
|
||||
@@ -464,7 +470,6 @@ void Station::readGatewayMode(int mode, string p1, string p2, string p3)
|
||||
//this->setGarewayWorkMode();
|
||||
}
|
||||
|
||||
|
||||
njson json;
|
||||
if (JSON::parse(gatewayParam.param3, json))
|
||||
{
|
||||
@@ -481,8 +486,15 @@ void Station::readGatewayMode(int mode, string p1, string p2, string p3)
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayStatus(int cdzStatus, int emuStatus)
|
||||
void Station::readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus)
|
||||
{
|
||||
auto device = this->getDeviceByType(int(EDeviceType::GATEWAY), Utils::toStr(deviceNo));
|
||||
if (device)
|
||||
{
|
||||
device->online = true;
|
||||
device->ts = Utils::time();
|
||||
}
|
||||
|
||||
//充电桩 1:在线,0:离线
|
||||
if (cdzStatus >= 0)
|
||||
{
|
||||
@@ -567,6 +579,7 @@ void Station::writeStatistic()
|
||||
int64_t tDate = Utils::date();
|
||||
int64_t tDelta = tTime - tDate;
|
||||
int npos = (tTime-tDate) / 600;
|
||||
int tOffset = tDelta % 600;
|
||||
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
@@ -655,7 +668,14 @@ void Station::writeStatistic()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
int pos = npos;
|
||||
if (tOffset > 20) { pos += 1; }
|
||||
mapCacheElectIn[pos] = statData.dayElectIn;
|
||||
mapCacheElectOut[pos] = statData.dayElectOut;
|
||||
mapCacheElectCharger[pos] = 0;
|
||||
|
||||
// 预测数据源记录
|
||||
dao->setTableName("predict_day");
|
||||
|
||||
@@ -663,15 +683,15 @@ void Station::writeStatistic()
|
||||
fields.set("dt", dt);
|
||||
fields.set("station_id", stationId);
|
||||
fields.set("datatype", 1); // 1:储能充电,2:储能放电,3:充电桩充电,4:发电
|
||||
fields.set("value", MapValueToJson(npos, mapCacheElectIn));
|
||||
fields.set("value", MapValueToJson(pos, mapCacheElectIn));
|
||||
dao->duplicateUpdate(fields, {"value"});
|
||||
|
||||
fields.set("datatype", 2); // 1:储能充电,2:储能放电,3:充电桩充电,4:发电
|
||||
fields.set("value", MapValueToJson(npos, mapCacheElectOut));
|
||||
fields.set("value", MapValueToJson(pos, mapCacheElectOut));
|
||||
dao->duplicateUpdate(fields, {"value"});
|
||||
|
||||
fields.set("datatype", 3); // 1:储能充电,2:储能放电,3:充电桩充电,4:发电
|
||||
fields.set("value", MapValueToJson(npos, mapCacheElectCharger));
|
||||
fields.set("value", MapValueToJson(pos, mapCacheElectCharger));
|
||||
dao->duplicateUpdate(fields, {"value"});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ public:
|
||||
void readTHData(int deviceNo, string addr, int val);
|
||||
void readFire40Data(int deviceNo, string addr, int val);
|
||||
void readCoolingData(int deviceNo, string addr, int val);
|
||||
void readGatewayMode(int mode, string p1, string p2, string p3);
|
||||
void readGatewayStatus(int cdzStatus, int emuStatus);
|
||||
void readGatewayMode(int deviceNo, int mode, string p1, string p2, string p3);
|
||||
void readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus);
|
||||
|
||||
void setCache(int datatype, std::vector<float>& vd);
|
||||
void cache();
|
||||
|
||||
@@ -272,7 +272,6 @@ int MqttClient::onMessageArrived(char* topic, int topicLen, MQTTAsync_message* m
|
||||
int len = msg->payloadlen;
|
||||
std::string payload((const char*)msg->payload, len);
|
||||
|
||||
|
||||
// <数据方向>/<数据格式>/<厂家ID>/<指合>/<设备标识,上行可选>
|
||||
std::string direction = GetSubStr("/", topicStr);
|
||||
std::string datatype = GetSubStr("/", topicStr);
|
||||
@@ -280,46 +279,53 @@ int MqttClient::onMessageArrived(char* topic, int topicLen, MQTTAsync_message* m
|
||||
std::string command = GetSubStr("/", topicStr);
|
||||
std::string deviceCode = GetSubStr("/", topicStr);
|
||||
|
||||
|
||||
|
||||
spdlog::info("[mqtt] <<< message arrived: topic=[{},{}], len={}, payload={}", topic, msg->qos, len, payload);
|
||||
|
||||
njson json;
|
||||
bool ret = JSON::parse(payload, json);
|
||||
if (!ret)
|
||||
if (ret)
|
||||
{
|
||||
auto station = Application::data().getStationByCode(stationNo);
|
||||
if (station)
|
||||
{
|
||||
int deviceNo = -1;
|
||||
JSON::read(json, "no", deviceNo);
|
||||
if (command == "Gateway_YC")
|
||||
{
|
||||
int mode = -1;
|
||||
std::string param1;
|
||||
std::string param2;
|
||||
std::string param3 = json.dump();
|
||||
|
||||
JSON::read(json, "40001", mode);
|
||||
if (json.contains("40002")) { param1 = json["40002"].dump(); }
|
||||
if (json.contains("40021")) { param2 = json["40021"].dump(); }
|
||||
if (json.contains("40038")) { param3 = json["40038"].dump(); }
|
||||
station->readGatewayMode(deviceNo, mode, param1, param2, param3);
|
||||
}
|
||||
else if (command == "Gateway_YX")
|
||||
{
|
||||
int cdzStatus = -1;
|
||||
int emuStatus = -1;
|
||||
JSON::read(json, "cdz", cdzStatus);
|
||||
JSON::read(json, "emu", emuStatus);
|
||||
station->readGatewayStatus(deviceNo, cdzStatus, emuStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParseArrivedMessage(json, command, station);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[mqtt] get station error, clientId={}, stationId={}", clientId, stationNo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("[mqtt] json parse error.");
|
||||
return 1;
|
||||
}
|
||||
auto station = Application::data().getStationByCode(stationNo);
|
||||
if (!station)
|
||||
{
|
||||
spdlog::error("[mqtt] get station error, clientId={}, stationId={}", clientId, stationNo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (command == "Gateway_YC")
|
||||
{
|
||||
int mode = -1;
|
||||
std::string param1;
|
||||
std::string param2;
|
||||
std::string param3 = json.dump();
|
||||
|
||||
JSON::read(json, "40001", mode);
|
||||
if (json.contains("40002")) { param1 = json["40002"].dump(); }
|
||||
if (json.contains("40021")) { param2 = json["40021"].dump(); }
|
||||
if (json.contains("40038")) { param3 = json["40038"].dump(); }
|
||||
station->readGatewayMode(mode, param1, param2, param3);
|
||||
}
|
||||
else if (command == "Gateway_YX")
|
||||
{
|
||||
int cdzStatus = -1;
|
||||
int emuStatus = -1;
|
||||
JSON::read(json, "cdz", cdzStatus);
|
||||
JSON::read(json, "emu", emuStatus);
|
||||
station->readGatewayStatus(cdzStatus, emuStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParseArrivedMessage(json, command, station);
|
||||
}
|
||||
|
||||
// 必须释放消息内存!
|
||||
|
||||
@@ -31,6 +31,14 @@ MainApp::MainApp()
|
||||
//ui.weburl->setTitle("页面地址:");
|
||||
//ui.weburl->setValue("http://www.baidu.com");
|
||||
|
||||
ui.widgetMenu = std::make_shared<QWidget>(this);
|
||||
ui.widgetMenu->setObjectName("menu");
|
||||
ui.widgetMenu->setStyleSheet("#menu { background-color:rgba(120,120,120,30); border-radius:5px; }");
|
||||
//ui.widgetMenu->show();
|
||||
ui.widgetWorkspace = std::make_shared<QWidget>(this);
|
||||
ui.widgetWorkspace->setObjectName("workspace");
|
||||
ui.widgetWorkspace->setStyleSheet("#workspace { background-color:rgba(120,120,120,30); border-radius:5px; }");
|
||||
|
||||
this->initMenu();
|
||||
this->setMyLayout();
|
||||
this->onActiveMenu("系统总览");
|
||||
@@ -42,10 +50,6 @@ MainApp::MainApp()
|
||||
|
||||
void MainApp::initMenu()
|
||||
{
|
||||
ui.widgetMenu = std::make_shared<QWidget>(this);
|
||||
ui.widgetMenu->setObjectName("menu");
|
||||
ui.widgetMenu->setStyleSheet("#menu { background-color:rgba(120,120,120,80); border-radius:5px; }");
|
||||
ui.widgetMenu->show();
|
||||
ui.vecMenuItems.reserve(20);
|
||||
|
||||
ui.layoutMenu = std::make_shared<QGridLayout>(ui.widgetMenu.get());
|
||||
@@ -61,7 +65,7 @@ void MainApp::initMenu()
|
||||
// 设置列和行的伸缩因子
|
||||
ui.layoutMenu->setRowStretch(0, 0); // 设置第0列的伸缩因子为0,不伸缩
|
||||
|
||||
std::vector<std::string > menuItems = {"系统总览", "运行监控"};
|
||||
std::vector<std::string > menuItems = {"系统总览", "运行监控", "统计分析", "系统管理"};
|
||||
for (auto& name: menuItems)
|
||||
{
|
||||
|
||||
@@ -103,9 +107,9 @@ void MainApp::initMenu()
|
||||
|
||||
void MainApp::setMyLayout()
|
||||
{
|
||||
layout.main = std::make_shared<QGridLayout>(this);
|
||||
|
||||
auto Widget = this;
|
||||
|
||||
layout.main = std::make_shared<QGridLayout>(this);
|
||||
|
||||
layout.main->setObjectName(QString::fromUtf8("layout.main"));
|
||||
layout.main->setSpacing(6);
|
||||
@@ -115,9 +119,12 @@ void MainApp::setMyLayout()
|
||||
//layout->setVerticalSpacing(10); // 设置行间距为10像素
|
||||
//layout->setContentsMargins(10, 10, 10, 10); // 设置内容边距为10像素
|
||||
|
||||
|
||||
// 布局:左侧菜单widget
|
||||
ui.widgetMenu->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
|
||||
layout.main->addWidget(ui.widgetMenu.get(), 0, 0, 1, 1);
|
||||
// 布局:右侧工作区widget
|
||||
ui.widgetWorkspace->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
|
||||
layout.main->addWidget(ui.widgetWorkspace.get(), 0, 1, 1, 1);
|
||||
|
||||
// 设置列宽和行高
|
||||
layout.main->setColumnMinimumWidth(0, 200); // 设置第0列的最小宽度为100像素
|
||||
@@ -129,14 +136,26 @@ void MainApp::setMyLayout()
|
||||
//gridLayout->setRowStretch(0, 1); // 设置第0行的伸缩因子为1
|
||||
}
|
||||
|
||||
std::shared_ptr<MyWidget> MainApp::getWorkWidget(std::string name)
|
||||
{
|
||||
auto iter = ui.mapWorkWidgets.find(name);
|
||||
if (iter != ui.mapWorkWidgets.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
std::shared_ptr<MyWidget> widget {nullptr};
|
||||
if (name == "系统总览") { widget = make_shared<QWHome>(nullptr); }
|
||||
else if(name == "运行监控") { widget = make_shared<QWMonitor>(nullptr); }
|
||||
else if (name == "统计分析") { widget = make_shared<QWStatistics>(nullptr); }
|
||||
//else if (name == "预测管理") { widget = make_shared<QWPredict(nullptr); }
|
||||
else if (name == "系统管理") { widget = make_shared<QWSysmgr>(nullptr); }
|
||||
if (widget) { ui.mapWorkWidgets[name] = widget; }
|
||||
return widget;
|
||||
}
|
||||
|
||||
void MainApp::onActiveMenu(std::string name)
|
||||
{
|
||||
//ui.wigetHome->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
|
||||
//layout.main->addWidget(ui.wigetHome.get(), 0, 1, 1, 1);
|
||||
std::shared_ptr<MyWidget> widget {};
|
||||
if (name == "系统总览") { widget = (ui.wigetHome ? ui.wigetHome : (ui.wigetHome = make_shared<QWHome>(this))); }
|
||||
else if (name == "运行监控") { widget = (ui.wigetMonitor ? ui.wigetMonitor : (ui.wigetMonitor = make_shared<QWMonitor>(this))); }
|
||||
else { }
|
||||
std::shared_ptr<MyWidget> widget = getWorkWidget(name);
|
||||
|
||||
if (widget == ui.curActiveWidget) { return; }
|
||||
if (ui.curActiveWidget)
|
||||
@@ -146,15 +165,21 @@ void MainApp::onActiveMenu(std::string name)
|
||||
|
||||
if (widget)
|
||||
{
|
||||
widget->setParent(ui.widgetWorkspace.get());
|
||||
widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
|
||||
widget->show();
|
||||
layout.main->addWidget(widget.get(), 0, 1, 1, 1);
|
||||
|
||||
//layout.main->replaceWidget(ui.curActiveWidget.get(), widget.get());
|
||||
}
|
||||
|
||||
ui.curActiveWidget = widget;
|
||||
}
|
||||
|
||||
void MainApp::setWorkspaceWidget(std::shared_ptr<MyWidget> widget)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainApp::onTimer()
|
||||
{
|
||||
ui.labelDT->setText(Utils::timeStr().c_str());
|
||||
|
||||
@@ -15,6 +15,8 @@ using namespace std;
|
||||
|
||||
#include "widgets/QWHome.h"
|
||||
#include "widgets/QWMonitor.h"
|
||||
#include "widgets/QWStatistics.h"
|
||||
#include "widgets/QWSysmgr.h"
|
||||
|
||||
class MainApp : public QWidget
|
||||
{
|
||||
@@ -23,8 +25,9 @@ public:
|
||||
MainApp();
|
||||
void initMenu();
|
||||
void setMyLayout();
|
||||
|
||||
std::shared_ptr<MyWidget> getWorkWidget(std::string name);
|
||||
void onActiveMenu(std::string name);
|
||||
void setWorkspaceWidget(std::shared_ptr<MyWidget> widget);
|
||||
|
||||
private slots:
|
||||
void onTimer();
|
||||
@@ -40,10 +43,9 @@ public:
|
||||
std::shared_ptr<QGridLayout> layoutMenu;
|
||||
std::shared_ptr<QPushButton> curActiveMenuBtn;
|
||||
|
||||
std::shared_ptr<QWidget> widgetWorkspace;
|
||||
std::shared_ptr<MyWidget> curActiveWidget = nullptr;
|
||||
std::shared_ptr<MyWidget> wigetHome;
|
||||
std::shared_ptr<MyWidget> wigetMonitor;
|
||||
|
||||
std::map<std::string, std::shared_ptr<MyWidget>> mapWorkWidgets;
|
||||
} ui;
|
||||
|
||||
struct {
|
||||
|
||||
@@ -22,6 +22,12 @@ static const std::string QSS_BTN_MENU_ACTIVE =
|
||||
"QPushButton:pressed {border-width:3px 0 0 3px;border-style:inset;}"
|
||||
"QPushButton:disabled {color:rgb(150,150,150);}";
|
||||
|
||||
static const std::string QSS_BTN_TAB =
|
||||
"QPushButton {background:rgba(80,80,80,100);color:white;border-radius:3px;border:1px solid rgb(10,120,215);}"
|
||||
"QPushButton:hover {background-color:rgba(80,80,80,200);}";
|
||||
//"QPushButton:pressed {border-width:3px 0 0 3px;border-style:inset;}"
|
||||
//"QPushButton:disabled {color:rgb(150,150,150);}";
|
||||
|
||||
static const std::string QSS_LINE =
|
||||
"QLineEdit { background-color: rgb(14, 49, 66); color: #ffffff; border: 1px solid gray; border-radius: 5px; font: bold 13px; }";
|
||||
|
||||
@@ -51,6 +57,10 @@ static const std::string QSS_TABLE = // 表格整体样式
|
||||
" color: rgb(220,220,220);" // 选中文字颜色
|
||||
"}";
|
||||
|
||||
static const std::string QSS_BTN_COMBOX =
|
||||
"QComboBox { background-color: transparent; border: 1px solid rgb(18, 251, 255)}"
|
||||
"QListView::item { background-color: rgba(80,80,80,200); color: white; padding-left: 10px; }";
|
||||
|
||||
MyWidget::MyWidget(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
// 可以在这里设置样式表,也可以在其他地方设置
|
||||
@@ -82,6 +92,21 @@ MyPairLabelLine MyQUI::PairLine(QWidget* parent, int x, int y, string k, string
|
||||
return {key, value};
|
||||
}
|
||||
|
||||
std::shared_ptr<QTableWidget> MyQUI::TableWidget(QWidget* parent, int x, int y, int w, int h)
|
||||
{
|
||||
auto table = std::make_shared<QTableWidget>(parent);
|
||||
table->setGeometry(x, y, w, h);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
||||
table->horizontalHeader()->setFixedHeight(50);
|
||||
table->horizontalHeader()->setDefaultSectionSize(60);
|
||||
return table;
|
||||
}
|
||||
|
||||
void MyQUI::setTableCell(std::shared_ptr<QTableWidget> table, int row, int col, std::string text, std::string style /*= ""*/)
|
||||
{
|
||||
if (row >= table->rowCount())
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#include <QGroupBox>
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QTableWidget>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -34,9 +35,11 @@ extern const std::string QSS_BTN;
|
||||
extern const std::string QSS_BTN_ACTIVE;
|
||||
extern const std::string QSS_BTN_MENU;
|
||||
extern const std::string QSS_BTN_MENU_ACTIVE;
|
||||
extern const std::string QSS_BTN_TAB;
|
||||
extern const std::string QSS_LINE;
|
||||
|
||||
extern const std::string QSS_TABLE;
|
||||
extern const std::string QSS_BTN_COMBOX;
|
||||
|
||||
class LabelPair
|
||||
{
|
||||
@@ -82,7 +85,9 @@ public:
|
||||
|
||||
static MyPairLabelLine PairLine(QWidget* parent, int x, int y, string k, string v, bool readonly=true);
|
||||
|
||||
static std::shared_ptr<QTableWidget> TableWidget(QWidget* parent, int x, int y, int w, int h);
|
||||
|
||||
static void setTableCell(std::shared_ptr<QTableWidget> table, int row, int col, std::string text, std::string style = "");
|
||||
|
||||
|
||||
|
||||
};
|
||||
@@ -45,28 +45,16 @@ QWHome::QWHome(QWidget* parent) : MyWidget(parent)
|
||||
this->addPair("db-h", pw, 20, 50, "主机地址: ", Config::option.database.host);
|
||||
this->addPair("db-u", pw, 20, 80, "用 户 名: ", Config::option.database.user);
|
||||
|
||||
|
||||
table = std::make_shared<QTableWidget>(this);
|
||||
table->setGeometry(10, y += 130, 1190, 265);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
||||
table->horizontalHeader()->setFixedHeight(50);
|
||||
table->horizontalHeader()->setDefaultSectionSize(60);
|
||||
|
||||
QTableWidgetItem* headerItem;
|
||||
QStringList headerText_Row, headerText_Col;
|
||||
headerText_Row << "ID" << "站名" << "编号" << "状态" << "MQTT状态" << "召测(秒)"
|
||||
QStringList headerTextList;
|
||||
headerTextList << "ID" << "站名" << "编号" << "状态" << "MQTT状态" << "召测(秒)"
|
||||
<< "日充电\n电量" << "日放电\n电量" << "总充电\n电量" << "总放电\n电量"
|
||||
<< "日充电\n费用" << "日放电\n费用" << "总充电\n费用" << "总放电\n费用"
|
||||
<< "日收益" << "总收益" << "--";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, y += 130, 1190, 265);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerText_Row.size());
|
||||
table->setHorizontalHeaderLabels(headerText_Row);
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->setColumnWidth(0, 50);
|
||||
table->setColumnWidth(1, 120);
|
||||
table->setColumnWidth(2, 50);
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <QHBoxLayout>
|
||||
#include <QTableWidget>
|
||||
|
||||
|
||||
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
|
||||
@@ -38,24 +38,13 @@ QWMonitor::QWMonitor(QWidget* parent) : MyWidget(parent)
|
||||
});
|
||||
}
|
||||
|
||||
table = std::make_shared<QTableWidget>(this);
|
||||
table->setGeometry(10, y += 50, 700, 800);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
||||
table->horizontalHeader()->setFixedHeight(50);
|
||||
table->horizontalHeader()->setDefaultSectionSize(60);
|
||||
|
||||
QTableWidgetItem* headerItem;
|
||||
QStringList headerText_Row, headerText_Col;
|
||||
headerText_Row << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
QStringList headerTextList;
|
||||
headerTextList << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, y += 50, 700, 800);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerText_Row.size());
|
||||
table->setHorizontalHeaderLabels(headerText_Row);
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->setColumnWidth(0, 50);
|
||||
table->setColumnWidth(1, 60);
|
||||
table->setColumnWidth(2, 120);
|
||||
@@ -163,7 +152,8 @@ void QWMonitor::onCurrentCellChanged(int row, int col, int oldRow, int oldCol)
|
||||
curDevice = station->getDevice(deviceId);
|
||||
if (curDevice)
|
||||
{
|
||||
string info = curDevice->name;
|
||||
string info = curDevice->name + " ";
|
||||
info += (curDevice->ts > 0) ? Utils::timeStr(curDevice->ts) : "--";
|
||||
labDeviceInfo->setText(info.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
91
src/qt/widgets/QWStatistics.cpp
Normal file
91
src/qt/widgets/QWStatistics.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "QWStatistics.h"
|
||||
|
||||
#include "app/Application.h"
|
||||
#include "app/AppData.h"
|
||||
#include "app/Station.h"
|
||||
#include "database/DAO.h"
|
||||
|
||||
QWStatistics::QWStatistics(QWidget* parent) : MyWidget(parent)
|
||||
{
|
||||
comboxStation = make_shared<QComboBox>(this);
|
||||
comboxStation->setGeometry(10, 10, 200, 28);
|
||||
comboxStation->setStyleSheet(QSS_BTN_COMBOX.c_str());
|
||||
|
||||
QStringList listStation;
|
||||
listStation << "所有";
|
||||
for (auto item: Application::data().mapStation)
|
||||
{
|
||||
listStation << item.second->name.c_str();
|
||||
}
|
||||
comboxStation->addItems(listStation);
|
||||
|
||||
|
||||
QStringList headerTextList;
|
||||
headerTextList << "日期" << "日充电\n电量" << "日放电\n电量"
|
||||
<< "日充电\n电量(尖)" << "日充电\n电量(峰)" << "日充电\n电量(平)" << "日充电\n电量(谷)"
|
||||
<< "日放电\n电量(尖)" << "日放电\n电量(峰)" << "日放电\n电量(平)" << "日放电\n电量(谷)"
|
||||
<< "日充电\n费用" << "日放电\n费用" << "日收益" ;
|
||||
//<< "总充电\n电量" << "总放电\n电量"
|
||||
//<< "总充电\n电量(尖)" << "总充电\n电量(峰)" << "总充电\n电量(平)" << "总充电\n电量(谷)"
|
||||
//<< "总放电\n电量(尖)" << "总放电\n电量(峰)" << "总放电\n电量(平)" << "总放电\n电量(谷)";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, 50, 1190, 800);
|
||||
table->horizontalHeader()->setDefaultSectionSize(80);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->setColumnWidth(0, 120);
|
||||
|
||||
btnRefresh = make_shared<QPushButton>("刷新", this);
|
||||
btnRefresh->setGeometry(220, 10, 60, 30);
|
||||
//btnRefresh->setStyleSheet();
|
||||
|
||||
connect(comboxStation.get(), &QComboBox::currentIndexChanged, this, &QWStatistics::onCurrentIndexChanged);
|
||||
connect(btnRefresh.get(), &QPushButton::clicked, this, &QWStatistics::onCurrentIndexChanged);
|
||||
}
|
||||
|
||||
QWStatistics::~QWStatistics()
|
||||
{
|
||||
}
|
||||
|
||||
void QWStatistics::onCurrentIndexChanged(int index)
|
||||
{
|
||||
auto& appdata = Application::data();
|
||||
|
||||
string stationName = comboxStation->itemText(index).toStdString();
|
||||
if (stationName == "所有")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
auto station = appdata.getStationByName(stationName);
|
||||
if (station)
|
||||
{
|
||||
string sql = "SELECT * FROM stat_total_day std WHERE station_id='" + std::to_string(station->stationId)
|
||||
+ "' ORDER BY dt DESC LIMIT 100;";
|
||||
vector<Fields> result;
|
||||
DAO::exec(NULL, sql, result);
|
||||
table->clearContents();
|
||||
table->setRowCount(0);
|
||||
for (int i = 0; i<result.size(); ++i)
|
||||
{
|
||||
auto& fields = result[i];
|
||||
MyQUI::setTableCell(table, i, 0, fields.value("dt"));
|
||||
MyQUI::setTableCell(table, i, 1, fields.value("E_in"));
|
||||
MyQUI::setTableCell(table, i, 2, fields.value("E_in_J"));
|
||||
MyQUI::setTableCell(table, i, 3, fields.value("E_in_F"));
|
||||
MyQUI::setTableCell(table, i, 4, fields.value("E_in_P"));
|
||||
MyQUI::setTableCell(table, i, 5, fields.value("E_in_G"));
|
||||
MyQUI::setTableCell(table, i, 6, fields.value("E_out"));
|
||||
MyQUI::setTableCell(table, i, 7, fields.value("E_out_J"));
|
||||
MyQUI::setTableCell(table, i, 8, fields.value("E_out_F"));
|
||||
MyQUI::setTableCell(table, i, 9, fields.value("E_out_P"));
|
||||
MyQUI::setTableCell(table, i, 10, fields.value("E_out_G"));
|
||||
MyQUI::setTableCell(table, i, 11, fields.value("fee_in"));
|
||||
MyQUI::setTableCell(table, i, 12, fields.value("fee_out"));
|
||||
MyQUI::setTableCell(table, i, 13, fields.value("income"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/qt/widgets/QWStatistics.h
Normal file
19
src/qt/widgets/QWStatistics.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
|
||||
class QWStatistics : public MyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWStatistics(QWidget* parent);
|
||||
~QWStatistics();
|
||||
|
||||
public slots :
|
||||
void onCurrentIndexChanged(int index);
|
||||
|
||||
public:
|
||||
shared_ptr<QComboBox> comboxStation;
|
||||
shared_ptr<QTableWidget> table;
|
||||
shared_ptr<QPushButton> btnRefresh;
|
||||
};
|
||||
241
src/qt/widgets/QWSysmgr.cpp
Normal file
241
src/qt/widgets/QWSysmgr.cpp
Normal file
@@ -0,0 +1,241 @@
|
||||
#include "QWSysmgr.h"
|
||||
#include "common/Fields.h"
|
||||
|
||||
QWSysmgr::QWSysmgr(QWidget* parent) : MyWidget(parent)
|
||||
{
|
||||
std::vector<std::string > vecItems = {"用户管理", "权限管理", "角色管理", "场站管理", "设备管理", "策略管理", "日志管理", "告警管理"};
|
||||
vecBtnFunc.reserve(vecItems.size());
|
||||
int x = 10, y = 10;
|
||||
for (auto& itemName: vecItems)
|
||||
{
|
||||
auto btn = make_shared<QPushButton>(itemName.c_str(), this);
|
||||
btn->setGeometry(x, y, 120, 36);
|
||||
btn->setStyleSheet(QSS_BTN.c_str());
|
||||
vecBtnFunc.push_back(btn);
|
||||
x += 130;
|
||||
connect(btn.get(), &QPushButton::clicked, this, [=]()
|
||||
{
|
||||
if (btn != curActiveBtn)
|
||||
{
|
||||
if (curActiveBtn) { curActiveBtn->setStyleSheet(QSS_BTN.c_str()); }
|
||||
if (btn) { btn->setStyleSheet(QSS_BTN_ACTIVE.c_str()); }
|
||||
curActiveBtn = btn;
|
||||
this->initTable(itemName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QStringList headerTextList;
|
||||
//headerTextList << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, y += 100, 1190, 740);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->horizontalHeader()->setDefaultSectionSize(80);
|
||||
|
||||
if (vecBtnFunc.size() > 0)
|
||||
{
|
||||
curActiveBtn = vecBtnFunc[0];
|
||||
curActiveBtn->setStyleSheet(QSS_BTN_ACTIVE.c_str());
|
||||
this->initTable(curActiveBtn->text().toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
QWSysmgr::~QWSysmgr()
|
||||
{
|
||||
}
|
||||
|
||||
class TableOper
|
||||
{
|
||||
public:
|
||||
TableOper()
|
||||
{
|
||||
widget = make_shared<QWidget>();
|
||||
//auto btn = make_shared<QPushButton>(widget.get());
|
||||
//btn->setGeometry(10+mapBtn.size()*60, 10, 60, 30);
|
||||
//mapBtn["查看"] = btn;
|
||||
}
|
||||
|
||||
shared_ptr<QWidget> widget;
|
||||
map<string, shared_ptr<QPushButton>> mapBtn;
|
||||
};
|
||||
|
||||
struct VH
|
||||
{
|
||||
string key;
|
||||
string title;
|
||||
int width {0};
|
||||
VH(string k, string t, int w) : key(k), title(t), width(w)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
vector<VH> vecHeaderUser =
|
||||
{
|
||||
VH("user_id", "ID", 160),
|
||||
VH("account", "用户名", 0),
|
||||
VH("name", "姓名", 200),
|
||||
VH("gender", "性别", 0),
|
||||
VH("age", "年龄", 0),
|
||||
VH("phone", "联系方式", 0),
|
||||
VH("role_name", "角色", 200),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderPermission =
|
||||
{
|
||||
VH("permission_id", "ID", 60),
|
||||
VH("route", "路由", 160),
|
||||
VH("name", "权限名称", 0),
|
||||
VH("describe", "描述", 540),
|
||||
VH("is_open", "是否启用", 0),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderRole =
|
||||
{
|
||||
VH("role_id", "ID", 60), VH("name", "权限名称", 200), VH("describe", "描述", 600), VH("is_open", "是否启用", 0), VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderStation =
|
||||
{
|
||||
VH("station_id", "ID", 60), VH("name", "场站名称", 160), VH("code", "编号", 60), VH("address", "地址", 280), VH("lon", "经度", 0), VH("lat", "维度", 0), VH("attr", "参数", 200), VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderDevice =
|
||||
{
|
||||
VH("device_id", "ID", 60),
|
||||
VH("station_name", "所属场站", 200),
|
||||
VH("type_name", "设备类型", 200),
|
||||
VH("name", "设备名称", 340),
|
||||
VH("code", "编号", 60),
|
||||
VH("is_open", "是否启用", 0),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderPolicy =
|
||||
{
|
||||
VH("policy_id", "ID", 0),
|
||||
VH("type_name", "策略类型", 160),
|
||||
VH("name", "策略名称", 0),
|
||||
VH("describe", "描述", 200),
|
||||
VH("value", "参数", 400),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderLogSys =
|
||||
{
|
||||
VH("", "ID", 0), VH("", "日志类型", 0), VH("", "内容", 0), VH("", "状态", 0), VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderLogAlert =
|
||||
{
|
||||
VH("", "ID", 0), VH("", "告警类型", 0), VH("", "内容", 0), VH("", "状态", 0), VH("", "操作", 0)
|
||||
};
|
||||
map<string, vector<VH>> mapTableHeaderDef =
|
||||
{
|
||||
{"用户管理", vecHeaderUser},
|
||||
{"权限管理", vecHeaderPermission},
|
||||
{"角色管理", vecHeaderRole},
|
||||
{"场站管理", vecHeaderStation},
|
||||
{"设备管理", vecHeaderDevice},
|
||||
{"策略管理", vecHeaderPolicy},
|
||||
{"日志管理", vecHeaderLogSys},
|
||||
{"告警管理", vecHeaderLogAlert},
|
||||
} ;
|
||||
|
||||
#include "database/DAO.h"
|
||||
void QueryDB(const string& name, std::vector<Fields>& result)
|
||||
{
|
||||
string sql;
|
||||
if (name == "用户管理")
|
||||
{
|
||||
sql = "SELECT u.*, ur.role_id, r.name role_name FROM USER u LEFT JOIN user_role ur ON u.user_id=ur.user_id LEFT JOIN ROLE r ON r.role_id=ur.role_id;";
|
||||
|
||||
}
|
||||
else if (name == "权限管理")
|
||||
{
|
||||
sql = "SELECT * FROM permission;";
|
||||
}
|
||||
else if (name == "角色管理")
|
||||
{
|
||||
sql = "SELECT * FROM role;";
|
||||
}
|
||||
else if (name == "场站管理")
|
||||
{
|
||||
sql = "SELECT * FROM station;";
|
||||
}
|
||||
else if (name == "设备管理")
|
||||
{
|
||||
sql = "SELECT d.*, s.name station_name, ddt.name type_name FROM"
|
||||
" device d LEFT JOIN station s ON d.station_id=s.station_id"
|
||||
" LEFT JOIN def_device_type ddt ON ddt.device_type_id = d.`type`;";
|
||||
}
|
||||
else if (name == "策略管理")
|
||||
{
|
||||
sql = "SELECT p.*, dpt.name type_name FROM policy p LEFT JOIN def_policy_type dpt ON dpt.policy_type_id=p.`type`;";
|
||||
}
|
||||
else if (name == "日志管理")
|
||||
{
|
||||
}
|
||||
else if (name == "告警管理")
|
||||
{
|
||||
}
|
||||
DAO::exec(NULL, sql, result);
|
||||
}
|
||||
|
||||
vector<VH>& GetHeaderVec(const string& name)
|
||||
{
|
||||
static vector<VH> vecTmp;
|
||||
auto iter = mapTableHeaderDef.find(name);
|
||||
return (iter != mapTableHeaderDef.end()) ? iter->second : vecTmp;
|
||||
}
|
||||
|
||||
void QWSysmgr::initTable(const string& name)
|
||||
{
|
||||
auto& vecHeader = GetHeaderVec(name);
|
||||
QStringList headerTextList;
|
||||
for (auto& item: vecHeader) { headerTextList << item.title.c_str(); }
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
|
||||
for (int i = 0; i<vecHeader.size(); ++i)
|
||||
{
|
||||
auto& item = vecHeader[i];
|
||||
table->setColumnWidth(i, item.width > 0 ? item.width : 100);
|
||||
}
|
||||
this->initTableData(name);
|
||||
}
|
||||
|
||||
void QWSysmgr::initTableData(std::string name)
|
||||
{
|
||||
table->clearContents();
|
||||
table->setRowCount(0);
|
||||
|
||||
QueryDB(name, rowFields);
|
||||
|
||||
auto& vecHeader = GetHeaderVec(name);
|
||||
for (int row = 0; row<rowFields.size(); ++row)
|
||||
{
|
||||
auto& fields = rowFields[row];
|
||||
int col = 0;
|
||||
for (auto& item : vecHeader)
|
||||
{
|
||||
string key = item.key;
|
||||
if (item.title == "操作")
|
||||
{
|
||||
if (row >= table->rowCount()) { table->insertRow(row); }
|
||||
|
||||
QWidget* cellWidget = new QWidget();
|
||||
QPushButton* btn1 = new QPushButton("查看", cellWidget);
|
||||
btn1->setGeometry(5, 3, 50, 24);
|
||||
btn1->setStyleSheet(QSS_BTN_TAB.c_str());
|
||||
QPushButton* btn2 = new QPushButton("修改", cellWidget);
|
||||
btn2->setGeometry(60, 3, 50, 24);
|
||||
btn2->setStyleSheet(QSS_BTN_TAB.c_str());
|
||||
table->setCellWidget(row, col, cellWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
string val = fields.value(key);
|
||||
if (key == "is_open") { val = (val == "1" ? "启用" : "未启用"); }
|
||||
MyQUI::setTableCell(table, row, col, val);
|
||||
}
|
||||
++col;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/qt/widgets/QWSysmgr.h
Normal file
23
src/qt/widgets/QWSysmgr.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
#include "common/Fields.h"
|
||||
|
||||
class QWSysmgr : public MyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWSysmgr(QWidget* parent);
|
||||
~QWSysmgr();
|
||||
|
||||
void initTable(const string& name);
|
||||
void initTableData(std::string name);
|
||||
|
||||
public:
|
||||
std::vector<shared_ptr<QPushButton>> vecBtnFunc;
|
||||
shared_ptr<QPushButton> curActiveBtn;
|
||||
|
||||
shared_ptr<QTableWidget> table;
|
||||
|
||||
std::vector<Fields> rowFields;
|
||||
};
|
||||
Reference in New Issue
Block a user