package cn.iocoder.yudao.module.visit.dal.mysql.customerinfo;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.visit.dal.dataobject.customerinfo.CustomerInfoDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.visit.controller.admin.customerinfo.vo.*;

/**
 * 客户信息 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface CustomerInfoMapper extends BaseMapperX<CustomerInfoDO> {

    default PageResult<CustomerInfoDO> selectPage(CustomerInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CustomerInfoDO>()
                .likeIfPresent(CustomerInfoDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(CustomerInfoDO::getContact, reqVO.getContact())
                .likeIfPresent(CustomerInfoDO::getCompanyName, reqVO.getCompanyName())
                .eqIfPresent(CustomerInfoDO::getCustomerType, reqVO.getCustomerType())
                .eqIfPresent(CustomerInfoDO::getCityCode, reqVO.getCityCode())
                .betweenIfPresent(CustomerInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CustomerInfoDO::getId));
    }
    default PageResult<CustomerInfoDO> selectHomePage(CustomerInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CustomerInfoDO>()
                .eqIfPresent(CustomerInfoDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(CustomerInfoDO::getContact, reqVO.getContact())
                .eqIfPresent(CustomerInfoDO::getCompanyName, reqVO.getCompanyName())
                .eqIfPresent(CustomerInfoDO::getCustomerType, reqVO.getCustomerType())
                .eqIfPresent(CustomerInfoDO::getCityCode, reqVO.getCityCode())
                .betweenIfPresent(CustomerInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CustomerInfoDO::getId));
    }

    //根据公司名称查询客户信息（验证是否唯一使用）
    default CustomerInfoDO selectByCompanyName(String companyName){
        return selectOne(CustomerInfoDO::getCompanyName, companyName);
    }

    // 根据公司名称或手机号查询（根据任一条件带出符合条件的列表）
    default List<CustomerInfoDO> selectListByCompanyName(String companyName) {
        return selectList(new LambdaQueryWrapperX<CustomerInfoDO>()
                .likeIfPresent(CustomerInfoDO::getCompanyName, companyName));
    }
    default List<CustomerInfoDO> selectListByContact(String contact) {
        return selectList(new LambdaQueryWrapperX<CustomerInfoDO>()
                .likeIfPresent(CustomerInfoDO::getContact, contact));
    }
}