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 | 142 | // 创建CUSTOMER_USER用户 |
143 | 143 | Customer customer = createCustomer(userDTO.getUsername()); |
144 | 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 | 147 | // 激活CUSTOMER_USER的管理员 |
147 | 148 | activeTBUser(tbUser.getId()); |
148 | 149 | } |
... | ... | @@ -167,9 +168,13 @@ public class YtUserController extends BaseController { |
167 | 168 | try { |
168 | 169 | // 创建TB的租户管理员 |
169 | 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 | 178 | } catch (Exception e) { |
174 | 179 | throw handleException(e); |
175 | 180 | } |
... | ... | @@ -316,10 +321,9 @@ public class YtUserController extends BaseController { |
316 | 321 | * @return 用户 |
317 | 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 | 325 | throws ThingsboardException { |
321 | 326 | try { |
322 | - User tbUser = new User(); | |
323 | 327 | tbUser.setAuthority(authority); |
324 | 328 | tbUser.setTenantId(tenantId); |
325 | 329 | tbUser.setCustomerId(customerId); | ... | ... |
... | ... | @@ -32,6 +32,7 @@ public enum ErrorMessage { |
32 | 32 | USER_NAME_ALREADY_EXISTS(400013,"用户名已存在"), |
33 | 33 | DATA_ALREADY_EXISTS(400014,"数据已存在,无需重复添加"), |
34 | 34 | USER_NOT_EXISTS(400015,"用户不存在"), |
35 | + USERNAME_IS_IMMUTABLE(400016,"用户账号不可变"), | |
35 | 36 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
36 | 37 | private final int code; |
37 | 38 | private String message; | ... | ... |
... | ... | @@ -229,7 +229,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
229 | 229 | throw new NoneTenantAssetException("this user not belong to current tenant"); |
230 | 230 | } |
231 | 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 | 234 | validateUserNameAndPhoneNumberAndEmail(userDTO); |
235 | 235 | user.setRealName(userDTO.getRealName()); |
... | ... | @@ -237,13 +237,15 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
237 | 237 | user.setPhoneNumber(userDTO.getPhoneNumber()); |
238 | 238 | user.setEmail(userDTO.getEmail()); |
239 | 239 | user.setAccountExpireTime(userDTO.getAccountExpireTime()); |
240 | - if (!userDTO.getPassword().equals("******")) { | |
240 | + if (userDTO.getPassword() !=null && !userDTO.getPassword().equals("******")) { | |
241 | 241 | user.setPassword(passwordEncoder.encode(userDTO.getPassword())); |
242 | 242 | } |
243 | 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 | 249 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); |
248 | 250 | return userDTO; |
249 | 251 | } | ... | ... |