From 996c48790892f8ddf467bdc6484651cc545945de Mon Sep 17 00:00:00 2001 From: nieziyan Date: Tue, 1 Aug 2023 11:56:48 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/util/RedisStreamUtil.java | 24 +++++++++++ .../base/entity/postgre/AlarmRule.java | 3 ++ .../common/util/RedisStreamAlarmUtil.java | 43 ------------------- .../controller/AlarmRuleController.java | 5 +-- .../modules/entity/AlarmRuleAbnormal.java | 19 -------- .../jeecg/modules/mapper/AlarmRuleMapper.java | 4 +- .../modules/service/IAlarmRuleService.java | 8 ++-- .../service/impl/AlarmRuleServiceImpl.java | 30 ++++++------- .../modules/email/EmailLogProperties.java | 2 +- .../jeecg/modules/email/EmailProperties.java | 3 +- .../jeecg/modules/mapper/SysMailMapper.java | 2 +- .../modules/service/ISysMailService.java | 2 +- .../service/impl/SysMailServiceImpl.java | 2 +- .../modules/spectrum/SpecturmDataStorage.java | 2 +- 14 files changed, 56 insertions(+), 93 deletions(-) delete mode 100644 jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamAlarmUtil.java delete mode 100644 jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmRuleAbnormal.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java index 359dabe5..ea76a5f9 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java @@ -1,12 +1,17 @@ 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.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; @@ -187,4 +192,23 @@ public class RedisStreamUtil { return keys; }); } + + 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-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmRule.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmRule.java index e2912ada..73ee83cf 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmRule.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmRule.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; +import org.jeecg.modules.base.entity.Rule; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; @@ -103,4 +104,6 @@ public class AlarmRule implements Serializable { @TableField(value = "update_by") private String updateBy; + @TableField(exist = false) + private Rule rule; } 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 deleted file mode 100644 index bc9e288a..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/common/util/RedisStreamAlarmUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -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/controller/AlarmRuleController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java index d8d7361d..b85ac04a 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmRuleController.java @@ -8,7 +8,6 @@ import org.jeecg.modules.base.entity.monitor.Host; import org.jeecg.modules.base.entity.monitor.Servers; import org.jeecg.modules.base.entity.postgre.AlarmRule; import org.jeecg.modules.base.vo.AlarmRuleVo; -import org.jeecg.modules.entity.AlarmRuleAbnormal; import org.jeecg.modules.feignclient.MonitorAlarm; import org.jeecg.modules.service.IAlarmRuleService; import org.springframework.beans.factory.annotation.Autowired; @@ -43,13 +42,13 @@ public class AlarmRuleController { @PostMapping("create") @ApiOperation(value = "新增规则信息", notes = "新增规则信息") - public Result create(@RequestBody AlarmRuleAbnormal alarmRule){ + public Result create(@RequestBody AlarmRule alarmRule){ return alarmRuleService.create(alarmRule); } @PutMapping("update") @ApiOperation(value = "修改规则信息", notes = "修改规则信息") - public Result update(@RequestBody AlarmRuleAbnormal alarmRule){ + public Result update(@RequestBody AlarmRule alarmRule){ return alarmRuleService.update(alarmRule); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmRuleAbnormal.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmRuleAbnormal.java deleted file mode 100644 index da120e55..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/entity/AlarmRuleAbnormal.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jeecg.modules.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import org.jeecg.modules.base.entity.Rule; -import org.jeecg.modules.base.entity.postgre.AlarmRule; - -@Data -@TableName(value = "alarm_rule") -public class AlarmRuleAbnormal extends AlarmRule { - - /** - * 用于新增报警规则 - */ - @TableField(exist = false) - private Rule rule; - -} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java index 494cbaaa..f7c9d10d 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/AlarmRuleMapper.java @@ -3,12 +3,12 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.jeecg.modules.base.dto.AlarmRuleDto; import org.jeecg.modules.base.dto.AlarmRuleInfo; -import org.jeecg.modules.entity.AlarmRuleAbnormal; +import org.jeecg.modules.base.entity.postgre.AlarmRule; import java.util.List; import java.util.Map; -public interface AlarmRuleMapper extends BaseMapper { +public interface AlarmRuleMapper extends BaseMapper { List findPage(Map params); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java index fac1d2a2..644bfbb9 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmRuleService.java @@ -2,18 +2,18 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.entity.postgre.AlarmRule; import org.jeecg.modules.base.vo.AlarmRuleVo; -import org.jeecg.modules.entity.AlarmRuleAbnormal; -public interface IAlarmRuleService extends IService { +public interface IAlarmRuleService extends IService { Result findPage(AlarmRuleVo alarmRuleVo); Result findInfo(String alarmRuleId); - Result create(AlarmRuleAbnormal alarmRule); + Result create(AlarmRule alarmRule); - Result update(AlarmRuleAbnormal alarmRule); + Result update(AlarmRule alarmRule); Result deleteById(String alarmRuleId); 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 c47b09f2..575cc64f 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,13 +10,13 @@ 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.RedisStreamAlarmUtil; +import org.jeecg.common.util.RedisStreamUtil; import org.jeecg.modules.base.dto.AlarmRuleDto; import org.jeecg.modules.base.dto.AlarmRuleInfo; import org.jeecg.modules.base.dto.SourceDto; import org.jeecg.modules.base.entity.Rule; +import org.jeecg.modules.base.entity.postgre.AlarmRule; import org.jeecg.modules.base.vo.AlarmRuleVo; -import org.jeecg.modules.entity.AlarmRuleAbnormal; import org.jeecg.modules.mapper.AlarmRuleMapper; import org.jeecg.modules.service.IAlarmRuleService; import org.jeecg.modules.service.ISysDatabaseService; @@ -34,10 +34,10 @@ import java.util.Map; import static org.jeecg.modules.base.enums.SourceType.*; @Service("alarmRuleService") -public class AlarmRuleServiceImpl extends ServiceImpl implements IAlarmRuleService { +public class AlarmRuleServiceImpl extends ServiceImpl implements IAlarmRuleService { @Autowired - private RedisStreamAlarmUtil redisStreamUtil; + private RedisStreamUtil redisStreamUtil; @Autowired private ISysEmailService emailService; @@ -73,7 +73,7 @@ public class AlarmRuleServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(AlarmRuleAbnormal::getId, alarmRule.getId()); - AlarmRuleAbnormal alarmRuleOld = this.baseMapper.selectOne(wrapper); + public Result update(AlarmRule alarmRule) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(AlarmRule::getId, alarmRule.getId()); + AlarmRule alarmRuleOld = this.baseMapper.selectOne(wrapper); if (ObjectUtil.isNull(alarmRuleOld)){ return Result.error(Prompt.DATA_NOT_EXITS); } @@ -124,7 +124,7 @@ public class AlarmRuleServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(AlarmRuleAbnormal::getEnabled,1); - List alarmRules = this.list(wrapper); - Map ruleMap = new HashMap<>(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(AlarmRule::getEnabled,1); + List alarmRules = this.list(wrapper); + Map ruleMap = new HashMap<>(); Map silenceMap = new HashMap<>(); - for (AlarmRuleAbnormal alarmRule : alarmRules) { + for (AlarmRule alarmRule : alarmRules) { String sourceType = alarmRule.getSourceType(); String ruleId = alarmRule.getId(); Long silence = alarmRule.getSilenceCycle(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java index 98da3486..65a8ac13 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java @@ -1,7 +1,7 @@ package org.jeecg.modules.email; import lombok.Data; -import org.jeecg.modules.base.entity.SysEmailLog; +import org.jeecg.modules.base.entity.postgre.SysEmailLog; import java.util.List; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java index 14f20f05..53b3369b 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java @@ -1,10 +1,9 @@ package org.jeecg.modules.email; import lombok.Data; -import org.jeecg.modules.base.entity.SysEmail; +import org.jeecg.modules.base.entity.postgre.SysEmail; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; - import java.io.Serializable; /** diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java index 0ca57666..6aa9763c 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java @@ -1,7 +1,7 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.jeecg.modules.base.entity.SysEmail; +import org.jeecg.modules.base.entity.postgre.SysEmail; /** * 邮件数据表Mapper diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java index 8e9549e3..16757886 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java @@ -1,7 +1,7 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; -import org.jeecg.modules.base.entity.SysEmail; +import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jeecg.modules.email.EmailProperties; import java.util.List; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java index cc21366b..73fb3b8a 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java @@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; import org.jeecg.common.email.emuns.SysMailType; -import org.jeecg.modules.base.entity.SysEmail; +import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jeecg.modules.email.EmailProperties; import org.jeecg.modules.emuns.SysMailEnableType; import org.jeecg.modules.mapper.SysMailMapper; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpecturmDataStorage.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpecturmDataStorage.java index 6c8c9845..4866e1b8 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpecturmDataStorage.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpecturmDataStorage.java @@ -1,6 +1,6 @@ package org.jeecg.modules.spectrum; -import org.jeecg.modules.base.entity.GardsSampleData; +import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; public class SpecturmDataStorage {