package com.fdkankan.contro.service.impl; import cn.hutool.core.util.StrUtil; import com.fdkankan.contro.service.IBuildSceneDTService; import com.fdkankan.dingtalk.DingTalkSendUtils; import com.fdkankan.fyun.config.FYunFileConfig; import com.taobao.api.ApiException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.stereotype.Service; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.CompletableFuture; /** *
* TODO *
* * @author dengsixing * @since 2022/4/20 **/ @Slf4j @Service @RefreshScope public class BuildSceneDTServiceImpl implements IBuildSceneDTService { public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" + "**服务器名称**: %s\n\n" + "**失败原因**: %s\n\n" + "**num**: %s\n\n" + "**server-path**: %s\n\n"; public static final String contentExt = "**algorithm-log**: [%sbuild_log/%s/console.log](%sbuild_log/%s/console.log)"; @Autowired private DingTalkSendUtils dingTalkSendUtils; @Autowired private FYunFileConfig fYunFileConfig; @Value("${main.url}") private String mainUrl; @Override public void handModelFail(String reason, String serverPath, String num, String hostName) { CompletableFuture.runAsync(() -> { try { log.info("开始发送钉钉消息"); String logPath = String.format(contentExt,mainUrl,num,fYunFileConfig.getHost(),num); log.info("发送钉钉消息,content:{}", logPath); String content = String.format(this.DINGTALK_MSG_PATTERN, this.mainUrl, hostName, reason, num, serverPath) + logPath; log.info("发送钉钉消息,content:{}", content); dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败"); } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) { log.error("发送钉钉消息失败", apiException); } }); } @Override public void handBaseFail(String reason, String serverPath, String num, String hostName) { CompletableFuture.runAsync(() -> { try { String content = String.format(this.DINGTALK_MSG_PATTERN, this.mainUrl, hostName, reason, num, serverPath); log.info("发送钉钉消息,content:{}", content); dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败"); } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) { log.error("发送钉钉消息失败", apiException); } }); } }