<?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.imooc.mapper.VlogMapperCustom" >

  <select id="getIndexVlogList" parameterType="map" resultType="com.imooc.vo.IndexVlogVO">
    SELECT
		v.id as vlogId,
        v.vloger_id as vlogerId,
        u.face as vlogerFace,
        u.nickname as vlogerName,
        v.title as content,
        v.url as url,
        v.cover as cover,
        v.width as width,
        v.height as height,
        v.like_counts as likeCounts,
        v.comments_counts as commentsCounts,
        v.is_private as isPrivate
    FROM
        vlog v
    LEFT JOIN
        users u
    ON
        v.vloger_id = u.id
    WHERE
        v.is_private = 0
        <if test="paramMap.search != null and paramMap.search != ''">
          AND v.title like '%${paramMap.search}%'
        </if>
    ORDER BY
        v.created_time
    DESC
  </select>


    <select id="getVlogDetailById" parameterType="map" resultType="com.imooc.vo.IndexVlogVO">
        SELECT
            v.id as vlogId,
            v.vloger_id as vlogerId,
            u.face as vlogerFace,
            u.nickname as vlogerName,
            v.title as content,
            v.url as url,
            v.cover as cover,
            v.width as width,
            v.height as height,
            v.like_counts as likeCounts,
            v.comments_counts as commentsCounts,
            v.is_private as isPrivate
        FROM
          vlog v
        LEFT JOIN
          users u
        ON
          v.vloger_id = u.id
        WHERE
          v.id = #{paramMap.vlogId}
    </select>

    <select id="getMyLikedVlogList" parameterType="map" resultType="com.imooc.vo.IndexVlogVO">
        SELECT
            v.id as vlogId,
            v.vloger_id as vlogerId,
--             u.face as vlogerFace,
--             u.nickname as vlogerName,
            v.title as content,
            v.url as url,
            v.cover as cover,
            v.width as width,
            v.height as height,
            v.like_counts as likeCounts,
            v.comments_counts as commentsCounts,
            v.is_private as isPrivate
        FROM
            vlog v
        LEFT JOIN
            my_liked_vlog mlv
        ON
            v.id = mlv.vlog_id
        LEFT JOIN
            users u
        ON
            mlv.user_id = u.id
        WHERE
            u.id = #{paramMap.userId}
          AND
            v.is_private = 0
        ORDER BY
            v.created_time
        DESC
    </select>

    <select id="getMyFollowVlogList" parameterType="map" resultType="com.imooc.vo.IndexVlogVO">
        SELECT
            v.id as vlogId,
            v.vloger_id as vlogerId,
            u.face as vlogerFace,
            u.nickname as vlogerName,
            v.title as content,
            v.url as url,
            v.cover as cover,
            v.width as width,
            v.height as height,
            v.like_counts as likeCounts,
            v.comments_counts as commentsCounts,
            v.is_private as isPrivate
        FROM
            vlog v
        LEFT JOIN
            fans f
        ON
            v.vloger_id = f.vloger_id
        LEFT JOIN
            users u
        ON
            f.vloger_id = u.id
        WHERE
            v.is_private = 0
          AND
            f.fan_id = #{paramMap.myId}
        ORDER BY
            v.created_time
        DESC
    </select>

    <select id="getMyFriendVlogList" parameterType="map" resultType="com.imooc.vo.IndexVlogVO">
        SELECT
            v.id as vlogId,
            v.vloger_id as vlogerId,
            u.face as vlogerFace,
            u.nickname as vlogerName,
            v.title as content,
            v.url as url,
            v.cover as cover,
            v.width as width,
            v.height as height,
            v.like_counts as likeCounts,
            v.comments_counts as commentsCounts,
            v.is_private as isPrivate
        FROM
            vlog v
        LEFT JOIN
            fans f
        ON
            v.vloger_id = f.fan_id
        LEFT JOIN
            users u
        ON
            f.fan_id = u.id
        WHERE
            v.is_private = 0
          AND
            f.vloger_id = #{paramMap.myId}
          AND
            f.is_fan_friend_of_mine = 1
        ORDER BY
            v.created_time
        DESC
    </select>

</mapper>