Pre Merge pull request !38 from 李中原/dev_2.6.0

This commit is contained in:
李中原 2023-12-18 06:07:13 +00:00 committed by Gitee
commit 4d43bb3a5f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 17 additions and 13 deletions

View File

@ -36,7 +36,7 @@ import java.util.Map;
public class LarkAlarm extends AbstractAlarm<AlarmContext> {
public static final String atLabel = "<at id={0}></at>";
public static final String AT_LABEL = "<at id={0}></at>";
@Override
public Integer getAlarmType() {
@ -45,9 +45,7 @@ public class LarkAlarm extends AbstractAlarm<AlarmContext> {
@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<AlarmContext> {
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;
}
LogUtils.error(log, "发送lark消息失败:{}", execute.body());
return false;
} catch (Exception e) {
log.error("发送lark消息失败", e);
return false;
}
return true;
}
private List buildElements(String text, List<String> ats) {
@ -123,10 +124,10 @@ public class LarkAlarm extends AbstractAlarm<AlarmContext> {
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();
}

View File

@ -26,7 +26,7 @@ import java.util.Map;
@Component
public class QiYeWechatAlarm extends AbstractAlarm<AlarmContext> {
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<AlarmContext> {
}
Map<String, Object> 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;
}
LogUtils.error(log, "发送企业微信消息失败:{}", execute.body());
return false;
} catch (Exception e) {
log.error("发送企业微信消息失败", e);
return false;
}
return true;
}
@Override

View File

@ -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) {
}