package com.platform.modules.live.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * @author TONG
 * 2019/11/14 14:11
 **/
@Aspect
@Component
public class LiveTenantAspect extends BaseTenantAspect {

    public LiveTenantAspect(ApplicationContext applicationContext) {
        super(applicationContext);
    }

    @Around("@annotation(com.platform.modules.live.aspect.LiveTenant)")
    public Object doLiveSceneValid(ProceedingJoinPoint pjp) throws Throwable {
        return super.doTenantValid(pjp);
    }

    @Override
    public TenantAspectRegistry buildTenantAspectRegistry(Method method) {
        LiveTenant liveTenant = method.getAnnotation(LiveTenant.class);
        if (liveTenant == null) {
            return null;
        }
        return new TenantAspectRegistry(liveTenant.value(), liveTenant.tenantTableClazz(), liveTenant.method(), Serializable.class);
    }
}
