package com.yqzx.common.util;
|
|
import cn.hutool.core.lang.Snowflake;
|
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.RandomUtil;
|
|
/**
|
* @Description ID 生成
|
* @Author wh
|
* @Date 2023/12/9 16:30
|
*/
|
public class IdGenerator {
|
|
private static Snowflake snowflake;
|
|
public static Long getId() {
|
return snowflake.nextId();
|
}
|
|
static {
|
// 不同的机器可以设置不同的机器id去区分
|
// workerId是终端ID
|
// datacenterId是数据中心ID
|
snowflake = IdUtil.getSnowflake(1, 1);
|
}
|
|
public static String getUUID(){
|
//生成的UUID是带-的字符串,类似于:a5c8a5e8-df2b-4706-bea4-08d0939410e3
|
return IdUtil.randomUUID();
|
}
|
|
public static String getStrUUID(){
|
//生成的是不带-的字符串,类似于:b17f24ff026d40949c85a24f4f375d42
|
return IdUtil.simpleUUID();
|
}
|
}
|