xiaoyong931011
2022-09-23 f9a7691e2175281dd972ae2ad2beb73bc3fd0650
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
package cc.mrbird.febs.common.utils;
 
import cn.hutool.core.util.StrUtil;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
 
/**
 * @author wzy
 * @date 2021-09-22
 **/
public class MallUtils {
 
    public static String getRandomNum(int length) {
        String str = "0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(str.length());
            sb.append(str.charAt(number));
        }
 
        return sb.toString();
    }
 
    public static String getOrderNum(String prefix) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String dd=df.format(new Date());
        if (StrUtil.isNotBlank(prefix)) {
            return prefix+dd+getRandomNum(5);
        }
        return dd+getRandomNum(5);
    }
 
    public static String getOrderNum() {
        return getOrderNum(null);
    }
}