...
|
...
|
@@ -70,9 +70,9 @@ class ReactState { |
70
|
70
|
private final CacheManager cacheManager;
|
71
|
71
|
private final Cache cache;
|
72
|
72
|
private TkDeviceService ytDeviceService;
|
73
|
|
- private String triggerDevicesKey = "triggerDevices";
|
|
73
|
+ private String triggerDevicesKey;
|
74
|
74
|
|
75
|
|
- private String currentAlarmsKey = "currentAlarms";
|
|
75
|
+ private String currentAlarmsKey;
|
76
|
76
|
|
77
|
77
|
ReactState(String reactId, TbContext ctx, TbSceneReactNodeConfig config) {
|
78
|
78
|
this.reactId = reactId;
|
...
|
...
|
@@ -95,10 +95,12 @@ class ReactState { |
95
|
95
|
this.noticeService = SpringBeanUtils.getBean(TkNoticeService.class);
|
96
|
96
|
this.ytDeviceService = SpringBeanUtils.getBean(TkDeviceService.class);
|
97
|
97
|
this.cache = cacheManager.getCache(FastIotConstants.CacheConfigKey.SCENE_REACT);
|
|
98
|
+ this.triggerDevicesKey = reactId+ "_triggerDevices";
|
|
99
|
+ this.currentAlarmsKey = reactId+ "_currentAlarms";
|
98
|
100
|
this.triggerDevices = null == cache.get(triggerDevicesKey)?
|
99
|
|
- new ConcurrentHashMap<>():cache.get("triggerDevices",ConcurrentHashMap.class);
|
|
101
|
+ new ConcurrentHashMap<>():cache.get(triggerDevicesKey,ConcurrentHashMap.class);
|
100
|
102
|
this.currentAlarms = null == cache.get(currentAlarmsKey)?
|
101
|
|
- new ConcurrentHashMap<>():cache.get("triggerDevices",ConcurrentHashMap.class);
|
|
103
|
+ new ConcurrentHashMap<>():cache.get(currentAlarmsKey,ConcurrentHashMap.class);
|
102
|
104
|
}
|
103
|
105
|
|
104
|
106
|
/**
|
...
|
...
|
@@ -133,7 +135,7 @@ class ReactState { |
133
|
135
|
}else{
|
134
|
136
|
conditionMatched.set(true);
|
135
|
137
|
}
|
136
|
|
- cache.put(triggerDevicesKey,triggerDevices);
|
|
138
|
+
|
137
|
139
|
String msgData = msg.getData();
|
138
|
140
|
if (allowExecuteCondition && conditionMatched.get()) {
|
139
|
141
|
log.debug(String.format("设备【%s】的消息内容【%s】触发动作", deviceId, msgData));
|
...
|
...
|
@@ -213,6 +215,17 @@ class ReactState { |
213
|
215
|
fresh = true;
|
214
|
216
|
}
|
215
|
217
|
triggerResult = triggerState.process(ctx, msg,fresh);
|
|
218
|
+ if(fresh){
|
|
219
|
+ String triggerKey = deviceId + "_" + matchKey.get();
|
|
220
|
+ if(triggerResult){
|
|
221
|
+ //放入满足的触发器信息,设备ID+触发关键字
|
|
222
|
+ triggerDevices.put(triggerKey,
|
|
223
|
+ new TriggerData(msg,detail));
|
|
224
|
+ cache.put(triggerDevicesKey,triggerDevices);
|
|
225
|
+ }else{
|
|
226
|
+ triggerDevices.remove(triggerKey);
|
|
227
|
+ }
|
|
228
|
+ }
|
216
|
229
|
ObjectNode result = triggerState.getRuleState().getDetailInform();
|
217
|
230
|
log.debug(
|
218
|
231
|
String.format(
|
...
|
...
|
@@ -222,7 +235,7 @@ class ReactState { |
222
|
235
|
devId,
|
223
|
236
|
msg.getOriginator(),
|
224
|
237
|
msg.getData()));
|
225
|
|
- if (!result.isEmpty() && triggerResult) {
|
|
238
|
+ if (!result.isEmpty() && triggerResult && fresh) {
|
226
|
239
|
ObjectNode triggerData = JacksonUtil.newObjectNode();
|
227
|
240
|
triggerData.put(FastIotConstants.Scene.TRIGGER_DATA,result);
|
228
|
241
|
detail.set(devId,triggerData);
|
...
|
...
|
@@ -243,9 +256,6 @@ class ReactState { |
243
|
256
|
});
|
244
|
257
|
if(matched){
|
245
|
258
|
triggerMatched.set(matched);
|
246
|
|
- //放入满足的触发器信息,设备ID+触发关键字
|
247
|
|
- triggerDevices.put(deviceId + "_" + matchKey.get(),
|
248
|
|
- new TriggerData(msg,detail));
|
249
|
259
|
}
|
250
|
260
|
});
|
251
|
261
|
});
|
...
|
...
|
|