Files
energy_storage/src/app/AppData.h

95 lines
2.4 KiB
C
Raw Normal View History

#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <memory>
#include <map>
#include <unordered_map>
class Station;
class Device;
using VecPairSS = std::vector<std::pair<std::string, std::string>>;
struct DeviceType
{
int typeId {};
std::string name;
std::string attrs;
};
struct Role
{
int roleId {};
std::string name;
bool isOpen {false};
};
class AppData
{
public:
void init();
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::vector<std::string> getRoleNames();
// 获取场站名称列表
std::vector<std::string> getStationNames();
// 获取设备类型
std::vector<std::string> getDeviceTypes();
// 获取设备类型定义
std::unordered_map<int, std::shared_ptr<DeviceType>>& getDeviceTypeDef();
// 读取统计数据: 今日统计数据,累计统计数据
void loadStatData();
void initUser();
public:
///////////////////////////////////////////////////////////////////////////////////////////////
// === 系统 ===
int64_t sysActivationTime {};
///////////////////////////////////////////////////////////////////////////////////////////////
// === 数据库 ===
struct {
std::string host;
int port;
std::string user;
std::string passwd;
} db;
struct {
VecPairSS isopen {{"0", "禁用"}, {"1", "启用"}};
VecPairSS gender {{"0", ""}, {"1", ""}};
// 角色 Mapping id->name
VecPairSS role;
VecPairSS deviceType;
} mapping;
///////////////////////////////////////////////////////////////////////////////////////////////
// === 场站信息 ===
std::unordered_map<int, std::shared_ptr<Station>> mapStation;
///////////////////////////////////////////////////////////////////////////////////////////////
// === 角色定义 ===
std::unordered_map<int, std::shared_ptr<Role>> mapRole;
///////////////////////////////////////////////////////////////////////////////////////////////
// === 设备类型定义 ===
std::unordered_map<int, std::shared_ptr<DeviceType>> mapDeviceType;
};