|
@@ -19,7 +19,8 @@ public class IDGenerator {
|
|
public static synchronized long commonID() {
|
|
public static synchronized long commonID() {
|
|
String timestamp = dateFormat1.format(new Date()).substring(2);
|
|
String timestamp = dateFormat1.format(new Date()).substring(2);
|
|
long threadId = Thread.currentThread().getId();
|
|
long threadId = Thread.currentThread().getId();
|
|
-
|
|
|
|
|
|
+ String s1 = String.valueOf(threadId);
|
|
|
|
+ char c = s1.charAt(s1.length() - 1);
|
|
//huTool工具集的雪花算法 --> 生成19位id
|
|
//huTool工具集的雪花算法 --> 生成19位id
|
|
//参数1为终端ID
|
|
//参数1为终端ID
|
|
//参数2为数据中心ID
|
|
//参数2为数据中心ID
|
|
@@ -27,7 +28,7 @@ public class IDGenerator {
|
|
// long id = snowflake.nextId();
|
|
// long id = snowflake.nextId();
|
|
// System.out.println("id***" + id);
|
|
// System.out.println("id***" + id);
|
|
|
|
|
|
- return Long.parseLong(timestamp + String.format("%01d", threadId));
|
|
|
|
|
|
+ return Long.parseLong(timestamp + c);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,6 +39,8 @@ public class IDGenerator {
|
|
public static synchronized long orderID() {
|
|
public static synchronized long orderID() {
|
|
String timestamp = dateFormat.format(new Date()).substring(2);
|
|
String timestamp = dateFormat.format(new Date()).substring(2);
|
|
long threadId = Thread.currentThread().getId();
|
|
long threadId = Thread.currentThread().getId();
|
|
|
|
+ String s1 = String.valueOf(threadId);
|
|
|
|
+ char c = s1.charAt(s1.length() - 1);
|
|
String randomNumber = generateRandomNumber();
|
|
String randomNumber = generateRandomNumber();
|
|
|
|
|
|
// 乐观锁部分
|
|
// 乐观锁部分
|
|
@@ -47,9 +50,11 @@ public class IDGenerator {
|
|
currentSeq = seq.get();
|
|
currentSeq = seq.get();
|
|
nextSeq = (currentSeq >= 999) ? 0 : currentSeq + 1;
|
|
nextSeq = (currentSeq >= 999) ? 0 : currentSeq + 1;
|
|
} while (!seq.compareAndSet(currentSeq, nextSeq));
|
|
} while (!seq.compareAndSet(currentSeq, nextSeq));
|
|
|
|
+ String s2 = String.valueOf(nextSeq);
|
|
|
|
+ char c1 = s2.charAt(s2.length() - 1);
|
|
|
|
|
|
String s = "5"; // 表示国内订单
|
|
String s = "5"; // 表示国内订单
|
|
- return Long.parseLong(s + timestamp + String.format("%01d", threadId) + randomNumber + String.format("%01d", nextSeq));
|
|
|
|
|
|
+ return Long.parseLong(s + timestamp + c + randomNumber + c1);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -60,6 +65,8 @@ public class IDGenerator {
|
|
public static synchronized long coinOrderID() {
|
|
public static synchronized long coinOrderID() {
|
|
String timestamp = dateFormat.format(new Date()).substring(2);
|
|
String timestamp = dateFormat.format(new Date()).substring(2);
|
|
long threadId = Thread.currentThread().getId();
|
|
long threadId = Thread.currentThread().getId();
|
|
|
|
+ String s1 = String.valueOf(threadId);
|
|
|
|
+ char c = s1.charAt(s1.length() - 1);
|
|
String randomNumber = generateRandomNumber();
|
|
String randomNumber = generateRandomNumber();
|
|
|
|
|
|
// 乐观锁部分
|
|
// 乐观锁部分
|
|
@@ -69,9 +76,11 @@ public class IDGenerator {
|
|
currentSeq = seq.get();
|
|
currentSeq = seq.get();
|
|
nextSeq = (currentSeq >= 999) ? 0 : currentSeq + 1;
|
|
nextSeq = (currentSeq >= 999) ? 0 : currentSeq + 1;
|
|
} while (!seq.compareAndSet(currentSeq, nextSeq));
|
|
} while (!seq.compareAndSet(currentSeq, nextSeq));
|
|
|
|
+ String s2 = String.valueOf(nextSeq);
|
|
|
|
+ char c1 = s2.charAt(s2.length() - 1);
|
|
|
|
|
|
String s = "1"; // 表示海外订单
|
|
String s = "1"; // 表示海外订单
|
|
- return Long.parseLong(s + timestamp + String.format("%01d", threadId) + randomNumber + String.format("%01d", nextSeq));
|
|
|
|
|
|
+ return Long.parseLong(s + timestamp + c + randomNumber + c1);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|