wuxw
2022-05-12 c40e37c25eb1e173ce95e4d2244138b89b3cac69
java110-core/src/main/java/com/java110/core/aop/Java110TransactionalAop.java
@@ -4,6 +4,7 @@
import com.java110.core.log.LoggerFactory;
import com.java110.dto.order.OrderDto;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.util.StringUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
@@ -42,7 +43,37 @@
     */
    @Before("dataProcess()")
    public void deBefore(JoinPoint joinPoint) throws Throwable {
    }
    @AfterReturning(returning = "ret", pointcut = "dataProcess()")
    public void doAfterReturning(Object ret) throws Throwable {
        // 处理完请求,返回内容
        logger.debug("方法调用前执行doAfterReturning()");
    }
    //后置异常通知
    @AfterThrowing("dataProcess()")
    public void throwException(JoinPoint jp) {
        logger.debug("方法调用异常执行throwException()");
    }
    //后置最终通知,final增强,不管是抛出异常或者正常退出都会执行
    @After("dataProcess()")
    public void after(JoinPoint jp) throws IOException {
        // 接收到请求,记录请求内容
        logger.debug("方法调用后执行after()");
    }
    //环绕通知,环绕增强,相当于MethodInterceptor
    @Around("dataProcess()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object o = null;
        // 接收到请求,记录请求内容
        String curOId = Java110TransactionalFactory.getOId();
        if (StringUtil.isEmpty(curOId)) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        Enumeration<String> headerNames = request.getHeaderNames();
@@ -74,31 +105,6 @@
        Java110TransactionalFactory.getOrCreateOId(orderDto);
    }
    @AfterReturning(returning = "ret", pointcut = "dataProcess()")
    public void doAfterReturning(Object ret) throws Throwable {
        // 处理完请求,返回内容
        logger.debug("方法调用前执行doAfterReturning()");
    }
    //后置异常通知
    @AfterThrowing("dataProcess()")
    public void throwException(JoinPoint jp) {
        logger.debug("方法调用异常执行throwException()");
    }
    //后置最终通知,final增强,不管是抛出异常或者正常退出都会执行
    @After("dataProcess()")
    public void after(JoinPoint jp) throws IOException {
        // 接收到请求,记录请求内容
        logger.debug("方法调用后执行after()");
    }
    //环绕通知,环绕增强,相当于MethodInterceptor
    @Around("dataProcess()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object o = null;
        try {
            o = pjp.proceed();
            //观察者不做处理
@@ -106,7 +112,9 @@
                return o;
            }
            //完成事务
            if (StringUtil.isEmpty(curOId)) {
            Java110TransactionalFactory.finishOId();
            }
            return o;
        } catch (Throwable e) {
            logger.error("执行方法异常", e);