package com.chaozhanggui.admin.system.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.dao.system.dao.TbPlussBankCodeSxfMapper;
import com.chaozhanggui.dao.system.entity.TbPlussBankCard;
import com.chaozhanggui.dao.system.entity.TbPlussBankCodeSxf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class BankCardService {
    @Resource
    private TbPlussBankCodeSxfMapper bankCodeSxfMapper;

    /**
     * 校验银行卡信息是否合法
     * @param bankCard
     */
    public void checkBankInfo(TbPlussBankCard bankCard) {
        TbPlussBankCodeSxf bankCodeSxf = new TbPlussBankCodeSxf();
        bankCodeSxf.setCnapsCode(bankCard.getContactline());
        bankCodeSxf = bankCodeSxfMapper.selectOne(new QueryWrapper<>(bankCodeSxf));

        String bankName = bankCard.getBankname().replace("银行", "");

        if ("浦发".equals(bankName)) {
            bankName = "浦东发展";
        }

        if("长安".equals(bankName)){
            bankName="城市商业银行";
        }

        if (!bankCodeSxf.getBankName().contains(bankName) && !"其他".equals(bankName)) {
            MsgException.throwException("开户行与支行信息不匹配，请检查银行卡信息");
        }
    }
}
