报警模块实体类引入修改

redis缓存工具类移动
This commit is contained in:
qiaoqinzheng 2023-08-01 10:48:22 +08:00
parent 8194e89326
commit 566e11aaf3
7 changed files with 47 additions and 43 deletions

View File

@ -7,6 +7,7 @@ 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.*;
@ -166,7 +167,7 @@ public class RedisStreamUtil{
return putRecord(record);
}
public void setRules(Map<String, AlarmRule> ruleMap){
public void setRules(Map<String, AlarmRuleAbnormal> ruleMap){
Jackson2JsonRedisSerializer jacksonSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
// 使Jackson支持Java8的新日期API

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.base.entity.postgre.AlarmContactGroup;
import org.jeecg.modules.entity.AlarmContactGroupAbnormal;
public interface AlarmContactGroupMapper extends BaseMapper<AlarmContactGroup> {
public interface AlarmContactGroupMapper extends BaseMapper<AlarmContactGroupAbnormal> {
}

View File

@ -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.base.entity.postgre.AlarmRule;
import org.jeecg.modules.entity.AlarmRuleAbnormal;
import java.util.List;
import java.util.Map;
public interface AlarmRuleMapper extends BaseMapper<AlarmRule> {
public interface AlarmRuleMapper extends BaseMapper<AlarmRuleAbnormal> {
List<AlarmRuleDto> findPage(Map<String, Object> params);

View File

@ -4,20 +4,21 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.postgre.AlarmContactGroup;
import org.jeecg.modules.entity.AlarmContactGroupAbnormal;
public interface IAlarmContactGroupService extends IService<AlarmContactGroup> {
public interface IAlarmContactGroupService extends IService<AlarmContactGroupAbnormal> {
Result findPage(QueryRequest queryRequest, AlarmContactGroup alarmContactGroup);
Result findPage(QueryRequest queryRequest, AlarmContactGroupAbnormal alarmContactGroup);
Result findInfo(String id);
Result create(AlarmContactGroup alarmContactGroup);
Result create(AlarmContactGroupAbnormal alarmContactGroup);
Result update(AlarmContactGroup alarmContactGroup);
Result update(AlarmContactGroupAbnormal alarmContactGroup);
Result deleteById(String id);
Result deleteUserById(String id, String userId);
AlarmContactGroup getByName(String groupName);
AlarmContactGroupAbnormal getByName(String groupName);
}

View File

@ -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<AlarmRule> {
public interface IAlarmRuleService extends IService<AlarmRuleAbnormal> {
Result findPage(AlarmRuleVo alarmRuleVo);
Result findInfo(String alarmRuleId);
Result create(AlarmRule alarmRule);
Result create(AlarmRuleAbnormal alarmRule);
Result update(AlarmRule alarmRule);
Result update(AlarmRuleAbnormal alarmRule);
Result deleteById(String alarmRuleId);

View File

@ -14,6 +14,7 @@ import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.base.entity.postgre.AlarmContactGroup;
import org.jeecg.modules.base.entity.postgre.AlarmContactGroupMember;
import org.jeecg.modules.base.entity.postgre.SysUser;
import org.jeecg.modules.entity.AlarmContactGroupAbnormal;
import org.jeecg.modules.feignclient.SystemClient;
import org.jeecg.modules.mapper.AlarmContactGroupMapper;
import org.jeecg.modules.mapper.AlarmContactGroupMemberMapper;
@ -30,7 +31,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
@Service("alarmContactGroupService")
public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupMapper, AlarmContactGroup> implements IAlarmContactGroupService {
public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupMapper, AlarmContactGroupAbnormal> implements IAlarmContactGroupService {
@Autowired
private AlarmContactGroupMemberMapper alarmContactGroupMemberMapper;
@ -38,14 +39,14 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
private SystemClient systemClient;
@Override
public Result findPage(QueryRequest queryRequest, AlarmContactGroup alarmContactGroup) {
public Result findPage(QueryRequest queryRequest, AlarmContactGroupAbnormal alarmContactGroup) {
Result result = new Result();
//获取用户信息
Map<String ,SysUser> userList = systemClient.findUserMap();
Page<AlarmContactGroup> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(AlarmContactGroup::getCreateTime);
Page<AlarmContactGroup> alarmContactGroupPage = this.baseMapper.selectPage(page, queryWrapper);
Page<AlarmContactGroupAbnormal> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
LambdaQueryWrapper<AlarmContactGroupAbnormal> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(AlarmContactGroupAbnormal::getCreateTime);
Page<AlarmContactGroupAbnormal> alarmContactGroupPage = this.baseMapper.selectPage(page, queryWrapper);
LambdaQueryWrapper<AlarmContactGroupMember> contactGroupMemberQueryWrapper = new LambdaQueryWrapper<>();
List<AlarmContactGroupMember> alarmContactGroupMembers = alarmContactGroupMemberMapper.selectList(contactGroupMemberQueryWrapper);
alarmContactGroupPage.getRecords().forEach(item->{
@ -77,9 +78,9 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
public Result findInfo(String id) {
Result result = new Result();
//根据id查询对应的数据 判断数据是否在数据库中
LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlarmContactGroup::getId, id);
AlarmContactGroup alarmContactGroup = this.baseMapper.selectOne(queryWrapper);
LambdaQueryWrapper<AlarmContactGroupAbnormal> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlarmContactGroupAbnormal::getId, id);
AlarmContactGroupAbnormal alarmContactGroup = this.baseMapper.selectOne(queryWrapper);
if (Objects.isNull(alarmContactGroup)){
result.error500("Failed to query the data because the corresponding data does not exist!");
return result;
@ -98,7 +99,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
}
@Override
public Result create(AlarmContactGroup alarmContactGroup) {
public Result create(AlarmContactGroupAbnormal alarmContactGroup) {
Result result = new Result();
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
@ -132,7 +133,7 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
}
@Override
public Result update(AlarmContactGroup alarmContactGroup) {
public Result update(AlarmContactGroupAbnormal alarmContactGroup) {
Result result = new Result();
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
@ -149,9 +150,9 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
//获取当前操作人用户名
String username = JwtUtil.getUserNameByToken(request);
LambdaQueryWrapper<AlarmContactGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlarmContactGroup::getId, alarmContactGroup.getId());
AlarmContactGroup contactGroup = this.baseMapper.selectOne(queryWrapper);
LambdaQueryWrapper<AlarmContactGroupAbnormal> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlarmContactGroupAbnormal::getId, alarmContactGroup.getId());
AlarmContactGroupAbnormal contactGroup = this.baseMapper.selectOne(queryWrapper);
if (Objects.isNull(contactGroup)){
result.error500("The corresponding data does not exist!");
return result;
@ -205,9 +206,9 @@ public class AlarmContactGroupServiceImpl extends ServiceImpl<AlarmContactGroupM
}
@Override
public AlarmContactGroup getByName(String groupName) {
LambdaQueryWrapper<AlarmContactGroup> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmContactGroup::getName,groupName);
public AlarmContactGroupAbnormal getByName(String groupName) {
LambdaQueryWrapper<AlarmContactGroupAbnormal> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmContactGroupAbnormal::getName,groupName);
return getOne(wrapper);
}

View File

@ -15,8 +15,8 @@ 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,7 +34,7 @@ import java.util.Map;
import static org.jeecg.modules.base.enums.SourceType.*;
@Service("alarmRuleService")
public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule> implements IAlarmRuleService {
public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRuleAbnormal> implements IAlarmRuleService {
@Autowired
private RedisStreamUtil redisStreamUtil;
@ -73,7 +73,7 @@ public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule
}
@Override
public Result create(AlarmRule alarmRule) {
public Result create(AlarmRuleAbnormal alarmRule) {
Rule rule = alarmRule.getRule();
if (ObjectUtil.isNotNull(rule)){
String operator = JSON.toJSONString(rule);
@ -85,10 +85,10 @@ public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule
}
@Override
public Result update(AlarmRule alarmRule) {
LambdaQueryWrapper<AlarmRule> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmRule::getId, alarmRule.getId());
AlarmRule alarmRuleOld = this.baseMapper.selectOne(wrapper);
public Result update(AlarmRuleAbnormal alarmRule) {
LambdaQueryWrapper<AlarmRuleAbnormal> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmRuleAbnormal::getId, alarmRule.getId());
AlarmRuleAbnormal 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<AlarmRuleMapper, AlarmRule
@Override
public Result updateStatus(String alarmRuleId,Integer enabled) {
AlarmRule alarmRule = new AlarmRule();
AlarmRuleAbnormal alarmRule = new AlarmRuleAbnormal();
alarmRule.setId(alarmRuleId);
alarmRule.setEnabled(enabled);
if (updateById(alarmRule))
@ -142,12 +142,12 @@ public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule
String colon = SymbolConstant.COLON;
String prefixRule = CommonConstant.PREFIX_RULE;
String prefixSilence = CommonConstant.PREFIX_SILENCE;
LambdaQueryWrapper<AlarmRule> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmRule::getEnabled,1);
List<AlarmRule> alarmRules = this.list(wrapper);
Map<String, AlarmRule> ruleMap = new HashMap<>();
LambdaQueryWrapper<AlarmRuleAbnormal> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmRuleAbnormal::getEnabled,1);
List<AlarmRuleAbnormal> alarmRules = this.list(wrapper);
Map<String, AlarmRuleAbnormal> ruleMap = new HashMap<>();
Map<String, Long> silenceMap = new HashMap<>();
for (AlarmRule alarmRule : alarmRules) {
for (AlarmRuleAbnormal alarmRule : alarmRules) {
String sourceType = alarmRule.getSourceType();
String ruleId = alarmRule.getId();
Long silence = alarmRule.getSilenceCycle();