<?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.StoreWdOpcloseDao">
    <select id="selectWdOpenTimes" resultType="com.ruoyi.benyun.entity.vo.OpcloseTimeVo">
        SELECT
            start_time time,
	        COUNT(*) count
        FROM
            `bl_store_wd_opclose`
        <trim prefix="where" prefixOverrides="and">
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="code" open="and addr_code in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="typeCodeBys != null">
                <foreach collection="typeCodeBys" item="code" open="and type_code_by in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        GROUP BY
            start_time
        ORDER BY
            count DESC;
    </select>
    <select id="selectWdCloseTimes" resultType="com.ruoyi.benyun.entity.vo.OpcloseTimeVo">
        SELECT
            end_time time,
            COUNT(*) count
        FROM
            `bl_store_wd_opclose`
        <trim prefix="where" prefixOverrides="and">
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="code" open="and addr_code in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="typeCodeBys != null">
                <foreach collection="typeCodeBys" item="code" open="and type_code_by in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        GROUP BY
            end_time
        ORDER BY
            count DESC;
    </select>
    <select id="selectBrandOpenTimes" resultType="com.ruoyi.benyun.entity.vo.OpcloseTimeVo">
        SELECT
            brand_id,
            brand_name,
            start_time time,
            COUNT(*) count
        FROM
            `bl_store_wd_opclose`
        <trim prefix="where" prefixOverrides="and">
            <if test="brandIds != null">
                <foreach collection="brandIds" item="id" open="and brand_id in (" separator="," close=")">
                    #{id,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="code" open="and addr_code in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="typeCodeBys != null">
                <foreach collection="typeCodeBys" item="code" open="and type_code_by in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        GROUP BY
            brand_id,
            brand_name,
            start_time
        ORDER BY
            count DESC;
    </select>
    <select id="selectBrandCloseTimes" resultType="com.ruoyi.benyun.entity.vo.OpcloseTimeVo">
        SELECT
            brand_id,
            brand_name,
            end_time time,
            COUNT(*) count
        FROM
            `bl_store_wd_opclose`
        <trim prefix="where" prefixOverrides="and">
            <if test="brandIds != null">
                <foreach collection="brandIds" item="id" open="and brand_id in (" separator="," close=")">
                    #{id,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="code" open="and addr_code in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="typeCodeBys != null">
                <foreach collection="typeCodeBys" item="code" open="and type_code_by in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        GROUP BY
            brand_id,
            brand_name,
            end_time
        ORDER BY
            count DESC;
    </select>
    <select id="selectIns" resultType="java.lang.String">
        SELECT
            wd_id
        FROM
            `bl_store_wd_opclose`;
    </select>
    <select id="selectStatistics" resultType="com.ruoyi.benyun.entity.StoreWdOpclose">
        SELECT
        dwi.wd_id,
        addr_code,
        type_code_by,
        brand_id,
        brand_name,
        business_time
        FROM
        `ddt_wd_info` dwi,
        `ddt_store_wd` dsw
        WHERE
        dwi.wd_id = dsw.wd_id
        <if test="notIns != null">
            <foreach collection="notIns" item="notIn" open="AND dwi.wd_id NOT IN (" separator="," close=")">
                #{notIn,jdbcType=VARCHAR}
            </foreach>
        </if>
        AND business_time <![CDATA[<>]]> ''
        AND business_time <![CDATA[<>]]> '[]';
    </select>
</mapper>
