mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
149 lines
3.1 KiB
C++
149 lines
3.1 KiB
C++
#ifndef _DataFields_H_
|
||
#define _DataFields_H_
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <map>
|
||
#include <unordered_map>
|
||
#include <functional>
|
||
using namespace std;
|
||
|
||
struct PageInfo
|
||
{
|
||
int total = 0;
|
||
int page_id = 1;
|
||
int page_size = 10;
|
||
int page_max = 0;
|
||
};
|
||
|
||
class DataFields
|
||
{
|
||
public:
|
||
/**
|
||
* 设置索引名称和值
|
||
* @param: [string key] 索引名称
|
||
* @param: [string val] 值
|
||
*/
|
||
void set(string key, string val);
|
||
|
||
/**
|
||
* 设置索引名称和值
|
||
* @param: [string key] 索引名称
|
||
* @param: [float val] 值
|
||
*/
|
||
void set(string key, float val);
|
||
|
||
/**
|
||
* 设置索引名称和值
|
||
* @param: [string key] 索引名称
|
||
* @param: [int val] 值
|
||
*/
|
||
void set(string key, int val);
|
||
|
||
/**
|
||
* 设置索引名称和值
|
||
* @param: [string key] 索引名称
|
||
* @param: [int64_t val] 值
|
||
*/
|
||
void set(string key, int64_t val);
|
||
|
||
/**
|
||
* 获取 string 值
|
||
* @param: [string key] 索引名称
|
||
*/
|
||
string get_str(string key);
|
||
|
||
/**
|
||
* 获取 int 值
|
||
* @param: [string key] 索引名称
|
||
*/
|
||
int get_int(string key);
|
||
|
||
/**
|
||
* 获取 float 值
|
||
* @param: [string key] 索引名称
|
||
*/
|
||
float get_float(string key);
|
||
|
||
/**
|
||
* 删除指定索引的值
|
||
* @param: [string key] 索引名称
|
||
*/
|
||
void remove(string key);
|
||
|
||
/**
|
||
* 追加合并
|
||
* @param: [DataFields& fields] 要合并的数据
|
||
*/
|
||
void append(DataFields& fields);
|
||
|
||
/**
|
||
* 获取数据项map
|
||
*/
|
||
map<string, string>& fields();
|
||
|
||
/**
|
||
* 检查某一数据项的值进行替换,如果该项的值是val,则替换成成d
|
||
* @param: [string key] 索引名称
|
||
* @param: [string val] 要检查的值
|
||
* @param: [string d] 替换的值
|
||
*/
|
||
void check(string key, string val, string d);
|
||
|
||
/**
|
||
* 转换成插入数据的 sql 语句
|
||
* @param: [string tbname] 数据表名称
|
||
*/
|
||
string get_insert_sql(string tbname);
|
||
|
||
/**
|
||
* 转换成更新数据的 sql 语句
|
||
* @param: [string tbname] 数据表名称
|
||
* @param: [string sql_c] sql的更新条件,例如: where id='1'
|
||
*/
|
||
string get_update_sql(string tbname, string sql_c);
|
||
|
||
|
||
/**
|
||
* 转换成更新数据的 sql 语句
|
||
* @param: [string tbname] 数据表名称
|
||
* @param: [string vec_keys] 需要更新的字段名称
|
||
* @param: [string sql_c] sql的更新条件,例如: where id='1'
|
||
*/
|
||
string get_update_sql(string tbname, std::vector<std::string> vec_keys, string sql_c);
|
||
|
||
/**
|
||
* 遍历数据项
|
||
* @param: [function... on_foraach] 回调函数
|
||
*/
|
||
void foreach_item(function<void(string key, string val)> on_foraach);
|
||
|
||
/**
|
||
* 判断是否含有数据项
|
||
* @param: [string key] 索引名称
|
||
*/
|
||
bool is_empty(string key);
|
||
|
||
/**
|
||
* 判断数据项是否是float数值类型
|
||
* @param: [string key] 索引名称
|
||
*/
|
||
bool is_float_number(string key);
|
||
|
||
/**
|
||
* 转换成键值对的字符串格式
|
||
*/
|
||
string to_str();
|
||
|
||
/**
|
||
* 获取数据项的大小
|
||
*/
|
||
int size();
|
||
|
||
void clear();
|
||
|
||
private:
|
||
map<string, string> map_fields_;
|
||
};
|
||
|
||
#endif |