|
@@ -40,10 +40,13 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
-import static org.dromara.common.core.constant.Constants.Y;
|
|
|
|
|
|
+import static org.dromara.common.core.constant.Constants.THR;
|
|
import static org.dromara.common.core.constant.TenantConstants.SUPER_ADMIN_ROLE_KEY;
|
|
import static org.dromara.common.core.constant.TenantConstants.SUPER_ADMIN_ROLE_KEY;
|
|
-import static org.dromara.common.core.enums.UserType.*;
|
|
|
|
|
|
+import static org.dromara.common.core.constant.TenantConstants.TENANT_ADMIN_ROLE_KEY;
|
|
|
|
+import static org.dromara.common.core.enums.UserType.APP_STAFF;
|
|
|
|
+import static org.dromara.common.core.enums.UserType.PC_USER;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 租户Service业务层处理
|
|
* 租户Service业务层处理
|
|
@@ -146,8 +149,8 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
bo.setId(add.getId());
|
|
bo.setId(add.getId());
|
|
|
|
|
|
// 根据套餐创建角色
|
|
// 根据套餐创建角色
|
|
- List<Long> roleIds = createTenantRole(tenantId, bo.getPackageId());
|
|
|
|
-
|
|
|
|
|
|
+ List<SysRole> roles = createTenantRole(tenantId, bo.getPackageId());
|
|
|
|
+ List<Long> roleIds = roles.stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
|
// 创建部门: 公司名是部门名称
|
|
// 创建部门: 公司名是部门名称
|
|
SysDept dept = new SysDept();
|
|
SysDept dept = new SysDept();
|
|
dept.setTenantId(tenantId);
|
|
dept.setTenantId(tenantId);
|
|
@@ -177,7 +180,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
user.setPassword(BCrypt.hashpw(bo.getPassword()));
|
|
user.setPassword(BCrypt.hashpw(bo.getPassword()));
|
|
user.setDeptId(deptId);
|
|
user.setDeptId(deptId);
|
|
user.setPhonenumber(bo.getContactPhone());
|
|
user.setPhonenumber(bo.getContactPhone());
|
|
- user.setIsAuthentication(Y);
|
|
|
|
|
|
+ user.setIsAuthentication(THR);
|
|
user.setUserType(PC_USER.getUserType()+","+APP_STAFF.getUserType());
|
|
user.setUserType(PC_USER.getUserType()+","+APP_STAFF.getUserType());
|
|
userMapper.insert(user);
|
|
userMapper.insert(user);
|
|
//新增系统用户后,默认当前用户为部门的负责人
|
|
//新增系统用户后,默认当前用户为部门的负责人
|
|
@@ -188,14 +191,17 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
|
|
|
// 用户和角色关联表
|
|
// 用户和角色关联表
|
|
List<SysUserRole> userRoles = new ArrayList<>(roleIds.size());
|
|
List<SysUserRole> userRoles = new ArrayList<>(roleIds.size());
|
|
- roleIds.forEach(roleId -> {
|
|
|
|
- SysUserRole userRole = new SysUserRole();
|
|
|
|
- userRole.setUserId(user.getUserId());
|
|
|
|
- userRole.setRoleId(roleId);
|
|
|
|
- userRole.setTenantId(tenantId);
|
|
|
|
- userRoles.add(userRole);
|
|
|
|
- });
|
|
|
|
- userRoleMapper.insertBatch(userRoles);
|
|
|
|
|
|
+ for (SysRole role : roles) {
|
|
|
|
+ if (TENANT_ADMIN_ROLE_KEY.equals(role.getRoleKey())) {
|
|
|
|
+ SysUserRole userRole = new SysUserRole();
|
|
|
|
+ userRole.setUserId(user.getUserId());
|
|
|
|
+ userRole.setRoleId(role.getRoleId());
|
|
|
|
+ userRole.setTenantId(tenantId);
|
|
|
|
+ userRoles.add(userRole);
|
|
|
|
+ userRoleMapper.insert(userRole);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
// 租户和角色关联表
|
|
// 租户和角色关联表
|
|
SysUserTenant sysUserTenant = new SysUserTenant();
|
|
SysUserTenant sysUserTenant = new SysUserTenant();
|
|
@@ -274,7 +280,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
* @param packageId 租户套餐id
|
|
* @param packageId 租户套餐id
|
|
* @return 角色id
|
|
* @return 角色id
|
|
*/
|
|
*/
|
|
- private List<Long> createTenantRole(String tenantId, Long packageId) {
|
|
|
|
|
|
+ private List<SysRole> createTenantRole(String tenantId, Long packageId) {
|
|
// 获取租户套餐
|
|
// 获取租户套餐
|
|
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
|
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
|
if (ObjectUtil.isNull(tenantPackage)) {
|
|
if (ObjectUtil.isNull(tenantPackage)) {
|
|
@@ -286,22 +292,23 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
// 创建角色
|
|
// 创建角色
|
|
//查询000000的角色
|
|
//查询000000的角色
|
|
List<SysRoleVo> roleVos = sysRoleService.selectRoleAll();
|
|
List<SysRoleVo> roleVos = sysRoleService.selectRoleAll();
|
|
- List<Long> roleIds = new ArrayList<>();
|
|
|
|
|
|
+ List<SysRole> roles = new ArrayList<>();
|
|
for (SysRoleVo roleVo : roleVos) {
|
|
for (SysRoleVo roleVo : roleVos) {
|
|
if(!SUPER_ADMIN_ROLE_KEY.equals(roleVo.getRoleKey())){
|
|
if(!SUPER_ADMIN_ROLE_KEY.equals(roleVo.getRoleKey())){
|
|
SysRole role = new SysRole();
|
|
SysRole role = new SysRole();
|
|
|
|
+
|
|
role.setTenantId(tenantId);
|
|
role.setTenantId(tenantId);
|
|
- role.setRoleName(TenantConstants.TENANT_ADMIN_ROLE_NAME);
|
|
|
|
- role.setRoleKey(TenantConstants.TENANT_ADMIN_ROLE_KEY);
|
|
|
|
- role.setRoleSort(1);
|
|
|
|
- role.setStatus(SystemConstants.NORMAL);
|
|
|
|
|
|
+ role.setRoleName(roleVo.getRoleName());
|
|
|
|
+ role.setRoleKey(roleVo.getRoleKey());
|
|
|
|
+ role.setRoleSort(roleVo.getRoleSort());
|
|
|
|
+ role.setStatus(roleVo.getStatus());
|
|
roleMapper.insert(role);
|
|
roleMapper.insert(role);
|
|
|
|
|
|
Long roleId = role.getRoleId();
|
|
Long roleId = role.getRoleId();
|
|
- roleIds.add(roleId);
|
|
|
|
|
|
+ roles.add(role);
|
|
|
|
|
|
//查询角色的菜单
|
|
//查询角色的菜单
|
|
- List<Long> menuIdList =sysMenuMapper.selectMenuListByRoleId(roleId,false);
|
|
|
|
|
|
+ List<Long> menuIdList =sysMenuMapper.selectMenuListByRoleId(roleVo.getRoleId(),false);
|
|
// 创建角色菜单
|
|
// 创建角色菜单
|
|
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIdList.size());
|
|
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIdList.size());
|
|
menuIdList.forEach(menuId -> {
|
|
menuIdList.forEach(menuId -> {
|
|
@@ -315,7 +322,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- return roleIds;
|
|
|
|
|
|
+ return roles;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -424,7 +431,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
List<Long> roleIds = new ArrayList<>(roles.size() - 1);
|
|
List<Long> roleIds = new ArrayList<>(roles.size() - 1);
|
|
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
|
|
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
|
|
roles.forEach(item -> {
|
|
roles.forEach(item -> {
|
|
- if (TenantConstants.TENANT_ADMIN_ROLE_KEY.equals(item.getRoleKey())) {
|
|
|
|
|
|
+ if (TENANT_ADMIN_ROLE_KEY.equals(item.getRoleKey())) {
|
|
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
|
|
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
|
|
menuIds.forEach(menuId -> {
|
|
menuIds.forEach(menuId -> {
|
|
SysRoleMenu roleMenu = new SysRoleMenu();
|
|
SysRoleMenu roleMenu = new SysRoleMenu();
|