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

    <resultMap type="GoodsCommentResourceVo" id="GoodsCommentResourceResult">
        <result property="recourceId"    column="recource_id"    />
        <result property="commentId"    column="comment_id"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="type"    column="type"    />
        <result property="url"    column="url"    />
        <result property="faceImg"    column="face_img"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="version"    column="version"    />
    </resultMap>

    <sql id="selectGoodsCommentResourceVo">
        select recource_id, gcr.comment_id, gcr.merchant_id, gcr.type, url, face_img,
            gcr.is_del,
            gcr.create_time,
            gcr.update_time,
            gcr.version
            from goods_comment_resource gcr
    </sql>

    <select id="selectGoodsCommentResourceList" parameterType="GoodsCommentResourceVo" resultMap="GoodsCommentResourceResult">
        <include refid="selectGoodsCommentResourceVo"/>
        <where>
            <if test="commentId != null "> and gcr.comment_id = #{commentId}</if>
            <if test="merchantId != null "> and gcr.merchant_id = #{merchantId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="faceImg != null  and faceImg != ''"> and face_img = #{faceImg}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="version != null "> and version = #{version}</if>
        </where>
        order by gcr.type desc
    </select>

    <select id="selectGoodsCommentResourceByRecourceId" parameterType="Long" resultMap="GoodsCommentResourceResult">
        <include refid="selectGoodsCommentResourceVo"/>
        where recource_id = #{recourceId}
    </select>

    <insert id="insertGoodsCommentResource" parameterType="GoodsCommentResource">
        insert into goods_comment_resource
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recourceId != null">recource_id,</if>
            <if test="commentId != null">comment_id,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="url != null and url != ''">url,</if>
            <if test="faceImg != null">face_img,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="version != null">version,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recourceId != null">#{recourceId},</if>
            <if test="commentId != null">#{commentId},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="url != null and url != ''">#{url},</if>
            <if test="faceImg != null">#{faceImg},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="version != null">#{version},</if>
        </trim>
    </insert>

    <update id="updateGoodsCommentResource" parameterType="GoodsCommentResource">
        update goods_comment_resource
        <trim prefix="SET" suffixOverrides=",">
            <if test="commentId != null">comment_id = #{commentId},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="url != null and url != ''">url = #{url},</if>
            <if test="faceImg != null">face_img = #{faceImg},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="version != null">version = #{version},</if>
        </trim>
        where recource_id = #{recourceId}
    </update>

    <delete id="deleteGoodsCommentResourceByRecourceId" parameterType="Long">
        delete from goods_comment_resource where recource_id = #{recourceId}
    </delete>

    <delete id="deleteGoodsCommentResourceByRecourceIds" parameterType="String">
        delete from goods_comment_resource where recource_id in
        <foreach item="recourceId" collection="array" open="(" separator="," close=")">
            #{recourceId}
        </foreach>
    </delete>
</mapper>
