#ifndef _DaoDevice_H_
#define _DaoDevice_H_

#include "DataFields.h"

namespace DMDevice
{
    const string TABLENAME = "device";
    const string ID = "id";
    const string NAME = "name";
    const string CODE = "code";
    const string MODEL = "model";
    const string TYPE = "type";
    const string FACTORY = "factory";
    const string TEL = "factory_tel";
    const string PRODUCT_DATE = "product_time";
    const string IS_OPEN = "is_open";
    const string OPEN_TIME = "open_time";
    const string COMM_TYPE = "comm_type";
    const string COMM_PROTOCOL = "comm_protocol";
    const string COMM_IP = "comm_ip";
    const string COMM_PORT = "comm_port";
    const string STATUS = "status";
    const string CREATE_TIME = "create_time";
    const string UPDATE_TIME = "update_time";
}

namespace DMDeviceAttr
{
    const string TABLENAME = "device_attr";
    const string DEVICE_ID = "device_id";
    const string ATTR_ID = "attr_id";
    const string ATTR_VAL = "attr_val";
    // 属性ID的关键字
    // 充电机属性
    const string K_STORAGE_ID = "storage_id";
    const string K_MODEL = "model";
    const string K_MANUFACTOR = "manufactor";
    const string K_RATED_POWER = "rated_power";
    const string K_VOLTAGE_MIN = "voltage_min";
    const string K_VOLTAGE_MAX = "voltage_max";
    const string K_CURRENT_MAX = "current_max";
    // 存储架属性：仓位电池型号和存储的电池编号
    const string K_BATT_MODEL = "battery_model";
    const string K_BATT_CODE = "battery_code";
    // 电表属性：
    const string K_LINK_DEVICE = "link_device";
}

namespace DMDeviceDataRecord
{
    const string TABLENAME = "device_data_record";
    const string DEVICE_ID = "device_id";	// 设备ID
    const string COLLECT_TIME = "collect_time"; // 采集时间
    const string VOLTAGE = "voltage";	// 电压
    const string CURRENT = "current";	// 电流
    const string POWER = "power";		// 功率
    const string POWER_Q = "power_q";	// 无功功率
    const string POWER_S = "power_s";	// 视在功率
    const string FACTOR = "factor";		// 功率因数
}

class DaoDevice
{
public:

    /**
    * 新增设备信息, DataFields 的 key 见【namespace DaoDevice】中的定义
    */
    static void insert_device(DataFields& fields);

    /**
    * 查询设备信息，结果集字段见【namespace DaoDevice】中的定义
    * @param: sql_c 查询条件： 例："where id='1'"
    * @param: result 查询的结果数据集
    */
    static void query_device(string sql_c, vector<DataFields>& result);
    static void query_device_attr(string sql_c, vector<DataFields>& result);

    /**
    * 分页查询设备信息
    * @param: pageinfo 分页信息
    * @param: result 查询的结果数据集
    */
    static void query_device_page(PageInfo& pageinfo, vector<DataFields>& result);

    /**
    * 更新设备信息
    * @param: fields 更新的字段信息,其中 DaoDevice::FID_ID 作为更新条件
    */
    static int update_device(DataFields& fields);

    // ************************************************************************************************
    // 设备属性管理
    static void update_device_attr(vector<DataFields> vec_d);
    static void query_attr(int device_id, vector<DataFields>& result);

private:
};

#endif // !!!_DaoDevice_H_
