Showing
4 changed files
with
15 additions
and
24 deletions
... | ... | @@ -10,7 +10,6 @@ import org.thingsboard.server.common.data.yunteng.enums.UserStatusEnum; |
10 | 10 | |
11 | 11 | import javax.validation.constraints.NotEmpty; |
12 | 12 | import java.time.LocalDateTime; |
13 | -import java.util.List; | |
14 | 13 | import java.util.Set; |
15 | 14 | |
16 | 15 | @EqualsAndHashCode(callSuper = false) |
... | ... | @@ -39,7 +38,7 @@ public class UserDTO extends BaseDTO { |
39 | 38 | private String[] organizationIds; |
40 | 39 | |
41 | 40 | @ApiModelProperty(value = "角色ids") |
42 | - private List<String> roleIds; | |
41 | + private String[] roleIds; | |
43 | 42 | |
44 | 43 | @ApiModelProperty(value = "电话号码") |
45 | 44 | @NotEmpty(message = "电话号码不能为空或字符串", groups = AddGroup.class) | ... | ... |
... | ... | @@ -50,11 +50,10 @@ public class SysMenuServiceImpl extends AbstractBaseService<MenuMapper, SysMenuE |
50 | 50 | List<MenuDTO> menuDTOs; |
51 | 51 | if (isSysAdminOrPtAdmin) { |
52 | 52 | menuDTOs = baseMapper.selectSysAdminMenu(); |
53 | - } else { | |
54 | - menuDTOs = baseMapper.selectMyMenu(userId); | |
55 | - } | |
56 | - if (isTenantAdmin && menuDTOs ==null) { | |
53 | + } else if (isTenantAdmin) { | |
57 | 54 | menuDTOs = baseMapper.selectTenantMenu(tenantId); |
55 | + } else { | |
56 | + menuDTOs = baseMapper.selectMyMenu(userId); | |
58 | 57 | } |
59 | 58 | Map<String, MenuDTO> menuDTOMap = new LinkedHashMap<>(menuDTOs.size()); |
60 | 59 | menuDTOs.forEach(menuDTO -> menuDTOMap.put(menuDTO.getId(), menuDTO)); | ... | ... |
... | ... | @@ -110,22 +110,20 @@ public class SysRoleServiceImpl extends AbstractBaseService<RoleMapper, SysRoleE |
110 | 110 | cacheUtils.get(FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY, cacheKey); |
111 | 111 | cachePresent = optionalPermission.isPresent(); |
112 | 112 | allPermission = optionalPermission.orElseGet(menuMapper::getAllPermission); |
113 | - } else { | |
114 | - cacheKey = FastIotConstants.CacheConfigKey.USER_PERMISSION_PREFIX + useerId; | |
113 | + } else if (isTenantAdmin) { | |
114 | + cacheKey = FastIotConstants.CacheConfigKey.USER_PERMISSION_PREFIX + tenantId; | |
115 | 115 | Optional<Set<String>> optionalPermission = |
116 | 116 | cacheUtils.get(FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY, cacheKey); |
117 | 117 | cachePresent = optionalPermission.isPresent(); |
118 | 118 | allPermission = |
119 | - optionalPermission.orElseGet(() -> menuMapper.getAllPermissionsByUserId(useerId)); | |
120 | - } | |
121 | - /**租户管理员未获取到用户权限时,默认使用租户的权限*/ | |
122 | - if (isTenantAdmin && allPermission.isEmpty()) { | |
123 | - cacheKey = FastIotConstants.CacheConfigKey.USER_PERMISSION_PREFIX + tenantId; | |
119 | + optionalPermission.orElseGet(() -> menuMapper.getAllPermissionsByTenantId(tenantId)); | |
120 | + } else { | |
121 | + cacheKey = FastIotConstants.CacheConfigKey.USER_PERMISSION_PREFIX + useerId; | |
124 | 122 | Optional<Set<String>> optionalPermission = |
125 | 123 | cacheUtils.get(FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY, cacheKey); |
126 | 124 | cachePresent = optionalPermission.isPresent(); |
127 | 125 | allPermission = |
128 | - optionalPermission.orElseGet(() -> menuMapper.getAllPermissionsByTenantId(tenantId)); | |
126 | + optionalPermission.orElseGet(() -> menuMapper.getAllPermissionsByUserId(useerId)); | |
129 | 127 | } |
130 | 128 | if (cachePresent) { |
131 | 129 | return allPermission; | ... | ... |
... | ... | @@ -130,7 +130,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
130 | 130 | SysUserRoleEntity userRole = new SysUserRoleEntity(); |
131 | 131 | userRole.setUserId(user.getId()); |
132 | 132 | userRole.setRoleId(roleId); |
133 | -// userRoleMapper.insert(userRole); | |
133 | + userRoleMapper.insert(userRole); | |
134 | 134 | } |
135 | 135 | // 绑定用户和组织的关系 |
136 | 136 | organizationService.bindUserToOrganization( |
... | ... | @@ -311,11 +311,9 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
311 | 311 | } |
312 | 312 | baseMapper.updateById(user); |
313 | 313 | if (null != userDTO.getRoleIds()) { |
314 | - deleteAndAddUserRole(user.getId(), userDTO.getRoleIds()); | |
315 | - } | |
316 | - if (null != userDTO.getOrganizationIds()) { | |
314 | + deleteAndAddUserRole(user.getId(), Arrays.asList(userDTO.getRoleIds())); | |
317 | 315 | userOrganizationMappingService.addOrUpdateUserOrganizationMapping( |
318 | - user.getId(), Arrays.asList(userDTO.getOrganizationIds()), true); | |
316 | + user.getId(), Arrays.asList(userDTO.getOrganizationIds()), true); | |
319 | 317 | } |
320 | 318 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); |
321 | 319 | return userDTO; |
... | ... | @@ -451,8 +449,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
451 | 449 | } |
452 | 450 | baseMapper.insert(user); |
453 | 451 | List<SysTenantRoleEntity> tenantRoleList = validateTenantRole(userDTO.getTenantId()); |
454 | - for (String roleId : userDTO.getRoleIds()) { | |
455 | - roleMapper.saveUserRoleMapping(user.getId(), roleId); | |
452 | + for (SysTenantRoleEntity tenantRole : tenantRoleList) { | |
453 | + roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); | |
456 | 454 | } |
457 | 455 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); |
458 | 456 | return userDTO; |
... | ... | @@ -600,9 +598,6 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
600 | 598 | .stream() |
601 | 599 | .map(SysUserRoleEntity::getRoleId) |
602 | 600 | .collect(Collectors.toList()); |
603 | - if(roleIds.isEmpty()){ | |
604 | - roleIds.add(UUID.randomUUID().toString()); | |
605 | - } | |
606 | 601 | List<String> enableRoles = |
607 | 602 | roleMapper |
608 | 603 | .selectList( | ... | ... |