wang-hao-jie
2021-10-19 cc8111dbc369c1e82f159027ee8438912ae28128
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cn.exrick.xboot.core.common.utils;
 
import cn.hutool.core.util.IdUtil;
 
import java.security.SecureRandom;
 
/**
 * @author Exrickx
 */
public class CommonUtil {
 
    private CommonUtil() {
        throw new IllegalStateException("Utility class");
    }
 
    private static SecureRandom random = new SecureRandom();
 
    /**
     * 以UUID重命名
     * @param fileName
     * @return
     */
    public static String renamePic(String fileName) {
 
        String extName = "";
        if (fileName.contains(".")) {
            extName = fileName.substring(fileName.lastIndexOf("."));
        }
        return IdUtil.simpleUUID() + extName;
    }
 
    /**
     * 随机6位数生成
     */
    public static String getRandomNum() {
 
        int num = random.nextInt(999999);
        // 不足六位前面补0
        String str = String.format("%06d", num);
        return str;
    }
 
    /**
     * 批量递归删除时 判断target是否在ids中 避免重复删除
     * @param target
     * @param ids
     * @return
     */
    public static Boolean judgeIds(String target, String[] ids) {
 
        Boolean flag = false;
        for (String id : ids) {
            if (id.equals(target)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}