mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现策略配置功能
This commit is contained in:
@@ -51,10 +51,11 @@ void AppData::initFromDB()
|
||||
DAO::queryWorkModeDef(dao, result);
|
||||
for (auto& fields: result)
|
||||
{
|
||||
std::string workModeId = fields.value(DMDefWorkMode::WORK_MODE_ID);
|
||||
int workModeId = fields.get<int>(DMDefWorkMode::WORK_MODE_ID);
|
||||
std::string name = fields.value(DMDefWorkMode::NAME);
|
||||
this->mapping.workMode.push_back({workModeId, name});
|
||||
str += ("工作模式: {" + workModeId + ":" + name + "},");
|
||||
this->mapping.workMode.push_back({std::to_string(workModeId), name});
|
||||
this->mapWorkMode[workModeId] = name;
|
||||
str += ("工作模式: {" + std::to_string(workModeId)+":" + name + "},");
|
||||
}
|
||||
XLOGD() << str;
|
||||
}
|
||||
@@ -63,10 +64,11 @@ void AppData::initFromDB()
|
||||
DAO::queryPolicyTypeDef(dao, result);
|
||||
for (auto& fields: result)
|
||||
{
|
||||
std::string policyTypeId = fields.value(DMDefPolicyType::POLICY_TYPE_ID);
|
||||
int policyTypeId = fields.get<int>(DMDefPolicyType::POLICY_TYPE_ID);
|
||||
std::string name = fields.value(DMDefWorkMode::NAME);
|
||||
this->mapping.workMode.push_back({policyTypeId, name});
|
||||
str += ("策略类型: {" + policyTypeId + ":" + name + "},");
|
||||
this->mapping.policyType.push_back({std::to_string(policyTypeId), name});
|
||||
this->mapPolicyType[policyTypeId] = name;
|
||||
str += ("策略类型: {" + std::to_string(policyTypeId) + ":" + name + "},");
|
||||
}
|
||||
XLOGD() << str;
|
||||
}
|
||||
@@ -78,7 +80,9 @@ void AppData::initFromDB()
|
||||
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);
|
||||
item->group = fields.value(DMDefDeviceType::GROUP);
|
||||
item->attr = fields.value(DMDefDeviceType::ATTRS);
|
||||
item->fieldsAttr.parseJson(item->attr);
|
||||
mapDeviceType[item->typeId] = item;
|
||||
mapping.deviceType.push_back({std::to_string(item->typeId), item->name});
|
||||
str += ("设备类型: {" + std::to_string(item->typeId) + ":" + item->name + "},");
|
||||
@@ -106,12 +110,11 @@ void AppData::initFromDB()
|
||||
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 + "},");
|
||||
auto station = std::make_shared<Station>();
|
||||
station->setFields(fields);
|
||||
this->mapStation[station->id] = station;
|
||||
mapping.stationName.push_back({std::to_string(station->id), station->name});
|
||||
str += ("场站: {" + std::to_string(station->id) + ":" + station->name + "},");
|
||||
}
|
||||
XLOGD() << str;
|
||||
}
|
||||
@@ -126,6 +129,8 @@ void AppData::initFromDB()
|
||||
if (station)
|
||||
{
|
||||
auto device = Device::create(fields);
|
||||
auto deviceTypeDef = this->getDeviceTypeDef(device->type);
|
||||
device->group = deviceTypeDef->group;
|
||||
station->addDevice(deviceId, device);
|
||||
}
|
||||
else
|
||||
@@ -247,9 +252,24 @@ std::shared_ptr<Device> AppData::getDevice(int stationId, int deviceId)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unordered_map<int, std::shared_ptr<DeviceType>>& AppData::getDeviceTypeDef()
|
||||
std::string AppData::getDeviceNameById(int typeId)
|
||||
{
|
||||
return mapDeviceType;
|
||||
auto iter = mapDeviceType.find(typeId);
|
||||
if (iter != mapDeviceType.end())
|
||||
{
|
||||
return iter->second->name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::shared_ptr<DeviceType> AppData::getDeviceTypeDef(int typeId)
|
||||
{
|
||||
auto iter = mapDeviceType.find(typeId);
|
||||
if (iter != mapDeviceType.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AppData::loadStatData()
|
||||
@@ -261,8 +281,18 @@ void AppData::initUser()
|
||||
{
|
||||
auto dao = DaoEntity::create("");
|
||||
std::vector<Fields> result;
|
||||
}
|
||||
|
||||
|
||||
int AppData::getWorkModeIdByName(std::string name)
|
||||
{
|
||||
for (auto iter = mapWorkMode.begin(); iter!=mapWorkMode.end(); ++iter)
|
||||
{
|
||||
if (iter->second == name)
|
||||
{
|
||||
return iter->first;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> AppData::getRoleNames()
|
||||
@@ -331,6 +361,16 @@ std::vector<std::string> AppData::getPolicyNames()
|
||||
return vec;
|
||||
}
|
||||
|
||||
int AppData::getPolicyTypeId(std::string name)
|
||||
{
|
||||
for (auto iter = mapPolicyType.begin(); iter != mapPolicyType.end(); ++iter)
|
||||
{
|
||||
if (iter->second == name) { return iter->first; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> AppData::getElectPreiodVals(int month)
|
||||
{
|
||||
if (month > 0 && month-1 < vecElectPeriods.size())
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include "common/Fields.h"
|
||||
|
||||
class Station;
|
||||
class Device;
|
||||
@@ -16,7 +17,9 @@ struct DeviceType
|
||||
{
|
||||
int typeId {};
|
||||
std::string name;
|
||||
std::string attrs;
|
||||
std::string group;
|
||||
std::string attr;
|
||||
Fields fieldsAttr;
|
||||
};
|
||||
|
||||
struct Role
|
||||
@@ -47,20 +50,27 @@ public:
|
||||
void init();
|
||||
void initFromDB();
|
||||
|
||||
std::shared_ptr<Station> getStation(int stationId);
|
||||
|
||||
std::shared_ptr<Station> getStationByName(std::string name);
|
||||
|
||||
std::shared_ptr<Device> getDevice(int stationId, int deviceId);
|
||||
|
||||
// 获取设备类型定义
|
||||
std::unordered_map<int, std::shared_ptr<DeviceType>>& getDeviceTypeDef();
|
||||
|
||||
// 读取统计数据: 今日统计数据,累计统计数据
|
||||
void loadStatData();
|
||||
|
||||
void initUser();
|
||||
|
||||
|
||||
std::shared_ptr<Station> getStation(int stationId);
|
||||
|
||||
std::shared_ptr<Station> getStationByName(std::string name);
|
||||
|
||||
std::shared_ptr<Device> getDevice(int stationId, int deviceId);
|
||||
|
||||
std::string getDeviceNameById(int typeId);
|
||||
|
||||
// 获取设备类型定义
|
||||
std::shared_ptr<DeviceType> getDeviceTypeDef(int typeId);
|
||||
|
||||
int getWorkModeIdByName(std::string name);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 获取角色名称列表
|
||||
std::vector<std::string> getRoleNames();
|
||||
@@ -74,6 +84,9 @@ public:
|
||||
std::vector<std::string> getPolicyTypeNames();
|
||||
// 获取策略名称
|
||||
std::vector<std::string> getPolicyNames();
|
||||
// 根据策略类型ID获取策略类型名称
|
||||
// 根据策略类型名称获取策略类型ID
|
||||
int getPolicyTypeId(std::string name);
|
||||
|
||||
std::vector<std::string> getElectPreiodVals(int month);
|
||||
|
||||
@@ -103,6 +116,9 @@ public:
|
||||
VecPairSS deviceType;
|
||||
|
||||
VecPairSS workMode;
|
||||
|
||||
VecPairSS policyType;
|
||||
VecPairSS stationName;
|
||||
} mapping;
|
||||
|
||||
double electPriceSuperPeak {};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "common/Logger.h"
|
||||
#include "common/Utils.h"
|
||||
#include "protocol/Communicator.h"
|
||||
#include "protocol/CommEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
|
||||
//int DeviceEntity::getAttrInt(std::string key)
|
||||
@@ -56,7 +56,7 @@ int Device::startComm()
|
||||
// 创建新的通讯
|
||||
if (!commEntity)
|
||||
{
|
||||
commEntity = Communicator::createEntity(attrs);
|
||||
commEntity = CommEntity::create(attrs);
|
||||
if (!commEntity) { return -1; }
|
||||
}
|
||||
|
||||
|
||||
@@ -16,15 +16,14 @@ public:
|
||||
int type = -1;
|
||||
std::string name;
|
||||
std::string code;
|
||||
std::string group;
|
||||
bool isOpen = false;
|
||||
std::string attrsJson = "";
|
||||
|
||||
|
||||
int err = 0;
|
||||
int online = 0;
|
||||
int status = 0;
|
||||
|
||||
|
||||
//std::map<std::string, std::string> mapAttrs;
|
||||
Fields attrs;
|
||||
|
||||
@@ -41,16 +40,3 @@ public:
|
||||
|
||||
static std::shared_ptr<Device> create(Fields& fields);
|
||||
};
|
||||
|
||||
|
||||
//class Device
|
||||
//{
|
||||
//public:
|
||||
// static void add(DataFields& fields);
|
||||
//
|
||||
// static std::vector<std::shared_ptr<DeviceEntity>> getDeviceByType(int type);
|
||||
//
|
||||
//public:
|
||||
// static std::map<int, std::shared_ptr<DeviceEntity>> mapDevices;
|
||||
//};
|
||||
|
||||
|
||||
@@ -1,28 +1,70 @@
|
||||
#include "Station.h"
|
||||
#include "database/DAO.h"
|
||||
#include "database/SQL.h"
|
||||
#include "common/fields.h"
|
||||
#include "app/Device.h"
|
||||
|
||||
Station::Station(int id) : id(id)
|
||||
|
||||
Station::Station() : id(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Station::setFields(Fields& fields)
|
||||
{
|
||||
this->id = fields.get<int>(DMStation::STATION_ID);
|
||||
this->name = fields.value(DMStation::NAME);
|
||||
this->energyCapacity = fields.get<double>(DMStation::CAPACITY);
|
||||
this->workModeId = fields.get<int>(DMStation::WORK_MODE_ID);
|
||||
}
|
||||
|
||||
void Station::addDevice(int deviceId, std::shared_ptr<Device> device)
|
||||
{
|
||||
mapDevice_[deviceId] = device;
|
||||
mapDevice[deviceId] = device;
|
||||
mapDeviceGroupNum[device->group]++;
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> Station::getDevice(int deviceId)
|
||||
{
|
||||
auto iter = mapDevice_.find(deviceId);
|
||||
if (iter!=mapDevice_.end())
|
||||
auto iter = mapDevice.find(deviceId);
|
||||
if (iter!=mapDevice.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Station::getDeviceByType(int typeId, std::vector<std::shared_ptr<Device>>& res)
|
||||
{
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->type == typeId)
|
||||
{
|
||||
res.push_back(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Station::getDeviceNumByGroup(std::string name)
|
||||
{
|
||||
return mapDeviceGroupNum[name];
|
||||
}
|
||||
|
||||
void Station::getDeviceByGroup(std::string name, std::vector<std::shared_ptr<Device>>& res)
|
||||
{
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->group == name)
|
||||
{
|
||||
res.push_back(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Station::setWorkMode(int modeId)
|
||||
{
|
||||
this->workModeId = 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();
|
||||
@@ -43,4 +85,4 @@ void Station::setPolicy(int policyId)
|
||||
{
|
||||
XLOGE() << "set station policy failed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,27 +2,35 @@
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include "common/Fields.h"
|
||||
|
||||
class Device;
|
||||
|
||||
class Station
|
||||
{
|
||||
public:
|
||||
Station(int id);
|
||||
Station();
|
||||
|
||||
void setFields(Fields& fields);
|
||||
|
||||
void addDevice(int deviceId, std::shared_ptr<Device> device);
|
||||
std::shared_ptr<Device> getDevice(int deviceId);
|
||||
|
||||
void getDeviceByType(int typeId, std::vector<std::shared_ptr<Device>>& res);
|
||||
int getDeviceNumByGroup(std::string name);
|
||||
void getDeviceByGroup(std::string name, std::vector<std::shared_ptr<Device>>& res);
|
||||
|
||||
void setWorkMode(int modeId);
|
||||
void setPolicy(int policyId);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
int id {};
|
||||
std::string name;
|
||||
|
||||
int workModeId; // 运行模式
|
||||
int runPolicyId; // 运行策略
|
||||
int workModeId {}; // 运行模式
|
||||
int runPolicyId {}; // 运行策略
|
||||
|
||||
// 储能容量
|
||||
double energyCapacity {};
|
||||
@@ -77,5 +85,7 @@ public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// === 设备信息 ===
|
||||
std::unordered_map<int, std::shared_ptr<Device>> mapDevice_;
|
||||
std::unordered_map<int, std::shared_ptr<Device>> mapDevice;
|
||||
|
||||
std::map<std::string, int> mapDeviceGroupNum;
|
||||
};
|
||||
Reference in New Issue
Block a user