Commit 21e314f0fe94008692147e6d79d84c6a865088a0

Authored by 云中非
1 parent 21d8acfb

fix: 场景联动异常信息

1、场景联动异常信息
2、场景联动所属组织不存在的异常
... ... @@ -45,6 +45,10 @@ public enum ErrorMessage {
45 45 CONTACT_ALREADY_ASSOCIATED(400026,"当前联系人已被设备配置关联"),
46 46 MSG_CODE_NOT_MATCHED(400027,"验证码不正确"),
47 47 ACCOUNT_HAS_EXPIRED(400028,"账号已过期,请联系管理员"),
  48 + ORGANIZATION_NOT_EXTIED(400029,"组织不存在"),
  49 + ORGANIZATION_DEVICE_NOT_MATCHED_IN_TRIGGER(400030,"触发器中存在设备不属于场景联动所在组织"),
  50 + ORGANIZATION_DEVICE_NOT_MATCHED_IN_CONDITION(400031,"执行条件中存在设备不属于场景联动所在组织"),
  51 + ORGANIZATION_DEVICE_NOT_MATCHED_IN_ACTION(400032,"动作中存在设备不属于场景联动所在组织"),
48 52 HAVE_NO_PERMISSION(500002,"没有修改权限");
49 53 private final int code;
50 54 private String message;
... ...
... ... @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
12 12 import org.springframework.transaction.annotation.Transactional;
13 13 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
14 14 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
  15 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
15 16 import org.thingsboard.server.common.data.yunteng.dto.*;
16 17 import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum;
17 18 import org.thingsboard.server.common.data.yunteng.enums.TriggerTypeEnum;
... ... @@ -161,7 +162,7 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap
161 162 continue;
162 163 }
163 164 if (!tbDeviceIds.contains(deviceId)) {
164   - throw new DataValidationException("in trigger ,this device not belong this org");
  165 + throw new YtDataValidationException(ErrorMessage.ORGANIZATION_DEVICE_NOT_MATCHED_IN_TRIGGER.getMessage());
165 166 }
166 167 }
167 168 } else {
... ... @@ -202,7 +203,7 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap
202 203 continue;
203 204 }
204 205 if (!tbDeviceIds.contains(deviceId)) {
205   - throw new DataValidationException("in action ,this device not belong this org ");
  206 + throw new YtDataValidationException(ErrorMessage.ORGANIZATION_DEVICE_NOT_MATCHED_IN_ACTION.getMessage());
206 207 }
207 208 }
208 209 }
... ... @@ -218,6 +219,9 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap
218 219 .map(doActionDTO -> {
219 220 doActionDTO.setTenantId(sceneLinkageDTO.getTenantId());
220 221 doActionDTO.setSceneLinkageId(sceneLinkageDTO.getId());
  222 + StringBuilder contextBuilder = new StringBuilder("{\"method\": \"methodThingskit\",\"params\": ");
  223 + contextBuilder.append(doActionDTO.getDoContext());
  224 + doActionDTO.setDoContext(contextBuilder.toString());
221 225 return doActionDTO.getEntity(DoAction.class);
222 226 })
223 227 .collect(Collectors.toList());
... ... @@ -241,7 +245,7 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap
241 245 continue;
242 246 }
243 247 if (!tbDeviceIds.contains(deviceId)) {
244   - throw new DataValidationException("in condition ,this device not belong this org");
  248 + throw new YtDataValidationException(ErrorMessage.ORGANIZATION_DEVICE_NOT_MATCHED_IN_CONDITION.getMessage());
245 249 }
246 250 }
247 251 }
... ... @@ -345,6 +349,9 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap
345 349 .map(organization -> organization.getId())
346 350 .collect(Collectors.toList());
347 351 // 拿到当前组织ids所包含的设备集合
  352 + if(ids.isEmpty()){
  353 + throw new YtDataValidationException(ErrorMessage.ORGANIZATION_NOT_EXTIED.getMessage());
  354 + }
348 355 List<YtDevice> deviceList =
349 356 deviceMapper.selectList(
350 357 new QueryWrapper<YtDevice>().lambda().in(YtDevice::getOrganizationId, ids));
... ...