All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.cliveyuan.tools.IdTools Maven / Gradle / Ivy

There is a newer version: 4.0.6
Show newest version
package com.gitee.cliveyuan.tools;

import com.gitee.cliveyuan.tools.enums.DateTimeFormat;

import java.util.UUID;

/**
 * ID生成工具
 *
 * @author clive
 * Created on 2018/07/27
 * @since 1.0
 */
public class IdTools {

    private IdTools(){}

    /**
     * 随机一个原生UUID
     *
     */
    public static String randomUUID() {
        return UUID.randomUUID().toString();
    }

    /**
     * 随机去掉横杠的UUID
     *
     */
    public static String randomShortUUID() {
        String uuid = randomUUID();
        // 去掉“-”符号
        return uuid.replaceAll("-", "");
    }

    /**
     * 生成以日期时间开头的20位订单号
     *
     */
    public static String genOrderNo() {
        String dateTime = DateTimeTools.format(DateTimeTools.now(), DateTimeFormat.DATE_TIME_0);
        int randomInt = MathTools.randomInt(100000, 999999);
        return dateTime + randomInt;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy