Pre Merge pull request !38 from 李中原/dev_2.6.0
This commit is contained in:
commit
4d43bb3a5f
@ -36,7 +36,7 @@ import java.util.Map;
|
|||||||
public class LarkAlarm extends AbstractAlarm<AlarmContext> {
|
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
|
@Override
|
||||||
public Integer getAlarmType() {
|
public Integer getAlarmType() {
|
||||||
@ -45,9 +45,7 @@ public class LarkAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean asyncSendMessage(AlarmContext context) {
|
public boolean asyncSendMessage(AlarmContext context) {
|
||||||
threadPoolExecutor.execute(() -> {
|
threadPoolExecutor.execute(() -> syncSendMessage(context));
|
||||||
syncSendMessage(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -69,12 +67,15 @@ public class LarkAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
HttpRequest request = post.body(JsonUtil.toJsonString(builder), ContentType.JSON.toString());
|
HttpRequest request = post.body(JsonUtil.toJsonString(builder), ContentType.JSON.toString());
|
||||||
HttpResponse execute = request.execute();
|
HttpResponse execute = request.execute();
|
||||||
LogUtils.debug(log, JsonUtil.toJsonString(execute));
|
LogUtils.debug(log, JsonUtil.toJsonString(execute));
|
||||||
|
if (execute.isOk()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
LogUtils.error(log, "发送lark消息失败:{}", execute.body());
|
||||||
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("发送lark消息失败", e);
|
log.error("发送lark消息失败", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List buildElements(String text, List<String> ats) {
|
private List buildElements(String text, List<String> ats) {
|
||||||
@ -123,10 +124,10 @@ public class LarkAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
|
|
||||||
StringBuilder sb = new StringBuilder(text);
|
StringBuilder sb = new StringBuilder(text);
|
||||||
if (ats.stream().map(String::toLowerCase).anyMatch(SystemConstants.AT_ALL::equals)) {
|
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 {
|
} else {
|
||||||
ats.stream().filter(StrUtil::isNotBlank)
|
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();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
public class QiYeWechatAlarm extends AbstractAlarm<AlarmContext> {
|
public class QiYeWechatAlarm extends AbstractAlarm<AlarmContext> {
|
||||||
|
|
||||||
public static final String atLabel = "<@{0}>";
|
public static final String AT_LABEL = "<@{0}>";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getAlarmType() {
|
public Integer getAlarmType() {
|
||||||
@ -50,19 +50,22 @@ public class QiYeWechatAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
}
|
}
|
||||||
Map<String, Object> map = MapUtil.newHashMap();
|
Map<String, Object> map = MapUtil.newHashMap();
|
||||||
QiYeWechatMessageContent messageContent = new QiYeWechatMessageContent();
|
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("msgtype", "markdown");
|
||||||
map.put("markdown", messageContent);
|
map.put("markdown", messageContent);
|
||||||
HttpRequest post = HttpUtil.createPost(webhookUrl);
|
HttpRequest post = HttpUtil.createPost(webhookUrl);
|
||||||
HttpRequest request = post.body(JsonUtil.toJsonString(map), ContentType.JSON.toString());
|
HttpRequest request = post.body(JsonUtil.toJsonString(map), ContentType.JSON.toString());
|
||||||
HttpResponse execute = request.execute();
|
HttpResponse execute = request.execute();
|
||||||
LogUtils.debug(log, JsonUtil.toJsonString(execute));
|
LogUtils.debug(log, JsonUtil.toJsonString(execute));
|
||||||
|
if (execute.isOk()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
LogUtils.error(log, "发送企业微信消息失败:{}", execute.body());
|
||||||
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("发送企业微信消息失败", e);
|
log.error("发送企业微信消息失败", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +69,7 @@ public class LogUtils {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Environment environment = SpringContext.CONTEXT.getBean(Environment.class);
|
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) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user