From edde8b16a618739f7a803b5a86548b9970e3a4cf Mon Sep 17 00:00:00 2001 From: xiwa Date: Mon, 18 Apr 2022 03:20:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9B=91=E5=90=AC=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/iotkit/dao/ThingModelMessageDao.java | 2 +- .../dao/config/ElasticsearchConfiguration.java | 0 doc/ma.png | Bin .../cc/iotkit/ruleengine/action/HttpService.java | 0 .../ruleengine/handler/DeviceMessageHandler.java | 0 .../ruleengine/listener/DeviceCondition.java | 5 +++-- .../ruleengine/listener/DeviceListener.java | 15 +++++++++++++++ .../cc/iotkit/ruleengine/rule/RuleManager.java | 4 ++++ standalone-package/pom.xml | 0 .../resources/assemblies/standalone-package.xml | 0 10 files changed, 23 insertions(+), 3 deletions(-) mode change 100644 => 100755 dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java mode change 100644 => 100755 doc/ma.png mode change 100644 => 100755 rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpService.java mode change 100644 => 100755 rule-engine/src/main/java/cc/iotkit/ruleengine/handler/DeviceMessageHandler.java mode change 100644 => 100755 standalone-package/pom.xml mode change 100644 => 100755 standalone-package/src/main/resources/assemblies/standalone-package.xml diff --git a/dao/src/main/java/cc/iotkit/dao/ThingModelMessageDao.java b/dao/src/main/java/cc/iotkit/dao/ThingModelMessageDao.java index 2b06157f..901712b4 100755 --- a/dao/src/main/java/cc/iotkit/dao/ThingModelMessageDao.java +++ b/dao/src/main/java/cc/iotkit/dao/ThingModelMessageDao.java @@ -35,7 +35,7 @@ public class ThingModelMessageDao { builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier)); } NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(builder) - .withPageable(PageRequest.of(page, size, Sort.by(Sort.Order.desc("time")))) + .withPageable(PageRequest.of(page-1, size, Sort.by(Sort.Order.desc("time")))) .build(); SearchHits result = template.search(query, ThingModelMessage.class); return new Paging<>(result.getTotalHits(), result.getSearchHits().stream() diff --git a/dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java b/dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java old mode 100644 new mode 100755 diff --git a/doc/ma.png b/doc/ma.png old mode 100644 new mode 100755 diff --git a/rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpService.java b/rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpService.java old mode 100644 new mode 100755 diff --git a/rule-engine/src/main/java/cc/iotkit/ruleengine/handler/DeviceMessageHandler.java b/rule-engine/src/main/java/cc/iotkit/ruleengine/handler/DeviceMessageHandler.java old mode 100644 new mode 100755 diff --git a/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java b/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java index 8945ef7a..66693597 100755 --- a/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java +++ b/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java @@ -47,10 +47,11 @@ public class DeviceCondition { if ("*".equals(identifier)) { return true; } - //任意匹配 - if ("*".equals(comparator)) { + //存在参数,值任意匹配 + if (parameter.containsKey(identifier) && "*".equals(comparator)) { return true; } + Object left = parameter.get(identifier); if (left == null) { return false; diff --git a/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java b/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java index e4e8e064..c04f695e 100755 --- a/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java +++ b/rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java @@ -26,7 +26,22 @@ public class DeviceListener implements Listener { public boolean execute(ThingModelMessage message) { String identifier = message.getIdentifier(); Map mapData = message.dataToMap(); + String pk = message.getProductKey(); + String dn = message.getDeviceName(); for (DeviceCondition condition : this.conditions) { + String condPkDn = condition.getDevice(); + String[] pkAndDn = condPkDn.split("/"); + String condPk = pkAndDn[0]; + String condDn = pkAndDn[1]; + //判断产品是否匹配 + if (!pk.equals(condPk)) { + continue; + } + //判断设备是否匹配 + if (!"#".equals(condDn) && !dn.equals(condDn)) { + continue; + } + if (condition.matches(message.getType(), identifier, mapData)) { return true; } diff --git a/rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java b/rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java index 0e56cb64..e1f38843 100755 --- a/rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java +++ b/rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java @@ -59,6 +59,10 @@ public class RuleManager { 1000, Sort.by(Sort.Order.desc("createAt")))); rules.get().forEach(rule -> { try { + //不添加停止的规则 + if (RuleInfo.STATE_STOPPED.equals(rule.getState())) { + return; + } log.info("got rule {} to init", rule.getId()); add(rule); } catch (Throwable e) { diff --git a/standalone-package/pom.xml b/standalone-package/pom.xml old mode 100644 new mode 100755 diff --git a/standalone-package/src/main/resources/assemblies/standalone-package.xml b/standalone-package/src/main/resources/assemblies/standalone-package.xml old mode 100644 new mode 100755