<?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.WdOpcloseDao">
    <resultMap type="com.ruoyi.benyun.entity.WdOpclose" id="WdOpcloseResult">
        <result property="statId" column="stat_id"/>
        <result property="addrCode" column="addr_code"/>
        <result property="wdTypeCode" column="wd_type_code"/>
        <result property="openCount" column="open_count"/>
        <result property="closeCount" column="close_count"/>
        <result property="statTime" column="stat_time"/>
    </resultMap>
    <select id="selectListByAddrCodeAndWdTypeCodes" resultMap="WdOpcloseResult">
        SELECT
            SUM(open_count) open_count,
            SUM(close_count) close_count
        FROM
            `bl_wd_opclose_statistics`
        <trim prefix="where" prefixOverrides="and">
            <if test="addrCode != null">
                and addr_code LIKE CONCAT(#{addrCode}, '%')
            </if>
            <if test="wdTypeCodes != null">
                <foreach collection="wdTypeCodes" item="code" open="and wd_type_code in (" separator="," close=")">
                    #{code,jdbcType=VARCHAR}
                </foreach>
            </if>
            and DATE_FORMAT(stat_time, '%Y-%m') = DATE_FORMAT(#{time}, '%Y-%m');
        </trim>
    </select>
</mapper>

