Commit edb11b9555700f953c6693614c6c3986b3b2c2f3

Authored by 云中非
1 parent 7dc9bc93

refactor: 场景联动新增关联关系

1、告警创建
2、告警清除
... ... @@ -301,7 +301,7 @@ class ReactState {
301 301 currentAlarm = ctx.getAlarmService().createOrUpdateAlarm(currentAlarm);
302 302 ytDeviceService.freshAlarmStatus(entityId, 1);
303 303 currentAlarms.put(deviceId, currentAlarm);
304   -
  304 + alarmMsg(ctx, msg, currentAlarm, "Alarm Cleared");
305 305
306 306 AlarmInfoDTO formData = new AlarmInfoDTO();
307 307 formData.setDeviceName(msg.getMetaData().getData().get("deviceName"));
... ... @@ -322,10 +322,20 @@ class ReactState {
322 322 if (clearState.process(ctx, msg)) {
323 323 ctx.getAlarmService().clearAlarmForResult(ctx.getTenantId(), currentAlarms.get(deviceId).getId(), null, System.currentTimeMillis());
324 324 ytDeviceService.freshAlarmStatus(new DeviceId(UUID.fromString(deviceId)), 0);
  325 + alarmMsg(ctx, msg, currentAlarms.get(deviceId), "Alarm Cleared");
325 326 currentAlarms.remove(deviceId);
326 327 }
327 328 }
328 329
  330 + private void alarmMsg(TbContext ctx, TbMsg msg,Alarm alarm,String releationType) {
  331 + String lastMsgQueueName = msg.getQueueName();
  332 + TbMsgMetaData metaData = msg.getMetaData();
  333 + String data = JacksonUtil.valueToTree(alarm).toString();
  334 + TbMsg newMsg = ctx.newMsg(lastMsgQueueName != null ? lastMsgQueueName : ServiceQueue.MAIN, "ALARM",
  335 + alarm.getOriginator(), msg != null ? msg.getCustomerId() : null, metaData, data);
  336 + ctx.enqueueForTellNext(newMsg, releationType);
  337 + }
  338 +
329 339
330 340 private void reactMsg(TbContext ctx, TbMsg msg, DoAction action) {
331 341 //TODO: 场景联动关联消息通知
... ...
... ... @@ -42,7 +42,7 @@ import java.util.concurrent.ExecutionException;
42 42 type = ComponentType.FILTER,
43 43 name = "scene react",
44 44 configClazz = TbCheckAlarmStatusNodeConfig.class,
45   - relationTypes = {"Message", "RPC Request"},
  45 + relationTypes = {"Message","Alarm Created", "Alarm Updated", "RPC Request"},
46 46 nodeDescription = "基于业务场景,实现设备的交互控制。",
47 47 nodeDetails = "基于业务场景,实现设备的交互控制。",
48 48 uiResources = {"static/rulenode/rulenode-core-config.js"},
... ...