<?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.iamberry.wechat.service.mapper.ExchangeItemMapper">
    <resultMap  id="BaseResultMap" type="ExchangeItem" >
        <result    column="exchange_item_id"    property="exchangeItemId" />
        <result    column="exchange_id"    property="exchangeId" />
        <result    column="color_id"    property="colorId" />
        <result    column="exchange_item_num"    property="exchangeItemNum" />
    </resultMap>
    <sql    id="Base_List" >
        t.exchange_item_id,
        t.exchange_id,
        t.color_id,
        t.exchange_item_num
    </sql>
    <select id="getExchangeItemList" resultMap="BaseResultMap" parameterType="ExchangeItem" >
        select
        <include refid="Base_List" />
        from tb_iamberry_coupon_exchange_item t
        <where>
            <if test="exchangeItemId != null ">
                AND t.exchange_item_id = #{exchangeItemId}
            </if >
            <if test="exchangeId != null ">
                AND t.exchange_id = #{exchangeId}
            </if >
            <if test="colorId != null ">
                AND t.color_id = #{colorId}
            </if >
        </where>
    </select>
    <select id="getExchangeItemById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_coupon_exchange_item t
        where t.exchange_item_id= #{exchangeItemId}
    </select>
    <insert id="save" parameterType="ExchangeItem" >
        insert into
        tb_iamberry_coupon_exchange_item
        (
        exchange_id,
        color_id,
        exchange_item_num
        )
        values
        (
        #{exchangeId},
        #{colorId},
        #{exchangeItemNum}
        )
    </insert>
    <update id="update" parameterType="ExchangeItem" >
        update
        tb_iamberry_coupon_exchange_item
        <set >
            <if test="exchangeId != null ">
                exchange_id = #{exchangeId},
            </if >
            <if test="colorId != null ">
                color_id = #{colorId},
            </if >
            <if test="exchangeItemNum != null ">
                exchange_item_num = #{exchangeItemNum}
            </if >
        </set >
        where exchange_item_id= #{exchangeItemId}
    </update>
</mapper>