Skip to content

Commit

Permalink
bugfix enterprise wechat push display content is too cumbersome (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
l646505418 authored Aug 28, 2023
1 parent bda7223 commit 1fffd7f
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hertzbeat.common.constants.CommonConstants;
import org.dromara.hertzbeat.common.entity.alerter.Alert;
import org.dromara.hertzbeat.common.entity.manager.NoticeReceiver;
import org.dromara.hertzbeat.common.util.JsonUtil;
Expand All @@ -16,6 +17,8 @@
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
Expand Down Expand Up @@ -60,7 +63,7 @@ public void send(NoticeReceiver receiver, Alert alert) throws AlertNoticeExcepti
if (Objects.nonNull(entityResponse.getBody())) {
String accessToken = entityResponse.getBody().getAccessToken();
WeChatAppDTO.TextDTO textDTO = new WeChatAppDTO.TextDTO();
textDTO.setContent(JsonUtil.toJson(alert));
textDTO.setContent(generateContent(alert));
WeChatAppDTO weChatAppDTO = WeChatAppDTO.builder()
.toUser(DEFAULT_ALL)
.msgType(DEFAULT_TYPE)
Expand All @@ -86,4 +89,13 @@ public byte type() {
return 10;
}


private String generateContent(Alert alert){
Map<String,Object> contentMap = new HashMap<>(8);
contentMap.put("alertDefineId",alert.getAlertDefineId());
contentMap.put("content",alert.getContent());
contentMap.put("monitorName",alert.getTags().get(CommonConstants.TAG_MONITOR_NAME));
return JSON.toJSONString(contentMap);
}

}

0 comments on commit 1fffd7f

Please sign in to comment.