修改雪花id生成方式
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package com.chinaunicom.mall.ebtp.common.util;
|
package com.chinaunicom.mall.ebtp.common.util;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,15 +31,17 @@ public class PropertyUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getSnowflakeId() {
|
public static String getSnowflakeId() {
|
||||||
long l = IdUtil.getSnowflake(WORKER_ID, DATACENTER_ID).nextId();
|
return String.valueOf(getSnowflakeLongId());
|
||||||
return String.valueOf(l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成雪花id
|
* 生成雪花id
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static long getSnowflakeLongId() {
|
public static long getSnowflakeLongId() {
|
||||||
return IdUtil.getSnowflake(WORKER_ID, DATACENTER_ID).nextId();
|
long workerId = RandomUtil.getRandom().nextLong(31);
|
||||||
|
long datacenterId = RandomUtil.getRandom().nextLong(31);
|
||||||
|
return IdUtil.getSnowflake(workerId, datacenterId).nextId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user