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())
|
||||
|
||||
Reference in New Issue
Block a user