package com.cool.store.dao;

import com.cool.store.entity.HyPartnerUserInfoDO;
import com.cool.store.mapper.HyPartnerUserInfoMapper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2023/6/8 19:41
 * @Version 1.0
 */
@Repository
public class HyPartnerUserInfoDAO {


    @Resource
    HyPartnerUserInfoMapper hyPartnerUserInfoMapper;


    public int updateByPrimaryKeySelective(HyPartnerUserInfoDO hyPartnerUserInfoDO){
        return hyPartnerUserInfoMapper.updateByPrimaryKeySelective(hyPartnerUserInfoDO);
    }


    /**
     * 根据PartnerId查询用户
     * @param partnerId
     * @return
     */
    public HyPartnerUserInfoDO selectByPartnerId(String partnerId){
        if (StringUtils.isEmpty(partnerId)){
            return null;
        }
        return hyPartnerUserInfoMapper.selectByPartnerId(partnerId);
    }

    /**
     * 根据mobile查询用户
     * @param mobile
     * @return
     */
    public HyPartnerUserInfoDO selectByMobile(String mobile){
        if (StringUtils.isEmpty(mobile)){
            return null;
        }
        return hyPartnerUserInfoMapper.selectByMobile(mobile);
    }

    public HyPartnerUserInfoDO selectByOpenid(String openid){
        if (StringUtils.isEmpty(openid)){
            return null;
        }
        return hyPartnerUserInfoMapper.selectByOpenid(openid);
    }

    /**
     * 根据PartnerIds批量查询用户
     * @param partnerIds
     * @return
     */
    public List<HyPartnerUserInfoDO> selectByPartnerIds(List<String> partnerIds){
        if (CollectionUtils.isEmpty(partnerIds)){
            return Lists.newArrayList();
        }
        return hyPartnerUserInfoMapper.selectByPartnerIds(partnerIds);
    }

    public  int insertSelective( HyPartnerUserInfoDO record){
        return hyPartnerUserInfoMapper.insertSelective(record);
    }

    public int updateByPartnerId(HyPartnerUserInfoDO record){
        if(StringUtils.isBlank(record.getPartnerId())){
            return 0;
        }
        return hyPartnerUserInfoMapper.updateByPartnerId(record);
    }


    public String selectLastCrmCreateTime() {
        return hyPartnerUserInfoMapper.selectLastCrmCreateTime();
    }

}
