package com.yc.ship.module.resource.dal.mysql.supplier;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.resource.controller.admin.supplier.vo.SupplierListReqVO;
import com.yc.ship.module.resource.controller.admin.supplier.vo.SupplierPageReqVO;
import com.yc.ship.module.resource.controller.admin.supplier.vo.SupplierRespVO;
import com.yc.ship.module.resource.dal.dataobject.supplier.ProductSupplierDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;


/**
 * 资源供应商 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ProductSupplierMapper extends BaseMapperX<ProductSupplierDO> {

    default PageResult<ProductSupplierDO> selectPage(SupplierPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProductSupplierDO>()
                .likeIfPresent(ProductSupplierDO::getName, reqVO.getName())
                .eqIfPresent(ProductSupplierDO::getType, reqVO.getType())
                .eqIfPresent(ProductSupplierDO::getUseStatus, reqVO.getUseStatus())
                .gtIfPresent(ProductSupplierDO::getCooperateStartTime, reqVO.getCooperateStartTime())
                .ltIfPresent(ProductSupplierDO::getCooperateEndTime, reqVO.getCooperateEndTime())
                .eqIfPresent(ProductSupplierDO::getContactMan, reqVO.getContactMan())
                .eqIfPresent(ProductSupplierDO::getContactPhone, reqVO.getContactPhone())
                .eqIfPresent(ProductSupplierDO::getContactAddress, reqVO.getContactAddress())
                .eqIfPresent(ProductSupplierDO::getBusinessArea, reqVO.getBusinessArea())
                .eqIfPresent(ProductSupplierDO::getContract, reqVO.getContract())
                .eqIfPresent(ProductSupplierDO::getShortName,reqVO.getShortName())
                .eqIfPresent(ProductSupplierDO::getIsSystemDirect, reqVO.getIsSystemDirect())
                .eqIfPresent(ProductSupplierDO::getDirectParam, reqVO.getDirectParam())
                .eqIfPresent(ProductSupplierDO::getDirectAccount, reqVO.getDirectAccount())
                .eqIfPresent(ProductSupplierDO::getDirectOrderUrl, reqVO.getDirectOrderUrl())
                .eqIfPresent(ProductSupplierDO::getDirectCheckUrl, reqVO.getDirectCheckUrl())
                .eqIfPresent(ProductSupplierDO::getDirectRefundUrl, reqVO.getDirectRefundUrl())
                .likeIfPresent(ProductSupplierDO::getUnitName, reqVO.getUnitName())
                .eqIfPresent(ProductSupplierDO::getUnitAddress, reqVO.getUnitAddress())
                .likeIfPresent(ProductSupplierDO::getBankName, reqVO.getBankName())
                .eqIfPresent(ProductSupplierDO::getBankAccount, reqVO.getBankAccount())
                .eqIfPresent(ProductSupplierDO::getTaxId, reqVO.getTaxId())
                .eqIfPresent(ProductSupplierDO::getTelephone, reqVO.getTelephone())
                .eqIfPresent(ProductSupplierDO::getInterbankNumber, reqVO.getInterbankNumber())
                .betweenIfPresent(ProductSupplierDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProductSupplierDO::getId));
    }

    IPage<SupplierRespVO> queryPage(IPage<SupplierRespVO> iPage, @Param("param")SupplierPageReqVO pageReqVO);
    List<ProductSupplierDO> getSimpleListByCategory(@Param("param") SupplierListReqVO param);

    default List<ProductSupplierDO> selectListByType(SupplierListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProductSupplierDO>()
                .eqIfPresent(ProductSupplierDO::getType, reqVO.getType())
                .eqIfPresent(ProductSupplierDO::getUseStatus, reqVO.getUseStatus())
        );
    }
}