<?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.yonge.cooleshow.bbs.dao.BbsFollowDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.bbs.entity.BbsFollow">
            <result column="id_" property="id" />
	        <result column="user_id_" property="userId" />
	        <result column="friend_user_id" property="friendUserId" />
	        <result column="created_time_" property="createdTime" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.user_id_ as userId
        , t.friend_user_id as friendUserId
        , t.created_time_ as createdTime
        </sql> 
    
    <select id="detail" resultType="com.yonge.cooleshow.bbs.vo.BbsFollowVo">
        SELECT
            <include refid="baseColumns"/>
        FROM bbs_follow t
        where t.id_ = #{id}
    </select>
    
    <select id="selectPage" resultType="com.yonge.cooleshow.bbs.vo.BbsFollowVo">
		SELECT         
        	<include refid="baseColumns" />
        ,su.username_ as username
        ,su.avatar_ as avatar
		FROM bbs_follow t
        left join sys_user su on
        <choose>
            <when test="param.type == 'FANS'">
                t.user_id_ = su.id_
            </when>
            <when test="param.type == 'FOLLOW'">
                t.friend_user_id = su.id_
            </when>
        </choose>

        <where>
            <if test="param.userId != null">
                <choose>
                    <when test="param.type == 'FANS'">
                        t.friend_user_id = #{param.userId}
                    </when>
                    <when test="param.type == 'FOLLOW'">
                        and t.user_id_ = #{param.userId}
                    </when>
                </choose>
            </if>
        </where>
	</select>
</mapper>