package com.ycl.utils.uuid;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.Random;
|
|
/**
|
* ID生成器工具类
|
*
|
* @author ruoyi
|
*/
|
public class IdUtils
|
{
|
|
private final static SimpleDateFormat FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
/**
|
* 获取随机UUID
|
*
|
* @return 随机UUID
|
*/
|
public static String randomUUID()
|
{
|
return UUID.randomUUID().toString();
|
}
|
|
/**
|
* 简化的UUID,去掉了横线
|
*
|
* @return 简化的UUID,去掉了横线
|
*/
|
public static String simpleUUID()
|
{
|
return UUID.randomUUID().toString(true);
|
}
|
|
/**
|
* 获取随机UUID,使用性能更好的ThreadLocalRandom生成UUID
|
*
|
* @return 随机UUID
|
*/
|
public static String fastUUID()
|
{
|
return UUID.fastUUID().toString();
|
}
|
|
/**
|
* 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID
|
*
|
* @return 简化的UUID,去掉了横线
|
*/
|
public static String fastSimpleUUID()
|
{
|
return UUID.fastUUID().toString(true);
|
}
|
|
/**
|
* 获取当前时间+随机数的编号
|
*
|
* @param numberNum 时间后生成几位数字,默认5
|
* @return 编号
|
*/
|
public static String timeAddRandomNO(Integer numberNum)
|
{
|
if (numberNum == null || numberNum == 0 || numberNum < 3) {
|
numberNum = 5;
|
}
|
|
Date now = new Date();
|
String timeString = FORMAT.format(now);
|
|
Random random = new Random();
|
StringBuilder builder = new StringBuilder();
|
builder.append(timeString);
|
for (int i = 0; i < numberNum; i++) {
|
// 生成一个0到9之间的随机数(包括0和9)
|
builder.append(random.nextInt(10));
|
}
|
return builder.toString();
|
}
|
}
|