根据甲方意见修改:删除光伏等无数据的展示模块、储能充放电/收益按月+季度+周+年展示、修改首页展示内容

This commit is contained in:
lixiaoyuan
2026-05-27 16:35:12 +08:00
parent 9c51037aa1
commit 0f484a4a68
22 changed files with 788 additions and 193 deletions

View File

@@ -188,6 +188,8 @@ static std::map<std::string, HandlerOptions> g_mapHttpHandlerGet =
{"/queryStatDetailList", HandlerOptions(&HttpEntity::queryStatDetailList, {})},
{"/queryStatCharts", HandlerOptions(&HttpEntity::queryStatCharts, {})},
{"/exportStatReport", HandlerOptions(&HttpEntity::exportStatReport, {})},
{"/queryStatStationMode", HandlerOptions(&HttpEntity::queryStatStationMode, {})},
{"/queryEnvironment", HandlerOptions(&HttpEntity::queryEnvironment, { "station_id"})},
@@ -1225,12 +1227,16 @@ Errcode HttpEntity::queryPolicyByType(const httplib::Request& req, njson& json,
Errcode HttpEntity::querySystemLogList(const httplib::Request& req, njson& json, std::string& errmsg)
{
Fields params;
GetRequestParams(req, {"station_id"}, params);
PageInfo pageinfo;
pageinfo.index = Utils::toInt(req.get_param_value("page"));
pageinfo.size = Utils::toInt(req.get_param_value("page_size"));
std::string stationId = params.value("station_id");
std::vector<Fields> result;
auto err = DAO::querySystemLogList(pageinfo, result);
auto err = DAO::querySystemLogList(stationId, pageinfo, result);
HttpHelper::setPagination(pageinfo, result, json);
return err;
}
@@ -1245,12 +1251,16 @@ Errcode HttpEntity::updateSystemLog(const httplib::Request& req, njson& json, st
Errcode HttpEntity::queryAlertLogList(const httplib::Request& req, njson& json, std::string& errmsg)
{
Fields params;
GetRequestParams(req, {"station_id"}, params);
PageInfo pageinfo;
pageinfo.index = Utils::toInt(req.get_param_value("page"));
pageinfo.size = Utils::toInt(req.get_param_value("page_size"));
std::string stationId = params.value("station_id");
std::vector<Fields> result;
auto err = DAO::queryAlertLogList(pageinfo, result);
auto err = DAO::queryAlertLogList(stationId, pageinfo, result);
HttpHelper::setPagination(pageinfo, result, json);
return err;
}
@@ -1571,12 +1581,10 @@ Errcode HttpEntity::queryStatDayList(const httplib::Request& req, njson& json, s
int64_t t0 = Utils::time(startDate + " 00:00:00");
int64_t t1 = Utils::time(endDate + " 00:00:00");
int i = 0;
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;
@@ -1709,6 +1717,115 @@ Errcode HttpEntity::queryStatCharts(const httplib::Request& req, njson& json, st
return Errcode::OK;
}
Errcode HttpEntity::queryStatStationMode(const httplib::Request& req, njson& json, std::string& errmsg)
{
Fields params;
GetRequestParams(req, {"station_id", "start_date", "end_date", "mode"}, params);
std::string stationId = params.value("station_id");
std::string startDate = params.value("start_date");
std::string endDate = params.value("end_date");
std::string mode = params.value("mode");
std::string sqlC = std::format(" WHERE dt>='{}' AND dt<='{}'", startDate, endDate);
if (!stationId.empty()) sqlC += std::format(" AND station_id='{}'", stationId);
std::string sql = " SUM(E_in) E_in, SUM(E_out) E_out, SUM(fee_in) fee_in, SUM(fee_out) fee_out, SUM(income) income FROM stat_total_day";
std::string sqlGroupBy;
if (mode == "year") {
sql = "SELECT YEAR(dt) AS year, " + sql + sqlC + " GROUP BY YEAR(dt);";
} else if (mode == "quarter") {
sql = "SELECT YEAR(dt) AS year, QUARTER(dt) quarter, " + sql + sqlC+ " GROUP BY YEAR(dt), QUARTER(dt);";
} else if (mode == "month") {
sql = "SELECT YEAR(dt) AS year, MONTH(dt) month, " + sql + sqlC + "GROUP BY YEAR(dt), MONTH(dt);";
} else if (mode == "week") {
sql = "SELECT YEAR(dt) AS year, WEEK(dt) week, " + sql + sqlC + " GROUP BY YEAR(dt), WEEK(dt);";
} else {
mode = "date";
sql = "SELECT dt, E_in, E_out, fee_in, fee_out, income FROM stat_total_day " + sqlC + " LIMIT 1000;";
}
std::vector<Fields> result;
Errcode err = DAO::exec(NULL, sql, result);
njson jsondata = njson::array();
if (mode == "date")
{
std::map<std::string, Fields*> mapTemp;
for (auto& item: result)
{
auto& dt = item.value("dt");
mapTemp[dt] = &item;
}
int64_t t0 = Utils::time(startDate + " 00:00:00");
int64_t t1 = Utils::time(endDate + " 00:00:00");
for (int64_t t = t0; t<=t1; t += 86400)
{
njson jsonrow;
std::string dt = Utils::dateStr(t);
Fields* item = NULL;
auto iter = mapTemp.find(dt);
if (iter != mapTemp.end()) { item = iter->second; }
jsonrow["dt"] = dt;
jsonrow["E_in"] = item ? item->value("E_in") : "0";
jsonrow["E_out"] = item ? item->value("E_out") : "0";
jsonrow["fee_in"] = item ? item->value("fee_in") : "0";
jsonrow["fee_out"] = item ? item->value("fee_out") : "0";
jsonrow["income"] = item ? item->value("income") : "0";
int rate = 0;
if (item) {
int E_in = item->get<int>("E_in");
int E_out = item->get<int>("E_out");
if (E_in != 0) {
rate = (float(E_out)/float(E_in)) * 100;
}
}
jsonrow["E_rate"] = rate;
jsondata.push_back(jsonrow);
}
}
else
{
for (auto& item: result)
{
njson jsonrow;
if (mode == "year") {
jsonrow["dt"] = item.value("year") + "";
}
else if (mode == "quarter") {
jsonrow["dt"] = item.value("year") + "" + item.value("quarter") + "季度";
}
else if (mode == "month") {
jsonrow["dt"] = item.value("year") + "" + item.value("month") + "";
}
else if (mode == "week") {
jsonrow["dt"] = item.value("year") + "" + item.value("week") + "";
}
else {
jsonrow["dt"] = item.value("dt");
}
jsonrow["E_in"] = item.value("E_in");
jsonrow["E_out"] = item.value("E_out");
int rate = 0;
int E_in = item.get<int>("E_in");
int E_out = item.get<int>("E_out");
if (E_in != 0) {
rate = (float(E_out)/float(E_in)) * 100;
}
jsonrow["E_rate"] = rate;
jsonrow["fee_in"] = item.value("fee_in");
jsonrow["fee_out"] = item.value("fee_out");
jsonrow["income"] = item.value("income");
jsondata.push_back(jsonrow);
}
}
json["data"] = jsondata;
return Errcode::OK;
}
Errcode HttpEntity::exportStatReport(const httplib::Request& req, njson& json, std::string& errmsg)
{