Browse Source

#告警修改

zhongwei
yang_shj 1 year ago
parent
commit
b214f8d755
  1. 35
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleMarkVo.java
  2. 10
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java
  3. 6
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java
  4. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/AlarmConfigDetailService.java
  5. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/AlarmConfigService.java
  6. 102
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigDetailServiceImpl.java
  7. 44
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigServiceImpl.java
  8. 53
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java
  9. 5
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/AlarmSaveService.java
  10. 78
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java
  11. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java

35
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleMarkVo.java

@ -0,0 +1,35 @@
package com.hnac.hzims.alarm.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
public class AlarmHandleMarkVo {
@ApiModelProperty(value = "是否集中监控右侧列表展示 : 0-展示 1-不展示")
private Integer isRightTabulation;
@ApiModelProperty(value = "是否集中监控弹窗展示 : 0-展示 1-不展示")
private Integer isShowAlert;
@ApiModelProperty(value = "是否集中监控铃铛展示 : 0-展示 1-不展示")
private Integer isSmallBell;
@ApiModelProperty(value = "是否集中监控遮罩展示 : 0-展示 1-不展示")
private Integer isMask;
@ApiModelProperty(value = "是否语音播报 : 0-播报 1-不播报")
private Integer isBroadcast;
@ApiModelProperty(value = "是否进行平台消息推送 : 0-推送 1-不推送")
private Integer isPlatformMessage;
@ApiModelProperty(value = "是否短信推送 :0-推送 1-不推送")
private Integer isShortMessage;
@ApiModelProperty(value = "是否微信公众号消息推送 :0-推送 1-不推送")
private Integer isWxMessage;
}

10
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java

@ -31,6 +31,8 @@ public interface IStationClient {
String QUERY_EXIST_LGTD_LTTD = API_PREFIX + "/queryExistLgtdAndLttd"; String QUERY_EXIST_LGTD_LTTD = API_PREFIX + "/queryExistLgtdAndLttd";
String GET_ONE = API_PREFIX + "/getOne"; String GET_ONE = API_PREFIX + "/getOne";
String QUERY_STATION_BY_CODES = API_PREFIX + "/querySatationByCodes";
@GetMapping(GET_LIST_ALL) @GetMapping(GET_LIST_ALL)
R<List<StationEntity>> getListAll(); R<List<StationEntity>> getListAll();
@ -71,4 +73,12 @@ public interface IStationClient {
*/ */
@PostMapping(GET_ONE) @PostMapping(GET_ONE)
R<StationEntity> getOne(@RequestBody StationEntity request); R<StationEntity> getOne(@RequestBody StationEntity request);
/**
* 根据站点code查询站点
* @param codes
* @return
*/
@PostMapping(QUERY_STATION_BY_CODES)
R<List<StationEntity>> querySatationByCodes(@RequestParam("codes") List<String> codes);
} }

6
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java

@ -6,6 +6,7 @@ import org.springblade.core.tool.api.R;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Component @Component
@ -70,4 +71,9 @@ public class IStationClientFallBack implements IStationClient {
public R<StationEntity> getOne(StationEntity request) { public R<StationEntity> getOne(StationEntity request) {
return R.data(null); return R.data(null);
} }
@Override
public R<List<StationEntity>> querySatationByCodes(List<String> codes) {
return R.data(new ArrayList<>());
}
} }

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/AlarmConfigDetailService.java

@ -3,6 +3,7 @@ package com.hnac.hzims.alarm.config.service;
import com.hnac.hzims.alarm.entity.AlarmConfigDetailEntity; import com.hnac.hzims.alarm.entity.AlarmConfigDetailEntity;
import com.hnac.hzims.alarm.entity.AlarmConfigEntity; import com.hnac.hzims.alarm.entity.AlarmConfigEntity;
import com.hnac.hzims.alarm.vo.AlarmConfigSourceVo; import com.hnac.hzims.alarm.vo.AlarmConfigSourceVo;
import com.hnac.hzims.alarm.vo.AlarmHandleMarkVo;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
@ -21,4 +22,5 @@ public interface AlarmConfigDetailService extends BaseService<AlarmConfigDetailE
AlarmConfigDetailEntity isSupport(String code, Integer source, Integer type); AlarmConfigDetailEntity isSupport(String code, Integer source, Integer type);
AlarmHandleMarkVo defaultMark(Integer source, Integer type);
} }

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/AlarmConfigService.java

