private final String AUTH_KEY="AUTH_CODE_KEY";
private final Integer AUTH_KEY_LEN=6;
public String nextNo() throws SeqException {
RLock lock = redissonCache.redissonClient.getLock(AUTH_KEY);
String lastKey=null;
try {
lock.lock();
lastKey = redissonCache.getCacheObject(Tool.LICENSE+AUTH_KEY);
if(null==lastKey){
lastKey=String.format("%06d",0);
}
int pos = AUTH_KEY_LEN-1;
char lastArr[]=lastKey.toCharArray();
Tool.carry(pos,lastArr);
lastKey = String.valueOf(lastArr);
redissonCache.setCacheObject(Tool.LICENSE+AUTH_KEY,lastKey);
}catch (Exception e){
e.printStackTrace();
}finally {
lock.unlock();
}
return lastKey;
}
/**
* @Date 2023/4/23
*/
public class Tool {
public static String LICENSE="LICENSE:";
private static final String key="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/**
* 62进制式唯一递增key
* pos 0开始
* @date: 2023/4/21
*/
public static void carry(int pos,char arr[]){
char cur = arr[pos];
int inx = key.indexOf(cur);
if(inx==key.length()-1){//需要进1
arr[pos]='0';
carry(pos-1,arr);
}else {
arr[pos]=key.charAt(inx+1);
}
}
}