From 91ba8c5c21b1ee0c03b329003067cfd9f0112a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E5=BA=86=E5=90=89?= <51312040@qq.com> Date: Thu, 5 Aug 2021 15:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9B=AA=E8=8A=B1id=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chinaunicom/mall/ebtp/common/util/PropertyUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/util/PropertyUtils.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/util/PropertyUtils.java index 47f5a81..598ec8e 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/util/PropertyUtils.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/util/PropertyUtils.java @@ -1,6 +1,7 @@ package com.chinaunicom.mall.ebtp.common.util; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.RandomUtil; import org.springframework.beans.factory.annotation.Value; /** @@ -30,15 +31,17 @@ public class PropertyUtils { * @return */ public static String getSnowflakeId() { - long l = IdUtil.getSnowflake(WORKER_ID, DATACENTER_ID).nextId(); - return String.valueOf(l); + return String.valueOf(getSnowflakeLongId()); } + /** * 生成雪花id * * @return */ 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(); } }