mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现系统管理表格操作接口、分页操作
This commit is contained in:
160
src/common/Fields.h
Normal file
160
src/common/Fields.h
Normal file
@@ -0,0 +1,160 @@
|
||||
#ifndef _Fields_H_
|
||||
#define _Fields_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
using namespace std;
|
||||
|
||||
struct PageInfo
|
||||
{
|
||||
int total {0};
|
||||
int index {0};
|
||||
int size {10};
|
||||
};
|
||||
|
||||
class Fields
|
||||
{
|
||||
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);
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
std::string& value(std::string key);
|
||||
|
||||
/**
|
||||
* 获取 int 值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
int getInt(string key);
|
||||
|
||||
/**
|
||||
* 获取 float 值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
float getFloat(string key);
|
||||
|
||||
/**
|
||||
* 获取 double 值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
double getDouble(string key);
|
||||
|
||||
/**
|
||||
* 删除指定索引的值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
std::map<string, string>::iterator remove(string key);
|
||||
|
||||
/**
|
||||
* 追加合并
|
||||
* @param: [DataFields& fields] 要合并的数据
|
||||
*/
|
||||
void append(Fields& 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 tableName] 数据表名称
|
||||
*/
|
||||
string get_insert_sql(string tableName);
|
||||
|
||||
/**
|
||||
* 转换成更新数据的 sql 语句
|
||||
* @param: [string tableName] 数据表名称
|
||||
* @param: [string condition] sql的更新条件,例如: where id='1'
|
||||
*/
|
||||
string get_update_sql(string tableName, string condition);
|
||||
|
||||
|
||||
/**
|
||||
* 转换成更新数据的 sql 语句
|
||||
* @param: [string tableName] 数据表名称
|
||||
* @param: [string vecKeys] 需要更新的字段名称
|
||||
* @param: [string condition] sql的更新条件,例如: where id='1'
|
||||
*/
|
||||
string get_update_sql(string tableName, std::vector<std::string> vecKeys, string condition);
|
||||
|
||||
/**
|
||||
* 遍历数据项
|
||||
* @param: [function... onForaach] 回调函数
|
||||
*/
|
||||
void foreachItem(function<void(string key, string& val)> onForaach);
|
||||
|
||||
/**
|
||||
* 判断是否含有数据项
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
bool isEmpty(string key);
|
||||
|
||||
/**
|
||||
* 判断数据项是否是float数值类型
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
bool is_float_number(string key);
|
||||
|
||||
/**
|
||||
* 转换成键值对的字符串格式
|
||||
*/
|
||||
string toStr();
|
||||
|
||||
/**
|
||||
* 获取数据项的大小
|
||||
*/
|
||||
int size();
|
||||
|
||||
void clear();
|
||||
|
||||
bool hasKey(std::string key);
|
||||
|
||||
|
||||
|
||||
std::map<string, string>& map() { return mapFields; }
|
||||
|
||||
private:
|
||||
std::map<string, string> mapFields;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user