mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
完成系统管理web端功能,实现系统管理服务端接口,实现登录功能
This commit is contained in:
@@ -3,45 +3,45 @@
|
||||
|
||||
void DataFields::set(string key, string val)
|
||||
{
|
||||
map_fields_[key] = val;
|
||||
mapFields_[key] = val;
|
||||
}
|
||||
void DataFields::set(string key, float val)
|
||||
{
|
||||
map_fields_[key] = std::to_string(val);
|
||||
mapFields_[key] = std::to_string(val);
|
||||
}
|
||||
void DataFields::set(string key, int val)
|
||||
{
|
||||
map_fields_[key] = std::to_string(val);
|
||||
mapFields_[key] = std::to_string(val);
|
||||
}
|
||||
void DataFields::set(string key, int64_t val)
|
||||
{
|
||||
map_fields_[key] = std::to_string(val);
|
||||
mapFields_[key] = std::to_string(val);
|
||||
}
|
||||
string DataFields::get_str(string key)
|
||||
string DataFields::getStr(string key)
|
||||
{
|
||||
if (map_fields_.count(key) > 0)
|
||||
if (mapFields_.count(key) > 0)
|
||||
{
|
||||
return map_fields_[key];
|
||||
return mapFields_[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
int DataFields::get_int(string key)
|
||||
int DataFields::getInt(string key)
|
||||
{
|
||||
return map_fields_.count(key) > 0 ? Utils::toInt(map_fields_[key]) : 0;
|
||||
return mapFields_.count(key) > 0 ? Utils::toInt(mapFields_[key]) : 0;
|
||||
}
|
||||
float DataFields::get_float(string key)
|
||||
float DataFields::getFloat(string key)
|
||||
{
|
||||
return map_fields_.count(key) > 0 ? Utils::toFloat(map_fields_[key]) : 0.0f;
|
||||
return mapFields_.count(key) > 0 ? Utils::toFloat(mapFields_[key]) : 0.0f;
|
||||
}
|
||||
void DataFields::remove(string key)
|
||||
{
|
||||
auto it = map_fields_.find(key);
|
||||
if (it != map_fields_.end())
|
||||
auto it = mapFields_.find(key);
|
||||
if (it != mapFields_.end())
|
||||
{
|
||||
map_fields_.erase(it);
|
||||
mapFields_.erase(it);
|
||||
}
|
||||
}
|
||||
void DataFields::append(DataFields& datafield)
|
||||
@@ -49,19 +49,19 @@ void DataFields::append(DataFields& datafield)
|
||||
auto& map_f = datafield.fields();
|
||||
for (auto it = map_f.begin(); it != map_f.end(); it++)
|
||||
{
|
||||
map_fields_[it->first] = it->second;
|
||||
mapFields_[it->first] = it->second;
|
||||
}
|
||||
}
|
||||
map<string, string>& DataFields::fields()
|
||||
{
|
||||
return map_fields_;
|
||||
return mapFields_;
|
||||
}
|
||||
|
||||
void DataFields::check(string key, string val, string d)
|
||||
{
|
||||
if (map_fields_.count(key) > 0 && map_fields_[key] == val)
|
||||
if (mapFields_.count(key) > 0 && mapFields_[key] == val)
|
||||
{
|
||||
map_fields_[key] = d;
|
||||
mapFields_[key] = d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ string DataFields::get_insert_sql(string tbname)
|
||||
{
|
||||
string key;
|
||||
string val;
|
||||
for (auto it = map_fields_.begin(); it != map_fields_.end(); it++)
|
||||
for (auto it = mapFields_.begin(); it != mapFields_.end(); it++)
|
||||
{
|
||||
if (!key.empty())
|
||||
{
|
||||
@@ -93,9 +93,9 @@ string DataFields::get_update_sql(string tbname, string sql_c)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "update " << tbname << " set ";
|
||||
for (auto iter = map_fields_.begin(); iter != map_fields_.end(); iter++)
|
||||
for (auto iter = mapFields_.begin(); iter != mapFields_.end(); iter++)
|
||||
{
|
||||
if (iter != map_fields_.begin())
|
||||
if (iter != mapFields_.begin())
|
||||
{
|
||||
oss << ",";
|
||||
};
|
||||
@@ -120,12 +120,12 @@ string DataFields::get_update_sql(string tbname, std::vector<std::string> vec_ke
|
||||
|
||||
ostringstream oss;
|
||||
oss << "update " << tbname << " set ";
|
||||
for (auto iter = map_fields_.begin(); iter != map_fields_.end(); iter++)
|
||||
for (auto iter = mapFields_.begin(); iter != mapFields_.end(); iter++)
|
||||
{
|
||||
auto& k = iter->first;
|
||||
auto& v = iter->second;
|
||||
if (!map_keys[k]) { continue; }
|
||||
if (iter != map_fields_.begin())
|
||||
if (iter != mapFields_.begin())
|
||||
{
|
||||
oss << ",";
|
||||
};
|
||||
@@ -145,7 +145,7 @@ string DataFields::get_update_sql(string tbname, std::vector<std::string> vec_ke
|
||||
|
||||
void DataFields::foreach_item(function<void(string key, string val)> on_foraach)
|
||||
{
|
||||
for (auto it = map_fields_.begin(); it != map_fields_.end(); it++)
|
||||
for (auto it = mapFields_.begin(); it != mapFields_.end(); it++)
|
||||
{
|
||||
if (on_foraach)
|
||||
{
|
||||
@@ -153,15 +153,15 @@ void DataFields::foreach_item(function<void(string key, string val)> on_foraach)
|
||||
}
|
||||
}
|
||||
}
|
||||
bool DataFields::is_empty(string key)
|
||||
bool DataFields::isEmpty(string key)
|
||||
{
|
||||
auto& s = map_fields_[key];
|
||||
auto& s = mapFields_[key];
|
||||
return s.empty();
|
||||
}
|
||||
|
||||
bool DataFields::is_float_number(string key)
|
||||
{
|
||||
auto& s = map_fields_[key];
|
||||
auto& s = mapFields_[key];
|
||||
if (s.empty())
|
||||
{
|
||||
return false;
|
||||
@@ -179,7 +179,7 @@ bool DataFields::is_float_number(string key)
|
||||
string DataFields::to_str()
|
||||
{
|
||||
string s;
|
||||
for (auto it = map_fields_.begin(); it != map_fields_.end(); it++)
|
||||
for (auto it = mapFields_.begin(); it != mapFields_.end(); it++)
|
||||
{
|
||||
s += ("[" + it->first + ":" + it->second + "] ");
|
||||
}
|
||||
@@ -188,10 +188,10 @@ string DataFields::to_str()
|
||||
|
||||
int DataFields::size()
|
||||
{
|
||||
return map_fields_.size();
|
||||
return mapFields_.size();
|
||||
}
|
||||
|
||||
void DataFields::clear()
|
||||
{
|
||||
map_fields_.clear();
|
||||
mapFields_.clear();
|
||||
}
|
||||
@@ -51,19 +51,19 @@ public:
|
||||
* 获取 string 值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
string get_str(string key);
|
||||
string getStr(string key);
|
||||
|
||||
/**
|
||||
* 获取 int 值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
int get_int(string key);
|
||||
int getInt(string key);
|
||||
|
||||
/**
|
||||
* 获取 float 值
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
float get_float(string key);
|
||||
float getFloat(string key);
|
||||
|
||||
/**
|
||||
* 删除指定索引的值
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
* 判断是否含有数据项
|
||||
* @param: [string key] 索引名称
|
||||
*/
|
||||
bool is_empty(string key);
|
||||
bool isEmpty(string key);
|
||||
|
||||
/**
|
||||
* 判断数据项是否是float数值类型
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
map<string, string> map_fields_;
|
||||
map<string, string> mapFields_;
|
||||
};
|
||||
|
||||
#endif
|
||||
67
src/common/JsonN.h
Normal file
67
src/common/JsonN.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
using NJson = nlohmann::json;
|
||||
|
||||
/// =============================================================================================
|
||||
/// 使用说明:
|
||||
|
||||
/// 创建 -------------
|
||||
// json j;
|
||||
// j["name"] = "Alice";
|
||||
// j["age"] = 25;
|
||||
// j["address"] = {{"city", "Beijing"}, {"country", "China"}};
|
||||
|
||||
/// 字符串解析 -------------
|
||||
// json::parse(R"({"name": "Alice", "age": 25})");
|
||||
// 说明:解析失败会抛出异常
|
||||
// try {
|
||||
// auto j = json::parse("invalid json");
|
||||
// }
|
||||
// catch (json::parse_error& e) {
|
||||
// std::cerr << "JSON 解析错误: " << e.what() << std::endl;
|
||||
// }
|
||||
|
||||
/// 文件解析 -------------
|
||||
// std::ifstream file("data.json");
|
||||
// json j;
|
||||
// file >> j;
|
||||
|
||||
/// 访问 JSON 数据 -------------
|
||||
// std::string name = j["name"]; // 直接访问
|
||||
// int age = j.at("age"); // 使用 at() 检查 key 是否存在
|
||||
// auto address = j["address"]; // 获取数组
|
||||
|
||||
/// 序列化为字符串 -------------
|
||||
// std::string json_str = j.dump(4); // 4 表示缩进,美化输出
|
||||
|
||||
static bool NJsonLoad(std::string jsonfile, NJson& json)
|
||||
{
|
||||
std::ifstream ifs(jsonfile);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
ifs >> json;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool NJsonParse(std::string jsonstr, NJson& json)
|
||||
{
|
||||
try
|
||||
{
|
||||
json = NJson::parse(jsonstr);
|
||||
}
|
||||
catch (nlohmann::json::parse_error& e)
|
||||
{
|
||||
//std::cerr << "JSON 解析错误: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool NJsonLHas(NJson& json, std::string key)
|
||||
{
|
||||
return json.contains("database");
|
||||
}
|
||||
@@ -6,222 +6,205 @@
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
// 如果不使用 mutex, 则开启下面这个定义, 但是我发现, 还是开启 mutex 功能, 速度比较快
|
||||
// #define SNOWFLAKE_ID_WORKER_NO_LOCK
|
||||
|
||||
|
||||
/**
|
||||
* @brief 分布式id生成类
|
||||
* https://segmentfault.com/a/1190000011282426
|
||||
* https://github.com/twitter/snowflake/blob/snowflake-2010/src/main/scala/com/twitter/service/snowflake/IdWorker.scala
|
||||
*
|
||||
* 64bit id: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
|
||||
* || || || | | |
|
||||
* |└---------------------------时间戳--------------------------┘└中心-┘└机器-┘ └----序列号----┘
|
||||
* |
|
||||
* 不用
|
||||
* SnowFlake的优点: 整体上按照时间自增排序, 并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分), 并且效率较高, 经测试, SnowFlake每秒能够产生26万ID左右.
|
||||
*/
|
||||
/**
|
||||
* @brief 分布式id生成类
|
||||
* https://segmentfault.com/a/1190000011282426
|
||||
* https://github.com/twitter/snowflake/blob/snowflake-2010/src/main/scala/com/twitter/service/snowflake/IdWorker.scala
|
||||
*
|
||||
* 64bit id: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
|
||||
* || || || | | |
|
||||
* |└---------------------------时间戳---------------------------┘└-中心-┘└机器-┘ └----序列号----┘
|
||||
* 不用
|
||||
* SnowFlake的优点: 整体上按照时间自增排序, 并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分), 并且效率较高, 经测试, SnowFlake每秒能够产生26万ID左右.
|
||||
*/
|
||||
class Snowflake
|
||||
{
|
||||
public:
|
||||
static Snowflake& instance()
|
||||
{
|
||||
static Snowflake sf;
|
||||
return sf;
|
||||
}
|
||||
|
||||
typedef unsigned int UInt;
|
||||
typedef unsigned long long int UInt64;
|
||||
//typedef unsigned int UInt;
|
||||
//typedef unsigned long long int UInt64;
|
||||
|
||||
#ifdef SNOWFLAKE_ID_WORKER_NO_LOCK
|
||||
typedef std::atomic<UInt> AtomicUInt;
|
||||
typedef std::atomic<UInt64> AtomicUInt64;
|
||||
typedef std::atomic<UInt> AtomicUInt;
|
||||
typedef std::atomic<uint64_t> AtomicUInt64;
|
||||
#else
|
||||
typedef UInt AtomicUInt;
|
||||
typedef UInt64 AtomicUInt64;
|
||||
typedef unsigned int AtomicUInt;
|
||||
typedef uint64_t AtomicUInt64;
|
||||
#endif
|
||||
|
||||
void set_worker_id(UInt workerId)
|
||||
{
|
||||
this->workerId = workerId;
|
||||
}
|
||||
static Snowflake& instance()
|
||||
{
|
||||
static Snowflake inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
void set_datacenter_id(UInt datacenterId)
|
||||
{
|
||||
this->datacenterId = datacenterId;
|
||||
}
|
||||
void setWorkerId(unsigned int workerId) {
|
||||
this->workerId_ = workerId;
|
||||
}
|
||||
|
||||
string nextIdStr()
|
||||
{
|
||||
return std::to_string(next_id());
|
||||
}
|
||||
void setDatacenterId(unsigned int datacenterId) {
|
||||
this->datacenterId_ = datacenterId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得下一个ID (该方法是线程安全的)
|
||||
*
|
||||
* @return SnowflakeId
|
||||
*/
|
||||
UInt64 next_id()
|
||||
{
|
||||
uint64_t getId() {
|
||||
return nextId();
|
||||
}
|
||||
|
||||
std::string getIdStr() {
|
||||
return std::to_string(nextId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得下一个ID (该方法是线程安全的)
|
||||
*
|
||||
* @return SnowflakeId
|
||||
*/
|
||||
uint64_t nextId() {
|
||||
#ifndef SNOWFLAKE_ID_WORKER_NO_LOCK
|
||||
std::unique_lock<std::mutex> lock {mutex};
|
||||
AtomicUInt64 timestamp {0};
|
||||
std::unique_lock<std::mutex> lock {mutex};
|
||||
AtomicUInt64 timestamp {0};
|
||||
#else
|
||||
static AtomicUInt64 timestamp {0};
|
||||
static AtomicUInt64 timestamp {0};
|
||||
#endif
|
||||
timestamp = time_now_ms();
|
||||
timestamp = timetick();
|
||||
|
||||
// 如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
|
||||
if (timestamp < lastTimestamp)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "clock moved backwards. Refusing to generate id for " << lastTimestamp - timestamp << " milliseconds";
|
||||
throw std::exception(std::runtime_error(s.str()));
|
||||
}
|
||||
// 如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
|
||||
if (timestamp < lastTimestamp_) {
|
||||
std::ostringstream s;
|
||||
s << "clock moved backwards. Refusing to generate id for " << lastTimestamp_ - timestamp << " milliseconds";
|
||||
throw std::exception(std::runtime_error(s.str()));
|
||||
}
|
||||
|
||||
if (lastTimestamp == timestamp)
|
||||
{
|
||||
// 如果是同一时间生成的,则进行毫秒内序列
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
if (0 == sequence)
|
||||
{
|
||||
// 毫秒内序列溢出, 阻塞到下一个毫秒,获得新的时间戳
|
||||
timestamp = next_millis(lastTimestamp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sequence = 0;
|
||||
}
|
||||
if (lastTimestamp_ == timestamp) {
|
||||
// 如果是同一时间生成的,则进行毫秒内序列
|
||||
sequence_ = (sequence_ + 1) & sequenceMask;
|
||||
if (0 == sequence_) {
|
||||
// 毫秒内序列溢出, 阻塞到下一个毫秒,获得新的时间戳
|
||||
timestamp = tilNextMillis(lastTimestamp_);
|
||||
}
|
||||
}
|
||||
else {
|
||||
sequence_ = 0;
|
||||
}
|
||||
|
||||
#ifndef SNOWFLAKE_ID_WORKER_NO_LOCK
|
||||
lastTimestamp = timestamp;
|
||||
lastTimestamp_ = timestamp;
|
||||
#else
|
||||
lastTimestamp = timestamp.load();
|
||||
lastTimestamp_ = timestamp.load();
|
||||
#endif
|
||||
|
||||
// 移位并通过或运算拼到一起组成64位的ID
|
||||
//return ((timestamp - twepoch) << timestampLeftShift)
|
||||
// | (datacenterId << datacenterIdShift)
|
||||
// | (workerId << workerIdShift)
|
||||
// | sequence;
|
||||
return ((timestamp - twepoch) << sequenceBits)
|
||||
//| (datacenterId << datacenterIdShift)
|
||||
//| (workerId << workerIdShift)
|
||||
| sequence;
|
||||
}
|
||||
// 移位并通过或运算拼到一起组成64位的ID
|
||||
return ((timestamp - twepoch_) << timestampLeftShift)
|
||||
| (datacenterId_ << datacenterIdShift)
|
||||
| (workerId_ << workerIdShift)
|
||||
| sequence_;
|
||||
}
|
||||
|
||||
protected:
|
||||
Snowflake() : workerId(0), datacenterId(0), sequence(0), lastTimestamp(0)
|
||||
{
|
||||
}
|
||||
Snowflake() : workerId_(0), datacenterId_(0), sequence_(0), lastTimestamp_(0) {}
|
||||
|
||||
/**
|
||||
* 返回以毫秒为单位的当前时间
|
||||
*
|
||||
* @return 当前时间(毫秒)
|
||||
*/
|
||||
UInt64 time_now_ms() const
|
||||
{
|
||||
//auto t = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now());
|
||||
auto t = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
|
||||
return t.time_since_epoch().count();
|
||||
}
|
||||
/**
|
||||
* 返回以毫秒为单位的当前时间
|
||||
*
|
||||
* @return 当前时间(毫秒)
|
||||
*/
|
||||
uint64_t timetick() const {
|
||||
//auto t = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now());
|
||||
auto t = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
|
||||
return t.time_since_epoch().count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻塞到下一个毫秒,直到获得新的时间戳
|
||||
*
|
||||
* @param lastTimestamp 上次生成ID的时间截
|
||||
* @return 当前时间戳
|
||||
*/
|
||||
UInt64 next_millis(UInt64 lastTimestamp) const
|
||||
{
|
||||
UInt64 timestamp = time_now_ms();
|
||||
while (timestamp <= lastTimestamp)
|
||||
{
|
||||
timestamp = time_now_ms();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
/**
|
||||
* 阻塞到下一个毫秒,直到获得新的时间戳
|
||||
*
|
||||
* @param lastTimestamp 上次生成ID的时间截
|
||||
* @return 当前时间戳
|
||||
*/
|
||||
uint64_t tilNextMillis(uint64_t lastTimestamp) const {
|
||||
uint64_t timestamp = timetick();
|
||||
while (timestamp <= lastTimestamp) {
|
||||
timestamp = timetick();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
#ifndef SNOWFLAKE_ID_WORKER_NO_LOCK
|
||||
std::mutex mutex;
|
||||
std::mutex mutex;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 开始时间截 (2010-01-01 00:00:00.000) 1262275200000
|
||||
*/
|
||||
const UInt64 twepoch = 1262275200000;
|
||||
/**
|
||||
* 开始时间截 2025-01-01 00:00:00.000
|
||||
*/
|
||||
const uint64_t twepoch_ = 1735660800000;
|
||||
|
||||
/**
|
||||
* 机器id所占的位数
|
||||
*/
|
||||
const UInt workerIdBits = 5;
|
||||
/**
|
||||
* 机器id所占的位数
|
||||
*/
|
||||
const unsigned int workerIdBits = 4;
|
||||
|
||||
/**
|
||||
* 数据中心id所占的位数
|
||||
*/
|
||||
const UInt datacenterIdBits = 5;
|
||||
/**
|
||||
* 数据中心id所占的位数
|
||||
*/
|
||||
const unsigned int datacenterIdBits = 1;
|
||||
|
||||
/**
|
||||
* 序列所占的位数
|
||||
*/
|
||||
const UInt sequenceBits = 12;
|
||||
/**
|
||||
* 序列所占的位数
|
||||
*/
|
||||
const unsigned int sequenceBits = 12;
|
||||
|
||||
/**
|
||||
* 机器ID向左移12位
|
||||
*/
|
||||
const UInt workerIdShift = sequenceBits;
|
||||
/**
|
||||
* 机器ID向左移12位
|
||||
*/
|
||||
const unsigned int workerIdShift = sequenceBits;
|
||||
|
||||
/**
|
||||
* 数据标识id向左移17位
|
||||
*/
|
||||
const UInt datacenterIdShift = workerIdShift + workerIdBits;
|
||||
/**
|
||||
* 数据标识id向左移16位
|
||||
*/
|
||||
const unsigned int datacenterIdShift = workerIdShift + workerIdBits;
|
||||
|
||||
/**
|
||||
* 时间截向左移22位
|
||||
*/
|
||||
const UInt timestampLeftShift = datacenterIdShift + datacenterIdBits;
|
||||
/**
|
||||
* 时间截向左移17位
|
||||
*/
|
||||
const unsigned int timestampLeftShift = datacenterIdShift + datacenterIdBits;
|
||||
|
||||
/**
|
||||
* 支持的最大机器id,结果是31
|
||||
*/
|
||||
const UInt maxWorkerId = -1 ^ (-1 << workerIdBits);
|
||||
/**
|
||||
* 支持的最大机器id,
|
||||
*/
|
||||
const unsigned int maxWorkerId = -1 ^ (-1 << workerIdBits);
|
||||
|
||||
/**
|
||||
* 支持的最大数据中心id,结果是31
|
||||
*/
|
||||
const UInt maxDatacenterId = -1 ^ (-1 << datacenterIdBits);
|
||||
/**
|
||||
* 支持的最大数据中心id,
|
||||
*/
|
||||
const unsigned int maxDatacenterId = -1 ^ (-1 << datacenterIdBits);
|
||||
|
||||
/**
|
||||
* 生成序列的掩码,这里为4095
|
||||
*/
|
||||
const UInt sequenceMask = -1 ^ (-1 << sequenceBits);
|
||||
/**
|
||||
* 生成序列的掩码,这里为4095
|
||||
*/
|
||||
const unsigned int sequenceMask = -1 ^ (-1 << sequenceBits);
|
||||
|
||||
/**
|
||||
* 工作机器id(0~31)
|
||||
*/
|
||||
UInt workerId;
|
||||
/**
|
||||
* 工作机器id(0~31)
|
||||
*/
|
||||
unsigned int workerId_;
|
||||
|
||||
/**
|
||||
* 数据中心id(0~31)
|
||||
*/
|
||||
UInt datacenterId;
|
||||
/**
|
||||
* 数据中心id(0~31)
|
||||
*/
|
||||
unsigned int datacenterId_;
|
||||
|
||||
/**
|
||||
* 毫秒内序列(0~4095)
|
||||
*/
|
||||
AtomicUInt sequence {0};
|
||||
|
||||
/**
|
||||
* 上次生成ID的时间截
|
||||
*/
|
||||
AtomicUInt64 lastTimestamp {0};
|
||||
/**
|
||||
* 毫秒内序列(0~4095)
|
||||
*/
|
||||
AtomicUInt sequence_ {0};
|
||||
|
||||
/**
|
||||
* 上次生成ID的时间截
|
||||
*/
|
||||
AtomicUInt64 lastTimestamp_ {0};
|
||||
};
|
||||
#endif // _JW_CORE_ID_WORKER_H_
|
||||
|
||||
#endif // _JW_CORE_ID_WORKER_H_
|
||||
Reference in New Issue
Block a user