package com.chaozhanggui.admin.system.service;

import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.dao.system.dao.TbPlussIdCardMapper;
import com.chaozhanggui.dao.system.dao.TbPlussMerchantBaseInfoMapper;
import com.chaozhanggui.dao.system.dao.TbPlussMerchantChannelStatusMapper;
import com.chaozhanggui.dao.system.entity.TbPlussIdCard;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantBaseInfo;

import javax.annotation.Resource;

/**
 * 进件通用方法放到这里
 * @author lyf
 */
public abstract class BaseMerchantAuditService {
    @Resource
    protected TbPlussMerchantChannelStatusMapper merchantChannelStatusMapper;
    @Resource
    protected TbPlussMerchantBaseInfoMapper merchantBaseInfoMapper;
    @Resource
    protected TbPlussIdCardMapper idCardMapper;
    @Resource
    protected AccountService accountService;
    /**
     * 进件检测
     * @param userId
     * @param isFailCheck
     */
    public void merchantAuditCheck(String userId, boolean isFailCheck) {

        TbPlussMerchantBaseInfo merchantBaseInfo = merchantBaseInfoMapper.selectByUserId(userId);
        MsgException.checkNull(merchantBaseInfo, "请完善经营信息");

        String merchantType = merchantBaseInfo.getMerchanttype();
        String principalPerson = merchantBaseInfo.getPrincipalperson();

        TbPlussIdCard legalIdCard = idCardMapper.getLegalIdCard(userId);
        MsgException.checkNull(legalIdCard, "请完善法人信息");

        if (!"1".equals(merchantType)) {
            MsgException.checkBlank(principalPerson, "请完善营业执照信息");
        }

        accountService.checkCert(legalIdCard.getCertno(), "同一证件只能注册三个小微商户, 如有增加需求请联系客服");
    }
}
