Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
tyty 1 year ago
parent
commit
d91445ca0b
  1. 1
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmEntity.java
  2. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java
  3. 9
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java
  4. 52
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java
  5. 44
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java
  6. 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;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java

@ -7,7 +7,7 @@ import com.hnac.hzims.alarm.entity.AlarmEntity;
*/
public interface MessageService {
void message(AlarmEntity entity);
void shortMessage(AlarmEntity entity);
void webAppMessage(AlarmEntity entity);

9
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java

@ -40,7 +40,7 @@ public class MessageServiceImpl implements MessageService {
* @param entity : 告警对象
*/
@Override
public void message(AlarmEntity entity) {
public void shortMessage(AlarmEntity entity) {
}
@ -53,14 +53,14 @@ public class MessageServiceImpl implements MessageService {
boolean support = alarmConfigService.isSupport(entity.getStationId(), entity.getAlarmSource(), entity.getAlarmType(), AlarmConstants.IS_PLATFORM_MESSAGE);
R<StationEntity> stationByCode = stationClient.getStationByCode(entity.getStationId());
if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) {
log.error("消息发送失败:站点code获取失败",entity);
log.error("消息发送失败:站点code获取失败 : {}",entity);
return;
}
Long dept = stationByCode.getData().getCreateDept();
// 获取站点用户
R<List<User>> result = userClient.userListByDeptId(dept);
if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) {
log.error("消息发送失败:用户获取失败",entity);
log.error("消息发送失败:用户获取失败 : {}",entity);
return;
}
if (support) {
@ -68,8 +68,7 @@ public class MessageServiceImpl implements MessageService {
message.setBusinessClassify("warning");
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey());
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription());
// todo
// message.setTaskId(entity.getAlarmId());
message.setTaskId(Long.valueOf(entity.getAlarmId()));
message.setTenantId("200000");
message.setContent(entity.getAlarmContext());
message.setDeptId(dept);

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

@ -1,31 +1,51 @@
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 com.hnac.hzims.alarm.handle.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.StringUtil;
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.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
/**
* @author ysj
* @version 4.0.0
* @create 2023-11-09-14:04
*/
@Component
public class AlarmListener implements MessageListener {
@Service
@RedisQueue(topicName = "hzims:queue:alarm")
@Slf4j
public class AlarmListener implements IQueueConsume {
@Autowired
private AlarmMessageSendService alarmMessageSendService;
private MessageService messageService;
@Autowired
private RedisTemplate redisTemplate;
private StringRedisTemplate 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) {
if(StringUtil.isEmpty(message)){
return;
}
// 步骤1.消息对象转换
AlarmEntity alarm = JSONObject.parseObject(message,AlarmEntity.class);
// 步骤2.WEB/APP消息推送
if(alarm.getIsPlatformMessage() == 0){
messageService.webAppMessage(alarm);
}
// 步骤3.短信推送
if(alarm.getIsShortMessage() == 0){
messageService.shortMessage(alarm);
}
// 步骤4.微信公众号发送
if(alarm.getIsWxMessage() == 0){
messageService.weChatMessage(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