<?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.WdInfoMapper">
    <resultMap type="com.ruoyi.demo.entity.vo.AddStatusVo" id="AddStatusResult">
        <result property="typeCode" column="wd_type_code"/>
        <result property="count" column="count"/>
        <result property="time" column="time"/>
    </resultMap>

    <select id="list" parameterType="com.ruoyi.demo.entity.vo.WdInfoVo" resultType="com.ruoyi.demo.entity.WdInfo">
        select * from ddt_wd_info
        <where>
            <if test="wdName != null and wdName != ''">
                and wd_name like concat("%",#{wdName},"%")
            </if>
            <if test="typeCodeBy != null and typeCodeBy != ''">
                and type_code_by = #{typeCodeBy}
            </if>
            <if test="addrCode != null and addrCode != ''">
                and addr_code = #{addrCode}
            </if>
            <if test="showDelete != -1">
                and show_delete = #{showDelete}
            </if>
        </where>
    </select>
    <select id="searchAddStatusByMulti" resultMap="AddStatusResult">
        SELECT
            wd_type_code,
            COUNT(*) count,
	        DATE_FORMAT(collect_time, "%Y-%m") time
        FROM
            `ddt_wd_info`
        <trim prefix="where" prefixOverrides="and">
            <if test="times != null">
                <foreach collection="times" item="time" open="and DATE_FORMAT(collect_time, '%Y-%m') IN (" separator="," close=")">
                    #{time,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="addrCodes != null">
                <foreach collection="addrCodes" item="addrCode" open="and addr_code IN (" separator="," close=")">
                    #{addrCode,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="wdTypeCodes != null">
                <foreach collection="wdTypeCodes" item="type" open="and wd_type_code IN (" separator="," close=")">
                    #{type,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
        GROUP BY
            wd_type_code,
            time
    </select>
    <update id="recoverWd" parameterType="java.lang.String">
        update ddt_wd_info set show_delete = 0 where wd_id = #{wdId}
    </update>
    <select id="selectChannel" resultType="com.ruoyi.demo.entity.vo.ChannelVo">
        SELECT
            dwi.wd_img,
            dwi.wd_name,
            dsw.contact,
            dsw.telephone,
            channel_type
        FROM
            `ddt_store_wd` dsw
                LEFT JOIN `ddt_wd_info` dwi ON dwi.wd_id = dsw.wd_id ${ew.customSqlSegment}
    </select>
</mapper>
