package com.zt.plat.module.contractorder.dal.mysql.contract;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.datapermission.core.annotation.CompanyDataPermissionIgnore;
import com.zt.plat.framework.datapermission.core.annotation.DataPermission;
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.contractorder.api.vo.contract.ContractPageReqVO;
import com.zt.plat.module.contractorder.dal.dataobject.contract.ContractMainDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 合同主信息 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ContractMainMapper extends BaseMapperX<ContractMainDO> {
    default PageResult<ContractMainDO> selectContractPage(ContractPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ContractMainDO>()
                .likeIfPresent(ContractMainDO::getContractName, reqVO.getContractName())
                .likeIfPresent(ContractMainDO::getContractPaperNumber, reqVO.getContractPaperNumber())
                .eqIfPresent(ContractMainDO::getDirection, reqVO.getDirection())
                .betweenIfPresent(ContractMainDO::getSignDate, reqVO.getSignDate())
                .likeIfPresent(ContractMainDO::getPurchaseCompanyName, reqVO.getPurchaseCompanyName())
                .likeIfPresent(ContractMainDO::getSalesCompanyName, reqVO.getSalesCompanyName())
                .eqIfPresent(ContractMainDO::getBasicAmount, reqVO.getBasicAmount())
                .eqIfPresent(ContractMainDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ContractMainDO::getBusinessType, reqVO.getBusinessType())
                .orderByDesc(ContractMainDO::getCreateTime));
    }

    @CompanyDataPermissionIgnore
    @DeptDataPermissionIgnore
    default PageResult<ContractMainDO> selectContractPageNoPermission(ContractPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ContractMainDO>()
                .eq(ContractMainDO::getId, reqVO.getId())
                .likeIfPresent(ContractMainDO::getContractName, reqVO.getContractName())
                .likeIfPresent(ContractMainDO::getContractPaperNumber, reqVO.getContractPaperNumber())
                .eqIfPresent(ContractMainDO::getDirection, reqVO.getDirection())
                .betweenIfPresent(ContractMainDO::getSignDate, reqVO.getSignDate())
                .likeIfPresent(ContractMainDO::getPurchaseCompanyName, reqVO.getPurchaseCompanyName())
                .likeIfPresent(ContractMainDO::getSalesCompanyName, reqVO.getSalesCompanyName())
                .eqIfPresent(ContractMainDO::getBasicAmount, reqVO.getBasicAmount())
                .eqIfPresent(ContractMainDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ContractMainDO::getBusinessType, reqVO.getBusinessType())
                .eqIfPresent(ContractMainDO::getErpSalesCompanyNumber, reqVO.getErpSalesCompanyNumber())
                .eqIfPresent(ContractMainDO::getErpPurchaseCompanyNumber, reqVO.getErpPurchaseCompanyNumber())
                .orderByDesc(ContractMainDO::getCreateTime));
    }
}