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

    <resultMap type="GoodsCommentsVO" id="GoodsCommentResult">
        <result property="commontId"    column="commont_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="serverId"    column="server_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="content"    column="content"    />
        <result property="score"    column="score"    />
        <result property="reply"    column="reply"    />
        <result property="replyTime"    column="reply_time"    />
        <result property="reContent"    column="re_content"    />
        <result property="reContentTime"    column="re_content_time"    />
        <result property="isAnonymous"    column="is_anonymous"    />
        <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="goodScore"    column="goodScore"    />
        <result property="phone"    column="phone"    />
        <result property="realName"    column="real_name"    />
        <result property="serverUserScore"    column="serverUserScore"    />
        <result property="goodName"    column="name"    />
        <result property="categoryName"    column="category_name"    />
        <result property="evaluate"    column="evaluate" />
    </resultMap>

    <sql id="selectGoodsCommentVo">
        select commont_id, member_id,
            gc.server_id,
            gc.order_id, gc.merchant_id, gc.goods_id, content,
            gc.score as goodScore, reply, reply_time, re_content, re_content_time, is_anonymous, gc.create_by, gc.create_time, gc.update_by, gc.update_time, gc.column1, gc.column2, gc.column3,
            gc.del_flag,
            su.phone,
            su.real_name,
            su.score as serverUserScore,
            og.`name`,
            cg.category_name,
            GROUP_CONCAT(concat(d.`name`,gsd.score)) as evaluate
            from goods_comment gc
            LEFT JOIN server_user su on su.server_id=gc.server_id
            LEFT join order_goods og on og.order_id=gc.order_id
            LEFT JOIN category cg ON cg.category_id = og.cate_id
            left join goods_server_dimension gsd on gsd.goods_id=gc.goods_id
            left join dimension d on d.dimension_id=gsd.dimension_id
    </sql>

    <select id="selectGoodsCommentList" parameterType="GoodsComment" resultMap="GoodsCommentResult">
        <include refid="selectGoodsCommentVo"/>
        <where>
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="serverId != null "> and gc.server_id = #{serverId}</if>
            <if test="orderId != null "> and gc.order_id = #{orderId}</if>
            <if test="merchantId != null "> and gc.merchant_id = #{merchantId}</if>
            <if test="goodsId != null  and goodsId != ''"> and gc.goods_id = #{goodsId}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="reply != null  and reply != ''"> and reply = #{reply}</if>
            <if test="replyTime != null "> and reply_time = #{replyTime}</if>
            <if test="reContent != null  and reContent != ''"> and re_content = #{reContent}</if>
            <if test="reContentTime != null "> and re_content_time = #{reContentTime}</if>
            <if test="isAnonymous != null "> and is_anonymous = #{isAnonymous}</if>
            <if test="column1 != null  and column1 != ''"> and gc.column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and gc.column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and gc.column3 = #{column3}</if>
            <if test="goodName != null  and goodName != ''"> and  og.`name` like concat('%', #{goodName}, '%')</if>
            <if test="phone != null  and phone != ''"> and   su.phone= #{phone}</if>
            <if test="realName != null  and realName != ''"> and   su.real_name like concat('%', #{realName}, '%')</if>
        </where>
        GROUP BY  gc.commont_id
        ORDER BY gc.create_time
    </select>

    <select id="selectGoodsCommentByCommontId" parameterType="Long" resultMap="GoodsCommentResult">
        <include refid="selectGoodsCommentVo"/>
        where commont_id = #{commontId}
    </select>

    <insert id="insertGoodsComment" parameterType="GoodsComment">
        insert into goods_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="commontId != null">commont_id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="serverId != null">server_id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="content != null">content,</if>
            <if test="score != null">score,</if>
            <if test="reply != null">reply,</if>
            <if test="replyTime != null">reply_time,</if>
            <if test="reContent != null">re_content,</if>
            <if test="reContentTime != null">re_content_time,</if>
            <if test="isAnonymous != null">is_anonymous,</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="commontId != null">#{commontId},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="serverId != null">#{serverId},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="content != null">#{content},</if>
            <if test="score != null">#{score},</if>
            <if test="reply != null">#{reply},</if>
            <if test="replyTime != null">#{replyTime},</if>
            <if test="reContent != null">#{reContent},</if>
            <if test="reContentTime != null">#{reContentTime},</if>
            <if test="isAnonymous != null">#{isAnonymous},</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="updateGoodsComment" parameterType="GoodsComment">
        update goods_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="serverId != null">server_id = #{serverId},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="score != null">score = #{score},</if>
            <if test="reply != null">reply = #{reply},</if>
            <if test="replyTime != null">reply_time = #{replyTime},</if>
            <if test="reContent != null">re_content = #{reContent},</if>
            <if test="reContentTime != null">re_content_time = #{reContentTime},</if>
            <if test="isAnonymous != null">is_anonymous = #{isAnonymous},</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 commont_id = #{commontId}
    </update>

    <delete id="deleteGoodsCommentByCommontId" parameterType="Long">
        delete from goods_comment where commont_id = #{commontId}
    </delete>

    <delete id="deleteGoodsCommentByCommontIds" parameterType="String">
        delete from goods_comment where commont_id in
        <foreach item="commontId" collection="array" open="(" separator="," close=")">
            #{commontId}
        </foreach>
    </delete>
</mapper>
