<?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.wzj.soopin.content.mapper.VlogMapperCustom" >

  <select id="getIndexVlogList" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
    SELECT
		v.id,
        v.member_id,
        m.avatar,
        m.nickname,
        m.phone_encrypted as phone,
        v.create_time,
        v.title as content,
        v.url as url,
        v.cover as cover,
        v.title,
        v.width as width,
        v.height as height,
        v.like_counts as likeCounts,
        v.comments_counts as commentsCounts,
        v.is_private as isPrivate,
        v.city_code as cityCode,
        v.reason as reason,
        v.file_id as fileId,
        v.status as status,
        v.first_frame_img as firstFrameImg
    FROM
        cont_vlog v
    LEFT JOIN
        ums_member m
    ON
        v.member_id = m.id
    WHERE
        v.is_private = 0
        <choose>
          <when test="bo.status != null and bo.status!=''">
              AND v.status = #{bo.status}
          </when>
          <otherwise>
              AND v.status = 1
          </otherwise>
        </choose>
        AND v.first_frame_img IS NOT NULL
        <if test="bo.cityCode != null and bo.cityCode != ''">
          AND v.city_code = #{bo.cityCode}
        </if>
      <if test="bo.memberId != null and bo.memberId != ''">
          AND v.member_id = #{bo.memberId}
      </if>
        <if test="bo.title != null and bo.title != ''">
          AND v.title like '%${bo.title}%'
        </if>
      <if test="bo.startTime != null ">
          AND v.create_time >= #{bo.startTime}
      </if>
      <if test="bo.endTime != null ">
          AND #{bo.endTime} >= v.create_time
      </if>
      <if test="bo.mobile != null and bo.mobile != ''">
          AND m.phone_encrypted like '%${bo.mobile}%'
      </if>
      <if test="bo.blockVd != null and bo.blockVd.size() > 0">
          AND v.id NOT IN
          <foreach collection="bo.blockVd" item="vlogId" open="(" separator="," close=")">
              #{vlogId}
          </foreach>
      </if>
      <if test="bo.blockUser != null and bo.blockUser.size() > 0">
          AND v.member_id NOT IN
          <foreach collection="bo.blockUser" item="memberId" open="(" separator="," close=")">
              #{memberId}
          </foreach>
      </if>
      <if test="bo.ids != null and bo.ids.size() > 0">
          AND v.id  IN
          <foreach collection="bo.ids" item="vlogId" open="(" separator="," close=")">
              #{vlogId}
          </foreach>
      </if>
    ORDER BY
        v.create_time
    DESC
  </select>


    <select id="getVlogDetailById" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
        SELECT
            v.id as vlogId,
            v.member_id as vlogerId,
            m.avatar as vlogerFace,
            m.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,
            v.city_code as cityCode,
            v.reason as reason,
            v.file_id as fileId,
            v.status as status,
            v.first_frame_img as firstFrameImg,
            v.id as vlogId
        FROM
          cont_vlog v
        LEFT JOIN
          ums_member m
        ON
          v.member_id = m.id
        WHERE
          v.id = #{paramMap.vlogId}
          AND v.status = 1
          AND v.first_frame_img IS NOT NULL
    </select>

    <select id="getMyLikedVlogList" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
        SELECT
            v.id as vlogId,
            v.member_id as memberId,
            v.title as title,
            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,
            v.city_code as cityCode,
            v.reason as reason,
            v.status as status,
            v.file_id as fileId,
            v.first_frame_img as firstFrameImg,
            v.id as Id,
            m.avatar as avatar,
            m.nickname as nickname

        FROM
            cont_vlog v
        LEFT JOIN
            cont_my_liked_vlog mlv
        ON
            v.id = mlv.vlog_id
        LEFT JOIN
            ums_member m
        ON
            v.member_id = m.id
        WHERE
            mlv.user_id = #{paramMap.myId}
            AND v.status = 1
            AND v.first_frame_img IS NOT NULL
            AND v.is_private = 0
            <if test="paramMap.blockVd != null and paramMap.blockVd.size() > 0">
                AND v.id NOT IN
                <foreach collection="paramMap.blockVd" item="vlogId" open="(" separator="," close=")">
                    #{vlogId}
                </foreach>
            </if>
            <if test="paramMap.blockUser != null and paramMap.blockUser.size() > 0">
                AND v.member_id NOT IN
                <foreach collection="paramMap.blockUser" item="vlogerId" open="(" separator="," close=")">
                    #{vlogerId}
                </foreach>
            </if>
        ORDER BY
            v.create_time
        DESC
    </select>

    <select id="getMyFollowVlogList" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
        SELECT
            v.id AS vlogId,
            v.member_id AS memberId,
            v.title AS title,
            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,
            v.city_code AS cityCode,
            v.reason AS reason,
            v.STATUS AS STATUS,
            v.file_id AS fileId,
            v.first_frame_img AS firstFrameImg,
            v.id AS Id,
            m.avatar AS avatar,
            m.nickname AS nickname
        FROM
            cont_vlog v
                LEFT JOIN ums_fans f ON v.member_id = f.vlogger_id
                LEFT JOIN ums_member m ON v.member_id = m.id
        WHERE
            NOT EXISTS ( SELECT 1 FROM cms_vlog_member vm WHERE v.id = vm.vlog_id AND vm.member_id = #{paramMap.myId} )
          AND v.is_private = 0
          AND v.STATUS = 1
          AND v.first_frame_img IS NOT NULL
          AND
            f.fan_id = #{paramMap.myId}
        ORDER BY
          v.create_time
        DESC
    </select>

    <select id="getMyFriendVlogList" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
        SELECT
            v.id AS vlogId,
            v.member_id AS memberId,
            v.title AS title,
            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,
            v.city_code AS cityCode,
            v.reason AS reason,
            v.STATUS AS STATUS,
            v.file_id AS fileId,
            v.first_frame_img AS firstFrameImg,
            v.id AS Id,
            m.avatar AS avatar,
            m.nickname AS nickname
        FROM
            cont_vlog v
                LEFT JOIN ums_fans f ON v.member_id = f.vlogger_id
                LEFT JOIN ums_member m ON v.member_id = m.id
        WHERE
            v.is_private = 0
          AND v.STATUS = 1
          AND v.first_frame_img IS NOT NULL
          AND f.fan_id = #{paramMap.myId}
          AND f.friend_flag = 1
          AND NOT EXISTS ( SELECT 1 FROM cms_vlog_member vm WHERE v.id = vm.vlog_id AND  vm.member_id= #{paramMap.myId} )
        ORDER BY
            v.create_time DESC
    </select>

</mapper>
