package cn.iocoder.yudao.module.supplier.dal.mysql.product;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.supplier.controller.admin.product.vo.ContactPageReqVO;
import cn.iocoder.yudao.module.supplier.dal.dataobject.product.ContactDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 供应商联系人 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ContactMapper extends BaseMapperX<ContactDO> {

    default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>()
                .eqIfPresent(ContactDO::getSupplierId, reqVO.getSupplierId())
                .likeIfPresent(ContactDO::getName, reqVO.getName())
                .eqIfPresent(ContactDO::getPosition, reqVO.getPosition())
                .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone())
                .eqIfPresent(ContactDO::getEmail, reqVO.getEmail())
                .eqIfPresent(ContactDO::getProductIds, reqVO.getProductIds())
                .eqIfPresent(ContactDO::getProductNames, reqVO.getProductNames())
                .eqIfPresent(ContactDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ContactDO::getSupplierName, reqVO.getSupplierName())
                .betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ContactDO::getId));
    }

    default List<ContactDO> selectListBySupplierId(Long supplierId) {
        return selectList(new LambdaQueryWrapperX<ContactDO>()
                .eq(ContactDO::getSupplierId, supplierId)
                .orderByDesc(ContactDO::getId));

    }

}
