生成16位id

This commit is contained in:
2023-11-13 09:06:26 +08:00
parent be89f49d74
commit de57827206
2 changed files with 7 additions and 3 deletions

View File

@@ -59,6 +59,10 @@ public class IdUtils {
// 2.中间四位整数,标识日期
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
String dayTime = sdf.format(new Date());
// 2.生成四位随机整数
int valueOf = (int)((Math.random()*9+1)*1000);
// 3.生成uuid的hashCode值
int hashCode = UUID.randomUUID().toString().hashCode();
// 4.可能为负数
@@ -66,8 +70,8 @@ public class IdUtils {
hashCode = -hashCode;
}
// 5.算法处理: 0-代表前面补充0; 10-代表长度为10; d-代表参数为正数型
String value = machineId + dayTime + String.format("%010d", hashCode);
System.out.println(value);
String value = machineId + valueOf + String.format("%010d", hashCode);
// System.out.println(value);
return value;
}