| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -8,11 +8,17 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					package com.epmet.commons.tools.aspect; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.alibaba.fastjson.JSON; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.dingtalk.api.DefaultDingTalkClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.dingtalk.api.DingTalkClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.dingtalk.api.request.OapiRobotSendRequest; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.dingtalk.api.response.OapiRobotSendResponse; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.dto.form.DingTalkTextMsg; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.enums.EnvEnum; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.HttpClientManager; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.Result; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.SpringContextUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.taobao.api.ApiException; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.apache.logging.log4j.LogManager; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.apache.logging.log4j.Logger; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.beans.factory.annotation.Value; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -35,32 +41,69 @@ public class CustomerApplicationRunner implements ApplicationRunner { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private static Logger logger = LogManager.getLogger(CustomerApplicationRunner.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Value("${spring.application.name}") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private String appName; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Value("${server.version}") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private String version; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Override | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void run(ApplicationArguments args) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //发送启动成功消息
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        EnvEnum currentEnv = EnvEnum.getCurrentEnv(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        logger.info(currentEnv); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (!EnvEnum.DEV.getCode().equals(currentEnv.getCode()) && !EnvEnum.LOCAL.getCode().equals(currentEnv.getCode())) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String serverIp = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //sendDingTextMsg();
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            sendDingMarkDownMsg(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private void sendDingTextMsg() { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //发送启动成功消息
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String serverIp = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //开发小组 群机器人地址
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String url = "https://oapi.dingtalk.com/robot/send?access_token=ffd7c972b0525e249283df1a16b65a8b9d0012601f3a458dfc588c2eac497bb5"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        StringBuilder stringBuilder = new StringBuilder(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        stringBuilder.append(EnvEnum.getCurrentEnv().getName()) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .append("【") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .append(appName) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .append("】") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .append("ip地址: ") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .append(serverIp) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .append("部署完毕!"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        DingTalkTextMsg msg = new DingTalkTextMsg(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        msg.setWebHook(url); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        msg.setAtAll(true); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        msg.setContent(stringBuilder.toString()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Result<String> stringResult = HttpClientManager.getInstance().sendPostByJSON(url, msg.getMsgContent()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        logger.info(stringResult); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private String getServerIp() { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private void sendDingMarkDownMsg() { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=ffd7c972b0525e249283df1a16b65a8b9d0012601f3a458dfc588c2eac497bb5"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        OapiRobotSendRequest request = new OapiRobotSendRequest(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        request.setMsgtype("markdown"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        markdown.setTitle("部署成功通知"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //开发小组 群机器人地址
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String url = "https://oapi.dingtalk.com/robot/send?access_token=ffd7c972b0525e249283df1a16b65a8b9d0012601f3a458dfc588c2eac497bb5"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            StringBuilder stringBuilder = new StringBuilder(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            stringBuilder.append(EnvEnum.getCurrentEnv().getName()) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    .append("【") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    .append(appName) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    .append("】") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    .append("ip地址: ") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    .append(serverIp) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    .append("部署完毕!"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            DingTalkTextMsg msg = new DingTalkTextMsg(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            msg.setWebHook(url); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            msg.setAtAll(true); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            msg.setContent(stringBuilder.toString()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            Result<String> stringResult = HttpClientManager.getInstance().sendPostByJSON(url, msg.getMsgContent()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.info(stringResult); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        markdown.setText("部署成功通知 \n" + | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "> 服务:" + appName + "\n\n" + | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "> 版本:" + version + "\n\n" + | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "> 环境:" + EnvEnum.getCurrentEnv().getName() + "\n\n" + | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "> IP: " + getServerIp() + "\n\n" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        request.setMarkdown(markdown); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        at.setIsAtAll(true); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        request.setAt(at); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            OapiRobotSendResponse execute = client.execute(request); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.info("=====通知结果===>" + JSON.toJSONString(execute)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } catch (ApiException e) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.error("sendDingMarkDownMsg exception", e); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |