wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
 
    @Resource
    public void setSnowFlake(SnowFlake snowFlake) {
        IDUtils.snowFlake = snowFlake;
    }
 
    public static String randomID(Integer num) {
        num = ObjectUtils.isEmpty(num) ? 16 : num;
        return RandomStringUtils.randomAlphanumeric(num);
    }
 
    // 主键请不要使用字符串 推荐雪花算法
    public static Long snowID() {
        return snowFlake.nextId();
    }
}