package com.ruoyi.ss.risk.service.impl;

import com.ruoyi.ss.risk.domain.RiskVO;
import com.ruoyi.ss.risk.service.RiskService;
import com.ruoyi.ss.risk.service.RiskValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

import static com.ruoyi.common.utils.SecurityUtils.getUserId;

/**
 * @author wjh
 * 2024/11/23
 */
@Service
public class RiskValidatorImpl implements RiskValidator {

    @Autowired
    private RiskService riskService;

    @Override
    public boolean isUser(RiskVO risk, Long userId) {
        return risk != null && userId != null && Objects.equals(risk.getUserId(), getUserId());
    }

    @Override
    public boolean isUser(Long riskId, Long userId) {
        if (riskId == null || userId == null) {
            return false;
        }
        RiskVO risk = riskService.selectRiskByRiskId(riskId);
        return isUser(risk, userId);
    }

    @Override
    public boolean isExist(Long riskId) {
        if (riskId == null) {
            return false;
        }
        return riskService.selectRiskByRiskId(riskId) != null;
    }
}
