<?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.fs.live.mapper.LiveAfterSalesItemMapper">

    <resultMap type="LiveAfterSalesItem" id="LiveAfterSalesItemResult">
        <result property="id"    column="id"    />
        <result property="afterSalesId"    column="after_sales_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="productId"    column="product_id"    />
        <result property="jsonInfo"    column="json_info"    />
        <result property="isDel"    column="is_del"    />
        <result property="productAttrValueId"    column="product_attr_value_id"    />
    </resultMap>

    <sql id="selectLiveAfterSalesItemVo">
        select id, after_sales_id, goods_id, product_id, json_info, is_del, product_attr_value_id from live_after_sales_item
    </sql>

    <select id="selectLiveAfterSalesItemList" parameterType="LiveAfterSalesItem" resultMap="LiveAfterSalesItemResult">
        <include refid="selectLiveAfterSalesItemVo"/>
        <where>
            <if test="afterSalesId != null "> and after_sales_id = #{afterSalesId}</if>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="jsonInfo != null  and jsonInfo != ''"> and json_info = #{jsonInfo}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="productAttrValueId != null "> and product_attr_value_id = #{productAttrValueId}</if>
        </where>
    </select>

    <select id="selectLiveAfterSalesItemById" parameterType="Long" resultMap="LiveAfterSalesItemResult">
        <include refid="selectLiveAfterSalesItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertLiveAfterSalesItem" parameterType="LiveAfterSalesItem" useGeneratedKeys="true" keyProperty="id">
        insert into live_after_sales_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="afterSalesId != null">after_sales_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="jsonInfo != null and jsonInfo != ''">json_info,</if>
            <if test="isDel != null">is_del,</if>
            <if test="productAttrValueId != null">product_attr_value_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="afterSalesId != null">#{afterSalesId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="jsonInfo != null and jsonInfo != ''">#{jsonInfo},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="productAttrValueId != null">#{productAttrValueId},</if>
         </trim>
    </insert>

    <update id="updateLiveAfterSalesItem" parameterType="LiveAfterSalesItem">
        update live_after_sales_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="afterSalesId != null">after_sales_id = #{afterSalesId},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="jsonInfo != null and jsonInfo != ''">json_info = #{jsonInfo},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="productAttrValueId != null">product_attr_value_id = #{productAttrValueId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLiveAfterSalesItemById" parameterType="Long">
        delete from live_after_sales_item where id = #{id}
    </delete>

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