Browse Source

推送告警消息邮件

zhongwei
ty 8 months ago
parent
commit
42332e9882
  1. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java
  2. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java
  3. 13
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java

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

@ -46,7 +46,7 @@ public class AlarmListener implements IQueueConsume {
// 步骤4.微信公众号发送 // 步骤4.微信公众号发送
if(ObjectUtil.isNotEmpty(alarm.getIsWxMessage()) && alarm.getIsWxMessage() == 0){ if(ObjectUtil.isNotEmpty(alarm.getIsWxMessage()) && alarm.getIsWxMessage() == 0){
//messageService.weChatMessage(alarm); messageService.weChatMessage(alarm);
} }
} }
} }

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java

@ -148,7 +148,7 @@ public class MessageServiceImpl implements MessageService {
} }
WxMessageDTO message = new WxMessageDTO(); WxMessageDTO message = new WxMessageDTO();
// 模板Id // 模板Id
message.setTemplateId("hIgINCsjpG-gyCKh8wzwBWjR-hkbjkNLFTXQEsnR_Z8"); message.setTemplateId("Ce2YAZtX0UyoNrAag6CANtC8XQeLuil7domvJrUivhM");
// 微信消息跳转地址 // 微信消息跳转地址
message.setSkipUrl("http://baidu.com"); message.setSkipUrl("http://baidu.com");
// 机构Id // 机构Id
@ -164,7 +164,7 @@ public class MessageServiceImpl implements MessageService {
map.put("thing18",entity.getStationName()); map.put("thing18",entity.getStationName());
map.put("thing5",Optional.ofNullable(entity.getDeviceCode()).orElse("未知设备")); map.put("thing5",Optional.ofNullable(entity.getDeviceCode()).orElse("未知设备"));
map.put("thing11",entity.getAlarmContext()); map.put("thing11",entity.getAlarmContext());
map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmType())); map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmSource()));
map.put("time2",entity.getAlarmTime()); map.put("time2",entity.getAlarmTime());
message.setMap(map); message.setMap(map);
// 消息内容 // 消息内容

13
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java

@ -86,9 +86,20 @@ public class WxMessageServiceImpl implements IMessageService {
PushTemplate template = new PushTemplate(); PushTemplate template = new PushTemplate();
template.setTemplateId(message.getTemplateId()); template.setTemplateId(message.getTemplateId());
template.setSkipUrl(message.getSkipUrl()); template.setSkipUrl(message.getSkipUrl());
template.setMap(message.getMap()); Map<String, Object> map = message.getMap();
map.replaceAll((key,value)->getTruncateString(value.toString(),27));
template.setMap(map);
template.setUserIds(Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList())); template.setUserIds(Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList()));
template.setTenantId("200000");
R<WxPushFeignVO> result = wxPushClient.sendPushTemplateByUserId(template); R<WxPushFeignVO> result = wxPushClient.sendPushTemplateByUserId(template);
return result.isSuccess(); return result.isSuccess();
} }
private String getTruncateString(String ruleDefName, int maxSize) {
if (ruleDefName.length()<= maxSize){
return ruleDefName;
}else {
return ruleDefName.substring(0, maxSize - 3) + "...";
}
}
} }

Loading…
Cancel
Save