实现削峰套利策略的编辑页面

This commit is contained in:
lixiaoyuan
2025-08-26 18:36:25 +08:00
parent 7fe51ea362
commit 8f6c83147b
37 changed files with 1506 additions and 729 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 B

After

Width:  |  Height:  |  Size: 264 B

View File

@@ -2,88 +2,215 @@
#include "common/Utils.h" #include "common/Utils.h"
#include "app/Station.h" #include "app/Station.h"
#include "app/Device.h" #include "app/Device.h"
#include "app/Policy.h"
#include "database/Dao.h" #include "database/Dao.h"
#include "common/JsonN.h"
#include "common/Utils.h"
void InitStation(AppData* appdata) void ElectPeriod::parse(std::string jsonstr)
{ {
// 读取数据库 NJsonNode jsonroot;
NJson::parse(jsonstr, jsonroot);
NJson::read(jsonroot, "price_super_peak", this->priceSuperPeak);
NJson::read(jsonroot, "price_peak", this->pricePeak);
NJson::read(jsonroot, "price_shoulder", this->priceShoulder);
NJson::read(jsonroot, "price_off_peak", this->priceOffPeak);
NJson::read<std::vector<std::vector<std::string>>>(jsonroot, "periods", this->vecPeriods);
}
std::string ElectPeriod::dump()
{
NJsonNode jsonroot;
jsonroot["price_super_peak"] = this->priceSuperPeak;
jsonroot["price_peak"] = this->pricePeak;
jsonroot["price_shoulder"] = this->priceShoulder;
jsonroot["price_off_peak"] = this->priceOffPeak;
jsonroot["periods"] = this->vecPeriods;
return jsonroot.dump();
}
void AppData::initFromDB()
{
auto dao = DaoEntity::create("");
if (!dao->isConnected())
{
XLOGE() << "Database connected error.";
return;
}
std::string str;
std::vector<Fields> result; std::vector<Fields> result;
DAO::queryStationList(NULL, result);
for (auto& fields: result)
{
int stationId = fields.getInt(DMStation::STATION_ID);
auto station = std::make_shared<Station>(stationId);
station->name = fields.value(DMStation::NAME);
station->energyCapacity = fields.getDouble(DMStation::CAPACITY);
appdata->mapStation[stationId] = station;
}
}
void InitDevice(AppData* appdata) { // 数据库读取工作模式定义
{ str = "", result.clear();
vector<Fields> result; DAO::queryWorkModeDef(dao, result);
DAO::queryDeviceList(NULL, result); for (auto& fields: result)
for (auto& fields: result)
{
int deviceId = fields.getInt(DMDevice::DEVICE_ID);
int stationId = fields.getInt(DMDevice::STATION_ID);
auto station = appdata->getStation(stationId);
if (station)
{ {
auto device = Device::create(fields); std::string workModeId = fields.value(DMDefWorkMode::WORK_MODE_ID);
station->addDevice(deviceId, device); std::string name = fields.value(DMDefWorkMode::NAME);
this->mapping.workMode.push_back({workModeId, name});
str += ("工作模式: {" + workModeId + ":" + name + "},");
} }
else XLOGD() << str;
}
{ // 数据库读取策略类型定义
str = "", result.clear();
DAO::queryPolicyTypeDef(dao, result);
for (auto& fields: result)
{ {
XLOGE() << "init device error: unknown station_id:[" << stationId << "] device_id=" << deviceId; std::string policyTypeId = fields.value(DMDefPolicyType::POLICY_TYPE_ID);
std::string name = fields.value(DMDefWorkMode::NAME);
this->mapping.workMode.push_back({policyTypeId, name});
str += ("策略类型: {" + policyTypeId + ":" + name + "},");
}
XLOGD() << str;
}
{ // 数据库读取设备类型定义
str = "", result.clear();
DAO::queryDeviceTypeDef(dao, result);
for (auto& fields: result)
{
auto item = std::make_shared<DeviceType>();
item->typeId = fields.get<int>(DMDefDeviceType::DEVICE_TYPE_ID);
item->name = fields.value(DMDefDeviceType::NAME);
item->attrs = fields.value(DMDefDeviceType::ATTRS);
mapDeviceType[item->typeId] = item;
mapping.deviceType.push_back({std::to_string(item->typeId), item->name});
str += ("设备类型: {" + std::to_string(item->typeId) + ":" + item->name + "},");
}
XLOGD() << str;
}
{ // 数据库读取角色定义
str = "", result.clear();
this->mapping.role.clear();
DAO::queryRoleList(dao, result);
for (auto& fields : result)
{
auto item = std::make_shared<Role>();
item->roleId = fields.get<int>(DMRole::ROLE_ID);
item->name = fields.value(DMRole::NAME);
item->isOpen = fields.get<int>(DMRole::IS_OPEN);
mapRole[item->roleId] = item;
mapping.role.push_back({std::to_string(item->roleId), item->name});
str += ("角色: {" + std::to_string(item->roleId) + ":" + item->name + "},");
}
XLOGD() << str;
}
{ // 数据库读取场站信息
str = "", result.clear();
DAO::queryStationList(dao, result);
for (auto& fields: result)
{
int stationId = fields.get<int>(DMStation::STATION_ID);
auto station = std::make_shared<Station>(stationId);
station->name = fields.value(DMStation::NAME);
station->energyCapacity = fields.get<double>(DMStation::CAPACITY);
this->mapStation[stationId] = station;
str += ("场站: {" + std::to_string(stationId) + ":" + station->name + "},");
}
XLOGD() << str;
}
{ // 数据库读取设备信息
str = "", result.clear();
DAO::queryDeviceList(dao, result);
for (auto& fields: result)
{
int deviceId = fields.get<int>(DMDevice::DEVICE_ID);
int stationId = fields.get<int>(DMDevice::STATION_ID);
auto station = this->getStation(stationId);
if (station)
{
auto device = Device::create(fields);
station->addDevice(deviceId, device);
}
else
{
XLOGE() << "init device error: unknown station_id:[" << stationId << "] device_id=" << deviceId;
}
} }
} }
} { // 数据库读取策略信息
str = "", result.clear();
void InitStatData(AppData* appdata) DAO::queryPolicyList(dao, result);
{ for (auto& fields: result)
std::string curDate = Utils::dateStr();
vector<Fields> result;
DAO::queryStatDataList(curDate, curDate, result);
for (auto& fields: result)
{
std::string dt = fields.value(DMStatStation::DT);
int stationId = fields.getInt(DMStatStation::STATION_ID);
auto station = appdata->getStation(stationId);
if (station)
{ {
station->storageIn = fields.getFloat(DMStatStation::STORAGE_ELECT_IN); auto policy = std::make_shared<MyPolicy>();
station->storageOut = fields.getFloat(DMStatStation::STORAGE_ELECT_OUT); policy->policyId = fields.get<int>(DMPolicy::POLICY_ID);
//station->storageNumIn = fields.getFloat(DMStatStation::STORAGE_NUM); policy->type = fields.get<int>(DMPolicy::TYPE);
//station->storageNumOut = fields.getFloat(DMStatStation::STORAGE_NUM); policy->name = fields.value(DMPolicy::NAME);
station->storageNumErr = fields.getFloat(DMStatStation::STORAGE_NUM_ERR); policy->value = fields.value(DMPolicy::VALUE);
this->mapPolicy[policy->policyId] = policy;
station->solarGen = fields.getFloat(DMStatStation::SOLAR_ELECT_GEN);
station->solarGrid = fields.getFloat(DMStatStation::SOLAR_ELECT_GRID);
station->solarNumErr = fields.getFloat(DMStatStation::SOLAR_NUM_ERR);
station->chargeElect = fields.getFloat(DMStatStation::CHARGE_ELECT);
station->chargeNum = fields.getFloat(DMStatStation::CHARGE_NUM);
station->chargeNumErr = fields.getFloat(DMStatStation::CHARGE_NUM_ERR);
}
else
{
XLOGE() << "init staticis data error: unknown station_id:[" << stationId << "] dt=" << dt;
} }
} }
{ // 数据库读取电价分段信息
result.clear();
vecElectPeriods.resize(12);
DAO::exec(dao, "SELECT * FROM configure;", result);
Fields info;
for (auto& fields: result)
{
auto k = fields.value("key");
auto v = fields.value("val");
info.set(k, v);
}
for (int month = 1; month<=12; month++)
{
if (month-1 < vecElectPeriods.size())
{
auto& vecItems = vecElectPeriods[month-1];
std::string str = info.value("period_" + std::to_string(month));
std::vector<std::string> vec;
Utils::split(str, ",", vecItems);
}
}
electPriceSuperPeak = info.get<double>("price_super_peak");
electPricePeak = info.get<double>("price_peak");
electPriceShoulder = info.get<double>("price_shoulder");
electPriceOffPeak = info.get<double>("price_off_peak");
}
{ // 数据库读取统计数据
vector<Fields> result;
std::string curDate = Utils::dateStr();
DAO::queryStatDataList(dao, curDate, curDate, result);
for (auto& fields: result)
{
std::string dt = fields.value(DMStatStation::DT);
int stationId = fields.get<int>(DMStatStation::STATION_ID);
auto station = this->getStation(stationId);
if (station)
{
station->storageIn = fields.get<double>(DMStatStation::STORAGE_ELECT_IN);
station->storageOut = fields.get<double>(DMStatStation::STORAGE_ELECT_OUT);
//station->storageNumIn = fields.getFloat(DMStatStation::STORAGE_NUM);
//station->storageNumOut = fields.getFloat(DMStatStation::STORAGE_NUM);
station->storageNumErr = fields.get<int>(DMStatStation::STORAGE_NUM_ERR);
station->solarGen = fields.get<double>(DMStatStation::SOLAR_ELECT_GEN);
station->solarGrid = fields.get<double>(DMStatStation::SOLAR_ELECT_GRID);
station->solarNumErr = fields.get<int>(DMStatStation::SOLAR_NUM_ERR);
station->chargeElect = fields.get<double>(DMStatStation::CHARGE_ELECT);
station->chargeNum = fields.get<int>(DMStatStation::CHARGE_NUM);
station->chargeNumErr = fields.get<int>(DMStatStation::CHARGE_NUM_ERR);
}
else
{
XLOGE() << "init staticis data error: unknown station_id:[" << stationId << "] dt=" << dt;
}
}
}
} }
void AppData::init() void AppData::init()
{ {
// 初始化场站信息 this->initFromDB();
InitStation(this);
// 读取设备信息,连接设备
InitDevice(this);
// 读取基础统计信息,在系统总览中需要展示
InitStatData(this);
this->initUser(); this->initUser();
} }
@@ -135,31 +262,7 @@ void AppData::initUser()
auto dao = DaoEntity::create(""); auto dao = DaoEntity::create("");
std::vector<Fields> result; std::vector<Fields> result;
// 数据库读取角色定义
mapping.role.clear();
DAO::queryRoleList(dao, result);
for (auto& fields : result)
{
auto item = std::make_shared<Role>();
item->roleId = fields.getInt(DMRole::ROLE_ID);
item->name = fields.value(DMRole::NAME);
item->isOpen = fields.getInt(DMRole::IS_OPEN);
mapRole[item->roleId] = item;
mapping.role.push_back({std::to_string(item->roleId), item->name});
}
// 数据库读取设备类型定义
result.clear();
DAO::queryDeviceTypeDef(dao, result);
for (auto& fields : result)
{
auto item = std::make_shared<DeviceType>() ;
item->typeId = fields.getInt(DMDeviceTypeDef::TYPE_ID);
item->name = fields.value(DMDeviceTypeDef::NAME);
item->attrs = fields.value(DMDeviceTypeDef::ATTRS);
mapDeviceType[item->typeId] = item;
mapping.deviceType.push_back({std::to_string(item->typeId), item->name});
}
} }
std::vector<std::string> AppData::getRoleNames() std::vector<std::string> AppData::getRoleNames()
@@ -186,7 +289,7 @@ std::vector<std::string> AppData::getStationNames()
return vec; return vec;
} }
std::vector<std::string> AppData::getDeviceTypes() std::vector<std::string> AppData::getDeviceTypeNames()
{ {
std::vector<std::string> vec(mapping.deviceType.size()); std::vector<std::string> vec(mapping.deviceType.size());
int i = 0; int i = 0;
@@ -196,4 +299,61 @@ std::vector<std::string> AppData::getDeviceTypes()
++i; ++i;
} }
return vec; return vec;
}
std::vector<std::string> AppData::getWorkModes()
{
std::vector<std::string> vec(mapWorkMode.size());
int i = 0;
for (auto iter = mapWorkMode.begin(); iter!=mapWorkMode.end(); ++iter)
{
vec[i] = iter->second;
++i;
}
return vec;
}
std::vector<std::string> AppData::getPolicyTypeNames()
{
std::vector<std::string> vec(mapPolicyType.size());
int i = 0;
for (auto iter = mapPolicyType.begin(); iter!=mapPolicyType.end(); ++iter)
{
vec[i] = iter->second;
++i;
}
return vec;
}
std::vector<std::string> AppData::getPolicyNames()
{
std::vector<std::string> vec;
return vec;
}
std::vector<std::string> AppData::getElectPreiodVals(int month)
{
if (month > 0 && month-1 < vecElectPeriods.size())
{
return vecElectPeriods[month-1];
}
return {};
}
std::string AppData::getElectPreiodVal(int month, int hour)
{
if (month > 0 && month-1 < vecElectPeriods.size())
{
auto& vec = vecElectPeriods[month-1];
if (hour > 0 && hour-1 < vec.size())
{
auto& val = vec[hour-1];
if (val == "") return "尖峰";
if (val == "") return "高峰";
if (val == "") return "平段";
if (val == "") return "低谷";
return val;
}
}
return "";
} }

