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

    <resultMap type="QwGroupChat" id="QwGroupChatResult">
        <result property="chatId"    column="chat_id"    />
        <result property="name"    column="name"    />
        <result property="owner"    column="owner"    />
        <result property="notice"    column="notice"    />
        <result property="memberVersion"    column="member_version"    />
        <result property="status"    column="status"    />
        <result property="companyId"    column="company_id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createAt"    column="create_at"    />
        <result property="groupSize"    column="group_size"    />
        <result property="todayJoin"    column="today_join"    />
        <result property="todayOut"    column="today_out"    />
        <result property="allOutGroup"    column="all_out_group"    />
    </resultMap>

    <sql id="selectQwGroupChatVo">
        select chat_id, name, owner, notice, member_version, status, company_id, corp_id, create_time, update_time, create_at, group_size, today_join, today_out, all_out_group from qw_group_chat
    </sql>

    <select id="selectQwGroupChatList" parameterType="QwGroupChat" resultMap="QwGroupChatResult">
        <include refid="selectQwGroupChatVo"/>
        <where>
            <if test="chatId != null  and chatId != ''"> and chat_id like concat('%', #{chatId}, '%')</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="owner != null  and owner != ''"> and owner = #{owner}</if>
            <if test="notice != null  and notice != ''"> and notice like concat('%', #{notice}, '%')</if>
            <if test="memberVersion != null  and memberVersion != ''"> and member_version = #{memberVersion}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
            <if test="groupSize != null "> and group_size = #{groupSize}</if>
            <if test="todayJoin != null "> and today_join = #{todayJoin}</if>
            <if test="todayOut != null "> and today_out = #{todayOut}</if>
            <if test="allOutGroup != null "> and all_out_group = #{allOutGroup}</if>
        </where>
    </select>

    <select id="selectQwGroupChatByChatId" parameterType="String" resultMap="QwGroupChatResult">
        <include refid="selectQwGroupChatVo"/>
        where chat_id = #{chatId}
    </select>
    <select id="selectQwGroupChatByChatIds" resultType="com.fs.qw.domain.QwGroupChat">
        select * from qw_group_chat where chat_id in <foreach collection="ids" open="(" separator="," close=")" item="item">#{item}</foreach>
    </select>
    <insert id="insertOrUpdateQwGroupChat" parameterType="QwGroupChat">
        insert into qw_group_chat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="chatId != null">chat_id,</if>
            <if test="name != null">name,</if>
            <if test="owner != null">owner,</if>
            <if test="notice != null">notice,</if>
            <if test="memberVersion != null">member_version,</if>
            <if test="status != null">status,</if>
            <if test="companyId != null">company_id,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createAt != null">create_at,</if>
            <if test="groupSize != null">group_size,</if>
            <if test="todayJoin != null">today_join,</if>
            <if test="todayOut != null">today_out,</if>
            <if test="allOutGroup != null">all_out_group,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="chatId != null">#{chatId},</if>
            <if test="name != null">#{name},</if>
            <if test="owner != null">#{owner},</if>
            <if test="notice != null">#{notice},</if>
            <if test="memberVersion != null">#{memberVersion},</if>
            <if test="status != null">#{status},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="groupSize != null">#{groupSize},</if>
            <if test="todayJoin != null">#{todayJoin},</if>
            <if test="todayOut != null">#{todayOut},</if>
            <if test="allOutGroup != null">#{allOutGroup},</if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="notice != null">notice = #{notice},</if>
            <if test="memberVersion != null">member_version = #{memberVersion},</if>
            <if test="status != null">status = #{status},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="groupSize != null">group_size = #{groupSize},</if>
            <if test="todayJoin != null">today_join = #{todayJoin},</if>
            <if test="todayOut != null">today_out = #{todayOut},</if>
            <if test="allOutGroup != null">all_out_group = #{allOutGroup},</if>
        </trim>
    </insert>

    <insert id="insertQwGroupChat" parameterType="QwGroupChat">
        insert into qw_group_chat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="chatId != null">chat_id,</if>
            <if test="name != null">name,</if>
            <if test="owner != null">owner,</if>
            <if test="notice != null">notice,</if>
            <if test="memberVersion != null">member_version,</if>
            <if test="status != null">status,</if>
            <if test="companyId != null">company_id,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createAt != null">create_at,</if>
            <if test="groupSize != null">group_size,</if>
            <if test="todayJoin != null">today_join,</if>
            <if test="todayOut != null">today_out,</if>
            <if test="allOutGroup != null">all_out_group,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="chatId != null">#{chatId},</if>
            <if test="name != null">#{name},</if>
            <if test="owner != null">#{owner},</if>
            <if test="notice != null">#{notice},</if>
            <if test="memberVersion != null">#{memberVersion},</if>
            <if test="status != null">#{status},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="groupSize != null">#{groupSize},</if>
            <if test="todayJoin != null">#{todayJoin},</if>
            <if test="todayOut != null">#{todayOut},</if>
            <if test="allOutGroup != null">#{allOutGroup},</if>
         </trim>
    </insert>

    <update id="updateQwGroupChat" parameterType="QwGroupChat">
        update qw_group_chat
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="notice != null">notice = #{notice},</if>
            <if test="memberVersion != null">member_version = #{memberVersion},</if>
            <if test="status != null">status = #{status},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="groupSize != null">group_size = #{groupSize},</if>
            <if test="todayJoin != null">today_join = #{todayJoin},</if>
            <if test="todayOut != null">today_out = #{todayOut},</if>
            <if test="allOutGroup != null">all_out_group = #{allOutGroup},</if>
        </trim>
        where chat_id = #{chatId}
    </update>

    <delete id="deleteQwGroupChatByChatId" parameterType="String">
        delete from qw_group_chat where chat_id = #{chatId}
    </delete>

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