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 | 68 | @Validated(AddGroup.class) @RequestBody DeviceDTO deviceDTO) |
69 | 69 | throws ThingsboardException, ExecutionException, InterruptedException { |
70 | 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 | 74 | DeviceDTO newDeviceDTO = null; |
76 | 75 | boolean isIncludeRelation = false; |
77 | 76 | ... | ... |
... | ... | @@ -3,7 +3,6 @@ package org.thingsboard.server.dao.yunteng.impl; |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
5 | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
6 | -import com.fasterxml.jackson.databind.JsonNode; | |
7 | 6 | import lombok.RequiredArgsConstructor; |
8 | 7 | import lombok.extern.slf4j.Slf4j; |
9 | 8 | import org.apache.commons.lang3.StringUtils; |
... | ... | @@ -13,7 +12,6 @@ import org.springframework.stereotype.Service; |
13 | 12 | import org.springframework.transaction.annotation.Transactional; |
14 | 13 | import org.thingsboard.common.util.JacksonUtil; |
15 | 14 | import org.thingsboard.server.common.data.DeviceProfile; |
16 | -import org.thingsboard.server.common.data.id.DeviceId; | |
17 | 15 | import org.thingsboard.server.common.data.id.EntityId; |
18 | 16 | import org.thingsboard.server.common.data.id.TenantId; |
19 | 17 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
... | ... | @@ -34,9 +32,7 @@ import org.thingsboard.server.dao.yunteng.mapper.*; |
34 | 32 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
35 | 33 | import org.thingsboard.server.dao.yunteng.service.YtDeviceService; |
36 | 34 | |
37 | -import java.time.Instant; | |
38 | 35 | import java.time.LocalDateTime; |
39 | -import java.time.ZoneOffset; | |
40 | 36 | import java.util.*; |
41 | 37 | import java.util.stream.Collectors; |
42 | 38 | |
... | ... | @@ -92,25 +88,22 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
92 | 88 | } |
93 | 89 | |
94 | 90 | @Override |
95 | - public boolean validateFormdata(String currentTenantId, DeviceDTO deviceDTO) { | |
91 | + public void validateFormdata(String currentTenantId, DeviceDTO deviceDTO) { | |
96 | 92 | boolean insert = StringUtils.isBlank(deviceDTO.getId()); |
97 | 93 | String deviceTenantId = deviceDTO.getTenantId(); |
98 | 94 | if (StringUtils.isBlank(deviceDTO.getName())) { |
99 | - throw new YtDataValidationException("device name cannot be blank"); | |
95 | + throw new YtDataValidationException("设备名称不能为空"); | |
100 | 96 | } |
101 | 97 | // validate IOT DB |
102 | 98 | if (StringUtils.isBlank(deviceDTO.getProfileId())) { |
103 | - throw new YtDataValidationException("device profile cannot be blank"); | |
99 | + throw new YtDataValidationException("设备配置不能为空"); | |
104 | 100 | } |
105 | 101 | |
106 | 102 | // 验证设备名称是否已经存在 如果此处直接使用deviceDTO 将有误 |
103 | + if (deviceNameUsed(currentTenantId, deviceDTO.getName(),deviceDTO.getId())) { | |
104 | + throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
105 | + } | |
107 | 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 | 107 | deviceTenantId = currentTenantId; |
115 | 108 | deviceDTO.setTenantId(currentTenantId); |
116 | 109 | } else { |
... | ... | @@ -127,6 +120,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
127 | 120 | sceneNotUsed(currentTenantId, deviceDTO.getTbDeviceId(), oldOrganizationId); |
128 | 121 | } |
129 | 122 | } |
123 | + | |
130 | 124 | // 验证数据profileId的正确性 |
131 | 125 | TenantId id = TenantId.fromUUID(UUID.fromString(deviceTenantId)); |
132 | 126 | DeviceProfile deviceProfile = |
... | ... | @@ -137,7 +131,6 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
137 | 131 | } else if (!organization.getTenantId().equals(deviceTenantId)) { |
138 | 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 | 360 | } |
368 | 361 | |
369 | 362 | @Override |
370 | - public List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO) { | |
363 | + public boolean deviceNameUsed(String tenantId, String deviceName,String deviceId) { | |
371 | 364 | List<YtDevice> deviceList = |
372 | - baseMapper.selectList( | |
373 | - new QueryWrapper<YtDevice>() | |
365 | + baseMapper.selectList(new QueryWrapper<YtDevice>() | |
374 | 366 | .lambda() |
375 | 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 | 380 | @Override | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | |
3 | -import org.thingsboard.server.common.data.id.DeviceId; | |
4 | 3 | import org.thingsboard.server.common.data.id.EntityId; |
5 | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
6 | 5 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
... | ... | @@ -30,7 +29,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { |
30 | 29 | * |
31 | 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 | 37 | * @param deviceDTO 过滤参数 |
39 | 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 | 42 | List<String> findTbDeviceId(String tenantId, Set<String> ids); |
44 | 43 | ... | ... |