Commit c41990d368aa1eeed800f7b5ee94d633dddf4c61

Authored by chenjunyu_1481036421
1 parent c908161f

feat:编辑客户时判断是否已分配给客户设 有则提示

... ... @@ -139,6 +139,7 @@ public enum ErrorMessage {
139 139 SSRC_NO_ENABLED(400113,"未获取到可用的SSRC资源"),
140 140 TENANT_ERROR(400114,"租户管理员只允许创建一个"),
141 141 DEVICE_CENTER_IS_DISABLED(400115,"设备【%s】未被允许执行任务"),
  142 + CUSTOMER_USER_UPDATE_ERROR(400116,"已分配设备给该客户,请取消分配后重试"),
142 143 HAVE_NO_PERMISSION(500002,"没有修改权限"),
143 144 NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置");
144 145
... ...
... ... @@ -18,6 +18,7 @@ import org.springframework.security.access.AccessDeniedException;
18 18 import org.springframework.security.crypto.password.PasswordEncoder;
19 19 import org.springframework.stereotype.Service;
20 20 import org.springframework.transaction.annotation.Transactional;
  21 +import org.thingsboard.server.common.data.User;
21 22 import org.thingsboard.server.common.data.id.EntityId;
22 23 import org.thingsboard.server.common.data.id.TenantId;
23 24 import org.thingsboard.server.common.data.id.UserId;
... ... @@ -82,6 +83,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE
82 83 private final AccountProperties accountProperties;
83 84
84 85 private final TenantMapper tenantMapper;
  86 + private final TkCustomerDevice tkCustomerDevice;
85 87
86 88 @Override
87 89 public List<UserDetailsDTO> findUserDetailsByUsername(String username, String tenantId) {
... ... @@ -299,6 +301,31 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE
299 301 if (!user.getUsername().equals(userDTO.getUsername())) {
300 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 329 validateUserNameAndPhoneNumberAndEmail(userDTO);
303 330 user.setRealName(userDTO.getRealName());
304 331 user.setEnabled(userDTO.isEnabled());
... ...