package cn.pluss.platform.cashAccount.impl;

import cn.pluss.platform.IdCardService;
import cn.pluss.platform.cashAccount.CashAccountService;
import cn.pluss.platform.entity.CashAccount;
import cn.pluss.platform.entity.IdCard;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.CashAccountMapper;
import cn.pluss.platform.userApp.UserAppService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bzg
 * @since 2021-07-23
 */
@Service
public class CashAccountServiceImpl extends ServiceImpl<CashAccountMapper, CashAccount> implements CashAccountService {

    @Autowired @Lazy
    private UserAppService uaService;

    @Autowired @Lazy
    private IdCardService idCardService;

    @Override
    public boolean apiSave(CashAccount entity) {
        MsgException.checkNull(entity.getAccountName(), "缺少支付宝账户名");
        MsgException.checkNull(entity.getAccountNo(), "缺少支付号账号");

        UserApp userApp = uaService.queryUserAppByToken();

        IdCard certIdCard = idCardService.getCertIdCard(userApp.getUserId() + "");

        MsgException.checkNull(certIdCard, "请先进行实名认证");

        MsgException.checkUnequals(certIdCard.getCertName(), entity.getAccountName(), "支付宝账户名需与实名信息保持一致");

        return save(entity);
    }
}
