2025-08-20 19:00:22 +08:00
|
|
|
|
#include "Station.h"
|
2025-08-26 18:36:25 +08:00
|
|
|
|
#include "database/DAO.h"
|
|
|
|
|
|
#include "database/SQL.h"
|
2025-08-28 18:42:37 +08:00
|
|
|
|
#include "common/fields.h"
|
|
|
|
|
|
#include "app/Device.h"
|
2025-09-01 20:08:40 +08:00
|
|
|
|
#include "common/Spdlogger.h"
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
|
|
|
|
|
|
Station::Station() : id(0)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
void Station::addDevice(int deviceId, std::shared_ptr<Device> device)
|
|
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
mapDevice[deviceId] = device;
|
|
|
|
|
|
mapDeviceGroupNum[device->group]++;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Device> Station::getDevice(int deviceId)
|
|
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
auto iter = mapDevice.find(deviceId);
|
|
|
|
|
|
if (iter!=mapDevice.end())
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
return iter->second;
|
|
|
|
|
|
}
|
|
|
|
|
|
return nullptr;
|
2025-08-26 18:36:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
void Station::setWorkMode(int modeId)
|
|
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
this->workModeId = modeId;
|
2025-08-26 18:36:25 +08:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2025-09-01 20:08:40 +08:00
|
|
|
|
spdlog::error("set station work mode failed.");
|
2025-08-26 18:36:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2025-09-01 20:08:40 +08:00
|
|
|
|
spdlog::error("set station policy failed.");
|
2025-08-26 18:36:25 +08:00
|
|
|
|
}
|
2025-08-28 18:42:37 +08:00
|
|
|
|
}
|