diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/LarkAttribute.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/LarkAttribute.java index 9f4d4339..e1fbeffd 100644 --- a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/LarkAttribute.java +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/LarkAttribute.java @@ -2,8 +2,10 @@ package com.aizuda.easy.retry.common.core.alarm; import lombok.Data; +import java.util.List; + /** - * 飞书地址 + * 飞书 * * @author: www.byteblogs.com * @date : 2023-05-31 13:45 @@ -13,4 +15,8 @@ import lombok.Data; public class LarkAttribute { private String larkUrl; + + private List ats; + + private boolean isAtAll; } diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/LarkAlarm.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/LarkAlarm.java index 0e4ce2e3..b208345d 100644 --- a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/LarkAlarm.java +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/LarkAlarm.java @@ -1,5 +1,4 @@ package com.aizuda.easy.retry.common.core.alarm.strategy; - import cn.hutool.http.ContentType; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; @@ -14,7 +13,8 @@ import lombok.Builder; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; - +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -31,6 +31,10 @@ import java.util.Map; @Slf4j public class LarkAlarm extends AbstractAlarm { + + + public static final String atLabel = ""; + @Override public Integer getAlarmType() { return AlarmTypeEnum.LARK.getValue(); @@ -52,7 +56,7 @@ public class LarkAlarm extends AbstractAlarm { Map map = new HashMap<>(); map.put("header", buildHeader(context.getTitle())); - map.put("elements", buildElements(context.getText())); + map.put("elements", buildElements(context.getText(),larkAttribute.getAts(),larkAttribute.isAtAll())); LarkMessage builder = LarkMessage.builder() .msgType("interactive") @@ -71,10 +75,10 @@ public class LarkAlarm extends AbstractAlarm { return true; } - private List buildElements(final String text) { + private List buildElements(String text,List ats,boolean isAtAll) { Map map = new HashMap<>(); map.put("tag", "markdown"); - map.put("content", text); + map.put("content", getAtText(text,ats,isAtAll)); return Collections.singletonList(map); } @@ -110,5 +114,16 @@ public class LarkAlarm extends AbstractAlarm { private Map card; } + public String getAtText(String text, List ats, boolean isAtAll) { + StringBuilder sb = new StringBuilder(text); + if (isAtAll) { + sb.append(MessageFormat.format(atLabel, "all")); + } else { + if (!CollectionUtils.isEmpty(ats)) { + ats.forEach(at -> sb.append(MessageFormat.format(atLabel, at))); + } + } + return sb.toString(); + } } diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/util/DingDingUtils.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/util/DingDingUtils.java index b1aba572..be7e22e2 100644 --- a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/util/DingDingUtils.java +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/util/DingDingUtils.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import java.text.MessageFormat; import java.util.Arrays; import java.util.List; @@ -17,6 +18,9 @@ import java.util.List; */ @Slf4j public class DingDingUtils { + + public static final String atLabel = "@{0}"; + /** * 防止文本过长钉钉限流,目前最大为4000 * @@ -55,14 +59,13 @@ public class DingDingUtils { return request; } - private static String getAtText(List ats, String text) { - if(CollectionUtils.isEmpty(ats)){ + public static String getAtText(List ats, String text) { + if (CollectionUtils.isEmpty(ats)) { return text; } - for(String at: ats){ - text = "@" + at; - } - return text; + StringBuilder sb = new StringBuilder(text); + ats.forEach(at -> sb.append(MessageFormat.format(atLabel, at))); + return sb.toString(); } /** diff --git a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailDeadLetterAlarmListener.java b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailDeadLetterAlarmListener.java index 1d1ab367..cc18ca04 100644 --- a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailDeadLetterAlarmListener.java +++ b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailDeadLetterAlarmListener.java @@ -107,7 +107,7 @@ public class RetryTaskFailDeadLetterAlarmListener extends AbstractFlowControl im retryDeadLetter.getSceneName(), retryDeadLetter.getArgsStr(), DateUtils.format(retryDeadLetter.getCreateDt(), DateUtils.NORM_DATETIME_PATTERN)) - .title("组:[{}] 场景:[{}] 环境重试任务失败进入死信队列", retryDeadLetter.getGroupName(), retryDeadLetter.getSceneName()) + .title("{}环境 重试任务失败进入死信队列", EnvironmentUtils.getActiveProfile()) .notifyAttribute(notifyConfig.getNotifyAttribute()); Alarm alarmType = easyRetryAlarmFactory.getAlarmType(notifyConfig.getNotifyType()); alarmType.asyncSendMessage(context); diff --git a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailMoreThresholdAlarmListener.java b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailMoreThresholdAlarmListener.java index 9611580f..7c1a3a17 100644 --- a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailMoreThresholdAlarmListener.java +++ b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/listener/RetryTaskFailMoreThresholdAlarmListener.java @@ -98,7 +98,7 @@ public class RetryTaskFailMoreThresholdAlarmListener extends AbstractFlowControl retryTask.getRetryCount(), retryTask.getArgsStr(), DateUtils.format(retryTask.getCreateDt(), DateUtils.NORM_DATETIME_PATTERN)) - .title("组:[{}] 场景:[{}] 环境重试任务失败数量超过阈值", retryTask.getGroupName(), retryTask.getSceneName()) + .title("{}环境 环境重试任务失败数量超过阈值", EnvironmentUtils.getActiveProfile()) .notifyAttribute(notifyConfig.getNotifyAttribute()); Alarm alarmType = easyRetryAlarmFactory.getAlarmType(notifyConfig.getNotifyType()); alarmType.asyncSendMessage(context); diff --git a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryErrorMoreThresholdAlarmSchedule.java b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryErrorMoreThresholdAlarmSchedule.java index dc4ffa76..a1cc6d45 100644 --- a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryErrorMoreThresholdAlarmSchedule.java +++ b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryErrorMoreThresholdAlarmSchedule.java @@ -81,8 +81,8 @@ public class RetryErrorMoreThresholdAlarmSchedule extends AbstractSchedule imple sceneConfig.getSceneName(), DateUtils.format(now.minusMinutes(30), DateUtils.NORM_DATETIME_PATTERN), - DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN), count) - .title("组:[{}] 场景:[{}] 环境重试失败数据监控", sceneConfig.getGroupName(),sceneConfig.getSceneName()) + DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN), count) + .title("{}环境 场景重试失败数量超过阈值", EnvironmentUtils.getActiveProfile()) .notifyAttribute(notifyConfig.getNotifyAttribute()); Alarm alarmType = easyRetryAlarmFactory.getAlarmType(notifyConfig.getNotifyType()); alarmType.asyncSendMessage(context); diff --git a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryTaskMoreThresholdAlarmSchedule.java b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryTaskMoreThresholdAlarmSchedule.java index 821ae917..3d6f53f4 100644 --- a/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryTaskMoreThresholdAlarmSchedule.java +++ b/easy-retry-server/easy-retry-server-retry-task/src/main/java/com/aizuda/easy/retry/server/retry/task/support/schedule/RetryTaskMoreThresholdAlarmSchedule.java @@ -79,7 +79,7 @@ public class RetryTaskMoreThresholdAlarmSchedule extends AbstractSchedule implem sceneConfig.getSceneName(), DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN), count) - .title("组:[{}] 场景:[{}] 重试数据过多", sceneConfig.getGroupName(),sceneConfig.getSceneName()) + .title("{}环境 场景重试数量超过阈值", EnvironmentUtils.getActiveProfile()) .notifyAttribute(notifyConfig.getNotifyAttribute()); Alarm alarmType = easyRetryAlarmFactory.getAlarmType(notifyConfig.getNotifyType()); alarmType.asyncSendMessage(context); diff --git a/frontend/src/views/task/form/NotifyFrom.vue b/frontend/src/views/task/form/NotifyFrom.vue index d64f3fbd..d7efc30c 100644 --- a/frontend/src/views/task/form/NotifyFrom.vue +++ b/frontend/src/views/task/form/NotifyFrom.vue @@ -163,14 +163,14 @@ ]" /> - 被@负责人手机号  + 被@人手机号  - 被@负责人用户id  + 被@负责人用户id