1.新增服务端UI界面,显示服务基础信息。2.修改设备显示配置。3.监控页面储能系统显示储能模式,模式设置新增'手动'

This commit is contained in:
lixiaoyuan
2025-09-25 19:20:25 +08:00
parent d7888c2be4
commit 8aba56f47d
39 changed files with 2954 additions and 408 deletions

View File

@@ -203,6 +203,19 @@ void Station::setGarewayWorkMode()
mqttCli->publish("Gateway_YT", text);
}
string Station::getGatewayMode()
{
// 0手动1峰谷套利2增网配容3应急供电4并网保电5自定时段
if (workModeGateway == 0) { return "手动"; }
else if (workModeGateway == 1) { return "峰谷套利"; }
else if (workModeGateway == 2) { return "增网配容"; }
else if (workModeGateway == 3) { return "应急供电"; }
else if (workModeGateway == 4) { return "并网保电"; }
else if (workModeGateway == 5) { return "自定时段"; }
else { return "--"; };
}
void Station::checkDevice()
{
for (auto& item: mapDevice)
@@ -331,6 +344,7 @@ void Station::readCoolingData(int deviceNo, string addr, int val)
void Station::readGatewayMode(int mode)
{
this->workModeGateway = mode;
if (mode != this->workMode)
{
//this->setGarewayWorkMode();
@@ -363,20 +377,61 @@ void Station::readGatewayStatus(int cdzStatus, int emuStatus)
}
}
static std::string MapValueToJson(int npos, std::map<int, double>& mapV)
static std::string MapValueToJson(int npos, std::map<int, float>& mapV)
{
njson jsonarray = njson::array();
for (int i = 0; i<=npos; i++)
{
jsonarray.push_back(mapV[i]);
jsonarray.push_back(int(mapV[i]));
}
return jsonarray.dump();
}
void Station::setCache(int datatype, std::vector<float>& vd)
{
std::map<int, float>* mapptr = NULL;
if (datatype == 1) { mapptr = &mapCacheElectIn; }
else if (datatype == 2) { mapptr = &mapCacheElectOut; }
else if (datatype == 3) { mapptr = &mapCacheElectCharger; }
if (mapptr)
{
const int step = 600;
const int N = 86400/step;
int64_t tsSeconds = Utils::timeDaySeconds();
int npos = tsSeconds / step;
for (int i = 0; i<N; ++i)
{
if (i < vd.size()) { (*mapptr)[i] = vd[i]; }
else if (i <= npos) { (*mapptr)[i] = 0; }
}
}
}
void Station::cache()
{
int64_t tDaySeconds = Utils::timeDaySeconds();
int npos = tDaySeconds / 600;
int offset = tDaySeconds % 600;
bool save = false;
if (offset >= (600-180) && npos + 1 < 144)
{
npos += 1;
save = true;
}
else if (offset <= 180 && posCache < npos)
{
save = true;
posCache = npos;
}
if (save)
{
mapCacheElectIn[npos] = Utils::random(100, 800); // dayElectIn
mapCacheElectOut[npos] = Utils::random(100, 800); // dayElectOut
mapCacheElectCharger[npos] = Utils::random(100, 800); // 暂无数据源
}
}
void Station::writeStatistic()
{
auto dao = DaoEntity::create("history_day");
std::string dt = Utils::dateStr();
int64_t tTime = Utils::time();
int64_t tDate = Utils::date();
@@ -386,7 +441,7 @@ void Station::writeStatistic()
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
{
auto device = iter->second;
if (device->cache(npos) && device->type == int(EDeviceType::BMS))
if (device->cache(npos))
{
Fields fields;
fields.set("dt", dt);
@@ -407,7 +462,7 @@ void Station::writeStatistic()
}
}
if (statData.ts != 0)
if (statData.ts > 0)
{
Fields fields;
fields.set("dt", Utils::dateStr(statData.ts));
@@ -437,15 +492,14 @@ void Station::writeStatistic()
};
dao->duplicateUpdate(fields, vecKeys);
{
{ // stat_day
Fields fields;
fields.set("dt", Utils::dateStr(statData.ts));
fields.set("station_id", this->stationId);
fields.set("device_id", 0);
fields.set("storage_elect_in", statData.dayElectIn);
fields.set("storage_elect_out", statData.dayElectOut);
fields.set("income_elect", statData.dayIncome);
DAO::insertStatStation(dao, fields);
DAO::insertStatDay(dao, fields);
}
{
Fields fields;
@@ -458,4 +512,25 @@ void Station::writeStatistic()
}
}
{
// 预测数据源记录
dao->setTableName("predict_day");
Fields fields;
fields.set("dt", dt);
fields.set("station_id", stationId);
fields.set("datatype", 1); // 1储能充电2储能放电3充电桩充电4发电
fields.set("value", MapValueToJson(npos, mapCacheElectIn));
dao->duplicateUpdate(fields, {"value"});
fields.set("datatype", 2); // 1储能充电2储能放电3充电桩充电4发电
fields.set("value", MapValueToJson(npos, mapCacheElectOut));
dao->duplicateUpdate(fields, {"value"});
fields.set("datatype", 3); // 1储能充电2储能放电3充电桩充电4发电
fields.set("value", MapValueToJson(npos, mapCacheElectCharger));
dao->duplicateUpdate(fields, {"value"});
}
}