mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现启动splash画面,实现天历史数据的处理和数据库存贮
This commit is contained in:
@@ -6,8 +6,9 @@
|
||||
#include "common/Spdlogger.h"
|
||||
#include "common/Utils.h"
|
||||
#include "protocol/MqttEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
|
||||
Station::Station() : id(0)
|
||||
Station::Station() : stationId(0)
|
||||
{
|
||||
mqttCli = std::make_shared<MqttClient>();
|
||||
|
||||
@@ -32,7 +33,7 @@ Station::Station() : id(0)
|
||||
|
||||
void Station::setFields(Fields& fields)
|
||||
{
|
||||
this->id = fields.get<int>(DMStation::STATION_ID);
|
||||
this->stationId = fields.get<int>(DMStation::STATION_ID);
|
||||
this->name = fields.value(DMStation::NAME);
|
||||
this->energyCapacity = fields.get<double>(DMStation::CAPACITY);
|
||||
this->workModeId = fields.get<int>(DMStation::WORK_MODE);
|
||||
@@ -99,7 +100,7 @@ void Station::setWorkMode(int modeId)
|
||||
this->workModeId = modeId;
|
||||
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
|
||||
.update(DMStation::WORK_MODE, std::to_string(modeId))
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(id)).str();
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(stationId)).str();
|
||||
Errcode err = DAO::exec(NULL, sql);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
@@ -111,10 +112,49 @@ void Station::setPolicy(int policyId)
|
||||
{
|
||||
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
|
||||
.update(DMStation::POLICY_ID, std::to_string(policyId))
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(id)).str();
|
||||
.where(DMStation::STATION_ID + "=" + std::to_string(stationId)).str();
|
||||
Errcode err = DAO::exec(NULL, sql);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
spdlog::error("set station policy failed.");
|
||||
}
|
||||
}
|
||||
|
||||
static std::string MapValueToJson(int npos, std::map<int, double>& mapV)
|
||||
{
|
||||
njson jsonarray = njson::array();
|
||||
for (int i = 0; i<=npos; i++)
|
||||
{
|
||||
jsonarray.push_back(mapV[i]);
|
||||
}
|
||||
return jsonarray.dump();
|
||||
}
|
||||
|
||||
void Station::writeRuntimeData(std::string dt, int npos)
|
||||
{
|
||||
auto dao = DaoEntity::create("history_day");
|
||||
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
|
||||
{
|
||||
auto device = iter->second;
|
||||
if (device->cache(npos))
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("dt", dt);
|
||||
fields.set("station_id", this->stationId);
|
||||
fields.set("device_id", device->deviceId);
|
||||
fields.set("datatype", 1);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheVoltage));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 2);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCacheCurrent));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
fields.set("datatype", 3);
|
||||
fields.set("value", MapValueToJson(npos, device->mapCachePower));
|
||||
DAO::insertRuntimeData(dao, fields);
|
||||
|
||||
spdlog::info("[device] write runtime date to database, deviceId={}", device->deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user