This commit is contained in:
2025-07-09 18:19:13 +08:00
parent 3d072958d6
commit bb4432e643
35 changed files with 464 additions and 1100 deletions

View File

@@ -0,0 +1,3 @@
.idea/
.DS_Store
src/main/java/com/tashow/cloud/sdk/feishu/client/chat_history.txt

View File

@@ -5,22 +5,17 @@ import com.tashow.cloud.sdk.feishu.util.ChartImageGenerator;
import com.lark.oapi.service.im.v1.model.ext.MessageTemplate;
import com.lark.oapi.service.im.v1.model.ext.MessageTemplateData;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import com.tashow.cloud.sdk.feishu.config.LarkConfig;
import com.tashow.cloud.sdk.feishu.util.LarkClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 飞书告警客户端
* 用于处理系统告警消息的发送
*/
@Service
public class FeiShuAlertClient {
private final Logger log = LoggerFactory.getLogger(FeiShuAlertClient.class);
private final Client client;
private final LarkConfig larkConfig;
private final ChartImageGenerator chartImageGenerator;
@@ -56,42 +51,6 @@ public class FeiShuAlertClient {
return resp.getData().getChatId();
}
/**
* 发送带错误信息的埋点报警消息
*
* @param chatId 会话ID
* @param buriedPointData 埋点数据
* @param failCount 失败数量
* @param errorMessage 错误信息
* @return 发送的消息ID
* @throws Exception 异常信息
*/
public String sendBuriedPointAlertMessage(String chatId, List<ChartImageGenerator.MonitoringDataPoint> buriedPointData, int failCount, String errorMessage) throws Exception {
HashMap<String, Object> templateData = new HashMap<>();
String imageKey = uploadImage(buriedPointData, errorMessage);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentTime = sdf.format(new Date());
templateData.put("alert_title", "埋点数据异常告警");
templateData.put("image_key", imageKey);
templateData.put("current_time", currentTime);
templateData.put("fail_count", failCount);
return sendCardMessage(chatId, "AAqdpjayeOVp2", templateData);
}
/**
* 发送带错误信息的埋点报警消息(创建群)
*
* @param buriedPointData 埋点数据
* @param failCount 失败数量
* @param errorMessage 错误信息
* @return 创建的群ID和消息ID格式为 "chatId:messageId"
* @throws Exception 异常信息
*/
public String sendBuriedPointAlertMessage(List<ChartImageGenerator.MonitoringDataPoint> buriedPointData, int failCount, String errorMessage) throws Exception {
String chatId = createAlertChat();
String messageId = sendBuriedPointAlertMessage(chatId, buriedPointData, failCount, errorMessage);
return chatId + ":" + messageId;
}
/**
* 发送报警消息

View File

@@ -0,0 +1 @@
com.tashow.cloud.sdk.feishu.config.LarkConfig