View File

@@ -8,6 +8,7 @@
class Station; class Station;
class Device; class Device;
class MyPolicy;
using VecPairSS = std::vector<std::pair<std::string, std::string>>; using VecPairSS = std::vector<std::pair<std::string, std::string>>;
@@ -25,27 +26,32 @@ struct Role
bool isOpen {false}; bool isOpen {false};
}; };
class ElectPeriod
{
public:
double priceSuperPeak {};
double pricePeak {};
double priceShoulder {};
double priceOffPeak {};
std::vector<std::vector<std::string>> vecPeriods;
void parse(std::string jsonstr);
std::string dump();
};
class AppData class AppData
{ {
public: public:
void init(); void init();
void initFromDB();
std::shared_ptr<Station> getStation(int stationId); std::shared_ptr<Station> getStation(int stationId);
std::shared_ptr<Station> getStationByName(std::string name); std::shared_ptr<Station> getStationByName(std::string name);
std::shared_ptr<Device> getDevice(int stationId, int deviceId);
/////////////////////////////////////////////////////////////////////////////////////////////// std::shared_ptr<Device> getDevice(int stationId, int deviceId);
// 获取角色名称列表
std::vector<std::string> getRoleNames();
// 获取场站名称列表
std::vector<std::string> getStationNames();
// 获取设备类型
std::vector<std::string> getDeviceTypes();
// 获取设备类型定义 // 获取设备类型定义
std::unordered_map<int, std::shared_ptr<DeviceType>>& getDeviceTypeDef(); std::unordered_map<int, std::shared_ptr<DeviceType>>& getDeviceTypeDef();
@@ -55,6 +61,25 @@ public:
void initUser(); void initUser();
///////////////////////////////////////////////////////////////////////////////////////////////
// 获取角色名称列表
std::vector<std::string> getRoleNames();
// 获取场站名称列表
std::vector<std::string> getStationNames();
// 获取设备类型
std::vector<std::string> getDeviceTypeNames();
// 获取工作模式
std::vector<std::string> getWorkModes();
// 获取策略类型定义
std::vector<std::string> getPolicyTypeNames();
// 获取策略名称
std::vector<std::string> getPolicyNames();
std::vector<std::string> getElectPreiodVals(int month);
std::string getElectPreiodVal(int month, int hour);
public: public:
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
// === 系统 === // === 系统 ===
@@ -77,18 +102,33 @@ public:
VecPairSS deviceType; VecPairSS deviceType;
VecPairSS workMode;
} mapping; } mapping;
/////////////////////////////////////////////////////////////////////////////////////////////// double electPriceSuperPeak {};
// === 场站信息 === double electPricePeak {};
double electPriceShoulder {};
double electPriceOffPeak {};
// 场站信息
std::unordered_map<int, std::shared_ptr<Station>> mapStation; std::unordered_map<int, std::shared_ptr<Station>> mapStation;
/////////////////////////////////////////////////////////////////////////////////////////////// // 角色信息
// === 角色定义 ===
std::unordered_map<int, std::shared_ptr<Role>> mapRole; std::unordered_map<int, std::shared_ptr<Role>> mapRole;
/////////////////////////////////////////////////////////////////////////////////////////////// // 设备类型定义
// === 设备类型定义 ===
std::unordered_map<int, std::shared_ptr<DeviceType>> mapDeviceType; std::unordered_map<int, std::shared_ptr<DeviceType>> mapDeviceType;
// 工作模式定义
std::unordered_map<int, std::string> mapWorkMode;
// 策略类型定义
std::unordered_map<int, std::string> mapPolicyType;
// 策略信息
std::unordered_map<int, std::shared_ptr<MyPolicy>> mapPolicy;
// 电力峰谷分段 (12个月每个月按小时分成24个时段)
std::vector<std::vector<std::string>> vecElectPeriods;
}; };

View File

@@ -9,8 +9,8 @@ AppOption Config::option;
bool Config::init(std::string filename) bool Config::init(std::string filename)
{ {
NJson jsonroot; NJsonNode jsonroot;
bool ret = NJsonLoad(filename, jsonroot); bool ret = NJson::load(filename, jsonroot);
if (!ret) if (!ret)
{ {
XLOGE() << "[APP] load config failed, filename=" << filename; XLOGE() << "[APP] load config failed, filename=" << filename;
@@ -20,7 +20,7 @@ bool Config::init(std::string filename)
if (jsonroot.contains("database")) if (jsonroot.contains("database"))
{ {
NJson json = jsonroot.at("database"); NJsonNode json = jsonroot.at("database");
option.database.host = json.contains("host") ? json.at("host") : ""; option.database.host = json.contains("host") ? json.at("host") : "";
option.database.port = json.contains("port") ? json.at("port") : 0; option.database.port = json.contains("port") ? json.at("port") : 0;
option.database.user = json.contains("user") ? json.at("user") : ""; option.database.user = json.contains("user") ? json.at("user") : "";

View File

@@ -47,7 +47,7 @@ Errcode DAO1::login(std::shared_ptr<DaoEntity> dao, std::string account, std::st
} }
Fields& fields = res[0]; Fields& fields = res[0];
std::string userId = fields.value("user_id"); std::string userId = fields.value("user_id");
int loginCount = fields.getInt("login_count"); int loginCount = fields.get<int>("login_count");
// 判断密码 // 判断密码
if (passwd != fields.value("passwd")) if (passwd != fields.value("passwd"))

View File

@@ -67,16 +67,16 @@ int Device::startComm()
std::shared_ptr<Device> Device::create(Fields& fields) std::shared_ptr<Device> Device::create(Fields& fields)
{ {
auto device = std::make_shared<Device>(); auto device = std::make_shared<Device>();
device->deviceId = fields.getInt("device_id"); device->deviceId = fields.get<int>("device_id");
device->type = fields.getInt("type"); device->type = fields.get<int>("type");
device->name = fields.value("name"); device->name = fields.value("name");
device->code = fields.value("code"); device->code = fields.value("code");
device->isOpen = fields.getInt("is_open"); device->isOpen = fields.get<int>("is_open");
device->attrsJson = fields.value("attrs"); device->attrsJson = fields.value("attrs");
// 解析属性的JSON字符串转换成键值对 // 解析属性的JSON字符串转换成键值对
NJson jsonroot; NJsonNode jsonroot;
bool ret = NJsonParse(device->attrsJson, jsonroot); bool ret = NJson::parse(device->attrsJson, jsonroot);
if (!ret) // 解析错误 if (!ret) // 解析错误
{ {
XLOGE() << "device attr json parse error, device_id=" << device->deviceId; XLOGE() << "device attr json parse error, device_id=" << device->deviceId;

0
src/app/Policy.cpp Normal file
View File

15
src/app/Policy.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include <string>
#include "common/Fields.h"
class MyPolicy
{
public:
int policyId {0};
int type {0};
std::string name;
std::string value;
int isOpen {0};
Fields fields;
};

View File

@@ -1,5 +1,6 @@
#include "Station.h" #include "Station.h"
#include "database/DAO.h"
#include "database/SQL.h"
Station::Station(int id) : id(id) Station::Station(int id) : id(id)
{ {
@@ -18,4 +19,28 @@ std::shared_ptr<Device> Station::getDevice(int deviceId)
return iter->second; return iter->second;
} }
return nullptr; return nullptr;
}
void Station::setWorkMode(int modeId)
{
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
.update(DMStation::WORK_MODE_ID, std::to_string(modeId))
.where(DMStation::STATION_ID + "=" + std::to_string(id)).str();
Errcode err = DAO::exec(NULL, sql);
if (err != Errcode::OK)
{
XLOGE() << "set station work mode failed.";
}
}
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();
Errcode err = DAO::exec(NULL, sql);
if (err != Errcode::OK)
{
XLOGE() << "set station policy failed.";
}
} }

View File

@@ -13,10 +13,17 @@ public:
void addDevice(int deviceId, std::shared_ptr<Device> device); void addDevice(int deviceId, std::shared_ptr<Device> device);
std::shared_ptr<Device> getDevice(int deviceId); std::shared_ptr<Device> getDevice(int deviceId);
void setWorkMode(int modeId);
void setPolicy(int policyId);
public: public:
int id {}; int id {};
std::string name; std::string name;
int workModeId; // 运行模式
int runPolicyId; // 运行策略
// 储能容量 // 储能容量
double energyCapacity {}; double energyCapacity {};

View File

@@ -1,22 +1,7 @@
#include "Fields.h" #include "Fields.h"
#include "common/Utils.h" #include "common/Utils.h"
void Fields::set(string key, string val)
{
mapFields[key] = val;
}
void Fields::set(string key, float val)
{
mapFields[key] = std::to_string(val);
}
void Fields::set(string key, int val)
{
mapFields[key] = std::to_string(val);
}
void Fields::set(string key, int64_t val)
{
mapFields[key] = std::to_string(val);
}
std::string& Fields::value(std::string key) std::string& Fields::value(std::string key)
{ {
static std::string tmp; static std::string tmp;
@@ -24,27 +9,12 @@ std::string& Fields::value(std::string key)
return (it != mapFields.end()) ? it->second : (tmp = ""); return (it != mapFields.end()) ? it->second : (tmp = "");
} }
//string Fields::getStr(string key) bool Fields::contains(std::string key)
//{
// return (mapFields.count(key) > 0) ? mapFields[key] : "";
//}
int Fields::getInt(string key)
{ {
return mapFields.count(key) > 0 ? Utils::toInt(mapFields[key]) : 0; return (mapFields.find(key) != mapFields.end());
} }
float Fields::getFloat(string key) std::unordered_map<string, string>::iterator Fields::remove(string key)
{
return mapFields.count(key) > 0 ? Utils::toFloat(mapFields[key]) : 0.0f;
}
double Fields::getDouble(string key)
{
return mapFields.count(key) > 0 ? Utils::toDouble(mapFields[key]) : 0.0;
}
std::map<string, string>::iterator Fields::remove(string key)
{ {
auto it = mapFields.find(key); auto it = mapFields.find(key);
if (it != mapFields.end()) if (it != mapFields.end())
@@ -53,19 +23,36 @@ std::map<string, string>::iterator Fields::remove(string key)
} }
return it; return it;
} }
void Fields::append(Fields& datafield) void Fields::append(Fields& datafield)
{ {
auto& map_f = datafield.fields(); auto& mapVal = datafield.map();
for (auto it = map_f.begin(); it != map_f.end(); it++) for (auto it = mapVal.begin(); it != mapVal.end(); it++)
{ {
mapFields[it->first] = it->second; mapFields[it->first] = it->second;
} }
} }
map<string, string>& Fields::fields()
std::unordered_map<string, string>& Fields::map()
{ {
return mapFields; return mapFields;
} }
int Fields::size()
{
return mapFields.size();
}
bool Fields::isEmpty()
{
return mapFields.empty();
}
void Fields::clear()
{
mapFields.clear();
}
void Fields::check(string key, string val, string d) void Fields::check(string key, string val, string d)
{ {
if (mapFields.count(key) > 0 && mapFields[key] == val) if (mapFields.count(key) > 0 && mapFields[key] == val)
@@ -74,84 +61,6 @@ void Fields::check(string key, string val, string d)
} }
} }
string Fields::get_insert_sql(string tbname)
{
string key;
string val;
for (auto it = mapFields.begin(); it != mapFields.end(); it++)
{
if (!key.empty())
{
key += ",";
val += ",";
}
key += ("`" + it->first + "`");
if (it->second == "null" || it->second == "NULL")
{
val += "NULL";
}
else
{
val += ("'" + it->second + "'");
}
}
return "INSERT INTO `" + tbname + "` (" + key + ") VALUES(" + val + ");";
}
string Fields::get_update_sql(string tbname, string sql_c)
{
ostringstream oss;
oss << "update " << tbname << " set ";
for (auto iter = mapFields.begin(); iter != mapFields.end(); iter++)
{
if (iter != mapFields.begin())
{
oss << ",";
};
oss << "`" << iter->first << "`=";
if (iter->second == "null" || iter->second == "NULL")
{
oss << "NULL";
}
else
{
oss << "'" << iter->second << "'";
}
}
oss << " " << sql_c << ";";
return oss.str();
}
string Fields::get_update_sql(string tbname, std::vector<std::string> vec_keys, string sql_c)
{
std::map<std::string, bool> map_keys;
for (auto& k : vec_keys) { map_keys[k] = true; }
ostringstream oss;
oss << "update " << tbname << " set ";
for (auto iter = mapFields.begin(); iter != mapFields.end(); iter++)
{
auto& k = iter->first;
auto& v = iter->second;
if (!map_keys[k]) { continue; }
if (iter != mapFields.begin())
{
oss << ",";
};
oss << "`" << k << "`=";
if (v == "null" || v == "NULL")
{
oss << "NULL";
}
else
{
oss << "'" << v << "'";
}
}
oss << " " << sql_c << ";";
return oss.str();
}
void Fields::foreachItem(function<void(string key, string& val)> onForaach) void Fields::foreachItem(function<void(string key, string& val)> onForaach)
{ {
for (auto it = mapFields.begin(); it != mapFields.end(); it++) for (auto it = mapFields.begin(); it != mapFields.end(); it++)
@@ -162,11 +71,6 @@ void Fields::foreachItem(function<void(string key, string& val)> onForaach)
} }
} }
} }
bool Fields::isEmpty(string key)
{
auto& s = mapFields[key];
return s.empty();
}
bool Fields::is_float_number(string key) bool Fields::is_float_number(string key)
{ {
@@ -195,19 +99,84 @@ string Fields::toStr()
return s; return s;
} }
int Fields::size() string Fields::toSqlInsert(string tableName)
{ {
return mapFields.size(); string key;
string val;
for (auto it = mapFields.begin(); it != mapFields.end(); it++)
{
if (!key.empty())
{
key += ",";
val += ",";
}
key += ("`" + it->first + "`");
if (it->second == "null" || it->second == "NULL")
{
val += "NULL";
}
else
{
val += ("'" + it->second + "'");
}
}
return "INSERT INTO `" + tableName + "` (" + key + ") VALUES(" + val + ");";
} }
void Fields::clear() string Fields::toSqlUpdate(string tableName, string sql_c)
{ {
mapFields.clear(); ostringstream oss;
oss << "update " << tableName << " set ";
for (auto iter = mapFields.begin(); iter != mapFields.end(); iter++)
{
if (iter != mapFields.begin())
{
oss << ",";
};
oss << "`" << iter->first << "`=";
if (iter->second == "null" || iter->second == "NULL")
{
oss << "NULL";
}
else
{
oss << "'" << iter->second << "'";
}
}
oss << " " << sql_c << ";";
return oss.str();
} }
bool Fields::hasKey(std::string key) string Fields::toSqlUpdate(string tableName, std::vector<std::string> vecKeys, string condition)
{ {
auto iter = mapFields.find(key); std::map<std::string, bool> map_keys;
return (iter != mapFields.end()); for (auto& k : vecKeys) { map_keys[k] = true; }
ostringstream oss;
oss << "update " << tableName << " set ";
for (auto iter = mapFields.begin(); iter != mapFields.end(); iter++)
{
auto& k = iter->first;
auto& v = iter->second;
if (!map_keys[k]) { continue; }
if (iter != mapFields.begin())
{
oss << ",";
};
oss << "`" << k << "`=";
if (v == "null" || v == "NULL")
{
oss << "NULL";
}
else
{
oss << "'" << v << "'";
}
}
oss << " " << condition << ";";
return oss.str();
} }

