添加 IdGen.randomShortString() 方法
This commit is contained in:
@@ -28,13 +28,6 @@ public class IdGen {
|
|||||||
return StringUtils.replace(UUID.randomUUID().toString(),"-", "");
|
return StringUtils.replace(UUID.randomUUID().toString(),"-", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用SecureRandom随机生成Long.
|
|
||||||
*/
|
|
||||||
public static long randomLong() {
|
|
||||||
return Math.abs(random.nextLong());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基于Base62编码的SecureRandom随机生成bytes.
|
* 基于Base62编码的SecureRandom随机生成bytes.
|
||||||
*/
|
*/
|
||||||
@@ -44,6 +37,20 @@ public class IdGen {
|
|||||||
return EncodeUtils.encodeBase62(randomBytes);
|
return EncodeUtils.encodeBase62(randomBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机小写字符串
|
||||||
|
*/
|
||||||
|
public static String randomString(int length) {
|
||||||
|
return randomBase62(length).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机简短小写字符串(对重复频率要求不高的使用)
|
||||||
|
*/
|
||||||
|
public static String randomShortString() {
|
||||||
|
return randomBase62(4).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用SecureRandom随机生成指定范围的Integer.
|
* 使用SecureRandom随机生成指定范围的Integer.
|
||||||
*/
|
*/
|
||||||
@@ -51,6 +58,13 @@ public class IdGen {
|
|||||||
return random.nextInt(max) % (max - min + 1) + min;
|
return random.nextInt(max) % (max - min + 1) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用SecureRandom随机生成Long.
|
||||||
|
*/
|
||||||
|
public static long randomLong() {
|
||||||
|
return Math.abs(random.nextLong());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取新唯一编号(18为数值)
|
* 获取新唯一编号(18为数值)
|
||||||
* 来自于twitter项目snowflake的id产生方案,全局唯一,时间有序。
|
* 来自于twitter项目snowflake的id产生方案,全局唯一,时间有序。
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class LogInterceptor extends BaseService implements HandlerInterceptor {
|
|||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||||
Object handler) throws Exception {
|
Object handler) throws Exception {
|
||||||
if (StringUtils.isBlank(MDC.get(TRACE_ID))) {
|
if (StringUtils.isBlank(MDC.get(TRACE_ID))) {
|
||||||
MDC.put(TRACE_ID, IdGen.randomBase62(4));
|
MDC.put(TRACE_ID, IdGen.randomShortString());
|
||||||
}
|
}
|
||||||
long beginTime = System.currentTimeMillis();// 1、开始时间
|
long beginTime = System.currentTimeMillis();// 1、开始时间
|
||||||
startTimeThreadLocal.set(beginTime); // 线程绑定变量(该数据只有当前请求的线程可见)
|
startTimeThreadLocal.set(beginTime); // 线程绑定变量(该数据只有当前请求的线程可见)
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class EmpUserServiceSupport extends CrudService<EmpUserDao, EmpUser>
|
|||||||
// 如果没有设置用户编码,则根据登录名生成一个
|
// 如果没有设置用户编码,则根据登录名生成一个
|
||||||
if (StringUtils.isBlank(user.getUserCode())){
|
if (StringUtils.isBlank(user.getUserCode())){
|
||||||
userService.genId(user, user.getLoginCode());
|
userService.genId(user, user.getLoginCode());
|
||||||
user.setUserCode(user.getUserCode()+"_"+IdGen.randomBase62(4).toLowerCase());
|
user.setUserCode(user.getUserCode()+"_"+IdGen.randomShortString());
|
||||||
}
|
}
|
||||||
user.setUserType(EmpUser.USER_TYPE_EMPLOYEE);
|
user.setUserType(EmpUser.USER_TYPE_EMPLOYEE);
|
||||||
user.setMgrType(EmpUser.MGR_TYPE_NOT_ADMIN);
|
user.setMgrType(EmpUser.MGR_TYPE_NOT_ADMIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user