南瑞意见修改:前端页面和后端接口

This commit is contained in:
lixiaoyuan
2026-01-05 16:13:13 +08:00
parent 97e4b182de
commit e278ae1003
51 changed files with 2812 additions and 958 deletions

View File

@@ -18,6 +18,18 @@ Station::Station() : stationId(0)
predictStorageIn = vector<int>(144, 0);
predictStorageOut = vector<int>(144, 0);
predictCharge = vector<int>(144, 0);
storage.U = vector<int>(144, 0);
storage.I = vector<int>(144, 0);
storage.P = vector<int>(144, 0);
charge.U = vector<int>(144, 0);
charge.I = vector<int>(144, 0);
charge.P = vector<int>(144, 0);
pv.U = vector<int>(144, 0);
pv.I = vector<int>(144, 0);
pv.P = vector<int>(144, 0);
}
void Station::setFields(Fields& fields)
@@ -214,13 +226,13 @@ void Station::setGarewayParams()
string Station::getGatewayMode()
{
// 0手动1峰谷套利2配网增容3应急供电4并网保电5自定时段
// 0手动1峰谷套利2配网增容3应急供电4并网保电5运营支撑
if (gatewayParam.mode == 0) { return "手动"; }
else if (gatewayParam.mode == 1) { return "峰谷套利"; }
else if (gatewayParam.mode == 2) { return "配网增容"; }
else if (gatewayParam.mode == 3) { return "应急供电"; }
else if (gatewayParam.mode == 4) { return "并网保电"; }
else if (gatewayParam.mode == 5) { return "自定时段"; }
else if (gatewayParam.mode == 5) { return "运营支撑"; }
else { return "--"; };
}
@@ -236,7 +248,11 @@ static map<int, string> mapPeriodOper =
string Station::getGatewayParam()
{
stringstream ss;
std::string str1 = "峰谷套利时段:<br>";
std::string str1 = std::format("运行模式:{}<br>储能EMY状态{}<br>充电桩状态:{}<br><br>",
getGatewayMode(),
this->emuStatus == 1 ? "在线" : (this->emuStatus == 0 ? "离线" : "--"),
this->cdzStatus == 1 ? "在线" : (this->cdzStatus == 0 ? "离线" : "--"));
str1 += "峰谷套利时段:<br>";
{
njson json;
if (JSON::parse(gatewayParam.param1, json))
@@ -346,18 +362,24 @@ void Station::readAlert(std::shared_ptr<Device> device, std::string addr, int v,
}
}
void Station::readRuntimeData(int deviceNo, string addr, int val)
void Station::readEnergyData(int deviceNo, string addr, int val)
{
if (deviceNo == 1)
if (deviceNo == 1) // 入网电表
{
if (addr == "0x000B") { this->voltage = val; } // A相电压 R uint32 1V 0x000B
if (addr == "0x0011") { this->current = val; } // A相电流 R int32 1A 0x0011
if (addr == "0x0023") { this->power = val; } // 三相总有功 R int32 1kW 0x0023
if (addr == "0x000B") { this->grid.voltage = val; } // A相电压 R uint32 1V 0x000B
if (addr == "0x0011") { this->grid.current = val; } // A相电流 R int32 1A 0x0011
if (addr == "0x0023") { this->grid.power = val; } // 三相总有功 R int32 1kW 0x0023
// 功率因数 ?? 电表没有功率因数数据
}
else if (deviceNo == 2)
else if (deviceNo == 2) // 储能电表
{
statData.ts = Utils::time();
if (addr == "0x002F") { statData.dayElectIn = val; } //日充电电量 R uint32 1kWh 0x002F
if (addr == "0x000B") { this->storage.voltage = val; } // A相电压 R uint32 1V 0x000B
else if (addr == "0x0011") { this->storage.current = val; } // A相电流 R int32 1A 0x0011
else if (addr == "0x0023") { this->storage.power = val; } // 三相总有功 R int32 1kW 0x0023
// 功率因数 ?? 电表没有功率因数数据
else if (addr == "0x002F") { statData.dayElectIn = val; } // 日充电电量 R uint32 1kWh 0x002F
else if (addr == "0x0031") { statData.dayElectOut = val; } //日放电电量 R uint32 1kWh 0x0031
else if (addr == "0x0033") { statData.dayFeeIn = val; } //日充电费用 R uint32 1RMB 0x0033
else if (addr == "0x0035") { statData.dayFeeOut = val; } //日放电费用 R uint32 1RMB 0x0035
@@ -392,7 +414,29 @@ void Station::readRuntimeData(int deviceNo, string addr, int val)
else if (addr == "0x0069") { statData.totalElectOut_Total = val; } //总反向总有功电能 R uint32 1kWh 0x0069
}
}
// 充电桩
void Station::readChargeData(int deviceNo, string addr, int val)
{
if (addr == "11") { charge.connector1.isCharge = val; } //枪1:状态 R uint16 11
//枪1 : 需求电压 R uint16 12
//枪1 : 需求电流 R uint16 13
//枪1 : 需求功率 R uint16 14
else if (addr == "15") { charge.connector1.voltage = val * 0.1; } //枪1 : 输出电压 R uint16 15
else if (addr == "16") { charge.connector1.current = val * 0.01; } //枪1 : 输出电流 R uint16 16
else if (addr == "17") { charge.connector1.power = val * 0.1; } //枪1 : 输出功率 R uint16 17
//枪1 : 功率限值 R uint16 18
else if (addr == "21") { charge.connector2.isCharge = val; } //枪2 : 状态 R uint16 21
//枪2 : 需求电压 R uint16 22
//枪2 : 需求电流 R uint16 23
//枪2 : 需求功率 R uint16 24
else if (addr == "25") { charge.connector2.voltage = val * 0.1; } //枪2 : 输出电压 R uint16 25
else if (addr == "26") { charge.connector2.current = val * 0.01; } //枪2 : 输出电流 R uint16 26
else if (addr == "27") { charge.connector2.power = val * 0.1; } //枪2 : 输出功率 R uint16 27
//枪2 : 功率限值 R uint16 28
bool isCharge = (charge.connector1.isCharge || charge.connector2.isCharge);
charge.status = isCharge ? 2 : 1;
}
void Station::readTHData(int deviceNo, string addr, int val)
{
auto& unit = mapTempHumUnit[deviceNo];
@@ -507,6 +551,11 @@ void Station::readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus)
device->ts = Utils::time();
}
if (cdzStatus == 0) charge.status = 0;
else if (charge.status == 0) charge.status = 1;
if (emuStatus == 0) storage.status = 0;
else if (storage.status == 0) storage.status = 1;
//充电桩 1在线0离线
if (cdzStatus >= 0)
{
@@ -565,24 +614,51 @@ void Station::cache()
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)
if (posCache != npos && offset <= 180) // 超过时间点3分钟内没有存储进行兼容处理
{
if (npos == 0)
{
std::fill(storage.U.begin(), storage.U.end(), 0);
std::fill(storage.I.begin(), storage.I.end(), 0);
std::fill(storage.P.begin(), storage.P.end(), 0);
std::fill(charge.U.begin(), charge.U.end(), 0);
std::fill(charge.I.begin(), charge.I.end(), 0);
std::fill(charge.P.begin(), charge.P.end(), 0);
std::fill(pv.U.begin(), pv.U.end(), 0);
std::fill(pv.I.begin(), pv.I.end(), 0);
std::fill(pv.P.begin(), pv.P.end(), 0);
}
save = true;
posCache = npos;
}
if (save)
if (save && npos < storage.U.size())
{
mapCacheElectIn[npos] = Utils::random(100, 800); // dayElectIn
mapCacheElectOut[npos] = Utils::random(100, 800); // dayElectOut
mapCacheElectCharger[npos] = Utils::random(100, 800); // 暂无数据源
storage.U[npos] = storage.voltage;
storage.I[npos] = storage.current;
storage.P[npos] = storage.power;
charge.U[npos] = charge.connector1.voltage;
charge.I[npos] = charge.connector1.current;
charge.P[npos] = charge.connector1.power;
//pv.U[npos];
//pv.I[npos];
//pv.P[npos];
}
}
static njson VectorToJsonArray(vector<float>& vec, int n)
{
//int v = Utils::random(40, 50);
njson jsonArray = njson::array();
for (int i = 0; i <= n && i < vec.size(); ++i)
{
jsonArray.push_back(int(vec[i]));
//jsonArray.push_back(v + Utils::random(1, 6) -3);
}
return jsonArray;
}
void Station::writeStatistic()
{
auto dao = DaoEntity::create("history_day");
@@ -603,15 +679,15 @@ void Station::writeStatistic()
fields.set("station_id", this->stationId);
fields.set("device_id", device->deviceId);
fields.set("datatype", 1);
fields.set("value", MapValueToJson(npos, device->mapCacheVoltage));
fields.set("value", VectorToJsonArray(device->cacheU, npos));
DAO::insertRuntimeData(dao, fields);
fields.set("datatype", 2);
fields.set("value", MapValueToJson(npos, device->mapCacheCurrent));
fields.set("value", VectorToJsonArray(device->cacheI, npos));
DAO::insertRuntimeData(dao, fields);
fields.set("datatype", 3);
fields.set("value", MapValueToJson(npos, device->mapCachePower));
fields.set("value", VectorToJsonArray(device->cacheP, npos));
DAO::insertRuntimeData(dao, fields);
//spdlog::info("[device] write runtime date to database, deviceId={}", device->deviceId);
}
@@ -802,4 +878,10 @@ void Station::predict()
// predictStorageOut[i] = v2 >= 0 ? v2 : 0;
// predictCharge[i] = v3 >= 0 ? v3 : 0;
//}
}
void Station::writeDeviceData()
{
}