zxl
2025-06-11 861582390dc7c395897159077a547d3e7078727c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cn.lili.common.utils;
 
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
 
/**
 * 通用工具
 * @author Chopper
 */
public class CommonUtil {
 
    public static final String BASE_NUMBER = "0123456789";
 
    /**
     * 以UUID重命名
     * @param fileName 文件名称
     * @return 格式化名称
     */
    public static String rename(String fileName) {
        String extName = fileName.substring(fileName.lastIndexOf("."));
        return UUID.randomUUID().toString().replace("-", "") + extName;
    }
 
 
    /**
     * 随机6位数生成
     */
    public static String getRandomNum() {
        StringBuilder sb = new StringBuilder(6);
        for (int i = 0; i < 6; i++) {
            int num = ThreadLocalRandom.current().nextInt(BASE_NUMBER.length());
            sb.append(BASE_NUMBER.charAt(num));
        }
        return sb.toString();
    }
 
    /**
     * 获取特定字符 + 6位随机数
     * @return
     */
    public static String getSpecialStr(String value) {
        return value + getRandomNum();
    }
}