fix(X-Pack): 集群多节点 ID 冲突,增加配置机器 ID

This commit is contained in:
fit2cloud-chenyw
2025-04-03 11:05:22 +08:00
committed by fit2cloud-chenyw
parent 9ba4057f40
commit d463bd8282
2 changed files with 24 additions and 1 deletions

View File

@@ -1,12 +1,21 @@
package io.dataease.utils;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Component;
@Component
public class IDUtils {
private static SnowFlake snowFlake = new SnowFlake(1, 1);
private static SnowFlake snowFlake;
@Resource
public void setSnowFlake(SnowFlake snowFlake) {
IDUtils.snowFlake = snowFlake;
}
public static String randomID(Integer num) {
num = ObjectUtils.isEmpty(num) ? 16 : num;

View File

@@ -1,7 +1,17 @@
package io.dataease.utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class SnowFlake {
@Value("${dataease.machine-id:1}")
public void setMachineId(long machineId) {
this.machineId = machineId;
}
/**
* 起始的时间戳
*/
@@ -44,6 +54,10 @@ public class SnowFlake {
this.machineId = machineId;
}
public SnowFlake() {
this.datacenterId = 1;
}
/**
* 产生下一个ID
*