<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.custom.mapper.CarBrandMapper">

    <sql id="baseCarBrandColumn">
        tbcb.id,
        tbcb.brand_name,
        tbcb.brand_type,
        tbcb.status,
        tbcb.remark,
        tbcb.creator,
        tbcb.create_time,
        tbcb.updater,
        tbcb.update_time,
        tbcb.logo_img,
        tbcb.english_name,
        tbcb.abb_name,
        tbcb.rule_mileage,
        tbcb.rule_time,
        tbcb.brand_value,
        tbcb.deleted,
        tbcb.tenant_id
    </sql>

    <select id="findPage" resultType="cn.iocoder.yudao.module.custom.vo.CarBrandRespVO">
        SELECT
        <include refid="baseCarBrandColumn"></include>
        FROM `base_car_brand` tbcb
        WHERE
        tbcb.deleted = 0
        <if test="dto.brandName != null and dto.brandName != ''">
            AND tbcb.brand_name LIKE CONCAT('%',#{dto.brandName},'%')
        </if>
        <if test="dto.brandType != null and dto.brandType != ''">
            AND tbcb.brand_type = #{dto.brandType}
        </if>
        <if test="dto.status != null and dto.status != ''">
            AND tbcb.status = #{dto.status}
        </if>
        <if test="dto.remark != null and dto.remark != ''">
            AND tbcb.remark = #{dto.remark}
        </if>
        <if test="dto.brandValue != null and dto.brandValue != ''">
            AND tbcb.brand_value = #{dto.brandValue}
        </if>
        <if test="dto.englishName != null and dto.englishName != ''">
            AND tbcb.english_name LIKE CONCAT('%',#{dto.englishName},'%')
        </if>
        <if test="dto.abbName != null and dto.abbName != ''">
            AND tbcb.abb_name LIKE CONCAT('%',#{dto.abbName},'%')
        </if>
        <if test="dto.createTime != null">
            AND tbcb.create_time = #{dto.createTime}
        </if>
        ORDER BY
            tbcb.create_time DESC
    </select>

    <select id="searchBrand" resultType="cn.iocoder.yudao.module.custom.vo.CascaderOptionsVO">
        SELECT
            main.brand_name AS 'label',
            main.id AS 'value',
            '0' AS 'leaf'
        FROM
            base_car_brand main
                LEFT JOIN base_car_model tbcm ON main.id = tbcm.brand_id
        WHERE
            main.deleted = '0'
            AND tbcm.deleted = '0'
        <if test="dto.brandName != null and dto.brandName != ''">
            AND CONCAT( '',main.brand_name, tbcm.model_name, main.abb_name, tbcm.abb_name ) LIKE CONCAT('%',#{dto.brandName},'%')
        </if>
        GROUP BY
            main.id
    </select>

</mapper>