Commit c6b0188391a52598c54b599fe27416ae62edb1d2
1 parent
51a18c77
fix: 租户管理员修改失败的BUG,租户管理员修改时不调用TB,只有新增才调用
Showing
3 changed files
with
18 additions
and
11 deletions
@@ -142,7 +142,8 @@ public class YtUserController extends BaseController { | @@ -142,7 +142,8 @@ public class YtUserController extends BaseController { | ||
142 | // 创建CUSTOMER_USER用户 | 142 | // 创建CUSTOMER_USER用户 |
143 | Customer customer = createCustomer(userDTO.getUsername()); | 143 | Customer customer = createCustomer(userDTO.getUsername()); |
144 | // 创建CUSTOMER_USER的管理员 | 144 | // 创建CUSTOMER_USER的管理员 |
145 | - User tbUser = createTBUser(userDTO,customer.getTenantId(),customer.getId(), Authority.CUSTOMER_USER); | 145 | + User tbUser = new User(); |
146 | + tbUser = createTBUser(tbUser,userDTO,customer.getTenantId(),customer.getId(), Authority.CUSTOMER_USER); | ||
146 | // 激活CUSTOMER_USER的管理员 | 147 | // 激活CUSTOMER_USER的管理员 |
147 | activeTBUser(tbUser.getId()); | 148 | activeTBUser(tbUser.getId()); |
148 | } | 149 | } |
@@ -167,9 +168,13 @@ public class YtUserController extends BaseController { | @@ -167,9 +168,13 @@ public class YtUserController extends BaseController { | ||
167 | try { | 168 | try { |
168 | // 创建TB的租户管理员 | 169 | // 创建TB的租户管理员 |
169 | CustomerId customerId = new CustomerId(EntityId.NULL_UUID); | 170 | CustomerId customerId = new CustomerId(EntityId.NULL_UUID); |
170 | - User tbUser = createTBUser(userDTO, tenantId,customerId, Authority.TENANT_ADMIN); | ||
171 | - // 激活租户管理员 | ||
172 | - activeTBUser(tbUser.getId()); | 171 | + User tbUser = new User(); |
172 | + //只有新增才调用TB | ||
173 | + if(null == userDTO.getId()){ | ||
174 | + tbUser = createTBUser(tbUser,userDTO, tenantId,customerId, Authority.TENANT_ADMIN); | ||
175 | + // 激活租户管理员 | ||
176 | + activeTBUser(tbUser.getId()); | ||
177 | + } | ||
173 | } catch (Exception e) { | 178 | } catch (Exception e) { |
174 | throw handleException(e); | 179 | throw handleException(e); |
175 | } | 180 | } |
@@ -316,10 +321,9 @@ public class YtUserController extends BaseController { | @@ -316,10 +321,9 @@ public class YtUserController extends BaseController { | ||
316 | * @return 用户 | 321 | * @return 用户 |
317 | * @throws ThingsboardException tb运行异常 | 322 | * @throws ThingsboardException tb运行异常 |
318 | */ | 323 | */ |
319 | - private User createTBUser(UserDTO userDTO, TenantId tenantId, CustomerId customerId, Authority authority) | 324 | + private User createTBUser(User tbUser,UserDTO userDTO, TenantId tenantId, CustomerId customerId, Authority authority) |
320 | throws ThingsboardException { | 325 | throws ThingsboardException { |
321 | try { | 326 | try { |
322 | - User tbUser = new User(); | ||
323 | tbUser.setAuthority(authority); | 327 | tbUser.setAuthority(authority); |
324 | tbUser.setTenantId(tenantId); | 328 | tbUser.setTenantId(tenantId); |
325 | tbUser.setCustomerId(customerId); | 329 | tbUser.setCustomerId(customerId); |
@@ -32,6 +32,7 @@ public enum ErrorMessage { | @@ -32,6 +32,7 @@ public enum ErrorMessage { | ||
32 | USER_NAME_ALREADY_EXISTS(400013,"用户名已存在"), | 32 | USER_NAME_ALREADY_EXISTS(400013,"用户名已存在"), |
33 | DATA_ALREADY_EXISTS(400014,"数据已存在,无需重复添加"), | 33 | DATA_ALREADY_EXISTS(400014,"数据已存在,无需重复添加"), |
34 | USER_NOT_EXISTS(400015,"用户不存在"), | 34 | USER_NOT_EXISTS(400015,"用户不存在"), |
35 | + USERNAME_IS_IMMUTABLE(400016,"用户账号不可变"), | ||
35 | HAVE_NO_PERMISSION(500002,"没有修改权限"); | 36 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
36 | private final int code; | 37 | private final int code; |
37 | private String message; | 38 | private String message; |
@@ -229,7 +229,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | @@ -229,7 +229,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | ||
229 | throw new NoneTenantAssetException("this user not belong to current tenant"); | 229 | throw new NoneTenantAssetException("this user not belong to current tenant"); |
230 | } | 230 | } |
231 | if (!user.getUsername().equals(userDTO.getUsername())) { | 231 | if (!user.getUsername().equals(userDTO.getUsername())) { |
232 | - throw new YtDataValidationException("username is immutable"); | 232 | + throw new YtDataValidationException(ErrorMessage.USERNAME_IS_IMMUTABLE.getMessage()); |
233 | } | 233 | } |
234 | validateUserNameAndPhoneNumberAndEmail(userDTO); | 234 | validateUserNameAndPhoneNumberAndEmail(userDTO); |
235 | user.setRealName(userDTO.getRealName()); | 235 | user.setRealName(userDTO.getRealName()); |
@@ -237,13 +237,15 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | @@ -237,13 +237,15 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | ||
237 | user.setPhoneNumber(userDTO.getPhoneNumber()); | 237 | user.setPhoneNumber(userDTO.getPhoneNumber()); |
238 | user.setEmail(userDTO.getEmail()); | 238 | user.setEmail(userDTO.getEmail()); |
239 | user.setAccountExpireTime(userDTO.getAccountExpireTime()); | 239 | user.setAccountExpireTime(userDTO.getAccountExpireTime()); |
240 | - if (!userDTO.getPassword().equals("******")) { | 240 | + if (userDTO.getPassword() !=null && !userDTO.getPassword().equals("******")) { |
241 | user.setPassword(passwordEncoder.encode(userDTO.getPassword())); | 241 | user.setPassword(passwordEncoder.encode(userDTO.getPassword())); |
242 | } | 242 | } |
243 | baseMapper.updateById(user); | 243 | baseMapper.updateById(user); |
244 | - deleteAndAddUserRole(user.getId(), Arrays.asList(userDTO.getRoleIds())); | ||
245 | - userOrganizationMappingService.addOrUpdateUserOrganizationMapping( | ||
246 | - user.getId(), Arrays.asList(userDTO.getOrganizationIds()), true); | 244 | + if(null != userDTO.getRoleIds()){ |
245 | + deleteAndAddUserRole(user.getId(), Arrays.asList(userDTO.getRoleIds())); | ||
246 | + userOrganizationMappingService.addOrUpdateUserOrganizationMapping( | ||
247 | + user.getId(), Arrays.asList(userDTO.getOrganizationIds()), true); | ||
248 | + } | ||
247 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); | 249 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); |
248 | return userDTO; | 250 | return userDTO; |
249 | } | 251 | } |