package com.ema.common.aspect.active;

import cn.hutool.core.util.ArrayUtil;
import com.ema.common.exceptions.MyAssert;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 环境锁切面
 */
@Aspect
@Component
public class ActiveLockAspect {

    @Value("${spring.profiles.active:}")
    private String profilesActive;


    @Around("@annotation(activeLock)")
    public Object around(ProceedingJoinPoint joinPoint,ActiveLock activeLock) throws Throwable {
        String[] actives = activeLock.actives();
        MyAssert.isTrue(ArrayUtil.contains(actives, profilesActive), profilesActive + "环境不支持该方法");
        return joinPoint.proceed();
    }

}