@ -1,12 +1,10 @@
package com.hnac.hzims.alarm.config.service; package com.hnac.hzims.alarm.config.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.alarm.entity.AlarmConfigEntity; import com.hnac.hzims.alarm.entity.AlarmConfigEntity;
import com.hnac.hzims.alarm.vo.AlarmConfigVo; import com.hnac.hzims.alarm.vo.AlarmConfigVo;
import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; import com.hnac.hzims.alarm.vo.AlarmHandleMarkVo;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
import java.util.List; import java.util.List;
@ -19,6 +17,8 @@ public interface AlarmConfigService extends BaseService<AlarmConfigEntity> {
List<String> exclude(Integer operate); List<String> exclude(Integer operate);
AlarmHandleMarkVo mark(String code,Integer source,Integer type);
boolean isSupport(String code,Integer source,Integer type,Integer operate); boolean isSupport(String code,Integer source,Integer type,Integer operate);
boolean add(AlarmConfigEntity entity); boolean add(AlarmConfigEntity entity);

102
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigDetailServiceImpl.java

@ -8,6 +8,8 @@ import com.hnac.hzims.alarm.entity.AlarmConfigDetailEntity;
import com.hnac.hzims.alarm.entity.AlarmConfigEntity; import com.hnac.hzims.alarm.entity.AlarmConfigEntity;
import com.hnac.hzims.alarm.vo.AlarmConfigChildVo; import com.hnac.hzims.alarm.vo.AlarmConfigChildVo;
import com.hnac.hzims.alarm.vo.AlarmConfigSourceVo; import com.hnac.hzims.alarm.vo.AlarmConfigSourceVo;
import com.hnac.hzims.alarm.vo.AlarmHandleMarkVo;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
@ -59,6 +61,106 @@ public class AlarmConfigDetailServiceImpl extends BaseServiceImpl<AlarmConfigDet
return super.saveBatch(batchs); return super.saveBatch(batchs);
} }
/**
* 获取默认处理标识
* @param source
* @param type
* @return
*/
@Override
public AlarmHandleMarkVo defaultMark(Integer source,Integer type) {
// HZ3000告警
if(AlarmConstants.HZ3000_ALARM.equals(source)){
return this.hz3000Marik(type);
// 等级告警
}else if(AlarmConstants.LEVEL_ALARM.equals(source)){
return this.levelMark(type);
// 条件告警
}else if(AlarmConstants.CONDITION_ALARM.equals(source)){
return this.conditionMark(type);
// 智能预警
}else if(AlarmConstants.EARLY_WARNING.equals(source)){
return this.earlyMark(type);
}
return null;
}
/**
* hz3000告警默认处理标识
* @param type
* @return
*/
private AlarmHandleMarkVo hz3000Marik(Integer type) {
AlarmHandleMarkVo mark = new AlarmHandleMarkVo();
mark.setIsRightTabulation(1);
mark.setIsShowAlert(1);
mark.setIsSmallBell(1);
mark.setIsMask(1);
mark.setIsBroadcast(1);
mark.setIsPlatformMessage(1);
mark.setIsShortMessage(1);
mark.setIsWxMessage(1);
return mark;
}
/**
* 等级告警默认处理标识
* @param type
* @return
*/
private AlarmHandleMarkVo levelMark(Integer type) {
AlarmHandleMarkVo mark = new AlarmHandleMarkVo();
mark.setIsRightTabulation(1);
mark.setIsShowAlert(1);
mark.setIsSmallBell(1);
mark.setIsMask(1);
mark.setIsBroadcast(1);
mark.setIsPlatformMessage(1);
mark.setIsShortMessage(1);
mark.setIsWxMessage(1);
return mark;
}
/**
* 条件告警默认处理标识
* @param type
* @return
*/
private AlarmHandleMarkVo conditionMark(Integer type) {
AlarmHandleMarkVo mark = new AlarmHandleMarkVo();
mark.setIsRightTabulation(1);
mark.setIsShowAlert(1);
mark.setIsSmallBell(1);
mark.setIsMask(1);
mark.setIsBroadcast(1);
mark.setIsPlatformMessage(1);
mark.setIsShortMessage(1);
mark.setIsWxMessage(1);
return mark;
}
/**
* 智能预警默认处理标识
* @param type
* @return
*/
private AlarmHandleMarkVo earlyMark(Integer type) {
AlarmHandleMarkVo mark = new AlarmHandleMarkVo();
mark.setIsRightTabulation(1);
mark.setIsShowAlert(1);
mark.setIsSmallBell(1);
mark.setIsMask(1);
mark.setIsBroadcast(1);
mark.setIsPlatformMessage(1);
mark.setIsShortMessage(1);
mark.setIsWxMessage(1);
return mark;
}
/** /**
* 叠加配置详情记录 * 叠加配置详情记录
* @param entity * @param entity

44
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigServiceImpl.java

@ -10,6 +10,8 @@ import com.hnac.hzims.alarm.constants.AlarmConstants;
import com.hnac.hzims.alarm.entity.AlarmConfigDetailEntity; import com.hnac.hzims.alarm.entity.AlarmConfigDetailEntity;
import com.hnac.hzims.alarm.entity.AlarmConfigEntity; import com.hnac.hzims.alarm.entity.AlarmConfigEntity;
import com.hnac.hzims.alarm.vo.AlarmConfigVo; import com.hnac.hzims.alarm.vo.AlarmConfigVo;
import com.hnac.hzims.alarm.vo.AlarmHandleMarkVo;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
@ -94,6 +96,48 @@ public class AlarmConfigServiceImpl extends BaseServiceImpl<AlarmConfigMapper, A
} }
/** /**
* 查询站点告警标识
* @param code
* @return
*/
@Override
public AlarmHandleMarkVo mark(String code, Integer source,Integer type) {
AlarmConfigEntity config = this.getOne(Wrappers.<AlarmConfigEntity>lambdaQuery()
.eq(AlarmConfigEntity::getStationId,code)
.eq(AlarmConfigEntity::getIsEnable,"0"));
if(ObjectUtil.isEmpty(config)){
return detailService.defaultMark(source,type);
}
AlarmConfigDetailEntity detail = detailService.getOne(Wrappers.<AlarmConfigDetailEntity>lambdaQuery()
.eq(AlarmConfigDetailEntity::getStrategyId,config.getId())
.eq(AlarmConfigDetailEntity::getAlarmType,source)
.eq(AlarmConfigDetailEntity::getAlarmChiledType,type)
);
if(ObjectUtil.isEmpty(config)){
return detailService.defaultMark(source,type);
}
AlarmHandleMarkVo mark = new AlarmHandleMarkVo();
mark.setIsRightTabulation(detail.getIsRightTabulation());
mark.setIsBroadcast(detail.getIsBroadcast());
mark.setIsMask(detail.getIsMask());
mark.setIsPlatformMessage(detail.getIsPlatformMessage());
mark.setIsShowAlert(detail.getIsShowAlert());
mark.setIsSmallBell(detail.getIsSmallBell());
mark.setIsShortMessage(detail.getIsShortMessage());
mark.setIsWxMessage(detail.getIsWxMessage());
return mark;
}
/**
* 获取默认告警配置
* @return
*/
private AlarmHandleMarkVo defaultMark() {
return new AlarmHandleMarkVo();
}
/**
* 是否支持操作 * 是否支持操作
* @param code : 站点编码 * @param code : 站点编码
* @param source : 告警来源 * @param source : 告警来源

53
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java

@ -14,32 +14,31 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
*/ */
public class QuqueConfig { public class QuqueConfig {
/**
* 创建连接工厂
*
* @param connectionFactory
* @param adapter
* @return
*/
@Bean
public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
MessageListenerAdapter adapter) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
//监听对应的channel
container.addMessageListener(adapter, new PatternTopic("alarmchannel"));
return container;
}
/** /**
* 创建连接工厂 * 绑定消息监听者和接收监听的方法
* * @param message
* @param connectionFactory * @return
* @param adapter */
* @return @Bean
*/ public MessageListenerAdapter adapter(RedisMessageListener message) {
@Bean // onMessage 如果RedisMessage 中 没有实现接口,这个参数必须跟RedisMessage中的读取信息的方法名称一样
public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, return new MessageListenerAdapter(message, "onMessage");
MessageListenerAdapter adapter) { }
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
//监听对应的channel
container.addMessageListener(adapter, new PatternTopic("alarmchannel"));
return container;
}
/**
* 绑定消息监听者和接收监听的方法
* @param message
* @return
*/
@Bean
public MessageListenerAdapter adapter(RedisMessageListener message) {
// onMessage 如果RedisMessage 中 没有实现接口,这个参数必须跟RedisMessage中的读取信息的方法名称一样
return new MessageListenerAdapter(message, "onMessage");
}
} }

