|
|
|
@ -34,6 +34,8 @@ public class IdUtils {
|
|
|
|
|
|
|
|
|
|
|
|
private static Map<String, RedisAtomicLong> map = new ConcurrentHashMap<>();
|
|
|
|
private static Map<String, RedisAtomicLong> map = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Map<String, RedisAtomicLong> mapGlobal = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Long nextId() {
|
|
|
|
public static Long nextId() {
|
|
|
|
return nextId(DEFAULT_GROUP_NAME);
|
|
|
|
return nextId(DEFAULT_GROUP_NAME);
|
|
|
|
@ -51,10 +53,10 @@ public class IdUtils {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static Long nextId(String groupName) {
|
|
|
|
public static Long nextId(String groupName) {
|
|
|
|
RedisAtomicLong counter = map.get(PREFIX_GLOBAL + groupName);
|
|
|
|
RedisAtomicLong counter = mapGlobal.get(PREFIX_GLOBAL + groupName);
|
|
|
|
if (counter == null) {
|
|
|
|
if (counter == null) {
|
|
|
|
counter = new RedisAtomicLong(PREFIX_GLOBAL + groupName, redisTemplate.getConnectionFactory());
|
|
|
|
counter = new RedisAtomicLong(PREFIX_GLOBAL + groupName, redisTemplate.getConnectionFactory());
|
|
|
|
map.put(PREFIX + groupName, counter);
|
|
|
|
mapGlobal.put(PREFIX_GLOBAL + groupName, counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return counter.incrementAndGet();
|
|
|
|
return counter.incrementAndGet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -74,7 +76,7 @@ public class IdUtils {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static boolean nextIdInit(String groupName) {
|
|
|
|
public static boolean nextIdInit(String groupName) {
|
|
|
|
return map.containsKey(PREFIX_GLOBAL + groupName);
|
|
|
|
return mapGlobal.containsKey(PREFIX_GLOBAL + groupName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void nextIdInit(Long startId) {
|
|
|
|
public static void nextIdInit(Long startId) {
|
|
|
|
@ -92,10 +94,10 @@ public class IdUtils {
|
|
|
|
* @param startId
|
|
|
|
* @param startId
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static void nextIdInit(String groupName, Long startId) {
|
|
|
|
public static void nextIdInit(String groupName, Long startId) {
|
|
|
|
RedisAtomicLong counter = map.get(PREFIX_GLOBAL + groupName);
|
|
|
|
RedisAtomicLong counter = mapGlobal.get(PREFIX_GLOBAL + groupName);
|
|
|
|
if (counter == null) {
|
|
|
|
if (counter == null) {
|
|
|
|
counter = new RedisAtomicLong(PREFIX_GLOBAL + groupName, redisTemplate.getConnectionFactory());
|
|
|
|
counter = new RedisAtomicLong(PREFIX_GLOBAL + groupName, redisTemplate.getConnectionFactory());
|
|
|
|
map.put(PREFIX_GLOBAL + groupName, counter);
|
|
|
|
mapGlobal.put(PREFIX_GLOBAL + groupName, counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
counter.set(startId);
|
|
|
|
counter.set(startId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|