|
@@ -59,9 +59,8 @@ public class TriggerCronTask implements ApplicationContextAware, InitializingBea
|
|
|
|
|
|
|
|
this.setDeviceConsumptionCache(ruleEngine.getId(), ruleEngineDetail);
|
|
this.setDeviceConsumptionCache(ruleEngine.getId(), ruleEngineDetail);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- this.cronTaskManager.performConsumptionTask();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ this.cronTaskManager.performConsumptionTask();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void startCronTask() {
|
|
private void startCronTask() {
|
|
@@ -85,13 +84,25 @@ public class TriggerCronTask implements ApplicationContextAware, InitializingBea
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 与库里的规则详情对齐能耗类设备触发器。去掉/改掉 consumption 时必须 remove,否则 ConsumptionJob 仍用旧缓存。
|
|
|
|
|
+ */
|
|
|
public void setDeviceConsumptionCache(Long ruleEngineId, RuleEngineDetail ruleEngineDetail) {
|
|
public void setDeviceConsumptionCache(Long ruleEngineId, RuleEngineDetail ruleEngineDetail) {
|
|
|
|
|
+ if (ruleEngineId == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
List<DeviceTrigger> deviceTriggers = this.ruleEngineService.getDeviceTriggers(ruleEngineDetail.getTriggers());
|
|
List<DeviceTrigger> deviceTriggers = this.ruleEngineService.getDeviceTriggers(ruleEngineDetail.getTriggers());
|
|
|
- if (deviceTriggers != null && !deviceTriggers.isEmpty()) {
|
|
|
|
|
- List<DeviceTrigger> consumptionTrigger = (List)deviceTriggers.stream().filter((deviceTrigger) -> deviceTrigger.getMethod().equals("consumption")).collect(Collectors.toList());
|
|
|
|
|
- if (!consumptionTrigger.isEmpty()) {
|
|
|
|
|
- this.consumptionTriggerCache.put(ruleEngineId, consumptionTrigger);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (deviceTriggers == null || deviceTriggers.isEmpty()) {
|
|
|
|
|
+ this.consumptionTriggerCache.remove(ruleEngineId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<DeviceTrigger> consumptionTriggers = deviceTriggers.stream()
|
|
|
|
|
+ .filter((t) -> "consumption".equals(t.getMethod()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (consumptionTriggers.isEmpty()) {
|
|
|
|
|
+ this.consumptionTriggerCache.remove(ruleEngineId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.consumptionTriggerCache.put(ruleEngineId, consumptionTriggers);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// List<SpaceTrigger> spaceTriggers = this.ruleEngineService.getSpaceTriggers(ruleEngineDetail.getTriggers());
|
|
// List<SpaceTrigger> spaceTriggers = this.ruleEngineService.getSpaceTriggers(ruleEngineDetail.getTriggers());
|
|
@@ -101,6 +112,12 @@ public class TriggerCronTask implements ApplicationContextAware, InitializingBea
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void removeDeviceConsumptionCache(Long ruleEngineId) {
|
|
|
|
|
+ if (ruleEngineId != null) {
|
|
|
|
|
+ this.consumptionTriggerCache.remove(ruleEngineId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void processCronTask(Long id, Long projectId, Long spaceId, RuleEngineDetail engineDetail, List<CronTrigger> cronTriggers) {
|
|
private void processCronTask(Long id, Long projectId, Long spaceId, RuleEngineDetail engineDetail, List<CronTrigger> cronTriggers) {
|
|
|
List<CronConstraint> cronConstraints = this.ruleEngineService.getCronConstraints(engineDetail.getConstraints());
|
|
List<CronConstraint> cronConstraints = this.ruleEngineService.getCronConstraints(engineDetail.getConstraints());
|
|
|
List<DeviceConstraint> deviceConstraints = this.ruleEngineService.getDeviceConstraints(engineDetail.getConstraints());
|
|
List<DeviceConstraint> deviceConstraints = this.ruleEngineService.getDeviceConstraints(engineDetail.getConstraints());
|