From 1c9f9fb9c58334e347f03898f418f5248255ffd4 Mon Sep 17 00:00:00 2001 From: lizhongyuan3 Date: Mon, 18 Dec 2023 13:53:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=92=8C=E9=A3=9E=E4=B9=A6=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/alarm/strategy/LarkAlarm.java | 17 +++++++++-------- .../core/alarm/strategy/QiYeWechatAlarm.java | 11 +++++++---- 2 files changed, 16 insertions(+), 12 deletions(-) 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 d2c094a5..e4612b48 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 @@ -36,7 +36,7 @@ import java.util.Map; public class LarkAlarm extends AbstractAlarm { - public static final String atLabel = ""; + public static final String AT_LABEL = ""; @Override public Integer getAlarmType() { @@ -45,9 +45,7 @@ public class LarkAlarm extends AbstractAlarm { @Override public boolean asyncSendMessage(AlarmContext context) { - threadPoolExecutor.execute(() -> { - syncSendMessage(context); - }); + threadPoolExecutor.execute(() -> syncSendMessage(context)); return true; } @@ -69,12 +67,15 @@ public class LarkAlarm extends AbstractAlarm { HttpRequest request = post.body(JsonUtil.toJsonString(builder), ContentType.JSON.toString()); HttpResponse execute = request.execute(); LogUtils.debug(log, JsonUtil.toJsonString(execute)); + if (execute.isOk()) { + return true; + } + log.error("发送lark消息失败:{}", execute.body()); + return false; } catch (Exception e) { log.error("发送lark消息失败", e); return false; } - - return true; } private List buildElements(String text, List ats) { @@ -123,10 +124,10 @@ public class LarkAlarm extends AbstractAlarm { StringBuilder sb = new StringBuilder(text); if (ats.stream().map(String::toLowerCase).anyMatch(SystemConstants.AT_ALL::equals)) { - sb.append(MessageFormat.format(atLabel, SystemConstants.AT_ALL)); + sb.append(MessageFormat.format(AT_LABEL, SystemConstants.AT_ALL)); } else { ats.stream().filter(StrUtil::isNotBlank) - .forEach(at -> sb.append(MessageFormat.format(atLabel, at))); + .forEach(at -> sb.append(MessageFormat.format(AT_LABEL, at))); } return sb.toString(); } diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java index 91f7a277..c0508bee 100644 --- a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java @@ -26,7 +26,7 @@ import java.util.Map; @Component public class QiYeWechatAlarm extends AbstractAlarm { - public static final String atLabel = "<@{0}>"; + public static final String AT_LABEL = "<@{0}>"; @Override public Integer getAlarmType() { @@ -50,19 +50,22 @@ public class QiYeWechatAlarm extends AbstractAlarm { } Map map = MapUtil.newHashMap(); QiYeWechatMessageContent messageContent = new QiYeWechatMessageContent(); - messageContent.setContent(StrUtil.sub(DingDingUtils.getAtText(qiYeWechatAttribute.getAts(), context.getText(), atLabel), 0, 4096)); + messageContent.setContent(StrUtil.sub(DingDingUtils.getAtText(qiYeWechatAttribute.getAts(), context.getText(), AT_LABEL), 0, 4096)); map.put("msgtype", "markdown"); map.put("markdown", messageContent); HttpRequest post = HttpUtil.createPost(webhookUrl); HttpRequest request = post.body(JsonUtil.toJsonString(map), ContentType.JSON.toString()); HttpResponse execute = request.execute(); LogUtils.debug(log, JsonUtil.toJsonString(execute)); + if (execute.isOk()) { + return true; + } + log.error("发送企业微信消息失败:{}", execute.body()); + return false; } catch (Exception e) { log.error("发送企业微信消息失败", e); return false; } - return true; - } @Override From 8eeac834a39d362005b244e911c5c7cab3e95057 Mon Sep 17 00:00:00 2001 From: lizhongyuan3 Date: Mon, 18 Dec 2023 14:00:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=92=8C=E9=A3=9E=E4=B9=A6=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aizuda/easy/retry/common/core/alarm/strategy/LarkAlarm.java | 2 +- .../easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 e4612b48..1ffcddc0 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 @@ -70,7 +70,7 @@ public class LarkAlarm extends AbstractAlarm { if (execute.isOk()) { return true; } - log.error("发送lark消息失败:{}", execute.body()); + LogUtils.error(log, "发送lark消息失败:{}", execute.body()); return false; } catch (Exception e) { log.error("发送lark消息失败", e); diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java index c0508bee..39a92de2 100644 --- a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/alarm/strategy/QiYeWechatAlarm.java @@ -60,7 +60,7 @@ public class QiYeWechatAlarm extends AbstractAlarm { if (execute.isOk()) { return true; } - log.error("发送企业微信消息失败:{}", execute.body()); + LogUtils.error(log, "发送企业微信消息失败:{}", execute.body()); return false; } catch (Exception e) { log.error("发送企业微信消息失败", e); From 49f7e8aa179a7ca90c407eb255d5bd452d264b38 Mon Sep 17 00:00:00 2001 From: lizhongyuan3 Date: Mon, 18 Dec 2023 14:03:06 +0800 Subject: [PATCH 3/3] =?UTF-8?q?LogUtils=20=E8=8E=B7=E5=8F=96=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=8A=B6=E6=80=81=E5=BB=BA=E8=AE=AE=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=92=8C=20SystemProperties=E3=80=81EasyRetryProperti?= =?UTF-8?q?es=20=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aizuda/easy/retry/common/core/log/LogUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/log/LogUtils.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/log/LogUtils.java index 4e416fb1..1c7aeb85 100644 --- a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/log/LogUtils.java +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/log/LogUtils.java @@ -69,7 +69,7 @@ public class LogUtils { try { Environment environment = SpringContext.CONTEXT.getBean(Environment.class); - return environment.getProperty("easy.retry.log.status", Boolean.class, Boolean.TRUE); + return environment.getProperty("easy-retry.log.status", Boolean.class, Boolean.TRUE); } catch (Exception ignored) { }