Browse Source

#告警修改

zhongwei
yang_shj 1 year ago
parent
commit
3b2a451b0f
  1. 1
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmEntity.java
  2. 31
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java
  3. 44
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java
  4. 25
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java

1
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmEntity.java

@ -7,6 +7,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import java.io.Serializable;
import java.util.Date;

31
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java

@ -1,31 +1,28 @@
package com.hnac.hzims.alarm.monitor.listener;
import com.hnac.hzims.alarm.monitor.service.AlarmMessageSendService;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.alarm.entity.AlarmEntity;
import lombok.extern.slf4j.Slf4j;
import org.springblade.queue.annotation.RedisQueue;
import org.springblade.queue.consume.IQueueConsume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* @author ysj
* @version 4.0.0
* @create 2023-11-09-14:04
*/
@Component
public class AlarmListener implements MessageListener {
@Autowired
private AlarmMessageSendService alarmMessageSendService;
@Service
@RedisQueue(topicName = "hzims:queue:alarm")
@Slf4j
public class AlarmListener implements IQueueConsume {
@Autowired
private RedisTemplate redisTemplate;
@Override
public void onMessage(Message message, byte[] pattern) {
RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
String msg = serializer.deserialize(message.getBody());
System.out.println("接收到的消息是:" + msg);
public void handlerMessage(String message) {
AlarmEntity alarm = JSONObject.parseObject(message,AlarmEntity.class);
log.error("handler_message_alarm : {}",alarm);
}
}
}

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

@ -1,44 +0,0 @@
package com.hnac.hzims.alarm.monitor.listener;
import com.hnac.hzims.common.config.RedisMessageListener;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
/**
* @author ysj
* @version 4.0.0
* @create 2023-11-09 14:02
*/
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
* @return
*/
@Bean
public MessageListenerAdapter adapter(RedisMessageListener message) {
// onMessage 如果RedisMessage 中 没有实现接口,这个参数必须跟RedisMessage中的读取信息的方法名称一样
return new MessageListenerAdapter(message, "onMessage");
}
}

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

@ -1,25 +1,22 @@
package com.hnac.hzims.alarm.monitor.service.impl;
import com.alibaba.fastjson.JSON;
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.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.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.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import springfox.documentation.spring.web.json.Json;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author ysj
@ -35,13 +32,7 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
private final IStationClient stationClient;
private final RedisTemplate redisTemplate;
@GetMapping(value = "pub/{msg}")
public String pubMsg(@PathVariable String msg){
return msg;
}
private final StringRedisTemplate stringRedisTemplate;
/**
* 告警数据保存
@ -51,12 +42,12 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
@Override
public Boolean save(List<AlarmEntity> alarms) {
// 步骤1.查询告警数据对应站点
/*// 步骤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->{
@ -85,7 +76,7 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
}
// 步骤6.发生数据至redis告警队列
redisTemplate.convertAndSend("alarmchannel",alarm);
stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm));
});
return true;
}

Loading…
Cancel
Save