package com.vivo.finance.vivopay.core.aop;
/**
- 该切面主要是打印日志,需要注意一下几点
- 1.打印的方法为com.vivo.finance.member.core.facade 目录下添加@com.vivo.finance.member.core.common.NeedLogInAndOut 的
- 方法才能进入打印
- 2.提供过滤加密打印,需要在加密的字段添加上@SecurityParam,这样会加密打印
- @Author : JimmyZ on 2018/8/21 23:33
**/
import com.vivo.finance.common.exception.FinanceBizException;
import com.vivo.finance.common.exception.FinanceRuntimeException;
import com.vivo.finance.common.utils.JsonUtils;
import com.vivo.finance.vivopay.core.exception.ExceptionConstants;
import com.vivo.finance.vivopay.core.exception.NfcCardsBizException;
import com.vivo.finance.vivopay.core.exception.VivoPayInterfaceBizException;
import com.vivo.finance.vivopay.core.exception.VivoPayInterfaceException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component //加入到IoC容器
@Aspect //指定当前类为切面类
public class LogAop {
private Logger logger = LoggerFactory.getLogger(getClass());
@Around("execution(* com.vivo.finance.vivopay.core.biz.*.*(..))")
public Object pointCut(ProceedingJoinPoint pjp) {
Object retVal = null;
String methodName = pjp.getSignature().getName();
String className = pjp.getTarget().getClass().getName();
Object[] args = pjp.getArgs();
try {
// String argsSerialize = JsonUtils.serialize(args == null ? “” : args);
// logger.info("{}#{} req params is {}", className, methodName, argsSerialize);
retVal = pjp.proceed(args);
// String retSerialize = JsonUtils.serialize(retVal == null ? “” : retVal);
// logger.info("{}#{} rsp result is 1 {}", className, methodName, retSerialize);
} catch (VivoPayInterfaceBizException e) {
logger.warn("{}#{} interface biz error, code is {}, msg is {}", className, methodName, e.getDefineCode(), e.getMessage());
throw VivoPayInterfaceException.newException(e,e.getMessage());
}catch (FinanceBizException e) {
logger.error("{}#{} biz error, code is {}, msg is {}", className, methodName, e.getDefineCode(), e.getMessage(), e);
if(VivoPayInterfaceException.class.isInstance(e)){
throw VivoPayInterfaceException.newException((VivoPayInterfaceException)e,e.getMessage());
}
throw FinanceBizException.newException(e);
} catch (FinanceRuntimeException e) {
logger.error("{}#{} runtime error, msg is {}", className, methodName,e.getMessage(), e);
throw e;
} catch (Throwable e) {
logger.error("{}#{} error, msg is {}", className, methodName,e.getMessage(), e);
throw NfcCardsBizException.newException(ExceptionConstants.SERVER_ERROR, e.getMessage());
}
return retVal;
}
}