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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
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.SupplierPageReqVO;
import cn.iocoder.yudao.module.supplier.dal.dataobject.product.SupplierDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 供应商主数据 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface SupplierMapper extends BaseMapperX<SupplierDO> {

    /**
     * 禁用数据权限 共享客商信息
     * @param reqVO
     * @return
     */
    @DataPermission(enable = false)
    default PageResult<SupplierDO> selectPage(SupplierPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SupplierDO>()
                .eqIfPresent(SupplierDO::getCode, reqVO.getCode())
                .likeIfPresent(SupplierDO::getName, reqVO.getName())
                .eqIfPresent(SupplierDO::getClassification, reqVO.getClassification())
                .eqIfPresent(SupplierDO::getType, reqVO.getType())
                .eqIfPresent(SupplierDO::getNature, reqVO.getNature())
                .eqIfPresent(SupplierDO::getCreditCode, reqVO.getCreditCode())
                .eqIfPresent(SupplierDO::getTin, reqVO.getTin())
                .eqIfPresent(SupplierDO::getCorporation, reqVO.getCorporation())
                .betweenIfPresent(SupplierDO::getIncorporationDate, reqVO.getIncorporationDate())
                .eqIfPresent(SupplierDO::getAddress, reqVO.getAddress())
                .eqIfPresent(SupplierDO::getBizScope, reqVO.getBizScope())
                .eqIfPresent(SupplierDO::getRegisteredCapital, reqVO.getRegisteredCapital())
                .eqIfPresent(SupplierDO::getAnnualTurnove, reqVO.getAnnualTurnove())
                .eqIfPresent(SupplierDO::getSize, reqVO.getSize())
                .eqIfPresent(SupplierDO::getStatus, reqVO.getStatus())
                .eqIfPresent(SupplierDO::getRemark, reqVO.getRemark())
                .eqIfPresent(SupplierDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(SupplierDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(SupplierDO::getCustomerNature, reqVO.getCustomerNature())
                .eqIfPresent(SupplierDO::getSapCode, reqVO.getSapCode())
                .betweenIfPresent(SupplierDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SupplierDO::getId));
    }

    default SupplierDO selectByBpmProcessInstanceId(String processInstanceId) {
        return selectOne(new LambdaQueryWrapperX<SupplierDO>()
                .eq(SupplierDO::getProcessInstanceId, processInstanceId));

    }

}
