package cn.iocoder.yudao.module.asset.dal.mysql.replacement;

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.asset.controller.admin.replacement.vo.VehicleReplacementPageReqVO;
import cn.iocoder.yudao.module.asset.dal.dataobject.replacement.VehicleReplacementDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 替换车申请 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface VehicleReplacementMapper extends BaseMapperX<VehicleReplacementDO> {

    default PageResult<VehicleReplacementDO> selectPage(VehicleReplacementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VehicleReplacementDO>()
                .likeIfPresent(VehicleReplacementDO::getReplacementCode, reqVO.getReplacementCode())
                .eqIfPresent(VehicleReplacementDO::getReplacementType, reqVO.getReplacementType())
                .eqIfPresent(VehicleReplacementDO::getContractId, reqVO.getContractId())
                .likeIfPresent(VehicleReplacementDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(VehicleReplacementDO::getStatus, reqVO.getStatus())
                .orderByDesc(VehicleReplacementDO::getId));
    }

    @Select("SELECT replacement_code FROM asset_vehicle_replacement WHERE replacement_code LIKE CONCAT(#{prefix}, '%') AND deleted = 0 ORDER BY replacement_code DESC LIMIT 1")
    String selectMaxReplacementCodeByPrefix(@Param("prefix") String prefix);

}
