package com.ruoyi.web.core.aspectj;

import com.ruoyi.ss.user.domain.UserVO;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.ss.user.service.IUserService;
import com.ruoyi.web.core.annotation.DeviceAdminRequired;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户类型权限切面
 * @author qzz
 * 2024/3/8
 */
@Aspect
@Component
public class DeviceAdminRequiredAspect {

    @Autowired
    private IUserService userService;

    @Autowired
    private TokenService tokenService;

    // 判断当前用户是否有权限访问
    @Before("@annotation(required)")
    public void doBefore(JoinPoint point, DeviceAdminRequired required) {
        UserVO user = userService.selectUserById(SecurityUtils.getUserId());
        ServiceUtil.assertion(user == null, "您无权操作" );
    }

}
