广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package cn.huge.base.common.utils;
 
import org.apache.commons.lang3.StringUtils;
 
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;
 
/**
 * @title: ID生成工具
 * @description: ID生成工具
 * @company: hugeinfo
 * @author: liyj
 * @time: 2021-11-05 16:51:48
 * @version: 1.0.0
 */
public class IdUtils {
 
    /**
     * 新建编号
     */
    public static String NEW_ID = "new";
 
    /**
     * 时间Id统计常量
     */
    private static int COUNT_NUM = 1000;
 
    /**
     * 时间Id统计常量,常量前缀
     */
    private static int SIGN_COUNT_NUM = 1000;
 
    /**
     * 时间Id统计常量,常量后缀
     */
    private static int COUNT_NUM_SIGN = 1000;
 
    /**
     * UUID随机字符串,有"-"
     * @return String
     */
    public static String uuid()
    {
        return UUID.randomUUID().toString();
    }
 
    /**
     * UUID随机字符串,无"-"
     * @return String
     */
    public static String uuid2()
    {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
 
    /**
     * UUID随机字符串
     * @return String
     */
    public static String uuid3()
    {
        long val = ByteBuffer.wrap(uuid2().getBytes()).getLong();
        return Long.toString(val, 36);
    }
 
    /**
     * 获取带有的时间Id,后四位随机数
     * @return String
     */
    public synchronized static String getTimeRandomId(){
        String str = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
        String randomNum = getRandomNum(4);
        String  timeId = str.replaceAll("-","").replaceAll(":","").replaceAll(" ","") + randomNum;
        timeId = timeId.substring(2,timeId.length());
        return timeId;
    }
 
    //随机产生N位数字随机数
    public static String getRandomNum(int length) { //length表示生成字符串的长度
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
 
    /**
     * 判断是否为新增对象编号
     */
    public static Boolean checkNewId(String id){
        if (StringUtils.isEmpty(id) || NEW_ID.equals(id)){
            return true;
        }else{
            return false;
        }
    }
 
    /**
     * 获取时间Id,后四位常量
     * @return String
     */
    public synchronized static String getNewTimeId(){
        String  timeId = getNowTime() + (COUNT_NUM++);
        if(COUNT_NUM > 99999){
            COUNT_NUM = 10000;
        }
        timeId=timeId.substring(2, timeId.length());
        return timeId;
    }
 
    /**
     * 获取时间Id,后四位常量
     * @return String
     */
    public synchronized static String getNowTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String nowTime = sdf.format(new Date());
        return nowTime;
    }
}
/**
 * -------------------_ooOoo_-------------------
 * ------------------o8888888o------------------
 * ------------------88" . "88------------------
 * ------------------(| -_- |)------------------
 * ------------------O\  =  /O------------------
 * ---------------____/`---'\____---------------
 * -------------.'  \\|     |//  `.-------------
 * ------------/  \\|||  :  |||//  \------------
 * -----------/  _||||| -:- |||||-  \-----------
 * -----------|   | \\\  -  /// |   |-----------
 * -----------| \_|  ''\---/''  |   |-----------
 * -----------\  .-\__  `-`  ___/-. /-----------
 * ---------___`. .'  /--.--\  `. . __----------
 * ------."" '<  `.___\_<|>_/___.'  >'"".-------
 * -----| | :  `- \`.;`\ _ /`;.`/ - ` : | |-----
 * -----\  \ `-.   \_ __\ /__ _/   .-` /  /-----
 * ======`-.____`-.___\_____/___.-`____.-'======
 * -------------------`=---='
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 * ---------佛祖保佑---hugeinfo---永无BUG----------
 */