|
@@ -18,6 +18,7 @@ import org.springframework.security.access.AccessDeniedException; |
|
@@ -18,6 +18,7 @@ import org.springframework.security.access.AccessDeniedException; |
18
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
18
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
19
|
import org.springframework.stereotype.Service;
|
19
|
import org.springframework.stereotype.Service;
|
20
|
import org.springframework.transaction.annotation.Transactional;
|
20
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
21
|
+import org.thingsboard.server.common.data.User;
|
21
|
import org.thingsboard.server.common.data.id.EntityId;
|
22
|
import org.thingsboard.server.common.data.id.EntityId;
|
22
|
import org.thingsboard.server.common.data.id.TenantId;
|
23
|
import org.thingsboard.server.common.data.id.TenantId;
|
23
|
import org.thingsboard.server.common.data.id.UserId;
|
24
|
import org.thingsboard.server.common.data.id.UserId;
|
|
@@ -82,6 +83,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
|
@@ -82,6 +83,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
82
|
private final AccountProperties accountProperties;
|
83
|
private final AccountProperties accountProperties;
|
83
|
|
84
|
|
84
|
private final TenantMapper tenantMapper;
|
85
|
private final TenantMapper tenantMapper;
|
|
|
86
|
+ private final TkCustomerDevice tkCustomerDevice;
|
85
|
|
87
|
|
86
|
@Override
|
88
|
@Override
|
87
|
public List<UserDetailsDTO> findUserDetailsByUsername(String username, String tenantId) {
|
89
|
public List<UserDetailsDTO> findUserDetailsByUsername(String username, String tenantId) {
|
|
@@ -299,6 +301,31 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
|
@@ -299,6 +301,31 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
299
|
if (!user.getUsername().equals(userDTO.getUsername())) {
|
301
|
if (!user.getUsername().equals(userDTO.getUsername())) {
|
300
|
throw new TkDataValidationException(ErrorMessage.USERNAME_IS_IMMUTABLE.getMessage());
|
302
|
throw new TkDataValidationException(ErrorMessage.USERNAME_IS_IMMUTABLE.getMessage());
|
301
|
}
|
303
|
}
|
|
|
304
|
+
|
|
|
305
|
+ boolean difference = false;
|
|
|
306
|
+ //判断客户组织是否有变化
|
|
|
307
|
+ List<String> newList = List.of(userDTO.getOrganizationIds());
|
|
|
308
|
+ List<String> oldList = userOrganizationMappingService.getOrganizationIdsByUserId(userDTO.getId());
|
|
|
309
|
+ if(newList.size()!=oldList.size()){
|
|
|
310
|
+ difference = true;
|
|
|
311
|
+ }
|
|
|
312
|
+ if(!difference) {
|
|
|
313
|
+ List<String> differenceList = newList.stream()
|
|
|
314
|
+ .filter(element -> !oldList.contains(element))
|
|
|
315
|
+ .collect(Collectors.toList());
|
|
|
316
|
+ if (null != differenceList && !differenceList.isEmpty()) {
|
|
|
317
|
+ difference = true;
|
|
|
318
|
+ }
|
|
|
319
|
+ }
|
|
|
320
|
+ //有变化则查询该客户是否分配设备 分配设备则不允许修改
|
|
|
321
|
+ if(difference){
|
|
|
322
|
+ User tbuser = tbUserService.findUserById(new TenantId(UUID.fromString(tenantId)), new UserId(UUID.fromString(user.getTbUser())));
|
|
|
323
|
+ List<TkCustomerDeviceDTO> dtolist = tkCustomerDevice.getMappingByCustomerId(tbuser.getCustomerId().toString());
|
|
|
324
|
+ if(null != dtolist&&!dtolist.isEmpty()){
|
|
|
325
|
+ throw new TkDataValidationException(ErrorMessage.CUSTOMER_USER_UPDATE_ERROR.getMessage());
|
|
|
326
|
+ }
|
|
|
327
|
+ }
|
|
|
328
|
+
|
302
|
validateUserNameAndPhoneNumberAndEmail(userDTO);
|
329
|
validateUserNameAndPhoneNumberAndEmail(userDTO);
|
303
|
user.setRealName(userDTO.getRealName());
|
330
|
user.setRealName(userDTO.getRealName());
|
304
|
user.setEnabled(userDTO.isEnabled());
|
331
|
user.setEnabled(userDTO.isEnabled());
|