<?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.BbsReplyDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.bbs.entity.BbsReply">
            <result column="id_" property="id" />
	        <result column="parent_id_" property="parentId" />
	        <result column="article_id" property="articleId" />
	        <result column="user_id_" property="userId" />
	        <result column="content_" property="content" />
	        <result column="status_" property="status" />
	        <result column="created_time_" property="createdTime" />
	        <result column="updated_time_" property="updatedTime" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.parent_id_ as parentId
        , t.article_id as articleId
        , t.user_id_ as userId
        , t.content_ as content
        , t.status_ as status
        , t.created_time_ as createdTime
        , t.updated_time_ as updatedTime
        </sql> 
    
    <select id="detail" resultType="com.yonge.cooleshow.bbs.vo.BbsReplyVo">
        SELECT
            <include refid="baseColumns"/>
        FROM bbs_reply t
        where t.id_ = #{id}
    </select>
    
    <select id="selectPage" resultType="com.yonge.cooleshow.bbs.vo.BbsReplyVo">
		SELECT         
        	<include refid="baseColumns" />
		FROM bbs_reply t
        <where>
            <if test="param.userId != null">
                and #{param.userId} = t.user_id_
            </if>
        </where>
	</select>

	<select id="selectCommentPage" resultType="com.yonge.cooleshow.bbs.vo.BbsReplyVo">
        select
        br.id_ as id
        , br.parent_id_ as parentId
        , br.article_id as articleId
        , br.user_id_ as userId
        , br.content_ as content
        , br.status_ as status
        , br.created_time_ as createdTime
        , br.updated_time_ as updatedTime
        ,ba.title_ as articleTitle
        from bbs_reply br
        left join bbs_article ba on br.article_id = ba.id_
        <where>
            <if test="query.userId != null">
                and  br.user_id_ = #{query.userId}
            </if>
        </where>
        order by br.created_time_ desc
    </select>

	<select id="selectReplyPage" resultType="com.yonge.cooleshow.bbs.vo.BbsReplyVo">
        select
        br.id_ as id
        , br.parent_id_ as parentId
        , br.article_id as articleId
        , br.user_id_ as userId
        , br.content_ as content
        , br.status_ as status
        , br.created_time_ as createdTime
        , br.updated_time_ as updatedTime
        ,ba.title_ as articleTitle
        from bbs_reply br
        left join bbs_article ba on br.article_id = ba.id_
        left join bbs_reply br2 on br.parent_id_ = br2.id_
        <where>
            ba.del_flag_ = 0
            <if test="query.userId != null">
                and  (ba.user_id_ = #{query.userId} or br2.user_id_ = #{query.userId})
            </if>
        </where>
        order by br.created_time_ desc
    </select>

	<select id="selectAuditListPage" resultType="com.yonge.cooleshow.bbs.vo.BbsReplyAuditVo">
        select
        br.id_ as id
        , br.parent_id_ as parentId
        , br.article_id as articleId
        , br.user_id_ as userId
        , br.content_ as content
        , br.status_ as status
        , br.created_time_ as createdTime
        , br.updated_time_ as updatedTime
        ,ba.title_ as articleTitle
        , su.username_ as userName
        ,su.real_name_ as realName
        ,su.phone_ as phone
        ,verify.username_ as verifyName
        ,brar.reason_ as reason
        ,brar.update_time_ as verifyTime
        from bbs_reply br
        left join bbs_article ba on br.article_id = ba.id_
        left join bbs_reply_auth_record brar on br.id_ = brar.reply_id_
        left join sys_user su on br.user_id_ = su.id_
        left join sys_user verify on verify.id_ = brar.verify_user_id_
        <where>
            ba.del_flag_ = 0
            <if test="query.status != null">
                and #{query.status} = brar.audit_state_
            </if>
        </where>
    </select>
    <select id="selectConfig" resultType="java.lang.String" parameterType="java.lang.String">
        SELECT param_value_ FROM sys_config WHERE param_name_=#{paramName}
    </select>
</mapper>