修改http统计查询接口

This commit is contained in:
lixiaoyuan
2025-12-01 18:26:42 +08:00
parent f8dad86731
commit 97e4b182de
6 changed files with 139 additions and 78 deletions

View File

@@ -308,6 +308,7 @@ string Station::getGatewayParam()
void Station::checkDevice()
{
int err = 0;
for (auto& item: mapDevice)
{
auto& device = item.second;
@@ -317,8 +318,13 @@ void Station::checkDevice()
{
device->online = 0;
}
if (device->type != 5 && (device->err == 1 || device->online == 0))
{
err = 1;
}
}
}
this->err = err;
}
void Station::readAlert(std::shared_ptr<Device> device, std::string addr, int v, std::string text)
@@ -333,7 +339,7 @@ void Station::readAlert(std::shared_ptr<Device> device, std::string addr, int v,
if (device) { fields.set("device_id", device->deviceId); }
fields.set("type", int(EAlertType::DEVICE));
fields.set("content", text + ":故障(" + std::to_string(v) + ")");
fields.set("status", 1);
fields.set("status", 0);
auto dao = DaoEntity::create("log_alert");
dao->insertFields(fields);
mapAlertCache[alertId] = ts;
@@ -611,6 +617,31 @@ void Station::writeStatistic()
}
}
{
Fields fields;
fields.set("dt", Utils::dateStr(statData.ts));
fields.set("station_id", this->stationId);
fields.set("E_in", statData.totalElectIn);
fields.set("E_in_J", statData.totalElectIn_J);
fields.set("E_in_F", statData.totalElectIn_F);
fields.set("E_in_P", statData.totalElectIn_P);
fields.set("E_in_G", statData.totalElectIn_G);
fields.set("E_out", statData.totalElectOut);
fields.set("E_out_J", statData.totalElectOut_J);
fields.set("E_out_F", statData.totalElectOut_F);
fields.set("E_out_P", statData.totalElectOut_P);
fields.set("E_out_G", statData.totalElectOut_G);
fields.set("fee_in", statData.totalFeeIn);
fields.set("fee_Out", statData.totalFeeOut);
fields.set("income", statData.totalIncome);
dao->setTableName("stat_total");
dao->duplicateUpdate(fields, {
"E_in", "E_in_J", "E_in_F", "E_in_P", "E_in_G",
"E_out", "E_out_J", "E_out_F", "E_out_P", "E_out_G",
"fee_in", "fee_Out", "income"
});
}
if (statData.ts > 0)
{
{ // stat_day
@@ -622,31 +653,8 @@ void Station::writeStatistic()
fields.set("income_elect", statData.dayIncome);
DAO::insertStatDay(dao, fields);
}
{
Fields fields;
fields.set("dt", Utils::dateStr(statData.ts));
fields.set("station_id", this->stationId);
fields.set("E_in", statData.totalElectIn);
fields.set("E_in_J", statData.totalElectIn_J);
fields.set("E_in_F", statData.totalElectIn_F);
fields.set("E_in_P", statData.totalElectIn_P);
fields.set("E_in_G", statData.totalElectIn_G);
fields.set("E_out", statData.totalElectOut);
fields.set("E_out_J", statData.totalElectOut_J);
fields.set("E_out_F", statData.totalElectOut_F);
fields.set("E_out_P", statData.totalElectOut_P);
fields.set("E_out_G", statData.totalElectOut_G);
fields.set("fee_in", statData.totalFeeIn);
fields.set("fee_Out", statData.totalFeeOut);
fields.set("income", statData.totalIncome);
dao->setTableName("stat_total");
dao->duplicateUpdate(fields, {
"E_in", "E_in_J", "E_in_F", "E_in_P", "E_in_G",
"E_out", "E_out_J", "E_out_F", "E_out_P", "E_out_G",
"fee_in", "fee_Out", "income"
});
}
if (statData.dayElectIn > 0.0f || statData.dayElectOut > 0.0f)
{
Fields fields;
fields.set("dt", Utils::dateStr(statData.ts));
@@ -699,6 +707,23 @@ void Station::writeStatistic()
fields.set("value", MapValueToJson(pos, mapCacheElectCharger));
dao->duplicateUpdate(fields, {"value"});
}
{
std::string sql = std::format("select dt, station_id, count(1) count from ( "
" select DATE(la.create_time) as dt, station_id, la.device_id, count(1), la.content from log_alert la "
" LEFT JOIN device d ON d.device_id = la.device_id "
"where la.create_time >= '{}' group by la.content, station_id, device_id, dt "
") as tmp group by tmp.dt, station_id; ", Utils::dateStr(Utils::time()- 86400 * 7));
vector<Fields> result;
dao->exec(sql, result);
for (auto& item : result)
{
string dt = item.value("dt");
string station_id = item.value("station_id");
string count = item.value("count");
std::string sqlUpdate = std::format("update stat_day set storage_num_err='{}' where dt='{}' AND station_id='{}'", count, dt, station_id);
dao->exec(sqlUpdate);
}
}
}
@@ -735,15 +760,24 @@ void Station::predict()
if (vdptr)
{
int v0 = 0;
string& strval = fields.value("value");
std::vector<int> vec;
JSON::parseArray(strval, vec);
for (int i = 0; i<vdptr->size() && i<vec.size(); ++i)
{
auto& v0 = vec[i];
auto& v = vec[i];
if (v < v0)
{
v = v0;
}
else
{
v0 = v;
}
//if (v0 > 0)
{
(*vdptr)[i] += v0;
(*vdptr)[i] += v;
if (datatype == 1) { countStorageIn[i]++; }
else if (datatype == 2) { countStorageOut[i]++; }
else if (datatype == 3) { countCharge[i]++; }