Optimize notification and alarm text reading (#445)

* Spotless add skip condition

* Optimize notification and alarm text reading

* delete meaningless blank lines
pull/450/head
小马哥 2 years ago committed by GitHub
parent ed46e0767e
commit 2a9f94cd35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.toolkit;
import lombok.SneakyThrows;
import org.springframework.core.io.ClassPathResource;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/**
* File util;
*/
public class FileUtil {
@SneakyThrows
public static String readUtf8String(String path) {
String resultReadStr;
ClassPathResource classPathResource = new ClassPathResource(path);
try (
InputStream inputStream = classPathResource.getInputStream();
BufferedInputStream bis = new BufferedInputStream(inputStream);
ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
int result = bis.read();
while (result != -1) {
buf.write((byte) result);
result = bis.read();
}
resultReadStr = buf.toString("UTF-8");
}
return resultReadStr;
}
}

@ -43,7 +43,6 @@ public final class Singleton {
return result == null ? null : (T) result;
}
/**
* Get a singleton object by key.
*

@ -25,7 +25,7 @@ import cn.hippo4j.message.platform.base.AbstractRobotSendMessageHandler;
import cn.hippo4j.message.platform.base.RobotMessageActualContent;
import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO;
import cn.hippo4j.message.platform.constant.DingAlarmConstants;
import cn.hutool.core.io.FileUtil;
import cn.hippo4j.common.toolkit.FileUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;

@ -26,7 +26,7 @@ import cn.hippo4j.message.request.AlarmNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hippo4j.common.toolkit.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import lombok.AllArgsConstructor;

@ -17,13 +17,13 @@
package cn.hippo4j.message.platform;
import cn.hippo4j.common.toolkit.FileUtil;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.message.enums.NotifyPlatformEnum;
import cn.hippo4j.message.platform.base.AbstractRobotSendMessageHandler;
import cn.hippo4j.message.platform.base.RobotMessageActualContent;
import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import lombok.Data;
import lombok.experimental.Accessors;
@ -44,15 +44,15 @@ public class WeChatSendMessageHandler extends AbstractRobotSendMessageHandler {
@Override
protected RobotMessageActualContent buildMessageActualContent() {
String weChatAlarmTxtKet = "message/robot/dynamic-thread-pool/wechat-alarm.txt";
String weChatConfigTxtKet = "message/robot/dynamic-thread-pool/wechat-alarm.txt";
String weChatAlarmTxtKey = "message/robot/dynamic-thread-pool/wechat-alarm.txt";
String weChatConfigTxtKey = "message/robot/dynamic-thread-pool/wechat-alarm.txt";
RobotMessageActualContent robotMessageActualContent = RobotMessageActualContent.builder()
.receiveSeparator("><@")
.changeSeparator(" ➲ ")
.replaceTxt(WE_CHAT_ALARM_TIMOUT_REPLACE_TXT)
.traceReplaceTxt(WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT)
.alarmMessageContent(Singleton.get(weChatAlarmTxtKet, () -> FileUtil.readUtf8String(weChatAlarmTxtKet)))
.configMessageContent(Singleton.get(weChatConfigTxtKet, () -> FileUtil.readUtf8String(weChatConfigTxtKet)))
.alarmMessageContent(Singleton.get(weChatAlarmTxtKey, () -> FileUtil.readUtf8String(weChatAlarmTxtKey)))
.configMessageContent(Singleton.get(weChatConfigTxtKey, () -> FileUtil.readUtf8String(weChatConfigTxtKey)))
.build();
return robotMessageActualContent;
}

Loading…
Cancel
Save