From c25318d60f18255c81e8065d7d521366d642e41b Mon Sep 17 00:00:00 2001 From: xiwa Date: Sat, 3 Feb 2024 19:54:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A7=84=E5=88=99=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/main/script/ScriptVerticle.java | 29 +++-- .../ruleengine/filter/DeviceFilter.java | 4 + .../ruleengine/listener/DeviceListener.java | 4 + .../iotkit/ruleengine/rule/RuleManager.java | 25 +++- .../cc/iotkit/config/EmbeddedRedisConfig.java | 7 +- .../src/main/resources/application.yml | 2 +- .../src/main/resources/sql/schema-postgre.sql | 112 ------------------ 7 files changed, 53 insertions(+), 130 deletions(-) delete mode 100644 iot-starter/src/main/resources/sql/schema-postgre.sql diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java index 307e23c3..5aa0aea6 100644 --- a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java @@ -21,6 +21,7 @@ import org.springframework.stereotype.Component; import java.time.Duration; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -69,22 +70,26 @@ public class ScriptVerticle extends AbstractVerticle { @Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS) public void checkScriptUpdate() { //定时检查脚本是否需要更新 - pluginScripts.forEach((k, v) -> { - PluginInfo pluginInfo = pluginInfoData.findByPluginId(k); - if (pluginInfo == null) { - return; + List plugins = pluginInfoData.findAll(); + for (PluginInfo plugin : plugins) { + String pluginId = plugin.getPluginId(); + String oldMd5 = pluginScripts.get(pluginId); + String script = plugin.getScript(); + if(script==null){ + continue; } - String md5 = CodecUtil.md5Str(pluginInfo.getScript()); - if (v.equals(md5)) { - return; + String md5 = CodecUtil.md5Str(script); + if (oldMd5 != null && oldMd5.equals(md5)) { + continue; } - IScriptEngine scriptEngine = PLUGIN_SCRIPT_ENGINES.get(k); + + IScriptEngine scriptEngine = PLUGIN_SCRIPT_ENGINES.get(pluginId); if (scriptEngine == null) { - return; + continue; } - pluginScripts.put(k, md5); - scriptEngine.setScript(pluginInfo.getScript()); - }); + pluginScripts.put(pluginId, md5); + scriptEngine.setScript(script); + } } @Override diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java index 4c0a0091..cdfe595a 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java @@ -23,6 +23,10 @@ public class DeviceFilter implements Filter { private String type; + private String pk; + + private String dn; + private List conditions; private IDeviceInfoData deviceInfoData; diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java index d26e3e59..5ba68547 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java @@ -24,6 +24,10 @@ public class DeviceListener implements Listener { private String type; + private String pk; + + private String dn; + private List conditions; @Override diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java index 00301ea0..6085b728 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java @@ -40,6 +40,7 @@ import cc.iotkit.ruleengine.config.RuleConfiguration; import cc.iotkit.ruleengine.filter.DeviceFilter; import cc.iotkit.ruleengine.filter.Filter; import cc.iotkit.ruleengine.link.LinkFactory; +import cc.iotkit.ruleengine.listener.DeviceCondition; import cc.iotkit.ruleengine.listener.DeviceListener; import cc.iotkit.ruleengine.listener.Listener; import cn.hutool.core.collection.CollectionUtil; @@ -127,6 +128,9 @@ public class RuleManager { } public void add(RuleInfo ruleInfo) { + if(RuleInfo.STATE_STOPPED.equals(ruleInfo.getState())){ + return; + } Rule rule = parseRule(ruleInfo); ruleMessageHandler.putRule(rule); } @@ -175,7 +179,15 @@ public class RuleManager { private Listener parseListener(String type, String config) { if (DeviceListener.TYPE.equals(type)) { - return parse(config, DeviceListener.class); + DeviceListener listener = parse(config, DeviceListener.class); + for (DeviceCondition condition : listener.getConditions()) { + String dn = "#"; + if (StringUtils.isNotBlank(listener.getDn())) { + dn = listener.getDn(); + } + condition.setDevice(listener.getPk() + "/" + dn); + } + return listener; } return null; } @@ -183,6 +195,13 @@ public class RuleManager { private Filter parseFilter(String type, String config) { if (DeviceFilter.TYPE.equals(type)) { DeviceFilter filter = parse(config, DeviceFilter.class); + for (cc.iotkit.ruleengine.filter.DeviceCondition condition : filter.getConditions()) { + String dn = "#"; + if (StringUtils.isNotBlank(filter.getDn())) { + dn = filter.getDn(); + } + condition.setDevice(filter.getPk() + "/" + dn); + } filter.setDeviceInfoData(deviceInfoData); return filter; } @@ -231,7 +250,7 @@ public class RuleManager { List alertServices = new ArrayList<>(); for (AlertConfig alertConfig : alertConfigs) { - if(alertConfig.getEnable()!=null && !alertConfig.getEnable()){ + if (alertConfig.getEnable() != null && !alertConfig.getEnable()) { continue; } @@ -248,7 +267,7 @@ public class RuleManager { .alertConfigId(alertConfig.getId()) .build(); - if(channelConfigId!=null) { + if (channelConfigId != null) { ChannelConfig channelConfig = channelConfigData.findById(channelTemplate.getChannelConfigId()); Channel channel = channelData.findById(channelConfig.getChannelId()); message.setChannel(channel.getCode()); diff --git a/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java b/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java index 2640b67c..ddd42708 100644 --- a/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java +++ b/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java @@ -28,12 +28,15 @@ public class EmbeddedRedisConfig { .setting("bind localhost") .build(); } else { - redisServer = new RedisServer(); + redisServer = RedisServer.builder() + .port(6378) + .setting("bind localhost") + .build(); } try { redisServer.start(); } catch (Exception e) { - if(e.getMessage().contains("Address already in use")){ + if (e.getMessage().contains("Address already in use")) { throw new RuntimeException("redis端口被占用,请先停止本地的redis服务"); } log.error("start redis server failed", e); diff --git a/iot-starter/src/main/resources/application.yml b/iot-starter/src/main/resources/application.yml index 294a47e9..5704c47b 100644 --- a/iot-starter/src/main/resources/application.yml +++ b/iot-starter/src/main/resources/application.yml @@ -120,7 +120,7 @@ spring: #使用内置redis的配置 #host: redis host: 127.0.0.1 - port: 6379 + port: 6378 database: 0 mvc: diff --git a/iot-starter/src/main/resources/sql/schema-postgre.sql b/iot-starter/src/main/resources/sql/schema-postgre.sql deleted file mode 100644 index c593d651..00000000 --- a/iot-starter/src/main/resources/sql/schema-postgre.sql +++ /dev/null @@ -1,112 +0,0 @@ - --- ---------------------------- --- 18、代码生成业务表 --- ---------------------------- -drop table if exists gen_table; -create table if not exists gen_table -( - table_id int8, - data_name varchar(200) default ''::varchar, - table_name varchar(200) default ''::varchar, - table_comment varchar(500) default ''::varchar, - sub_table_name varchar(64) default ''::varchar, - sub_table_fk_name varchar(64) default ''::varchar, - class_name varchar(100) default ''::varchar, - tpl_category varchar(200) default 'crud'::varchar, - package_name varchar(100) default null::varchar, - module_name varchar(30) default null::varchar, - business_name varchar(30) default null::varchar, - function_name varchar(50) default null::varchar, - function_author varchar(50) default null::varchar, - gen_type char default '0'::bpchar not null, - gen_path varchar(200) default '/'::varchar, - options varchar(1000) default null::varchar, - create_dept int8, - create_by int8, - create_time timestamp, - update_by int8, - update_time timestamp, - remark varchar(500) default null::varchar, - constraint gen_table_pk primary key (table_id) - ); - -comment on table gen_table is '代码生成业务表'; -comment on column gen_table.table_id is '编号'; -comment on column gen_table.data_name is '数据源名称'; -comment on column gen_table.table_name is '表名称'; -comment on column gen_table.table_comment is '表描述'; -comment on column gen_table.sub_table_name is '关联子表的表名'; -comment on column gen_table.sub_table_fk_name is '子表关联的外键名'; -comment on column gen_table.class_name is '实体类名称'; -comment on column gen_table.tpl_category is '使用的模板(CRUD单表操作 TREE树表操作)'; -comment on column gen_table.package_name is '生成包路径'; -comment on column gen_table.module_name is '生成模块名'; -comment on column gen_table.business_name is '生成业务名'; -comment on column gen_table.function_name is '生成功能名'; -comment on column gen_table.function_author is '生成功能作者'; -comment on column gen_table.gen_type is '生成代码方式(0zip压缩包 1自定义路径)'; -comment on column gen_table.gen_path is '生成路径(不填默认项目路径)'; -comment on column gen_table.options is '其它生成选项'; -comment on column gen_table.create_dept is '创建部门'; -comment on column gen_table.create_by is '创建者'; -comment on column gen_table.create_time is '创建时间'; -comment on column gen_table.update_by is '更新者'; -comment on column gen_table.update_time is '更新时间'; -comment on column gen_table.remark is '备注'; - --- ---------------------------- --- 19、代码生成业务表字段 --- ---------------------------- -drop table if exists gen_table_column; -create table if not exists gen_table_column -( - column_id int8, - table_id int8, - column_name varchar(200) default null::varchar, - column_comment varchar(500) default null::varchar, - column_type varchar(100) default null::varchar, - java_type varchar(500) default null::varchar, - java_field varchar(200) default null::varchar, - is_pk char default null::bpchar, - is_increment char default null::bpchar, - is_required char default null::bpchar, - is_insert char default null::bpchar, - is_edit char default null::bpchar, - is_list char default null::bpchar, - is_query char default null::bpchar, - query_type varchar(200) default 'EQ'::varchar, - html_type varchar(200) default null::varchar, - dict_type varchar(200) default ''::varchar, - sort int4, - create_dept int8, - create_by int8, - create_time timestamp, - update_by int8, - update_time timestamp, - constraint gen_table_column_pk primary key (column_id) - ); - -comment on table gen_table_column is '代码生成业务表字段'; -comment on column gen_table_column.column_id is '编号'; -comment on column gen_table_column.table_id is '归属表编号'; -comment on column gen_table_column.column_name is '列名称'; -comment on column gen_table_column.column_comment is '列描述'; -comment on column gen_table_column.column_type is '列类型'; -comment on column gen_table_column.java_type is 'JAVA类型'; -comment on column gen_table_column.java_field is 'JAVA字段名'; -comment on column gen_table_column.is_pk is '是否主键(1是)'; -comment on column gen_table_column.is_increment is '是否自增(1是)'; -comment on column gen_table_column.is_required is '是否必填(1是)'; -comment on column gen_table_column.is_insert is '是否为插入字段(1是)'; -comment on column gen_table_column.is_edit is '是否编辑字段(1是)'; -comment on column gen_table_column.is_list is '是否列表字段(1是)'; -comment on column gen_table_column.is_query is '是否查询字段(1是)'; -comment on column gen_table_column.query_type is '查询方式(等于、不等于、大于、小于、范围)'; -comment on column gen_table_column.html_type is '显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)'; -comment on column gen_table_column.dict_type is '字典类型'; -comment on column gen_table_column.sort is '排序'; -comment on column gen_table_column.create_dept is '创建部门'; -comment on column gen_table_column.create_by is '创建者'; -comment on column gen_table_column.create_time is '创建时间'; -comment on column gen_table_column.update_by is '更新者'; -comment on column gen_table_column.update_time is '更新时间';