修改注册功能
This commit is contained in:
@@ -3,10 +3,7 @@ package com.jsh.erp.service.app;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.datasource.entities.App;
|
||||
import com.jsh.erp.datasource.entities.AppExample;
|
||||
import com.jsh.erp.datasource.entities.User;
|
||||
import com.jsh.erp.datasource.entities.UserBusiness;
|
||||
import com.jsh.erp.datasource.entities.*;
|
||||
import com.jsh.erp.datasource.mappers.AppMapper;
|
||||
import com.jsh.erp.datasource.mappers.AppMapperEx;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
@@ -292,4 +289,6 @@ public class AppService {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jsh.erp.utils.ExceptionCodeConstants;
|
||||
import com.jsh.erp.utils.JshException;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
import org.apache.ibatis.annotations.DeleteProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -354,7 +355,8 @@ public class UserService {
|
||||
BusinessConstants.LOG_OPERATION_TYPE_ADD,
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
//检查用户名和登录名
|
||||
checkUserNameAndLoginName(ue);
|
||||
checkLoginName(ue);
|
||||
checkUserName(ue);
|
||||
//新增用户信息
|
||||
ue= this.addUser(ue);
|
||||
if(ue==null){
|
||||
@@ -394,7 +396,11 @@ public class UserService {
|
||||
* 3是否管理者默认为员工
|
||||
* 4默认用户状态为正常
|
||||
* */
|
||||
ue.setPassword(Tools.md5Encryp(BusinessConstants.USER_DEFAULT_PASSWORD));
|
||||
|
||||
//用户没有设置密码时,使用默认密码
|
||||
if(StringUtil.isEmpty(ue.getPassword())){
|
||||
ue.setPassword(Tools.md5Encryp(BusinessConstants.USER_DEFAULT_PASSWORD));
|
||||
}
|
||||
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
|
||||
if(ue.getIsmanager()==null){
|
||||
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
|
||||
@@ -416,7 +422,7 @@ public class UserService {
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public UserEx registerUser(UserEx ue, Integer manageRoleId) throws Exception{
|
||||
public UserEx registerUser(UserEx ue, Long manageRoleId) throws Exception{
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* create time: 2019/4/9 18:00
|
||||
@@ -428,38 +434,46 @@ public class UserService {
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
|
||||
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
|
||||
} else {
|
||||
ue.setPassword(Tools.md5Encryp(ue.getPassword()));
|
||||
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
|
||||
if (ue.getIsmanager() == null) {
|
||||
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
|
||||
}
|
||||
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
|
||||
int result=0;
|
||||
try{
|
||||
result= userMapperEx.addUser(ue);
|
||||
}catch(Exception e){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
|
||||
ExceptionConstants.DATA_WRITE_FAIL_MSG);
|
||||
}
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* create time: 2019/4/24 10:57
|
||||
* website:https://qiankunpingtai.cn
|
||||
* description:
|
||||
* 检查登录名是否已存在
|
||||
*
|
||||
*/
|
||||
checkLoginName(ue);
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* create time: 2019/4/24 14:47
|
||||
* website:https://qiankunpingtai.cn
|
||||
* description:
|
||||
* 注册一个新用户需要做如下操作
|
||||
* 1、分配应用
|
||||
* 2、分配功能模块
|
||||
* 3、分配产品扩展字段
|
||||
* 4、分配角色(默认添加超级管理员角色,不可修改)
|
||||
* 5、写入用户信息
|
||||
* 6、写入用户角色应用功能关系
|
||||
*/
|
||||
|
||||
ue=this.addUser(ue);
|
||||
|
||||
//更新租户id
|
||||
User user = new User();
|
||||
user.setId(ue.getId());
|
||||
user.setTenantId(ue.getId());
|
||||
userService.updateUserTenant(user);
|
||||
//新增用户与角色的关系
|
||||
JSONObject ubObj = new JSONObject();
|
||||
ubObj.put("type", "UserRole");
|
||||
ubObj.put("keyid", ue.getId());
|
||||
JSONArray ubArr = new JSONArray();
|
||||
ubArr.add(manageRoleId);
|
||||
ubObj.put("value", ubArr.toString());
|
||||
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
if (result > 0) {
|
||||
return ue;
|
||||
}
|
||||
return null;
|
||||
addRegisterUserNotInclueUser(user.getId(),user.getTenantId(),manageRoleId);
|
||||
// //新增用户与角色的关系
|
||||
// JSONObject ubObj = new JSONObject();
|
||||
// ubObj.put("type", "UserRole");
|
||||
// ubObj.put("keyid", ue.getId());
|
||||
// JSONArray ubArr = new JSONArray();
|
||||
// ubArr.add(manageRoleId);
|
||||
// ubObj.put("value", ubArr.toString());
|
||||
// userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
return ue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,7 +501,8 @@ public class UserService {
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
//检查用户名和登录名
|
||||
checkUserNameAndLoginName(ue);
|
||||
checkLoginName(ue);
|
||||
checkUserName(ue);
|
||||
//更新用户信息
|
||||
ue = this.updateUser(ue);
|
||||
if (ue == null) {
|
||||
@@ -542,14 +557,13 @@ public class UserService {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* create by: cjl
|
||||
* create by: qiankunpingtai
|
||||
* create time: 2019/4/24 11:02
|
||||
* website:https://qiankunpingtai.cn
|
||||
* description:
|
||||
* 检查用户名称和登录名不能重复
|
||||
* create time: 2019/3/12 11:36
|
||||
* @Param: userEx
|
||||
* @return void
|
||||
* 检查登录名全局唯一
|
||||
*/
|
||||
public void checkUserNameAndLoginName(UserEx userEx)throws Exception{
|
||||
public void checkLoginName(UserEx userEx)throws Exception{
|
||||
List<User> list=null;
|
||||
if(userEx==null){
|
||||
return;
|
||||
@@ -579,10 +593,25 @@ public class UserService {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* create time: 2019/4/24 11:02
|
||||
* website:https://qiankunpingtai.cn
|
||||
* description:
|
||||
* 检查用户名同一个租户范围内内唯一
|
||||
*
|
||||
*/
|
||||
public void checkUserName(UserEx userEx)throws Exception{
|
||||
List<User> list=null;
|
||||
if(userEx==null){
|
||||
return;
|
||||
}
|
||||
Long userId=userEx.getId();
|
||||
//检查用户名
|
||||
if(!StringUtils.isEmpty(userEx.getUsername())){
|
||||
String userName=userEx.getUsername();
|
||||
list=this.getUserListByUserName(userName);
|
||||
list=this.getUserListByUserNameAndTenantId(userName,userEx.getTenantId());
|
||||
if(list!=null&&list.size()>0){
|
||||
if(list.size()>1){
|
||||
//超过一条数据存在,该用户名已存在
|
||||
@@ -603,8 +632,31 @@ public class UserService {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* website:https://qiankunpingtai.cn
|
||||
* description:
|
||||
* 通过用户名和租户id获取用户信息
|
||||
* create time: 2019/4/24 11:18
|
||||
* @Param: userName
|
||||
* @Param: tenantId
|
||||
* @return java.util.List<com.jsh.erp.datasource.entities.User>
|
||||
*/
|
||||
private List<User> getUserListByUserNameAndTenantId(String userName, Long tenantId) {
|
||||
|
||||
List<User> list =null;
|
||||
try{
|
||||
list=userMapperEx.getUserListByUserNameAndTenantId(userName,tenantId);
|
||||
}catch(Exception e){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
|
||||
ExceptionConstants.DATA_READ_FAIL_MSG);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户列表
|
||||
* */
|
||||
@@ -673,4 +725,34 @@ public class UserService {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* website:https://qiankunpingtai.cn
|
||||
* description:
|
||||
* 1、分配应用
|
||||
* 2、分配功能模块
|
||||
* 3、分配产品扩展字段
|
||||
* 4、分配角色(默认添加超级管理员角色,不可修改)
|
||||
* 5、写入用户角色应用功能关系
|
||||
* create time: 2019/4/26 9:37
|
||||
* @Param: userId 用户id
|
||||
* @Param: tenantId 租户id
|
||||
* @Param: roleId 模板角色id
|
||||
* @return java.lang.String
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public String addRegisterUserNotInclueUser(Long userId,Long tenantId,Long roleId)throws Exception {
|
||||
|
||||
String result =null;
|
||||
try{
|
||||
result=userMapperEx.addRegisterUserNotInclueUser(userId,tenantId,roleId);
|
||||
}catch(Exception e){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
|
||||
ExceptionConstants.DATA_WRITE_FAIL_MSG);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user