package cn.iocoder.yudao.module.bpm.dal.mysql.oa;

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.bpm.controller.admin.oa.vo.supplierprocurementplan.BpmOASupplierProcurementPlanPageReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASupplierProcurementPlanDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 供应商采购计划 Mapper
 *
 * @author 艾楷
 */
@Mapper
public interface BpmOASupplierProcurementPlanMapper extends BaseMapperX<BpmOASupplierProcurementPlanDO> {

    default PageResult<BpmOASupplierProcurementPlanDO> selectPage(BpmOASupplierProcurementPlanPageReqVO reqVO) {
        LambdaQueryWrapperX<BpmOASupplierProcurementPlanDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<BpmOASupplierProcurementPlanDO>()
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getUserId, reqVO.getUserId())
                .likeIfPresent(BpmOASupplierProcurementPlanDO::getSupplierName, reqVO.getSupplierName())
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getSettlementMethod, reqVO.getSettlementMethod())
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getSettlementFlag, reqVO.getSettlementFlag())
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getCompanyAccount, reqVO.getCompanyAccount())
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getBankAccountOpeningBank, reqVO.getBankAccountOpeningBank())
                .betweenIfPresent(BpmOASupplierProcurementPlanDO::getSettlementDate, reqVO.getSettlementDate())
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getResult, reqVO.getResult())
                .eqIfPresent(BpmOASupplierProcurementPlanDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .betweenIfPresent(BpmOASupplierProcurementPlanDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BpmOASupplierProcurementPlanDO::getId);
        if (reqVO.getCertificateFlag() != null) {
            lambdaQueryWrapperX.isNull(reqVO.getCertificateFlag() == 0, BpmOASupplierProcurementPlanDO::getTheArrivalFileItems);
            lambdaQueryWrapperX.isNotNull(reqVO.getCertificateFlag() == 1, BpmOASupplierProcurementPlanDO::getTheArrivalFileItems);
        }
        return selectPage(reqVO, lambdaQueryWrapperX);
    }

}
