<?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.GiftPoolMapper">
    <resultMap  id="BaseResultMap" type="GiftPool" >
        <result    column="gift_pool_id"    property="giftPoolId" />
        <result    column="sett_gift_id"    property="settGiftId" />
        <result    column="gift_pool_color_id"    property="giftPoolColorId" />
        <result    column="gift_pool_price"    property="giftPoolPrice" />
        <result    column="gift_pool_num"    property="giftPoolNum" />
        <result    column="gift_pool_status"    property="giftPoolStatus" />
        <result    column="gift_pool_sort"    property="giftPoolSort" />
        <result    column="gift_pool_stock"    property="giftPoolStock" />
        <result    column="gift_pool_relation"    property="giftPoolRelation" />
        <result    column="gift_pool_relation_desc"    property="giftPoolRelationDesc" />
        <result    column="gift_pool_create_time"    property="giftPoolCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.gift_pool_id,
        t.sett_gift_id,
        t.gift_pool_color_id,
        t.gift_pool_price,
        t.gift_pool_num,
        t.gift_pool_status,
        t.gift_pool_sort,
        t.gift_pool_stock,
        t.gift_pool_relation,
        t.gift_pool_relation_desc,
        t.gift_pool_create_time
    </sql>
    <select id="getGiftPoolList" resultMap="BaseResultMap" parameterType="GiftPool" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_gift_pool t
        <where>
            <if test="giftPoolId != null ">
                AND t.gift_pool_id = #{giftPoolId}
            </if >
            <if test="settGiftId != null ">
                AND t.sett_gift_id = #{settGiftId}
            </if >
            <if test="giftPoolColorId != null ">
                AND t.gift_pool_color_id = #{giftPoolColorId}
            </if >
            <if test="giftPoolPrice != null ">
                AND t.gift_pool_price = #{giftPoolPrice}
            </if >
            <if test="giftPoolNum != null ">
                AND t.gift_pool_num = #{giftPoolNum}
            </if >
            <if test="giftPoolStatus != null ">
                AND t.gift_pool_status = #{giftPoolStatus}
            </if >
            <if test="giftPoolSort != null ">
                AND t.gift_pool_sort = #{giftPoolSort}
            </if >
            <if test="giftPoolStock != null ">
                AND t.gift_pool_stock = #{giftPoolStock}
            </if >
        </where>
    </select>
    <select id="getGiftPoolById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_gift_pool t
        where t.gift_pool_id= #{giftPoolId}
    </select>

    <update id="updateStock" parameterType="GiftPool" >
        update
        tb_iamberry_eo_gift_pool
        SET
        gift_pool_stock = gift_pool_stock - #{giftPoolStock}
        where gift_pool_id= #{giftPoolId}
    </update>

    <update id="updateAddStock" parameterType="GiftPool" >
        update
        tb_iamberry_eo_gift_pool
        SET
        gift_pool_stock = gift_pool_stock + #{giftPoolStock}
        where gift_pool_id= #{giftPoolId}
    </update>
</mapper>