<?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.demo.mapper.BrandZoneDao">
    <resultMap type="com.ruoyi.demo.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.demo.entity.BrandProvince" id="ProvinceResult">
        <result property="disId" column="dis_id"/>
        <result property="brandId" column="brand_id"/>
        <result property="addrCode" column="addr_code"/>
        <result property="province" column="province"/>
        <result property="lat" column="lat"/>
        <result property="lng" column="lng"/>
        <result property="disCount" column="dis_count"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <resultMap type="com.ruoyi.demo.entity.BrandCity" id="CityResult">
        <result property="disId" column="dis_id"/>
        <result property="brandId" column="brand_id"/>
        <result property="addrCode" column="addr_code"/>
        <result property="city" column="city"/>
        <result property="lat" column="lat"/>
        <result property="lng" column="lng"/>
        <result property="disCount" column="dis_count"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <select id="searchZoneCountByBrandId" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `bl_brand_zone_distribution`
        WHERE
            brand_id = #{brandId}
    </select>
    <select id="searchQuicklyStatistics" resultMap="BrandZoneResult">
        SELECT
            brand_id,
            brand_name,
            addr_code,
            COUNT(*) dis_count,
            ROUND(AVG(score), 2) avg_score
        FROM
            `ddt_store_wd` dsw,
            `ddt_wd_info` dwi
        WHERE
            dsw.wd_id = dwi.wd_id
        AND brand_id IS NOT NULL
        AND brand_id <![CDATA[<>]]> ''
        <if test="ins != null">
            <foreach collection="ins" item="in" open="and brand_id in (" separator="," close=")">
                #{in,jdbcType=VARCHAR}
            </foreach>
        </if>
        GROUP BY
            brand_id,
            brand_name,
            addr_code;
    </select>
    <select id="selectIns" resultType="java.lang.String">
        SELECT DISTINCT
            brand_id
        FROM
            `bl_brand_zone_distribution`;
    </select>
    <select id="selectTierCountByBrandIdAndCode" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `bl_brand_zone_distribution`
        WHERE
            brand_id = #{brandId}
          AND addr_code LIKE CONCAT(#{code},"%");
    </select>
</mapper>
