mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
调试修改MQTT通讯问题
This commit is contained in:
@@ -128,6 +128,8 @@ public:
|
||||
|
||||
static std::map<std::string, HandlerOptions> g_mapHttpHandlerGet =
|
||||
{
|
||||
{"/queryBaseinfo", HandlerOptions(&HttpEntity::logqueryBaseinfoin, {})},
|
||||
|
||||
{"/login", HandlerOptions(&HttpEntity::login, {DMUser::ACCOUNT, DMUser::PASSWD})},
|
||||
{"/queryUserList", HandlerOptions(&HttpEntity::queryUserList, {})},
|
||||
{"/deleteUser", HandlerOptions(&HttpEntity::deleteUser, { DMUser::USER_ID})},
|
||||
@@ -280,6 +282,7 @@ void HttpEntity::runHandler(std::string name, const HandlerOptions& handler, con
|
||||
jsonresp["errmsg"] = ErrcodeStr(errcode) + (errmsg.empty() ? "" : (":"+errmsg));
|
||||
resp.set_content(jsonresp.dump(), "text/plain; charset=utf-8");
|
||||
resp.status = 200;
|
||||
spdlog::info("[http] request: {}, response: {}.", name, int(errcode));
|
||||
}
|
||||
|
||||
void HttpEntity::registGet(std::string name, void (HttpEntity::* func)(const httplib::Request& req, httplib::Response& resp))
|
||||
@@ -287,6 +290,18 @@ void HttpEntity::registGet(std::string name, void (HttpEntity::* func)(const htt
|
||||
this->httpsvr.Get(name, std::bind(func, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
Errcode HttpEntity::logqueryBaseinfoin(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
json["data"] = {
|
||||
{"encryption", Config::option.http.encryption},
|
||||
{"encryptKey", Config::option.http.encryptKey},
|
||||
{"latitude", Config::option.view.latitude},
|
||||
{"longitude", Config::option.view.longitude},
|
||||
{"altitude", Config::option.view.altitude}
|
||||
};
|
||||
return Errcode::OK;
|
||||
}
|
||||
|
||||
Errcode HttpEntity::login(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
std::string userId;
|
||||
@@ -602,12 +617,13 @@ Errcode HttpEntity::insertStation(const httplib::Request& req, njson& json, std:
|
||||
Errcode HttpEntity::updateStation(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
GetRequestParam(req, {"station_id", "name", "address", "lon", "lat", "tel", "capacity", "status", "work_mode", "policy_id"}, params);
|
||||
GetRequestParam(req, {"station_id", "name", "address", "lon", "lat", "tel", "capacity", "status", "work_mode", "policy_id", "operation_date"}, params);
|
||||
std::string stationId = params.value("station_id");
|
||||
params.check("capacity", "", "0.0");
|
||||
params.check("lon", "", "0.0");
|
||||
params.check("lat", "", "0.0");
|
||||
params.check("status", "", "1");
|
||||
params.check("policy_id", "", "NULL");
|
||||
Errcode err = DAO::updateStationById(params);
|
||||
if (err == Errcode::OK)
|
||||
{
|
||||
@@ -621,16 +637,11 @@ Errcode HttpEntity::updateStation(const httplib::Request& req, njson& json, std:
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.size() > 0)
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
if (result.size() > 0 && station)
|
||||
{
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
if (station)
|
||||
{
|
||||
station->setFields(result[0]);
|
||||
station->setGarewayWorkMode();
|
||||
}
|
||||
station->setFields(result[0]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return err;
|
||||
@@ -681,6 +692,15 @@ Errcode HttpEntity::queryStationOverview(const httplib::Request& req, njson& jso
|
||||
njson jsonCharge = njson::parse(R"({"category":2, "count":0, "power":0.0})");
|
||||
njson jsonSolar = njson::parse(R"({"category":3, "count":0, "power":0.0})");
|
||||
njson jsonSecurity = njson::parse(R"({"category":4, "count":0, "power":0.0})");
|
||||
auto videoInfo = Config::getVideoInfo(stationId);
|
||||
if (videoInfo)
|
||||
{
|
||||
jsonSecurity["host"] = videoInfo->host;
|
||||
jsonSecurity["port"] = videoInfo->port;
|
||||
jsonSecurity["user"] = videoInfo->user;
|
||||
jsonSecurity["passwd"] = videoInfo->passwd;
|
||||
}
|
||||
|
||||
for (auto& fields : result)
|
||||
{
|
||||
int category = fields.get<int>("category");
|
||||
@@ -743,16 +763,21 @@ Errcode HttpEntity::queryStationInfo(const httplib::Request& req, njson& json, s
|
||||
}
|
||||
Errcode HttpEntity::queryStationData(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
// 温度, 电压、电流、功率、功率因数、
|
||||
std::string stationId = req.get_param_value("station_id");
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
njson jsondata;
|
||||
jsondata["voltage"] = Utils::toStr(200.32);
|
||||
jsondata["current"] = Utils::toStr(20.56);
|
||||
jsondata["power"] = Utils::toStr(200.32);
|
||||
jsondata["powerFactor"] = Utils::toStr(1);
|
||||
jsondata["envTemp"] = Utils::toStr(200.32);
|
||||
jsondata["envhum"] = Utils::toStr(200.32);
|
||||
jsondata["aircStatus"] = Utils::toStr(1);
|
||||
jsondata["coolingStatus"] = Utils::toStr(0);
|
||||
if (station)
|
||||
{
|
||||
// 温度, 电压、电流、功率、功率因数、
|
||||
jsondata["voltage"] = station->voltage;
|
||||
jsondata["current"] = station->current;
|
||||
jsondata["power"] = station->power;
|
||||
jsondata["powerFactor"] = station->powerFactor;
|
||||
jsondata["envTemp"] = station->temperature;
|
||||
jsondata["envhum"] = station->humidity;
|
||||
jsondata["aircStatus"] = station->aircStatus;
|
||||
jsondata["coolingStatus"] = station->coolingStatus;
|
||||
}
|
||||
|
||||
json["data"] = jsondata;
|
||||
return Errcode::OK;
|
||||
@@ -1106,9 +1131,9 @@ static std::string VerifyStatSqlCondition(Fields& params)
|
||||
return sqlCondition;
|
||||
}
|
||||
|
||||
static std::string GetRequestStatParams(const httplib::Request& req)
|
||||
static std::string GetRequestStatParams(const httplib::Request& req, Fields& params)
|
||||
{
|
||||
Fields params;
|
||||
|
||||
GetRequestParam(req, {"station_id", "category", "start_date", "end_date"}, params);
|
||||
VerifyRequstParamsStatDate(params);
|
||||
return VerifyStatSqlCondition(params);
|
||||
@@ -1116,7 +1141,8 @@ static std::string GetRequestStatParams(const httplib::Request& req)
|
||||
|
||||
Errcode HttpEntity::queryStatTotal(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
std::string sqlCondition = GetRequestStatParams(req);
|
||||
Fields params;
|
||||
std::string sqlCondition = GetRequestStatParams(req, params);
|
||||
std::string sql = R"(SELECT SUM(ss.storage_elect_in) storage_elect_in,
|
||||
SUM(storage_elect_in) storage_elect_in,
|
||||
SUM(storage_elect_out) storage_elect_out,
|
||||
@@ -1135,12 +1161,22 @@ Errcode HttpEntity::queryStatTotal(const httplib::Request& req, njson& json, std
|
||||
SUM(income_charge) income_charge
|
||||
FROM stat_station ss)" + sqlCondition + ";";
|
||||
|
||||
std::string stationId = params.value("station_id");
|
||||
|
||||
njson jsondata;
|
||||
|
||||
auto station = Application::data().getStation(Utils::toInt(stationId));
|
||||
if (station)
|
||||
{
|
||||
jsondata["launch_date"] = station->launchDate;
|
||||
}
|
||||
|
||||
std::vector<Fields> result;
|
||||
DaoEntity::execOnce(sql, result);
|
||||
if (result.size() > 0)
|
||||
{
|
||||
auto& fields = result[0];
|
||||
njson jsondata;
|
||||
|
||||
// jsondata["launch_date"] = "2025-09-01"; //场站上线日期
|
||||
// jsondata["station_id"] = station_id;
|
||||
jsondata["storage_elect_in"] = fields.value("storage_elect_in"); //储能充电电量(kWh),精度:0.001
|
||||
@@ -1200,7 +1236,8 @@ Errcode HttpEntity::queryStatDetailList(const httplib::Request& req, njson& json
|
||||
|
||||
std::vector<Fields> result;
|
||||
auto err = DAO::queryStatStationList(pageinfo, params, result);
|
||||
json["data"] = FieldsToJsonArray(result);
|
||||
//json["data"] = FieldsToJsonArray(result);
|
||||
HttpHelper::setPagination(pageinfo, result, json);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1286,40 +1323,38 @@ Errcode HttpEntity::queryEnvironment(const httplib::Request& req, njson& json, s
|
||||
auto& unit = iter->second;
|
||||
njson node;
|
||||
node["pos"] = "#" + std::to_string(iter->first);
|
||||
node["temp"] = unit.temp;
|
||||
node["hum"] = unit.hum;
|
||||
node["temp"] = Utils::toStr(unit.temp);
|
||||
node["hum"] = Utils::toStr(unit.hum);
|
||||
nodearray.push_back(node);
|
||||
}
|
||||
jsondata["temp_hum"] = nodearray;
|
||||
}
|
||||
{ //空调
|
||||
auto& mapAircUnit = station->mapAircUnit;
|
||||
AircUnit unitTmp;
|
||||
AircUnit* unit = (mapAircUnit.size() > 0) ? &(mapAircUnit[0]) : &unitTmp;
|
||||
njson nodearray = njson::array();
|
||||
if (unit)
|
||||
for (auto& item: mapAircUnit)
|
||||
{
|
||||
nodearray.push_back({{"pos", "开关"}, {"status", unit->powerOn == 0 ? "关机" : "开机"}});
|
||||
nodearray.push_back({{"pos", "启动制冷指令"}, {"status", unit->cooling == 0 ? "启动" : "关闭"}});
|
||||
nodearray.push_back({{"pos", "启动送风指令"}, {"status", unit->airSupply == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "启动待机指令"}, {"status", unit->standby == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "启动加热指令"}, {"status", unit->heating == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "传感器故障"}, {"status", unit->sensorAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高低电压告警"}, {"status", unit->voltageAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高低温告警"}, {"status", unit->tempAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高低压告警"}, {"status", unit->pressureAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "压缩机告警"}, {"status", unit->compressorAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "当前温度"}, {"status", std::to_string(unit->temp) + "℃"}});
|
||||
nodearray.push_back({{"pos", "当前湿度"}, {"status", std::to_string(unit->hum) + "%"}});
|
||||
auto& unit = item.second;
|
||||
nodearray.push_back({{"pos", "开关"}, {"status", unit.powerOn == 0 ? "关机" : "开机"}});
|
||||
nodearray.push_back({{"pos", "启动制冷指令"}, {"status", unit.cooling == 0 ? "启动" : "关闭"}});
|
||||
nodearray.push_back({{"pos", "启动送风指令"}, {"status", unit.airSupply == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "启动待机指令"}, {"status", unit.standby == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "启动加热指令"}, {"status", unit.heating == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "传感器故障"}, {"status", unit.sensorAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高低电压告警"}, {"status", unit.voltageAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高低温告警"}, {"status", unit.tempAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高低压告警"}, {"status", unit.pressureAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "压缩机告警"}, {"status", unit.compressorAlarm == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "当前温度"}, {"status", std::to_string(unit.temp) + "℃"}});
|
||||
nodearray.push_back({{"pos", "当前湿度"}, {"status", std::to_string(unit.hum) + "%"}});
|
||||
break;
|
||||
}
|
||||
jsondata["airc"] = nodearray;
|
||||
}
|
||||
{ // 消防
|
||||
static std::map<int, std::string> mapFireStatusDef = { {0, "正常"}, {1,"预警"}, {2,"火警"} };
|
||||
|
||||
|
||||
std::map<int, string> mapStatusDef = {{0, "无效"}, {1, "掉线"}, {2, "正常"}, {3, "启动"}};
|
||||
|
||||
auto& mapFire40Unit = station->mapFire40Unit;
|
||||
njson nodearray = njson::array();
|
||||
for (auto iter = mapFire40Unit.begin(); iter!=mapFire40Unit.end(); ++iter)
|
||||
@@ -1338,20 +1373,19 @@ Errcode HttpEntity::queryEnvironment(const httplib::Request& req, njson& json, s
|
||||
}
|
||||
{ // 冷机
|
||||
auto& mapCoolingUnit = station->mapCoolingUnit;
|
||||
CoolingUnit unitTmp;
|
||||
CoolingUnit* unit = (mapCoolingUnit.size() > 0) ? &(mapCoolingUnit[0]) : &unitTmp;
|
||||
njson nodearray = njson::array();
|
||||
if (unit)
|
||||
for (auto& item: mapCoolingUnit)
|
||||
{
|
||||
auto& unit = item.second;
|
||||
njson node;
|
||||
nodearray.push_back({{"pos", "开关"}, {"status", unit->powerOn == 0 ? "关机" : "开机"}});
|
||||
nodearray.push_back({{"pos", "采样模式"}, {"status", unit->mode == 0 ? "出水温度" : "电芯温度"}});
|
||||
nodearray.push_back({{"pos", "制冷状态"}, {"status", unit->cooling == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "制热状态"}, {"status", unit->heating == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "高温告警"}, {"status", unit->highTemp == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "低温告警"}, {"status", unit->lowTemp == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高压告警"}, {"status", unit->highPressure == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "低压告警"}, {"status", unit->lowPressure == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "开关"}, {"status", unit.powerOn == 0 ? "关机" : "开机"}});
|
||||
nodearray.push_back({{"pos", "采样模式"}, {"status", unit.mode == 0 ? "出水温度" : "电芯温度"}});
|
||||
nodearray.push_back({{"pos", "制冷状态"}, {"status", unit.cooling == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "制热状态"}, {"status", unit.heating == 0 ? "关闭" : "启动"}});
|
||||
nodearray.push_back({{"pos", "高温告警"}, {"status", unit.highTemp == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "低温告警"}, {"status", unit.lowTemp == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "高压告警"}, {"status", unit.highPressure == 0 ? "正常" : "告警"}});
|
||||
nodearray.push_back({{"pos", "低压告警"}, {"status", unit.lowPressure == 0 ? "正常" : "告警"}});
|
||||
}
|
||||
jsondata["cooling"] = nodearray;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user