<?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.QwGroupMsgUserMapper">

    <resultMap type="QwGroupMsgUser" id="QwGroupMsgUserResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="msgId"    column="msg_id"    />
        <result property="status"    column="status"    />
        <result property="sendTime"    column="send_time"    />
        <result property="externalUserid"    column="external_userid"    />
        <result property="chatId"    column="chat_id"    />
        <result property="chatType"    column="chat_type"    />
        <result property="corpId"    column="corp_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="sendStatus"    column="send_status"    />
        <result property="groupMsgId"    column="group_msg_id"    />
    </resultMap>

    <sql id="selectQwGroupMsgUserVo">
        select id, user_id, msg_id, status, send_time, external_userid, chat_id, chat_type, corp_id, company_id, send_status, group_msg_id from qw_group_msg_user
    </sql>

    <select id="selectQwGroupMsgUserList" parameterType="QwGroupMsgUser" resultMap="QwGroupMsgUserResult">
        <include refid="selectQwGroupMsgUserVo"/>
        <where>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="msgId != null  and msgId != ''"> and msg_id = #{msgId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="externalUserid != null  and externalUserid != ''"> and external_userid = #{externalUserid}</if>
            <if test="chatId != null  and chatId != ''"> and chat_id = #{chatId}</if>
            <if test="chatType != null  and chatType != ''"> and chat_type = #{chatType}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="sendStatus != null  and sendStatus != ''"> and send_status = #{sendStatus}</if>
            <if test="groupMsgId != null "> and group_msg_id = #{groupMsgId}</if>
        </where>
    </select>

    <select id="selectQwGroupMsgUserById" parameterType="Long" resultMap="QwGroupMsgUserResult">
        <include refid="selectQwGroupMsgUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwGroupMsgUser" parameterType="QwGroupMsgUser" useGeneratedKeys="true" keyProperty="id">
        insert into qw_group_msg_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="msgId != null">msg_id,</if>
            <if test="status != null">status,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="externalUserid != null">external_userid,</if>
            <if test="chatId != null">chat_id,</if>
            <if test="chatType != null">chat_type,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="sendStatus != null">send_status,</if>
            <if test="groupMsgId != null">group_msg_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="msgId != null">#{msgId},</if>
            <if test="status != null">#{status},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="externalUserid != null">#{externalUserid},</if>
            <if test="chatId != null">#{chatId},</if>
            <if test="chatType != null">#{chatType},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="sendStatus != null">#{sendStatus},</if>
            <if test="groupMsgId != null">#{groupMsgId},</if>
         </trim>
    </insert>

    <update id="updateQwGroupMsgUser" parameterType="QwGroupMsgUser">
        update qw_group_msg_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="msgId != null">msg_id = #{msgId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="externalUserid != null">external_userid = #{externalUserid},</if>
            <if test="chatId != null">chat_id = #{chatId},</if>
            <if test="chatType != null">chat_type = #{chatType},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="sendStatus != null">send_status = #{sendStatus},</if>
            <if test="groupMsgId != null">group_msg_id = #{groupMsgId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateQwGroupMsgUserResult" parameterType="QwGroupMsgUser">
        update qw_group_msg_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="msgId != null">msg_id = #{msgId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="externalUserid != null">external_userid = #{externalUserid},</if>
            <if test="chatId != null">chat_id = #{chatId},</if>
            <if test="chatType != null">chat_type = #{chatType},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="sendStatus != null">send_status = #{sendStatus},</if>
            <if test="groupMsgId != null">group_msg_id = #{groupMsgId},</if>
        </trim>
        where user_id = #{userId} and msg_id = #{msgId} and external_userid = #{externalUserid}
    </update>


    <delete id="deleteQwGroupMsgUserById" parameterType="Long">
        delete from qw_group_msg_user where id = #{id}
    </delete>

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