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

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.company.vo.CompanyPageReqVO;
import com.yc.ship.module.resource.controller.admin.vo.SimpleListReqVO;
import com.yc.ship.module.resource.dal.dataobject.company.CompanyDO;
import com.yc.ship.module.resource.enums.CommonStatusEnum;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 供应商 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface CompanyMapper extends BaseMapperX<CompanyDO> {

    default PageResult<CompanyDO> selectPage(CompanyPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CompanyDO>()
                .eqIfPresent(CompanyDO::getId, reqVO.getId())
                .eqIfPresent(CompanyDO::getCompanyCode, reqVO.getCompanyCode())
                .likeIfPresent(CompanyDO::getCompanyName, reqVO.getCompanyName())
                .likeIfPresent(CompanyDO::getShortName, reqVO.getShortName())
                .eqIfPresent(CompanyDO::getCompanyType, reqVO.getCompanyType())
                .eqIfPresent(CompanyDO::getContactUser, reqVO.getContactUser())
                .eqIfPresent(CompanyDO::getContactPhone, reqVO.getContactPhone())
                .eqIfPresent(CompanyDO::getContactAddr, reqVO.getContactAddr())
                .betweenIfPresent(CompanyDO::getContractDate, reqVO.getContractDate())
                .eqIfPresent(CompanyDO::getUseStatus, reqVO.getUseStatus())
                .eqIfPresent(CompanyDO::getContractInfo, reqVO.getContractInfo())
                .eqIfPresent(CompanyDO::getRemark, reqVO.getRemark())
                .likeIfPresent(CompanyDO::getBankName, reqVO.getBankName())
                .eqIfPresent(CompanyDO::getBankAccout, reqVO.getBankAccout())
                .likeIfPresent(CompanyDO::getBankUserName, reqVO.getBankUserName())
                .eqIfPresent(CompanyDO::getBankLinkNo, reqVO.getBankLinkNo())
                .betweenIfPresent(CompanyDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CompanyDO::getResourceType, reqVO.getResourceType())
                .orderByDesc(CompanyDO::getId));
    }

    default List<CompanyDO> selectList(SimpleListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CompanyDO>()
                .likeIfPresent(CompanyDO::getCompanyName, reqVO.getName())
                .eqIfPresent(CompanyDO::getUseStatus, reqVO.getStatus())
                .eqIfPresent(CompanyDO::getCompanyType, reqVO.getCompanyType())
                .eqIfPresent(CompanyDO::getDeleted, CommonStatusEnum.ENABLE.getStatus())
                .eqIfPresent(CompanyDO::getTenantId, reqVO.getTenantId()));
    }

}