mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
新增策略运行效益接口
This commit is contained in:
@@ -193,7 +193,9 @@ static std::map<std::string, HandlerOptions> g_mapHttpHandlerGet =
|
||||
|
||||
{"/queryServiceApiList", HandlerOptions(&HttpEntity::queryServiceApiList, {})},
|
||||
{"/deleteServiceApi", HandlerOptions(&HttpEntity::deleteServiceApi, {"api_id"})},
|
||||
|
||||
|
||||
{"/queryEGridPeriod", HandlerOptions(&HttpEntity::queryEGridPeriod, {})},
|
||||
|
||||
//{"/insert", HandlerOptions(&HttpEntity::insert, {})},
|
||||
//{"/update", HandlerOptions(&HttpEntity::update, {})},
|
||||
//{"/delete", HandlerOptions(&HttpEntity::delete, {})},
|
||||
@@ -1895,4 +1897,124 @@ Errcode HttpEntity::updateGatewayParams(const httplib::Request& req, njson& json
|
||||
return Errcode::OK;
|
||||
}
|
||||
return Errcode::ERR_PARAM;
|
||||
}
|
||||
|
||||
|
||||
static float SetPeriodRowJson(njson& jsonrow, std::string period, int eIn, int eOut, float priceIn, float priceOut, std::string dt)
|
||||
{
|
||||
jsonrow["dt"] = dt;
|
||||
jsonrow["period"] = period;
|
||||
jsonrow["E_in"] = eIn;
|
||||
jsonrow["E_out"] = eOut;
|
||||
jsonrow["grid_price"] = Utils::toStr(priceIn);
|
||||
jsonrow["charge_price"] = Utils::toStr(priceOut);
|
||||
return eOut * priceOut - eIn * priceIn;
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
GetRequestParams(req, {"dt", "station_id"}, params);
|
||||
|
||||
int stationId = params.get<int>("station_id");
|
||||
std::string dt = params.value("dt");
|
||||
//int year = 0;
|
||||
//int month = 0;
|
||||
//int day = 0;
|
||||
//int ret = sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day); // 解析3个值,成功返回3
|
||||
//if (ret != 3)
|
||||
//{
|
||||
// return Errcode::ERR_PARAM;
|
||||
//}
|
||||
if (stationId == 0 || dt.empty())
|
||||
{
|
||||
return Errcode::ERR_PARAM;
|
||||
}
|
||||
|
||||
float priceJ = 0.0;
|
||||
float priceF = 0.0;
|
||||
float priceP = 0.0;
|
||||
float priceG = 0.0;
|
||||
float priceC = 0.0;
|
||||
|
||||
std::vector<Fields> result;
|
||||
auto err = DAO::exec(NULL, "select * from egrid_price;", result);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
if (result.size() > 0)
|
||||
{
|
||||
for (auto& item: result)
|
||||
{
|
||||
int etype = item.get<int>("etype");
|
||||
float price = item.get<float>("price", 2);
|
||||
if (etype == 1) { priceJ = price; }
|
||||
else if (etype == 2) { priceF = price; }
|
||||
else if (etype == 3) { priceP = price; }
|
||||
else if (etype == 4) { priceG = price; }
|
||||
else if (etype == 9) { priceC = price; }
|
||||
}
|
||||
}
|
||||
|
||||
//std::string sql = std::format("SELECT ep.*, ep2.price FROM egrid_period ep LEFT JOIN egrid_price ep2 ON ep.etype=ep2.etype WHERE ep.`month`={};", month);
|
||||
std::string sql = std::format("select * from stat_total_day WHERE dt='{}' AND station_id='{}';", dt, stationId);
|
||||
err = DAO::exec(NULL, sql, result);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
njson jsondata = njson::array();
|
||||
if (result.size() > 0)
|
||||
{
|
||||
auto& item = result[0];
|
||||
float incomeTotal = 0.0f;
|
||||
// 谷
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "谷", item.get<int>("E_in_G"), item.get<int>("E_out_G"), priceG, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 平
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "平", item.get<int>("E_in_P"), item.get<int>("E_out_P"), priceP, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 峰
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "峰", item.get<int>("E_in_F"), item.get<int>("E_out_F"), priceF, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 尖
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "尖", item.get<int>("E_in_J"), item.get<int>("E_out_J"), priceJ, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 总计
|
||||
{
|
||||
njson jsonrow;
|
||||
jsonrow["dt"] = dt;
|
||||
jsonrow["period"] = "总计";
|
||||
jsonrow["E_in"] = item.get<int>("E_in");
|
||||
jsonrow["E_out"] = item.get<int>("E_out");
|
||||
jsonrow["grid_price"] = "";
|
||||
jsonrow["charge_price"] = "";
|
||||
jsonrow["income"] = Utils::toStr(incomeTotal);
|
||||
jsondata.push_back(jsonrow);
|
||||
}
|
||||
}
|
||||
json["data"] = jsondata;
|
||||
return Errcode::OK;
|
||||
}
|
||||
Reference in New Issue
Block a user