public class IdGenerator extends Object
Get 24-bit fixed-length sequential code. Used to generate sequential codes with dates. The first 8 bits are the year, month and date. The 9th bit is the microservice designator and takes values in the range 0-15 (displayed as hex 0-9A-F). The 10th bit is the machine designator and takes the value range 0-15 (displayed as 0-9A-F in hexadecimal). The last 14 bits are the sequence codes. Example: 20211202AB10098259438592
| 限定符和类型 | 字段和说明 |
|---|---|
private static long |
APP_BIT |
private static long |
APP_LEFT |
private long |
appId |
private String |
appIdChar |
private static int |
CODE_LENGTH |
private static String |
DATE_STRING |
private static DateTimeFormatter |
DF |
private long |
lastTimeStamp |
private static long |
MACHINE_BIT |
private static long |
MACHINE_LEFT |
private String |
machineChar |
private long |
machineId |
private static long |
MAX_APP_NUM |
private static long |
MAX_MACHINE_NUM |
private static long |
MAX_SEQUENCE |
private long |
sequence |
private static long |
SEQUENCE_BIT |
private static long |
START_TIMESTAMP |
private static long |
TIME_LEFT |
| 构造器和说明 |
|---|
IdGenerator(long appId,
long machineId)
The parameters are required
|
private static final int CODE_LENGTH
private static final long APP_BIT
private static final long MACHINE_BIT
private static final long SEQUENCE_BIT
private static final long MAX_SEQUENCE
private static final long MAX_MACHINE_NUM
private static final long MAX_APP_NUM
private static final long MACHINE_LEFT
private static final long APP_LEFT
private static final long TIME_LEFT
private static final String DATE_STRING
private static final DateTimeFormatter DF
private static final long START_TIMESTAMP
private long appId
private long machineId
private long sequence
private long lastTimeStamp
private String appIdChar
private String machineChar
public IdGenerator(long appId,
long machineId)
appId - Microservice Code,takes values in the range 0-15machineId - Machine code,takes values in the range 0-15private long getNext()
private long getNew()
public String genId()
private String cast(String StringNumber)
StringNumber - private String getZero(int x)
x - Number of replenishments requiredCopyright © 2022. All rights reserved.