View File

@@ -1,9 +1,10 @@
#ifndef _Fields_H_ #ifndef _Fields_H_
#define _Fields_H_ #define _Fields_H_
#include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <sstream>
#include <unordered_map> #include <unordered_map>
#include <functional> #include <functional>
using namespace std; using namespace std;
@@ -18,33 +19,29 @@ struct PageInfo
class Fields class Fields
{ {
public: public:
/** template <typename T>
* 设置索引名称和值 void set(string key, T val, int precision=6)
* @param: [string key] 索引名称 {
* @param: [string val] 值 stringstream ss;
*/ ss.precision(precision);
void set(string key, string val); ss << val;
mapFields[key] = ss.str();
}
/** template <typename T>
* 设置索引名称和值 T get(string key, int precision = 6)
* @param: [string key] 索引名称 {
* @param: [float val] 值 T val {};
*/ auto iter = mapFields.find(key);
void set(string key, float val); if (iter != mapFields.end())
{
stringstream ss(iter->second);
ss.precision(precision);
ss >> val;
}
return val;
}
/**
* 设置索引名称和值
* @param: [string key] 索引名称
* @param: [int val] 值
*/
void set(string key, int val);
/**
* 设置索引名称和值
* @param: [string key] 索引名称
* @param: [int64_t val] 值
*/
void set(string key, int64_t val);
/** /**
* 获取值 * 获取值
@@ -53,28 +50,17 @@ public:
std::string& value(std::string key); std::string& value(std::string key);
/** /**
* 获取 int 值 * 是否包含 key
* @param: [string key] 索引名称 * @param: [string key] 索引名称
* @return: true: 包含; false不包含
*/ */
int getInt(string key); bool contains(std::string key);
/**
* 获取 float 值
* @param: [string key] 索引名称
*/
float getFloat(string key);
/**
* 获取 double 值
* @param: [string key] 索引名称
*/
double getDouble(string key);
/** /**
* 删除指定索引的值 * 删除指定索引的值
* @param: [string key] 索引名称 * @param: [string key] 索引名称
*/ */
std::map<string, string>::iterator remove(string key); std::unordered_map<string, string>::iterator remove(string key);
/** /**
* 追加合并 * 追加合并
@@ -83,9 +69,25 @@ public:
void append(Fields& fields); void append(Fields& fields);
/** /**
* 获取数据项map * 获取数据项 map
*/ */
map<string, string>& fields(); std::unordered_map<string, string>& map();
/**
* 获取数据项的大小
*/
int size();
/**
* 判断是否含有数据项
* @param: [string key] 索引名称
*/
bool isEmpty();
/**
* 清空数据项
*/
void clear();
/** /**
* 检查某一数据项的值进行替换如果该项的值是val则替换成成d * 检查某一数据项的值进行替换如果该项的值是val则替换成成d
@@ -95,39 +97,12 @@ public:
*/ */
void check(string key, string val, string d); void check(string key, string val, string d);
/**
* 转换成插入数据的 sql 语句
* @param: [string tableName] 数据表名称
*/
string get_insert_sql(string tableName);
/**
* 转换成更新数据的 sql 语句
* @param: [string tableName] 数据表名称
* @param: [string condition] sql的更新条件例如 where id='1'
*/
string get_update_sql(string tableName, string condition);
/**
* 转换成更新数据的 sql 语句
* @param: [string tableName] 数据表名称
* @param: [string vecKeys] 需要更新的字段名称
* @param: [string condition] sql的更新条件例如 where id='1'
*/
string get_update_sql(string tableName, std::vector<std::string> vecKeys, string condition);
/** /**
* 遍历数据项 * 遍历数据项
* @param: [function... onForaach] 回调函数 * @param: [function... onForaach] 回调函数
*/ */
void foreachItem(function<void(string key, string& val)> onForaach); void foreachItem(function<void(string key, string& val)> onForaach);
/**
* 判断是否含有数据项
* @param: [string key] 索引名称
*/
bool isEmpty(string key);
/** /**
* 判断数据项是否是float数值类型 * 判断数据项是否是float数值类型
@@ -141,20 +116,28 @@ public:
string toStr(); string toStr();
/** /**
* 获取数据项的大小 * 转换成插入数据的 sql 语句
* @param: [string tableName] 数据表名称
*/ */
int size(); string toSqlInsert(string tableName);
void clear(); /**
* 转换成更新数据的 sql 语句
* @param: [string tableName] 数据表名称
* @param: [string condition] sql的更新条件例如 where id='1'
*/
string toSqlUpdate(string tableName, string condition);
bool hasKey(std::string key); /**
* 转换成更新数据的 sql 语句
* @param: [string tableName] 数据表名称
* @param: [string vecKeys] 需要更新的字段名称
std::map<string, string>& map() { return mapFields; } * @param: [string condition] sql的更新条件例如 where id='1'
*/
string toSqlUpdate(string tableName, std::vector<std::string> vecKeys, string condition);
private: private:
std::map<string, string> mapFields; std::unordered_map<string, string> mapFields;
}; };
#endif #endif

View File

@@ -1,8 +1,9 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <iostream>
using NJson = nlohmann::json; using NJsonNode = nlohmann::json;
/// ============================================================================================= /// =============================================================================================
/// 使用说明: /// 使用说明:
@@ -36,32 +37,60 @@ using NJson = nlohmann::json;
/// 序列化为字符串 ------------- /// 序列化为字符串 -------------
// std::string json_str = j.dump(4); // 4 表示缩进,美化输出 // std::string json_str = j.dump(4); // 4 表示缩进,美化输出
static bool NJsonLoad(std::string jsonfile, NJson& json) /// 数组解析 -------------
{ // json jArray = json::array()
std::ifstream ifs(jsonfile); // jArray.push_back(1);
if (ifs.is_open()) // jArray.push_back(2);
{ // json j;
ifs >> json; // j["data"] = {1,2,3,4,5};
return true; // std::vector<int> v1;
} // v1 = j.at["data"].get<std::vector<int>>()
return false;
}
static bool NJsonParse(std::string jsonstr, NJson& json) class NJson
{ {
try public:
{ static bool load(std::string jsonfile, NJsonNode& json)
json = NJson::parse(jsonstr);
}
catch (nlohmann::json::parse_error& e)
{ {
//std::cerr << "JSON 解析错误: " << e.what() << std::endl; std::ifstream ifs(jsonfile);
if (ifs.is_open())
{
ifs >> json;
return true;
}
return false; return false;
} }
return true;
}
static bool NJsonLHas(NJson& json, std::string key) static bool parse(std::string jsonstr, NJsonNode& json)
{ {
return json.contains("database"); try
} {
json = NJsonNode::parse(jsonstr);
}
catch (nlohmann::json::parse_error& e)
{
std::cout << "JSON parse error: " << e.what() << std::endl;
return false;
}
return true;
}
static bool contains(NJsonNode& json, std::string key)
{
return json.contains("database");
}
template <typename T>
static void read(NJsonNode& 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: " << e.what() << std::endl;
}
}
};

View File

