<?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.wecloud.im.mapper.ImConversationMembersMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , create_time, update_time, fk_appid, fk_conversation_id, fk_client_id
    </sql>

    <select id="getImConversationMembersById" resultType="com.wecloud.im.param.ImConversationMembersQueryVo">
        select
        <include refid="Base_Column_List"/>
        from im_conversation_members where id = #{id}
    </select>

    <select id="getImConversationMembersPageList" parameterType="com.wecloud.im.param.ImConversationMembersPageParam"
            resultType="com.wecloud.im.param.ImConversationMembersQueryVo">
        select
        <include refid="Base_Column_List"/>
        from im_conversation_members
    </select>
    <select id="getRestApiImConversationMembersList"
            resultType="com.wecloud.im.param.ApiImConversationMembersQueryVo">

        SELECT im_client.client_id AS clientId
        FROM im_conversation_members AS imConversationMembers
                 INNER JOIN im_client AS im_client ON im_client.id = imConversationMembers.fk_client_id
        WHERE fk_conversation_id = #{conversationId}

    </select>
    <select id="getImConversationMembersList" resultType="com.wecloud.im.vo.ImConversationMemberListVo">

        SELECT im_client.client_id                        as clientId,
               im_conversation_members.client_remark_name as clientRemarkName,
               im_client.head_portrait                    as headPortrait,
               im_client.nickname,
               im_conversation_members.attributes         AS memberAttributes,
               im_client.attributes                       AS clientAttributes
        FROM im_conversation_members AS im_conversation_members
                 INNER JOIN im_client AS im_client ON im_client.id = im_conversation_members.fk_client_id
        WHERE im_conversation_members.fk_conversation_id = #{conversationId}

    </select>

    <select id="findThousandGroupsByClientId" resultType="java.lang.Long">
        select a.id from im_conversation a
            inner join im_conversation_members b on a.id = b.fk_conversation_id
        where b.fk_client_id = #{clientId} and a.chat_type = 3
    </select>

</mapper>
