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

    <insert id="addLog">
        insert into ftb_log_member_log (F_Id, F_Log_Template_Id, F_Title,
                                        F_Log_Type, F_Organize_Id, F_Organize_Name,
                                        F_Position_Id, F_Position_Name, F_Pic,
                                        F_File, F_CreatorTime, F_CreatorUserId,
                                        F_LastModifyTime, F_LastModifyUserId)
        values (#{logMemberLogDto.id}, #{logMemberLogDto.logTemplateId}, #{logMemberLogDto.title},
                #{logMemberLogDto.logType}, #{logMemberLogDto.organizeId}, #{logMemberLogDto.organizeName},
                #{logMemberLogDto.positionId}, #{logMemberLogDto.positionName}, #{logMemberLogDto.pic},
                #{logMemberLogDto.file}, now(), #{userId},
                now(), #{userId})
    </insert>
<!--    修改日志主表-->
    <update id="updateLog">
        update ftb_log_member_log
        set
            F_Title = #{logMemberLogDto.title},
            F_Organize_Id = #{logMemberLogDto.organizeId},
            F_Organize_Name = #{logMemberLogDto.organizeName},
            F_Position_Id = #{logMemberLogDto.positionId},
            F_Position_Name = #{logMemberLogDto.positionName},
            F_Pic = #{logMemberLogDto.pic},
            F_File = #{logMemberLogDto.file},
            F_LastModifyTime = now(),
            F_LastModifyUserId = #{userId}
        where F_Id = #{logMemberLogDto.id}
    </update>
    <update id="deleteLog">
        update ftb_log_member_log
        set
            F_DeleteTime = now(),
            F_DeleteUserId = #{userId},
            F_EnabledMark = 1
        where F_Id = #{logId}
    </update>
    <!--    通过日志id获取日志详情-->
    <select id="getLogDetail" resultType="jnpf.model.memberLog.vo.LogMemberLogVo">
        SELECT l.F_Id id, l.F_Log_Template_Id logTemplateId, l.F_Title title, l.F_Log_Type logType,
               l.F_Organize_Id organizeId, l.F_Organize_Name organizeName,l.F_Position_Id positionId,
               l.F_Position_Name positionName, l.F_Pic pic, l.F_File file, l.F_CreatorTime creatorTime,
               l.F_CreatorUserId creatorUserId,l.F_LastModifyTime lastModifyTime, l.F_LastModifyUserId lastModifyUserId  ,F_EnabledMark enabledMark,
               (SELECT  COUNT(DISTINCT F_User_Id) FROM ftb_log_member_log_association WHERE F_Type = 4 AND F_User_Type = 1  AND F_Member_Log_Id = l.F_Id) AS likeNum,
               (SELECT  COUNT(DISTINCT F_User_Id) FROM ftb_log_member_log_association WHERE (F_Type = 1 OR F_Type = 2)  AND F_User_Type = 1  AND F_Read = 1 AND F_Member_Log_Id = l.F_Id) AS readNUm,
               (SELECT  COUNT(DISTINCT F_User_Id) FROM ftb_log_member_log_association WHERE (F_Type = 1 OR F_Type = 2)  AND F_User_Type = 1  AND F_Read = 0 AND F_Member_Log_Id = l.F_Id) AS noReadNum,
                (SELECT COUNT(0) FROM ftb_log_comment WHERE F_Member_Log_Id = l.F_Id AND F_EnabledMark = 0) AS replyNum
        FROM ftb_log_member_log l
        WHERE F_Id = #{logId} and F_EnabledMark = 0
    </select>
    <select id="selectById" resultType="jnpf.model.memberLog.vo.LogMemberLogVo">
        SELECT l.F_Id id, l.F_Log_Template_Id logTemplateId, l.F_Title title, l.F_Log_Type logType,
               l.F_Organize_Id organizeId, l.F_Organize_Name organizeName,l.F_Position_Id positionId,
               l.F_Position_Name positionName, l.F_Pic pic, l.F_File file, l.F_CreatorTime creatorTime,
               l.F_CreatorUserId creatorUserId,l.F_LastModifyTime lastModifyTime, l.F_LastModifyUserId lastModifyUserId  ,F_EnabledMark enabledMark
        FROM ftb_log_member_log l
        WHERE F_Id = #{logId} and F_EnabledMark = 0
    </select>
</mapper>