<?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,device_type,valid
    </sql>
    <update id="removeOldToken">
        UPDATE im_client
        SET device_token = NULL
        WHERE device_token = #{deviceToken}
          AND fk_appid = #{appId}
    </update>

    <select id="getImClientById" resultType="com.wecloud.im.param.ImClientQueryVo">
        select
        <include refid="Base_Column_List"/>
        from im_client where id = #{id}
    </select>

    <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.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>

</mapper>
