package com.njcn.rdms.module.project.framework.security.service;

import com.njcn.rdms.framework.security.core.util.SecurityFrameworkUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 项目对象业务授权服务。
 */
@Service
public class ProjectObjectAuthorizationService {

    @Resource
    private ProjectObjectPermissionService projectObjectPermissionService;

    /**
     * 当前登录人是业务负责人时直接放行，否则回落到项目对象角色权限校验。
     */
    public void checkOwnerOrProjectPermission(Long projectId, Long ownerUserId, String permission) {
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        if (Objects.equals(loginUserId, ownerUserId)) {
            return;
        }
        projectObjectPermissionService.checkPermission(projectId, permission, false);
    }

}
