实现MQTT功能, 修改HTTP接口

This commit is contained in:
lixiaoyuan
2025-09-04 19:31:04 +08:00
parent 61ed4f355f
commit d81bcd9983
30 changed files with 2029 additions and 697 deletions

View File

@@ -88,7 +88,7 @@ static Errcode QueryCount(DaoEntity& dao, std::string sqlFrom, int& count)
{
std::vector<Fields> result;
int ret = dao.exec("SELECT COUNT(*) count " + sqlFrom, result);
if (ret != 0)
if (ret == 0)
{
count = (result.size() > 0) ? result[0].get<int>("count") : 0;
}
@@ -110,8 +110,9 @@ static Errcode QueryPagination(std::string sqlFields, std::string sqlCondition,
return err;
}
if (page.index < 1) page.index = 1;
page.total = count;
std::string sql = "SELECT " + sqlFields + " " + sqlCondition + DAO::sqlPageLimit(page.index, page.size);
std::string sql = "SELECT " + sqlFields + " " + sqlCondition + DAO::sqlPageLimit(page.index -1, page.size);
int ret = dao.exec(sql, result);
return Errcode(ret);
}
@@ -555,4 +556,11 @@ Errcode DAO::queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>&
{
std::string sql = "SELECT * FROM " + DMDefPolicyType::TABLENAME + ";";
return DAO::exec(dao, sql, result);
}
Errcode DAO::insertRuntimeData(std::shared_ptr<DaoEntity> dao, Fields& fields)
{
if (!dao) { dao = DaoEntity::create("history1"); }
int ret = dao->duplicateUpdate(fields, {"value"});
return Errcode(ret);
}

View File

@@ -117,4 +117,6 @@ public:
static Errcode queryWorkModeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
static Errcode queryPolicyTypeDef(std::shared_ptr<DaoEntity> dao, vector<Fields>& result);
static Errcode insertRuntimeData(std::shared_ptr<DaoEntity> dao, Fields& fields);
};

View File

@@ -89,8 +89,10 @@ namespace DMStation
const string TEL = "tel";
const string CAPACITY = "capacity";
const string STATUS = "status";
const string WORK_MODE_ID = "work_mode_id";
const string WORK_MODE = "work_mode";
const string POLICY_ID = "policy_id";
const string CODE = "code";
const string ATTR = "attr";
}
namespace DMDefDeviceType
@@ -178,4 +180,14 @@ namespace DMStatStation
const string CHARGE_ELECT = "charge_elect";
const string CHARGE_NUM = "charge_num";
const string CHARGE_NUM_ERR = "charge_num_err";
}
}
namespace DMHistory1
{
const string TABLENAME = "history1";
const string DT = "dt";
const string STATION_ID = "station_id";
const string DEVICE_ID = "device_id";
const string DATATYPE = "datatype";
const string VALUE = "value";
}