规则监听问题修复

V0.5.x
xiwa 2022-04-18 03:20:48 +08:00
parent 4dbed12ac1
commit edde8b16a6
10 changed files with 23 additions and 3 deletions

View File

@ -35,7 +35,7 @@ public class ThingModelMessageDao {
builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier)); builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier));
} }
NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(builder) 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(); .build();
SearchHits<ThingModelMessage> result = template.search(query, ThingModelMessage.class); SearchHits<ThingModelMessage> result = template.search(query, ThingModelMessage.class);
return new Paging<>(result.getTotalHits(), result.getSearchHits().stream() return new Paging<>(result.getTotalHits(), result.getSearchHits().stream()

View File

0
doc/ma.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

View File

@ -47,10 +47,11 @@ public class DeviceCondition {
if ("*".equals(identifier)) { if ("*".equals(identifier)) {
return true; return true;
} }
//任意匹配 //存在参数,值任意匹配
if ("*".equals(comparator)) { if (parameter.containsKey(identifier) && "*".equals(comparator)) {
return true; return true;
} }
Object left = parameter.get(identifier); Object left = parameter.get(identifier);
if (left == null) { if (left == null) {
return false; return false;

View File

@ -26,7 +26,22 @@ public class DeviceListener implements Listener<DeviceCondition> {
public boolean execute(ThingModelMessage message) { public boolean execute(ThingModelMessage message) {
String identifier = message.getIdentifier(); String identifier = message.getIdentifier();
Map<String, Object> mapData = message.dataToMap(); Map<String, Object> mapData = message.dataToMap();
String pk = message.getProductKey();
String dn = message.getDeviceName();
for (DeviceCondition condition : this.conditions) { 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)) { if (condition.matches(message.getType(), identifier, mapData)) {
return true; return true;
} }

View File

@ -59,6 +59,10 @@ public class RuleManager {
1000, Sort.by(Sort.Order.desc("createAt")))); 1000, Sort.by(Sort.Order.desc("createAt"))));
rules.get().forEach(rule -> { rules.get().forEach(rule -> {
try { try {
//不添加停止的规则
if (RuleInfo.STATE_STOPPED.equals(rule.getState())) {
return;
}
log.info("got rule {} to init", rule.getId()); log.info("got rule {} to init", rule.getId());
add(rule); add(rule);
} catch (Throwable e) { } catch (Throwable e) {

0
standalone-package/pom.xml Normal file → Executable file
View File