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

  <!--
      FIXME
      思考：阿里规范明确规定不能超过三表关联，这里达到了四张表
      我们应该如何优化呢？使得sql脚本查询表位三表或者两表查询
      来实现呢又或者说我们能不能不使用数据库，使用别的手段（中间件）？mycat
   -->
  <select id="getCommentList" resultType="com.wzj.soopin.content.domain.vo.CommentVO">
    SELECT
        c.id,
        c.id as commentId,
        c.member_id as vlogerId,
        c.status,
        c.father_comment_id as fatherCommentId,
        c.vlog_id as vlogId,
        c.comment_user_id as commentUserId,
        m.nickname as commentUserNickname,
        m.avatar as commentUserFace,
        c.content,
        c.like_counts as likeCounts,
        c.create_time as createTime
    FROM cont_comment c
    LEFT JOIN ums_member m ON c.comment_user_id = m.id
    <where>
        <if test="paramMap.vlogId != null and paramMap.vlogId != ''">
            AND c.vlog_id = #{paramMap.vlogId}
        </if>
        <if test="paramMap.mobile != null and paramMap.mobile != ''">
            AND m.phone_hidden LIKE CONCAT('%', #{paramMap.mobile}, '%')
        </if>
        <if test="true">
            AND (c.father_comment_id = '0' OR c.father_comment_id IS NULL)
        </if>
    </where>
    ORDER BY c.create_time DESC
  </select>

  <select id="selectByMobileAndVlogId" resultType="com.wzj.soopin.content.domain.vo.CommentVO">
    SELECT
        c.id,
        c.id as commentId,
        c.member_id as vlogerId,
        c.father_comment_id as fatherCommentId,
        c.vlog_id as vlogId,
        c.comment_user_id as commentUserId,
        c.status,
        m.nickname as commentUserNickname,
        m.avatar as commentUserFace,
        c.content,
        c.like_counts as likeCounts,
        c.create_time as createTime
    FROM cont_comment c
    LEFT JOIN ums_member m ON c.comment_user_id = m.id
    <where>
        c.father_comment_id = '0'
        <if test="vlogId != null and vlogId != ''">
            AND c.vlog_id = #{vlogId}
        </if>
        <if test="mobile != null and mobile != ''">
            AND m.phone_hidden LIKE CONCAT('%', #{mobile}, '%')
        </if>
    </where>
    ORDER BY c.create_time DESC
  </select>

</mapper>
