<?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.dgtly.wxportal.mapper.WxSendMessageMapper">
    
    <resultMap type="WxSendMessage" id="WxSendMessageResult">
        <result property="id"    column="id"    />
        <result property="createTime"    column="create_time"    />
        <result property="toUser"    column="to_user"    />
        <result property="isSuccess"    column="is_success"    />
        <result property="sendText"    column="send_text"    />
        <result property="type"    column="type"    />
        <result property="form"    column="form"    />
    </resultMap>

    <sql id="selectWxSendMessageVo">
        select id, create_time, to_user, is_success, send_text, type,form from wx_send_message
    </sql>

    <select id="selectWxSendMessageList" parameterType="WxSendMessage" resultMap="WxSendMessageResult">
        <include refid="selectWxSendMessageVo"/>
        <where>  
            <if test="toUser != null  and toUser != ''"> and to_user = #{toUser}</if>
            <if test="isSuccess != null  and isSuccess != ''"> and is_success = #{isSuccess}</if>
            <if test="sendText != null  and sendText != ''"> and send_text = #{sendText}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="form != null  and form != ''"> and form = #{form}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
    
    <select id="selectWxSendMessageById" parameterType="Long" resultMap="WxSendMessageResult">
        <include refid="selectWxSendMessageVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWxSendMessage" parameterType="WxSendMessage">
        insert into wx_send_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="toUser != null  and toUser != ''">to_user,</if>
            <if test="isSuccess != null  and isSuccess != ''">is_success,</if>
            <if test="sendText != null  and sendText != ''">send_text,</if>
            <if test="type != null  and type != ''">type,</if>
            <if test="form != null  and form != ''">form,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="toUser != null  and toUser != ''">#{toUser},</if>
            <if test="isSuccess != null  and isSuccess != ''">#{isSuccess},</if>
            <if test="sendText != null  and sendText != ''">#{sendText},</if>
            <if test="type != null  and type != ''">#{type},</if>
            <if test="form != null  and form != ''">#{form},</if>
         </trim>
    </insert>

    <update id="updateWxSendMessage" parameterType="WxSendMessage">
        update wx_send_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="toUser != null  and toUser != ''">to_user = #{toUser},</if>
            <if test="isSuccess != null  and isSuccess != ''">is_success = #{isSuccess},</if>
            <if test="sendText != null  and sendText != ''">send_text = #{sendText},</if>
            <if test="type != null  and type != ''">type = #{type},</if>
            <if test="form != null  and form != ''">type = #{form},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxSendMessageById" parameterType="Long">
        delete from wx_send_message where id = #{id}
    </delete>

    <delete id="deleteWxSendMessageByIds" parameterType="String">
        delete from wx_send_message where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <insert id="bathInsertWxSendMessage">
        insert into wx_send_message(create_time, to_user,is_success,send_text,type,form) values
        <foreach item="item" index="index" collection="list" separator=",">
            (now(),#{item.toUser},#{item.isSuccess},#{item.sendText},#{item.type},#{item.form})
        </foreach>
    </insert>
    
</mapper>