@@ -435,7 +435,7 @@ void Utils::split(string buf, string c, vector<string>& res)
string tmp = buf; string tmp = buf;
while (true) while (true)
{ {
auto pos = tmp.find(c); auto pos = tmp.find_first_of(c);
if (pos == string::npos) if (pos == string::npos)
{ {
res.push_back(tmp); res.push_back(tmp);

View File

@@ -18,18 +18,40 @@ bool DAO::count(DaoEntity& dao, std::string tableName, std::string condition, in
bool ret = dao.exec(sql, result); bool ret = dao.exec(sql, result);
if (ret) if (ret)
{ {
count = (result.size() > 0) ? result[0].getInt("count") : 0; count = (result.size() > 0) ? result[0].get<int>("count") : 0;
} }
return ret; return ret;
} }
Errcode DAO::exec(std::shared_ptr<DaoEntity> dao, std::string sql)
{
if (!dao) { dao = DaoEntity::create(""); }
if (!dao->isConnected())
{
return Errcode::ERR_DB_CONN;
}
auto ret = dao->exec(sql);
return ret ? Errcode::OK : Errcode::ERR_DB_SQL;
}
Errcode DAO::exec(std::shared_ptr<DaoEntity> dao, std::string sql, vector<Fields>& result)
{
if (!dao) { dao = DaoEntity::create(""); }
if (!dao->isConnected())
{
return Errcode::ERR_DB_CONN;
}
auto ret = dao->exec(sql, result);
return ret ? Errcode::OK : Errcode::ERR_DB_SQL;
}
static bool QueryCount(DaoEntity& dao, std::string sqlFrom, int& count) static bool QueryCount(DaoEntity& dao, std::string sqlFrom, int& count)
{ {
std::vector<Fields> result; std::vector<Fields> result;
bool ret = dao.exec("SELECT COUNT(*) count " + sqlFrom, result); bool ret = dao.exec("SELECT COUNT(*) count " + sqlFrom, result);
if (ret) if (ret)
{ {
count = (result.size() > 0) ? result[0].getInt("count") : 0; count = (result.size() > 0) ? result[0].get<int>("count") : 0;
} }
return ret; return ret;
} }
@@ -108,7 +130,7 @@ Errcode DAO::updateUserById(Fields& params)
std::string createTime = Utils::timeStr(); std::string createTime = Utils::timeStr();
std::string userId = params.value(DMUser::USER_ID); std::string userId = params.value(DMUser::USER_ID);
std::string roleId = ""; std::string roleId = "";
if (params.hasKey(DMRole::ROLE_ID)) if (params.contains(DMRole::ROLE_ID))
{ {
roleId = params.value(DMRole::ROLE_ID); roleId = params.value(DMRole::ROLE_ID);
params.remove(DMUser::USER_ID); params.remove(DMUser::USER_ID);
@@ -137,11 +159,10 @@ Errcode DAO::updateUserById(Fields& params)
return Errcode::OK; return Errcode::OK;
} }
bool DAO::queryRoleList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result) Errcode DAO::queryRoleList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{ {
if (!dao) { dao = DaoEntity::create(""); }
std::string sql = "SELECT * FROM " + DMRole::TABLENAME + ";"; std::string sql = "SELECT * FROM " + DMRole::TABLENAME + ";";
return dao->exec(sql, result); return DAO::exec(dao, sql, result);
} }
bool DAO::queryRoleList(PageInfo& pageInfo, vector<Fields>& result) bool DAO::queryRoleList(PageInfo& pageInfo, vector<Fields>& result)
@@ -174,20 +195,16 @@ Errcode DAO::insertStation(Fields& params)
params.remove(DMStation::STATION_ID); params.remove(DMStation::STATION_ID);
params.check(DMStation::LATITUDE, "", "NULL"); params.check(DMStation::LATITUDE, "", "NULL");
params.check(DMStation::LONGITUDE, "", "NULL"); params.check(DMStation::LONGITUDE, "", "NULL");
bool ret = dao->insertFields(params);
if (!ret) std::string sql = params.toSqlInsert(DMStation::TABLENAME);
{ return DAO::exec(dao, sql);
return Errcode::ERR_DB_SQL;
}
return Errcode::OK;
} }
// 查询场站信息列表 // 查询场站信息列表
bool DAO::queryStationList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result) Errcode DAO::queryStationList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{ {
if (!dao) { dao = DaoEntity::create(""); }
std::string sql = "SELECT * FROM " + DMStation::TABLENAME; std::string sql = "SELECT * FROM " + DMStation::TABLENAME;
return DaoEntity::execOnce(sql, result); return DAO::exec(dao, sql, result);
} }
// 分页查询场站信息列表 // 分页查询场站信息列表
@@ -221,11 +238,10 @@ Errcode DAO::updateStationById(Fields& params)
} }
// 查询设备信息列表 // 查询设备信息列表
bool DAO::queryDeviceList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result) Errcode DAO::queryDeviceList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{ {
if (!dao) { dao = DaoEntity::create(""); }
std::string sql = "SELECT * FROM " + DMDevice::TABLENAME; std::string sql = "SELECT * FROM " + DMDevice::TABLENAME;
return DaoEntity::execOnce(sql, result); return DAO::exec(dao, sql, result);
} }
// 分页查询设备信息列表 // 分页查询设备信息列表
@@ -242,23 +258,17 @@ bool DAO::queryDeviceList(PageInfo& pageInfo, vector<Fields>& result)
} }
// 查询设备类型定义 // 查询设备类型定义
bool DAO::queryDeviceTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result) Errcode DAO::queryDeviceTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{ {
if (!dao) { dao = DaoEntity::create(""); } std::string sql = "SELECT * FROM " + DMDefDeviceType::TABLENAME + ";";
std::string sql = "SELECT * FROM " + DMDeviceTypeDef::TABLENAME + ";"; return DAO::exec(dao, sql, result);
return DaoEntity::execOnce(sql, result);
} }
Errcode DAO::insertDevice(Fields& params) Errcode DAO::insertDevice(Fields& params)
{ {
auto dao = DaoEntity::create(DMDevice::TABLENAME); return DAO::exec(NULL, params.toSqlInsert(DMDevice::TABLENAME));
bool ret = dao->insertFields(params);
if (!ret)
{
return Errcode::ERR_DB_SQL;
}
return Errcode::OK;
} }
Errcode DAO::updateDeviceById(Fields& params) Errcode DAO::updateDeviceById(Fields& params)
{ {
std::string deviceId = params.value(DMDevice::DEVICE_ID); std::string deviceId = params.value(DMDevice::DEVICE_ID);
@@ -266,13 +276,8 @@ Errcode DAO::updateDeviceById(Fields& params)
{ {
return Errcode::ERR_DB_SQL; return Errcode::ERR_DB_SQL;
} }
auto dao = DaoEntity::create(DMDevice::TABLENAME); std::string sql = params.toSqlUpdate(DMDevice::TABLENAME, "WHERE " + DMDevice::DEVICE_ID + "='" + deviceId + "'");
bool ret = dao->updateFields(params, "WHERE " + DMDevice::DEVICE_ID + "='" + deviceId + "'"); return DAO::exec(NULL, sql);
if (!ret)
{
return Errcode::ERR_DB_SQL;
}
return Errcode::OK;
} }
// 策略管理 // 策略管理
@@ -288,6 +293,12 @@ bool DAO::queryPolicyList(PageInfo& pageInfo, vector<Fields>& result)
return ret; return ret;
} }
Errcode DAO::queryPolicyList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{
std::string sql = "SELECT * FROM " + DMPolicy::TABLENAME;
return DAO::exec(dao, sql, result);
}
// 系统日志管理 // 系统日志管理
bool DAO::querySystemLogList(PageInfo& pageInfo, vector<Fields>& result) bool DAO::querySystemLogList(PageInfo& pageInfo, vector<Fields>& result)
{ {
@@ -301,8 +312,21 @@ bool DAO::querySystemLogList(PageInfo& pageInfo, vector<Fields>& result)
return ret; return ret;
} }
bool DAO::queryStatDataList(std::string startDate, std::string endDate, vector<Fields>& result) Errcode DAO::queryStatDataList(std::shared_ptr<DaoEntity> dao, std::string startDate, std::string endDate, vector<Fields>& result)
{ {
std::string sql = "SELECT * FROM " + DMStatStation::TABLENAME + " WHERE dt BETWEEN '" + startDate + "' AND '" + endDate + "';"; std::string sql = "SELECT * FROM " + DMStatStation::TABLENAME + " WHERE dt BETWEEN '" + startDate + "' AND '" + endDate + "';";
return DaoEntity::execOnce(sql, result); return DAO::exec(dao, sql, result);
}
Errcode DAO::queryWorkModeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{
std::string sql = "SELECT * FROM " + DMDefWorkMode::TABLENAME + ";";
return DAO::exec(dao, sql, result);
}
Errcode DAO::queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result)
{
std::string sql = "SELECT * FROM " + DMDefPolicyType::TABLENAME + ";";
return DAO::exec(dao, sql, result);
} }

View File

@@ -11,51 +11,55 @@ public:
static bool count(DaoEntity& dao, std::string tableName, std::string condition, int& count); static bool count(DaoEntity& dao, std::string tableName, std::string condition, int& count);
/////////////////////////////////////////////////////////////////////////////////////////////// static Errcode exec(std::shared_ptr<DaoEntity> dao, std::string sql);
// === 用户管理 static Errcode exec(std::shared_ptr<DaoEntity> dao, std::string sql, vector<Fields>& result);
// 新增用户信息
static Errcode insertUser(Fields& params);
// 分页查询用户信息列表 // 查询用户信息列表(分页)
static bool queryUserList(PageInfo& pageInfo, vector<Fields>& result); static bool queryUserList(PageInfo& pageInfo, vector<Fields>& result);
// 新增用户信息
static Errcode insertUser(Fields& params);
// 更新用户信息
static Errcode updateUserById(Fields& params); static Errcode updateUserById(Fields& params);
///////////////////////////////////////////////////////////////////////////////////////////////
// === 角色管理 === // 查询角色信息列表(分页)
// 查询角色信息列表
static bool queryRoleList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 分页查询角色信息列表
static bool queryRoleList(PageInfo& pageInfo, vector<Fields>& result); static bool queryRoleList(PageInfo& pageInfo, vector<Fields>& result);
/////////////////////////////////////////////////////////////////////////////////////////////// // 查询角色信息列表
// === 权限管理 === static Errcode queryRoleList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 查询权限信息列表(分页)
static bool queryPermissionList(PageInfo& pageInfo, vector<Fields>& result); static bool queryPermissionList(PageInfo& pageInfo, vector<Fields>& result);
///////////////////////////////////////////////////////////////////////////////////////////////
// === 场站管理 ===
// 新增场站信息
static Errcode insertStation(Fields& params); // 查询场站信息列表(分页)
// 查询场站信息列表
static bool queryStationList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 分页查询场站信息列表
static bool queryStationList(PageInfo& pageInfo, vector<Fields>& result); static bool queryStationList(PageInfo& pageInfo, vector<Fields>& result);
// 查询场站信息列表
static Errcode queryStationList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 新增场站信息
static Errcode insertStation(Fields& params);
// 更新场站信息
static Errcode updateStationById(Fields& params); static Errcode updateStationById(Fields& params);
///////////////////////////////////////////////////////////////////////////////////////////////
// === 设备管理 ===
// 查询设备信息列表
static bool queryDeviceList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 分页查询设备信息列表
static bool queryDeviceList(PageInfo& pageInfo, vector<Fields>& result);
// 查询设备类型定义
static bool queryDeviceTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 查询设备信息列表(分页)
static bool queryDeviceList(PageInfo& pageInfo, vector<Fields>& result);
// 查询设备信息列表
static Errcode queryDeviceList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 查询设备类型定义
static Errcode queryDeviceTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
// 新增设备信息
static Errcode insertDevice(Fields& params); static Errcode insertDevice(Fields& params);
// 更新设备信息
static Errcode updateDeviceById(Fields& params); static Errcode updateDeviceById(Fields& params);
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
@@ -63,6 +67,8 @@ public:
// 分页查询策略信息列表 // 分页查询策略信息列表
static bool queryPolicyList(PageInfo& pageInfo, vector<Fields>& result); static bool queryPolicyList(PageInfo& pageInfo, vector<Fields>& result);
static Errcode queryPolicyList(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
// === 系统日志管理 === // === 系统日志管理 ===
// 分页查询系统日志列表 // 分页查询系统日志列表
@@ -70,7 +76,10 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
// === 统计数据管理 === // === 统计数据管理 ===
static bool queryStatDataList(std::string startDate, std::string endDate, vector<Fields>& result); static Errcode queryStatDataList(std::shared_ptr<DaoEntity> dao, std::string startDate, std::string endDate, vector<Fields>& result);
static Errcode queryWorkModeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
static Errcode queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
}; };

View File

