/**
* Alipay.com Inc.
* Copyright (c) 2004-2012 All Rights Reserved.
*/
package com.taobao.jnpiter.eros.common.util;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.taobao.eagleeye.EagleEye;
import com.taobao.jnpiter.eros.common.vo.chargefree.ChangeCheckReq;
import com.taobao.jnpiter.eros.common.vo.chargefree.ChangeCreateReq;
import com.taobao.jnpiter.eros.common.vo.chargefree.ChangeUpdateReq;
import com.taobao.jnpiter.eros.service.ChangeFreeService;
import com.taobao.jnpiter.eros.service.impl.ChangeFreeCheckServiceImpl;
import com.taobao.jnpiter.eros.service.impl.ChangeFreeCreateServiceImpl;
import com.taobao.jnpiter.eros.service.impl.ChangeFreeUpdateServiceImpl;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* tair拦截器
* @author zhenyuan.he
* @version $Id: ErosTairInterceptor.java, v 0.1 2019年4月1日 下午9:57:28 zhenyuan.he Exp $
*/
public class ErosTairInterceptor implements MethodInterceptor {
private static final Logger logger = LoggerFactory.getLogger(ErosTairInterceptor.class);
/**
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
*/
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
boolean success = false;
final long startTime = System.currentTimeMillis();
final String sourceOrderId = startTime + "";
final String empId = EagleEye.getUserData("empId") == null ? "39482"
: EagleEye.getUserData("empId");
ChangeCreateReq changeCreateReq = null;
// String fullClassName = invocation.getMethod().getDeclaringClass().getName();
//
// String sysName = StringUtils
// .substringBefore(StringUtils.substringAfter(fullClassName, "integration."), ".");
//
// String className = invocation.getMethod().getDeclaringClass().getSimpleName();
String methodName = invocation.getMethod().getName();
Object[] args = invocation.getArguments();
try {
//不被拦截
if (!SwitchCommon.EROS_TAIR_INTERCEPTOR_METHODS.contains(methodName)) {
return invocation.proceed();
}
ChangeFreeService changeFreeService = new ChangeFreeCheckServiceImpl();
ChangeCheckReq changeCheckReq = new ChangeCheckReq();
changeCheckReq.setSourceOrderId(sourceOrderId);
changeCheckReq.setHasSelfProcess("false");
changeCheckReq.setExecutorEmpId(empId);
changeCheckReq.setChangeTitle("changeTitle");
changeCheckReq.setEnv(EnvUtil.getChangeFreeEnv());
changeCheckReq.setChangeTypeKey("APP_CONFIG_PUSH");
changeCheckReq.setChangeStartTime(new Date().getTime() + "");
changeCheckReq.setChangeEndTime(new Date().getTime() + "");
Map<String, Object> maps = new HashMap<>();
maps.put("name", args);
changeCheckReq.setChangeObject(JSONObject.toJSONString(maps));
changeCheckReq.setChangeObjectType("CONFIG");
changeCheckReq.setEnv(EnvUtil.getChangeFreeEnv());
boolean pass = changeFreeService.excute(changeCheckReq);
LoggerUtil.info(logger, "changeFreeService.check,changeCreateReq=", changeCheckReq,
"pass=", pass, "methodName=", methodName);
if (!pass) {
return null;
}
Object result = invocation.proceed();
ChangeFreeService changeFreeCreateService = new ChangeFreeCreateServiceImpl();
changeCreateReq = new ChangeCreateReq(changeCheckReq, 1, 1);
success = changeFreeCreateService.excute(changeCreateReq);
LoggerUtil.info(logger, "changeFreeService.create,changeCreateReq=", changeCreateReq,
"success=", success);
return result;
} catch (Throwable t) {
LoggerUtil.error(logger, t, "ErosTairInterceptor.invoke error");
throw new RuntimeException(t);
} finally {
if (success && changeCreateReq != null) {
ChangeFreeService changeFreeService = new ChangeFreeUpdateServiceImpl();
ChangeUpdateReq changeBaseRequest = new ChangeUpdateReq(changeCreateReq);
boolean suc = changeFreeService.excute(changeBaseRequest);
LoggerUtil.info(logger, "changeFreeService.update end,succes=", suc,
"changeBaseRequest=", changeBaseRequest);
}
}
}
}
<!-- 拦截器 -->
<bean id="ibatisMapperInterceptor"
class="com.alibaba.surge.interceptors.IbatisMapperInterceptor"/>
<aop:config>
<!--切入点-->
<aop:pointcut id="ibatisPoint"
expression="execution( * com.alibaba.surge.mapper..*.*(..)) "/>
<!--在该切入点使用自定义拦截器-->
<aop:advisor pointcut-ref="ibatisPoint" advice-ref="ibatisMapperInterceptor"/>
</aop:config>
MethodInterceptor方法拦截
最新推荐文章于 2024-06-28 09:40:34 发布