2025-08-20 19:00:22 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <unordered_map>
|
2025-08-28 18:42:37 +08:00
|
|
|
|
#include "common/Fields.h"
|
2025-08-31 14:38:53 +08:00
|
|
|
|
#include "app/Config.h"
|
2025-09-01 20:08:40 +08:00
|
|
|
|
#include "common/Spdlogger.h"
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
class Station;
|
|
|
|
|
|
class Device;
|
2025-08-26 18:36:25 +08:00
|
|
|
|
class MyPolicy;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
using VecPairSS = std::vector<std::pair<std::string, std::string>>;
|
|
|
|
|
|
|
2025-08-31 14:38:53 +08:00
|
|
|
|
struct User
|
|
|
|
|
|
{
|
|
|
|
|
|
std::string userId;
|
|
|
|
|
|
std::string account;
|
|
|
|
|
|
std::string token;
|
|
|
|
|
|
int64_t loginTime {};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
struct DeviceType
|
|
|
|
|
|
{
|
|
|
|
|
|
int typeId {};
|
|
|
|
|
|
std::string name;
|
2025-08-28 18:42:37 +08:00
|
|
|
|
std::string group;
|
|
|
|
|
|
std::string attr;
|
|
|
|
|
|
Fields fieldsAttr;
|
2025-08-22 19:06:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Role
|
|
|
|
|
|
{
|
|
|
|
|
|
int roleId {};
|
|
|
|
|
|
std::string name;
|
|
|
|
|
|
bool isOpen {false};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
class ElectPeriod
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
double priceSuperPeak {};
|
|
|
|
|
|
double pricePeak {};
|
|
|
|
|
|
double priceShoulder {};
|
|
|
|
|
|
double priceOffPeak {};
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::vector<std::string>> vecPeriods;
|
|
|
|
|
|
|
|
|
|
|
|
void parse(std::string jsonstr);
|
|
|
|
|
|
|
|
|
|
|
|
std::string dump();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
class AppData
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void init();
|
2025-08-26 18:36:25 +08:00
|
|
|
|
void initFromDB();
|
2025-08-22 19:06:50 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
// 读取统计数据: 今日统计数据,累计统计数据
|
|
|
|
|
|
void loadStatData();
|
|
|
|
|
|
|
2025-08-31 14:38:53 +08:00
|
|
|
|
std::string userLogin(std::string userId, std::string account);
|
|
|
|
|
|
User getUser(std::string token);
|
2025-08-28 18:42:37 +08:00
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
std::shared_ptr<Station> getStation(int stationId);
|
2025-09-01 20:08:40 +08:00
|
|
|
|
int getStationCount();
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Station> getStationByName(std::string name);
|
2025-09-04 19:31:04 +08:00
|
|
|
|
std::shared_ptr<Station> getStationByCode(std::string code);
|
2025-08-26 18:36:25 +08:00
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
std::shared_ptr<Device> getDevice(int stationId, int deviceId);
|
2025-09-08 19:34:12 +08:00
|
|
|
|
std::shared_ptr<Device> getDeviceByType(int stationId, int deviceType, std::string code);
|
2025-08-28 18:42:37 +08:00
|
|
|
|
|
|
|
|
|
|
std::string getDeviceNameById(int typeId);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
// 获取设备类型定义
|
2025-08-28 18:42:37 +08:00
|
|
|
|
std::shared_ptr<DeviceType> getDeviceTypeDef(int typeId);
|
2025-08-26 18:36:25 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
int getWorkModeIdByName(std::string name);
|
2025-08-26 18:36:25 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// 获取角色名称列表
|
|
|
|
|
|
std::vector<std::string> getRoleNames();
|
|
|
|
|
|
// 获取场站名称列表
|
|
|
|
|
|
std::vector<std::string> getStationNames();
|
|
|
|
|
|
// 获取设备类型
|
2025-08-26 18:36:25 +08:00
|
|
|
|
std::vector<std::string> getDeviceTypeNames();
|
|
|
|
|
|
// 获取工作模式
|
|
|
|
|
|
std::vector<std::string> getWorkModes();
|
|
|
|
|
|
// 获取策略类型定义
|
|
|
|
|
|
std::vector<std::string> getPolicyTypeNames();
|
|
|
|
|
|
// 获取策略名称
|
|
|
|
|
|
std::vector<std::string> getPolicyNames();
|
2025-08-28 18:42:37 +08:00
|
|
|
|
// 根据策略类型ID获取策略类型名称
|
|
|
|
|
|
// 根据策略类型名称获取策略类型ID
|
|
|
|
|
|
int getPolicyTypeId(std::string name);
|
2025-08-22 19:06:50 +08:00
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
std::vector<std::string> getElectPreiodVals(int month);
|
2025-08-22 19:06:50 +08:00
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
std::string getElectPreiodVal(int month, int hour);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-09-04 19:31:04 +08:00
|
|
|
|
void storeRuntimeDB();
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// === 系统 ===
|
|
|
|
|
|
int64_t sysActivationTime {};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// === 数据库 ===
|
|
|
|
|
|
struct {
|
|
|
|
|
|
std::string host;
|
|
|
|
|
|
int port;
|
|
|
|
|
|
std::string user;
|
|
|
|
|
|
std::string passwd;
|
|
|
|
|
|
} db;
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
struct {
|
|
|
|
|
|
VecPairSS isopen {{"0", "禁用"}, {"1", "启用"}};
|
|
|
|
|
|
VecPairSS gender {{"0", "女"}, {"1", "男"}};
|
|
|
|
|
|
// 角色 Mapping (id->name)
|
|
|
|
|
|
VecPairSS role;
|
|
|
|
|
|
|
|
|
|
|
|
VecPairSS deviceType;
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
VecPairSS workMode;
|
2025-08-28 18:42:37 +08:00
|
|
|
|
|
|
|
|
|
|
VecPairSS policyType;
|
|
|
|
|
|
VecPairSS stationName;
|
2025-08-22 19:06:50 +08:00
|
|
|
|
} mapping;
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
double electPriceSuperPeak {};
|
|
|
|
|
|
double electPricePeak {};
|
|
|
|
|
|
double electPriceShoulder {};
|
|
|
|
|
|
double electPriceOffPeak {};
|
|
|
|
|
|
|
|
|
|
|
|
// 场站信息
|
2025-08-20 19:00:22 +08:00
|
|
|
|
std::unordered_map<int, std::shared_ptr<Station>> mapStation;
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
// 角色信息
|
2025-08-22 19:06:50 +08:00
|
|
|
|
std::unordered_map<int, std::shared_ptr<Role>> mapRole;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
// 设备类型定义
|
2025-08-22 19:06:50 +08:00
|
|
|
|
std::unordered_map<int, std::shared_ptr<DeviceType>> mapDeviceType;
|
2025-08-26 18:36:25 +08:00
|
|
|
|
|
|
|
|
|
|
// 工作模式定义
|
|
|
|
|
|
std::unordered_map<int, std::string> mapWorkMode;
|
|
|
|
|
|
|
|
|
|
|
|
// 策略类型定义
|
|
|
|
|
|
std::unordered_map<int, std::string> mapPolicyType;
|
|
|
|
|
|
|
|
|
|
|
|
// 策略信息
|
|
|
|
|
|
std::unordered_map<int, std::shared_ptr<MyPolicy>> mapPolicy;
|
|
|
|
|
|
|
|
|
|
|
|
// 电力峰谷分段 (12个月,每个月按小时分成24个时段)
|
|
|
|
|
|
std::vector<std::vector<std::string>> vecElectPeriods;
|
|
|
|
|
|
|
2025-09-04 19:31:04 +08:00
|
|
|
|
std::map<int64_t, double> mapDataDay;
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
};
|