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

import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ss.realName.domain.RealNameQuery;
import com.ruoyi.ss.realName.service.RealNameService;
import com.ruoyi.ss.realName.service.RealNameValidator;
import com.ruoyi.ss.user.domain.SmUserQuery;
import com.ruoyi.ss.user.service.ISmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wjh
 * 2024/11/4
 */
@Service
public class RealNameValidatorImpl implements RealNameValidator {

    @Autowired
    private RealNameService realNameService;

    @Autowired
    private ISmUserService userService;

    /**
     * 判断身份证是否已经实名
     */
    @Override
    public void checkIdCard(Long userId, String idCard) {
        if (StringUtils.isBlank(idCard)) {
            return;
        }
        SmUserQuery query = new SmUserQuery();
        query.setIsReal(true);
        query.setEqRealIdCard(idCard);
        query.setExcludeUserId(userId);
        ServiceUtil.assertion(userService.selectCount(query) > 0, "当前身份证已被其他用户使用，无法重复实名");
    }
}
