修改策略分析页面数据查询接口和表格显示数据变化时表格高度异常的问题

This commit is contained in:
lixiaoyuan
2026-05-08 16:57:55 +08:00
parent 27365642d9
commit 72721608e3
5 changed files with 98 additions and 44 deletions

View File

@@ -1981,10 +1981,12 @@ static float SetPeriodRowJson(njson& jsonrow, std::string period, int eIn, int e
Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, std::string& errmsg)
{
Fields params;
GetRequestParams(req, {"dt", "station_id"}, params);
GetRequestParams(req, {"dt_start", "dt_end", "station_id"}, params);
int stationId = params.get<int>("station_id");
std::string dt = params.value("dt");
std::string dtStart = params.value("dt_start");
std::string dtEnd = params.value("dt_end");
//int year = 0;
//int month = 0;
//int day = 0;
@@ -1993,7 +1995,7 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
//{
// return Errcode::ERR_PARAM;
//}
if (stationId == 0 || dt.empty())
if (stationId == 0 || dtStart.empty() || dtEnd.empty())
{
return Errcode::ERR_PARAM;
}
@@ -2025,25 +2027,28 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
}
//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);
std::string sql = std::format("select * from stat_total_day WHERE dt>='{}' AND dt<='{}' AND station_id='{}';", dtStart, dtEnd, stationId);
err = DAO::exec(NULL, sql, result);
if (err != Errcode::OK)
{
return err;
}
int totalIn {};
int totalOut {};
float totalIncome {0.0f};
njson jsondata = njson::array();
if (result.size() > 0)
for (auto& item: result)
{
auto& item = result[0];
float incomeTotal = 0.0f;
std::string dt = item.get<std::string>("dt");
// 谷
{
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;
totalIncome += income;
}
// 平
{
@@ -2051,7 +2056,7 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
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;
totalIncome += income;
}
// 峰
{
@@ -2059,7 +2064,7 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
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;
totalIncome += income;
}
// 尖
{
@@ -2067,21 +2072,24 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
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);
totalIncome += income;
}
totalIn += item.get<int>("E_in");
totalOut += item.get<int>("E_out");
}
// 总计
{
njson jsonrow;
jsonrow["dt"] = "";
jsonrow["period"] = "总计";
jsonrow["E_in"] = totalIn;
jsonrow["E_out"] = totalOut;
jsonrow["grid_price"] = "";
jsonrow["charge_price"] = "";
jsonrow["income"] = Utils::toStr(totalIncome);
jsondata.push_back(jsonrow);
}
json["data"] = jsondata;
return Errcode::OK;
}