fix:规则引擎问题修复
parent
0d04a302a8
commit
c25318d60f
|
@ -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<PluginInfo> 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
|
||||
|
|
|
@ -23,6 +23,10 @@ public class DeviceFilter implements Filter<DeviceCondition> {
|
|||
|
||||
private String type;
|
||||
|
||||
private String pk;
|
||||
|
||||
private String dn;
|
||||
|
||||
private List<DeviceCondition> conditions;
|
||||
|
||||
private IDeviceInfoData deviceInfoData;
|
||||
|
|
|
@ -24,6 +24,10 @@ public class DeviceListener implements Listener<DeviceCondition> {
|
|||
|
||||
private String type;
|
||||
|
||||
private String pk;
|
||||
|
||||
private String dn;
|
||||
|
||||
private List<DeviceCondition> conditions;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<AlertService> 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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -120,7 +120,7 @@ spring:
|
|||
#使用内置redis的配置
|
||||
#host: redis
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
port: 6378
|
||||
database: 0
|
||||
|
||||
mvc:
|
||||
|
|
|
@ -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 '更新时间';
|
Loading…
Reference in New Issue