<?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.friend.mapper.ImFriendRecommendMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, client_id, client_id_friend, source, del_flag, create_time, update_time
    </sql>

    <select id="getImFriendRecommendPageList" resultType="com.wecloud.im.friend.param.ImFriendRecommendDto">
        select
            recommend.id, client.client_id as friendClientId, recommend.source, recommend.del_flag
        from im_friend_recommend recommend inner join im_client client on recommend.client_id_friend = client.client_id
        where client_id = #{clientId}
    </select>

    <update id="batchDeleteRecommend">
        update im_friend_recommend set del_flag = 1 where client_id = #{clientId} and client_id_friend in (
        select client_id from im_client where (fk_appid, client_id) in
        <foreach collection="friendClientIds" item="friendClientId" open="(" close=")" separator=",">
            (#{fkAppId}, #{friendClientId})
        </foreach>
        )
    </update>

    <insert id="batchCreateRecommend" >
        insert into im_friend_recommend(id, client_id, client_id_friend, source, del_flag, create_time)
        values
               <foreach collection="list" item="item" separator=",">
                   (#{item.id},#{item.clientId},#{item.clientIdFriend},#{item.source},#{item.delFlag}, NOW())
               </foreach>
        ON DUPLICATE KEY UPDATE update_time = now()
    </insert>

</mapper>
