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,6 +1,91 @@
|
||||
#include "AppData.h"
|
||||
|
||||
#include "common/Utils.h"
|
||||
#include "app/Station.h"
|
||||
#include "app/Device.h"
|
||||
#include "database/Dao.h"
|
||||
|
||||
|
||||
void InitStation(AppData* appdata)
|
||||
{
|
||||
// 读取数据库
|
||||
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)
|
||||
{
|
||||
vector<Fields> result;
|
||||
DAO::queryDeviceList(NULL, 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);
|
||||
station->addDevice(deviceId, device);
|
||||
}
|
||||
else
|
||||
{
|
||||
XLOGE() << "init device error: unknown station_id:[" << stationId << "] device_id=" << deviceId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitStatData(AppData* appdata)
|
||||
{
|
||||
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);
|
||||
station->storageOut = fields.getFloat(DMStatStation::STORAGE_ELECT_OUT);
|
||||
//station->storageNumIn = fields.getFloat(DMStatStation::STORAGE_NUM);
|
||||
//station->storageNumOut = fields.getFloat(DMStatStation::STORAGE_NUM);
|
||||
station->storageNumErr = fields.getFloat(DMStatStation::STORAGE_NUM_ERR);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AppData::init()
|
||||
{
|
||||
// 初始化场站信息
|
||||
InitStation(this);
|
||||
// 读取设备信息,连接设备
|
||||
InitDevice(this);
|
||||
// 读取基础统计信息,在系统总览中需要展示
|
||||
InitStatData(this);
|
||||
|
||||
this->initUser();
|
||||
}
|
||||
|
||||
std::shared_ptr<Station> AppData::getStation(int stationId)
|
||||
{
|
||||
@@ -24,15 +109,6 @@ std::shared_ptr<Station> AppData::getStationByName(std::string name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AppData::getStationNames(std::vector<std::string>& vecNames)
|
||||
{
|
||||
vecNames.resize(mapStation.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapStation.begin(); iter!=mapStation.end(); ++iter)
|
||||
{
|
||||
vecNames[i] = iter->second->name;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> AppData::getDevice(int stationId, int deviceId)
|
||||
{
|
||||
@@ -44,6 +120,80 @@ std::shared_ptr<Device> AppData::getDevice(int stationId, int deviceId)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unordered_map<int, std::shared_ptr<DeviceType>>& AppData::getDeviceTypeDef()
|
||||
{
|
||||
return mapDeviceType;
|
||||
}
|
||||
|
||||
void AppData::loadStatData()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AppData::initUser()
|
||||
{
|
||||
auto dao = DaoEntity::create("");
|
||||
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> vec(mapRole.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapRole.begin(); iter!=mapRole.end(); ++iter)
|
||||
{
|
||||
vec[i] = iter->second->name;
|
||||
++i;
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::vector<std::string> AppData::getStationNames()
|
||||
{
|
||||
std::vector<std::string> vec(mapStation.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapStation.begin(); iter!=mapStation.end(); ++iter)
|
||||
{
|
||||
vec[i] = iter->second->name;
|
||||
++i;
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::vector<std::string> AppData::getDeviceTypes()
|
||||
{
|
||||
std::vector<std::string> vec(mapping.deviceType.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapping.deviceType.begin(); iter!=mapping.deviceType.end(); ++iter)
|
||||
{
|
||||
vec[i] = iter->second;
|
||||
++i;
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
Reference in New Issue
Block a user