5
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/AlarmSaveService.java

@ -1,8 +1,13 @@
package com.hnac.hzims.alarm.monitor.service; package com.hnac.hzims.alarm.monitor.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import java.util.List;
/** /**
* @author ysj * @author ysj
*/ */
public interface AlarmSaveService { public interface AlarmSaveService {
Boolean save(List<AlarmEntity> alarms);
} }

78
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java

@ -1,9 +1,25 @@
package com.hnac.hzims.alarm.monitor.service.impl; package com.hnac.hzims.alarm.monitor.service.impl;
import com.hnac.hzims.alarm.config.service.AlarmConfigService;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.vo.AlarmHandleMarkVo;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author ysj * @author ysj
@ -11,6 +27,66 @@ import org.springframework.stereotype.Service;
@AllArgsConstructor @AllArgsConstructor
@Service @Service
@Slf4j @Slf4j
public class AlarmSaveServiceImpl implements AlarmSaveService { public class AlarmSaveServiceImpl implements AlarmSaveService {
private final AlarmService alarmService;
private final AlarmConfigService alarmConfigService;
private final IStationClient stationClient;
private final RedisTemplate<Object, Object> redisTemplate;
@GetMapping(value = "pub/{msg}")
public String pubMsg(@PathVariable String msg){
return msg;
}
/**
* 告警数据保存
* @param alarms
* @return
*/
@Override
public Boolean save(List<AlarmEntity> alarms) {
// 步骤1.查询告警数据对应站点
R<List<StationEntity>> result = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList()));
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){
log.error("alarm query station is null : {}",alarms.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()));
return false;
}
// 步骤2.遍历保存告警数据
alarms.forEach(alarm->{
// 步骤3.根据站点查询配置标识
AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType());
if(ObjectUtil.isEmpty(mark)){
log.error("alarm obtain mark is null : {}",alarm.getAlarmId());
return;
}
// 步骤4.告警处理标识赋值
alarm.setIsRightTabulation(mark.getIsRightTabulation());
alarm.setIsBroadcast(mark.getIsBroadcast());
alarm.setIsMask(mark.getIsMask());
alarm.setIsPlatformMessage(mark.getIsPlatformMessage());
alarm.setIsShowAlert(mark.getIsShowAlert());
alarm.setIsSmallBell(mark.getIsSmallBell());
alarm.setIsShortMessage(mark.getIsShortMessage());
alarm.setIsWxMessage(mark.getIsWxMessage());
// 步骤5.保存当日告警数据
boolean isSave = alarmService.save(alarm);
if(!isSave){
log.error("alarm save fail : {}",alarm.getAlarmId());
return;
}
// 步骤6.发生数据至redis告警队列
redisTemplate.convertAndSend("alarmchannel",alarm);
});
return true;
}
} }

8
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java

@ -128,9 +128,11 @@ public class StationClient implements IStationClient {
return R.data(stationService.getOne(request)); return R.data(stationService.getOne(request));
} }
@Override
public R<List<StationEntity>> querySatationByCodes(List<String> codes) {
return R.data(stationService.list(Wrappers.<StationEntity>lambdaQuery()
.in(StationEntity::getCode,codes)));
}
@Override @Override

Loading…
Cancel
Save