BuildSceneDTServiceImpl.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.fdkankan.contro.service.IBuildSceneDTService;
  4. import com.fdkankan.dingtalk.DingTalkSendUtils;
  5. import com.fdkankan.fyun.config.FYunFileConfig;
  6. import com.taobao.api.ApiException;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.stereotype.Service;
  11. import java.io.UnsupportedEncodingException;
  12. import java.security.InvalidKeyException;
  13. import java.security.NoSuchAlgorithmException;
  14. import java.util.concurrent.CompletableFuture;
  15. /**
  16. * <p>
  17. * TODO
  18. * </p>
  19. *
  20. * @author dengsixing
  21. * @since 2022/4/20
  22. **/
  23. @Slf4j
  24. @Service
  25. public class BuildSceneDTServiceImpl implements IBuildSceneDTService {
  26. public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
  27. "**服务器名称**: %s\n\n" +
  28. "**失败原因**: %s\n\n" +
  29. "**num**: %s\n\n" +
  30. "**server-path**: %s\n\n";
  31. public static final String contentExt = "**algorithm-log**: [%sbuild_log/%s/console.log](%sbuild_log/%s/console.log)";
  32. @Autowired
  33. private DingTalkSendUtils dingTalkSendUtils;
  34. @Autowired
  35. private FYunFileConfig fYunFileConfig;
  36. @Value("${main.url}")
  37. private String mainUrl;
  38. @Override
  39. public void handModelFail(String reason, String serverPath, String num, String hostName) {
  40. String logPath = String.format(contentExt,fYunFileConfig.getHost(),num,fYunFileConfig.getHost(),num);
  41. this.handModelFail(reason, serverPath, num, hostName, logPath);
  42. }
  43. @Override
  44. public void handModelFail(String reason, String serverPath, String num, String hostName, String logPath) {
  45. try {
  46. log.info("发送钉钉消息,content:{}", logPath);
  47. String content = String.format(this.DINGTALK_MSG_PATTERN, this.mainUrl, hostName, reason, num, serverPath) + logPath;
  48. log.info("发送钉钉消息,content:{}", content);
  49. dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
  50. } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
  51. log.error("发送钉钉消息失败", apiException);
  52. }
  53. }
  54. @Override
  55. public void handBaseFail(String reason, String serverPath, String num, String hostName) {
  56. try {
  57. String content = String.format(this.DINGTALK_MSG_PATTERN, this.mainUrl, hostName, reason, num, serverPath);
  58. log.info("发送钉钉消息,content:{}", content);
  59. dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
  60. } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
  61. log.error("发送钉钉消息失败", apiException);
  62. }
  63. }
  64. }