@@ -41,8 +41,7 @@ void DaoEntity::setOption(std::string host, int port, std::string user, std::str
std::shared_ptr<DaoEntity> DaoEntity::create(string tb_name) std::shared_ptr<DaoEntity> DaoEntity::create(string tb_name)
{ {
std::shared_ptr<DaoEntity> dao = std::make_shared<DaoEntity>(tb_name); return std::make_shared<DaoEntity>(tb_name);
return (dao->isConnected() ? dao : nullptr);
} }
bool DaoEntity::execOnce(string sql) bool DaoEntity::execOnce(string sql)
@@ -79,7 +78,7 @@ bool DaoEntity::exec(string sql, vector<Fields>& result)
bool DaoEntity::insertFields(Fields& fields) bool DaoEntity::insertFields(Fields& fields)
{ {
string sql = fields.get_insert_sql(tableName_); string sql = fields.toSqlInsert(tableName_);
return this->db_->exec(sql); return this->db_->exec(sql);
} }
@@ -95,7 +94,7 @@ bool DaoEntity::insertFields(vector<Fields>& vec_fields)
{ {
keys = ""; keys = "";
values = ""; values = "";
for (auto& item : field.fields()) for (auto& item : field.map())
{ {
const string& k = item.first; const string& k = item.first;
const string& v = item.second; const string& v = item.second;
@@ -133,7 +132,7 @@ bool DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
//insert into device_attr(device_id, attr_id, attr_val) values('26', 'model', '型号1') on duplicate key update attr_val='型号1'; //insert into device_attr(device_id, attr_id, attr_val) values('26', 'model', '型号1') on duplicate key update attr_val='型号1';
string s_key; string s_key;
string s_val; string s_val;
for (auto& item : fields.fields()) for (auto& item : fields.map())
{ {
if (!s_key.empty()) if (!s_key.empty())
{ {
@@ -162,18 +161,17 @@ bool DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
// }); // });
//} //}
bool DaoEntity::queryFields(string keys, const string& condition, vector<Fields>& result)
bool DaoEntity::queryFields(string keys, const string& sql_c, vector<Fields>& result)
{ {
ostringstream oss; ostringstream oss;
oss << "SELECT " + keys + " FROM " << tableName_ << (" " + sql_c) << "; "; oss << "SELECT " + keys + " FROM " << tableName_ << (" " + condition) << "; ";
return this->db_->exec(oss.str(), result); return this->db_->exec(oss.str(), result);
} }
bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, vector<Fields>& result) bool DaoEntity::queryFields(string keys, const string& condition, PageInfo& page, vector<Fields>& result)
{ {
ostringstream oss; ostringstream oss;
oss << "SELECT count(1) total FROM `" << tableName_ << "` " << sql_c << ";"; oss << "SELECT count(1) total FROM `" << tableName_ << "` " << condition << ";";
vector<Fields> res_total; vector<Fields> res_total;
if (!this->db_->exec(oss.str().c_str(), res_total)) if (!this->db_->exec(oss.str().c_str(), res_total))
@@ -186,7 +184,7 @@ bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, ve
page.total = 0; page.total = 0;
return true; return true;
} }
page.total = res_total[0].getInt("total"); page.total = res_total[0].get<int>("total");
if (page.total <= 0) if (page.total <= 0)
{ {
return true; return true;
@@ -198,29 +196,18 @@ bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, ve
page.index = 1; page.index = 1;
} }
int start = (page.index - 1) * page.size; int start = (page.index - 1) * page.size;
oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << sql_c << " LIMIT " << start << "," << page.size << ";"; oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << condition << " LIMIT " << start << "," << page.size << ";";
return this->db_->exec(oss.str().c_str(), result); return this->db_->exec(oss.str().c_str(), result);
} }
bool DaoEntity::updateFields(Fields& fields, const string& sql_c) bool DaoEntity::updateFields(Fields& fields, const string& condition)
{ {
string sql = fields.get_update_sql(tableName_, sql_c); string sql = fields.toSqlUpdate(tableName_, condition);
std::cout << sql; return this->db_->exec(sql);
if (sql_c.empty())
{
//Spdlogger::error("[DB] update condition is empty, not exec, sql={}", sql);
return false;
}
return this->db_->exec(sql.c_str());
} }
bool DaoEntity::updateFields(Fields& fields, vector<string> vec_keys, const string& sql_c) bool DaoEntity::updateFields(Fields& fields, vector<string> vecKeys, const string& condition)
{ {
string sql = fields.get_update_sql(tableName_, vec_keys, sql_c); string sql = fields.toSqlUpdate(tableName_, vecKeys, condition);
if (sql_c.empty()) return this->db_->exec(sql);
{
//Spdlogger::error("[DB] update condition is empty, not exec, sql={}", sql);
return false;
}
return this->db_->exec(sql.c_str());
} }

View File

@@ -3,6 +3,15 @@
#include <string> #include <string>
using namespace std; using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// 工作模式定义 表结构字段
namespace DMDefWorkMode
{
const string TABLENAME = "def_work_mode";
const string WORK_MODE_ID = "work_mode_id";
const string NAME = "name";
}
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
/// 用户 表结构字段 /// 用户 表结构字段
namespace DMUser namespace DMUser
@@ -80,6 +89,16 @@ namespace DMStation
const string TEL = "tel"; const string TEL = "tel";
const string CAPACITY = "capacity"; const string CAPACITY = "capacity";
const string STATUS = "status"; const string STATUS = "status";
const string WORK_MODE_ID = "work_mode_id";
const string POLICY_ID = "policy_id";
}
namespace DMDefDeviceType
{
const string TABLENAME = "def_device_type";
const string DEVICE_TYPE_ID = "device_type_id";
const string NAME = "name";
const string ATTRS = "attrs";
} }
namespace DMDevice namespace DMDevice
@@ -87,7 +106,7 @@ namespace DMDevice
const string TABLENAME = "device"; const string TABLENAME = "device";
const string DEVICE_ID = "device_id"; const string DEVICE_ID = "device_id";
const string STATION_ID = "station_id"; const string STATION_ID = "station_id";
const string TYPE_ID = "type_id"; const string TYPE = "type";
const string NAME = "name"; const string NAME = "name";
const string CODE = "code"; const string CODE = "code";
const string MODEL = "model"; const string MODEL = "model";
@@ -100,12 +119,11 @@ namespace DMDevice
const string UPDATE_TIME = "update_time"; const string UPDATE_TIME = "update_time";
} }
namespace DMDeviceTypeDef namespace DMDefPolicyType
{ {
const string TABLENAME = "def_device_type"; const string TABLENAME = "def_policy_type";
const string TYPE_ID = "type_id"; const string POLICY_TYPE_ID = "policy_type_id";
const string NAME = "name"; const string NAME = "name";
const string ATTRS = "attrs";
} }
namespace DMPolicy namespace DMPolicy

View File

@@ -50,12 +50,16 @@ void MysqlClient::close()
bool MysqlClient::exec(std::string sql) bool MysqlClient::exec(std::string sql)
{ {
//XLOGD() << "Mysql exec sql=" << sql;
if (!mysql_) if (!mysql_)
{ {
XLOGE() << "Mysql exec error, database is not connected."; XLOGE() << "Mysql exec error, database is not connected.";
return false; return false;
} }
if (sql.empty())
{
XLOGE() << "Mysql exec error, sql is empty.";
return false;
}
int ret = mysql_query(mysql_, sql.c_str()); int ret = mysql_query(mysql_, sql.c_str());
if (0 != ret) if (0 != ret)
{ {
@@ -68,28 +72,18 @@ bool MysqlClient::exec(std::string sql)
bool MysqlClient::exec(std::string sql, vector<Fields>& result) bool MysqlClient::exec(std::string sql, vector<Fields>& result)
{ {
result.clear(); result.clear();
if (!mysql_) bool ret = MysqlClient::exec(sql);
if (!ret)
{ {
return false; return false;
} }
int ret = mysql_query(mysql_, sql.c_str());
if (0 != ret)
{
//Spdlogger::error("[mysql] mysql_query failed!! error ret={:d}, sql={}", ret, sql);
XLOGE() << "mysql error: " << sql;
return false;
}
else
{
//Spdlogger::info("[mysql] query success. sql={}", sql);
}
MYSQL_RES* res = mysql_store_result(mysql_); MYSQL_RES* res = mysql_store_result(mysql_);
if (!res) if (!res)
{ {
return false; return false;
} }
vector<string> field_names; vector<string> fieldNames;
while (true) while (true)
{ {
MYSQL_FIELD* field = mysql_fetch_field(res); MYSQL_FIELD* field = mysql_fetch_field(res);
@@ -97,7 +91,7 @@ bool MysqlClient::exec(std::string sql, vector<Fields>& result)
{ {
break; break;
} }
field_names.push_back(field->name); fieldNames.push_back(field->name);
} }
while (true) while (true)
@@ -108,13 +102,13 @@ bool MysqlClient::exec(std::string sql, vector<Fields>& result)
break; break;
} }
Fields row_data; Fields rowData;
for (size_t i = 0; i < field_names.size(); ++i) for (size_t i = 0; i < fieldNames.size(); ++i)
{ {
string field_text = (row[i] == NULL) ? "" : row[i]; string field_text = (row[i] == NULL) ? "" : row[i];
row_data.set(field_names[i], field_text); rowData.set(fieldNames[i], field_text);
} }
result.push_back(row_data); result.push_back(rowData);
} }
// 释放结果集 // 释放结果集

64
src/database/SQL.cpp Normal file
View File

@@ -0,0 +1,64 @@
#include "SQL.h"
std::string SQL::str()
{
if (type == TYPE::select)
{
// SELECT * from t_tabname WHERE id='1';
if (sql_k.empty()) {}
std::string s = "SELECT " + (sql_k.empty() ? "*" : sql_k) + " FROM `" + tabname + "`";
if (!sql_c.empty()) { s += (" WHERE" + sql_c); }
return s + ";";
}
else if (type == TYPE::update)
{
// UPDATE t_tabname SET a='1', b='2' WHERE id='1';
std::string s = "UPDATE `" + tabname + "` SET " + sql_k + " WHERE" + sql_c;
return s + ";";
}
else if (type == TYPE::insert)
{
// INSERT INTO t_tabname (a,b,c) VALUES('1','2','3');
std::string s = "INSERT INTO `" + tabname + "` (" + sql_k + ") VALUES(" + sql_v + ");";
return s;
}
else if (type == TYPE::del)
{
return "";
}
return "";
}
SQL& SQL::table(std::string t)
{
tabname = t;
return *this;
}
SQL& SQL::select(std::string k)
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += k;
return *this;
}
SQL& SQL::where(std::string expr)
{
sql_c += (" " + expr);
return *this;
}
SQL& SQL::update(std::string k, std::string v)
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += ("`" + k + "`='" + v + "'");
return *this;
}
SQL& SQL::insert(std::string k, std::string v)
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += ("`" + k + "`");
if (!sql_v.empty()) { sql_v += ","; }
sql_v += ("'" + v + "'");
return *this;
}

View File

@@ -13,71 +13,19 @@ public:
del, del,
}; };
SQL(TYPE t = TYPE::select) : type(t) SQL(TYPE t = TYPE::select) : type(t) {}
{
}
std::string str() std::string str();
{
if (type == TYPE::select)
{
// SELECT * from t_tabname WHERE id='1';
if (sql_k.empty()) {}
std::string s = "SELECT " + (sql_k.empty() ? "*" : sql_k) + " FROM `" + tabname + "`";
if (!sql_c.empty()) { s += (" WHERE" + sql_c); }
return s + ";";
}
else if (type == TYPE::update)
{
// UPDATE t_tabname SET a='1', b='2' WHERE id='1';
std::string s = "UPDATE `" + tabname + "` SET " + sql_k + " WHERE" + sql_c;
return s + ";";
}
else if (type == TYPE::insert)
{
// INSERT INTO t_tabname (a,b,c) VALUES('1','2','3');
std::string s = "INSERT INTO `" + tabname + "` (" + sql_k + ") VALUES(" + sql_v + ");";
return s;
}
else if (type == TYPE::del)
{
return "";
}
return "";
}
SQL& table(std::string t)
{
tabname = t;
return *this;
}
SQL& select(std::string k) SQL& table(std::string t);
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += k;
return *this;
}
SQL& where(std::string expr)
{
sql_c += (" " + expr);
return *this;
}
SQL& update(std::string k, std::string v) SQL& select(std::string k);
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += ("`" + k + "`='" + v + "'");
return *this;
}
SQL& insert(std::string k, std::string v) SQL& where(std::string expr);
{
if (!sql_k.empty()) { sql_k += ","; } SQL& update(std::string k, std::string v);
sql_k += ("`" + k + "`");
if (!sql_v.empty()) { sql_v += ","; } SQL& insert(std::string k, std::string v);
sql_v += ("'" + v + "'");
return *this;
}
private: private:
TYPE type = TYPE::select; TYPE type = TYPE::select;

View File

@@ -18,23 +18,41 @@
#include "pv/PvApp.h" #include "pv/PvApp.h"
#include "pv/PvUser.h" #include "pv/PvUser.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
std::string str = "用户编号";
int a = str.size();
int b = str.length();
int x = 5/10 + int(6%10 != 0);
// 设置控制台输出为 UTF-8 编码 // 设置控制台输出为 UTF-8 编码
SetConsoleOutputCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8);
// 设置控制台输入为 UTF-8 编码(如果需要输入中文) // 设置控制台输入为 UTF-8 编码(如果需要输入中文)
SetConsoleCP(CP_UTF8); SetConsoleCP(CP_UTF8);
NJson jsonroot;
NJsonParse(R"({"name": "Alice", "age": 25, 111,})", jsonroot);
std::cout << (jsonroot.is_null() ? "ERROR" : "OK") << std::endl; {
NJsonNode jsonroot;
NJson::parse(R"({"name": "Alice", "age": 25, "data":[["1","1","1"],["1","1","1"],["1","1","1"]]})", jsonroot);
std::cout << (jsonroot.is_null() ? "ERROR" : "OK") << std::endl;
std::vector<std::vector<std::string>> v1;
NJson::read<std::vector<std::vector<std::string>>>(jsonroot, "data", v1);
std::vector<std::vector<std::string>> vec = {
{"1", "1", "1", "1", "1", "1", "1", "1"},
{"1", "1", "1", "1", "1", "1", "1", "1"},
{"1", "1", "1", "1", "1", "1", "1", "1"},
{"1", "1", "1", "1", "1", "1", "1", "1"}
};
NJsonNode jsonroot1;
jsonroot1["price_super_peak"] = 0.53;
jsonroot1["price_peak"] = 0.53;
jsonroot1["price_shoulder"] = 0.53;
jsonroot1["price_off_peak"] = 0.53;
jsonroot1["periods"] = vec;
std::cout << jsonroot1.dump();
}
std::cout << "===>>> main start ... " << std::endl;
////std::cout << Snowflake::instance().getId() << std::endl; ////std::cout << Snowflake::instance().getId() << std::endl;
//for (int i = 0; i<=10; ++i) { //for (int i = 0; i<=10; ++i) {
@@ -83,7 +101,7 @@ int main(int argc, char** argv)
//mainWin.show(); //mainWin.show();
//qapp.exec(); //qapp.exec();
// 运行pv主流程
PARAM p; PARAM p;
int s; int s;
pvInit(argc, argv, &p); pvInit(argc, argv, &p);

View File

@@ -5,8 +5,8 @@ std::shared_ptr<CommEntity> Communicator::createEntity(Fields& data)
{ {
std::string commType = data.value("commType"); std::string commType = data.value("commType");
std::string ip = data.value("ip"); std::string ip = data.value("ip");
int port = data.getInt("port"); int port = data.get<int>("port");
int isclient = data.getInt("isclient"); int isclient = data.get<int>("isclient");
if (commType == "TCP") if (commType == "TCP")
{ {

View File

@@ -132,7 +132,7 @@ int PvApp::image(PARAM* p, int parent, int x, int y, int w, int h, const char* f
return id; return id;
} }
int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector<std::string>& vecItems) int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector<std::string>& vecItems, int index /*= 0*/)
{ {
int id = PvApp::pvid(p); int id = PvApp::pvid(p);
pvQComboBox(p, id, parent, 0, 0); pvQComboBox(p, id, parent, 0, 0);
@@ -141,8 +141,9 @@ int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::v
for (int i=0; i<vecItems.size(); ++i) for (int i=0; i<vecItems.size(); ++i)
{ {
pvInsertItem(p, id, i, NULL, vecItems[i].c_str()); pvInsertItem(p, id, i, NULL, vecItems[i].c_str());
if (index == i) pvSetCurrentItem(p, id, i);
} }
PvApp::image(p, id, w-h, 0, h, h, "downFill.png"); PvApp::image(p, id, w-18, (h-9)*0.5, 14, 9, "downFill.png");
return id; return id;
} }
@@ -158,17 +159,44 @@ int PvApp::lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::strin
int PvApp::textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) int PvApp::textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{ {
static std::string qssTextEdit = static std::string style =
"QTextEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}" "QTextEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}"
"QTextEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}"; "QTextEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}";
int id = PvApp::pvid(p); int id = PvApp::pvid(p);
pvQMultiLineEdit(p, id, parent, true, 10); pvQMultiLineEdit(p, id, parent, true, 10);
pvSetGeometry(p, id, x, y, w, h); pvSetGeometry(p, id, x, y, w, h);
pvSetStyleSheet(p, id, qssTextEdit.c_str()); pvSetStyleSheet(p, id, style.c_str());
if (!text.empty()) { pvSetText(p, id, text.c_str()); } if (!text.empty()) { pvSetText(p, id, text.c_str()); }
return id; return id;
} }
int PvApp::radioButton(PARAM* p, int parent, int x, int y, int w, int h, std::string text)
{
static std::string style =
"QRadioButton { background-color: transparent; color:white; font: bold 14px \"微软雅黑\";}"
"QRadioButton:disabled { border: none; color:rgb(150,150,150);}";
int id = PvApp::pvid(p);
pvQRadioButton(p, id, parent);
pvSetGeometry(p, id, x, y, w, h);
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
pvSetStyleSheet(p, id, style.c_str());
return id;
}
int PvApp::timeEdit(PARAM* p, int parent, int x, int y, int w, int h)
{
static std::string style =
"QTimeEdit { background-color: rgb(17, 55, 73); border: 1px solid rgb(0, 185, 208); color:white; font: normal 14px \"微软雅黑\";}"
"QTimeEdit:disabled { border: none; color:rgb(150,150,150);}";
int id = PvApp::pvid(p);
pvQTimeEdit(p, id, parent);
pvSetGeometry(p, id, x, y, w, h);
pvSetStyleSheet(p, id, style.c_str());
return id;
}
PvRect::PvRect() PvRect::PvRect()
{ {
} }

