<?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.GoodsCommentMapper">
    <resultMap id="GoodsCommentVoServerResult" extends="GoodsCommentResult" type="com.younike.system.domain.vo.GoodsCommentVo">
        <result column="avatar" property="avatar"/>
        <result column="phone" property="phone"/>
        <result column="commont_id" property="commontId"/>
        <result column="order_index" property="orderIndex"/>
        <result column="is_anonymous" property="isAnonymous"/>

    </resultMap>
    <select id="getCommentlistByServerId" resultMap="GoodsCommentVoServerResult" >
        SELECT
           m.avatar,m.phone,gc.create_time,gc.content,gc.score,gc.reply,gc.re_content,gc.reply_time,gc.re_content_time,gc.commont_id,gc.is_anonymous,o.order_index
        FROM
           goods_comment gc
        LEFT JOIN  member m ON gc.member_id = m.member_id AND m.del_flag = 0
        LEFT JOIN `order` o ON o.order_id = gc.order_id AND o.del_flag = 0
        WHERE
           gc.del_flag = 0
        AND
           gc.server_id = #{serverId}
        ORDER BY gc.create_time DESC
    </select>

    <select id="getMemberGoodsCommentDetail" resultType="com.younike.system.domain.vo.GoodsCommentVo" >
        SELECT
        gc.commont_id,
        gc.content,
        gc.score,
        gc.reply,
        gc.reply_time,
        gc.re_content,
        gc.re_content_time,
        gc.is_anonymous,
        gc.create_by,
        gc.create_time
        FROM
        goods_comment gc
        WHERE gc.del_flag = 0
        AND gc.commont_id = #{commontId}
    </select>

    <!--根据订单id和memberId查询评价-->
    <select id="getByOrderIdAndMemberId" resultType="com.younike.system.domain.GoodsComment" >
        SELECT
            gc.commont_id,
            gc.content,
            gc.score,
            gc.reply,
            gc.reply_time,
            gc.re_content,
            gc.re_content_time,
            gc.is_anonymous,
            gc.create_by,
            gc.create_time
        FROM
            goods_comment gc
        WHERE gc.del_flag = 0
          AND gc.order_id = #{orderId}
          AND gc.member_id = #{memberId}
    </select>

    <!--根据订单id查询评价-->
    <select id="getByOrderId" resultType="com.younike.system.domain.GoodsComment" >
        SELECT
            gc.commont_id,
            gc.content,
            gc.score,
            gc.reply,
            gc.reply_time,
            gc.re_content,
            gc.re_content_time,
            gc.is_anonymous,
            gc.create_by,
            gc.create_time
        FROM
            goods_comment gc
        WHERE gc.del_flag = 0
          AND gc.order_id = #{orderId}
        ORDER BY gc.create_time DESC
        LIMIT 1
    </select>
</mapper>
