package cn.cslg.report.common.core.annotation;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class PermissionAspect {

//    @Autowired
//    private ProjectUserService projectUserService;
//    @Autowired
//    private ProjectService projectService;
//    @Autowired
//    private CacheUtils cacheUtils;
//
//    @Pointcut("execution(public * cn.cslg.pas.controller.*.*(..))")
//    public void privilege() {
//    }
//
//    @ResponseBody
//    @Around("privilege()")
//    public Object isAccessMethod(ProceedingJoinPoint joinPoint) throws Throwable {
//        //获取访问目标方法
//        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
//        Method targetMethod = methodSignature.getMethod();
//        final int[] methodAccess = AnnotationParse.permissionParse(targetMethod);
//        if (methodAccess != null && methodAccess.length != 0) {
//            HttpServletRequest request = RequestHolder.getRequest();
//            if (request != null) {
//                String projectId = request.getHeader("x-project-id");
//                Integer userId = StpUtil.getLoginIdAsInt();
//                if (StringUtils.isNotEmpty(projectId)) {
//                    Project project = projectService.getById(projectId);
//                    User user = cacheUtils.getLoginUser(userId);
//                    ProjectUser projectUser = projectUserService.getProjectUserByProjectIdAndUserId(Integer.parseInt(projectId), userId);
//                    if (projectUser != null && project != null && user != null) {
//                        if (project.getCreateBy().equals(userId)) {
//                            return joinPoint.proceed();
//                        }
//                        if (Arrays.stream(methodAccess).noneMatch(item -> item == projectUser.getType())) {
//                            throw new PermissionException("用户操作拦截");
//                        }
//                    }
//                }
//            }
//        }
//        return joinPoint.proceed();
//    }
}
