mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
上传项目代码
This commit is contained in:
48
src/database/dao/DaoCharge.cpp
Normal file
48
src/database/dao/DaoCharge.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "DaoCharge.h"
|
||||
|
||||
#include "app/Global.h"
|
||||
#include "common/spdlogger.h"
|
||||
#include "common/TimeUtils.h"
|
||||
#include "common/Snowflake.h"
|
||||
#include "database/DaoEntity.h"
|
||||
#include "database/dao/DaoDevice.h"
|
||||
#include "Device.h"
|
||||
|
||||
bool DaoCharge::create_charge_record(std::string biz_id, int device_id)
|
||||
{
|
||||
DataFields fields;
|
||||
fields.set(DMChargeRecord::ID, biz_id);
|
||||
fields.set(DMChargeRecord::DEVICE_ID, device_id);
|
||||
DaoEntity dao(DMChargeRecord::TABLENAME);
|
||||
return dao.insert_fields(fields);
|
||||
}
|
||||
|
||||
bool DaoCharge::update_charge_record(std::string biz_id, int device_id, DataFields fields)
|
||||
{
|
||||
DaoEntity dao(DMChargeRecord::TABLENAME);
|
||||
std::vector<DataFields> result;
|
||||
dao.exec("select * from " + DMChargeRecord::TABLENAME + " WHERE id='" + biz_id + "';", result);
|
||||
if (result.size() == 0)
|
||||
{
|
||||
fields.set(DMChargeRecord::ID, biz_id);
|
||||
fields.set(DMChargeRecord::DEVICE_ID, device_id);
|
||||
dao.insert_fields(fields);
|
||||
}
|
||||
fields.remove(DMChargeRecord::ID);
|
||||
fields.remove(DMChargeRecord::DEVICE_ID);
|
||||
return dao.update_fields(fields, "where " + DMChargeRecord::ID + "='" + biz_id + "'");
|
||||
}
|
||||
|
||||
void DaoCharge::query_charger(vector<DataFields>& result)
|
||||
{
|
||||
DaoEntity dao(DMDevice::TABLENAME);
|
||||
string sql = " where device.type='智能充电设备';";
|
||||
dao.query_fields("*", sql, result);
|
||||
}
|
||||
|
||||
void DaoCharge::query_charger_attr(vector<DataFields>& result)
|
||||
{
|
||||
DaoEntity dao(DMDevice::TABLENAME);
|
||||
string sql = " left join device_attr on device.id =device_attr.device_id where device.type='智能充电设备';";
|
||||
dao.query_fields("*", sql, result);
|
||||
}
|
||||
Reference in New Issue
Block a user