<?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.younike.system.mapper.PublishQuoteReplyMapper">

    <resultMap type="PublishQuoteReply" id="PublishQuoteReplyResult">
        <result property="replyId"    column="reply_id"    />
        <result property="quoteId"    column="quote_id"    />
        <result property="reReplyId" column="re_reply_id"/>
        <result property="serverUserId"    column="server_user_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="replyType"    column="reply_type"    />
        <result property="replyDesc"    column="reply_desc"    />
        <result property="readFlag"    column="read_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <result property="nikeName"    column="nike_name"    />
    </resultMap>
    <resultMap type="com.younike.system.domain.vo.PublishQuoteReplyVo" id="PublishQuoteReplyVoResult">
        <result property="replyId"    column="reply_id"    />
        <result property="quoteId"    column="quote_id"    />
        <result property="reReplyId" column="re_reply_id"/>
        <result property="serverUserId"    column="server_user_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="replyType"    column="reply_type"    />
        <result property="replyDesc"    column="reply_desc"    />
        <result property="readFlag"    column="read_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="serverAvatar"    column="serverAvatar"    />
        <result property="serverName"    column="serverName"    />
        <result property="avatar"    column="avatar"    />
        <result property="name"    column="name"    />
        <collection property="replyVoList" select="getQuoteId" column="reply_id"
                    ofType="com.younike.system.domain.vo.PublishQuoteReplyVo">
        </collection>
    </resultMap>
    <resultMap type="com.younike.system.domain.vo.PublishQuoteReplyVo" id="PublishQuoteReplyDataResult">
        <result property="replyId"    column="reply_id"    />
        <result property="quoteId"    column="quote_id"    />
        <result property="reReplyId" column="re_reply_id"/>
        <result property="serverUserId"    column="server_user_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="replyType"    column="reply_type"    />
        <result property="replyDesc"    column="reply_desc"    />
        <result property="readFlag"    column="read_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="serverAvatar"    column="serverAvatar"    />
        <result property="serverName"    column="serverName"    />
        <result property="avatar"    column="avatar"    />
        <result property="name"    column="name"    />
        <result property="replyReplyType"    column="replyReplyType"    />
        <result property="replyServerAvatar"    column="replyServerAvatar"    />
        <result property="replyServerName"    column="replyServerName"    />
        <result property="replyAvatar"    column="replyAvatar"    />
        <result property="replyName"    column="replyName"    />
    </resultMap>

    <sql id="selectPublishQuoteReplyVo">
        select reply_id, quote_id, re_reply_id, server_user_id,
               pqr.member_id, reply_type, reply_desc, read_flag,
               pqr.del_flag, pqr.create_by, pqr.create_time, pqr.update_by,
               pqr.update_time, pqr.column1, pqr.column2, pqr.column3,m.nike_name,pqr.create_time
        from publish_quote_reply pqr
        left join member m on pqr.member_id = m.member_id
    </sql>
    <sql id="selectPublishQuoteReply">
       a.reply_id, a.quote_id, a.re_reply_id, a.server_user_id, a.member_id, a.reply_type, a.reply_desc, a.read_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.column1, a.column2, a.column3
    </sql>


    <select id="selectPublishQuoteReplyList" parameterType="PublishQuoteReply" resultMap="PublishQuoteReplyResult">
        <include refid="selectPublishQuoteReplyVo"/>
        <where>
            <if test="quoteId != null "> and pqr.quote_id = #{quoteId}</if>
            <if test="serverUserId != null "> and pqr.server_user_id = #{serverUserId}</if>
            <if test="memberId != null "> and pqr.member_id = #{memberId}</if>
            <if test="replyType != null  and replyType != ''"> and reply_type = #{replyType}</if>
            <if test="replyDesc != null  and replyDesc != ''"> and reply_desc = #{replyDesc}</if>
            <if test="readFlag != null  and readFlag != ''"> and read_flag = #{readFlag}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
            <if test="reReplyId != null  "> and re_reply_id = #{reReplyId}</if>
        </where>
    </select>






    <select id="selectPublishQuoteReplyByReplyId" parameterType="Long" resultMap="PublishQuoteReplyResult">
        <include refid="selectPublishQuoteReplyVo"/>
        where reply_id = #{replyId}
    </select>

    <insert id="insertPublishQuoteReply" parameterType="PublishQuoteReply" useGeneratedKeys="true" keyProperty="replyId">
        insert into publish_quote_reply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="quoteId != null">quote_id,</if>
            <if test="serverUserId != null">server_user_id,</if>
            <if test="reReplyId != null">re_reply_id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="replyType != null and replyType != ''">reply_type,</if>
            <if test="replyDesc != null">reply_desc,</if>
            <if test="readFlag != null and readFlag != ''">read_flag,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="quoteId != null">#{quoteId},</if>
            <if test="serverUserId != null">#{serverUserId},</if>
            <if test="reReplyId != null">#{reReplyId},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="replyType != null and replyType != ''">#{replyType},</if>
            <if test="replyDesc != null">#{replyDesc},</if>
            <if test="readFlag != null and readFlag != ''">#{readFlag},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <update id="updatePublishQuoteReply" parameterType="PublishQuoteReply">
        update publish_quote_reply
        <trim prefix="SET" suffixOverrides=",">
            <if test="quoteId != null">quote_id = #{quoteId},</if>
            <if test="serverUserId != null">server_user_id = #{serverUserId},</if>
            <if test="reReplyId != null">re_reply_id = #{reReplyId},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="replyType != null and replyType != ''">reply_type = #{replyType},</if>
            <if test="replyDesc != null">reply_desc = #{replyDesc},</if>
            <if test="readFlag != null and readFlag != ''">read_flag = #{readFlag},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where reply_id = #{replyId}
    </update>

    <delete id="deletePublishQuoteReplyByReplyId" parameterType="Long">
        delete from publish_quote_reply where reply_id = #{replyId}
    </delete>

    <delete id="deletePublishQuoteReplyByReplyIds" parameterType="String">
        delete from publish_quote_reply where reply_id in
        <foreach item="replyId" collection="array" open="(" separator="," close=")">
            #{replyId}
        </foreach>
    </delete>

    <select id="getQuoteId" resultMap="PublishQuoteReplyVoResult">
      select  <include refid="selectPublishQuoteReply"/>,
        b.avatar as serverAvatar,
        b.nike_name as serverName,
        c.avatar,
        c.nike_name as name
        from publish_quote_reply a
        left join server_user b on a.server_user_id=b.server_id and b.del_flag=0
        left join  member c on c.member_id=a.member_id and c.del_flag=0
        where a.re_reply_id = #{reply_id}
        and a.del_flag=0
    </select>

</mapper>
