package com.czg.handler;

import cn.dev33.satoken.annotation.handler.SaAnnotationHandlerInterface;
import cn.hutool.core.util.StrUtil;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.sa.StpKit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 员工权限校验
 * @author Administrator
 */
@Component
@Slf4j
public class SaStaffCheckPermissionHandler implements SaAnnotationHandlerInterface<SaStaffCheckPermission> {

    @Override
    public Class<SaStaffCheckPermission> getHandlerAnnotationClass() {
        return SaStaffCheckPermission.class;
    }

    @Override
    public void checkMethod(SaStaffCheckPermission at, Method method) {
        if (at != null && StrUtil.isNotBlank(at.value()) && StpKit.USER.isStaff()) {
            StpKit.USER.checkPermission(at.value());
        }
    }
}
