BuildSceneDTServiceImpl.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.fdkankan.dingtalk.DingTalkSendUtils;
  4. import com.fdkankan.scene.service.IBuildSceneDTService;
  5. import com.taobao.api.ApiException;
  6. import java.io.UnsupportedEncodingException;
  7. import java.security.InvalidKeyException;
  8. import java.security.NoSuchAlgorithmException;
  9. import java.util.concurrent.CompletableFuture;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Service;
  14. /**
  15. * <p>
  16. * TODO
  17. * </p>
  18. *
  19. * @author dengsixing
  20. * @since 2022/4/20
  21. **/
  22. @Slf4j
  23. @Service
  24. public class BuildSceneDTServiceImpl implements IBuildSceneDTService {
  25. public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
  26. "**服务器名称**: %s\n\n" +
  27. "**失败原因**: %s\n\n" +
  28. "**num**: %s\n\n" +
  29. "**server-path**: %s\n\n";
  30. // "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
  31. public static final String contentExt = "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
  32. @Autowired
  33. private DingTalkSendUtils dingTalkSendUtils;
  34. @Value("${spring.profiles.active}")
  35. private String environment;
  36. @Override
  37. public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
  38. CompletableFuture.runAsync(() -> {
  39. try {
  40. String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN + contentExt;
  41. String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
  42. log.info("发送钉钉消息,content:{}", content);
  43. dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
  44. } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
  45. log.error("发送钉钉消息失败", apiException);
  46. }
  47. });
  48. }
  49. }