diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java similarity index 80% rename from jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamUtil.java rename to jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java index 18fdd99c..359dabe5 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java @@ -1,18 +1,12 @@ package org.jeecg.common.util; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.PropertyAccessor; -import com.fasterxml.jackson.databind.ObjectMapper; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.modules.base.dto.RuleDto; -import org.jeecg.modules.base.entity.postgre.AlarmRule; -import org.jeecg.modules.entity.AlarmRuleAbnormal; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.stream.*; import org.springframework.data.redis.core.*; -import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.stereotype.Component; import java.util.HashSet; @@ -21,7 +15,7 @@ import java.util.Map; import java.util.Set; @Component -public class RedisStreamUtil{ +public class RedisStreamUtil { @Autowired private RedisTemplate redisTemplate; @@ -167,25 +161,6 @@ public class RedisStreamUtil{ return putRecord(record); } - public void setRules(Map ruleMap){ - Jackson2JsonRedisSerializer jacksonSerializer = new Jackson2JsonRedisSerializer(Object.class); - ObjectMapper objectMapper = new ObjectMapper(); - // 使Jackson支持Java8的新日期API - // objectMapper.registerModule(new JavaTimeModule()); - objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); - objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); - jacksonSerializer.setObjectMapper(objectMapper); - // 返回批处理的执行结果 - List execResult = redisTemplate.executePipelined((RedisConnection connection) -> { - Set keySet = ruleMap.keySet(); - for (String key : keySet) { - AlarmRule rule = ruleMap.get(key); - connection.set(key.getBytes(),jacksonSerializer.serialize(rule)); - } - return null; - }); - } - public void setSilence(Map silenceMap){ // 返回批处理的执行结果 List execResult = redisTemplate.executePipelined((RedisConnection connection) -> { diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamAlarmUtil.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamAlarmUtil.java new file mode 100644 index 00000000..bc9e288a --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamAlarmUtil.java @@ -0,0 +1,43 @@ +package org.jeecg.common.util; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.jeecg.modules.base.entity.postgre.AlarmRule; +import org.jeecg.modules.entity.AlarmRuleAbnormal; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +@Component +public class RedisStreamAlarmUtil extends RedisStreamUtil { + + @Autowired + private RedisTemplate redisTemplate; + + public void setRules(Map ruleMap){ + Jackson2JsonRedisSerializer jacksonSerializer = new Jackson2JsonRedisSerializer(Object.class); + ObjectMapper objectMapper = new ObjectMapper(); + // 使Jackson支持Java8的新日期API + // objectMapper.registerModule(new JavaTimeModule()); + objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); + jacksonSerializer.setObjectMapper(objectMapper); + // 返回批处理的执行结果 + List execResult = redisTemplate.executePipelined((RedisConnection connection) -> { + Set keySet = ruleMap.keySet(); + for (String key : keySet) { + AlarmRule rule = ruleMap.get(key); + connection.set(key.getBytes(),jacksonSerializer.serialize(rule)); + } + return null; + }); + } + +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java index 3cf7b395..c47b09f2 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmRuleServiceImpl.java @@ -10,7 +10,7 @@ import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.Prompt; import org.jeecg.common.constant.SymbolConstant; -import org.jeecg.common.util.RedisStreamUtil; +import org.jeecg.common.util.RedisStreamAlarmUtil; import org.jeecg.modules.base.dto.AlarmRuleDto; import org.jeecg.modules.base.dto.AlarmRuleInfo; import org.jeecg.modules.base.dto.SourceDto; @@ -37,7 +37,7 @@ import static org.jeecg.modules.base.enums.SourceType.*; public class AlarmRuleServiceImpl extends ServiceImpl implements IAlarmRuleService { @Autowired - private RedisStreamUtil redisStreamUtil; + private RedisStreamAlarmUtil redisStreamUtil; @Autowired private ISysEmailService emailService;