<?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.ruoyi.benyun.mapper.BrandZoneMapper">
    <resultMap type="com.ruoyi.benyun.entity.BrandZone" id="BrandZoneResult">
        <result property="disId" column="dis_id"/>
        <result property="brandId" column="brand_id"/>
        <result property="industryCode" column="industry_code"/>
        <result property="addrCode" column="addr_code"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="zone" column="zone"/>
        <result property="lat" column="lat"/>
        <result property="lng" column="lng"/>
        <result property="disCount" column="dis_count"/>
        <result property="avgScore" column="avg_score"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <resultMap type="com.ruoyi.benyun.entity.bo.BrandAddrDistribution" id="AddrDisResult">
        <result property="addrCode" column="addr_code"/>
        <result property="count" column="count"/>
    </resultMap>
    <select id="searchByBrandId" resultMap="BrandZoneResult">
        select * from bl_brand_zone_distribution where brand_id = #{brandId}
    </select>
    <select id="searchByMulti" resultMap="BrandZoneResult">
        SELECT
            *
        FROM
            `bl_brand_zone_distribution`
        <trim prefix="where" prefixOverrides="and">
            <if test="brandIds != null">
                <foreach collection="brandIds" item="brandId" open="and brand_id IN (" separator="," close=")">
                    #{brandId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="addrCode" open="and addr_code IN (" separator="," close=")">
                    #{addrCode,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="industryCodes != null">
                <foreach collection="industryCodes" item="industryCode" open="and industry_code IN (" separator="," close=")">
                    #{industryCode,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
    </select>
    <select id="searchByAddrCodeGroup" resultMap="AddrDisResult">
        SELECT
            addr_code,
            COUNT(*) count
        FROM
            `bl_brand_zone_distribution`
        <where>
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="addrCode" open="addr_code IN (" separator="," close=")">
                    #{addrCode,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        GROUP BY
            addr_code;
    </select>
</mapper>
