Commit 5c32456c968bdc65c385e7324220c567048ebd71
1 parent
d1d067bc
fix(DEFECT-741): 设备重名提示内容调整
1、新增设备时,设备名称已存在 2、编辑设备时,设备名称已存在
Showing
3 changed files
with
24 additions
and
29 deletions
@@ -68,10 +68,9 @@ public class YtDeviceController extends BaseController { | @@ -68,10 +68,9 @@ public class YtDeviceController extends BaseController { | ||
68 | @Validated(AddGroup.class) @RequestBody DeviceDTO deviceDTO) | 68 | @Validated(AddGroup.class) @RequestBody DeviceDTO deviceDTO) |
69 | throws ThingsboardException, ExecutionException, InterruptedException { | 69 | throws ThingsboardException, ExecutionException, InterruptedException { |
70 | String currentTenantId = getCurrentUser().getCurrentTenantId(); | 70 | String currentTenantId = getCurrentUser().getCurrentTenantId(); |
71 | - boolean enable = deviceService.validateFormdata(currentTenantId, deviceDTO); | ||
72 | - if (!enable) { | ||
73 | - ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); | ||
74 | - } | 71 | + deviceService.validateFormdata(currentTenantId, deviceDTO); |
72 | + | ||
73 | + | ||
75 | DeviceDTO newDeviceDTO = null; | 74 | DeviceDTO newDeviceDTO = null; |
76 | boolean isIncludeRelation = false; | 75 | boolean isIncludeRelation = false; |
77 | 76 |
@@ -3,7 +3,6 @@ package org.thingsboard.server.dao.yunteng.impl; | @@ -3,7 +3,6 @@ package org.thingsboard.server.dao.yunteng.impl; | ||
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
5 | import com.baomidou.mybatisplus.core.metadata.IPage; | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
6 | -import com.fasterxml.jackson.databind.JsonNode; | ||
7 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
8 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
9 | import org.apache.commons.lang3.StringUtils; | 8 | import org.apache.commons.lang3.StringUtils; |
@@ -13,7 +12,6 @@ import org.springframework.stereotype.Service; | @@ -13,7 +12,6 @@ import org.springframework.stereotype.Service; | ||
13 | import org.springframework.transaction.annotation.Transactional; | 12 | import org.springframework.transaction.annotation.Transactional; |
14 | import org.thingsboard.common.util.JacksonUtil; | 13 | import org.thingsboard.common.util.JacksonUtil; |
15 | import org.thingsboard.server.common.data.DeviceProfile; | 14 | import org.thingsboard.server.common.data.DeviceProfile; |
16 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
17 | import org.thingsboard.server.common.data.id.EntityId; | 15 | import org.thingsboard.server.common.data.id.EntityId; |
18 | import org.thingsboard.server.common.data.id.TenantId; | 16 | import org.thingsboard.server.common.data.id.TenantId; |
19 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 17 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
@@ -34,9 +32,7 @@ import org.thingsboard.server.dao.yunteng.mapper.*; | @@ -34,9 +32,7 @@ import org.thingsboard.server.dao.yunteng.mapper.*; | ||
34 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 32 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
35 | import org.thingsboard.server.dao.yunteng.service.YtDeviceService; | 33 | import org.thingsboard.server.dao.yunteng.service.YtDeviceService; |
36 | 34 | ||
37 | -import java.time.Instant; | ||
38 | import java.time.LocalDateTime; | 35 | import java.time.LocalDateTime; |
39 | -import java.time.ZoneOffset; | ||
40 | import java.util.*; | 36 | import java.util.*; |
41 | import java.util.stream.Collectors; | 37 | import java.util.stream.Collectors; |
42 | 38 | ||
@@ -92,25 +88,22 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -92,25 +88,22 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
92 | } | 88 | } |
93 | 89 | ||
94 | @Override | 90 | @Override |
95 | - public boolean validateFormdata(String currentTenantId, DeviceDTO deviceDTO) { | 91 | + public void validateFormdata(String currentTenantId, DeviceDTO deviceDTO) { |
96 | boolean insert = StringUtils.isBlank(deviceDTO.getId()); | 92 | boolean insert = StringUtils.isBlank(deviceDTO.getId()); |
97 | String deviceTenantId = deviceDTO.getTenantId(); | 93 | String deviceTenantId = deviceDTO.getTenantId(); |
98 | if (StringUtils.isBlank(deviceDTO.getName())) { | 94 | if (StringUtils.isBlank(deviceDTO.getName())) { |
99 | - throw new YtDataValidationException("device name cannot be blank"); | 95 | + throw new YtDataValidationException("设备名称不能为空"); |
100 | } | 96 | } |
101 | // validate IOT DB | 97 | // validate IOT DB |
102 | if (StringUtils.isBlank(deviceDTO.getProfileId())) { | 98 | if (StringUtils.isBlank(deviceDTO.getProfileId())) { |
103 | - throw new YtDataValidationException("device profile cannot be blank"); | 99 | + throw new YtDataValidationException("设备配置不能为空"); |
104 | } | 100 | } |
105 | 101 | ||
106 | // 验证设备名称是否已经存在 如果此处直接使用deviceDTO 将有误 | 102 | // 验证设备名称是否已经存在 如果此处直接使用deviceDTO 将有误 |
103 | + if (deviceNameUsed(currentTenantId, deviceDTO.getName(),deviceDTO.getId())) { | ||
104 | + throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | ||
105 | + } | ||
107 | if (insert) { | 106 | if (insert) { |
108 | - DeviceDTO check = new DeviceDTO(); | ||
109 | - check.setName(deviceDTO.getName()); | ||
110 | - if (findTbDeviceId(deviceTenantId, check).size() > 0) { | ||
111 | - throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | ||
112 | - } | ||
113 | - | ||
114 | deviceTenantId = currentTenantId; | 107 | deviceTenantId = currentTenantId; |
115 | deviceDTO.setTenantId(currentTenantId); | 108 | deviceDTO.setTenantId(currentTenantId); |
116 | } else { | 109 | } else { |
@@ -127,6 +120,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -127,6 +120,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
127 | sceneNotUsed(currentTenantId, deviceDTO.getTbDeviceId(), oldOrganizationId); | 120 | sceneNotUsed(currentTenantId, deviceDTO.getTbDeviceId(), oldOrganizationId); |
128 | } | 121 | } |
129 | } | 122 | } |
123 | + | ||
130 | // 验证数据profileId的正确性 | 124 | // 验证数据profileId的正确性 |
131 | TenantId id = TenantId.fromUUID(UUID.fromString(deviceTenantId)); | 125 | TenantId id = TenantId.fromUUID(UUID.fromString(deviceTenantId)); |
132 | DeviceProfile deviceProfile = | 126 | DeviceProfile deviceProfile = |
@@ -137,7 +131,6 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -137,7 +131,6 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
137 | } else if (!organization.getTenantId().equals(deviceTenantId)) { | 131 | } else if (!organization.getTenantId().equals(deviceTenantId)) { |
138 | throw new YtDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | 132 | throw new YtDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); |
139 | } | 133 | } |
140 | - return true; | ||
141 | } | 134 | } |
142 | 135 | ||
143 | /** | 136 | /** |
@@ -367,17 +360,21 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -367,17 +360,21 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
367 | } | 360 | } |
368 | 361 | ||
369 | @Override | 362 | @Override |
370 | - public List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO) { | 363 | + public boolean deviceNameUsed(String tenantId, String deviceName,String deviceId) { |
371 | List<YtDevice> deviceList = | 364 | List<YtDevice> deviceList = |
372 | - baseMapper.selectList( | ||
373 | - new QueryWrapper<YtDevice>() | 365 | + baseMapper.selectList(new QueryWrapper<YtDevice>() |
374 | .lambda() | 366 | .lambda() |
375 | .eq(true, YtDevice::getTenantId, tenantId) | 367 | .eq(true, YtDevice::getTenantId, tenantId) |
376 | - .eq( | ||
377 | - StringUtils.isNotBlank(deviceDTO.getName()), | ||
378 | - YtDevice::getName, | ||
379 | - deviceDTO.getName())); | ||
380 | - return ReflectUtils.sourceToTarget(deviceList, DeviceDTO.class); | 368 | + .eq(YtDevice::getName,deviceName)); |
369 | + for(YtDevice dev: deviceList){ | ||
370 | + if(deviceName.equals(dev.getName()) | ||
371 | + && (StringUtils.isEmpty(deviceId) || !deviceId.equals(dev.getId())) | ||
372 | + ){ | ||
373 | + return true; | ||
374 | + } | ||
375 | + } | ||
376 | + | ||
377 | + return false; | ||
381 | } | 378 | } |
382 | 379 | ||
383 | @Override | 380 | @Override |
1 | package org.thingsboard.server.dao.yunteng.service; | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | ||
3 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
4 | import org.thingsboard.server.common.data.id.EntityId; | 3 | import org.thingsboard.server.common.data.id.EntityId; |
5 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
6 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | 5 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
@@ -30,7 +29,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { | @@ -30,7 +29,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { | ||
30 | * | 29 | * |
31 | * @param ytDevice | 30 | * @param ytDevice |
32 | */ | 31 | */ |
33 | - boolean validateFormdata(String currentTenantId, DeviceDTO ytDevice); | 32 | + void validateFormdata(String currentTenantId, DeviceDTO ytDevice); |
34 | 33 | ||
35 | /** | 34 | /** |
36 | * 查询所有的设备信息 | 35 | * 查询所有的设备信息 |
@@ -38,7 +37,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { | @@ -38,7 +37,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { | ||
38 | * @param deviceDTO 过滤参数 | 37 | * @param deviceDTO 过滤参数 |
39 | * @return List<DeviceDTO> | 38 | * @return List<DeviceDTO> |
40 | */ | 39 | */ |
41 | - List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO); | 40 | + boolean deviceNameUsed(String tenantId, String deviceName,String deviceId); |
42 | 41 | ||
43 | List<String> findTbDeviceId(String tenantId, Set<String> ids); | 42 | List<String> findTbDeviceId(String tenantId, Set<String> ids); |
44 | 43 |