mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
南瑞意见修改:前端页面和后端接口
This commit is contained in:
@@ -159,7 +159,10 @@ static std::map<std::string, HandlerOptions> g_mapHttpHandlerGet =
|
||||
{"/queryStationData", HandlerOptions(&HttpEntity::queryStationData, { DMStation::STATION_ID})},
|
||||
{"/queryStationOverview", HandlerOptions(&HttpEntity::queryStationOverview, {DMStation::STATION_ID})},
|
||||
|
||||
|
||||
{"/queryStationTodayU", HandlerOptions(&HttpEntity::queryStationTodayU, {DMStation::STATION_ID, "category"})},
|
||||
{"/queryStationTodayI", HandlerOptions(&HttpEntity::queryStationTodayI, {DMStation::STATION_ID, "category"})},
|
||||
{"/queryStationTodayP", HandlerOptions(&HttpEntity::queryStationTodayP, {DMStation::STATION_ID, "category"})},
|
||||
|
||||
{"/queryDeviceList", HandlerOptions(&HttpEntity::queryDeviceList, {})},
|
||||
{"/deleteDevice", HandlerOptions(&HttpEntity::deleteDevice, { DMDevice::DEVICE_ID})},
|
||||
{"/queryDevicTypeDef", HandlerOptions(&HttpEntity::queryDevicTypeDef, {})},
|
||||
@@ -823,28 +826,120 @@ Errcode HttpEntity::queryStationData(const httplib::Request& req, njson& json, s
|
||||
njson jsondata;
|
||||
if (station)
|
||||
{
|
||||
// 温度, 电压、电流、功率、功率因数、
|
||||
jsondata["voltage"] = Utils::toStr(station->voltage, 0);
|
||||
jsondata["current"] = Utils::toStr(station->current, 0);
|
||||
jsondata["power"] = Utils::toStr(station->power, 0);
|
||||
jsondata["powerFactor"] = Utils::toStr(station->powerFactor, 0);
|
||||
jsondata["envTemp"] = Utils::toStr(station->temperature, 0);
|
||||
jsondata["envhum"] = Utils::toStr(station->humidity, 0);
|
||||
jsondata["aircStatus"] = station->aircStatus;
|
||||
jsondata["coolingStatus"] = station->coolingStatus;
|
||||
/// 储能:电压、电流、功率、功率因数
|
||||
{
|
||||
njson json = njson::object();
|
||||
json["U"] = Utils::toStr(station->storage.voltage);
|
||||
json["I"] = Utils::toStr(station->storage.current);
|
||||
json["P"] = Utils::toStr(station->storage.power);
|
||||
//json["PF"] = Utils::toStr(station->storage.powerFactor, 1);
|
||||
jsondata["storage"] = json;
|
||||
}
|
||||
/// 充电:电压、电流、功率、功率因数
|
||||
{
|
||||
njson json = njson::object();
|
||||
json["U"] = Utils::toStr(station->charge.connector1.voltage);
|
||||
json["I"] = Utils::toStr(station->charge.connector1.current);
|
||||
json["P"] = Utils::toStr(station->charge.connector1.power);
|
||||
jsondata["charge"] = json;
|
||||
}
|
||||
/// 光伏
|
||||
{
|
||||
njson json = njson::object();
|
||||
json["P"] = Utils::toStr(station->pv.power);
|
||||
jsondata["pv"] = json;
|
||||
}
|
||||
/// 电网
|
||||
{
|
||||
njson json = njson::object();
|
||||
json["U"] = Utils::toStr(station->grid.voltage);
|
||||
json["I"] = Utils::toStr(station->grid.current);
|
||||
json["P"] = Utils::toStr(station->grid.power);
|
||||
//json["PF"] = Utils::toStr(station->grid.powerFactor, 1);
|
||||
jsondata["grid"] = json;
|
||||
}
|
||||
|
||||
/// 环境:温度、湿度
|
||||
{
|
||||
njson json = njson::object();
|
||||
json["envTemp"] = Utils::toStr(station->temperature, 0);
|
||||
json["envhum"] = Utils::toStr(station->humidity, 0);
|
||||
json["aircStatus"] = station->aircStatus;
|
||||
json["coolingStatus"] = station->coolingStatus;
|
||||
jsondata["env"] = json;
|
||||
}
|
||||
}
|
||||
json["data"] = jsondata;
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
static njson VectorToJsonArray(vector<float>& vec, int n)
|
||||
{
|
||||
njson jsonArray = njson::array();
|
||||
for (int i = 0; i <= n && i < vec.size(); ++i)
|
||||
{
|
||||
jsonArray.push_back(int(vec[i]));
|
||||
}
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
// 获取场站今日电压曲线数据,category: 1:储能,2:充电,3:光伏
|
||||
Errcode HttpEntity::queryStationTodayU(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
std::string stationId = req.get_param_value("station_id");
|
||||
std::string catogray = req.get_param_value("category");
|
||||
njson jsondata;
|
||||
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
if (station)
|
||||
{
|
||||
int n = Utils::timeDaySeconds() / 600;
|
||||
if (catogray == "1")
|
||||
{
|
||||
auto device = station->getDeviceByType(int(EDeviceType::E_METER), "2");
|
||||
if (device) {
|
||||
jsondata["U"] = VectorToJsonArray(device->cacheU, n);
|
||||
jsondata["I"] = VectorToJsonArray(device->cacheI, n);
|
||||
jsondata["P"] = VectorToJsonArray(device->cacheP, n);
|
||||
}
|
||||
}
|
||||
else if (catogray == "2")
|
||||
{
|
||||
auto device = station->getDeviceByType(int(EDeviceType::CHARGER), "1");
|
||||
if (device) {
|
||||
jsondata["U"] = VectorToJsonArray(device->cacheU, n);
|
||||
jsondata["I"] = VectorToJsonArray(device->cacheI, n);
|
||||
jsondata["P"] = VectorToJsonArray(device->cacheP, n);
|
||||
}
|
||||
}
|
||||
else if (catogray == "3")
|
||||
{
|
||||
}
|
||||
}
|
||||
json["data"] = jsondata;
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
// 获取场站今日电流曲线数据,category: 1:储能,2:充电,3:光伏
|
||||
Errcode HttpEntity::queryStationTodayI(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
// 获取场站今日功率曲线数据,category: 1:储能,2:充电,3:光伏
|
||||
Errcode HttpEntity::queryStationTodayP(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryDeviceList(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
PageInfo pageinfo;
|
||||
pageinfo.index = Utils::toInt(req.get_param_value("page"));
|
||||
pageinfo.size = Utils::toInt(req.get_param_value("page_size"));
|
||||
|
||||
string stationId = req.get_param_value("station_id");
|
||||
std::vector<Fields> result;
|
||||
auto err = DAO::queryDeviceList(pageinfo, result);
|
||||
auto err = DAO::queryDeviceListByStation(pageinfo, stationId, result);
|
||||
HttpHelper::setPagination(pageinfo, result, json);
|
||||
return err;
|
||||
};
|
||||
@@ -983,14 +1078,20 @@ Errcode HttpEntity::queryDevicCharts(const httplib::Request& req, njson& json, s
|
||||
int deviceId = params.get<int>("device_id");
|
||||
auto device = Application::data().getDevice(stationId, deviceId);
|
||||
|
||||
std::vector<std::string> vecV, vecI, vecP;
|
||||
int npos = Utils::timeDaySeconds() / 600;
|
||||
std::vector<int> vecU(npos, 0);
|
||||
std::vector<int> vecI(npos, 0);
|
||||
std::vector<int> vecP(npos, 0);
|
||||
if (device)
|
||||
{
|
||||
device->getCacheVoltage(vecV);
|
||||
device->getCacheCurrent(vecI);
|
||||
device->getCachePower(vecP);
|
||||
for (size_t i = 0; i < npos; ++i)
|
||||
{
|
||||
if (i < device->cacheU.size()) vecU[i] = int(device->cacheU[i]);
|
||||
if (i < device->cacheI.size()) vecI[i] = int(device->cacheI[i]);
|
||||
if (i < device->cacheP.size()) vecP[i] = int(device->cacheP[i]);
|
||||
}
|
||||
}
|
||||
json["data"] = {{"V", vecV}, {"I", vecI}, {"P", vecP}};
|
||||
json["data"] = {{"V", vecU}, {"I", vecI}, {"P", vecP}};
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
@@ -1141,45 +1242,220 @@ Errcode HttpEntity::queryPredictionDetail(const httplib::Request& req, njson& js
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
static void VerifyRequstParamsStatDate(Fields& params)
|
||||
{
|
||||
if (!params.contains("end_date"))
|
||||
{
|
||||
if (!params.contains("start_date"))
|
||||
{
|
||||
params.set("end_date", Utils::dateStr());
|
||||
params.set("start_date", Utils::dateStr(Utils::date() - 86400 * 7));
|
||||
}
|
||||
else
|
||||
{
|
||||
params.set("end_date", Utils::dateStr(Utils::time(params.value("start_date") + " 00:00:00") + 86400 * 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
static std::string VerifyStatSqlCondition(Fields& params)
|
||||
{
|
||||
std::string stationId = params.value("station_id");
|
||||
std::string category = params.value("category");
|
||||
std::string dtStart = params.value("start_date");
|
||||
std::string dtEnd = params.value("end_date");
|
||||
|
||||
std::string sqlCondition;
|
||||
if (!dtStart.empty() && dtEnd.empty())
|
||||
{
|
||||
sqlCondition += "dt BETWEEN '" + dtStart + "' AND '" + dtEnd + "'";
|
||||
}
|
||||
if (!stationId.empty())
|
||||
{
|
||||
if (!sqlCondition.empty()) sqlCondition += " AND ";
|
||||
sqlCondition += "ss.station_id='" + stationId + "'";
|
||||
}
|
||||
if (!category.empty() && category != "0")
|
||||
{
|
||||
//if (!sqlCondition.empty()) sqlCondition += " AND ";
|
||||
//sqlCondition += "ss.category='" + category + "'";;
|
||||
}
|
||||
if (!sqlCondition.empty()) { sqlCondition = " WHERE " + sqlCondition; }
|
||||
return sqlCondition;
|
||||
}
|
||||
static std::string GetRequestStatParams(const httplib::Request& req, Fields& params)
|
||||
{
|
||||
|
||||
GetRequestParams(req, { "station_id", "category", "start_date", "end_date" }, params);
|
||||
VerifyRequstParamsStatDate(params);
|
||||
return VerifyStatSqlCondition(params);
|
||||
}
|
||||
|
||||
static string GetStationStatusStr(int status)
|
||||
{
|
||||
if (status == 1) return "空闲";
|
||||
else if (status == 2) return "充电";
|
||||
else if (status == 2) return "放电";
|
||||
else if (status == 9) return "故障";
|
||||
else return "离线";
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryStatTotal(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
std::string sqlCondition = GetRequestStatParams(req, params);
|
||||
|
||||
njson jsondata;
|
||||
std::string launchDate;
|
||||
float incomeTotal{};
|
||||
int storageDeviceNum = 0;
|
||||
int chargeDeviceNum = 0;
|
||||
int solarDeviceNum = 0;
|
||||
int capacityTotal{};
|
||||
|
||||
bool isQueryStation = params.contains("station_id");
|
||||
if (isQueryStation)
|
||||
{
|
||||
std::string stationId = params.value("station_id");
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
if (station)
|
||||
{
|
||||
launchDate = station->launchDate;
|
||||
storageDeviceNum = 1; //: 储能设备数量
|
||||
chargeDeviceNum = station->getDeviceCount(2); //: 光伏设备数量
|
||||
solarDeviceNum = station->getDeviceCount(3); //: 光伏设备数量
|
||||
capacityTotal = station->capacity; // : 储能总容量(kWh),精度0.001
|
||||
jsondata["storage_status"] = GetStationStatusStr(station->storage.status);
|
||||
jsondata["charge_status"] = GetStationStatusStr(station->charge.status);
|
||||
jsondata["pv_status"] = "离线";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& appdata = Application::data();
|
||||
launchDate = appdata.launchDate; //: 系统上线启用日期,格式:yyyy-mm-dd
|
||||
for (auto& item : appdata.mapStation)
|
||||
{
|
||||
auto& station = item.second;
|
||||
storageDeviceNum += 1;
|
||||
chargeDeviceNum += station->getDeviceCount(2);
|
||||
solarDeviceNum += station->getDeviceCount(3);
|
||||
capacityTotal += station->capacity;
|
||||
}
|
||||
}
|
||||
|
||||
jsondata["launch_date"] = launchDate; // 场站上线启用日期,格式:yyyy-mm-dd
|
||||
jsondata["storage_device_num"] = storageDeviceNum; //: 储能设备数量
|
||||
jsondata["charge_device_num"] = chargeDeviceNum; //: 储能设备数量
|
||||
jsondata["income_total"] = incomeTotal; // : 累计收益(元),精度0.01
|
||||
jsondata["solar_device_num"] = solarDeviceNum; //: 光伏设备数量
|
||||
jsondata["capacity_total"] = capacityTotal; // : 储能总容量(kWh),精度0.001
|
||||
|
||||
|
||||
|
||||
// 从 stat_total 表中查询日期最新的一条数据
|
||||
std::vector<Fields> result;
|
||||
std::string sql = std::format("SELECT st.* FROM stat_total st INNER JOIN "
|
||||
"(SELECT station_id, MAX(dt) max_dt FROM stat_total ss {} GROUP BY station_id) tmp "
|
||||
"ON st.station_id = tmp.station_id AND st.dt = tmp.max_dt; ", sqlCondition);
|
||||
DaoEntity::execOnce(sql, result);
|
||||
|
||||
int eIn = 0;
|
||||
int eOut = 0;
|
||||
int tIn = 0;
|
||||
int tOut = 0;
|
||||
int nErr = 0;
|
||||
int eGen = 0;
|
||||
int eGrid = 0;
|
||||
int eCharge = 0;
|
||||
int income = 0;
|
||||
int incomeCharge = 0;
|
||||
for (int i=0; i<result.size(); ++i)
|
||||
{
|
||||
auto& fields = result[i];
|
||||
if (isQueryStation)
|
||||
{
|
||||
if (params.value("station_id") == fields.value("station_id"))
|
||||
{
|
||||
eIn = fields.get<int>("E_in");
|
||||
eOut = fields.get<int>("E_out");
|
||||
tIn = fields.get<int>("t_in");
|
||||
tOut = fields.get<int>("t_out");
|
||||
eGen = fields.get<int>("E_gen");
|
||||
eGrid = fields.get<int>("E_grid");
|
||||
eCharge = fields.get<int>("E_charge");
|
||||
income = fields.get<int>("income");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eIn += fields.get<int>("E_in");
|
||||
eOut += fields.get<int>("E_out");
|
||||
tIn += fields.get<int>("t_in");
|
||||
tOut += fields.get<int>("t_out");
|
||||
eGen += fields.get<int>("E_gen");
|
||||
eGrid = fields.get<int>("E_grid");
|
||||
eCharge += fields.get<int>("E_charge");
|
||||
income += fields.get<int>("income");
|
||||
}
|
||||
}
|
||||
|
||||
jsondata["storage_elect_in"] = eIn; //储能充电电量(kWh),精度:0.001
|
||||
jsondata["storage_elect_out"] = eOut; //储能放电电量(kWh),精度:0.001
|
||||
jsondata["storage_num_in"] = tIn; //储能设备充电次数
|
||||
jsondata["storage_num_out"] = tOut; //储能设备放电次数
|
||||
//jsondata["storage_num_err"] = fields.value("n_err"); //储能设备故障次数
|
||||
jsondata["solar_elect_gen"] = eGen; //光伏发电电量(kWh),精度:0.001
|
||||
jsondata["solar_elect_grid"] = eGrid; //光伏入网电量(kWh),精度:0.001
|
||||
//jsondata["solar_num_err"] = fields.value("n_err_solor"); //光伏设备故障次数
|
||||
jsondata["charge_elect"] = eCharge; //充电设备充电电量(kWh),精度:0.001
|
||||
//jsondata["charge_num"] = fields.value("n_charge"); //充电设备充电次数
|
||||
//jsondata["charge_num_err"] = fields.value("n_err_charge"); //充电设备故障次数
|
||||
jsondata["income_elect"] = income; //发电收益(元),精度:0.01
|
||||
//jsondata["income_charge"] = fields.value("income_charge"); //充电收益(元),精度:0.01
|
||||
//jsondata["usage_rate"] = 0; //Utils::toStr(float(fields.get<int>("storage_usage") + fields.get<int>("storage_usage")) * 0.5f, 0);
|
||||
json["data"] = jsondata;
|
||||
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
|
||||
Errcode HttpEntity::queryStatSystem(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
auto& appdata = Application::data();
|
||||
|
||||
float incomeTotal {};
|
||||
float station_num = appdata.getStationCount();
|
||||
float solarDeviceNum {};
|
||||
float capacityTotal {};
|
||||
float electGenTotal {};
|
||||
float electGridTotal {};
|
||||
float electStorageIn {};
|
||||
float electStorageOut {};
|
||||
float income = 0.0;
|
||||
int nStation = 0;
|
||||
int nSolar {};
|
||||
int capacity {};
|
||||
int eGen {};
|
||||
int eGrid {};
|
||||
int eIn {};
|
||||
int eOut {};
|
||||
for (auto& item : appdata.mapStation)
|
||||
{
|
||||
auto& station = item.second;
|
||||
solarDeviceNum += station->getDeviceCount(3);
|
||||
capacityTotal += station->capacity;
|
||||
electGenTotal += station->electGenTotal;
|
||||
electGridTotal += station->electGridTotal;
|
||||
electStorageIn += station->electStorageIn;
|
||||
electStorageOut += station->electStorageOut;
|
||||
nStation += 1;
|
||||
nSolar += station->getDeviceCount(3);
|
||||
capacity += station->capacity;
|
||||
eGen += station->electGenTotal;
|
||||
eGrid += station->electGridTotal;
|
||||
eIn += station->statData.totalElectIn;
|
||||
eOut += station->statData.totalElectOut;
|
||||
}
|
||||
|
||||
float income = 0.0;
|
||||
|
||||
njson jsondata;
|
||||
jsondata["launch_date"] = appdata.launchDate; //: 系统上线启用日期,格式:yyyy-mm-dd
|
||||
jsondata["income_total"] = incomeTotal; // : 累计收益(元),精度0.01
|
||||
jsondata["station_num"] = station_num; // : 能源站数量
|
||||
jsondata["storage_device_num"] = station_num; //: 储能设备数量
|
||||
jsondata["solar_device_num"] = solarDeviceNum; //: 光伏设备数量
|
||||
jsondata["capacity_total"] = capacityTotal; // : 储能总容量(kWh),精度0.001
|
||||
jsondata["solar_elect_gen"] = electGenTotal; // : 发电总电量(kWh),精度0.001
|
||||
jsondata["solar_elect_grid"] = electGridTotal; // : 入网种电量(kWh),精度0.001
|
||||
jsondata["storage_elect_in"] = electStorageIn; // : 储能充电总电量(kWh),精度0.001
|
||||
jsondata["storage_elect_out"] = electStorageOut; // : 储能放电总电量(kWh),精度0.001
|
||||
jsondata["income_total"] = income; // : 累计收益(元),精度0.01
|
||||
jsondata["storage_device_num"] = nStation; //: 储能设备数量
|
||||
jsondata["solar_device_num"] = nSolar; //: 光伏设备数量
|
||||
jsondata["capacity_total"] = capacity; // : 储能总容量(kWh),精度0.001
|
||||
jsondata["solar_elect_gen"] = eGen; // : 发电总电量(kWh),精度0.001
|
||||
jsondata["solar_elect_grid"] = eGrid; // : 入网总电量(kWh),精度0.001
|
||||
jsondata["storage_elect_in"] = eIn; // : 储能充电总电量(kWh),精度0.001
|
||||
jsondata["storage_elect_out"] = eOut; // : 储能放电总电量(kWh),精度0.001
|
||||
|
||||
// 总览页面:累计收益
|
||||
std::string sql = "SELECT * FROM stat_total st INNER JOIN "
|
||||
std::string sql = "SELECT st.* FROM stat_total st INNER JOIN "
|
||||
"(SELECT station_id, MAX(dt) max_dt FROM stat_total GROUP BY station_id) tmp "
|
||||
"ON st.station_id = tmp.station_id AND st.dt = tmp.max_dt; ";
|
||||
std::vector<Fields> result;
|
||||
@@ -1216,119 +1492,7 @@ Errcode HttpEntity::queryStatStationGroup(const httplib::Request& req, njson& js
|
||||
return Errcode(err);
|
||||
}
|
||||
|
||||
static void VerifyRequstParamsStatDate(Fields& params)
|
||||
{
|
||||
if (!params.contains("end_date"))
|
||||
{
|
||||
if (!params.contains("start_date"))
|
||||
{
|
||||
params.set("end_date", Utils::dateStr());
|
||||
params.set("start_date", Utils::dateStr(Utils::date() - 86400*7));
|
||||
}
|
||||
else
|
||||
{
|
||||
params.set("end_date", Utils::dateStr(Utils::time(params.value("start_date") +" 00:00:00") + 86400*7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::string VerifyStatSqlCondition(Fields& params)
|
||||
{
|
||||
std::string stationId = params.value("station_id");
|
||||
std::string category = params.value("category");
|
||||
std::string dtStart = params.value("start_date");
|
||||
std::string dtEnd = params.value("end_date");
|
||||
|
||||
std::string sqlCondition;
|
||||
if (!dtStart.empty() && dtEnd.empty())
|
||||
{
|
||||
sqlCondition += "dt BETWEEN '" + dtStart + "' AND '" + dtEnd + "'";
|
||||
}
|
||||
if (!stationId.empty())
|
||||
{
|
||||
if (!sqlCondition.empty()) sqlCondition += " AND ";
|
||||
sqlCondition += "ss.station_id='" + stationId + "'";
|
||||
}
|
||||
if (!category.empty() && category != "0")
|
||||
{
|
||||
//if (!sqlCondition.empty()) sqlCondition += " AND ";
|
||||
//sqlCondition += "ss.category='" + category + "'";;
|
||||
}
|
||||
if (!sqlCondition.empty()) { sqlCondition = " WHERE " + sqlCondition; }
|
||||
return sqlCondition;
|
||||
}
|
||||
|
||||
static std::string GetRequestStatParams(const httplib::Request& req, Fields& params)
|
||||
{
|
||||
|
||||
GetRequestParams(req, {"station_id", "category", "start_date", "end_date"}, params);
|
||||
VerifyRequstParamsStatDate(params);
|
||||
return VerifyStatSqlCondition(params);
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryStatTotal(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
std::string sqlCondition = GetRequestStatParams(req, params);
|
||||
//std::string sql = R"(SELECT
|
||||
// SUM(storage_elect_in) storage_elect_in,
|
||||
// SUM(storage_elect_out) storage_elect_out,
|
||||
// SUM(storage_num_in) storage_num_in,
|
||||
// SUM(storage_num_out) storage_num_out,
|
||||
// SUM(storage_num_err) storage_num_err,
|
||||
// SUM(solar_elect_gen) solar_elect_gen,
|
||||
// SUM(solar_elect_grid) solar_elect_grid,
|
||||
// SUM(solar_num_err) solar_num_err,
|
||||
// AVG(storage_usage) storage_usage,
|
||||
// SUM(charge_elect) charge_elect,
|
||||
// SUM(charge_num) charge_num,
|
||||
// SUM(charge_num_err) charge_num_err,
|
||||
// AVG(charge_usage) charge_usage,
|
||||
// SUM(income_elect) income_elect,
|
||||
// SUM(income_charge) income_charge
|
||||
// FROM stat_day ss)" + sqlCondition + ";";
|
||||
|
||||
std::string stationId = params.value("station_id");
|
||||
|
||||
njson jsondata;
|
||||
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
if (station)
|
||||
{
|
||||
jsondata["launch_date"] = station->launchDate;
|
||||
}
|
||||
|
||||
auto& appdata = Application::data();
|
||||
std::vector<Fields> result;
|
||||
std::string sql = std::format("SELECT * FROM stat_total st INNER JOIN "
|
||||
"(SELECT station_id, MAX(dt) max_dt FROM stat_total ss {} GROUP BY station_id) tmp "
|
||||
"ON st.station_id = tmp.station_id AND st.dt = tmp.max_dt; ", sqlCondition);
|
||||
DaoEntity::execOnce(sql, result);
|
||||
if (result.size() > 0)
|
||||
{
|
||||
auto& fields = result[0];
|
||||
|
||||
//jsondata["launch_date"] = appdata.launchDate; //: 系统上线启用日期,格式:yyyy-mm-dd
|
||||
// jsondata["station_id"] = station_id;
|
||||
jsondata["storage_elect_in"] = fields.value("E_in"); //储能充电电量(kWh),精度:0.001
|
||||
jsondata["storage_elect_out"] = fields.value("E_out"); //储能放电电量(kWh),精度:0.001
|
||||
jsondata["storage_num_in"] = fields.value("t_in"); //储能设备充电次数
|
||||
jsondata["storage_num_out"] = fields.value("t_out"); //储能设备放电次数
|
||||
jsondata["storage_num_err"] = fields.value("n_err"); //储能设备故障次数
|
||||
jsondata["solar_elect_gen"] = fields.value("E_gen"); //光伏发电电量(kWh),精度:0.001
|
||||
jsondata["solar_elect_grid"] = fields.value("E_grid"); //光伏入网电量(kWh),精度:0.001
|
||||
jsondata["solar_num_err"] = fields.value("n_err_solor"); //光伏设备故障次数
|
||||
jsondata["charge_elect"] = fields.value("E_charge"); //充电设备充电电量(kWh),精度:0.001
|
||||
jsondata["charge_num"] = fields.value("n_charge"); //充电设备充电次数
|
||||
jsondata["charge_num_err"] = fields.value("n_err_charge"); //充电设备故障次数
|
||||
jsondata["income_elect"] = fields.value("income"); //发电收益(元),精度:0.01
|
||||
jsondata["income_charge"] = fields.value("income_charge"); //充电收益(元),精度:0.01
|
||||
jsondata["usage_rate"] = 0; //Utils::toStr(float(fields.get<int>("storage_usage") + fields.get<int>("storage_usage")) * 0.5f, 0);
|
||||
json["data"] = jsondata;
|
||||
}
|
||||
|
||||
return Errcode::OK;
|
||||
}
|
||||
Errcode HttpEntity::queryStatDayList(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
@@ -1362,6 +1526,7 @@ Errcode HttpEntity::queryStatDayList(const httplib::Request& req, njson& json, s
|
||||
njson jsondata = njson::array();
|
||||
for (int64_t t = t0; t<=t1; t += 86400)
|
||||
{
|
||||
i++;
|
||||
njson jsonrow;
|
||||
std::string dt = Utils::dateStr(t);
|
||||
Fields* fields = NULL;
|
||||
@@ -1369,21 +1534,21 @@ Errcode HttpEntity::queryStatDayList(const httplib::Request& req, njson& json, s
|
||||
if (iter != mapTemp.end()) { fields = iter->second; }
|
||||
|
||||
jsonrow["dt"] = dt.substr(5);
|
||||
jsonrow["storage_elect_in"] = fields ? fields->value("storage_elect_in") : "0";
|
||||
jsonrow["storage_elect_in"] = fields ? fields->value("storage_elect_in") : "0";
|
||||
jsonrow["storage_elect_out"] = fields ? fields->value("storage_elect_out") : "0";
|
||||
jsonrow["storage_num_in"] = fields ? fields->value("storage_num_in") : "0";
|
||||
jsonrow["storage_num_out"] = fields ? fields->value("storage_num_out") : "0";
|
||||
jsonrow["storage_num_err"] = fields ? fields->value("storage_num_err") : "0";
|
||||
jsonrow["solar_elect_gen"] = fields ? fields->value("solar_elect_gen") : "0";
|
||||
jsonrow["solar_elect_grid"] = fields ? fields->value("solar_elect_grid") : "0";
|
||||
jsonrow["solar_num_err"] = fields ? fields->value("solar_num_err") : "0";
|
||||
jsonrow["storage_usage"] = fields ? fields->value("storage_usage") : "0";
|
||||
jsonrow["charge_elect"] = fields ? fields->value("charge_elect") : "0";
|
||||
jsonrow["charge_num"] = fields ? fields->value("charge_num") : "0";
|
||||
jsonrow["charge_num_err"] = fields ? fields->value("charge_num_err") : "0";
|
||||
jsonrow["charge_usage"] = fields ? fields->value("charge_usage") : "0";
|
||||
jsonrow["income_elect"] = fields ? fields->value("income_elect") : "0";
|
||||
jsonrow["income_charge"] = fields ? fields->value("income_charge") : "0";
|
||||
jsonrow["storage_num_in"] = fields ? fields->value("storage_num_in") : "0";
|
||||
jsonrow["storage_num_out"] = fields ? fields->value("storage_num_out") : "0";
|
||||
jsonrow["storage_num_err"] = fields ? fields->value("storage_num_err") : "0";
|
||||
jsonrow["solar_elect_gen"] = fields ? fields->value("solar_elect_gen") : "0";
|
||||
jsonrow["solar_elect_grid"] = fields ? fields->value("solar_elect_grid") : "0";
|
||||
jsonrow["solar_num_err"] = fields ? fields->value("solar_num_err") : "0";
|
||||
jsonrow["storage_usage"] = fields ? fields->value("storage_usage") : "0";
|
||||
jsonrow["charge_elect"] = fields ? fields->value("charge_elect") : "0";
|
||||
jsonrow["charge_num"] = fields ? fields->value("charge_num") : "0";
|
||||
jsonrow["charge_num_err"] = fields ? fields->value("charge_num_err") : "0";
|
||||
jsonrow["charge_usage"] = fields ? fields->value("charge_usage") : "0";
|
||||
jsonrow["income_elect"] = fields ? fields->value("income_elect") : "0";
|
||||
jsonrow["income_charge"] = fields ? fields->value("income_charge") : "0";
|
||||
jsondata.push_back(jsonrow);
|
||||
}
|
||||
json["data"] = jsondata;
|
||||
|
||||
Reference in New Issue
Block a user