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

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.inspection.vo.InspectionTemplatePageReqVO;
import cn.iocoder.yudao.module.asset.dal.dataobject.inspection.InspectionTemplateDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 验车模板 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface InspectionTemplateMapper extends BaseMapperX<InspectionTemplateDO> {

    default PageResult<InspectionTemplateDO> selectPage(InspectionTemplatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InspectionTemplateDO>()
                .likeIfPresent(InspectionTemplateDO::getCode, reqVO.getCode())
                .likeIfPresent(InspectionTemplateDO::getName, reqVO.getName())
                .eqIfPresent(InspectionTemplateDO::getBizType, reqVO.getBizType())
                .eqIfPresent(InspectionTemplateDO::getStatus, reqVO.getStatus())
                .orderByDesc(InspectionTemplateDO::getId));
    }

    default InspectionTemplateDO selectByBizTypeAndVehicleType(Integer bizType, String vehicleType) {
        return selectOne(new LambdaQueryWrapperX<InspectionTemplateDO>()
                .eq(InspectionTemplateDO::getBizType, bizType)
                .eqIfPresent(InspectionTemplateDO::getVehicleType, vehicleType)
                .eq(InspectionTemplateDO::getStatus, 1)
                .last("LIMIT 1"));
    }

    default InspectionTemplateDO selectDefaultByBizType(Integer bizType) {
        return selectOne(new LambdaQueryWrapperX<InspectionTemplateDO>()
                .eq(InspectionTemplateDO::getBizType, bizType)
                .isNull(InspectionTemplateDO::getVehicleType)
                .eq(InspectionTemplateDO::getStatus, 1)
                .last("LIMIT 1"));
    }

}
