<?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.cyksj.mapper.corp.CorpGroupChatMemberMapper">

    <insert id="batchInsert">
        insert into
        corp_group_chat_member(`wx_crop_id`,`user_id`,`group_chat_id`,`corp_user_id`,`type`,`unionid`,`join_time`,`join_scene`,`group_nickname`,`name`,`inviter_user_id`,`created_time`,`update_time`)
        values
        <foreach collection="memberList" item="item" separator=",">
            (#{wxCorpId},#{item.yhUserId},#{groupChatId},#{item.userId},#{item.type},#{item.unionId},#{item.joinTime},#{item.joinScene},#{item.groupNickname},#{item.name},
            <if test="item.invitor == null">
                ''
            </if>
            <if test="item.invitor != null">
                #{item.invitor.userid}
            </if>
            ,now(),now())
        </foreach>
        ON DUPLICATE KEY UPDATE chatId = VALUES(chatId),
        deleted = 1
    </insert>

    <update id="batchDeleteByChatIdAndUserId">
        update corp_group_chat_member
        set deleted = false
        where group_chat_id = #{groupChatId} and
        corp_user_id in
        <foreach collection="delUserIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

    <select id="getAllMemberByCorpIdAndChatId" resultType="java.lang.String">
        select corp_user_id
        from corp_group_chat_member
        where group_chat_id = #{groupChatId}
    </select>
</mapper>