From 3e36135f110f31d23bd54a1095be054d38f1631d Mon Sep 17 00:00:00 2001 From: lixiaoyuan Date: Tue, 17 Mar 2026 15:21:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AD=96=E7=95=A5=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/protocol/HttpEntity.cpp | 48 +++++ src/protocol/HttpEntity.h | 3 + web/src/components/system/policyForm.vue | 231 ++++++++++++++--------- web/src/views/system/policy.vue | 41 +++- 4 files changed, 222 insertions(+), 101 deletions(-) diff --git a/src/protocol/HttpEntity.cpp b/src/protocol/HttpEntity.cpp index 116d8c9..5410e82 100644 --- a/src/protocol/HttpEntity.cpp +++ b/src/protocol/HttpEntity.cpp @@ -686,6 +686,7 @@ Errcode HttpEntity::updateStation(const httplib::Request& req, njson& json, std: } } } + // 发送指令到网关 if (params.contains("station_id") && params.contains("work_mode")) { int stationId = params.get("station_id"); @@ -694,6 +695,53 @@ Errcode HttpEntity::updateStation(const httplib::Request& req, njson& json, std: if (station) { station->setGarewayWorkMode(); + // 根据 work_mode 到数据库查询策略信息 + std::string sql = std::format("select * from policy where `type`='{}'", workmode); + std::vector result; + int ret = DaoEntity::execOnce(sql, result); + if (result.size() > 0) + { + auto& item = result[0]; + std::string valJson = item.value("value"); + + njson json = njson::parse(valJson); + if (json.is_object()) + { + // 设置 station 的网关参数,然后调用 setGarewayParams 向网关发送指令 + if (workmode == 6) + { + if (json.contains("soc_min")) { station->gatewayParam.socMin = Utils::toFloat(json["soc_min"])*100; } + if (json.contains("soc_max")) { station->gatewayParam.socMax = Utils::toFloat(json["soc_max"])*100; } + } + else if (workmode == 7) + { + //if (json.contains("charge")) { station->gatewayParam.powerCharge = json["charge"].get(); } + //if (json.contains("discharge")) { station->gatewayParam.powerDischarge = json["discharge"].get(); } + } + else if (workmode == 8) + { + if (json.contains("charge")) { station->gatewayParam.powerCharge = Utils::toInt(json["charge"]); } + if (json.contains("discharge")) { station->gatewayParam.powerDischarge = Utils::toInt(json["discharge"]); } + if (json.contains("power_reverse")) { station->gatewayParam.backflow = Utils::toInt(json["power_reverse"]); } + } + else if (workmode == 9) + { + if (json.contains("charge")) { station->gatewayParam.powerCharge = Utils::toInt(json["charge"]); } + if (json.contains("discharge")) { station->gatewayParam.powerDischarge = Utils::toInt(json["discharge"]); } + } + } + //station->setGarewayParams(); + } + + ////params.get("work_mode", station->workMode); + //ps.get("soc_min", station->gatewayParam.socMin); // 储能放电下限值 SOC 40038 (%, 0-99) + //ps.get("soc_max", station->gatewayParam.socMax); // 储能充电上限值 SOC 40039 (%:1-100) + //ps.get("capacity", station->gatewayParam.capacity); // 台区变压器容量 40040 (KVA 160-1600) + //ps.get("power_safe", station->gatewayParam.powerSafe); // 安全输入功率 40041 (KW 0-400) + //ps.get("power_discharge", station->gatewayParam.powerDischarge); // 储能最大放电功率 40042 (1KW 0-150) + //ps.get("power_charge", station->gatewayParam.powerCharge); // 储能最大充电功率 40043 (1KW 0-150) + //ps.get("backflow", station->gatewayParam.backflow); // 防逆流回差 40058(1KW 10-300) + //ps.get("overload", station->gatewayParam.overload); // 防过载回差 40059(1KW 10-300) } } return err; diff --git a/src/protocol/HttpEntity.h b/src/protocol/HttpEntity.h index 0e1dce7..f98c279 100644 --- a/src/protocol/HttpEntity.h +++ b/src/protocol/HttpEntity.h @@ -51,6 +51,8 @@ public: Errcode queryStationList(const httplib::Request& req, njson& json, std::string& errmsg); Errcode insertStation(const httplib::Request& req, njson& json, std::string& errmsg); + + // 参数中有work_mode时,发送指令到网关 Errcode updateStation(const httplib::Request& req, njson& json, std::string& errmsg); Errcode deleteStation(const httplib::Request& req, njson& json, std::string& errmsg); @@ -125,6 +127,7 @@ public: Errcode updateServiceApi(const httplib::Request& req, njson& json, std::string& errmsg); Errcode deleteServiceApi(const httplib::Request& req, njson& json, std::string& errmsg); + // 更新网关参数 Errcode updateGatewayParams(const httplib::Request& req, njson& json, std::string& errmsg); /// =========================================================================================== diff --git a/web/src/components/system/policyForm.vue b/web/src/components/system/policyForm.vue index 1cbb54e..ea253a2 100644 --- a/web/src/components/system/policyForm.vue +++ b/web/src/components/system/policyForm.vue @@ -12,10 +12,11 @@ :rules="rules" ref="formRef" > - - + + - + + + + + + + + + + + + + - - - + + - - - - - - - - - - - -