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