mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
修改MQTT通讯数据解析问题
This commit is contained in:
@@ -524,13 +524,14 @@ Errcode DAO::insertSystemLogUser(std::string token, std::string content, int sta
|
||||
fields.set("user_account", user.account);
|
||||
return DAO::insertSystemLog(fields);
|
||||
}
|
||||
Errcode DAO::insertSystemLogDevice(std::string deviceId, std::string content, int status)
|
||||
Errcode DAO::insertSystemLogDevice(int stationId, int deviceId, std::string content, int status)
|
||||
{
|
||||
Fields fields;
|
||||
fields.set("station_id", stationId);
|
||||
fields.set("device_id", deviceId);
|
||||
fields.set("type", 3);
|
||||
fields.set("content", content);
|
||||
fields.set("status", status);
|
||||
fields.set("device_id", deviceId);
|
||||
return DAO::insertSystemLog(fields);
|
||||
}
|
||||
|
||||
@@ -576,7 +577,6 @@ Errcode DAO::queryStatStationGroup(std::shared_ptr<DaoEntity> dao, string statio
|
||||
if (!sqlCondition.empty()) { sqlCondition = " WHERE " + sqlCondition; }
|
||||
|
||||
std::string sql = R"(SELECT dt,
|
||||
SUM(ss.storage_elect_in) storage_elect_in,
|
||||
SUM(storage_elect_in) storage_elect_in,
|
||||
SUM(storage_elect_out) storage_elect_out,
|
||||
SUM(storage_num_in) storage_num_in,
|
||||
@@ -592,7 +592,7 @@ Errcode DAO::queryStatStationGroup(std::shared_ptr<DaoEntity> dao, string statio
|
||||
AVG(charge_usage) charge_usage,
|
||||
SUM(income_elect) income_elect,
|
||||
SUM(income_charge) income_charge
|
||||
FROM stat_station ss)" + sqlCondition + "GROUP by dt;";
|
||||
FROM stat_day)" + sqlCondition + " GROUP by dt;";
|
||||
return DAO::exec(dao, sql, result);
|
||||
}
|
||||
|
||||
@@ -621,7 +621,7 @@ Errcode DAO::queryStatStationList(PageInfo& pageInfo, Fields& params, vector<Fie
|
||||
if (!sqlCondition.empty()) { sqlCondition = " WHERE " + sqlCondition; }
|
||||
|
||||
std::string sqlFields = "ss.*, d.name device_name, ddt.name device_type";
|
||||
std::string sqlFrom = R"(FROM stat_station ss
|
||||
std::string sqlFrom = R"(FROM stat_day ss
|
||||
LEFT JOIN device d ON d.device_id = ss.device_id
|
||||
LEFT JOIN def_device_type ddt ON ddt.device_type_id = d.`type`)" + sqlCondition;
|
||||
|
||||
@@ -643,7 +643,8 @@ Errcode DAO::queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>&
|
||||
Errcode DAO::insertStatStation(std::shared_ptr<DaoEntity> dao, Fields& fields)
|
||||
{
|
||||
// 根据主键(dt、station_id、category),写入或更新数据
|
||||
if (!dao) { dao = DaoEntity::create("stat_station"); }
|
||||
if (!dao) { dao = DaoEntity::create("stat_day"); }
|
||||
else { dao->setTableName("stat_day"); }
|
||||
std::vector<std::string> vecKeys = {
|
||||
"storage_elect_in",
|
||||
"storage_elect_out",
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
|
||||
static Errcode insertSystemLogSys(std::string content, int status);
|
||||
static Errcode insertSystemLogUser(std::string token, std::string content, int status);
|
||||
static Errcode insertSystemLogDevice(std::string deviceId, std::string content, int status);
|
||||
static Errcode insertSystemLogDevice(int stationId, int deviceId, std::string content, int status);
|
||||
|
||||
static Errcode queryAlertLogList(PageInfo& pageInfo, vector<Fields>& result);
|
||||
static Errcode insertAlertLog(Fields& params);
|
||||
|
||||
@@ -44,13 +44,13 @@ std::shared_ptr<DaoEntity> DaoEntity::create(string tb_name)
|
||||
return std::make_shared<DaoEntity>(tb_name);
|
||||
}
|
||||
|
||||
bool DaoEntity::execOnce(string sql)
|
||||
int DaoEntity::execOnce(string sql)
|
||||
{
|
||||
auto db = make_shared<MysqlClient>(DaoEntity::option);
|
||||
return db->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::execOnce(string sql, vector<Fields>& result)
|
||||
int DaoEntity::execOnce(string sql, vector<Fields>& result)
|
||||
{
|
||||
auto db = make_shared<MysqlClient>(DaoEntity::option);
|
||||
return db->exec(sql, result);
|
||||
@@ -129,21 +129,18 @@ int DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
|
||||
string val;
|
||||
for (auto& item : fields.map())
|
||||
{
|
||||
if (!key.empty())
|
||||
{
|
||||
key += ","; val += ",";
|
||||
}
|
||||
if (!key.empty()) { key += ","; val += ","; }
|
||||
key += (item.first);
|
||||
val += ("'" + item.second + "'");
|
||||
}
|
||||
string str;
|
||||
for (auto& k : keys)
|
||||
{
|
||||
if (!str.empty())
|
||||
if (fields.contains(k))
|
||||
{
|
||||
str += ",";
|
||||
if (!str.empty()) { str += ","; }
|
||||
str += (k + "='" + fields.value(k) + "'");
|
||||
}
|
||||
str += (k + "='" + fields.value(k) + "'");
|
||||
}
|
||||
string sql = "INSERT INTO " + tableName + "(" + key + ") VALUES (" + val + ") ON duplicate KEY UPDATE " + str;
|
||||
return this->db->exec(sql);
|
||||
|
||||
@@ -18,14 +18,14 @@ public:
|
||||
* 执行sql语句
|
||||
* @param: sql 要执行的完整 sql 语句
|
||||
*/
|
||||
static bool execOnce(string sql);
|
||||
static int execOnce(string sql);
|
||||
|
||||
/**
|
||||
* 执行sql语句,返回结果数据集
|
||||
* @param: sql 要执行的完整 sql 语句
|
||||
* @param: result 返回的结果数据集
|
||||
*/
|
||||
static bool execOnce(string sql, vector<Fields>& result);
|
||||
static int execOnce(string sql, vector<Fields>& result);
|
||||
|
||||
/**
|
||||
* 设置数据库表名称
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace DMLogAlert
|
||||
|
||||
namespace DMStatStation
|
||||
{
|
||||
const string TABLENAME = "stat_station";
|
||||
const string TABLENAME = "stat_day";
|
||||
const string DT = "dt";
|
||||
const string STATION_ID = "station_id";
|
||||
const string STORAGE_ELECT_IN = "storage_elect_in";
|
||||
|
||||
Reference in New Issue
Block a user