<?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.BrandStoreOpcloseDao">
    <resultMap type="com.ruoyi.benyun.entity.vo.BrandOpcloseVo" id="BrandOpcloseResult">
        <result property="brandId" column="brand_id"/>
        <result property="brandName" column="brand_name"/>
        <result property="count" column="count"/>
    </resultMap>
    <select id="selectOpenByMulti" resultMap="BrandOpcloseResult">
        SELECT
            brand_id,
            brand_name,
            SUM(open_count) count
        FROM
            `bl_brand_store_opclose_statistics`
        <trim prefix="where" prefixOverrides="and">
            <if test="typeCodes != null">
                <foreach collection="typeCodes" item="typeCode" open="and type_code_by in (" separator="," close=")">
                    #{typeCode,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="startTime != null">
                and DATE_FORMAT(#{startTime},'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(stat_time, '%Y-%m-%d')
            </if>
            <if test="endTime != null">
                and DATE_FORMAT(stat_time, '%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{endTime},'%Y-%m-%d')
            </if>
        </trim>
        GROUP BY
            brand_id,
            brand_name
        ORDER BY
            count DESC;
    </select>
    <select id="selectCloseByMulti" resultMap="BrandOpcloseResult">
        SELECT
            brand_id,
            brand_name,
            SUM(close_count) count
        FROM
            `bl_brand_store_opclose_statistics`
        <trim prefix="where" prefixOverrides="and">
            <if test="typeCodes != null">
                <foreach collection="typeCodes" item="typeCode" open="and type_code_by in (" separator="," close=")">
                    #{typeCode,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="startTime != null">
                and DATE_FORMAT(#{startTime},'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(stat_time, '%Y-%m-%d')
            </if>
            <if test="endTime != null">
                and DATE_FORMAT(stat_time, '%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{endTime},'%Y-%m-%d')
            </if>
        </trim>
        GROUP BY
            brand_id,
            brand_name
        ORDER BY
            count DESC;
    </select>
</mapper>
