BuildSceneDTServiceImpl.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.cloud.context.config.annotation.RefreshScope;
  11. import org.springframework.stereotype.Service;
  12. import java.io.UnsupportedEncodingException;
  13. import java.security.InvalidKeyException;
  14. import java.security.NoSuchAlgorithmException;
  15. import java.util.concurrent.CompletableFuture;
  16. /**
  17. * <p>
  18. * TODO
  19. * </p>
  20. *
  21. * @author dengsixing
  22. * @since 2022/4/20
  23. **/
  24. @Slf4j
  25. @Service
  26. @RefreshScope
  27. public class BuildSceneDTServiceImpl implements IBuildSceneDTService {
  28. public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
  29. "**服务器名称**: %s\n\n" +
  30. "**失败原因**: %s\n\n" +
  31. "**num**: %s\n\n" +
  32. "**server-path**: %s\n\n";
  33. public static final String contentExt = "**algorithm-log**: [%sbuild_log/%s/console.log](%sbuild_log/%s/console.log)";
  34. @Autowired
  35. private DingTalkSendUtils dingTalkSendUtils;
  36. @Autowired
  37. private FYunFileConfig fYunFileConfig;
  38. @Value("${main.url}")
  39. private String mainUrl;
  40. @Override
  41. public void handModelFail(String reason, String serverPath, String num, String hostName) {
  42. CompletableFuture.runAsync(() -> {
  43. try {
  44. log.info("开始发送钉钉消息");
  45. String logPath = String.format(contentExt,mainUrl,num,fYunFileConfig.getHost(),num);
  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. }
  55. @Override
  56. public void handBaseFail(String reason, String serverPath, String num, String hostName) {
  57. CompletableFuture.runAsync(() -> {
  58. try {
  59. String content = String.format(this.DINGTALK_MSG_PATTERN, this.mainUrl, hostName, reason, num, serverPath);
  60. log.info("发送钉钉消息,content:{}", content);
  61. dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
  62. } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
  63. log.error("发送钉钉消息失败", apiException);
  64. }
  65. });
  66. }
  67. }