去除掉用户姓名重复的校验
This commit is contained in:
@@ -52,9 +52,6 @@ public class ExceptionConstants {
|
|||||||
//修改用户信息失败
|
//修改用户信息失败
|
||||||
public static final int USER_EDIT_FAILED_CODE = 500002;
|
public static final int USER_EDIT_FAILED_CODE = 500002;
|
||||||
public static final String USER_EDIT_FAILED_MSG = "修改用户信息失败";
|
public static final String USER_EDIT_FAILED_MSG = "修改用户信息失败";
|
||||||
//用户名已存在
|
|
||||||
public static final int USER_USER_NAME_ALREADY_EXISTS_CODE = 500003;
|
|
||||||
public static final String USER_USER_NAME_ALREADY_EXISTS_MSG = "用户名在本系统已存在";
|
|
||||||
//登录名已存在
|
//登录名已存在
|
||||||
public static final int USER_LOGIN_NAME_ALREADY_EXISTS_CODE = 500003;
|
public static final int USER_LOGIN_NAME_ALREADY_EXISTS_CODE = 500003;
|
||||||
public static final String USER_LOGIN_NAME_ALREADY_EXISTS_MSG = "登录名在本系统已存在";
|
public static final String USER_LOGIN_NAME_ALREADY_EXISTS_MSG = "登录名在本系统已存在";
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ public class UserController {
|
|||||||
HttpServletRequest request)throws Exception{
|
HttpServletRequest request)throws Exception{
|
||||||
JSONObject result = ExceptionConstants.standardSuccess();
|
JSONObject result = ExceptionConstants.standardSuccess();
|
||||||
ue.setUsername(ue.getLoginName());
|
ue.setUsername(ue.getLoginName());
|
||||||
userService.checkUserNameAndLoginName(ue); //检查用户名和登录名
|
userService.checkLoginName(ue); //检查登录名
|
||||||
ue = userService.registerUser(ue,manageRoleId,request);
|
ue = userService.registerUser(ue,manageRoleId,request);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ public class UserService {
|
|||||||
BusinessConstants.LOG_OPERATION_TYPE_ADD,
|
BusinessConstants.LOG_OPERATION_TYPE_ADD,
|
||||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||||
//检查用户名和登录名
|
//检查用户名和登录名
|
||||||
checkUserNameAndLoginName(ue);
|
checkLoginName(ue);
|
||||||
//新增用户信息
|
//新增用户信息
|
||||||
ue= this.addUser(ue);
|
ue= this.addUser(ue);
|
||||||
if(ue==null){
|
if(ue==null){
|
||||||
@@ -528,7 +528,7 @@ public class UserService {
|
|||||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
|
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
|
||||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||||
//检查用户名和登录名
|
//检查用户名和登录名
|
||||||
checkUserNameAndLoginName(ue);
|
checkLoginName(ue);
|
||||||
//更新用户信息
|
//更新用户信息
|
||||||
ue = this.updateUser(ue);
|
ue = this.updateUser(ue);
|
||||||
if (ue == null) {
|
if (ue == null) {
|
||||||
@@ -593,14 +593,12 @@ public class UserService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* create by: cjl
|
* 检查登录名不能重复
|
||||||
* description:
|
|
||||||
* 检查用户名称和登录名不能重复
|
|
||||||
* create time: 2019/3/12 11:36
|
* create time: 2019/3/12 11:36
|
||||||
* @Param: userEx
|
* @Param: userEx
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public void checkUserNameAndLoginName(UserEx userEx)throws Exception{
|
public void checkLoginName(UserEx userEx)throws Exception{
|
||||||
List<User> list=null;
|
List<User> list=null;
|
||||||
if(userEx==null){
|
if(userEx==null){
|
||||||
return;
|
return;
|
||||||
@@ -627,46 +625,8 @@ public class UserService {
|
|||||||
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG);
|
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//检查用户名
|
|
||||||
if(!StringUtils.isEmpty(userEx.getUsername())){
|
|
||||||
String userName=userEx.getUsername();
|
|
||||||
list=this.getUserListByUserName(userName);
|
|
||||||
if(list!=null&&list.size()>0){
|
|
||||||
if(list.size()>1){
|
|
||||||
//超过一条数据存在,该用户名已存在
|
|
||||||
logger.error("异常码[{}],异常提示[{}],参数,userName:[{}]",
|
|
||||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG,userName);
|
|
||||||
throw new BusinessRunTimeException(ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,
|
|
||||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG);
|
|
||||||
}
|
|
||||||
//一条数据,新增时抛出异常,修改时和当前的id不同时抛出异常
|
|
||||||
if(list.size()==1){
|
|
||||||
if(userId==null||(userId!=null&&!userId.equals(list.get(0).getId()))){
|
|
||||||
logger.error("异常码[{}],异常提示[{}],参数,userName:[{}]",
|
|
||||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG,userName);
|
|
||||||
throw new BusinessRunTimeException(ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,
|
|
||||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 通过用户名获取用户列表
|
|
||||||
* */
|
|
||||||
public List<User> getUserListByUserName(String userName)throws Exception{
|
|
||||||
List<User> list =null;
|
|
||||||
try{
|
|
||||||
list=userMapperEx.getUserListByUserNameOrLoginName(userName,null);
|
|
||||||
}catch(Exception e){
|
|
||||||
JshException.readFail(logger, e);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 通过登录名获取用户列表
|
* 通过登录名获取用户列表
|
||||||
|
|||||||
Reference in New Issue
Block a user