Browse Source

#告警短信推送bug修改

zhongwei
yang_shj 8 months ago
parent
commit
569621b8aa
  1. 5
      hzims-biz-common/src/main/java/com/hnac/hzims/common/constant/CommonConstant.java
  2. 7
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java
  3. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java
  4. 79
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java

5
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;
}

7
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);
}
}

4
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);
}

79
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<StationEntity> station = stationClient.getStationByCode(entity.getStationId());
if (!station.isSuccess() || ObjectUtils.isEmpty(station.getData())) {
log.error("消息发送失败:站点code获取失败 : {}",entity);
return;
}
//通知站点项目经理这个角色
List<User> 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<String,String>(){{
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<StationEntity> station = stationClient.getStationByCode(entity.getStationId());
if (!station.isSuccess() || ObjectUtils.isEmpty(station.getData())) {
log.error("短信发送失败:站点code获取失败 : {}",entity);
return;
}
log.error("短信发送,站点信息: {}",station.getData());
//通知站点项目经理这个角色
List<User> 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<String,String>(){{
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
*/

Loading…
Cancel
Save