View File

@@ -99,11 +99,15 @@ public:
static int image(PARAM* p, int parent, int x, int y, int w, int h, const char* filename); static int image(PARAM* p, int parent, int x, int y, int w, int h, const char* filename);
static int combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector<std::string>& vecItems); static int combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector<std::string>& vecItems, int index=0);
static int lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); static int lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = "");
static int textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); static int textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = "");
static int radioButton(PARAM* p, int parent, int x, int y, int w, int h, std::string text);
static int timeEdit(PARAM* p, int parent, int x, int y, int w, int h);
}; };
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -159,7 +159,7 @@ Fields PvPopWidget::getChangedData()
{ {
auto& key = it->second->key; auto& key = it->second->key;
auto& val = it->second->val; auto& val = it->second->val;
if (primaryKeys.hasKey(key) || val != dataOrigin.value(key)) if (primaryKeys.contains(key) || val != dataOrigin.value(key))
{ {
fields.set(key, val); fields.set(key, val);
} }
@@ -174,7 +174,7 @@ void PvPopWidget::checkChangedData(Fields& fields)
{ {
auto& key = it->first; auto& key = it->first;
auto& val = it->second; auto& val = it->second;
if (!primaryKeys.hasKey(key) && val == dataOrigin.value(key)) if (!primaryKeys.contains(key) && val == dataOrigin.value(key))
{ {
mapItems.erase(it); mapItems.erase(it);
} }

View File

@@ -111,15 +111,11 @@ namespace qss
"QComboBox:disabled { color:rgb(150,150,150);}"; "QComboBox:disabled { color:rgb(150,150,150);}";
const std::string LINEEDIT = const std::string LINEEDIT =
"QLineEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}" "QLineEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 14px;}"
"QLineEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}"; "QLineEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}";
const std::string STYLE_TITLE_ICON = const std::string STYLE_TITLE_ICON =
"padding-top: 0px;" "padding-top: 0px;"
"background-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 71, 105, 255),stop:1 rgba(0, 71, 105, 0));" "background-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 71, 105, 255),stop:1 rgba(0, 71, 105, 0));"
@@ -142,7 +138,7 @@ namespace qss
// 表头标签 // 表头标签
const std::string QSS_TABLE_HEAD = const std::string QSS_TABLE_HEAD =
qss::label(15, "", "rgb(18, 93, 113)", "1px solid rgb(120, 120, 120); border-style:inset solid"); qss::label(14, "", "rgb(18, 93, 113)", "1px solid rgb(120, 120, 120); border-style:inset solid");
//"background-color: rgb(18, 93, 113); color:rgb(255, 255, 255); font:bold 16px;" //"background-color: rgb(18, 93, 113); color:rgb(255, 255, 255); font:bold 16px;"
//"border-width:1 1 1 1px; border-style:inset solid; border-color:rgb(120, 120, 120);"; //"border-width:1 1 1 1px; border-style:inset solid; border-color:rgb(120, 120, 120);";

View File

@@ -1,6 +1,7 @@
#include "PvTable.h" #include "PvTable.h"
#include "PvStyle.h" #include "PvStyle.h"
#include "pv/PvApp.h" #include "pv/PvApp.h"
#include "pv/PvPopWidget.h"
static const string STYLE_BKG = static const string STYLE_BKG =
"border-width:1 1 1 1px; border-style:outset solid; border-color:rgba(180,180,180,255);" "border-width:1 1 1 1px; border-style:outset solid; border-color:rgba(180,180,180,255);"
@@ -208,7 +209,7 @@ void PvTable::mappingData(Fields& fields)
for (int i=0; i< vecHead_.size(); ++i) for (int i=0; i< vecHead_.size(); ++i)
{ {
auto& head = vecHead_[i]; auto& head = vecHead_[i];
if (fields.hasKey(head.id)) if (fields.contains(head.id))
{ {
auto& val = fields.value(head.id); auto& val = fields.value(head.id);
val = head.getMapping(val); val = head.getMapping(val);
@@ -417,16 +418,91 @@ void PvPagination::setCallback(std::function<void(int index)> func)
callback = func; callback = func;
} }
PvPageTable::PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts)
//: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* rows + (opts.show_header ? (opts.header_height) : 0)))
: PvObject(p)
{
int h = opts.row_height* rows + (opts.show_header ? (opts.head_height) : 0);
int pvid_ = PvApp::widget(p, parent, x, y, w, h);
table_ = make_shared<PvTable>(p, pvid_, 0, 0, w, rows, opts);
}
shared_ptr<PvTable> PvPageTable::getTable() ///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageTable ===
PageTable::PageTable(PARAM* p) : PvMask(p)
{ {
return table_; 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));
}

View File

@@ -158,16 +158,34 @@ private:
}; };
class PvPageTable :public PvObject ///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageTable ===
class PvPopWidget;
class PageTable : public PvMask
{ {
public: public:
PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts); PageTable(PARAM* p);
shared_ptr<PvTable> getTable(); void setPage(int pageIndex, int pageSize, int count) {}
private: std::shared_ptr<PvPopWidget> addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys);
shared_ptr<PvTable> table_ = nullptr;
shared_ptr<PvPagination> page_ctrl_ = nullptr; void showPop(int index, std::string optr, Fields& fields);
void hidePop(int index);
void updateDataFromDB();
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) {}
virtual void onOperate(int row, int col, std::string oper) {};
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
int pageSize {15};
int pageIndex {0};
PvTable::Options option;
std::shared_ptr<PvTable> table;
std::shared_ptr<PvPagination> pagination;
std::vector<std::shared_ptr<PvPopWidget>> vecPop;
}; };
#endif // ! _PvTable_H_ #endif // ! _PvTable_H_

View File

@@ -5,6 +5,20 @@
#include "pv/PvTable.h" #include "pv/PvTable.h"
#include "pv/PvChart.h" #include "pv/PvChart.h"
#include "pv/PvPopWidget.h"
#include "pv/pages/PanelPolicy.h"
void TestPage(PARAM* p)
{
auto& appdata = Application::data();
auto pagination = new PvPagination(p, 0, 600, 160, 20);
pagination->setPage(5, 10);
int id = PvApp::label(p, 0, 0, 0, 1920, 800, "", qss::label(14, "", "rgb(15, 50, 68)"));
new PanelPolicyPeak(p, id, 0, 0, 1920, 1080);
}
static int CreatePanel(PARAM* p, int parent, int x, int y, int w, int h, std::string title) static int CreatePanel(PARAM* p, int parent, int x, int y, int w, int h, std::string title)
{ {
@@ -304,8 +318,10 @@ int MaskPageHome::initUI(EPvCode pvcode)
this->updateUI(); this->updateUI();
auto pagination = new PvPagination(p, 0, 600, 160, 20);
pagination->setPage(5, 10); TestPage(p);
return 0; return 0;
} }

View File

@@ -1,6 +1,6 @@
#include "MaskPageRunning.h" #include "MaskPageRunning.h"
#include "app/Application.h" #include "app/Application.h"
#include "app/AppData.h"
static int CreateParamLabel(PARAM* p, int parent, int x, int y, std::string k, std::string v) static int CreateParamLabel(PARAM* p, int parent, int x, int y, std::string k, std::string v)
{ {
@@ -119,10 +119,10 @@ int MaskPageRunning::initUI(EPvCode pvcode)
} }
PvApp::label(p, 0, 320, 110, 80, 30, "运行模式", "color:white; font: bold 16px;"); PvApp::label(p, 0, 320, 110, 80, 30, "运行模式", "color:white; font: bold 16px;");
PvApp::combox(p, 0, 400, 110, 200, 30, {"最优经济化运行模式", "最优经济化运行模式", "自定义"}); PvApp::combox(p, 0, 400, 110, 200, 30, Application::data().getWorkModes());
PvApp::label(p, 0, 670, 110, 80, 30, "策略名称", "color:white; font: bold 16px;"); PvApp::label(p, 0, 670, 110, 80, 30, "策略名称", "color:white; font: bold 16px;");
PvApp::combox(p, 0, 750, 110, 200, 30, {"峰谷套利策略", "需求响应策略", "自发自用上网策略"}); PvApp::combox(p, 0, 750, 110, 200, 30, Application::data().getPolicyNames());
int x = 20, y = 160, w = 200, h = 180; int x = 20, y = 160, w = 200, h = 180;
// 储能设备 // 储能设备

View File

