|
@@ -429,7 +429,25 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public DeviceDTO updateDevice(UpdateDeviceParams params) {
|
|
|
- //1.校验设备是否存在
|
|
|
+
|
|
|
+ // 1.参数范围大小校验
|
|
|
+ if (params.getXxEnd().compareTo(params.getXxStart()) <= 0 || params.getYyEnd().compareTo(params.getYyStart()) <= 0) {
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_PARAM_ERROR.getErrorCode(), ErrorEnum.DEVICE_PARAM_ERROR.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BigDecimal> validAngles = Arrays.asList(
|
|
|
+ BigDecimal.ZERO,
|
|
|
+ BigDecimal.valueOf(90),
|
|
|
+ BigDecimal.valueOf(180),
|
|
|
+ BigDecimal.valueOf(270)
|
|
|
+ );
|
|
|
+ boolean valid = validAngles.stream()
|
|
|
+ .anyMatch(angle -> angle.compareTo(params.getNorthAngle()) == 0);
|
|
|
+ if (!valid) {
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_PARAM_ERROR.getErrorCode(), ErrorEnum.DEVICE_PARAM_ERROR.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.校验设备是否存在
|
|
|
DevInfo devInfo = devInfoService.getOne(
|
|
|
Wrappers.<DevInfo>lambdaQuery()
|
|
|
.eq(DevInfo::getClientId, params.getClientId()));
|
|
@@ -437,12 +455,12 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- //2.校验是否为主绑人
|
|
|
+ //3.校验是否为主绑人
|
|
|
if (!devInfo.getUserId().equals(params.getUserId())) {
|
|
|
throw new BizException(ErrorEnum.USER_NO_PERMISSION.getErrorCode(), ErrorEnum.USER_NO_PERMISSION.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- //3.更新数据
|
|
|
+ //4.更新数据
|
|
|
|
|
|
boolean updated = devInfoService.updateDevice(devInfo.getClientId(), params);
|
|
|
if (!updated) {
|
|
@@ -452,10 +470,10 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
|
logService.saveLog(OprLogType.UPDATE_DEVICE.getCode(), params);
|
|
|
|
|
|
- //4.通过MQTT把信息参数发送到设备
|
|
|
+ //5.通过MQTT把信息参数发送到设备
|
|
|
mqttSend.sendDeviceParamsToMqtt(devInfo.getClientId(), params);
|
|
|
|
|
|
- //5.重新从数据库获取最新的设备信息,确保返回的数据完整
|
|
|
+ //6.重新从数据库获取最新的设备信息,确保返回的数据完整
|
|
|
DevInfo updatedDevInfo = devInfoService.getOne(
|
|
|
Wrappers.<DevInfo>lambdaQuery()
|
|
|
.eq(DevInfo::getClientId, params.getClientId()));
|
|
@@ -463,7 +481,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- //6.将查询到的完整设备数据复制到 DeviceDTO 返还前端
|
|
|
+ //7.将查询到的完整设备数据复制到 DeviceDTO 返还前端
|
|
|
DeviceDTO dto = new DeviceDTO();
|
|
|
BeanUtils.copyProperties(updatedDevInfo, dto);
|
|
|
return dto;
|