diff --git a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java index 6a681b90..8537533a 100755 --- a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java +++ b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java @@ -60,9 +60,13 @@ public class RuleManager { @SneakyThrows public void initRules() { - int idx = 0; + int idx = 1; while (true) { Paging rules = ruleInfoData.findAll(idx, 1000); + // 如果记录为空,直接跳出循环 + if (rules.getData() == null || rules.getData().isEmpty()) { + break; + } rules.getData().forEach(rule -> { try { //不添加停止的规则 @@ -76,9 +80,6 @@ public class RuleManager { } }); idx++; - if (rules.getTotal() == 0) { - break; - } } } diff --git a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java index 5ff5d25d..72ddeeb1 100755 --- a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java +++ b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java @@ -48,9 +48,13 @@ public class TaskManager implements ApplicationContextAware { } public void initTask() { - int idx = 0; + int idx = 1; while (true) { Paging tasks = taskInfoData.findAll(idx, 1000); + // 如果记录为空,直接跳出循环 + if (tasks.getData() == null || tasks.getData().isEmpty()) { + break; + } tasks.getData().forEach(task -> { try { if (!TaskInfo.STATE_RUNNING.equals(task.getState())) { @@ -63,9 +67,6 @@ public class TaskManager implements ApplicationContextAware { } }); idx++; - if (tasks.getTotal() == 0) { - break; - } } }