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

    <resultMap type="QwGroupMsg" id="QwGroupMsgResult">
        <result property="id"    column="id"    />
        <result property="msgid"    column="msgid"    />
        <result property="chatType"    column="chat_type"    />
        <result property="selectType"    column="select_type"    />
        <result property="filterCustomers"    column="filter_customers"    />
        <result property="sender"    column="sender"    />
        <result property="allowSelect"    column="allow_select"    />
        <result property="textContent"    column="text_content"    />
        <result property="corpId"    column="corp_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="tagNames"    column="tag_names"    />
        <result property="groupChatNames"    column="group_chat_names"    />
        <result property="fromUserCount"    column="from_user_count"    />
        <result property="toUserCount"    column="to_user_count"    />
        <result property="fromUserNum"    column="from_user_num"    />
        <result property="toUserNum"    column="to_user_num"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createName"    column="create_name"    />
        <result property="isSend"    column="is_send"    />
        <result property="isTimerSend"    column="is_timer_send"    />
        <result property="timerSend"    column="timer_send"    />
    </resultMap>

    <sql id="selectQwGroupMsgVo">
        select id, msgid, chat_type,select_type,filter_customers, sender, allow_select, text_content, corp_id, company_id, tag_names, group_chat_names, from_user_count, to_user_count, from_user_num, to_user_num, create_time, update_time, create_name, is_send, is_timer_send, timer_send from qw_group_msg
    </sql>

    <select id="selectQwGroupMsgList" parameterType="QwGroupMsg" resultMap="QwGroupMsgResult">
        <include refid="selectQwGroupMsgVo"/>
        <where>
            <if test="msgid != null  and msgid != ''"> and msgid = #{msgid}</if>
            <if test="chatType != null  and chatType != ''"> and chat_type = #{chatType}</if>
            <if test="selectType != null  and selectType != ''"> and select_type = #{selectType}</if>
            <if test="filterCustomers != null  and filterCustomers != ''"> and filter_customers = #{filterCustomers}</if>
            <if test="sender != null  and sender != ''"> and sender = #{sender}</if>
            <if test="allowSelect != null  and allowSelect != ''"> and allow_select = #{allowSelect}</if>
            <if test="textContent != null  and textContent != ''"> and text_content like concat('%', #{textContent}, '%')</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="tagNames != null  and tagNames != ''"> and tag_names like concat('%', #{tagNames}, '%')</if>
            <if test="groupChatNames != null  and groupChatNames != ''"> and group_chat_names like concat('%', #{groupChatNames}, '%')</if>
            <if test="fromUserCount != null "> and from_user_count = #{fromUserCount}</if>
            <if test="toUserCount != null "> and to_user_count = #{toUserCount}</if>
            <if test="fromUserNum != null "> and from_user_num = #{fromUserNum}</if>
            <if test="toUserNum != null "> and to_user_num = #{toUserNum}</if>
            <if test="createName != null  and createName != ''"> and create_name like concat('%', #{createName}, '%')</if>
            <if test="isSend != null "> and is_send = #{isSend}</if>
            <if test="isTimerSend != null "> and is_timer_send = #{isTimerSend}</if>
            <if test="timerSend != null "> and timer_send = #{timerSend}</if>
        </where>
    </select>

    <select id="selectQwGroupMsgById" parameterType="Long" resultMap="QwGroupMsgResult">
        <include refid="selectQwGroupMsgVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwGroupMsg" parameterType="QwGroupMsg" useGeneratedKeys="true" keyProperty="id">
        insert into qw_group_msg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="msgid != null and msgid != ''">msgid,</if>
            <if test="chatType != null and chatType != ''">chat_type,</if>
            <if test="selectType != null and selectType != ''">select_type,</if>
            <if test="filterCustomers != null and filterCustomers != ''">filter_customers,</if>
            <if test="sender != null and sender != ''">sender,</if>
            <if test="allowSelect != null ">allow_select,</if>
            <if test="textContent != null and textContent != ''">text_content,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="tagNames != null">tag_names,</if>
            <if test="groupChatNames != null">group_chat_names,</if>
            <if test="fromUserCount != null">from_user_count,</if>
            <if test="toUserCount != null">to_user_count,</if>
            <if test="fromUserNum != null">from_user_num,</if>
            <if test="toUserNum != null">to_user_num,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createName != null">create_name,</if>
            <if test="isSend != null">is_send,</if>
            <if test="isTimerSend != null">is_timer_send,</if>
            <if test="timerSend != null">timer_send,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="msgid != null and msgid != ''">#{msgid},</if>
            <if test="chatType != null and chatType != ''">#{chatType},</if>
            <if test="selectType != null and selectType != ''">#{selectType},</if>
            <if test="filterCustomers != null and filterCustomers != ''">#{filterCustomers},</if>
            <if test="sender != null and sender != ''">#{sender},</if>
            <if test="allowSelect != null and allowSelect != ''">#{allowSelect},</if>
            <if test="textContent != null and textContent != ''">#{textContent},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="tagNames != null">#{tagNames},</if>
            <if test="groupChatNames != null">#{groupChatNames},</if>
            <if test="fromUserCount != null">#{fromUserCount},</if>
            <if test="toUserCount != null">#{toUserCount},</if>
            <if test="fromUserNum != null">#{fromUserNum},</if>
            <if test="toUserNum != null">#{toUserNum},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createName != null">#{createName},</if>
            <if test="isSend != null">#{isSend},</if>
            <if test="isTimerSend != null">#{isTimerSend},</if>
            <if test="timerSend != null">#{timerSend},</if>
         </trim>
    </insert>

    <update id="updateQwGroupMsg" parameterType="QwGroupMsg">
        update qw_group_msg
        <trim prefix="SET" suffixOverrides=",">
            <if test="msgid != null and msgid != ''">msgid = #{msgid},</if>
            <if test="chatType != null and chatType != ''">chat_type = #{chatType},</if>
            <if test="selectType != null and selectType != ''">select_type = #{selectType},</if>
            <if test="filterCustomers != null and filterCustomers != ''">filter_customers = #{filterCustomers},</if>
            <if test="sender != null and sender != ''">sender = #{sender},</if>
            <if test="allowSelect != null and allowSelect != ''">allow_select = #{allowSelect},</if>
            <if test="textContent != null and textContent != ''">text_content = #{textContent},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="tagNames != null">tag_names = #{tagNames},</if>
            <if test="groupChatNames != null">group_chat_names = #{groupChatNames},</if>
            <if test="fromUserCount != null">from_user_count = #{fromUserCount},</if>
            <if test="toUserCount != null">to_user_count = #{toUserCount},</if>
            <if test="fromUserNum != null">from_user_num = #{fromUserNum},</if>
            <if test="toUserNum != null">to_user_num = #{toUserNum},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createName != null">create_name = #{createName},</if>
            <if test="isSend != null">is_send = #{isSend},</if>
            <if test="isTimerSend != null">is_timer_send = #{isTimerSend},</if>
            <if test="timerSend != null">timer_send = #{timerSend},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwGroupMsgById" parameterType="Long">
        delete from qw_group_msg where id = #{id}
    </delete>

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