|
|
@ -6,10 +6,13 @@ import com.github.tingyugetc520.ali.dingtalk.bean.message.DtCorpConversationMsgS |
|
|
import com.github.tingyugetc520.ali.dingtalk.bean.message.DtMessage; |
|
|
import com.github.tingyugetc520.ali.dingtalk.bean.message.DtMessage; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.google.common.collect.Lists; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.redisson.api.RedissonClient; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Component |
|
|
@Component |
|
|
@ -17,10 +20,32 @@ public class NotifyUtil { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private DtService dtService; |
|
|
private DtService dtService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RedissonClient redissonClient; |
|
|
|
|
|
|
|
|
|
|
|
// 钉钉通知相关配置
|
|
|
|
|
|
private static final List<String> WARN_USER_LIST = Lists.newArrayList( |
|
|
|
|
|
"283712335120874575", |
|
|
|
|
|
"01231011386731976125", |
|
|
|
|
|
"5902043009320002110" |
|
|
|
|
|
); |
|
|
|
|
|
// 防重复缓存key前缀
|
|
|
|
|
|
private static final String WARN_LOCK_KEY_PREFIX = "question:gen:warn:lock:"; |
|
|
|
|
|
// 重复发送间隔:1小时(3600秒)
|
|
|
|
|
|
private static final long WARN_LOCK_EXPIRE_SECONDS = 3600L; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void notify(Long taskId,Long clusterId) { |
|
|
public void notify(Long taskId,Long clusterId) { |
|
|
// "283712335120874575", "01231011386731976125",
|
|
|
|
|
|
ArrayList<String> userIDList = Lists.newArrayList( "283712335120874575", "01231011386731976125","590204300932000212"); |
|
|
// 构建Redis缓存key(按taskId唯一)
|
|
|
|
|
|
String cacheKey = WARN_LOCK_KEY_PREFIX + taskId; |
|
|
|
|
|
|
|
|
|
|
|
// 核心逻辑:检查Redis缓存,存在则直接返回(1小时内已发送过)
|
|
|
|
|
|
boolean isCached = redissonClient.getBucket(cacheKey).isExists(); |
|
|
|
|
|
if (isCached) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
String markdown = String.format("### 【告警】算法生题API调用失败通知 \n\n") + |
|
|
String markdown = String.format("### 【告警】算法生题API调用失败通知 \n\n") + |
|
|
@ -32,7 +57,7 @@ public class NotifyUtil { |
|
|
String.format("- 算法服务是否正常运行\n"); |
|
|
String.format("- 算法服务是否正常运行\n"); |
|
|
DtCorpConversationMessage corpConversationMessage = DtCorpConversationMessage.builder() |
|
|
DtCorpConversationMessage corpConversationMessage = DtCorpConversationMessage.builder() |
|
|
.agentId(dtService.getDtConfigStorage().getAgentId()) |
|
|
.agentId(dtService.getDtConfigStorage().getAgentId()) |
|
|
.userIds(Lists.newArrayList(userIDList)) |
|
|
.userIds(WARN_USER_LIST) |
|
|
.msg(DtMessage.MARKDOWN() |
|
|
.msg(DtMessage.MARKDOWN() |
|
|
.content("算法生题API调用失败通知") |
|
|
.content("算法生题API调用失败通知") |
|
|
.text(markdown) |
|
|
.text(markdown) |
|
|
@ -41,6 +66,7 @@ public class NotifyUtil { |
|
|
DtCorpConversationMsgSendResult result = dtService.getCorpConversationMsgService().send(corpConversationMessage); |
|
|
DtCorpConversationMsgSendResult result = dtService.getCorpConversationMsgService().send(corpConversationMessage); |
|
|
if (result.getErrCode() == 0) { |
|
|
if (result.getErrCode() == 0) { |
|
|
log.info(">>> [算法生题API调用失败通知] 成功发送通知 ,考试任务ID:{} ,知识点簇ID:{}", taskId, clusterId); |
|
|
log.info(">>> [算法生题API调用失败通知] 成功发送通知 ,考试任务ID:{} ,知识点簇ID:{}", taskId, clusterId); |
|
|
|
|
|
redissonClient.getBucket(cacheKey).set("SEND_SUCCESS", WARN_LOCK_EXPIRE_SECONDS, TimeUnit.SECONDS); |
|
|
} else { |
|
|
} else { |
|
|
log.error(">>> [算法生题API调用失败通知] 发送失败.考试任务ID:{} ,知识点簇ID:{}, 错误码: {}, 错误信息: {}", taskId, clusterId, |
|
|
log.error(">>> [算法生题API调用失败通知] 发送失败.考试任务ID:{} ,知识点簇ID:{}, 错误码: {}, 错误信息: {}", taskId, clusterId, |
|
|
result.getErrCode(), result.getErrMsg()); |
|
|
result.getErrCode(), result.getErrMsg()); |
|
|
|