From 569621b8aa010bdbb66ec3699b6a1441f025bcbd Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Sat, 16 Mar 2024 08:59:29 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E7=9F=AD=E4=BF=A1=E6=8E=A8?= =?UTF-8?q?=E9=80=81bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/common/constant/CommonConstant.java | 5 ++ .../alarm/monitor/listener/AlarmListener.java | 7 +- .../hzims/alarm/source/service/MessageService.java | 4 +- .../source/service/impl/MessageServiceImpl.java | 79 +++++++++++----------- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/constant/CommonConstant.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/constant/CommonConstant.java index 801f766..71e02f3 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/constant/CommonConstant.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/constant/CommonConstant.java @@ -54,4 +54,9 @@ public interface CommonConstant { */ String TENANT_ID = "200000"; + /** + * 系统用户 + */ + Long SYSTEM_USER = 1434782836098891778L; + } 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 e48bf9a..bb125ac 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 @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.config.entity.AlarmEntity; import com.hnac.hzims.alarm.source.service.MessageService; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.queue.annotation.RedisQueue; import org.springblade.queue.consume.IQueueConsume; @@ -34,17 +35,17 @@ public class AlarmListener implements IQueueConsume { AlarmEntity alarm = JSONObject.parseObject(message,AlarmEntity.class); // 步骤2.WEB/APP消息推送 - if(alarm.getIsPlatformMessage() == 0){ + if(ObjectUtil.isNotEmpty(alarm.getIsPlatformMessage()) && alarm.getIsPlatformMessage() == 0){ messageService.webAppMessage(alarm); } // 步骤3.短信推送 - if(alarm.getIsShortMessage() == 0){ + if(ObjectUtil.isNotEmpty(alarm.getIsShortMessage()) && alarm.getIsShortMessage() == 0){ messageService.shortMessage(alarm); } // 步骤4.微信公众号发送 - if(alarm.getIsWxMessage() == 0){ + if(ObjectUtil.isNotEmpty(alarm.getIsWxMessage()) && alarm.getIsWxMessage() == 0){ //messageService.weChatMessage(alarm); } } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java index f2e499d..71b8661 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java @@ -7,9 +7,9 @@ import com.hnac.hzims.alarm.config.entity.AlarmEntity; */ public interface MessageService { - void shortMessage(AlarmEntity entity); - void webAppMessage(AlarmEntity entity); + void shortMessage(AlarmEntity entity); + void weChatMessage(AlarmEntity entity); } \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java index 1dd637b..a42107e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java @@ -5,6 +5,7 @@ import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.service.AlarmConfigService; import com.hnac.hzims.alarm.config.entity.AlarmEntity; import com.hnac.hzims.alarm.source.service.MessageService; +import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.BusinessMessageDTO; import com.hnac.hzims.message.dto.SmsImmediatelyPushDTO; @@ -30,6 +31,7 @@ import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MANAGER; @@ -54,44 +56,6 @@ public class MessageServiceImpl implements MessageService { private final AlarmConfigService alarmConfigService; /** - * 短信推送 - * @param entity : 告警对象 - */ - @Override - public void shortMessage(AlarmEntity entity) { - R station = stationClient.getStationByCode(entity.getStationId()); - if (!station.isSuccess() || ObjectUtils.isEmpty(station.getData())) { - log.error("消息发送失败:站点code获取失败 : {}",entity); - return; - } - //通知站点项目经理这个角色 - List users = userClient.relationUserListByRoleAlias(station.getData().getTenantId(), station.getData().getRefDept(), PROJECT_MANAGER).getData(); - if(CollectionUtil.isEmpty(users)){ - log.error("消息发送失败:获取站点项目经理用户失败 : {}",entity); - return; - } - SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() - .deptId(entity.getCreateDept()) - .taskId(entity.getId()) - .businessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()) - .businessClassify(MessageConstants.BusinessClassifyEnum.WARNING.getKey()) - .content(entity.getAlarmContext()) - .subject("告警短信通知") - .tenantId(entity.getTenantId()) - .resourceCode(AlarmConstants.SMS_MESSAGE_TEMPLATE_CODE) - .pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) - .createUser(station.getData().getCreateUser()) - .params(new HashMap(){{ - put("projectName",entity.getStationName()); - put("deviceName",entity.getDeviceName()); - put("ruleDefName",entity.getAlarmContext()); - put("ts", DateUtil.format(entity.getAlarmTime(),DateUtil.PATTERN_DATETIME)); - }}) - .build(); - messageClient.sendSmsImmediatelyMsg(push); - } - - /** * web/app消息推送 * @param entity : 告警对象 */ @@ -127,6 +91,45 @@ public class MessageServiceImpl implements MessageService { } /** + * 短信推送 + * @param entity : 告警对象 + */ + @Override + public void shortMessage(AlarmEntity entity) { + R station = stationClient.getStationByCode(entity.getStationId()); + if (!station.isSuccess() || ObjectUtils.isEmpty(station.getData())) { + log.error("短信发送失败:站点code获取失败 : {}",entity); + return; + } + log.error("短信发送,站点信息: {}",station.getData()); + //通知站点项目经理这个角色 + List users = userClient.relationUserListByRoleAlias(station.getData().getTenantId(), station.getData().getRefDept(), PROJECT_MANAGER).getData(); + if(CollectionUtil.isEmpty(users)){ + log.error("短信发送失败:获取站点项目经理用户失败 : {}",entity); + return; + } + SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() + .deptId(entity.getCreateDept()) + .taskId(entity.getId()) + .businessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()) + .businessClassify(MessageConstants.BusinessClassifyEnum.WARNING.getKey()) + .content(entity.getAlarmContext()) + .subject("告警短信通知") + .tenantId(entity.getTenantId()) + .resourceCode(AlarmConstants.SMS_MESSAGE_TEMPLATE_CODE) + .pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) + .createUser(CommonConstant.SYSTEM_USER) + .params(new HashMap(){{ + put("projectName",entity.getStationName()); + put("deviceName", Optional.ofNullable(entity.getDeviceName()).orElse("")); + put("ruleDefName",entity.getAlarmContext()); + put("ts", DateUtil.format(entity.getAlarmTime(),DateUtil.PATTERN_DATETIME)); + }}) + .build(); + messageClient.sendSmsImmediatelyMsg(push); + } + + /** * 微信公众号消息推送 * @param entity */