xuefei
2020-12-12 160487aedf89e2aea61f043c7a5c3d211ed19798
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cn.cetc54.platform.core.common.utils;
 
 
import cn.cetc54.platform.core.common.exception.PlatformException;
import cn.cetc54.platform.core.common.constant.CommonConstant;
import cn.hutool.core.util.StrUtil;
 
import java.util.Random;
import java.util.UUID;
 
/**
 * @author
 */
public class CommonUtil {
 
    /**
     * 以UUID重命名
     *
     * @param fileName
     * @return
     */
    public static String renamePic(String fileName) {
        String extName = fileName.substring(fileName.lastIndexOf("."));
        return UUID.randomUUID().toString().replace("-", "") + extName;
    }
 
    /**
     * 随机6位数生成
     */
    public static String getRandomNum() {
 
        Random random = new Random();
        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;
    }
 
    /**
     * 禁用词判断
     * @param param
     */
    public static void stopwords(String param){
 
        if (StrUtil.isBlank(param)) {
            return;
        }
 
        // 转换成小写
        param = param.toLowerCase();
        // 判断是否包含非法字符
        for (String keyword : CommonConstant.STOP_WORDS) {
            if (param.contains(keyword)) {
                throw new PlatformException("名称包含禁用词:" + keyword);
            }
        }
    }
}