<?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="com.yunzhi.marketing.xlk.mapper.BrandMapper">

    <select id="getWxBrandList" resultType="com.yunzhi.marketing.xlk.entity.Brand">
        SELECT
            b.*
        FROM
            xlk_brand b
            INNER JOIN (
            SELECT
                t.building_id,
                t.brand_id
            FROM
                ta_building t
            WHERE
                t.org_id = #{orgId}
            <if test="cityId != null">
                AND t.city_id = #{cityId}
            </if>
            GROUP BY
                t.brand_id
            ) c ON b.brand_id = c.brand_id
        WHERE
            b.ORG_ID = #{orgId}
        <if test="brandName != null and brandName != ''">
            and b.brand_name like CONCAT('%', #{brandName}, '%')
        </if>
        ORDER BY b.Index_letter
    </select>
</mapper>
