From 3b2a451b0f536293a4ce2563fd7b287453cf4906 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 15 Nov 2023 13:43:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/alarm/entity/AlarmEntity.java | 1 + .../alarm/monitor/listener/AlarmListener.java | 31 +++++++-------- .../hzims/alarm/monitor/listener/QuqueConfig.java | 44 ---------------------- .../monitor/service/impl/AlarmSaveServiceImpl.java | 25 ++++-------- 4 files changed, 23 insertions(+), 78 deletions(-) delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmEntity.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmEntity.java index ed28604..1a273d8 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmEntity.java +++ b/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; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java index 2e553a7..4956b5d 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java +++ b/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 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); } -} +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java deleted file mode 100644 index 31c63b6..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/QuqueConfig.java +++ /dev/null @@ -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"); - } -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java index bb22640..9ec38d8 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java +++ b/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 alarms) { - // 步骤1.查询告警数据对应站点 + /*// 步骤1.查询告警数据对应站点 R> 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; } From a725c2a79a09b4231a452c981dedae683659ab68 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 15 Nov 2023 15:15:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/alarm/handle/service/MessageService.java | 2 +- .../handle/service/impl/MessageServiceImpl.java | 2 +- .../alarm/monitor/listener/AlarmListener.java | 30 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java index 92b3f74..230150e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java +++ b/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); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java index 9e62c3f..fd80cc9 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java +++ b/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) { } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java index 4956b5d..8741a71 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java @@ -2,11 +2,14 @@ package com.hnac.hzims.alarm.monitor.listener; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.handle.service.MessageService; +import com.hnac.hzims.message.fegin.IMessageClient; 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.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; /** @@ -18,11 +21,32 @@ import org.springframework.stereotype.Service; public class AlarmListener implements IQueueConsume { @Autowired - private RedisTemplate redisTemplate; + private MessageService messageService; + + @Autowired + private StringRedisTemplate redisTemplate; @Override public void handlerMessage(String message) { + if(StringUtil.isEmpty(message)){ + return; + } + // 步骤1.消息对象转换 AlarmEntity alarm = JSONObject.parseObject(message,AlarmEntity.class); - log.error("handler_message_alarm : {}",alarm); + + // 步骤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); + } } } \ No newline at end of file From 117acc2b09aaf0a6964aeadac201aaa3f35681b7 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 15 Nov 2023 17:09:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java | 7 +++---- .../java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java index fd80cc9..8200dd8 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java @@ -53,14 +53,14 @@ public class MessageServiceImpl implements MessageService { boolean support = alarmConfigService.isSupport(entity.getStationId(), entity.getAlarmSource(), entity.getAlarmType(), AlarmConstants.IS_PLATFORM_MESSAGE); R 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> 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); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java index 8741a71..ce4f618 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java @@ -3,7 +3,6 @@ package com.hnac.hzims.alarm.monitor.listener; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; import com.hnac.hzims.alarm.handle.service.MessageService; -import com.hnac.hzims.message.fegin.IMessageClient; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.StringUtil; import org.springblade.queue.annotation.RedisQueue;