Commit 907a1201b24d85c7d2386a7f99dd3104ec5a2518
Merge branch '20220920' into 'master'
fix(DEFECT-741): 设备重名提示内容调整 See merge request huang/thingsboard3.3.2!133
Showing
9 changed files
with
31 additions
and
33 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 | ... | ... |
... | ... | @@ -215,6 +215,7 @@ public class YtDeviceProfileController extends BaseController { |
215 | 215 | tbDeviceProfile.setType(DeviceProfileType.DEFAULT); |
216 | 216 | UUID tenantId = UUID.fromString(deviceProfileDTO.getTenantId()); |
217 | 217 | tbDeviceProfile.setTenantId(TenantId.fromUUID(tenantId)); |
218 | + tbDeviceProfile.setDefault(deviceProfileDTO.isDefault()); | |
218 | 219 | |
219 | 220 | // 获取当前租户的默认规则链 |
220 | 221 | if (StringUtils.isNotBlank(deviceProfileDTO.getDefaultRuleChainId())) { | ... | ... |
... | ... | @@ -42,7 +42,7 @@ public class YtNoAuthController{ |
42 | 42 | @PostMapping("/send_login_code/{phoneNumber}") |
43 | 43 | public boolean sendVerificationCode(@PathVariable("phoneNumber") String phoneNumber) { |
44 | 44 | Assert.isTrue( |
45 | - CHINA_MOBILE_PATTERN.matcher(phoneNumber).matches(), "please input correct phone number"); | |
45 | + CHINA_MOBILE_PATTERN.matcher(phoneNumber).matches(), "请输入有效电话号码"); | |
46 | 46 | return smsService.sendSmsCode(phoneNumber, MsgTemplatePurposeEnum.FOR_LOGIN); |
47 | 47 | } |
48 | 48 | ... | ... |
... | ... | @@ -73,7 +73,7 @@ public class YtNoticeController extends BaseController { |
73 | 73 | } |
74 | 74 | |
75 | 75 | @DeleteMapping("delete") |
76 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:notice:delete'})") | |
76 | + @PreAuthorize("@check.checkPermissions({},{'api:yt:notice:delete:delete'})") | |
77 | 77 | @ApiOperation("批量删除") |
78 | 78 | public void delete(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { |
79 | 79 | sysNoticeService.delete(deleteDTO.getIds(), getCurrentUser().getCurrentTenantId()); | ... | ... |
... | ... | @@ -79,6 +79,8 @@ public enum ErrorMessage { |
79 | 79 | TARGET_TEMPLATE_NOT_EXISTS_SELF_NOTICE(400056,"密码重置成功,请自行通知用户!"), |
80 | 80 | ASSERT_DEFAULT_NAME_NO_CHANGED(400056,"系统预制资源,不能修改名称!"), |
81 | 81 | DATA_BOARD_IS_PRIVATE(400057,"该数据看板不是公有视图"), |
82 | + MESSAGE_SEND_TOO_FAST(400058,"1分钟内请求次数过多,请休息一下!"), | |
83 | + PASSWORD_INCORRECT(4010059, "密码错误!"), | |
82 | 84 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
83 | 85 | private final int code; |
84 | 86 | private String message; | ... | ... |
... | ... | @@ -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 | ... | ... |
... | ... | @@ -134,7 +134,7 @@ public class YtSmsServiceImpl implements YtSmsService { |
134 | 134 | }) |
135 | 135 | .orElse(true); |
136 | 136 | if (!canSend) { |
137 | - return false; | |
137 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_SEND_TOO_FAST.getMessage()); | |
138 | 138 | } |
139 | 139 | List<MessageTemplate> messageTemplates = |
140 | 140 | messageTemplateMapper.selectList( | ... | ... |
... | ... | @@ -693,7 +693,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
693 | 693 | // 判断用户密码是否正确 |
694 | 694 | boolean isMatch = passwordEncoder.matches(accountReqDTO.getPassword(), user.getPassword()); |
695 | 695 | if (!isMatch) { |
696 | - throw new YtDataValidationException(ErrorMessage.USERNAME_PASSWORD_INCORRECT.getMessage()); | |
696 | + throw new YtDataValidationException(ErrorMessage.PASSWORD_INCORRECT.getMessage()); | |
697 | 697 | } |
698 | 698 | user.setPassword(accountReqDTO.getResetPassword()); |
699 | 699 | } | ... | ... |
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 | ... | ... |