| | |
| | | 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.*; |
| | |
| | | */ |
| | | @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(); |
| | |
| | | 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(); |
| | | //观察者不做处理 |
| | |
| | | return o; |
| | | } |
| | | //完成事务 |
| | | if (StringUtil.isEmpty(curOId)) { |
| | | Java110TransactionalFactory.finishOId(); |
| | | } |
| | | return o; |
| | | } catch (Throwable e) { |
| | | logger.error("执行方法异常", e); |