<?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="jnpf.memberLog.mapper.LogMemberAssociationMapper" >

<!--    批量新增成员信息-->
    <insert id="addMemberAssociation">
        insert into ftb_log_member_log_association (F_Id, F_Member_Log_Id, F_User_Id,
                                                    F_User_Type, F_Type, F_Read)
        values
        <foreach collection="logMemberAssociationList" item="item" separator=",">
            (#{item.id}, #{id}, #{item.userId},
            #{item.userType}, #{item.type}, 0)
        </foreach>
    </insert>
<!--    修改指定日志下的所有人为未读-->
    <update id="updateUnRead">
        update ftb_log_member_log_association
        set F_Read = 0
        where F_Member_Log_Id = #{id}
    </update>
<!--    阅读指定信息-->
    <update id="readByIds">
        update ftb_log_member_log_association
        set F_Read = 1
        where F_Id  in
        <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>
    <!--    通过日志id获取关联用户信息-->
    <select id="getReceiveRange" resultType="jnpf.model.memberLog.po.LogMemberAssociation">
        SELECT F_Id id, F_Member_Log_Id memberLogId, F_User_Id userId,F_User_Type userType, F_Type type, F_Read `read`
        FROM ftb_log_member_log_association
        WHERE  F_Member_Log_Id = #{logId}
    </select>
<!--    日志阅读相关查询-->
    <select id="getReadDependence" resultType="jnpf.model.memberLog.po.LogMemberAssociation">
        SELECT  DISTINCT F_User_Id userId,F_User_Type userType, F_Read `read`
        FROM ftb_log_member_log_association
        WHERE  F_Member_Log_Id = #{logId} AND  F_User_Type = 1 AND ( F_Type = 1 OR F_Type = 2) AND F_Read = #{read}
    </select>
<!--    获取日志点赞列表-->
    <select id="getLikeList" resultType="jnpf.model.memberLog.po.LogMemberAssociation">
        SELECT  DISTINCT F_User_Id userId,F_User_Type userType, F_Read `read`
        FROM ftb_log_member_log_association
        WHERE  F_Member_Log_Id = #{logId} AND  F_User_Type = 1 and F_Type = 4
    </select>
    <select id="getMeLike" resultType="java.lang.String">
        SELECT F_Id FROM ftb_log_member_log_association
        WHERE F_Member_Log_Id = #{logId} AND F_User_Id = #{userId}  AND F_User_Type = 1 AND F_Type = 4
    </select>
<!--    获取当前用户在该日志中汇报和抄送中未读的记录-->
    <select id="getMeUnRead" resultType="java.lang.String">
        SELECT F_Id FROM ftb_log_member_log_association
        WHERE F_Member_Log_Id = #{logId} AND F_User_Id = #{userId}
          AND F_User_Type = 1 AND F_Type IN (1,2) AND F_Read = 0
    </select>
</mapper>