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