<?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.fs.qw.mapper.QwMessagesMapper">
    
    <resultMap type="QwMessages" id="QwMessagesResult">
        <result property="id"    column="id"    />
        <result property="msgid"    column="msgid"    />
        <result property="action"    column="action"    />
        <result property="from"    column="from"    />
        <result property="tolist"    column="tolist"    />
        <result property="roomid"    column="roomid"    />
        <result property="msgtime"    column="msgtime"    />
        <result property="msgtype"    column="msgtype"    />
        <result property="content"    column="content"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectQwMessagesVo">
        select id, msgid, action, from, tolist, roomid, msgtime, msgtype, content, created_at, updated_at from qw_messages
    </sql>

    <select id="selectQwMessagesList" parameterType="QwMessages" resultMap="QwMessagesResult">
        <include refid="selectQwMessagesVo"/>
        <where>  
            <if test="msgid != null  and msgid != ''"> and msgid = #{msgid}</if>
            <if test="action != null  and action != ''"> and action = #{action}</if>
            <if test="from != null  and from != ''"> and from = #{from}</if>
            <if test="tolist != null  and tolist != ''"> and tolist = #{tolist}</if>
            <if test="roomid != null  and roomid != ''"> and roomid = #{roomid}</if>
            <if test="msgtime != null "> and msgtime = #{msgtime}</if>
            <if test="msgtype != null  and msgtype != ''"> and msgtype = #{msgtype}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectQwMessagesById" parameterType="Long" resultMap="QwMessagesResult">
        <include refid="selectQwMessagesVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQwMessages" parameterType="QwMessages" useGeneratedKeys="true" keyProperty="id">
        insert into qw_messages
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="msgid != null and msgid != ''">msgid,</if>
            <if test="action != null and action != ''">action,</if>
            <if test="from != null and from != ''">from,</if>
            <if test="tolist != null and tolist != ''">tolist,</if>
            <if test="roomid != null">roomid,</if>
            <if test="msgtime != null">msgtime,</if>
            <if test="msgtype != null and msgtype != ''">msgtype,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="msgid != null and msgid != ''">#{msgid},</if>
            <if test="action != null and action != ''">#{action},</if>
            <if test="from != null and from != ''">#{from},</if>
            <if test="tolist != null and tolist != ''">#{tolist},</if>
            <if test="roomid != null">#{roomid},</if>
            <if test="msgtime != null">#{msgtime},</if>
            <if test="msgtype != null and msgtype != ''">#{msgtype},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>
    <insert id="batchInsertQwMessages" parameterType="java.util.List">
        insert into qw_messages
        (msgid, action, `from`, tolist, roomid, msgtime, msgtype, content, created_at, updated_at)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.msgid},
            #{item.action},
            #{item.from},
            #{item.tolist},
            #{item.roomid},
            #{item.msgtime},
            #{item.msgtype},
            #{item.content},
            #{item.createdAt},
            #{item.updatedAt}
            )
        </foreach>
    </insert>
    <update id="updateQwMessages" parameterType="QwMessages">
        update qw_messages
        <trim prefix="SET" suffixOverrides=",">
            <if test="msgid != null and msgid != ''">msgid = #{msgid},</if>
            <if test="action != null and action != ''">action = #{action},</if>
            <if test="from != null and from != ''">from = #{from},</if>
            <if test="tolist != null and tolist != ''">tolist = #{tolist},</if>
            <if test="roomid != null">roomid = #{roomid},</if>
            <if test="msgtime != null">msgtime = #{msgtime},</if>
            <if test="msgtype != null and msgtype != ''">msgtype = #{msgtype},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwMessagesById" parameterType="Long">
        delete from qw_messages where id = #{id}
    </delete>

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