package cn.iocoder.yudao.module.system.dal.mysql.rental;

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.system.controller.admin.rental.vo.customer.RentalCustomerPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.rental.RentalCustomerDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Objects;

/**
 * 租赁客户 Mapper
 *
 * @author 符溶馨
 */
@Mapper
public interface RentalCustomerMapper extends BaseMapperX<RentalCustomerDO> {

    default PageResult<RentalCustomerDO> selectPage(RentalCustomerPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RentalCustomerDO>()
                .likeIfPresent(RentalCustomerDO::getName, reqVO.getName())
                .eqIfPresent(RentalCustomerDO::getMobile, reqVO.getMobile())
                .likeIfPresent(RentalCustomerDO::getBankName, reqVO.getBankName())
                .eqIfPresent(RentalCustomerDO::getBankNo, reqVO.getBankNo())
                .eqIfPresent(RentalCustomerDO::getAmount, reqVO.getAmount())
                .betweenIfPresent(RentalCustomerDO::getCreateTime, reqVO.getCreateTime())
                .apply(Objects.nonNull(reqVO.getFactoryId()), "JSON_CONTAINS(factory_ids, '{0}', '$')", reqVO.getFactoryId())
                .orderByDesc(RentalCustomerDO::getId));
    }

    List<RentalCustomerDO> selectListByFactory(@Param("userId") Long userId);
}