mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现启动splash画面,实现天历史数据的处理和数据库存贮
This commit is contained in:
BIN
bin/Release/assets/ui/splash.jpg
Normal file
BIN
bin/Release/assets/ui/splash.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
BIN
bin/Release/assets/ui/splash.png
Normal file
BIN
bin/Release/assets/ui/splash.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 663 KiB |
BIN
bin/Release/yhicon.ico
Normal file
BIN
bin/Release/yhicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@@ -83,9 +83,11 @@ ADD_SOURCE_GROUP(protocol)
|
||||
#ADD_SOURCE_GROUP(widgets/pages)
|
||||
ADD_SOURCE_GROUP(pv)
|
||||
ADD_SOURCE_GROUP(pv/pages)
|
||||
ADD_SOURCE_GROUP(qt)
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin)
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILE})
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILE} "resource.rc")
|
||||
|
||||
#set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
@@ -97,6 +99,7 @@ target_link_libraries(${PROJECT_NAME}
|
||||
Qt5::Charts
|
||||
Qt5::WebEngineWidgets
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
ws2_32 iphlpapi
|
||||
${THIRDPARTY_PATH}/mysql/lib/x64/libmysql.lib
|
||||
|
||||
BIN
src/RCa06216
Normal file
BIN
src/RCa06216
Normal file
Binary file not shown.
@@ -113,9 +113,9 @@ void AppData::initFromDB()
|
||||
{
|
||||
auto station = std::make_shared<Station>();
|
||||
station->setFields(fields);
|
||||
this->mapStation[station->id] = station;
|
||||
mapping.stationName.push_back({std::to_string(station->id), station->name});
|
||||
str += ("场站: {" + std::to_string(station->id) + ":" + station->name + "},");
|
||||
this->mapStation[station->stationId] = station;
|
||||
mapping.stationName.push_back({std::to_string(station->stationId), station->name});
|
||||
str += ("场站: {" + std::to_string(station->stationId) + ":" + station->name + "},");
|
||||
}
|
||||
spdlog::info(str);
|
||||
}
|
||||
@@ -210,6 +210,34 @@ void AppData::initFromDB()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ // 初始化场站设备的历史监测数据
|
||||
|
||||
vector<Fields> result;
|
||||
DAO::queryRuntimeData(dao, Utils::dateStr(), result);
|
||||
for (auto& item : result)
|
||||
{
|
||||
int stationId = item.get<int>("station_id");
|
||||
int deviceId = item.get<int>("device_id");
|
||||
auto device = this->getDevice(stationId, deviceId);
|
||||
if (device)
|
||||
{
|
||||
int datatype = item.get<int>("datatype");
|
||||
std::string value = item.value("value");
|
||||
|
||||
njson json;
|
||||
if (JSON::parse(value, json))
|
||||
{
|
||||
std::vector<double> vecVal(json.size());
|
||||
for (int i=0; i<json.size(); ++i)
|
||||
{
|
||||
vecVal[i] = JSON::get<double>(json[i]);
|
||||
}
|
||||
device->setCache(datatype, vecVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppData::init()
|
||||
|
||||
@@ -49,6 +49,9 @@ void Application::init()
|
||||
|
||||
// 创建主业务循环线程
|
||||
std::thread([=]() { runThreadMain(); }).detach();
|
||||
|
||||
// 统计分析
|
||||
std::thread([=]() { runThreadStat(); }).detach();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +59,7 @@ void Application::runThreadDevice()
|
||||
{
|
||||
while (!isQuit)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,3 +105,31 @@ void Application::runThreadMain()
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Application::runThreadStat()
|
||||
{
|
||||
int nCachePos = 0;
|
||||
while (!isQuit)
|
||||
{
|
||||
int64_t tTime = Utils::time();
|
||||
int64_t tDate = Utils::date();
|
||||
int64_t delta = tTime-tDate;
|
||||
int n = delta / 600;
|
||||
int offset = delta % 600;
|
||||
if (delta >=0 && delta < 86400 && offset <= 10 && n != nCachePos)
|
||||
{
|
||||
nCachePos = n;
|
||||
std::string dt = Utils::dateStr(tDate);
|
||||
for (auto item: appdata.mapStation)
|
||||
{
|
||||
item.second->writeRuntimeData(dt, nCachePos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("保存历史数据倒计时: {}", 600 - offset);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ public:
|
||||
|
||||
void runThreadDevice();
|
||||
|
||||
void runThreadStat();
|
||||
|
||||
public:
|
||||
bool isQuit = false;
|
||||
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
#include "protocol/CommEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
static std::unordered_set<int> g_setCacheDeviceType = {3, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110};
|
||||
static bool CheckCacheType(int type)
|
||||
{
|
||||
return g_setCacheDeviceType.find(type) != g_setCacheDeviceType.end();
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
{
|
||||
@@ -40,15 +47,15 @@ std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
}
|
||||
}
|
||||
|
||||
int step = 600;
|
||||
for (int i = 0; i*600<86400; ++i)
|
||||
{
|
||||
double voltage = double(Utils::random(20000, 30000))*0.01;
|
||||
double current = double(Utils::random(1000, 2000))*0.01;
|
||||
device->mapCacheVoltage[i*step] = voltage;
|
||||
device->mapCacheCurrent[i*step] = current;
|
||||
device->mapCachePower[i*step] = voltage * current;
|
||||
}
|
||||
//int step = 600;
|
||||
//for (int i = 0; i*600<86400; ++i)
|
||||
//{
|
||||
// double voltage = double(Utils::random(20000, 30000))*0.01;
|
||||
// double current = double(Utils::random(1000, 2000))*0.01;
|
||||
// device->mapCacheVoltage[i*step] = voltage;
|
||||
// device->mapCacheCurrent[i*step] = current;
|
||||
// device->mapCachePower[i*step] = voltage * current;
|
||||
//}
|
||||
|
||||
// 启动通讯,该函数中会自动判断isOpen状态,选择是否进行通讯连接
|
||||
//device->startComm();
|
||||
@@ -117,6 +124,64 @@ void Device::getCachePower(std::vector<std::string>& vec)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t GetCurrentTimePos(int step)
|
||||
{
|
||||
auto tp = chrono::system_clock::now();
|
||||
int64_t tTime = chrono::time_point_cast<chrono::seconds>(tp).time_since_epoch().count();
|
||||
std::time_t t = chrono::system_clock::to_time_t(tp);
|
||||
std::tm* tmlocal = localtime(&t);
|
||||
tmlocal->tm_hour = 0;
|
||||
tmlocal->tm_min = 0;
|
||||
tmlocal->tm_sec = 0;
|
||||
int64_t tDate = chrono::time_point_cast<chrono::seconds>(chrono::system_clock::from_time_t(mktime(tmlocal))).time_since_epoch().count();
|
||||
return (tTime - tDate) / step;
|
||||
}
|
||||
|
||||
void Device::setCache(int datatype, std::vector<double>& vec)
|
||||
{
|
||||
std::map<int, double>* mapptr = NULL;
|
||||
if (datatype == 1) { mapptr = &mapCacheVoltage; }
|
||||
else if (datatype == 2) { mapptr = &mapCacheCurrent; }
|
||||
else if (datatype == 3) { mapptr = &mapCachePower; }
|
||||
|
||||
if (mapptr)
|
||||
{
|
||||
const int step = 600;
|
||||
const int N = 86400/step;
|
||||
|
||||
int n = GetCurrentTimePos(step);
|
||||
for (int i = 0; i<N; ++i)
|
||||
{
|
||||
if (i < vec.size()) { (*mapptr)[i] = vec[i]; }
|
||||
else if (i <= n) { (*mapptr)[i] = 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Device::cache(int npos)
|
||||
{
|
||||
if (!CheckCacheType(this->type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (npos == 0)
|
||||
{
|
||||
mapCacheVoltage.clear();
|
||||
mapCacheCurrent.clear();
|
||||
mapCachePower.clear();
|
||||
}
|
||||
// 根据设备类型从参数(寄存器地址)中读取实时数据进行保存
|
||||
mapCacheVoltage[npos] = Utils::random(100, 200);
|
||||
mapCacheCurrent[npos] = Utils::random(100, 200);
|
||||
mapCachePower[npos] = Utils::random(100, 200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Device::storeDB(int npos)
|
||||
{
|
||||
}
|
||||
|
||||
void Device::setParam(std::string k, std::string v)
|
||||
{
|
||||
mapParams[k] = v;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/Fields.h"
|
||||
|
||||
@@ -15,18 +16,24 @@ class Device
|
||||
public:
|
||||
static std::shared_ptr<Device> create(Fields& fields);
|
||||
|
||||
|
||||
int startComm();
|
||||
|
||||
void getCacheVoltage(std::vector<std::string>& vec);
|
||||
void getCacheCurrent(std::vector<std::string>& vec);
|
||||
void getCachePower(std::vector<std::string>& vec);
|
||||
|
||||
// int datatype: 1: 电压,2:电流,3:功率
|
||||
void setCache(int datatype, std::vector<double>& vec);
|
||||
|
||||
bool cache(int npos);
|
||||
void storeDB(int npos);
|
||||
|
||||
void setParam(std::string k, std::string v);
|
||||
std::string getParam(std::string k, std::string defaultVal = "");
|
||||
|
||||
void getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params);
|
||||
|
||||
|
||||
public:
|
||||
int deviceId = -1;
|
||||
int type = -1;
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
#include "common/Spdlogger.h"
|
||||
#include "common/Utils.h"
|
||||
#include "protocol/MqttEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
|
||||
Station::Station() : id(0)
|
||||
Station::Station() : stationId(0)
|
||||
{
|
||||
mqttCli = std::make_shared<MqttClient>();
|
||||
|
||||
@@ -32,7 +33,7 @@ Station::Station() : id(0)
|
||||
|
||||
void Station::setFields(Fields& fields)
|
||||
{
|
||||
this->id = fields.get<int>(DMStation::STATION_ID);
|
||||
this->stationId = fields.get<int>(DMStation::STATION_ID);
|
||||
this->name = fields.value(DMStation::NAME);
|
||||
this->energyCapacity = fields.get<double>(DMStation::CAPACITY);
|
||||
this->workModeId = fields.get<int>(DMStation::WORK_MODE);
|
||||
@@ -99,7 +100,7 @@ void Station::setWorkMode(int modeId)
|
||||
this->workModeId = modeId;
|
||||
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
|
||||
.update(DMStation::WORK_MODE, std::to_string(modeId))
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(id)).str();
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(stationId)).str();
|
||||
Errcode err = DAO::exec(NULL, sql);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
@@ -111,10 +112,49 @@ void Station::setPolicy(int policyId)
|
||||
{
|
||||
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
|
||||
.update(DMStation::POLICY_ID, std::to_string(policyId))
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(id)).str();
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(stationId)).str();
|
||||
Errcode err = DAO::exec(NULL, sql);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
spdlog::error("set station policy failed.");
|
||||
}
|
||||
}
|
||||
|
||||
static std::string MapValueToJson(int npos, std::map<int, double>& mapV)
|
||||
{
|
||||
njson jsonarray = njson::array();
|
||||
for (int i = 0; i<=npos; i++)
|
||||
{
|
||||
jsonarray.push_back(mapV[i]);
|
||||
}
|
||||
return jsonarray.dump();
|
||||
}
|
||||
|
||||
void Station::writeRuntimeData(std::string dt, int npos)
|
||||
{
|
||||
auto dao = DaoEntity::create("history_day");
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->cache(npos))
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("dt", dt);
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("device_id", device->deviceId);
|
||||
fields.set("datatype", 1);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheVoltage));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 2);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheCurrent));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 3);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCachePower));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
spdlog::info("[device] write runtime date to database, deviceId={}", device->deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,9 +106,11 @@ public:
|
||||
void setPolicy(int policyId);
|
||||
|
||||
|
||||
void writeRuntimeData(std::string dt, int npos);
|
||||
|
||||
|
||||
public:
|
||||
int id {};
|
||||
int stationId {};
|
||||
std::string name;
|
||||
std::string code;
|
||||
bool isConnected {false};
|
||||
|
||||
@@ -35,7 +35,7 @@ void Fields::append(Fields& datafield)
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_map<string, string>& Fields::map()
|
||||
std::map<string, string>& Fields::map()
|
||||
{
|
||||
return mapFields;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
/**
|
||||
* 获取数据项 map
|
||||
*/
|
||||
std::unordered_map<string, string>& map();
|
||||
std::map<string, string>& map();
|
||||
|
||||
/**
|
||||
* 获取数据项的大小
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
void parseJson(std::string jsonstr);
|
||||
|
||||
private:
|
||||
std::unordered_map<string, string> mapFields;
|
||||
std::map<string, string> mapFields;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <common/Spdlogger.h>
|
||||
|
||||
using njson = nlohmann::json;
|
||||
|
||||
@@ -53,26 +54,36 @@ class JSON
|
||||
public:
|
||||
static bool load(std::string jsonfile, njson& json);
|
||||
|
||||
|
||||
static bool parse(std::string jsonstr, njson& json);
|
||||
|
||||
template <typename T>
|
||||
static void read(njson& json, std::string k, T& v)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (json.contains(k)) { v = json.at(k).get<T>(); }
|
||||
}
|
||||
catch (const nlohmann::detail::exception& e)
|
||||
{
|
||||
std::cout << "JSON read error: k=" << k << ", err=" << e.what() << std::endl;
|
||||
}
|
||||
try { if (json.contains(k)) { v = json.at(k).get<T>(); } }
|
||||
catch (const nlohmann::detail::exception& e) { Spdlogger::info("JSON read error: k={}, err={}", k, e.what()); }
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T read(njson& json, std::string k)
|
||||
{
|
||||
T v {};
|
||||
try { if (json.contains(k)) { v = json.at(k).get<T>(); } }
|
||||
catch (const nlohmann::detail::exception& e) { Spdlogger::info("JSON read error: k={}, err={}", k, e.what()); }
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T get(njson& json)
|
||||
{
|
||||
T v {};
|
||||
try { v = json.get<T>(); }
|
||||
catch (const nlohmann::detail::exception& e) { Spdlogger::info("JSON read error: err={}, json={}", e.what(), json.dump()); }
|
||||
return v;
|
||||
}
|
||||
|
||||
static std::string readStr(njson& json, std::string k);
|
||||
|
||||
static void parse(std::string jsonstr, std::vector<std::string>& vd);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -551,7 +551,25 @@ Errcode DAO::queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>&
|
||||
|
||||
Errcode DAO::insertRuntimeData(std::shared_ptr<DaoEntity> dao, Fields& fields)
|
||||
{
|
||||
if (!dao) { dao = DaoEntity::create("history1"); }
|
||||
if (!dao) { dao = DaoEntity::create("history_day"); }
|
||||
int ret = dao->duplicateUpdate(fields, {"value"});
|
||||
return Errcode(ret);
|
||||
}
|
||||
|
||||
|
||||
Errcode DAO::queryRuntimeData(std::shared_ptr<DaoEntity> dao, std::string dt, int stationId, int deviceId, vector<Fields>& result)
|
||||
{
|
||||
if (!dao) { dao = DaoEntity::create("history_day"); }
|
||||
std::string sql = "SELECT * FROM history_day WHERE dt='" + dt + "' AND station_id='" + std::to_string(stationId) +
|
||||
"' AND device_id='" + std::to_string(deviceId) + "';";
|
||||
int ret = dao->exec(sql, result);
|
||||
return Errcode(ret);
|
||||
}
|
||||
|
||||
Errcode DAO::queryRuntimeData(std::shared_ptr<DaoEntity> dao, std::string dt, vector<Fields>& result)
|
||||
{
|
||||
if (!dao) { dao = DaoEntity::create("history_day"); }
|
||||
std::string sql = "SELECT * FROM history_day WHERE dt='" + dt + "';";
|
||||
int ret = dao->exec(sql, result);
|
||||
return Errcode(ret);
|
||||
}
|
||||
@@ -118,5 +118,13 @@ public:
|
||||
|
||||
static Errcode queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// === 设备历史监测数据管理 ===
|
||||
static Errcode insertRuntimeData(std::shared_ptr<DaoEntity> dao, Fields& fields);
|
||||
static Errcode queryRuntimeData(std::shared_ptr<DaoEntity> dao, std::string dt, int stationId, int deviceId, vector<Fields>& result);
|
||||
static Errcode queryRuntimeData(std::shared_ptr<DaoEntity> dao, std::string dt, vector<Fields>& result);
|
||||
};
|
||||
@@ -105,6 +105,7 @@ int DaoEntity::insertFields(vector<Fields>& vec_fields)
|
||||
}
|
||||
if (!values.empty()) { values += ","; }
|
||||
values += ("'" + v + "'");
|
||||
std::cout << k << std::endl;
|
||||
}
|
||||
if (first)
|
||||
{
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace DMStatStation
|
||||
|
||||
namespace DMHistory1
|
||||
{
|
||||
const string TABLENAME = "history1";
|
||||
const string TABLENAME = "history_day";
|
||||
const string DT = "dt";
|
||||
const string STATION_ID = "station_id";
|
||||
const string DEVICE_ID = "device_id";
|
||||
|
||||
22
src/main.cpp
22
src/main.cpp
@@ -30,8 +30,7 @@
|
||||
#include <string>
|
||||
#include "DataStruct.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
#include "qt/MainWeb.h"
|
||||
|
||||
#define wsa rlwsa
|
||||
void rlSocketTest()
|
||||
@@ -159,23 +158,8 @@ int main(int argc, char** argv)
|
||||
}).detach();
|
||||
|
||||
QApplication qapp(argc, argv);
|
||||
|
||||
QMainWindow mainWin;
|
||||
mainWin.setWindowTitle("光储充站监控与运营管理平台");
|
||||
mainWin.setGeometry(0, 0, 1920, 1080);
|
||||
QWebEngineView webView;
|
||||
webView.setGeometry(0, 0, 1920, 1080);
|
||||
// 默认设置透明, 解决加载时的白屏闪烁
|
||||
webView.page()->setBackgroundColor(Qt::transparent);
|
||||
webView.setContextMenuPolicy(Qt::NoContextMenu);
|
||||
webView.load(QUrl(Config::option.webSrvUrl.c_str()));
|
||||
//webView.load(QUrl("file:///assets/html/main.html"));
|
||||
//connect(wWebView.get(), &QWebEngineView::loadFinished, this, &MyWidget::slotLoadFinished);
|
||||
//std::string htmlContent = "HelloWorld";
|
||||
//webView->setHtml(htmlContent.c_str(), QUrl("file:///assets/html/"));
|
||||
webView.show();
|
||||
mainWin.setCentralWidget(&webView);
|
||||
|
||||
qapp.setWindowIcon(QIcon("./yhicon.ico"));
|
||||
MainWeb mainWin;
|
||||
mainWin.show();
|
||||
qapp.exec();
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ static std::map<std::string, HandlerOptions> g_mapHttpHandlerGet =
|
||||
{"/queryDevicTypeDef", HandlerOptions(&HttpEntity::queryDevicTypeDef, {})},
|
||||
{"/queryDevicByCategory", HandlerOptions(&HttpEntity::queryDevicByCategory, {DMStation::STATION_ID, "category"})},
|
||||
{"/queryDevicCharts", HandlerOptions(&HttpEntity::queryDevicCharts, {DMStation::STATION_ID, "device_id"})},
|
||||
{"/queryDeviceBCUDetail", HandlerOptions(&HttpEntity::queryDeviceBCUDetail, {DMStation::STATION_ID, "device_id"})},
|
||||
|
||||
|
||||
{"/queryPolicyList", HandlerOptions(&HttpEntity::queryPolicyList, {})},
|
||||
@@ -305,11 +306,35 @@ Errcode HttpEntity::login(const httplib::Request& req, njson& json, std::string&
|
||||
DAO::queryRolePermission(dao, roleId, vecPermission);
|
||||
|
||||
njson nodePermission = njson::array();
|
||||
for (auto& item : vecPermission)
|
||||
std::map<std::string, int> mapParentPos;
|
||||
for (int i=0; i<vecPermission.size(); ++i)
|
||||
{
|
||||
njson node;
|
||||
FieldsToJson(item, node);
|
||||
nodePermission.push_back(node);
|
||||
auto& item = vecPermission[i];
|
||||
if (item.value("parent_id") == "")
|
||||
{
|
||||
mapParentPos[item.value("permission_id")] = i;
|
||||
njson node;
|
||||
FieldsToJson(item, node);
|
||||
node["children"] = njson::array();
|
||||
nodePermission.push_back(node);
|
||||
}
|
||||
}
|
||||
// 重新遍历处理二级子权限,防止父权限信息还未创建时导致错误
|
||||
for (int i = 0; i<vecPermission.size(); ++i)
|
||||
{
|
||||
auto& item = vecPermission[i];
|
||||
std::string id = item.value("permission_id");
|
||||
std::string parentId = item.value("parent_id");
|
||||
if (parentId != "")
|
||||
{
|
||||
auto iter = mapParentPos.find(parentId);
|
||||
if (iter != mapParentPos.end())
|
||||
{
|
||||
njson node;
|
||||
FieldsToJson(item, node);
|
||||
nodePermission[iter->second]["children"].push_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
json["permission"] = nodePermission;
|
||||
}
|
||||
@@ -406,25 +431,56 @@ Errcode HttpEntity::queryRoleList(const httplib::Request& req, njson& json, std:
|
||||
{
|
||||
return err;
|
||||
}
|
||||
std::map<std::string, std::vector<Fields>> mapP;
|
||||
|
||||
std::map<std::string, std::vector<njson>> mapPermission;
|
||||
for (auto& fields: vecPermission)
|
||||
for (int i = 0; i<vecPermission.size(); ++i)
|
||||
{
|
||||
std::string roleId = fields.value("role_id");
|
||||
auto& v = mapPermission[roleId];
|
||||
njson node;
|
||||
FieldsToJson(fields, node);
|
||||
v.push_back(node);
|
||||
auto& item = vecPermission[i];
|
||||
std::string roleId = item.value("role_id");
|
||||
std::string id = item.value("permission_id");
|
||||
std::string parentId = item.value("parent_id");
|
||||
|
||||
mapP[roleId].push_back(vecPermission[i]);
|
||||
}
|
||||
|
||||
HttpHelper::setPagination(pageinfo, result, json);
|
||||
if (json.contains("data"))
|
||||
for (auto& item : json["data"])
|
||||
{
|
||||
for (auto& item : json["data"])
|
||||
auto jsonpermission = njson::array();
|
||||
std::string roleId = item["role_id"];
|
||||
std::vector<Fields>& vecP = mapP[roleId];
|
||||
|
||||
std::map<std::string, int> mapParentPos;
|
||||
for (int i = 0; i<vecP.size(); ++i)
|
||||
{
|
||||
std::string roleId = item["role_id"];
|
||||
item["permission"] = mapPermission[roleId];
|
||||
auto& item = vecPermission[i];
|
||||
if (item.value("parent_id") == "")
|
||||
{
|
||||
mapParentPos[item.value("permission_id")] = i;
|
||||
njson node;
|
||||
FieldsToJson(item, node);
|
||||
node["children"] = njson::array();
|
||||
jsonpermission.push_back(node);
|
||||
}
|
||||
}
|
||||
// 重新遍历处理二级子权限,防止父权限信息还未创建时导致错误
|
||||
for (int i = 0; i<vecP.size(); ++i)
|
||||
{
|
||||
auto& item = vecP[i];
|
||||
std::string id = item.value("permission_id");
|
||||
std::string parentId = item.value("parent_id");
|
||||
if (parentId != "")
|
||||
{
|
||||
auto iter = mapParentPos.find(parentId);
|
||||
if (iter != mapParentPos.end())
|
||||
{
|
||||
njson node;
|
||||
FieldsToJson(item, node);
|
||||
jsonpermission[iter->second]["children"].push_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
item["permission"] = jsonpermission;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
@@ -501,7 +557,7 @@ Errcode HttpEntity::insertStation(const httplib::Request& req, njson& json, std:
|
||||
Errcode HttpEntity::updateStation(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
GetRequestParam(req, {"station_id", "name", "address", "lon", "lat", "tel", "capacity", "status"}, params);
|
||||
GetRequestParam(req, {"station_id", "name", "address", "lon", "lat", "tel", "capacity", "status", "work_mode"}, params);
|
||||
params.check("capacity", "", "0.0");
|
||||
params.check("lon", "", "0.0");
|
||||
params.check("lat", "", "0.0");
|
||||
@@ -739,6 +795,17 @@ Errcode HttpEntity::queryDevicCharts(const httplib::Request& req, njson& json, s
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryDeviceBCUDetail(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
njson jsondata = njson::array();
|
||||
for (int i = 0; i<=100; ++i)
|
||||
{
|
||||
jsondata.push_back({{"SOC", "1"}, {"SOH", "1"}, {"V", "1"}, {"T", "1"}, {"R_i", "1"}});
|
||||
}
|
||||
json["data"] = jsondata;
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryPolicyList(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
PageInfo pageinfo;
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
Errcode queryDevicTypeDef(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
Errcode queryDevicByCategory(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
Errcode queryDevicCharts(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
Errcode queryDeviceBCUDetail(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
|
||||
Errcode queryPolicyList(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
Errcode insertPolicy(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
|
||||
@@ -125,7 +125,7 @@ int MaskPageRunning::initUI(EPvCode pvcode)
|
||||
}
|
||||
|
||||
PvApp::label(p, 0, 320, 110, 80, 30, "运行模式", "color:white; font: bold 16px;");
|
||||
ui.comboxWorkMode = PvApp::combox(p, 0, 400, 110, 200, 30, appdata.getWorkModes(), activeStation->id - 1);
|
||||
ui.comboxWorkMode = PvApp::combox(p, 0, 400, 110, 200, 30, appdata.getWorkModes(), activeStation->stationId - 1);
|
||||
|
||||
PvApp::label(p, 0, 670, 110, 80, 30, "策略名称", "color:white; font: bold 16px;");
|
||||
PvApp::combox(p, 0, 750, 110, 200, 30, appdata.getPolicyNames());
|
||||
|
||||
57
src/qt/MainWeb.cpp
Normal file
57
src/qt/MainWeb.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "MainWeb.h"
|
||||
|
||||
#include "app/Config.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QLabel>
|
||||
#include <QThread>
|
||||
|
||||
|
||||
void MySplash(MainWeb* mainWin)
|
||||
{
|
||||
//===动态程序启动画面===
|
||||
QPixmap pixmap("./assets/ui/splash.png");
|
||||
QSplashScreen splash(pixmap);
|
||||
splash.show();
|
||||
QCoreApplication::processEvents();
|
||||
QLabel label(&splash);
|
||||
label.setStyleSheet("background-color: gray");
|
||||
label.setGeometry(100, 480, 800, 20);
|
||||
label.show();
|
||||
|
||||
QLabel labelProgress(&splash);
|
||||
labelProgress.setStyleSheet("background-color: rgb(29, 54, 102)");
|
||||
labelProgress.setGeometry(10, 10, 0, 20);
|
||||
labelProgress.show();
|
||||
|
||||
int i = 0;
|
||||
while ((++i)<500)
|
||||
{
|
||||
splash.showMessage(QString("Loading... %1 ms").arg(i), Qt::AlignBottom | Qt::AlignRight, Qt::black);
|
||||
labelProgress.setGeometry(100, 480, i*2*0.8, 20);
|
||||
QThread::msleep(10);
|
||||
}
|
||||
|
||||
splash.finish(mainWin);//程序启动画面结束
|
||||
}
|
||||
|
||||
|
||||
MainWeb::MainWeb()
|
||||
{
|
||||
this->setWindowTitle("光储充站监控与运营管理平台");
|
||||
this->setGeometry(0, 0, 1920, 1080);
|
||||
|
||||
webView.setGeometry(0, 0, 1920, 1080);
|
||||
// 默认设置透明, 解决加载时的白屏闪烁
|
||||
webView.page()->setBackgroundColor(Qt::transparent);
|
||||
webView.setContextMenuPolicy(Qt::NoContextMenu);
|
||||
webView.load(QUrl(Config::option.webSrvUrl.c_str()));
|
||||
//webView.load(QUrl("file:///assets/html/main.html"));
|
||||
//connect(wWebView.get(), &QWebEngineView::loadFinished, this, &MyWidget::slotLoadFinished);
|
||||
//std::string htmlContent = "HelloWorld";
|
||||
//webView->setHtml(htmlContent.c_str(), QUrl("file:///assets/html/"));
|
||||
webView.show();
|
||||
this->setCentralWidget(&webView);
|
||||
|
||||
MySplash(this);
|
||||
this->show();
|
||||
}
|
||||
14
src/qt/MainWeb.h
Normal file
14
src/qt/MainWeb.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <QMainWindow>
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
#include <QSplashScreen>
|
||||
|
||||
|
||||
|
||||
|
||||
class MainWeb : public QMainWindow
|
||||
{
|
||||
public:
|
||||
MainWeb();
|
||||
|
||||
QWebEngineView webView;
|
||||
};
|
||||
BIN
src/resource.aps
Normal file
BIN
src/resource.aps
Normal file
Binary file not shown.
16
src/resource.h
Normal file
16
src/resource.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ 生成的包含文件。
|
||||
// 供 ESS.rc 使用
|
||||
//
|
||||
#define IDI_ICON1 102
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 103
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
BIN
src/resource.rc
Normal file
BIN
src/resource.rc
Normal file
Binary file not shown.
BIN
src/yhicon.ico
Normal file
BIN
src/yhicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user