<?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.StoreDao">
    <resultMap type="com.ruoyi.benyun.entity.StoreWd" id="StoreWdResult">
        <result property="wdId" column="wd_id"/>
        <result property="brandId" column="brand_id"/>
        <result property="brandName" column="brand_name"/>
        <result property="perCapitaConsumption" column="per_capita_consumption"/>
        <result property="manageTypeCode" column="manage_type_code"/>
        <result property="industryCode" column="industry_code"/>
        <result property="organizationCode" column="organization_code"/>
        <result property="commentCount" column="comment_count"/>
        <result property="score" column="score"/>
        <result property="buyInfo" column="buy_info"/>
        <result property="indexScore" column="index_socre"/>
        <result property="businessStatus" column="business_status"/>
        <result property="businessTime" column="business_time"/>
        <result property="telephone" column="telephone"/>
        <result property="contact" column="contact"/>
    </resultMap>
    <resultMap type="com.ruoyi.benyun.entity.vo.BrandDisItem" id="StoreOrderByCountResult">
        <result property="code" column="brand_id"/>
        <result property="name" column="brand_name"/>
        <result property="count" column="count"/>
    </resultMap>
    <resultMap type="com.ruoyi.benyun.entity.vo.Info" id="InfoResult">
        <result property="addrCode" column="addr_code"/>
        <result property="avgScore" column="avg_Score"/>
        <result property="count" column="count"/>
    </resultMap>
    <update id="updateBrandIdByWdId">
        UPDATE `ddt_store_wd`
        SET brand_id = #{brandId}
        WHERE
        <foreach collection="wdIds" item="wdId" open="wd_id IN (" separator="," close=")">
            #{wdId,jdbcType=VARCHAR}
        </foreach>
    </update>
    <select id="searchCountOrderByCount" resultMap="StoreOrderByCountResult">
        SELECT
        brand_id,
        brand_name,
        COUNT(*) count
        FROM
        `ddt_store_wd`
        WHERE
        brand_id <![CDATA[<>]]> ''
        <if test="notIns != null">
            <foreach collection="notIns" item="ontIn" open="AND brand_id NOT IN (" separator="," close=")">
                #{ontIn,jdbcType=VARCHAR}
            </foreach>
        </if>
        GROUP BY
        brand_id,brand_name
        ORDER BY
        count DESC;
    </select>
    <select id="searchInfoByBrandId" resultMap="InfoResult">
        SELECT
            addr_code,
            COUNT(*) count,
	        ROUND(AVG(score),2) avg_score
        FROM
            `ddt_wd_info` wd,
            `ddt_store_wd` store
        WHERE
            wd.wd_id = store.wd_id
          AND brand_id = #{brandId}
        GROUP BY
            addr_code;
    </select>
    <select id="searchNomalStatusByBrandId" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `ddt_store_wd`
        WHERE
            business_status = "正常"
          AND brand_id = #{brandId}
    </select>
    <select id="searchPauseStatusByBrandId" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `ddt_store_wd`
        WHERE
            business_status = "暂停"
          AND brand_id = #{brandId}
    </select>
    <select id="searchNoStatusByBrandId" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `ddt_store_wd`
        WHERE
            business_status = "尚未营业"
          AND brand_id = #{brandId}
    </select>
    <select id="searchAll" resultMap="StoreWdResult">
        select * from `ddt_store_wd`
    </select>
</mapper>
