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

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , create_time, update_time, fk_appid, attributes,client_id,head_portrait,nickname
    </sql>

    <select id="getImClientPageList" parameterType="com.wecloud.im.param.ImClientPageParam"
            resultType="com.wecloud.im.param.ImClientQueryVo">
        select
        <include refid="Base_Column_List"/>
        from im_client
    </select>

    <select id="getInfoList" resultType="com.wecloud.im.vo.GetInfoListVo">

        SELECT
        im_client.id AS id,
        im_client.client_id AS clientId,
        im_client.head_portrait AS headPortrait,
        im_client.nickname,
        (SELECT im_conversation_members.client_remark_name FROM im_conversation_members AS im_conversation_members WHERE
        im_conversation_members.fk_conversation_id = #{conversationId} AND im_conversation_members.fk_client_id =
        clientId ) AS clientRemarkName ,
        (SELECT im_conversation_members.attributes FROM im_conversation_members AS im_conversation_members WHERE
        im_conversation_members.fk_conversation_id = #{conversationId} AND im_conversation_members.fk_client_id =
        clientId ) AS memberAttributes ,

        im_client.attributes AS clientAttributes
        FROM
        im_client AS im_client

        WHERE
        im_client.fk_appid = #{appId}
        AND im_client.client_id IN
        <foreach collection="clientIds" item="clientId" index="index" open="(" close=")" separator=",">
            #{clientId}
        </foreach>


    </select>

    <select id="getSimpleClients" resultType="com.wecloud.im.param.ImClientSimpleDto">
        select id, fk_appid, client_id from im_client where fk_appid = #{appId} and client_id in
        <foreach collection="clientIds" item="clientId" index="index" open="(" close=")" separator=",">
            #{clientId}
        </foreach>
    </select>

    <select id="getSimpleClientsByIds" resultType="com.wecloud.im.param.ImClientSimpleDto">
        select id, fk_appid, client_id from im_client where id in
        <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

</mapper>