@@ -6,7 +6,7 @@
#include "pv/PvPopWidget.h" #include "pv/PvPopWidget.h"
#include "database/Dao.h" #include "database/Dao.h"
#include "app/Application.h" #include "app/Application.h"
#include "PageSysmgrPop.h" #include "PageSysmgr.h"
static void createPvTable(PARAM* p) static void createPvTable(PARAM* p)
{ {

View File

@@ -1,4 +1,4 @@
#include "PageSysmgrPop.h" #include "PageSysmgr.h"
#include "app/Application.h" #include "app/Application.h"
@@ -6,94 +6,6 @@
#include "database/DataModelDef.h" #include "database/DataModelDef.h"
#include "common/Snowflake.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 ===
@@ -215,6 +127,7 @@ std::string PageRole::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fie
return ""; return "";
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePermission === // === PagePermission ===
PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p) PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p)
@@ -326,13 +239,14 @@ std::string PageStation::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields&
} }
return ""; return "";
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageDevice === // === PageDevice ===
PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p) PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p)
{ {
auto& appdata = Application::data(); auto& appdata = Application::data();
table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {}); table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {});
table->addHead(DMDevice::TYPE_ID, "设备类型", 120, appdata.mapping.deviceType); table->addHead(DMDevice::TYPE, "设备类型", 120, appdata.mapping.deviceType);
table->addHead(DMDevice::NAME, "设备名称", 180, {}); table->addHead(DMDevice::NAME, "设备名称", 180, {});
table->addHead(DMDevice::CODE, "设备编码", 160, {}); table->addHead(DMDevice::CODE, "设备编码", 160, {});
table->addHead(DMDevice::MODEL, "设备型号", 160, {}); table->addHead(DMDevice::MODEL, "设备型号", 160, {});
@@ -348,7 +262,7 @@ PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p)
int x = 50, y = 80, w = 350, h = 60; int x = 50, y = 80, w = 350, h = 60;
auto pop = this->addPop(700, 520, 180, "设备信息", {DMDevice::DEVICE_ID}); auto pop = this->addPop(700, 520, 180, "设备信息", {DMDevice::DEVICE_ID});
pop->addParamLineEdit(DMDevice::DEVICE_ID, "设备编号", x, y, false); pop->addParamLineEdit(DMDevice::DEVICE_ID, "设备编号", x, y, false);
pop->addParamCombox(DMDevice::TYPE_ID, "类型", x+w, y, appdata.getDeviceTypes()); pop->addParamCombox(DMDevice::TYPE, "类型", x+w, y, appdata.getDeviceTypeNames());
pop->addParamLineEdit(DMDevice::NAME, "设备名称", x, y += h); pop->addParamLineEdit(DMDevice::NAME, "设备名称", x, y += h);
pop->addParamLineEdit(DMDevice::CODE, "设备编码", x+w, y); pop->addParamLineEdit(DMDevice::CODE, "设备编码", x+w, y);
pop->addParamLineEdit(DMDevice::MODEL, "设备型号", x, y += h); pop->addParamLineEdit(DMDevice::MODEL, "设备型号", x, y += h);
@@ -394,8 +308,11 @@ std::string PageDevice::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& f
} }
return ""; return "";
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePolicy === // === PagePolicy ===
PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p) PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p)
{ {
auto& appdata = Application::data(); auto& appdata = Application::data();
@@ -410,9 +327,18 @@ PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p)
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); 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); }); PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60; int x = 50, y = 80, w = 280;
auto pop = this->addPop(500, 600, 180, "策略信息", {DMPolicy::POLICY_ID}); auto pop = this->addPop(1620, 800, 180, "策略信息", {DMPolicy::POLICY_ID});
pop->addParamLineEdit(DMPolicy::POLICY_ID, "编号", x, y, false); //pop->addParamLineEdit(DMPolicy::POLICY_ID, "编号", x, y, false);
{
pop->addParamLineEdit("1", "策略名称", x, y);
pop->addParamCombox("2", "策略类型", x+w, y, {"峰谷套利"});
pop->addParamLineEdit("3", "尖峰电价", x, y += 50);
pop->addParamLineEdit("4", "高峰电价", x+w, y);
pop->addParamLineEdit("5", "平段电价", x+w*2, y);
pop->addParamLineEdit("6", "低谷电价", x+w*3, y);
}
} }
void PagePolicy::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) void PagePolicy::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{ {
@@ -423,12 +349,18 @@ void PagePolicy::onOperate(int row, int col, std::string oper)
if (oper == POP_OPER_NEW) if (oper == POP_OPER_NEW)
{ {
Fields fields; Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields); this->showPop(0, oper, fields);
} }
else if (oper == POP_OPER_EDIT) else if (oper == POP_OPER_EDIT)
{ {
this->showPop(0, oper, table->getRowData(row)); table->getRowData(row);
auto& appdata = Application::data();
Fields fields;
fields.set("3", appdata.electPriceSuperPeak);
fields.set("4", appdata.electPricePeak);
fields.set("5", appdata.electPriceShoulder);
fields.set("6", appdata.electPriceOffPeak);
this->showPop(0, oper, fields);
} }
} }
std::string PagePolicy::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) std::string PagePolicy::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
@@ -438,6 +370,8 @@ std::string PagePolicy::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& f
std::string PagePolicy::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) std::string PagePolicy::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{ {
return ""; return "";
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -3,34 +3,6 @@
#include "pv/PvTable.h" #include "pv/PvTable.h"
#include "pv/PvPopWidget.h" #include "pv/PvPopWidget.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageTable ===
class PageTable : public PvMask
{
public:
PageTable(PARAM* p);
void setPage(int pageIndex, int pageSize, int count) {}
std::shared_ptr<PvPopWidget> addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys);
void showPop(int index, std::string optr, Fields& fields);
void hidePop(int index);
void updateDataFromDB();
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) {}
virtual void onOperate(int row, int col, std::string oper) {};
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
int pageSize {15};
int pageIndex {0};
PvTable::Options option;
std::shared_ptr<PvTable> table;
std::shared_ptr<PvPagination> pagination;
std::vector<std::shared_ptr<PvPopWidget>> vecPop;
};
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageUser === // === PageUser ===
@@ -108,6 +80,8 @@ public:
virtual void onOperate(int row, int col, std::string oper) override; virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override; virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override; virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
}; };
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,366 @@
#include "PanelPolicy.h"
#include "app/Application.h"
#include "app/AppData.h"
#include "common/JsonN.h"
const std::string QSS_COMBOX_1 =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(255, 89, 0); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
const std::string QSS_COMBOX_2 =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(255, 255, 0); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
const std::string QSS_COMBOX_3 =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(121, 191, 226); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
const std::string QSS_COMBOX_4 =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(0, 255, 58); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
static std::string GetPeriodQss(int v)
{
if (v == 1) { return QSS_COMBOX_1; }
else if (v == 2) { return QSS_COMBOX_2; }
else if (v == 3) { return QSS_COMBOX_3; }
else if (v == 4) { return QSS_COMBOX_4; }
else { return QSS_COMBOX_1; }
}
static std::string GetPeriodQss(std::string text)
{
if (text == "尖峰") { return QSS_COMBOX_1; }
else if (text == "高峰") { return QSS_COMBOX_2; }
else if (text == "平段") { return QSS_COMBOX_3; }
else if (text == "低谷") { return QSS_COMBOX_4; }
else { return QSS_COMBOX_1; }
}
static int GetPeriod(std::string text)
{
if (text == "尖峰") { return 1; }
else if (text == "高峰") { return 2; }
else if (text == "平段") { return 3; }
else if (text == "低谷") { return 4; }
else { return 3; }
}
PanelPolicyPeak::PanelPolicyPeak(PARAM* p, int parent, int x, int y, int w, int h) : PvObject(p)
{
data.vecPeriods.resize(12, std::vector<int>(24, 3));
ui.parent = parent;
ui.widget = PvApp::widget(p, parent, x, y, w, h);
auto& appdata = Application::data();
std::vector<std::string> vecPeriods = {"尖峰", "高峰", "平段", "低谷"};
ui.vecComboxs.resize(12, std::vector<int>(24, PV_ID_NUL));
{
int parent = ui.widget;
int x = 10, y = 180, w = 64, h = 30;
for (int row = 0; row<=12; row++)
{
for (int col = 0; col<=24; ++col)
{
std::string text;
if (row == 0)
{
text = (col == 0) ? "月份" : std::to_string(col-1) + "-" + std::to_string(col) + "";
}
else
{
text = (col == 0) ? std::to_string(row) : "";
}
if (row == 0 || col == 0)
{
std::string qssLabel = (row==0) ? qss::label(14, "", "rgb(19, 93, 114)") : "";
int label = PvApp::label(p, parent, x+w*col, y+h*row, w, h, text, qssLabel);
pvSetAlignment(p, label, AlignCenter);
}
else
{
int periodVal = data.vecPeriods[row-1][col-1];
int combox = PvApp::combox(p, parent, x+w*col, y+h*row+3, w-3, 24, vecPeriods, periodVal);
pvSetStyleSheet(p, combox, GetPeriodQss(periodVal).c_str());
ui.vecComboxs[row-1][col-1] = combox;
PvApp::bind(p, PvEvent::TEXT_EVENT, combox, [=](std::string text) {
pvSetStyleSheet(p, combox, GetPeriodQss(text).c_str());
data.vecPeriods[row-1][col-1] = GetPeriod(text);
});
}
}
}
const int H = 24;
int labelPolicy = PvApp::label(p, parent, 20, 600, 300, H, "充电策略");
ui.radioPolicy1 = PvApp::radioButton(p, labelPolicy, 80, 0, 80, H, "一充一放");
ui.radioPolicy2 = PvApp::radioButton(p, labelPolicy, 170, 0, 80, H, "两充两放");
ui.label1 = PvApp::label(p, parent, 10, 640, 610, 90, "第一次充放电过程", qss::label(14, "", "", "1px solid rgb(49, 130, 141)"));
pvSetAlignment(p, ui.label1, AlignLeft | AlignTop);
{
int y0 = 70;
int labelChargeT = PvApp::label(p, ui.label1, 10, 30, 300, H, "充电时间");
ui.attr1TimeCharge0 = PvApp::timeEdit(p, labelChargeT, y0, 0, 60, H);
PvApp::label(p, labelChargeT, 150, 0, 10, H, "--");
ui.attr1TimeCharge1 = PvApp::timeEdit(p, labelChargeT, 170, 0, 60, H);
int labelDischargeT = PvApp::label(p, ui.label1, 320, 30, 300, H, "放电时间");
ui.attr1TimeDischarge0 = PvApp::timeEdit(p, labelDischargeT, y0 = 70, 0, 60, H);
PvApp::label(p, labelDischargeT, y0+=70, 0, 10, H, "--");
ui.attr1TimeDischarge1 = PvApp::timeEdit(p, labelDischargeT, y0+=20, 0, 60, H);
int labelPowerIn = PvApp::label(p, ui.label1, 10, 60, 300, H, "充电功率");
ui.attr1RadioPowerInAuto = PvApp::radioButton(p, labelPowerIn, y0 = 70, 0, 60, H, "自动");
ui.attr1RadioPowerIn = PvApp::radioButton(p, labelPowerIn, y0 += 60, 0, 64, H, "自定义");
ui.arrt1LabelPowerIn = PvApp::lineEdit(p, labelPowerIn, y0 += 70, 0, 80, H, "");
int labelPowerOut = PvApp::label(p, ui.label1, 320, 60, 300, H, "放电功率");
ui.attr1RadioPowerOutAuto = PvApp::radioButton(p, labelPowerOut, y0 = 70, 0, 60, H, "自动");
ui.attr1RadioPowerOut = PvApp::radioButton(p, labelPowerOut, y0 += 60, 0, 64, H, "自定义");
ui.arrt1LabelPowerOut = PvApp::lineEdit(p, labelPowerOut, y0 += 70, 0, 80, H, "");
}
ui.label2 = PvApp::label(p, parent, 630, 640, 610, 90, "第二次充放电过程", qss::label(14, "", "", "1px solid rgb(49, 130, 141)"));
pvSetAlignment(p, ui.label2, AlignLeft | AlignTop);
{
int y0 = 70;
int labelChargeT = PvApp::label(p, ui.label2, 10, 30, 300, H, "充电时间");
XLOGD() << "labelChargeT=" << labelChargeT;
ui.attr2TimeCharge0 = PvApp::timeEdit(p, labelChargeT, y0, 0, 60, H);
PvApp::label(p, labelChargeT, 150, 0, 10, H, "--");
ui.attr2TimeCharge1 = PvApp::timeEdit(p, labelChargeT, 170, 0, 60, H);
int labelDischargeT = PvApp::label(p, ui.label2, 320, 30, 300, H, "放电时间");
ui.attr2TimeDischarge0 = PvApp::timeEdit(p, labelDischargeT, y0 = 70, 0, 60, H);
PvApp::label(p, labelDischargeT, y0 += 70, 0, 10, H, "--");
ui.attr2TimeDischarge1 = PvApp::timeEdit(p, labelDischargeT, y0 += 20, 0, 60, H);
int labelPowerIn = PvApp::label(p, ui.label2, 10, 60, 300, H, "充电功率");
ui.attr2RadioPowerInAuto = PvApp::radioButton(p, labelPowerIn, y0 = 70, 0, 60, H, "自动");
ui.attr2RadioPowerIn = PvApp::radioButton(p, labelPowerIn, y0 += 60, 0, 64, H, "自定义");
ui.arrt2LabelPowerIn = PvApp::lineEdit(p, labelPowerIn, y0 += 70, 0, 80, H, "");
int labelPowerOut = PvApp::label(p, ui.label2, 320, 60, 300, H, "放电功率");
ui.attr2RadioPowerOutAuto = PvApp::radioButton(p, labelPowerOut, y0 = 70, 0, 60, H, "自动");
ui.attr2RadioPowerOut = PvApp::radioButton(p, labelPowerOut, y0 += 60, 0, 64, H, "自定义");
ui.arrt2LabelPowerOut = PvApp::lineEdit(p, labelPowerOut, y0 += 70, 0, 80, H, "");
}
PvApp::bind(p, PvEvent::RADIOBUTTON_EVENT, ui.radioPolicy1, [=](std::string s) {
this->data.times = 1;
pvHide(p, ui.label2);
//setTimeText(ui.attr2TimeCharge0, "");
//setTimeText(ui.attr2TimeCharge1, "");
//setTimeText(ui.attr2TimeDischarge0, "");
//setTimeText(ui.attr2TimeDischarge1, "");
//pvSetChecked(p, ui.attr2RadioPowerInAuto, 1);
//pvSetChecked(p, ui.attr2RadioPowerOutAuto, 1);
//pvSetText(p, ui.arrt2LabelPowerOut, "");
//data.attr2.chargePower = data.attr2.dischargePower = 0.0;
//data.attr2.chargeTimeStart = data.attr2.chargeTimeEnd = data.attr2.dischargeTimeStart = data.attr2.dischargeTimeEnd = "";
});
PvApp::bind(p, PvEvent::RADIOBUTTON_EVENT, ui.radioPolicy2, [=](std::string s) {
this->data.times = 2;
pvShow(p, ui.label2);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeCharge0, [=](std::string s) {
data.attr1.chargeTimeStart = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeCharge1, [=](std::string s) {
data.attr1.chargeTimeEnd = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeDischarge0, [=](std::string s) {
data.attr1.dischargeTimeStart = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeDischarge1, [=](std::string s) {
data.attr1.dischargeTimeEnd = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeCharge0, [=](std::string s) {
data.attr2.chargeTimeStart = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeCharge1, [=](std::string s) {
data.attr2.chargeTimeEnd = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeDischarge0, [=](std::string s) {
data.attr2.dischargeTimeStart = s.substr(0, 8);
});
PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeDischarge1, [=](std::string s) {
data.attr2.dischargeTimeEnd = s.substr(0, 8);
});
{
int btn = PvApp::button(p, ui.widget, 10, 750, 100, 30, "DUMP");
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
XLOGD() << dumpAttr();
});
}
{
int btn = PvApp::button(p, ui.widget, 110, 750, 100, 30, "PARSE1");
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
std::string s = R"({"cycle":[{"charge_end":"","charge_power":0.0,"charge_start":"","discharge_end":"","discharge_power":0.0,"discharge_start":""}],
"period":[[1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]],
"times":1})";
parseAttr(s);
});
}
{
int btn = PvApp::button(p, ui.widget, 210, 750, 100, 30, "PARSE2");
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
std::string s = R"({"cycle":[{"charge_end":"09:00:00","charge_power":0.0,"charge_start":"00:00:00","discharge_end":"","discharge_power":0.0,"discharge_start":""}],
"period":[[1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]],
"times":2})";
parseAttr(s);
});
}
}
}
void PanelPolicyPeak::updateUI()
{
}
void PanelPolicyPeak::setTimeText(int id, std::string s)
{
int hour {0}, minute {0}, second {0};
sscanf_s(s.c_str(), "%d:%d:%d", &hour, &minute, &second);
pvSetTime(p, id, hour, minute, second);
}
void PanelPolicyPeak::parseAttr(std::string str)
{
NJsonNode jsonroot;
bool ret = NJson::parse(str, jsonroot);
if (!ret)
{
return;
}
NJson::read(jsonroot, "times", data.times);
// 更新UI (充电策略)
if (data.times == 2)
{
pvSetChecked(p, ui.radioPolicy2, 1);
pvShow(p, ui.label2);
}
else
{
pvSetChecked(p, ui.radioPolicy1, 1);
pvHide(p, ui.label2);
}
std::vector<std::vector<int>> vecTmp;
NJson::read<std::vector<std::vector<int>>>(jsonroot, "period", vecTmp);
for (int row = 0; row < data.vecPeriods.size(); ++row)
{
auto& vecRows = data.vecPeriods[row];
for (int col = 0; col < vecRows.size(); ++col)
{
auto& periodVal = vecRows[col];
int tmpVal {};
if (row < vecTmp.size())
{
tmpVal = (col < vecTmp[row].size() ? vecTmp[row][col] : 3);
}
else
{
tmpVal = 3;
}
if (periodVal != tmpVal)
{
periodVal = tmpVal;
// 更新UI (时段下拉列表)
auto combox = ui.vecComboxs[row][col];
pvSetCurrentItem(p, combox, periodVal);
pvSetStyleSheet(p, combox, GetPeriodQss(periodVal).c_str());
}
}
}
if (jsonroot.contains("cycle"))
{
auto& jsonCycle = jsonroot["cycle"];
if (jsonCycle.is_array())
{
auto size = jsonCycle.size();
if (size >= 1)
{
data.attr1.chargeTimeStart = jsonCycle[0]["charge_start"];
data.attr1.chargeTimeEnd = jsonCycle[0]["charge_end"];
data.attr1.chargePower = jsonCycle[0]["charge_power"];
data.attr1.dischargeTimeStart = jsonCycle[0]["discharge_start"];
data.attr1.dischargeTimeEnd = jsonCycle[0]["discharge_end"];
data.attr1.dischargePower = jsonCycle[0]["discharge_power"];
// 更新UI (一放一充)
setTimeText(ui.attr1TimeCharge0, data.attr1.chargeTimeStart);
setTimeText(ui.attr1TimeCharge1, data.attr1.chargeTimeEnd);
//setTimeText(ui.attr1TimeCharge1, data.attr1.chargeTimeEnd);
setTimeText(ui.attr1TimeDischarge0, data.attr1.dischargeTimeStart);
setTimeText(ui.attr1TimeDischarge1, data.attr1.dischargeTimeEnd);
//setTimeText(ui.attr1TimeCharge1, data.attr1.chargeTimeEnd);
}
if (size >= 2)
{
data.attr2.chargeTimeStart = jsonCycle[1]["charge_start"];
data.attr2.chargeTimeEnd = jsonCycle[1]["charge_end"];
data.attr2.chargePower = jsonCycle[1]["charge_power"];
data.attr2.dischargeTimeStart = jsonCycle[1]["discharge_start"];
data.attr2.dischargeTimeEnd = jsonCycle[1]["discharge_end"];
data.attr2.dischargePower = jsonCycle[1]["discharge_power"];
// 更新UI (两放两充)
setTimeText(ui.attr2TimeCharge0, data.attr2.chargeTimeStart);
setTimeText(ui.attr2TimeCharge1, data.attr2.chargeTimeEnd);
//setTimeText(ui.attr2TimeCharge1, data.attr2.chargeTimeEnd);
setTimeText(ui.attr2TimeDischarge0, data.attr2.dischargeTimeStart);
setTimeText(ui.attr2TimeDischarge1, data.attr2.dischargeTimeEnd);
//setTimeText(ui.attr2TimeCharge1, data.attr2.chargeTimeEnd);
}
}
}
// 更新UI
}
std::string PanelPolicyPeak::dumpAttr()
{
NJsonNode jsonroot;
jsonroot["period"] = data.vecPeriods;
jsonroot["times"] = data.times;
NJsonNode nodeCycle = NJsonNode::array();
NJsonNode nodeAttr1;
nodeAttr1["charge_start"] = data.attr1.chargeTimeStart;
nodeAttr1["charge_end"] = data.attr1.chargeTimeEnd;
nodeAttr1["charge_power"] = data.attr1.chargePower;
nodeAttr1["discharge_start"] = data.attr1.dischargeTimeStart;
nodeAttr1["discharge_end"] = data.attr1.dischargeTimeEnd;
nodeAttr1["discharge_power"] = data.attr1.dischargePower;
nodeCycle.push_back(nodeAttr1);
if (data.times > 1)
{
NJsonNode nodeAttr2;
nodeAttr2["charge_start"] = data.attr2.chargeTimeStart;
nodeAttr2["charge_end"] = data.attr2.chargeTimeEnd;
nodeAttr2["charge_power"] = data.attr2.chargePower;
nodeAttr2["discharge_start"] = data.attr2.dischargeTimeStart;
nodeAttr2["discharge_end"] = data.attr2.dischargeTimeEnd;
nodeAttr2["discharge_power"] = data.attr2.dischargePower;
nodeCycle.push_back(nodeAttr2);
}
jsonroot["cycle"] = nodeCycle;
return jsonroot.dump();
}

