package cn.pluss.platform.impl;

import cn.pluss.platform.entity.MerchantAuditRecord;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.MerchantAuditRecordMapper;
import cn.pluss.platform.MerchantAuditRecordService;
import cn.pluss.platform.userApp.UserAppService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Djh
 * @since 2020-11-27
 */
@Service
public class MerchantAuditRecordServiceImpl extends ServiceImpl<MerchantAuditRecordMapper, MerchantAuditRecord> implements MerchantAuditRecordService {

    @Setter(onMethod_ = {@Lazy, @Autowired})
    private UserAppService userAppService;

    @Override
    public Integer getFailCountByUserId(String userId) {
        UserApp userApp = new UserApp().setUserId(Long.parseLong(userId));
        userApp = userAppService.getOne(new QueryWrapper<>(userApp));
        if (userApp == null) {
            throw new MsgException("无效的userId");
        }

        return getFailCount(userApp.getMerchantCode());
    }
}
