<?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.dgtly.goods.mapper.GoodsAttributeMapper">
    
    <resultMap type="GoodsAttribute" id="GoodsAttributeResult">
        <result property="id"    column="id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="attributeId"    column="attribute_id"    />
        <result property="value"    column="value"    />
    </resultMap>

    <sql id="selectGoodsAttributeVo">
        select id, goods_id, attribute_id, value, create_time, create_by, update_time, update_by, remark from goods_attribute
    </sql>

    <select id="selectGoodsAttributeList" parameterType="GoodsAttribute" resultMap="GoodsAttributeResult">
        <include refid="selectGoodsAttributeVo"/>
        <where>  
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="attributeId != null "> and attribute_id = #{attributeId}</if>
            <if test="value != null  and value != ''"> and value = #{value}</if>
        </where>
    </select>

        
    <insert id="insertGoodsAttribute" parameterType="GoodsAttribute">
        insert into goods_attribute
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="goodsId != null ">goods_id,</if>
            <if test="attributeId != null ">attribute_id,</if>
            <if test="value != null  and value != ''">value,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="goodsId != null ">#{goodsId},</if>
            <if test="attributeId != null ">#{attributeId},</if>
            <if test="value != null  and value != ''">#{value},</if>
         </trim>
    </insert>

    <insert id="insertGoodsAttributeList" >
        insert into goods_attribute (goods_id,attribute_id,value) values
        <foreach collection="list" item="item" index="index"
                 separator=",">
            (
            #{goodsId},
            #{item.attributeId},
            #{item.value}
            )
        </foreach>
    </insert>

    <delete id="deleteGoodsAttributeById" parameterType="Long">
        delete from goods_attribute where id = #{id}
    </delete>

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