package com.ruoyi.framework.interceptor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.AopUtils;

public class MybatisPlusMethodInterceptor extends DataChangeAspect implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        //只处理baseMappper相关方法
       // return invocation.proceed();
        if (!(invocation.getThis() instanceof BaseMapper)) {
            //返回继续执行
            return invocation.proceed();
        }
        Object target=invocation.getThis();
        Class<?> targetClass = target != null ? AopUtils.getTargetClass(invocation.getThis()) : null;
        if (targetClass == null) {
            return invocation.proceed();
        }
        return super.work(target, targetClass, invocation.getMethod(), invocation.getArguments(), invocation::proceed);
    }
}
