mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现策略配置功能
This commit is contained in:
@@ -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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user