<?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_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}
        AND im_conversation_members.fk_appid = #{appId}
        AND im_client.client_id IN
        <foreach collection="clientIds" item="clientId" index="index" open="(" close=")" separator=",">
            #{clientId}
        </foreach>
    </select>

</mapper>
