<?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.GoodsColorMapper">
    
    <resultMap type="GoodsColor" id="GoodsColorResult">
        <result property="id"    column="id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="color"    column="color"    />
    </resultMap>

    <sql id="selectGoodsColorVo">
        select id, goods_id, color from goods_color
    </sql>

    <select id="selectGoodsColorList" parameterType="GoodsColor" resultMap="GoodsColorResult">
        <include refid="selectGoodsColorVo"/>
        <where>  
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="color != null  and color != ''"> and color = #{color}</if>
        </where>
    </select>
    
    <select id="selectGoodsColorById" parameterType="Long" resultMap="GoodsColorResult">
        <include refid="selectGoodsColorVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertGoodsColor" parameterType="GoodsColor">
        insert into goods_color
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="goodsId != null ">goods_id,</if>
            <if test="color != null  and color != ''">color,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="goodsId != null ">#{goodsId},</if>
            <if test="color != null  and color != ''">#{color},</if>
         </trim>
    </insert>

    <insert id="insertGoodsColorList" >
        insert into goods_color (goods_id,color) values
        <foreach collection="list" item="item" index="index"
                 separator=",">
            (
            #{goodsId},
            #{item.color}
            )
        </foreach>
    </insert>


</mapper>