View File

@@ -0,0 +1,75 @@
#pragma once
#include "pv/PvApp.h"
// 峰谷套利策、需求响应、自发自用
class PanelPolicyPeak : public PvObject
{
public:
PanelPolicyPeak(PARAM* p, int parent, int x, int y, int w, int h);
void updateUI();
void setTimeText(int id, std::string s);
void parseAttr(std::string str);
std::string dumpAttr();
struct {
int parent {};
int widget {PV_ID_NUL};
int label1 {PV_ID_NUL};
int label2 {PV_ID_NUL};
int radioPolicy1 {PV_ID_NUL};
int radioPolicy2 {PV_ID_NUL};
int attr1TimeCharge0 {PV_ID_NUL};
int attr1TimeCharge1 {PV_ID_NUL};
int attr1TimeDischarge0 {PV_ID_NUL};
int attr1TimeDischarge1 {PV_ID_NUL};
int attr1RadioPowerInAuto {PV_ID_NUL};
int attr1RadioPowerIn {PV_ID_NUL};
int arrt1LabelPowerIn {PV_ID_NUL};
int attr1RadioPowerOutAuto {PV_ID_NUL};
int attr1RadioPowerOut {PV_ID_NUL};
int arrt1LabelPowerOut {PV_ID_NUL};
int attr2TimeCharge0 {PV_ID_NUL};
int attr2TimeCharge1 {PV_ID_NUL};
int attr2TimeDischarge0 {PV_ID_NUL};
int attr2TimeDischarge1 {PV_ID_NUL};
int attr2RadioPowerInAuto {PV_ID_NUL};
int attr2RadioPowerIn {PV_ID_NUL};
int arrt2LabelPowerIn {PV_ID_NUL};
int attr2RadioPowerOutAuto {PV_ID_NUL};
int attr2RadioPowerOut {PV_ID_NUL};
int arrt2LabelPowerOut {PV_ID_NUL};
std::vector<std::vector<int>> vecComboxs {};
} ui;
struct ChargeAttr
{
std::string chargeTimeStart;
std::string chargeTimeEnd;
double chargePower {0.0};
std::string dischargeTimeStart;
std::string dischargeTimeEnd;
double dischargePower {0.0};
};
struct {
int times {1};
ChargeAttr attr1;
ChargeAttr attr2;
std::vector<std::vector<int>> vecPeriods;
} data;
};

View File

@@ -45,7 +45,7 @@ int pvMain(PARAM* p)
mask = std::make_shared<MaskMain>(p, pvcode); mask = std::make_shared<MaskMain>(p, pvcode);
// 超过设定数量值的控件将不会显示 // 超过设定数量值的控件将不会显示
pvStartDefinition(p, 1024); pvStartDefinition(p, 2048);
if (mask) if (mask)
{ {
pvSetFont(p, PV_ID_MAIN, "微软雅黑", 12, 1, 0, 0, 0); pvSetFont(p, PV_ID_MAIN, "微软雅黑", 12, 1, 0, 0, 0);
@@ -75,30 +75,30 @@ int pvMain(PARAM* p)
pvcode = mask->onEventNull(pvid); pvcode = mask->onEventNull(pvid);
} break; } break;
case BUTTON_EVENT: { case BUTTON_EVENT: {
pvcode = mask->onEventButton(pvid); std::cout << "EVENT: BUTTON\n"; pvcode = mask->onEventButton(pvid); std::cout << "EVENT: (" << pvid << ")BUTTON\n";
} break; } break;
case TEXT_EVENT: {} break; case TEXT_EVENT: { std::cout << "EVENT: (" << pvid << ")TEXT_EVENT\n"; } break;
case SLIDER_EVENT: {} break; case SLIDER_EVENT: { std::cout << "EVENT: (" << pvid << ")SLIDER_EVENT\n"; } break;
case CHECKBOX_EVENT: {} break; case CHECKBOX_EVENT: { std::cout << "EVENT: (" << pvid << ")CHECKBOX_EVENT\n"; } break;
case RADIOBUTTON_EVENT: {} break; case RADIOBUTTON_EVENT: { std::cout << "EVENT: (" << pvid << ")RADIOBUTTON_EVENT\n"; } break;
case GL_IDLE_EVENT: {} break; case GL_IDLE_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_IDLE_EVENT\n"; } break;
case GL_PAINT_EVENT: {} break; case GL_PAINT_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_PAINT_EVENT\n"; } break;
case GL_INITIALIZE_EVENT: {} break; case GL_INITIALIZE_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_INITIALIZE_EVENT\n"; } break;
case GL_RESIZE_EVENT: {} break; case GL_RESIZE_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_RESIZE_EVENT\n"; } break;
case TAB_EVENT: {} break; case TAB_EVENT: { std::cout << "EVENT: (" << pvid << ")TAB_EVENT\n"; } break;
case TABLE_CLICKED_EVENT: {} break; case TABLE_CLICKED_EVENT: { std::cout << "EVENT: (" << pvid << ")TABLE_CLICKED_EVENT\n"; } break;
case TABLE_TEXT_EVENT: {} break; case TABLE_TEXT_EVENT: { std::cout << "EVENT: (" << pvid << ")TABLE_TEXT_EVENT\n"; } break;
case SELECTION_EVENT: {} break; case SELECTION_EVENT: { std::cout << "EVENT: (" << pvid << ")SELECTION_EVENT\n"; } break;
case CLIPBOARD_EVENT: {} break; case CLIPBOARD_EVENT: { std::cout << "EVENT: (" << pvid << ")CLIPBOARD_EVENT\n"; } break;
case BUTTON_PRESSED_EVENT: {} break; case BUTTON_PRESSED_EVENT: { std::cout << "EVENT: (" << pvid << ")BUTTON_PRESSED_EVENT\n"; } break;
case BUTTON_RELEASED_EVENT: {} break; case BUTTON_RELEASED_EVENT: { std::cout << "EVENT: (" << pvid << ")BUTTON_RELEASED_EVENT\n"; } break;
case RIGHT_MOUSE_EVENT: {} break; case RIGHT_MOUSE_EVENT: { std::cout << "EVENT: (" << pvid << ")RIGHT_MOUSE_EVENT\n"; } break;
case KEYBOARD_EVENT: {} break; case KEYBOARD_EVENT: { std::cout << "EVENT: (" << pvid << ")KEYBOARD_EVENT\n"; } break;
case PLOT_MOUSE_MOVED_EVENT: {} break; case PLOT_MOUSE_MOVED_EVENT: { std::cout << "EVENT: (" << pvid << ")PLOT_MOUSE_MOVED_EVENT\n"; } break;
case PLOT_MOUSE_PRESSED_EVENT: {} break; case PLOT_MOUSE_PRESSED_EVENT: { std::cout << "EVENT: (" << pvid << ")PLOT_MOUSE_PRESSED_EVENT\n"; } break;
case PLOT_MOUSE_RELEASED_EVENT: {} break; case PLOT_MOUSE_RELEASED_EVENT: { std::cout << "EVENT: (" << pvid << ")PLOT_MOUSE_RELEASED_EVENT\n"; } break;
case USER_EVENT: {} break; case USER_EVENT: { std::cout << "EVENT: (" << pvid << ")USER_EVENT\n"; } break;
case MOUSE_OVER_EVENT: {} break; case MOUSE_OVER_EVENT: { /*std::cout << "EVENT: (" << pvid << ")MOUSE_OVER_EVENT\n";*/ } break;
default: {} break; default: {} break;
} }
} }